CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Community Contributions

[PyFoam] read result values with pyFoam

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 7, 2014, 03:40
Default read result values with pyFoam
  #1
Member
 
Davide Pasini
Join Date: Mar 2009
Posts: 34
Rep Power: 17
ilpaso is on a distinguished road
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

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 is offline   Reply With Quote

Old   February 11, 2014, 04:32
Default
  #2
Member
 
Davide Pasini
Join Date: Mar 2009
Posts: 34
Rep Power: 17
ilpaso is on a distinguished road
Hi again,
Any ideas to help me?

Thank you
ilpaso is offline   Reply With Quote

Old   February 13, 2014, 18:45
Default
  #3
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by ilpaso View Post
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

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?
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request
gschaider is offline   Reply With Quote

Old   February 14, 2014, 06:34
Default
  #4
Member
 
Davide Pasini
Join Date: Mar 2009
Posts: 34
Rep Power: 17
ilpaso is on a distinguished road
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.
ilpaso is offline   Reply With Quote

Old   February 14, 2014, 11:22
Default
  #5
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by ilpaso View Post
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)
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request
gschaider is offline   Reply With Quote

Old   February 17, 2014, 09:25
Default
  #6
Member
 
Davide Pasini
Join Date: Mar 2009
Posts: 34
Rep Power: 17
ilpaso is on a distinguished road
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.
ilpaso is offline   Reply With Quote

Old   February 20, 2014, 16:46
Default
  #7
Assistant Moderator
 
Bernhard Gschaider
Join Date: Mar 2009
Posts: 4,225
Rep Power: 51
gschaider will become famous soon enoughgschaider will become famous soon enough
Quote:
Originally Posted by ilpaso View Post
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)
__________________
Note: I don't use "Friend"-feature on this forum out of principle. Ah. And by the way: I'm not on Facebook either. So don't be offended if I don't accept your invitation/friend request
gschaider 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


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to calculate mass flow rate on patches and summation of that during the run? immortality OpenFOAM Post-Processing 104 February 16, 2021 08:46
DEFINE_ADJUST: How open and read file values (.prof or .txt) into one boundary rayolau Fluent UDF and Scheme Programming 0 April 25, 2013 07:01
read a file .txt with nurecial values of time and acceleration sicfred Fluent UDF and Scheme Programming 0 November 21, 2011 07:02
Problem in running ICEM grid in Openfoam Tarak OpenFOAM 6 September 9, 2011 17:51
Read values from previous timesteps vmlxb6 CFX 9 April 22, 2011 18:56


All times are GMT -4. The time now is 23:53.