CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (http://www.cfd-online.com/Forums/openfoam-solving/)
-   -   read result values with pyFoam (http://www.cfd-online.com/Forums/openfoam-solving/129535-read-result-values-pyfoam.html)

ilpaso February 7, 2014 04:40

read result values with pyFoam
 
Hi Foamers!

I'm trying to read the average p values on a patch with python.
What is the right way?
Yes, I'm a newbie :D

I have done some tests with pyFoam.
I'm able to modify the boundary condictions and run the solver but nothing in order to read the result values and convert in a "python" format.

I don't know if reading the csv output file is an easy way to read the openFoam outputs in python.

This is the function I wrote in controlDict in order to do that.

Code:

pressureAverage
    {
        type patchAverage;
        fields (
            p
        );
        patches (
            velocity-inlet-6
        );
        expression "p";
        outputFileMode csv;
        verbose true;
    }

thank you
Regards

ilpaso February 11, 2014 05:32

Hi again,
Any ideas to help me?

Thank you

gschaider February 13, 2014 19:45

Quote:

Originally Posted by ilpaso (Post 473873)
Hi Foamers!

I'm trying to read the average p values on a patch with python.
What is the right way?
Yes, I'm a newbie :D

I have done some tests with pyFoam.
I'm able to modify the boundary condictions and run the solver but nothing in order to read the result values and convert in a "python" format.

I don't know if reading the csv output file is an easy way to read the openFoam outputs in python.

This is the function I wrote in controlDict in order to do that.

Code:

pressureAverage
    {
        type patchAverage;
        fields (
            p
        );
        patches (
            velocity-inlet-6
        );
        expression "p";
        outputFileMode csv;
        verbose true;
    }

thank you
Regards

The PyFoam-parser for OpenFOAM-files is quote flexible but the price for this is that it is not very good at reading the results of simulations (if they are bigger than a few thousand cells). It COULD be extended to properly read field data and convert it into numpy-arrays but in my opinion the use of this would be limited as information about the mesh is not available that way (don't know what you mean with "average" but the arithmetic average only makes sense if all faces are of the same size).

Usually I do such calculations in a functionObject. The way you're sketching it. If this is the patchAverage from swak4Foam? Then you already should have a csv file in the case (exact location depends on the version of swak you're using).

Or is your problem READING that CSV-file?

ilpaso February 14, 2014 07:34

Thank you gschaider for your reply.
I'm trying to couple a 0D circuit with a 3D vessel.
For the 0d simulation I use OpenModelica, OpenFoam for the 3d model and python is a good language for a "simulation manager" script.

I was looking for an easy and efficient way to read result values.
According to what you say read the csv file directly is the best way. There are some libraries for that. I'll try this way.

Patch average:
at the interface 0D / 3D I've to calculate the velocity and pressure and insert the values in the 0D system .
I don't know if the functionObject I've written in the previous post is correct. I'll try.

I appreciate any advice that you can give me.

gschaider February 14, 2014 12:22

Quote:

Originally Posted by ilpaso (Post 474938)
Thank you gschaider for your reply.
I'm trying to couple a 0D circuit with a 3D vessel.
For the 0d simulation I use OpenModelica, OpenFoam for the 3d model and python is a good language for a "simulation manager" script.

I was looking for an easy and efficient way to read result values.
According to what you say read the csv file directly is the best way. There are some libraries for that. I'll try this way.

Patch average:
at the interface 0D / 3D I've to calculate the velocity and pressure and insert the values in the 0D system .
I don't know if the functionObject I've written in the previous post is correct. I'll try.

I appreciate any advice that you can give me.

But the 1D-model will only use the OF-data as an input? Not feed back? Then reading the result files is IMHO the best way.

Concerning the FO: "expression" is not needed for patchAverage (all things in the simpleFunctionObjects-sublibrary work without parsers. They MAY have subclasses that do that)

ilpaso February 17, 2014 10:25

Foreach timestep the python script reads the OF results and inserts the values to the 0D model.
After a timestep the 0D model returns the initial conditions of the 3D model.
I think this flow is correct.

gschaider February 20, 2014 17:46

Quote:

Originally Posted by ilpaso (Post 475332)
Foreach timestep the python script reads the OF results and inserts the values to the 0D model.
After a timestep the 0D model returns the initial conditions of the 3D model.
I think this flow is correct.

"For each timestep" and "initial condition" somehow don't work for me (or are you talking about boundary conditions? That would be a feedback of the model)


All times are GMT -4. The time now is 06:20.