CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Post-Processing (https://www.cfd-online.com/Forums/openfoam-post-processing/)
-   -   Computing Patch Average During Simulation (https://www.cfd-online.com/Forums/openfoam-post-processing/191753-computing-patch-average-during-simulation.html)

victorious_BIG August 18, 2017 20:19

Computing Patch Average During Simulation
 
Hi,

I spent some time trying to figure out an effective way to calculate the average of a scalar quantity of over a patch while the solver is iterating. I appended the code below to the bottom of my solver. In this example, the patch of interest is named "outlet":


runTime.write();

const label& patchID = mesh.boundaryMesh().findPatchID("outlet");
const fvPatch& outletPatch = mesh.boundary()[patchID];
const fvPatchField<scalar>& T =
outletPatch.lookupPatchField<volScalarField, scalar>("T");

Info << "Average Outlet Temp: "
<< sum(T * T.patch().magSf()) / sum(T.patch().magSf()) << endl;


This gave me the same result as running the post processing command from the terminal prompt:

>> postProcess -func 'patchAverage(name=outlet,T)'

Note: I have only tested this on a regular mesh.

I'd be happy to hear feedback as to whether there is a more effective/efficient method to do this than what I have written above.

victorious_BIG August 29, 2017 12:28

Post-processing Function Object Definitions
 
Hi,

I have been trying to search the source code for the location of the function object definitions. For example, in my post above I am using a possible definition to determine an average concentration. I've tried to find the location of the function object definitions in the source code using oxygen but haven't had much luck.

Does anyone know where the specific source code files for the function definition is located?

Thanks!

amdk136 November 28, 2018 05:23

Quote:

Originally Posted by victorious_BIG (Post 661212)
Hi,

I spent some time trying to figure out an effective way to calculate the average of a scalar quantity of over a patch while the solver is iterating. I appended the code below to the bottom of my solver. In this example, the patch of interest is named "outlet":

runTime.write();

const label& patchID = mesh.boundaryMesh().findPatchID("outlet");
const fvPatch& outletPatch = mesh.boundary()[patchID];
const fvPatchField<scalar>& T =
outletPatch.lookupPatchField<volScalarField, scalar>("T");

Info << "Average Outlet Temp: "
<< sum(T * T.patch().magSf()) / sum(T.patch().magSf()) << endl;

This gave me the same result as running the post processing command from the terminal prompt:

>> postProcess -func 'patchAverage(name=outlet,T)'

Note: I have only tested this on a regular mesh.

I'd be happy to hear feedback as to whether there is a more effective/efficient method to do this than what I have written above.

Hi,

I was wondering what file you have the first section of code in?:
Quote:

runTime.write();

const label& patchID = mesh.boundaryMesh().findPatchID("outlet");
const fvPatch& outletPatch = mesh.boundary()[patchID];
const fvPatchField<scalar>& T =
outletPatch.lookupPatchField<volScalarField, scalar>("T");

Info << "Average Outlet Temp: "
<< sum(T * T.patch().magSf()) / sum(T.patch().magSf()) << endl;
I am interested in this, however I am unsure where it should be put!

Thanks,
Arthur


All times are GMT -4. The time now is 19:08.