CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Programming & Development (
-   -   How to read and change temperature results at each time step in buoyantPimpleFoam? (

kriztof July 28, 2011 07:14

How to read and change temperature results at each time step in buoyantPimpleFoam?
Dear all,

I am an inexperienced user of OpenFoam and C++. I am using buoyantPimpleFoam solver to simulate ventilation in a small building.

My aim is to change temperature of wall patches at each time step. The temperature of the internal surfaces of walls will be calculated by a small piece of C++ code implementing the finite difference method. I cannot use timeVaryingFixedValue boundary condition, because the wall temperature at a given time step will depend also on the temperature of air near the wall. It must be calculated each time.

At first, I wanted to create my own boundary condition to do this task, but the OpenFOAM's code intimidated me a little bit... Modifying the solver should be the easier way, so now I am trying to read the temperature at each time step directly in the solver and then modify it due to my finite difference calculations.

However, I am able to read and change velocity U, pressure p and enthalpy h at each time step, but the temperature cannot be accessed directly.

Should I change it indirectly by changing the enthalpy or there is a simpler solution?

Can anyone give me a clue, how to start?
I will appreciate any help.


kriztof July 30, 2011 10:02

I understand - let me specify my question :)

At each time step I want to change the temperature of a given boundary patch - let's say "myPatch".
I would like to do this directly in the solver buoyantPimpleFoam.

I figured out, that the probable procedure should look something like this:
1) find out the ID of "myPatch", what can be done by including the following code inside the solver code:


        label myPatch_ID = mesh.boundaryMesh().findPatchID("myPatch");
2) calculate the patch enthalpy for a desired temperature "myT" of type <double>:


    // create a temperature scalarField for myPatch, which will be used to calculate the enthalpy
        scalarField T_myPatch = T.boundaryField()[myPatch];
        forAll(myPatch, i)
            T_myPatch[i] = myT; // whole patch will have the temperature "myT"

    // calculate the enthalpy corresponding to the temperature "myT"
        scalarField h_new = thermo.h(myPatch, myPatch_ID);

3) change the enthalpy h on the patch "myPatch":


        forAll(h.boundaryField()[myPatch_ID], i)
            h.boundaryField()[myPatch_ID][i] = h_new[i];

The problem is, that the temperature boundary condition type of myPatch is set to "fixedValue", what results in constant temperatures of myPatch even though I change its enthalpy at each time step.

How to force the solver to recalculate the temperature of this patch at each time step?
Do I have to modify the BC?

kriztof October 11, 2011 02:55

Ok, I have finally worked it out. The solution was easy, so I am sorry for cluttering up the forum.
The patch temperature can be changed directly by usint const_cast:


fvPatchScalarField& Tnew = const_cast<fvPatchScalarField&> (thermo.T().boundaryField()[patchi]]);   
forAll(Tnew, facei)
      Tnew[facei] = your_new_temperature;

Maybe it will be useful for someone.

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