![]() |
Get access to temperature in Openfoam
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. |
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. |
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:
|
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(); |
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:
|
There is a function T() in basicThermo.
Code:
const Foam::volScalarField& Foam::basicThermo::T() const Code:
Foam::volScalarField& Foam::basicThermo::TModifiable() const In your createFields.H you can use Code:
volScalarField& T=thermo.TModifiable(); |
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:
|
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:
|
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 ? |
Hi
I am trying these days and I think the method mentioned in the above thread can work. Thanks . Quote:
|
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 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 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. |
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:
|
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 |
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 |
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. |
Dear Fredo,
Thank you. When does it crash? when reading the thermodynamic model or start to solve the momentum equations? Quote:
|
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 :( |
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:
|
Something I really don't understand is that:
basicThermo.C has the following members: Code:
// Non Constant access to p Code:
// Access to thermodynamic state variables |
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:
|
All times are GMT -4. The time now is 07:55. |