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/)
-   -   How to get density-field for compressible flow? (https://www.cfd-online.com/Forums/openfoam-solving/75049-how-get-density-field-compressible-flow.html)

bgoeppner April 15, 2010 05:59

How to get density-field for compressible flow?
 
Hi there,

I was wondering how to get the density-field if using some compressible solver?

Beside rhoCentralFoam I think all other solvers define rho as a NOWRITE-object (like basicThermo does with psi, too). As density and compressiblity are a fundamental thing of compressible flow - if not it would be incompressible, right? - there should be a way to visualize those fields in postprocessing, shouldn't it?

Or do I have to calculate the Mach-Number, out of that the compressiblity, and according to this finally the density? Sounds complicated to me.. :confused:

Is it advisable as an easy solution to create a new solver as a copy of the existing one, say sonicFoam, with rho defined as AUTOWRITE-object?

Ben

gschaider April 15, 2010 08:32

Quote:

Originally Posted by bgoeppner (Post 254736)
Hi there,

I was wondering how to get the density-field if using some compressible solver?

Beside rhoCentralFoam I think all other solvers define rho as a NOWRITE-object (like basicThermo does with psi, too). As density and compressiblity are a fundamental thing of compressible flow - if not it would be incompressible, right? - there should be a way to visualize those fields in postprocessing, shouldn't it?

Or do I have to calculate the Mach-Number, out of that the compressiblity, and according to this finally the density? Sounds complicated to me.. :confused:

Is it advisable as an easy solution to create a new solver as a copy of the existing one, say sonicFoam, with rho defined as AUTOWRITE-object?

Ben

The rho-Field is there. It's just not being written. I think I saw somewhere in recent commits of 1.6.x a functionObject that lets you write such fields. Alternatively you can try writeFieldsAdditional from http://openfoamwiki.net/index.php/Co...unctionObjects

bgoeppner April 15, 2010 10:59

Hi Bernhard,

thanks for your quick reply. That sounds exactly what I'm looking for. Unfortunately I'm not very used to functionObjects in OpenFOAM right now and the official documention does not offer a lot of instructions about that, too... There's just a general reference to the tutorials-folder... ;-)

I will also check out your tools from the link you posted and have a look at the README-file, as well as I'm currently trying to understand the source-code.

Anyway, if you have any suggestions on where to get more information regarding this topic or if you could give some examples how to use those objects, that would be great!

Edit: I had a look at the source guide and some other resources... Am I right that the following steps would solve my problem?

1) Add some functions to the controlDict:
Code:

functions
(
  rho
  {
    type    writeRegisteredObject;
    functionObjectLibs  ("libfunctionObjects.so");
    objectNames
    (
      rho
    );
  }
)

2) if postprocessing then: Call execFlowFunctionObjects
or if having added the functions-section to control-dict before running the case, everything should be fine anyway

I will try that as soon as I'm back at my simulation-computer...

gschaider April 15, 2010 12:48

Quote:

Originally Posted by bgoeppner (Post 254802)
thanks for your quick reply. That sounds exactly what I'm looking for. Unfortunately I'm not very used to functionObjects in OpenFOAM right now and the official documention does not offer a lot of instructions about that, too... There's just a general reference to the tutorials-folder... ;-)

I will also check out your tools from the link you posted and have a look at the README-file, as well as I'm currently trying to understand the source-code.

Anyway, if you have any suggestions on where to get more information regarding this topic or if you could give some examples how to use those objects, that would be great!

You're on the right track. There is not much more material that I know of.

bgoeppner April 16, 2010 06:54

Problem solved
 
Just in case someone's having the same problem and is using the search-function, here's the solution:

Add the following to your controlDict:
Code:

functions
{
  rhofunc
  {
      type                writeRegisteredObject;
      functionObjectLibs  ("libIOFunctionObjects.so");
/*      outputControl        outputTime;*/
      outputControl        timeStep;
      outputInterval      1;
      objectNames
      (
        "rho"
        "psi"
      );
  }
}

If you insert this before running your case, you should have
Code:

outputControl    outputTime
enabled, otherwise (if you run the case without this section) you should have
Code:

outputControl    timeStep
enabled. Then just run
Code:

execFlowFunctionObjects
from your case-directory.

Have fun!

immortality September 9, 2013 07:37

Hi
for notice:
rhoCentralFoam now (in 2.2.0 version) writes "rho" field itself but doesn't write "phi" field.

Endel September 29, 2016 11:04

OpenFOAM 4.0: postProcess "rho" field after sonicFoam simulation
 
Hi everyone,

I am using OpenFOAM 4.0 and it seems, that the above solution doesn't work like that anymore. When I follow the work flow above and try to execute
Code:

execFlowFunctionObjects
I get an error message, saying: "execFlowFunctionObjects
execFlowFunctionObjects has been superceded by the '-postProcess' solver command-line option"

I can't figure out a way to calculate the "rho" field after having run the sonicFoam solver. I tried using the postProcess utility but only seem to get more error messages...

I would be very glad about any help!

Thank you very much

Endel January 18, 2017 10:14

Meanwhile I figured out, that the writeRegisteredObject type was superseded by the writeObjects type. Reading one error message after another, I edited the function given above to the following:

Code:

functions
{
  rhofunc
  {
      type                writeObjects;
      libs            ("libutilityFunctionObjects.so");
      writeControl        timeStep;
      writeInterval      1;
      objects
      ("rho");
  }
}

Executing this with the command

Code:

sonicFoam -postProcess
from my case directory, the utility finally wrote a rho field, which I could display in paraview.

However, the rho field is much to small, on the 10⁻11 level and doesn't show physical behavior...

Does anyone know, whether the function I implemented is still wrong and leads to the faulty results?

eemdee March 28, 2017 11:03

Hey Endel, I'm trying to do pretty much the exact same thing (getting density fields from sonicFoam) did you ever figure out how to get the solver to get the correct results?

Tobi March 29, 2017 10:33

Hi all,

I have no idea about the postProcess tool but if you want to have the density field you can do the following (not the optimal way):

  • Go to your sonicFoam source files
  • edit createFields.H
  • Change the volScalarField rho as follows:
Code:

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

    ),
    thermo.rho()
);

  • After that re-compile wmake
  • Done

Doing that, the solver will write the density file. I checked it with the shockTube tutorial and the density seems to be okay (0.125 - 0.998). But I have no idea in which range the density can go in shock waves.

eemdee March 29, 2017 14:09

This worked for me, though I have yet to confirm whether it is physical or not. One question though, why do you say that this isn't the optimal way?

Thanks a lot for your help!

Tobi March 29, 2017 14:13

Hi,

I said this might be not the optimal way because if you could do it in a post-processing way I would prefer this instead of recompiling. Maybe there are smarter way that I do not know. If the way of Endel would work, it would be smarter, right? And in fact, I am not an expert. Well, if it works for you, I am happy. Good luck and the density field you write is actually the one FOAM uses.

Aadithya April 26, 2017 07:51

Adding different density values
 
Hlo friends...

I am using interFoam solver is it possible to add different density values in the same case file by using setFields utility.????????

gschaider April 26, 2017 19:23

Quote:

Originally Posted by Aadithya (Post 646668)
Hlo friends...

I am using interFoam solver is it possible to add different density values in the same case file by using setFields utility.????????

No. In the classic interFoam the rhos of the two phases are constant values and the overall rho is calculated according to the alpha-field

pooyanni June 10, 2019 18:19

Using inline -postProcess tool
 
Quote:

Originally Posted by Endel (Post 633755)
Meanwhile I figured out, that the writeRegisteredObject type was superseded by the writeObjects type. Reading one error message after another, I edited the function given above to the following:

Code:

functions
{
  rhofunc
  {
      type                writeObjects;
      libs            ("libutilityFunctionObjects.so");
      writeControl        timeStep;
      writeInterval      1;
      objects
      ("rho");
  }
}

Executing this with the command

Code:

sonicFoam -postProcess
from my case directory, the utility finally wrote a rho field, which I could display in paraview.

However, the rho field is much to small, on the 10⁻11 level and doesn't show physical behavior...

Does anyone know, whether the function I implemented is still wrong and leads to the faulty results?


I think you can simply write the following line after the simulation is done and it should write the rho field for all the simulated times:

Code:

sonicFoam -postProcess -func 'writeObjects(rho)'
Best


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