CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (https://www.cfd-online.com/Forums/openfoam-solving/)
-   -   AUTO_WRITE and field updating (https://www.cfd-online.com/Forums/openfoam-solving/115869-auto_write-field-updating.html)

Pierre Le Fur April 8, 2013 15:34

AUTO_WRITE and field updating
 
Hello all,

I have been puzzled by the a simple question about a field defined say in createFields.H as:

Code:

volScalarField rho
      (
            IOobject
            (
                "rho",
                runTime.timeName(),
                mesh,
                IOobject::NO_READ,
                IOobject::AUTO_WRITE
            ),

            thermo->rho()
      );

Assuming that the thermo used is based on basicPsiThermo.
If in the solver, rho as defined here is not updated or touched in anyway by calling thermo->correct somewhere or by explicitly modifying it,
but is still used in solved equations i.e. momentum, pressure equations etc.... Will the field "rho" used in these solved equations be modified everytime time step due to its definition in createFields?
As far as I figure, when it is written in the time folder it will be evaluated and updated as thermo->rho(), which in this case might be "rho = P/RT",
In other words is there a difference between the values of the field "rho" used in the solver and the "rho" written down?

Any help would be appreciated.

Cheers

vbchris April 8, 2013 23:22

I'm not sure I completley understand but from my experience (somewhat limited). This code is a one-time creation of a volScalarField object. Thermo is used to point to a structure that has a member called rho (I assume this is used to calc rho of of the ideal gas law?). These values are used to populate the volScalarField rho. So... Without putting my foot in my mouth, I would say unless its modified in the time loop it shouldn't change.

makaveli_lcf April 9, 2013 04:03

Chris is totally right. With such a deffinition you create a copy of the data and that does not change unless you explicitly update it with something like "rho = ...". If you would like to connect variable rho with current thermo model data use a reference:

volScalarField & rho = thermo->rho();

or something like that.

Cheers,
Alex

Pierre Le Fur April 9, 2013 08:18

Thanks guys,

I did little tests last night to check the matter and indeed the field does not change and keeps the value set initially.

The question initially arose because some way or another, the density in the code I was working on was changing in mysterious ways... when, as I thought at the time, it wasn't supposed to. Eventually, I found the real culprit.... Me. I just can't see what's right in front of me.


All times are GMT -4. The time now is 14:31.