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

Calculating Cp, gamma and others during runtime

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 5, 2020, 16:45
Default Calculating Cp, gamma and others during runtime
  #1
Senior Member
 
Join Date: Dec 2019
Posts: 215
Rep Power: 7
shock77 is on a distinguished road
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 is offline   Reply With Quote

Old   June 5, 2020, 17:28
Default
  #2
Senior Member
 
Join Date: Dec 2019
Posts: 215
Rep Power: 7
shock77 is on a distinguished road
Just found the solution to the problem.


For anyone with the same issue:


Like meantioned in this thread (How to output other properties?), 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();
shock77 is offline   Reply With Quote

Old   June 5, 2020, 23:43
Default Must_read_if_modified
  #3
New Member
 
Sen Wang
Join Date: Jul 2018
Location: Singapore / Notre Dame, U.S.
Posts: 19
Blog Entries: 1
Rep Power: 7
wangsen992 is on a distinguished road
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.
wangsen992 is offline   Reply With Quote

Old   June 8, 2020, 03:33
Default
  #4
Senior Member
 
Join Date: Dec 2019
Posts: 215
Rep Power: 7
shock77 is on a distinguished road
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
shock77 is offline   Reply With Quote

Old   July 20, 2020, 08:34
Default
  #5
Senior Member
 
Joachim Herb
Join Date: Sep 2010
Posts: 650
Rep Power: 21
jherb is on a distinguished road
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)
jherb is offline   Reply With Quote

Old   July 20, 2020, 09:58
Default
  #6
Senior Member
 
Join Date: Dec 2019
Posts: 215
Rep Power: 7
shock77 is on a distinguished road
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
shock77 is offline   Reply With Quote

Old   July 22, 2020, 17:58
Default
  #7
Senior Member
 
Joachim Herb
Join Date: Sep 2010
Posts: 650
Rep Power: 21
jherb is on a distinguished road
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
jherb 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



All times are GMT -4. The time now is 08:33.