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

Openfoam - Write field average of U squared

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 8, 2021, 10:54
Default Openfoam - Write field average of U squared
  #1
New Member
 
Join Date: Mar 2021
Posts: 9
Rep Power: 5
BasG is on a distinguished road
Hello foamers,

I am trying to write the field average of U^2 - as a measure of field-averaged kinetic energy. So far I am able to write the field average of U by using:
PHP Code:
functions
{
    
volFieldAverage_VA
    
{
        
// Mandatory entries (unmodifiable)
        
type            volFieldValue;
        
libs            ("libfieldFunctionObjects.so");

        
// Mandatory entries (runtime modifiable)
        
fields          (p U k);
        
operation       volAverage;
        
regionType      all;

        
// Optional entries (runtime modifiable)
        
weightField     alpha.water;

        
// Optional (inherited) entries
        
writeFields     no;
        
writeToFile     true;
        
writeControl    timeStep;
        
writeInterval   1;
    }

Additionally, I want to obtain the volAverage for the field U^2. Could you help me doing so?

Best,

Bas
BasG is offline   Reply With Quote

Old   November 8, 2021, 16:01
Default
  #2
Member
 
MNM
Join Date: Aug 2017
Posts: 69
Rep Power: 8
SHUBHAM9595 is on a distinguished road
You can use swak4Foam for that...The following snippet should give you an idea...you might also need to modify it if some syntax error occurs

Code:
kineticEnergyExpression
    {
        type expressionField;
        outputControl timeStep;
        outputInterval 1;
        fieldName kineticEnergy;
        variables "Ukin=sum(U*U*vol())/sum(vol());";
        expression "Ukin";
        autowrite true;
    }


expression "pAverage-p";
Finally, make sure to add the corresponding libraries in the controlDict file....something like

Code:
libs (
    "libOpenFOAM.so"
    "libsimpleFunctionObjects.so"
    "libsimpleSwakFunctionObjects.so"
    "libswakFunctionObjects.so"
    );
SHUBHAM9595 is offline   Reply With Quote

Old   November 9, 2021, 04:10
Default
  #3
New Member
 
Join Date: Mar 2021
Posts: 9
Rep Power: 5
BasG is on a distinguished road
Thank you SHUBHAM9595 for your reply. Unfortunately I am running my models on a linux cluster owned by my institute and the swak4foam library is not yet installed. It will take quite a procedure to get it installed I am afraid. Are you aware of alternative ways to perform this task?
BasG is offline   Reply With Quote

Old   November 9, 2021, 07:35
Default
  #4
Member
 
MNM
Join Date: Aug 2017
Posts: 69
Rep Power: 8
SHUBHAM9595 is on a distinguished road
Alternatively, you can define a custom volScalarField in createFields.H (anywhere after the U ) as shown below

Code:
volScalarField KE
(
    IOobject
    (
        "KE",
        runTime.timeName(),
        mesh,
        IOobject::NO_READ,
        IOobject::AUTO_WRITE
    ),
    mag(U)*mag(U)
);


AUTO_WRITE will ensure that it write the Kinetic energy field at each writing interval. Additionally, to update its value with each iteration you need to insert the following line at the end of UEqn.H


Code:
KE = mag(U)*mag(U);
Good luck !!!
SHUBHAM9595 is offline   Reply With Quote

Old   November 9, 2021, 09:17
Default
  #5
Senior Member
 
Yann
Join Date: Apr 2012
Location: France
Posts: 1,148
Rep Power: 27
Yann will become famous soon enough
Hi Bas,

If you are using a relatively new version of OpenFOAM, you might be able to do it with the "multiply" function object to create the U^2 field before your volAverage function.
Here is the syntax for OpenFOAM-9:

Code:
functions
 {


     Usquare
    {
        type            multiply;
        libs            ("libfieldFunctionObjects.so");
        fields          (U U);
        result          Usquare;
        executeControl  writeTime;
        writeControl    writeTime;
    }

    volFieldAverage_VA
    {
        // Mandatory entries (unmodifiable)
        type            volFieldValue;
        libs            ("libfieldFunctionObjects.so");

        // Mandatory entries (runtime modifiable)
        fields          (p U k Usquare);
        operation       volAverage;
        regionType      all;

        // Optional entries (runtime modifiable)
        weightField     alpha.water;

        // Optional (inherited) entries
        writeFields     no;
        writeToFile     true;
        writeControl    timeStep;
        writeInterval   1;
    }
}
Cheers,
Yann
Yann is offline   Reply With Quote

Old   November 9, 2021, 09:50
Default
  #6
New Member
 
Join Date: Mar 2021
Posts: 9
Rep Power: 5
BasG is on a distinguished road
Thanks SHUBHAM9595! This is useful. I am now able to write the field for U^2 for every map output time. Eventhough it is not for every timestep (as are the volume averages of the other quantities), it is still usefull as I can determine the domain average in Paraview.

@Yann, thanks for your reply. I tried this as well. Unfortunately the version I use (v1812) does not have this functionality yet.
BasG is offline   Reply With Quote

Reply

Tags
fieldaverage, interfoam, kinetic energy, openfoam, volaverage


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
[swak4Foam] swakExpression not writing to log alexfells OpenFOAM Community Contributions 3 March 16, 2020 18:19
Converging Diverging Nozzle with dbnsTurbFoam Saleh Abuhanieh OpenFOAM Running, Solving & CFD 4 December 13, 2019 10:26
OpenFOAM Training Jan-Jul 2017, Virtual, London, Houston, Berlin CFDFoundation OpenFOAM Announcements from Other Sources 0 January 4, 2017 06:15
OpenFOAM floating point Error upuli OpenFOAM Programming & Development 5 June 20, 2016 03:19
[mesh manipulation] Importing Multiple Meshes thomasnwalshiii OpenFOAM Meshing & Mesh Conversion 18 December 19, 2015 18:57


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