CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Change Temperature boundary by a solver (rhoPimpleFoam) (http://www.cfd-online.com/Forums/openfoam-programming-development/117557-change-temperature-boundary-solver-rhopimplefoam.html)

fredo490 May 10, 2013 11:47

Change Temperature boundary by a solver (rhoPimpleFoam)
 
Hello everybody,
I would like to link the temperature of a boundary (a wall patch) with the solver solution. In other word, the solver has be able to change the value of the patch temperature.

In rhoPimpleFoam, the temperature field is created by a sub function and not by the createfield.h. Therefor, I cannot access/change directly the temperature field in the solver.

I can read the temperature field by using:
Code:

thermo.T()
Or by using a lookupObject:
Code:

const volScalarField& T = db().lookupObject<volScalarField>("T");
However, with those two methods, I cannot change the value of the temperature.

My dream is to get something like:
Code:

label patchWall = mesh.boundaryMesh().findPatchID("wall"); //patchID = id of the patch wall
const fvPatch& cPatch = mesh.boundary()[patchWall];

    forAll(cPatch, facei) //facei = id of the face
    {
    T.boundaryField()[patchWall][facei] = .......... ;
    };

Does anybody know a smart way to solve this problem ?

fredo490 May 11, 2013 10:57

I've just found another topic talking about my problem: http://www.cfd-online.com/Forums/ope...-openfoam.html

But if anybody has a solution, I'm still open.

fredo490 May 13, 2013 03:51

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.

Chris Lucas May 13, 2013 07:09

Hi,

an easy solution might be.

Define the temperature field in basicThermo as mutable (so that can change the field in a constant function)

Add a function that changes the values in the temperature field in the file called by the solver when the thermo class is constructed (basicPsiThermo in OF 2.1)

Regards,
Christian

hz283 May 13, 2013 10:43

I also used that method, but I had the similar problem:

#0 Foam::error::printStack(Foam::Ostream&) in "/home/hz283/OpenFOAM/OpenFOAM-2.1.1/platforms/linux64GccDPOpt/lib/libOpenFOAM.so"
#1 Foam::sigSegv::sigHandler(int) in "/home/hz283/OpenFOAM/OpenFOAM-2.1.1/platforms/linux64GccDPOpt/lib/libOpenFOAM.so"
#2 in "/lib64/libc.so.6"
#3 Foam::hPsiThermo<Foam::pureMixture<Foam::sutherlan dTransport<Foam::specieThermo<Foam::hConstThermo<F oam::perfectGas> > > > >::Cv() const in "/home/hz283/OpenFOAM/OpenFOAM-2.1.1/platforms/linux64GccDPOpt/lib/libbasicThermophysicalModels.so"
#4 Foam::compressible::LESModel::muEff() const in "/home/hz283/OpenFOAM/OpenFOAM-2.1.1/platforms/linux64GccDPOpt/lib/libcompressibleLESModels.so"
#5 Foam::compressible::LESModels::GenEddyVisc::divDev RhoBeff(Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh>&) const in "/home/hz283/OpenFOAM/OpenFOAM-2.1.1/platforms/linux64GccDPOpt/lib/libcompressibleLESModels.so"
#6 Foam::compressible::LESModel::divDevRhoReff(Foam:: GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh>&) const in "/home/hz283/OpenFOAM/OpenFOAM-2.1.1/platforms/linux64GccDPOpt/lib/libcompressibleLESModels.so"
#7
in "/home/hz283/OpenFOAM/hz283-2.1.1/platforms/linux64GccDPOpt/bin/cmcSgasFoam-0DCMC"
#8 __libc_start_main in "/lib64/libc.so.6"
#9
at /usr/src/packages/BUILD/glibc-2.11.3/csu/../sysdeps/x86_64/elf/start.S:116
Segmentation fault

In my stuff, I calculate the density and temperature from my own model. That means I did not use rho=P_*psi() to update the density in Openfoam. Besides, I use the following thermoynamic models:

thermoType hPsiThermo<pureMixture<sutherlandTransport<specieT hermo<hConstThermo<perfectGas>>>>>;

In hPsiThermo.C, I comment the line 48:

TCells[celli] = mixture_.TH(hCells[celli], TCells[celli]);

but I have the same problem as I mentioned in the beginning. I am working on it and keep you posted. Thanks.

Quote:

Originally Posted by fredo490 (Post 427102)
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.


fredo490 May 13, 2013 11:33

Quote:

Originally Posted by Chris Lucas (Post 427149)
Hi,

an easy solution might be.

Define the temperature field in basicThermo as mutable (so that can change the field in a constant function)

Add a function that changes the values in the temperature field in the file called by the solver when the thermo class is constructed (basicPsiThermo in OF 2.1)

Regards,
Christian

I didn't know this C++ function ! It looks really nice. I will try it tomorrow.
Thx

Chris Lucas May 14, 2013 03:33

Hi,

another possibility is to use a second temperature field (let’s say “realTemperature”). This field is defined in hPsiThermo similar to the enthalpy (sorry, I'm still using an older OF Version). However, the new field must read the file (boundary's) from the 0 folder of the case (unlike the enthalpy field). Then you need to change the calculate function in hPsiThermo . Additionally, a dummy function that later returns the “realTemperature” must be defined in basicPsiThermo (so that the solver can access the new temperature field). The function must be redefined (now correctly) in hPsiThermo so that it really returns “realTemperature”.

Then you must define a non-constant pointer “realTemperature” to in the solver (like the pointer for enthalpy). You can change the temperature field using this pointer (as done with enthalpy field).

The problem (or unpleasant side effect) is that you need to include a dummy temperature file "T" in your case folder

Regards,
Christian

fredo490 May 15, 2013 11:11

Thx Chris for your advices ! But the solution was much simplier than a complicated C++ function. The problem was simply that we had to recompile all OpenFoam and not only the thermo model.

So after all this, here is the final procedure (tested and approved !):
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/ 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 all OpenFoam. To do so, simply write "./Allwmake". This step might take few minutes depending of your system (for me it took about 45 minutes).


All times are GMT -4. The time now is 07:55.