CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM

Get access to temperature in Openfoam

Register Blogs Community New Posts Updated Threads Search

Like Tree7Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 8, 2013, 09:59
Question Get access to temperature in Openfoam
  #1
Senior Member
 
Join Date: Nov 2012
Posts: 171
Rep Power: 14
hz283 is on a distinguished road
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.
Kummi likes this.
hz283 is offline   Reply With Quote

Old   May 9, 2013, 01:21
Default
  #2
Senior Member
 
Adhiraj
Join Date: Sep 2010
Location: Karnataka, India
Posts: 187
Rep Power: 16
adhiraj is on a distinguished road
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.
adhiraj is offline   Reply With Quote

Old   May 9, 2013, 06:32
Question
  #3
Senior Member
 
Join Date: Nov 2012
Posts: 171
Rep Power: 14
hz283 is on a distinguished road
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:
Originally Posted by adhiraj View Post
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.
hz283 is offline   Reply With Quote

Old   May 9, 2013, 07:25
Default
  #4
Senior Member
 
Adhiraj
Join Date: Sep 2010
Location: Karnataka, India
Posts: 187
Rep Power: 16
adhiraj is on a distinguished road
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();
Then use T in the equations.
mm.abdollahzadeh and Kummi like this.
adhiraj is offline   Reply With Quote

Old   May 9, 2013, 07:39
Question
  #5
Senior Member
 
Join Date: Nov 2012
Posts: 171
Rep Power: 14
hz283 is on a distinguished road
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:
Originally Posted by adhiraj View Post
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();
Then use T in the equations.
hz283 is offline   Reply With Quote

Old   May 9, 2013, 07:49
Default
  #6
Senior Member
 
Adhiraj
Join Date: Sep 2010
Location: Karnataka, India
Posts: 187
Rep Power: 16
adhiraj is on a distinguished road
There is a function T() in basicThermo.
Code:
const Foam::volScalarField& Foam::basicThermo::T() const
{
    return T_;
}
Define function similar to this,
Code:
Foam::volScalarField& Foam::basicThermo::TModifiable() const
{
    return T_;
}
This will return nonconstant access to the temperature variable.
In your createFields.H you can use
Code:
volScalarField& T=thermo.TModifiable();
Then simply use the variable T in your solver.
Kummi and Shadab like this.
adhiraj is offline   Reply With Quote

Old   May 9, 2013, 09:49
Question
  #7
Senior Member
 
Join Date: Nov 2012
Posts: 171
Rep Power: 14
hz283 is on a distinguished road
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:
Originally Posted by hz283 View Post
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
hz283 is offline   Reply With Quote

Old   May 9, 2013, 11:55
Default
  #8
Senior Member
 
Join Date: Nov 2012
Posts: 171
Rep Power: 14
hz283 is on a distinguished road
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:
Originally Posted by ;426325
There is a function T() in basicThermo.
Code:
const Foam::volScalarField& Foam::basicThermo::T() const
{
    return T_;
}
Define function similar to this,
Code:
Foam::volScalarField& Foam::basicThermo::TModifiable() const
{
    return T_;
}
This will return nonconstant access to the temperature variable.
In your createFields.H you can use
Code:
volScalarField& T=thermo.TModifiable();
Then simply use the variable T in your solver.
hz283 is offline   Reply With Quote

Old   May 11, 2013, 11:58
Default
  #9
Senior Member
 
HECKMANN Frédéric
Join Date: Jul 2010
Posts: 249
Rep Power: 17
fredo490 is on a distinguished road
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 ?
fredo490 is offline   Reply With Quote

Old   May 11, 2013, 12:05
Default
  #10
Senior Member
 
Join Date: Nov 2012
Posts: 171
Rep Power: 14
hz283 is on a distinguished road
Hi

I am trying these days and I think the method mentioned in the above thread can work. Thanks .

Quote:
Originally Posted by fredo490 View Post
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 ?
hz283 is offline   Reply With Quote

Old   May 13, 2013, 04:51
Default
  #11
Senior Member
 
HECKMANN Frédéric
Join Date: Jul 2010
Posts: 249
Rep Power: 17
fredo490 is on a distinguished road
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_;
            }
4) with this text editor (still admin), open: "basicThermo.H" located in /opt/openfoam220/src/thermophysicalModels/basic/basicThermo
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();
6) Save the two files (To check if it was saved: look at the top of the editor, if the star remains it means that you didn't have the admin / root access).
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.
fredo490 is offline   Reply With Quote

Old   May 13, 2013, 05:04
Default
  #12
Senior Member
 
Join Date: Nov 2012
Posts: 171
Rep Power: 14
hz283 is on a distinguished road
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:
Originally Posted by fredo490 View Post
I have tried some modification and I think I'm getting the solution. I've succeed to compile my custom solver and I will run a test case tonight.

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_;
            }
4) with this text editor (still admin), open: "basicThermo.H" located in /opt/openfoam220/src/thermophysicalModels/basic/basicThermo
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();
6) Save the two files (To check if it was saved: look at the top of the editor, if the star remains it means that you didn't have the admin / root access).
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).

You can now use your new thermo model !
hz283 is offline   Reply With Quote

Old   May 13, 2013, 05:17
Default
  #13
Senior Member
 
HECKMANN Frédéric
Join Date: Jul 2010
Posts: 249
Rep Power: 17
fredo490 is on a distinguished road
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
fredo490 is offline   Reply With Quote

Old   May 13, 2013, 05:24
Default
  #14
Senior Member
 
HECKMANN Frédéric
Join Date: Jul 2010
Posts: 249
Rep Power: 17
fredo490 is on a distinguished road
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)
I will run some extra test and keep you updated.
fredo490 is offline   Reply With Quote

Old   May 13, 2013, 05:34
Default
  #15
Senior Member
 
HECKMANN Frédéric
Join Date: Jul 2010
Posts: 249
Rep Power: 17
fredo490 is on a distinguished road
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.
fredo490 is offline   Reply With Quote

Old   May 13, 2013, 10:53
Default
  #16
Senior Member
 
Join Date: Nov 2012
Posts: 171
Rep Power: 14
hz283 is on a distinguished road
Dear Fredo,

Thank you. When does it crash? when reading the thermodynamic model or start to solve the momentum equations?



Quote:
Originally Posted by fredo490 View Post
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.
hz283 is offline   Reply With Quote

Old   May 13, 2013, 12:30
Default
  #17
Senior Member
 
HECKMANN Frédéric
Join Date: Jul 2010
Posts: 249
Rep Power: 17
fredo490 is on a distinguished road
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
fredo490 is offline   Reply With Quote

Old   May 13, 2013, 12:34
Default
  #18
Senior Member
 
Join Date: Nov 2012
Posts: 171
Rep Power: 14
hz283 is on a distinguished road
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:
Originally Posted by fredo490 View Post
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.

My knowledge in C++ is really too weak
hz283 is offline   Reply With Quote

Old   May 14, 2013, 05:56
Default
  #19
Senior Member
 
HECKMANN Frédéric
Join Date: Jul 2010
Posts: 249
Rep Power: 17
fredo490 is on a distinguished road
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_;
}
Then basicThermo.H has the following members:
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;
Therefor, why the #&{$ adding the same non constant member as p but with T doesn't work ?! If it works for p, why it doesn't work for T ?
fredo490 is offline   Reply With Quote

Old   May 14, 2013, 07:27
Question
  #20
Senior Member
 
Join Date: Nov 2012
Posts: 171
Rep Power: 14
hz283 is on a distinguished road
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:
Originally Posted by fredo490 View Post
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_;
}
Then basicThermo.H has the following members:
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;
Therefor, why the #&{$ adding the same non constant member as p but with T doesn't work ?! If it works for p, why it doesn't work for T ?
hz283 is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


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


All times are GMT -4. The time now is 03:38.