|
[Sponsors] |
driftFluxFoam viscosity model modification problem |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
September 17, 2018, 16:12 |
driftFluxFoam viscosity model modification problem
|
#1 |
New Member
Damien Leduc
Join Date: Sep 2018
Posts: 10
Rep Power: 8 |
Hi everyone,
I’m quite a beginner on OpenFoam and I would need some help about a solver modification I’m trying to make. The aim I would like to build a model that respresents the behavior of activated sludge inside a secondary clarifier (basicly I need to make a model about the sedimentation of a non-newtonian fluid). For this purpose I chose the solver “driftFluxFoam” (which might be my first mistake…) My problem is that in “driftFluxFoam” the non-newtonian behaviours follow laws from this type : mu = A x 10^(b.alpha) [1] Whereas, from the literature I found, the activated sludge viscosity is calculated from :mu = K1/γ + K2 [2] I found that in the viscosityModels, the viscosity was calculated from this strain rate (through the strainRate function). I then tried to adapt the driftFluxFoam solver to solve [2]. The code In the driftFluxFoam solver, I added, inside the mixtureViscosityModels :
Code:
\*---------------------------------------------------------------------------*/ #include "strainRateFunction.H" #include "addToRunTimeSelectionTable.H" #include "surfaceFields.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // namespace Foam { namespace mixtureViscosityModels { defineTypeNameAndDebug(strainRateFunction, 0); addToRunTimeSelectionTable ( mixtureViscosityModel, strainRateFunction, dictionary ); } } // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::mixtureViscosityModels::strainRateFunction::strainRateFunction ( const word& name, const dictionary& viscosityProperties, const volVectorField& U, const surfaceScalarField& phi ) : mixtureViscosityModel(name, viscosityProperties, U, phi), strainRateFunctionCoeffs_ ( viscosityProperties.optionalSubDict(typeName + "Coeffs") ), strainRateFunction_ ( Function1<scalar>::New("function", strainRateFunctionCoeffs_) ), mu_ ( IOobject ( "mu", U_.time().timeName(), U_.db() ), U_.mesh(), dimensionedScalar("mu", dimensionSet(1, -1, -1, 0, 0), 0), calculatedFvPatchScalarField::typeName ) { correct(); } // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // Foam::tmp<Foam::volScalarField> Foam::mixtureViscosityModels::strainRateFunction::mu() const { return mu_; } Foam::tmp<Foam::scalarField> Foam::mixtureViscosityModels::strainRateFunction::mu(const label patchi) const { return mu_.boundaryField()[patchi]; } void Foam::mixtureViscosityModels::strainRateFunction::correct() { tmp<volScalarField> tsigma = strainRate(); const volScalarField& sigma = tsigma(); mu_.primitiveFieldRef() = strainRateFunction_->value(sigma()); volScalarField::Boundary& muBf = mu_.boundaryFieldRef(); const volScalarField::Boundary& sigmaBf = sigma.boundaryField(); forAll(muBf, patchi) { muBf[patchi] = strainRateFunction_->value(sigmaBf[patchi]); } } bool Foam::mixtureViscosityModels::strainRateFunction::read ( const dictionary& viscosityProperties ) { mixtureViscosityModel::read(viscosityProperties); strainRateFunctionCoeffs_ = viscosityProperties.optionalSubDict ( typeName + "Coeffs" ); strainRateFunction_.clear(); strainRateFunction_ = Function1<scalar>::New ( "function", strainRateFunctionCoeffs_ ); return true; } Code:
Class Foam::viscosityModels::strainRateFunction SourceFiles strainRateFunction.C \*---------------------------------------------------------------------------*/ #ifndef strainRateFunction_H #define strainRateFunction_H #include "mixtureViscosityModel.H" #include "volFields.H" #include "Function1.H" #include "plastic.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { namespace mixtureViscosityModels { /*---------------------------------------------------------------------------*\ Class strainRateFunction Declaration \*---------------------------------------------------------------------------*/ class strainRateFunction : public mixtureViscosityModel { // Private data //- Coefficients dictionary dictionary strainRateFunctionCoeffs_; //- Strain-rate function autoPtr<Function1<scalar>> strainRateFunction_; //- Current viscosity field const volScalarField mu_; public: //- Runtime type information TypeName("strainRateFunction"); // Constructors //- Construct from components strainRateFunction ( const word& name, const dictionary& viscosityProperties, const volVectorField& U, const surfaceScalarField& phi ); //- Destructor virtual ~strainRateFunction() {} // Member Functions //- Return the viscosity virtual tmp<volScalarField> mu() const; //- Return the viscosity for patch virtual tmp<scalarField> mu(const label patchi) const; //- Correct the laminar viscosity virtual void correct(); //- Read transportProperties dictionary virtual bool read(const dictionary& viscosityProperties); }; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace viscosityModels } // End namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #endif // ************************************************************************* // Code:
\*---------------------------------------------------------------------------*/ #include "mixtureViscosityModel.H" #include "volFields.H" #include "fvcGrad.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // namespace Foam { defineTypeNameAndDebug(mixtureViscosityModel, 0); defineRunTimeSelectionTable(mixtureViscosityModel, dictionary); } // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::mixtureViscosityModel::mixtureViscosityModel ( const word& name, const dictionary& viscosityProperties, const volVectorField& U, const surfaceScalarField& phi ) : name_(name), viscosityProperties_(viscosityProperties), U_(U), phi_(phi) {} // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // Foam::tmp<Foam::volScalarField> Foam::mixtureViscosityModel::strainRate() const { return sqrt(2.0)*mag(symm(fvc::grad(U_))); } bool Foam::mixtureViscosityModel::read(const dictionary& viscosityProperties) { viscosityProperties_ = viscosityProperties; return true; } // ************************************************************************* // Code:
SourceFiles mixtureViscosityModel.C mixtureViscosityModelNew.C \*---------------------------------------------------------------------------*/ #ifndef mixtureViscosityModel_H #define mixtureViscosityModel_H #include "dictionary.H" #include "volFieldsFwd.H" #include "surfaceFieldsFwd.H" #include "dimensionedScalar.H" #include "runTimeSelectionTables.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { /*---------------------------------------------------------------------------*\ Class mixtureViscosityModel Declaration \*---------------------------------------------------------------------------*/ class mixtureViscosityModel { protected: // Protected data word name_; dictionary viscosityProperties_; const volVectorField& U_; const surfaceScalarField& phi_; // Private Member Functions //- Disallow copy construct mixtureViscosityModel(const mixtureViscosityModel&); //- Disallow default bitwise assignment void operator=(const mixtureViscosityModel&); public: //- Runtime type information TypeName("mixtureViscosityModel"); // Declare run-time constructor selection table declareRunTimeSelectionTable ( autoPtr, mixtureViscosityModel, dictionary, ( const word& name, const dictionary& viscosityProperties, const volVectorField& U, const surfaceScalarField& phi ), (name, viscosityProperties, U, phi) ); // Selectors //- Return a reference to the selected viscosity model static autoPtr<mixtureViscosityModel> New ( const word& name, const dictionary& viscosityProperties, const volVectorField& U, const surfaceScalarField& phi ); // Constructors //- Construct from components mixtureViscosityModel ( const word& name, const dictionary& viscosityProperties, const volVectorField& U, const surfaceScalarField& phi ); //- Destructor virtual ~mixtureViscosityModel() {} // Member Functions //- Return the phase transport properties dictionary const dictionary& viscosityProperties() const { return viscosityProperties_; } //- Return the strain rate tmp<volScalarField> strainRate() const; //- Return the mixture viscosity // given the viscosity of the continuous phase virtual tmp<volScalarField> mu(const volScalarField& muc) const; //virtual tmp<volScalarField> mu(const volScalarField& muc) const = 0; //- Return the laminar viscosity for patch //virtual tmp<scalarField> mu(const label patchi) const = 0; Cet ajout fait bugger la compilation de plastic.C... //- Read transportProperties dictionary virtual bool read(const dictionary& viscosityProperties) = 0; }; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } The problem When I try to compile the solver, I’m having some troubles with a part of the strainRateFunction (see attached file) From what I understood, this problems comes from the fact that my code risks to modify a variable that shouldn’t be modified (const). But I have no idea about how to fix this… What I have tried I tried to avoid the parts of the code at the origin of my problem (with “//”), then the solver compiles, but when I try to run it, I’m getting an error message (“symbol look up error”). I also tried to make my solver without the strainRateFunction replacing “strainRate()” with “sqrt(2.0)*mag(symm(fvc::grad(U_)))” directly inside “Casson.C”. The solver also compiles but crashes when I try to run it. This time the problem came from LHS and RHS which didn’t have the same dimension. As I said I’m very new to OpenFoam, and to be perfectly honest, I don’t really understand how the programming process… That is why I expect quite some huge mistakes and apologize about this… Finally, I don't know if it's usefull, but attached the code about incompressibleTwoPhaseInteratingmixture. As I said, maybe my first mistake was to choose driftFluxFoam… If you know another solver which would enable be to solve my problem, it would be a pleasure to try it ! I know it's quite time consuming to read all this... So thanks in advance for your help ! |
|
September 19, 2018, 07:41 |
|
#2 |
New Member
Damien Leduc
Join Date: Sep 2018
Posts: 10
Rep Power: 8 |
Problem solved...
When I declared my variable mu_ in strainRateFunction.H, I used "const volScalarFiel mu_" where I should only have used "volScalarFiel mu_" in order to enable the correct() function to modify the mu_ variable ! |
|
September 19, 2018, 10:40 |
|
#3 |
New Member
Damien Leduc
Join Date: Sep 2018
Posts: 10
Rep Power: 8 |
Unfortunately, I'm running into another type of error :
Code:
symbol lookup error: /home/leduc/OpenFOAM/leduc-5.0/platforms/linux64GccDPInt32Opt/lib/libdriftFluxTransportModels.so: undefined symbol: _ZNK4Foam22mixtureViscosityModels18strainRateFunction2muERKNS_14GeometricFieldIdNS_12fvPatchFieldENS_7volMeshEEE Code:
c++filt _ZNK4Foam22mixtureViscosityModels18strainRateFunction2muERKNS_14GeometricFieldIdNS_12fvPatchFieldENS_7volMeshEEE Foam::mixtureViscosityModels::strainRateFunction::mu(Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> const&) const Code:
Foam::tmp<Foam::volScalarField> Foam::mixtureViscosityModels::strainRateFunction::mu() const { return mu_; } Foam::tmp<Foam::scalarField> Foam::mixtureViscosityModels::strainRateFunction::mu(const label patchi) const { return mu_.boundaryField()[patchi]; } Any idea about how to fix this ? |
|
September 23, 2018, 15:40 |
|
#4 |
Senior Member
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16 |
did you try to include the library you compiled in the controlDict
|
|
September 25, 2018, 10:37 |
|
#5 |
New Member
Damien Leduc
Join Date: Sep 2018
Posts: 10
Rep Power: 8 |
Hi mAlleto,
Thank you very much for your answer, I just tried this : Code:
oamFile { version 2.0; format ascii; class dictionary; location "system"; object controlDict; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // libs ("home/OpenFOAM/leduc-5.0/platforms/linux64GccDPInt32Opt/lib/libdriftFluxRelativeVelocityModels.so" "home/OpenFOAM/leduc-5.0/platforms/linux64GccDPInt32Opt/lib/libdriftFluxTransportModels.so"); application driftFluxFoam_Casson; From what I read, generally those problems come from the wmake files. Here are the wmake files of my solver : File Code:
incompressibleTwoPhaseInteractingMixture/incompressibleTwoPhaseInteractingMixture.C compressibleTurbulenceModels.C driftFluxFoam_Casson.C EXE = $(FOAM_USER_APPBIN)/driftFluxFoam_Casson LIB = $(FOAM_USER_LIBBIN)/driftFluxFoam_Casson Options Code:
"EXE_INC = \ -IincompressibleTwoPhaseInteractingMixture \ -ImixtureViscosityModels/lnInclude \ -IrelativeVelocityModels/lnInclude \ -I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude \ -I$(LIB_SRC)/sampling/lnInclude \ -I$(LIB_SRC)/transportModels \ -I$(LIB_SRC)/transportModels/compressible/lnInclude \ -I$(LIB_SRC)/transportModels/twoPhaseMixture/lnInclude \ -I$(LIB_SRC)/TurbulenceModels/turbulenceModels/lnInclude \ -I$(LIB_SRC)/TurbulenceModels/compressible/lnInclude EXE_LIBS = \ -ldriftFluxRelativeVelocityModels \ -ldriftFluxTransportModels \ -L$(FOAM_USER_LIBBIN) \ -ltwoPhaseMixture \ -lfiniteVolume \ -lmeshTools \ -lsampling \ -lfvOptions \ -lcompressibleTransportModels \ -lturbulenceModels \ -lcompressibleTurbulenceModels The wmake files for the mixtureViscosityModels solver are : Files Code:
mixtureViscosityModel/mixtureViscosityModel.C mixtureViscosityModel/mixtureViscosityModelNew.C Casson/Casson.C strainRateFunction/strainRateFunction.C LIB = $(FOAM_USER_LIBBIN)/libdriftFluxTransportModels Options Code:
EXE_INC = \ -I../incompressibleTwoPhaseInteractingMixture \ -I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/transportModels \ -I$(LIB_SRC)/transportModels/twoPhaseMixture/lnInclude \ -I$(LIB_SRC)/transportModels/incompressible/lnInclude \ LIB_LIBS = \ -ltwoPhaseMixture \ -lfiniteVolume The error I get tells me that it comes from the compiledlibdriftFluxTransportModels.so file. More precisely from the strainRateFunction.C (see previous post). I'm not really used to link different libraries, and I suspect an error in my options files but can't find it... Thanks again for the time you took mAlleto ! |
|
September 25, 2018, 11:30 |
|
#6 | |
Senior Member
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16 |
Quote:
Did you define the function: mu(const volScalarField& muc) const; somewhere in the code a pice of code tries the execute the function mu which takes a const volScalarField as argument but it does not find it. So the error is generated from it. Or better said it has found the declaration but not the definition. So I ask if you declared it |
||
September 26, 2018, 11:15 |
|
#7 |
New Member
Damien Leduc
Join Date: Sep 2018
Posts: 10
Rep Power: 8 |
You were perfectly right :
In the mixtureViscosityModel.H, I declared : Code:
//- Return the mixture viscosity //- given the viscosity of the continuous phase virtual tmp<volScalarField> mu(const volScalarField &muc) const = 0 Code:
//- Return the mixture viscosity // given the viscosity of the continuous phase virtual tmp<volScalarField> mu(const volScalarField& muc) const I solved the problem by supressing the declaration of mu(const volScalarField& muc) in strainRateFunction.H and by modifying the declaration in mixtureViscosityModel.H as follows : mixtureViscosityModel.H Code:
//- Return the mixture viscosity //- given the viscosity of the continuous phase virtual tmp<volScalarField> mu(const volScalarField &muc) const; Unfortunately, as soon as a problem is solved, another comes up... The error message I'm getting now is : Code:
driftFluxFoam_Casson: symbol lookup error: /home/leduc/OpenFOAM/leduc-5.0/platforms/linux64GccDPInt32Opt/lib/libdriftFluxTransportModels.so: undefined symbol: _ZTIN4Foam21mixtureViscosityModelE Code:
c++filt _ZTIN4Foam21mixtureViscosityModelE typeinfo for Foam::mixtureViscosityModel |
|
September 26, 2018, 15:46 |
|
#8 | |
Senior Member
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16 |
Quote:
By the way why did you put Code:
incompressibleTwoPhaseInteractingMixture/incompressibleTwoPhaseInteractingMixture.C compressibleTurbulenceModels.C driftFluxFoam_Casson.C EXE = $(FOAM_USER_APPBIN)/driftFluxFoam_Casson LIB = $(FOAM_USER_LIBBIN)/driftFluxFoam_Casson usually you put only the EXE |
||
September 27, 2018, 04:46 |
|
#9 |
New Member
Damien Leduc
Join Date: Sep 2018
Posts: 10
Rep Power: 8 |
Code:
The error I get tells me that it comes from the compiledlibdriftFluxTransportModels.so file. More precisely from the strainRateFunction.C (see previous post). I'm not really used to link different libraries, and I suspect an error in my options files but can't find it... Thanks again for the time you took mAlleto ! For the actual error : Code:
driftFluxFoam_Casson: symbol lookup error: /home/leduc/OpenFOAM/leduc-5.0/platforms/linux64GccDPInt32Opt/lib/libdriftFluxTransportModels.so: undefined symbol: _ZTIN4Foam21mixtureViscosityModelE Code:
c++filt _ZTIN4Foam21mixtureViscosityModelE typeinfo for Foam::mixtureViscosityModel Or is it again a declaration problem in the code ? Just in case... Here's a wetransfer link to download my solver an the test case I use to see if it works : https://we.tl/t-7VZHXDPdKU Last edited by dleduc; September 27, 2018 at 06:25. |
|
September 30, 2018, 06:10 |
|
#10 |
Senior Member
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16 |
what version of OF did you use to compile your code?
|
|
September 30, 2018, 07:49 |
|
#11 |
New Member
Damien Leduc
Join Date: Sep 2018
Posts: 10
Rep Power: 8 |
Hi mAlleto,
I'm using OF5.0 ! Do you think I should use the last version ? |
|
September 30, 2018, 11:12 |
|
#12 |
Senior Member
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16 |
I compiled your code with OF6 and a bunch of errors popped up. Probably some classes have changed from OF5 and OF6.
Can you try to post a code which compiles with OF6? Otherwise it would take me too long to figure out what's going wrong. best michael |
|
September 30, 2018, 16:01 |
|
#13 |
Senior Member
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16 |
Ok i was able to compile your code with OF6 by changing alphaEqn.H with the one of OF. I get the the same error as you when executing it.
when looking through Make/options I found that you included twice a the viscosity model: EXE_INC = \ -IincompressibleTwoPhaseInteractingMixture \ -ImixtureViscosityModels/lnInclude \ -I./relativeVelocityModels/lnInclude \ -I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude \ -I$(LIB_SRC)/sampling/lnInclude \ -I$(LIB_SRC)/transportModels \ -I$(LIB_SRC)/transportModels/compressible/lnInclude \ -I$(LIB_SRC)/transportModels/twoPhaseMixture/lnInclude \ -I$(LIB_SRC)/TurbulenceModels/turbulenceModels/lnInclude \ -I$(LIB_SRC)/TurbulenceModels/compressible/lnInclude EXE_LIBS = \ -ldriftFluxTransportModels \ -> the one of OF -ldriftFluxRelativeVelocityModels \ -ltwoPhaseMixture \ -lfiniteVolume \ -lmeshTools \ -lsampling \ -lfvOptions \ -lcompressibleTransportModels \ -lturbulenceModels \ -lcompressibleTurbulenceModels \ -L$(FOAM_USER_LIBBIN)/libdriftFluxTransportModels -> your when removing the library of OF i get similar errors as you but already at compile time. There must be a naming conflict somewhere. |
|
October 1, 2018, 04:04 |
|
#14 |
New Member
Damien Leduc
Join Date: Sep 2018
Posts: 10
Rep Power: 8 |
Hi mAlletto,
indeed there was a naming problem... I began to suspect it when I tried to run my test case with the original driftFluxFoam and got the same error... driftFluxFoam tried to access my user library : Code:
/home/leduc/OpenFOAM/leduc-5.0/platforms/linux64GccDPInt32Opt/lib/libdriftFluxTransportModels.so I then changed the names of my solver and library to Cassonsed and libCassonsed.so and the error went away... Now the error I get is quite more basic : Code:
-> FOAM FATAL ERROR: Unknown mixtureViscosityModel type transportModel Valid mixtureViscosityModels are : 3 ( BinghamPlastic plastic slurry ) Code:
{ const word modelType(viscosityProperties.lookup("transportModel")); Info<< "Selecting incompressible transport model " << modelType << endl; dictionaryConstructorTable::iterator cstrIter = dictionaryConstructorTablePtr_->find(modelType); if (cstrIter == dictionaryConstructorTablePtr_->end()) { FatalErrorInFunction << "Unknown viscosityModel type " << modelType << nl << nl << "Valid viscosityModels are : " << endl << dictionaryConstructorTablePtr_->sortedToc() << exit(FatalError); } Thank you very much for what you're doing, you're helping me a lot ! |
|
October 1, 2018, 10:02 |
|
#15 |
Senior Member
Michael Alletto
Join Date: Jun 2018
Location: Bremen
Posts: 616
Rep Power: 16 |
Just looking at the other viscosity models I would have just copied one and renamed it.
Afterward I would have modified the mu and read function (letting the input arguments as they are). By the way you don't need any strain rate functions. You can use the velocity U to calculate it. By compiling the new viscosity model it should by selectable at run time. |
|
October 1, 2018, 10:37 |
|
#16 |
New Member
Damien Leduc
Join Date: Sep 2018
Posts: 10
Rep Power: 8 |
Yes, I already tried that :
Code:
I also tried to make my solver without the strainRateFunction replacing “strainRate()” with “sqrt(2.0)*mag(symm(fvc::grad(U_)))” directly inside “Casson.C”. The solver also compiles but crashes when I try to run it. This time the problem came from LHS and RHS which didn’t have the same dimension. With my C++ level, it might indeed be more appriopriate just to modify the plastic solver just to fulfill my needs ! I'll try this again and hope I'll be able to find the solution about the LHS and RHS dimensions ! Thanks a lot michael ! |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Use of k-epsilon and k-omega Models | Jade M | Main CFD Forum | 40 | January 27, 2023 08:18 |
Wrong flow in ratating domain problem | Sanyo | CFX | 17 | August 15, 2015 07:20 |
problem with solving lagrange reaction cloud | Polli | OpenFOAM Running, Solving & CFD | 0 | April 30, 2014 08:53 |
Low Mixing time Problem | Mavier | CFX | 5 | April 29, 2013 01:00 |
modelling solids viscosity in eulerian multiphase model | derkaiser | FLUENT | 1 | December 5, 2011 04:42 |