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

Write a script to modify the data in files?

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By clapointe
  • 1 Post By qi.yang@polimi.it

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 15, 2021, 11:42
Default Write a script to modify the data in files?
  #1
Senior Member
 
kimy
Join Date: Mar 2019
Location: https://t.me/pump_upp
Posts: 164
Rep Power: 7
qi.yang@polimi.it is on a distinguished road
Send a message via ICQ to qi.yang@polimi.it Send a message via AIM to qi.yang@polimi.it Send a message via Yahoo to qi.yang@polimi.it
Hi,

I wrote a script to arrange the files based on the data post-processed by openfoam automatically, as below. However, I cannot use the original data in the 'p' files. Instead, I have to subtract p by a value. Anyone has ideas to make this change? Thanks.
Code:
patchname='patch_ground'
newpatchname='top'
variableFoldername=$patchname
variablename='p'
variaWriteName='p'
cp -r postProcessing/toppressuredata/surface .

for d in ./surface/* 
do

mkdir -p ./boundaryData/$newpatchname/$d/
#Write the default headline contents into the files
echo 'FoamFile
{
    version     2.0;
    format      ascii;
    class       scalarAverageField;
    object      values;
}
// **********************************************************************//
0.0' > ./boundaryData/$newpatchname/$d/$variaWriteName

#copy values from /surface folder to /boundaryData folder
cat 	./$d/$variableFoldername/scalarField/$variablename >> ./boundaryData/$newpatchname/$d/$variaWriteName
#mv ./boundaryData/newpatchname/$d ./boundaryData/newpatchname
done


#Transfer the format of the corresponding 'points' file
echo 'FoamFile
{
    version 2.0;
    format  ascii;
    class   vectorField;
    object  points;
}
// ******************************************************************************************//
'  > ./boundaryData/$newpatchname/points
cat  ./$d/$variableFoldername/faceCentres >> ./boundaryData/$newpatchname/points

#Transfer the format of the corresponding 'faces' file
echo 'FoamFile
{
    version 2.0;
    format  ascii;
    class   faceList;
    object  faces;
}
// ******************************************************************************************//
' > ./boundaryData/$newpatchname/faces
cat  ./$d/$variableFoldername/faces >> ./boundaryData/$newpatchname/faces

mv boundaryData/top/surface/* boundaryData/top
qi.yang@polimi.it is offline   Reply With Quote

Old   September 15, 2021, 12:16
Default
  #2
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
If you are using an "incompressible" solver such as pimpleFoam or simpleFoam, the pressure is not the real pressure. This pressure field p is actually p' which is p' = p/rho. As the value of p' is not of interest for the numerical process (it does not matter if p' has negative values as we don't have any EOS) you commonly need to multiply your pressure value by the density and add a reference pressure such as the atmosphere one. You simply can see it by checking the pressure dimensions in the 0/p file.
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   September 15, 2021, 12:36
Default
  #3
Senior Member
 
kimy
Join Date: Mar 2019
Location: https://t.me/pump_upp
Posts: 164
Rep Power: 7
qi.yang@polimi.it is on a distinguished road
Send a message via ICQ to qi.yang@polimi.it Send a message via AIM to qi.yang@polimi.it Send a message via Yahoo to qi.yang@polimi.it
Quote:
Originally Posted by Tobi View Post
If you are using an "incompressible" solver such as pimpleFoam or simpleFoam, the pressure is not the real pressure. This pressure field p is actually p' which is p' = p/rho. As the value of p' is not of interest for the numerical process (it does not matter if p' has negative values as we don't have any EOS) you commonly need to multiply your pressure value by the density and add a reference pressure such as the atmosphere one. You simply can see it by checking the pressure dimensions in the 0/p file.
Hi Tobi,

Thanks for your reply. I am using interfoam and the p is the real p that I need. Due to the fact that I require dynamic pressure, namely p-rho*g*h. Do you have any ideas to make this change based on my script?
qi.yang@polimi.it is offline   Reply With Quote

Old   September 15, 2021, 15:21
Default
  #4
Senior Member
 
Join Date: Aug 2015
Posts: 494
Rep Power: 15
clapointe is on a distinguished road
The solver actually computes (and writes) both! The field you're looking for is p_rgh (where p == p_rgh + rho*gh) -- you can check e.g. the pEqn to see this to be true.

Caelan
Tobi likes this.
__________________
Public git repository : https://github.com/clapointe2011/public

Last edited by clapointe; September 21, 2021 at 17:10.
clapointe is offline   Reply With Quote

Old   September 15, 2021, 15:28
Default
  #5
Senior Member
 
kimy
Join Date: Mar 2019
Location: https://t.me/pump_upp
Posts: 164
Rep Power: 7
qi.yang@polimi.it is on a distinguished road
Send a message via ICQ to qi.yang@polimi.it Send a message via AIM to qi.yang@polimi.it Send a message via Yahoo to qi.yang@polimi.it
Quote:
Originally Posted by clapointe View Post
The solver actually computes (and writes) both! The field you're looking for is p_rgh (where p == p_rgh * rho*gh) -- you can check e.g. the pEqn to see this to be true.

Caelan

Yes, I understood this but what makes me confused is that the p_rgh and p is the same at the bottom of the wave. After I used p_rgh or p at the bottom minus rho*g*h is the correct dynamic wave pressure that I need. I don't know why. Additionally, my objective is to process the files. thanks anyway.
Attached Images
File Type: png pressure.png (14.2 KB, 15 views)

Last edited by qi.yang@polimi.it; September 16, 2021 at 04:04.
qi.yang@polimi.it is offline   Reply With Quote

Old   September 21, 2021, 06:53
Default
  #6
Senior Member
 
kimy
Join Date: Mar 2019
Location: https://t.me/pump_upp
Posts: 164
Rep Power: 7
qi.yang@polimi.it is on a distinguished road
Send a message via ICQ to qi.yang@polimi.it Send a message via AIM to qi.yang@polimi.it Send a message via Yahoo to qi.yang@polimi.it
Hi,

I found p_rgh is definitely what I need after I modified the coordinates of gemetry. Now it is clear. Thank you both.
Tobi likes this.
qi.yang@polimi.it is offline   Reply With Quote

Old   September 21, 2021, 12:43
Default
  #7
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
Probably you can also change the "hRef" file (not given and is constructed by default).
It is similar to the gravity field and you specify the reference height here. This could solve your problem too.

Take a try and feel free to give feedback.

Code:
/*--------------------------------*- C++ -*----------------------------------*\ 
  =========                 |                                                   
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox             
   \\    /   O peration     | Website:  https://openfoam.org                    
    \\  /    A nd           | Version:  9                                       
     \\/     M anipulation  |                                                   
\*---------------------------------------------------------------------------*/ 
FoamFile                                                                        
{                                                                               
    format      ascii;                                                          
    class       uniformDimensionedScalarField;                                  
    location    "constant";                                                     
    object      hRef;                                                           
}                                                                               
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 
                                                                                
dimensions      [0 1 0 0 0 0 0];                                                
value           0.244;                                                          
                                                                                
// ************************************************************************* //
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   September 22, 2021, 04:16
Default
  #8
Senior Member
 
kimy
Join Date: Mar 2019
Location: https://t.me/pump_upp
Posts: 164
Rep Power: 7
qi.yang@polimi.it is on a distinguished road
Send a message via ICQ to qi.yang@polimi.it Send a message via AIM to qi.yang@polimi.it Send a message via Yahoo to qi.yang@polimi.it
Quote:
Originally Posted by Tobi View Post
Probably you can also change the "hRef" file (not given and is constructed by default).
It is similar to the gravity field and you specify the reference height here. This could solve your problem too.

Take a try and feel free to give feedback.

Code:
/*--------------------------------*- C++ -*----------------------------------*\ 
  =========                 |                                                   
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox             
   \\    /   O peration     | Website:  https://openfoam.org                    
    \\  /    A nd           | Version:  9                                       
     \\/     M anipulation  |                                                   
\*---------------------------------------------------------------------------*/ 
FoamFile                                                                        
{                                                                               
    format      ascii;                                                          
    class       uniformDimensionedScalarField;                                  
    location    "constant";                                                     
    object      hRef;                                                           
}                                                                               
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 
                                                                                
dimensions      [0 1 0 0 0 0 0];                                                
value           0.244;                                                          
                                                                                
// ************************************************************************* //
Thank you Tobi. The hRef represents the height where I want to see the dynamic wave pressure or something else. I just put this file into the system folder with any file name?
qi.yang@polimi.it is offline   Reply With Quote

Old   September 23, 2021, 04:10
Default
  #9
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
Hey,

it corresponds to the reference height which is related to:
Code:
p_rgh = p - rho*gh
The term gh is created in the createFields.H file:
Code:
#include "readGravitationalAcceleration.H"                                      
#include "readhRef.H"                                                           
#include "gh.H"
  • read the graviational acceleration file constant/g
  • read the hRef file constant/hRef (if exists - otherwise create one)
  • build the gh file
Code:
    Info<< "\nReading hRef" << endl;                                            
    uniformDimensionedScalarField hRef                                          
    (                                                                           
        IOobject                                                                
        (                                                                       
            "hRef",                                                             
            runTime.constant(),                                                 
            mesh,                                                               
            IOobject::READ_IF_PRESENT,                                          
            IOobject::NO_WRITE                                                  
        ),                                                                      
        dimensionedScalar(dimLength, Zero)                                      
    );
As it is stated, the hRef file is read if present in the constant/ folder (named hRef and does have the value (0 0 0) as default. Finally, the gh field is calculated:


Code:
    Info<< "Calculating field g.h\n" << endl;                                   
    dimensionedScalar ghRef                                                     
    (                                                                           
        mag(g.value()) > SMALL                                                  
      ? g & (cmptMag(g.value())/mag(g.value()))*hRef                            
      : dimensionedScalar("ghRef", g.dimensions()*dimLength, 0)                 
    );                                                                          
    volScalarField gh("gh", (g & mesh.C()) - ghRef);                            
    surfaceScalarField ghf("ghf", (g & mesh.Cf()) - ghRef);
Hope this helps you.
Tobi

PS: Code snippet taken from v2106
__________________
Keep foaming,
Tobias Holzmann
Tobi 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
[General] “Upload” vtk data from client to server in paraview script Jack001 ParaView 0 March 8, 2018 08:27
CGNS files contain no data ansys_matt FLUENT 1 August 19, 2016 23:22
[PyFoam] and paraview eelcovv OpenFOAM Community Contributions 28 May 30, 2016 10:23
[Commercial meshers] fluentMeshToFoam multidomain mesh conversion problem Attesz OpenFOAM Meshing & Mesh Conversion 12 May 2, 2013 11:52
Results saving in CFD hawk Main CFD Forum 16 July 21, 2005 21:51


All times are GMT -4. The time now is 01:14.