|
[Sponsors] |
March 30, 2018, 14:49 |
centroid | position weighted volume average
|
#1 |
Senior Member
Lucky
Join Date: Apr 2011
Location: Orlando, FL USA
Posts: 5,750
Rep Power: 66 |
I'm trying to output the centroid of several fields, Temperature in this example. This seems doable using the weightedVolAverage function object and doing a position weighted volume average. But what field name should I set for the weight field to get the x,y,z coordinates? Or conversely, average the coordinates and weight it by the T field.
Code:
T.x { functionObjectLibs ("libfieldFunctionObjects.so"); type cellSource; source all; weightField banana; // <<< x coordinate of T field fields ( T ); operation volAverage; } Or maybe it is not possible with built-in function opbjects? swak4Foam, defining the new field in createFields, or a coded function object comes to mind. Last edited by LuckyTran; April 9, 2018 at 17:16. |
|
April 1, 2018, 13:14 |
|
#2 |
Senior Member
Taher Chegini
Join Date: Nov 2014
Location: Houston, Texas
Posts: 125
Rep Power: 12 |
The weightedVolAverage doesn't give the centroid only the value of average, you need to use the coded directive in the functions and write a code that calculates the centroid. For example:
Code:
const volScalarField& T = mesh().lookupObject<volScalarField>("T"); const volVectorField& centers = mesh().C(); const scalarField& vols = mesh().V(); const objectRegistry& db = mesh().thisDb(); scalar ts = db.time().value(); scalar sumX = 0; scalar sumY = 0; scalar sumTV = 0; scalar sumV = 0; forAll(centers, I) { sumX += T[I]*vols[I]*centers[I].x(); sumY += T[I]*vols[I]*centers[I].y(); sumTV += T[I]*vols[I]; sumV += vols[I]; } reduce(sumX , sumOp<scalar>()); reduce(sumY , sumOp<scalar>()); reduce(sumTV, sumOp<scalar>()); reduce(sumV , sumOp<scalar>()); if (Pstream::master()) { scalar cX = sumX/max(sumTV, SMALL); scalar cY = sumY/max(sumTV, SMALL); scalar Ta = sumTV/max(sumV, SMALL); const fileName& outputFile = "TCentroids"; OFstream os ( outputFile, IOstream::ASCII, IOstream::currentVersion, IOstream::UNCOMPRESSED, true ); Info<< "Writing temperature field centroid" << endl; os << ts << " " << Ta << " " << cX << " " << cY << endl; } |
|
April 9, 2018, 17:36 |
|
#3 |
Senior Member
Lucky
Join Date: Apr 2011
Location: Orlando, FL USA
Posts: 5,750
Rep Power: 66 |
With minor tinkering to suit my purpose it works except for appending to an open file. In particular,
Code:
OFstream os ( outputFile, IOstream::ASCII, IOstream::currentVersion, IOstream::UNCOMPRESSED true ); |
|
April 9, 2018, 17:53 |
|
#4 | |
Senior Member
Taher Chegini
Join Date: Nov 2014
Location: Houston, Texas
Posts: 125
Rep Power: 12 |
Quote:
|
||
April 9, 2018, 18:50 |
|
#5 |
Senior Member
Lucky
Join Date: Apr 2011
Location: Orlando, FL USA
Posts: 5,750
Rep Power: 66 |
So std :: ofstream writes to file but formatting is required and need to include iomanip (not the IOmanip.H in openfoam). Since OFstream is not used, it's no longer necessary to include OFstream.H. And std :: ofstream does not need any include.
Code:
#include <iomanip> std::ofstream os; os.open ("Centroid", std::ofstream::out | std::ofstream::app); os <<std::setPrecision(9)<< ts << " " << Ta << " " << cX << " " << cY << " " << cZ << nl << endl; os.close(); |
|
|
|
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 09:46 |
area weighted average or mass weighted average | sa har | Main CFD Forum | 0 | January 5, 2016 14:16 |
how to read in a position file | jiejie | OpenFOAM | 0 | May 23, 2011 05:38 |
DPM UDF particle position using the macro P_POS(p)[i] | dm2747 | FLUENT | 0 | April 17, 2009 02:29 |
Combustion Convergence problems | Art Stretton | Phoenics | 5 | April 2, 2002 06:59 |