CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Post-Processing (http://www.cfd-online.com/Forums/openfoam-post-processing/)
-   -   mass flow calculation over a face zone (http://www.cfd-online.com/Forums/openfoam-post-processing/66738-mass-flow-calculation-over-face-zone.html)

mvoss July 23, 2009 03:25

mass flow calculation over a face zone
 
Hi

I want to calculate the mass flow over a face zone. I am able to calculate it over a boundary, following the advices in this thread, by means of patchIntegrate. But I'd like to calculate it in an internal surface, so I thought the most suitable way is to define a faceZone and integrate over it. As I'm quite new to OF, I don't know how to do it (extend patchIntegrate?, do it with paraview?,...).

Can someone help?

Juan

henrik July 23, 2009 03:56

I think these threads should help to find direction:

http://www.cfd-online.com/Forums/ope...g-faceset.html
http://www.cfd-online.com/Forums/ope...condition.html

Henrik

mvoss July 24, 2009 03:19

I'll try to create a cyclic boundary with the patchCreate utility. Unfortunately, as already reported in some other threads, this utility crashes. I will try it from the 1.5.x installation.
Thx for the prompt support.

mvoss July 31, 2009 07:58

That is what I did, for those interested:
- I created two closed volumina and defined a patch in both zones I want to put together
- Then I used createPatch from version 1.6 (1.5 does not work for me)
- I added phi to the fluxRequired variables in fvSchemes, so phi will be written in each time step
- I changed patchIntegrate to correctly calculate the massflow in the cyclic BC (in the original version, it gets cancelled because areas do sum zero) (see attached applications/utilities/postProcessing/patch/patchIntegrate/patchIntegrate.C)

happy Foaming!

Juan

--------------------- CUT HERE -------------------------------
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.

OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.

OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

Application
patchIntegrate

Description
Calculates the integral of the specified field over the specified patch.

\*---------------------------------------------------------------------------*/

#include "fvCFD.H"
#include "cyclicPolyPatch.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:

int main(int argc, char *argv[])
{
timeSelector::addOptions();
argList::validArgs.append("fieldName");
argList::validArgs.append("patchName");
# include "setRootCase.H"
# include "createTime.H"
instantList timeDirs = timeSelector::select0(runTime, args);
# include "createMesh.H"

word fieldName(args.additionalArgs()[0]);
word patchName(args.additionalArgs()[1]);

forAll(timeDirs, timeI)
{
runTime.setTime(timeDirs[timeI], timeI);
Info<< "Time = " << runTime.timeName() << endl;

IOobject fieldHeader
(
fieldName,
runTime.timeName(),
mesh,
IOobject::MUST_READ
);

// Check field exists
if (fieldHeader.headerOk())
{
mesh.readUpdate();

label patchi = mesh.boundaryMesh().findPatchID(patchName);
if (patchi < 0)
{
FatalError
<< "Unable to find patch " << patchName << nl
<< exit(FatalError);
}

// Give patch area
if (isType<cyclicPolyPatch>(mesh.boundaryMesh()[patchi]))
{
Info<< " Cyclic patch vector area: " << nl;
label nFaces = mesh.boundaryMesh()[patchi].size();
vector sum1 = vector::zero;
vector sum2 = vector::zero;
for (label i=0; i<nFaces/2; i++)
{
sum1 += mesh.Sf().boundaryField()[patchi][i];
sum2 += mesh.Sf().boundaryField()[patchi][i+nFaces/2];
}
reduce(sum1, sumOp<vector>());
reduce(sum2, sumOp<vector>());
Info<< " - half 1 = " << sum1 << ", " << mag(sum1) << nl
<< " - half 2 = " << sum2 << ", " << mag(sum2) << nl
<< " - total = " << (sum1 + sum2) << ", "
<< mag(sum1 + sum2) << endl;
Info<< " Cyclic patch area magnitude = "
<< gSum(mesh.magSf().boundaryField()[patchi])/2.0 << endl;

// Read field and calc integral
if (fieldHeader.headerClassName() == volScalarField::typeName)
{
Info<< " Reading " << volScalarField::typeName << " "
<< fieldName << endl;

volScalarField field(fieldHeader, mesh);

vector integral1 = vector::zero;
vector integral2 = vector::zero;
for (label i=0; i<nFaces/2; i++)
{
integral1 += mesh.Sf().boundaryField()[patchi][i] * field.boundaryField()[patchi][i];
integral2 += mesh.Sf().boundaryField()[patchi][i+nFaces/2] * field.boundaryField()[patchi][i+nFaces/2];
}
reduce(integral1, sumOp<vector>());
reduce(integral2, sumOp<vector>());

Info<< " Integral of " << fieldName
<< " over vector area & area magnitude of cyclic patch " << patchName << '[' << patchi << ']' << nl;

Info<< " - half 1 = " << integral1 << ", " << mag(integral1) << nl
<< " - half 2 = " << integral2 << ", " << mag(integral2) << nl
<< " - total = " << (integral1 + integral2) << ", "
<< mag(integral1 + integral2) << endl;

}
else if
(
fieldHeader.headerClassName() == surfaceScalarField::typeName
)
{
Info<< " Reading " << surfaceScalarField::typeName << " "
<< fieldName << endl;

surfaceScalarField field(fieldHeader, mesh);

scalar integral1 = 0.0;
scalar integral2 = 0.0;
for (label i=0; i<nFaces/2; i++)
{
integral1 += field.boundaryField()[patchi][i];
integral2 += field.boundaryField()[patchi][i+nFaces/2];
}

Info<< " Integral of " << fieldName << " over patch "
<< patchName << '[' << patchi << ']' << nl ;

Info<< " - half 1 = " << integral1 << nl
<< " - half 2 = " << integral2 << nl
<< " - total = " << (integral1 + integral2) << endl;

}
else
{
FatalError
<< "Only possible to integrate "
<< volScalarField::typeName << "s "
<< "and " << surfaceScalarField::typeName << "s"
<< nl << exit(FatalError);
}

}
else
{
// Give patch area
Info<< " Area vector of patch "
<< patchName << '[' << patchi << ']' << " = "
<< gSum(mesh.Sf().boundaryField()[patchi]) << endl;
Info<< " Area magnitude of patch "
<< patchName << '[' << patchi << ']' << " = "
<< gSum(mesh.magSf().boundaryField()[patchi]) << endl;


// Read field and calc integral
if (fieldHeader.headerClassName() == volScalarField::typeName)
{
Info<< " Reading " << volScalarField::typeName << " "
<< fieldName << endl;

volScalarField field(fieldHeader, mesh);

Info<< " Integral of " << fieldName
<< " over vector area of patch "
<< patchName << '[' << patchi << ']' << " = "
<< gSum
(
mesh.Sf().boundaryField()[patchi]
*field.boundaryField()[patchi]
)
<< nl;

Info<< " Integral of " << fieldName
<< " over area magnitude of patch "
<< patchName << '[' << patchi << ']' << " = "
<< gSum
(
mesh.magSf().boundaryField()[patchi]
*field.boundaryField()[patchi]
)
<< nl;
}
else if
(
fieldHeader.headerClassName() == surfaceScalarField::typeName
)
{
Info<< " Reading " << surfaceScalarField::typeName << " "
<< fieldName << endl;

surfaceScalarField field(fieldHeader, mesh);
scalar sumField = gSum(field.boundaryField()[patchi]);

Info<< " Integral of " << fieldName << " over patch "
<< patchName << '[' << patchi << ']' << " = "
<< sumField << nl;
}
else
{
FatalError
<< "Only possible to integrate "
<< volScalarField::typeName << "s "
<< "and " << surfaceScalarField::typeName << "s"
<< nl << exit(FatalError);
}
}
}
else
{
Info<< " No field " << fieldName << endl;
}

Info<< endl;
}

Info<< "End\n" << endl;

return 0;
}


// ************************************************** *********************** //

--------------------- CUT HERE -------------------------------

haghajani August 6, 2009 06:42

Dear All,
My problem is an underpressure vessel with a hole on it, and I want to monitor mass flow rate at this hole.
So I need to have face inside to solution domain, why it is not the boundary.
To follow the instructions, posted below;

How should I create the patch/face, defining the interested hole?

Thanks in advance,
Hamed

haghajani August 10, 2009 10:01

Steps to calculate mass flow rate at an internal face
 
Dear All,
I am going to ask my question in a new way, May that was not clear enough.

I want to calculate mass flow rate at cross section different from boundaries; so each cross-section contains many faces wich are (internal). I didn't get the idea of using utilities as faceSet, createPatch or patchIntegrate; Would you please tell me more how I should implement them?
If the solution is what is posted, I do not know

- How to creat closed volumina and defin a patch in zones?
- How to use createPatch?
- How to add phi to the fluxRequired variables in fvSchemes?
...
Please let me know the steps in detail;



Best regards,
Hamed

henrik August 10, 2009 11:56

Dear haghajani,

have a look at the faceZoneIntegration-functionObject that comes with 1.6. This should be very close to what you are looking for.

Henrik

gricci September 28, 2009 08:11

Unfortunately the faceZonesIntegration-functionObject only works with sufaceScalarField and cannot be used to integrate over internal faces where fields are defined as volScalarFields.

Maybe someone could explain here how to modify this functionObject to handle volScalarFields.

Thanks and keep up the good work!

steve September 13, 2010 12:50

...more hints on this topic?
 
Dear Foamers,

did you figure out a quick solution of the problem "mass flow calculation over face zones"? I tried out several things but did not get any satisfying solution. I keep struggling when trying to access the field data of a face zone.

Did you manage to adjust the faceZoneIntegration - functionObject for this purpose? I would be happy for any hint how to approach this problem.

Kind regards,
Steffen

gschaider September 14, 2010 08:57

Quote:

Originally Posted by steve (Post 275014)
Dear Foamers,

did you figure out a quick solution of the problem "mass flow calculation over face zones"? I tried out several things but did not get any satisfying solution. I keep struggling when trying to access the field data of a face zone.

Did you manage to adjust the faceZoneIntegration - functionObject for this purpose? I would be happy for any hint how to approach this problem.

Kind regards,
Steffen

Beware: this is advertisment for Beta-software.

Just yesterday I announced this piece of software http://www.cfd-online.com/Forums/ope...tml#post275057 which among other things can do what you're trying to do (have a look at the angledDuct-example that comes with it for an example on "how to calculate a massflow on a faceZone")

And another "advantage": there isn't too much documentation there yet, so you won't have to waste too much time reading ;)

Bernhard

steve September 14, 2010 11:26

Bernhard,

Thanks for the quick reply and this great hint!
I could not manage to get your tool swak4Foam running on OF1.5-dev, though. Is this tool also supported for this OF version or do I have to stick to OF1.6 or OF1.7?

Kind regards,
Steffen

gschaider September 14, 2010 11:34

Quote:

Originally Posted by steve (Post 275186)
Bernhard,

Thanks for the quick reply and this great hint!
I could not manage to get your tool swak4Foam running on OF1.5-dev, though. Is this tool also supported for this OF version or do I have to stick to OF1.6 or OF1.7?

Kind regards,
Steffen

I'm sorry. I would be surprised if it worked with 1.5 (changes should not be too hard but nevertheless incompatible with 1.6/1.7)

Bernhard


All times are GMT -4. The time now is 17:12.