CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Calculating Cp, gamma and others during runtime (https://www.cfd-online.com/Forums/openfoam-programming-development/227677-calculating-cp-gamma-others-during-runtime.html)

shock77 June 5, 2020 16:45

Calculating Cp, gamma and others during runtime
 
Hi,


I would like to calculate the specific heat capacity cp, specific heat ratio gamma and Ma number during the computation.


I have compiled a new solver based on rhoCentralFoam for this purpose.
In createFields.H I have added:


Code:

volScalarField cp
    (
    IOobject
        (
            "cp",
            runTime.timeName(),
            mesh,
            IOobject::READ_IF_PRESENT,
            IOobject::AUTO_WRITE
        ),
        thermo.Cp()
    );
   
volScalarField gamma
    (
    IOobject
        (
            "gamma",
            runTime.timeName(),
            mesh,
            IOobject::READ_IF_PRESENT,
            IOobject::AUTO_WRITE
        ),
        thermo.gamma()
    );
   
volScalarField Ma
    (
    IOobject
        (
            "Ma",
            runTime.timeName(),
            mesh,
            IOobject::READ_IF_PRESENT,
            IOobject::AUTO_WRITE
        ),
        mag(U)/sqrt(thermo.gamma()*thermo.p()/thermo.rho())
    );

I get the right values at time t = 0. Unfortunately they do not change over time, which is strange. Pressure, velocity and density do change, so the Mach Number should change aswell, but I cant see this. It works perfectly, if I use the functionObjects for the Mach Number.


I wanted to add also the total temperature and total pressure for compressible fluids to be calculated during runtime, but I would like to calculate them using the Mach Number, which is not calculated right at the moment.




Can anyone tell what I did wrong?






Kind regards,
shock77

shock77 June 5, 2020 17:28

Just found the solution to the problem.


For anyone with the same issue:


Like meantioned in this thread (https://www.cfd-online.com/Forums/op...roperties.html), it has to added, that those values are written during runtime. I have also changed IOobject::READ_IF_PRESENT to IOobject::NO_READ


So in the "while (runTime.run())" loop has to be added for example:


cp = thermo.Cp();

wangsen992 June 5, 2020 23:43

Must_read_if_modified
 
Hey,

Have you tried changing IOobject::READ_IF_PRESENT to IOobject::MUST_READ_IF_MODIFIED?

Since your coefficients are set to AUTO_WRITE, it means at end of each runTime iter those variables get written to the time directory.

While the proposed method above will achieve the same result as your method, it could be an alternative way to solve this issue (just to add to discussion). So in this way, you don't need to add
Code:

cp = thermo.Cp()
in the while loop since the backend objectRegistry should automatically update those values.

shock77 June 8, 2020 03:33

Hi,


yes, actually I have tried it before, but without success.
I think it couldnt be updated, because it didnt change, since cp and so on
werent calculated for further timesteps.






Kind regards,
shock77

jherb July 20, 2020 08:34

Have you tried the function object writeObjects? https://www.openfoam.com/documentati...teObjects.html


You could try either Cp or thermo.Cp and look if you get the fields written to the time folders (depending also on the writeInterval settings)

shock77 July 20, 2020 09:58

Hi,


I actually haven't tried that, since it worked like I have described it above.


But I think it is a good idea and when I have to do sth similar, I will try that too!


Kind regards,
shock77

jherb July 22, 2020 17:58

Today, OpenFOAM 8 has been released. It includes two improvements, which might also be helpful in this regard:
objectRegistry: Added support for optionally caching temporary objects
https://github.com/OpenFOAM/OpenFOAM...9dc79ea4ba08ea
objectRegistry: Corrected caching of registered temporary objects

https://github.com/OpenFOAM/OpenFOAM...53fc652ead5395


All times are GMT -4. The time now is 13:50.