|
[Sponsors] |
May 8, 2013, 09:59 |
Get access to temperature in Openfoam
|
#1 |
Senior Member
Join Date: Nov 2012
Posts: 171
Rep Power: 14 |
Hi All,
In rhoPimpleFoam, the total enthalpy is solved and based on that the temperature is updated. In creteFields, the enthalpy is defined as autoPtr<basicPsiThermo> pThermo ( basicPsiThermo::New(mesh) ); basicPsiThermo& thermo = pThermo(); volScalarField& p = thermo.p(); volScalarField& h = thermo.h(); I checked the enthalpy function h() in basicThermo.C and found the following: Foam::volScalarField& Foam::basicThermo::h() { notImplemented("basicThermo::h()"); return const_cast<volScalarField&>(volScalarField::null() ); } There are other three enthalpy function definitions for h(), but the above one should be for the case where the enthalpy is solved as the governing equation. I checked this because for my own work, I would like to update the temperature not through openfoam's enthalpy equation but through my own model (not solve the energy equations in Openfoam). So should I add the lines for T() as follows in basicThermo.C? Foam::volScalarField& Foam::basicThermo::T() { notImplemented("basicThermo::T()"); return const_cast<volScalarField&>(volScalarField::null() ); } Actually I also find that some other declare the temperature as follows (): Info<< "Reading field T\n" <<endl; volScalarField T ( IOobject ( "T", runTime.timeName(), mesh, IOobject::MUST_READ, IOobject::AUTO_WRITE ), mesh ); Which one is correct for temperature update? Does anybody know something about this? Thanks. |
|
May 9, 2013, 01:21 |
|
#2 |
Senior Member
Adhiraj
Join Date: Sep 2010
Location: Karnataka, India
Posts: 187
Rep Power: 16 |
Is this what you want to do?
http://openfoamwiki.net/index.php/Ho...ure_to_icoFoam This is when you want to add another scalar to solve. If you want to access the temperature from the thermo object and modify it, that needs a bit of more work. |
|
May 9, 2013, 06:32 |
|
#3 | |
Senior Member
Join Date: Nov 2012
Posts: 171
Rep Power: 14 |
Thanks. Not the link you mentioned. I am trying to do the latter. The temperature in the link will not affect the thermodynamic models because it is for the incompressible flows. So although it is updated, it will not affect the viscosity.
Thank you again! Quote:
|
||
May 9, 2013, 07:25 |
|
#4 |
Senior Member
Adhiraj
Join Date: Sep 2010
Location: Karnataka, India
Posts: 187
Rep Power: 16 |
Yes, you are right.
To modify temperature from the top-level solver you need to access the variable "T_" in basicThermo. You can write a function (say Tmodifiable) that returns nonconstant access to T_. Code:
volScalarField& T=thermo.Tmodifiable(); |
|
May 9, 2013, 07:39 |
|
#5 | |
Senior Member
Join Date: Nov 2012
Posts: 171
Rep Power: 14 |
Yes, I agree with you. As you know, in rhoPimpleFoam, the total enthalpy equation is solved, it corresponds to the following function:
Foam::volScalarField& Foam::basicThermo::h() { notImplemented("basicThermo::h()"); return const_cast<volScalarField&>(volScalarField::null() ); } But I do not know what is meaning of the two lines in this function. Can I similarly write a function for temperature as follows? Foam::volScalarField& Foam::basicThermo::T() { notImplemented("basicThermo::T()"); return const_cast<volScalarField&>(volScalarField::null() ); } Thank you very much! best regards, H Quote:
|
||
May 9, 2013, 07:49 |
|
#6 |
Senior Member
Adhiraj
Join Date: Sep 2010
Location: Karnataka, India
Posts: 187
Rep Power: 16 |
There is a function T() in basicThermo.
Code:
const Foam::volScalarField& Foam::basicThermo::T() const { return T_; } Code:
Foam::volScalarField& Foam::basicThermo::TModifiable() const { return T_; } In your createFields.H you can use Code:
volScalarField& T=thermo.TModifiable(); |
|
May 9, 2013, 09:49 |
|
#7 | |
Senior Member
Join Date: Nov 2012
Posts: 171
Rep Power: 14 |
Thank you very much. In the following:
Foam::volScalarField& Foam::basicThermo::TModifiable() const { return T_; } Why should the const should be there? if it is there, that means this function cannot change the values of temperature. but actually, when the temperature is updated at each time step, the T_ should change simutaneously. Is this understanding correct? I am not proficient in C++. Thanks. Quote:
|
||
May 9, 2013, 11:55 |
|
#8 | |
Senior Member
Join Date: Nov 2012
Posts: 171
Rep Power: 14 |
Hi Adhiraj,
Thank you very much for your reply. If I make the modifications just mentioned by you, should I just compile it in the folder src/thermophysicalModels/basic (use wmake)? what else should be done to make this modification be active? Thank you so much. Quote:
|
||
May 11, 2013, 11:58 |
|
#9 |
Senior Member
HECKMANN Frédéric
Join Date: Jul 2010
Posts: 249
Rep Power: 17 |
Your topic is really interesting and I actually asked the same thing in another topic: http://www.cfd-online.com/Forums/ope...tml#post426707
Did you try the introduction of a new function ? |
|
May 11, 2013, 12:05 |
|
#10 | |
Senior Member
Join Date: Nov 2012
Posts: 171
Rep Power: 14 |
Hi
I am trying these days and I think the method mentioned in the above thread can work. Thanks . Quote:
|
||
May 13, 2013, 04:51 |
|
#11 |
Senior Member
HECKMANN Frédéric
Join Date: Jul 2010
Posts: 249
Rep Power: 17 |
As told in the other topic, I'm getting close to the solution BUT I HAVE A BUG WITH THE THERMO MODEL.
Here is the procedure I used: 1) open a text editor in admin by writing in the terminal: "sudo gedit" 2) with this text editor, open: "basicThermo.C" located in /opt/openfoam220/src/thermophysicalModels/basic/basicThermo 3) Add the following line in the Member Functions (I put it at line 396 after the "basicThermo::T()" ): Code:
// Add this //- Temperature [K] // Non-const access allowed Foam::volScalarField& Foam::basicThermo::T() { return T_; } 5) Add the following line after the comment "Fields derived from thermodynamic state variables" (I put it at line 316 after the other Temperature member ): Code:
// Add this //- Temperature [K] // Non-const access allowed for transport equations virtual volScalarField& T(); 7) Go to /opt/openfoam220/src/thermophysicalModels and open a terminal 8) With the terminal located in this folder, we now want to get the full root access. To do so, write: "sudo -s". After typing your password, you will see that the command line will start with "root". 9) We need to recompile the thermo model of openfoam. To do so, simply write "./Allwmake". This step might take few minutes depending of your system (for me with virtualization, it took about 1 or 2 minutes). But I think there is a problem with the new compilation because even a simple rhoSimplecFoam doesn't work anymore. Last edited by fredo490; May 13, 2013 at 05:35. |
|
May 13, 2013, 05:04 |
|
#12 | |
Senior Member
Join Date: Nov 2012
Posts: 171
Rep Power: 14 |
Hi,
Thank you very much. Since the temperature is updated by T, not from enthalpy. So should I also comment the calculating temperature from enthalpy? Quote:
|
||
May 13, 2013, 05:17 |
|
#13 |
Senior Member
HECKMANN Frédéric
Join Date: Jul 2010
Posts: 249
Rep Power: 17 |
Just be careful, I have updated my post because I encounter a bug with the thermo model now...
I'm actually running my test on a virtual machine so I don't damage my openfoam installation. I tried to run a tutorial case to check and a bug occurs. So my solution is NOT valid yet |
|
May 13, 2013, 05:24 |
|
#14 |
Senior Member
HECKMANN Frédéric
Join Date: Jul 2010
Posts: 249
Rep Power: 17 |
I have made some test and it seems that the newly compiled thermo model has a problem.
I ran a simpleFoam tutorial (pitzDaily) = OK I ran a rhoSimplecFoam tutorial (squareBend) = Crash Here is the log: Code:
Create mesh for time = 0 SIMPLE: convergence criteria field p tolerance 0.001 field U tolerance 0.0001 field e tolerance 0.001 field "(k|epsilon|omega)" tolerance 0.001 Reading thermophysical properties Selecting thermodynamics package { type hePsiThermo; mixture pureMixture; transport sutherland; thermo hConst; equationOfState perfectGas; specie specie; energy sensibleInternalEnergy; } #0 Foam::error::printStack(Foam::Ostream&) at ??:? #1 Foam::sigSegv::sigHandler(int) at ??:? #2 in "/lib/x86_64-linux-gnu/libc.so.6" #3 Foam::PtrList<Foam::fvPatchField<double> >::operator[](int) const at ??:? #4 Foam::heThermo<Foam::psiThermo, Foam::pureMixture<Foam::sutherlandTransport<Foam::species::thermo<Foam::hConstThermo<Foam::perfectGas<Foam::specie> >, Foam::sensibleInternalEnergy> > > >::alphaEff(Foam::Field<double> const&, int) const at ??:? #5 at ??:? #6 __libc_start_main in "/lib/x86_64-linux-gnu/libc.so.6" #7 at ??:? Segmentation fault (core dumped) |
|
May 13, 2013, 05:34 |
|
#15 |
Senior Member
HECKMANN Frédéric
Join Date: Jul 2010
Posts: 249
Rep Power: 17 |
It is really strange... When I comment the code I've wrote, openFoam runs smoothly again. If I put the code, it crashes all the thermo model.
I will work to find why. |
|
May 13, 2013, 10:53 |
|
#16 |
Senior Member
Join Date: Nov 2012
Posts: 171
Rep Power: 14 |
Dear Fredo,
Thank you. When does it crash? when reading the thermodynamic model or start to solve the momentum equations? |
|
May 13, 2013, 12:30 |
|
#17 |
Senior Member
HECKMANN Frédéric
Join Date: Jul 2010
Posts: 249
Rep Power: 17 |
If I put any code (even a stupid function) into the basic thermo, all solvers encounter a bug when they start solving the momentum equation. I've tried with a custom solver, it is really the first momentum equation that crashes the solver. The problem doesn't seem to come from my compiler because if I comment my code, all the solvers work again.
I also had another very strange thing with one of my custom solver. I get a non matching dimension between the left and right hand side of the equation instead of the momentum bug. My knowledge in C++ is really too weak |
|
May 13, 2013, 12:34 |
|
#18 | |
Senior Member
Join Date: Nov 2012
Posts: 171
Rep Power: 14 |
If I put any code (even a stupid function) into the basic thermo, all solvers encounter a bug when they start solving the momentum equation.
The same symptom as my case. I am working on it..... also crash when the code move into the momentum equation. Pray to CFD god first... Quote:
|
||
May 14, 2013, 05:56 |
|
#19 |
Senior Member
HECKMANN Frédéric
Join Date: Jul 2010
Posts: 249
Rep Power: 17 |
Something I really don't understand is that:
basicThermo.C has the following members: Code:
// Non Constant access to p Foam::volScalarField& Foam::basicThermo::p() { return p_; } // Constant access to p const Foam::volScalarField& Foam::basicThermo::p() const { return p_; } // Constant access to T const Foam::volScalarField& Foam::basicThermo::T() const { return T_; } Code:
// Access to thermodynamic state variables //- Pressure [Pa] // Non-const access allowed for transport equations virtual volScalarField& p(); //- Pressure [Pa] virtual const volScalarField& p() const; //- Temperature [K] virtual const volScalarField& T() const; |
|
May 14, 2013, 07:27 |
|
#20 | |
Senior Member
Join Date: Nov 2012
Posts: 171
Rep Power: 14 |
In basicThermo.C and basicthermo.H, the non-constant access function for enthalpy is as follows:
Foam::volScalarFields& Foam::basicThermo::h() { notimplemented("basicThermo::h()") return const_cast<volscalarField&>(volScalarField::null() ) } is this the function called by the following line in createField.H? volScalarField& h=thermo.h() Quote:
|
||
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Problem with zeroGradient wall BC for temperature - Total temperature loss | cboss | OpenFOAM | 12 | October 1, 2018 07:36 |
Implementation of maxwell slip velocity and Temperature jump with openfoam | yassepid | OpenFOAM | 2 | June 28, 2016 08:05 |
coldEngineFoam (OpenFoam 2.1.x), constant Temperature during adiabatic compression | novakm | OpenFOAM Verification & Validation | 1 | February 25, 2013 13:25 |
Inlet won't apply UDF and has temperature at 0K! | tccruise | Fluent UDF and Scheme Programming | 2 | September 14, 2012 07:08 |
Cross-compiling OpenFOAM 1.7.0 on Linux for Windows 32 and 64bits with Mingw-w64 | wyldckat | OpenFOAM Announcements from Other Sources | 3 | September 8, 2010 07:25 |