|
[Sponsors] |
November 8, 2021, 11:54 |
Openfoam - Write field average of U squared
|
#1 |
New Member
Join Date: Mar 2021
Posts: 12
Rep Power: 5 |
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:
Best, Bas |
|
November 8, 2021, 17:01 |
|
#2 |
Member
MNM
Join Date: Aug 2017
Posts: 69
Rep Power: 9 |
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" ); |
|
November 9, 2021, 05:10 |
|
#3 |
New Member
Join Date: Mar 2021
Posts: 12
Rep Power: 5 |
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?
|
|
November 9, 2021, 08:35 |
|
#4 |
Member
MNM
Join Date: Aug 2017
Posts: 69
Rep Power: 9 |
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); |
|
November 9, 2021, 10:17 |
|
#5 |
Senior Member
Yann
Join Date: Apr 2012
Location: France
Posts: 1,236
Rep Power: 29 |
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; } } Yann |
|
November 9, 2021, 10:50 |
|
#6 |
New Member
Join Date: Mar 2021
Posts: 12
Rep Power: 5 |
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. |
|
Tags |
fieldaverage, interfoam, kinetic energy, openfoam, volaverage |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[swak4Foam] swakExpression not writing to log | alexfells | OpenFOAM Community Contributions | 3 | March 16, 2020 19:19 |
Converging Diverging Nozzle with dbnsTurbFoam | Saleh Abuhanieh | OpenFOAM Running, Solving & CFD | 4 | December 13, 2019 11:26 |
OpenFOAM Training Jan-Jul 2017, Virtual, London, Houston, Berlin | CFDFoundation | OpenFOAM Announcements from Other Sources | 0 | January 4, 2017 07:15 |
OpenFOAM floating point Error | upuli | OpenFOAM Programming & Development | 5 | June 20, 2016 04:19 |
[mesh manipulation] Importing Multiple Meshes | thomasnwalshiii | OpenFOAM Meshing & Mesh Conversion | 18 | December 19, 2015 19:57 |