CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (https://www.cfd-online.com/Forums/openfoam-solving/)
-   -   RhoCentralFoam sampling mass flow rate over time (https://www.cfd-online.com/Forums/openfoam-solving/230939-rhocentralfoam-sampling-mass-flow-rate-over-time.html)

shock77 October 13, 2020 10:07

RhoCentralFoam sampling mass flow rate over time
 
Hi everyone,


I am trying to sample the mass flow rate over time of a patch (inlet) during runtime. I am using OpenFOAM 4 and the solver rhoCentralFoam. I have found a couple of older threads but unfortunately the suggested solutions did not work for me.


First I have tried to add to my controldict:


Code:

functions

{
  inletMassFlow
  {
        type            surfaceFieldValue;
        functionObjectLibs ("libfieldFunctionObjects.so");
        enabled        true;
        writeControl    timeStep;
        writeInterval  100;
        log            true;
        writeFields    false;
        regionType      patch;
        name            inlet;
        operation      sum;
        fields
        (
            phi
        );
  }
   

}

But it seems this function is not available in OpenFOAM 4, I get:


Code:

Starting time loop

--> FOAM Warning :
    From function bool Foam::functionObjectList::read()
    in file db/functionObjects/functionObjectList/functionObjectList.C at line 671
    Caught FatalError
--> FOAM FATAL ERROR:
Unknown function type surfaceFieldValue

Valid functions are :

39
(
CourantNo
Lambda2
MachNo
PecletNo
Q
blendingFactor
components
div
enstrophy
fieldAverage
fieldCoordinateSystemTransform
fieldMinMax
fieldValueDelta
flowType
grad
histogram
mag
magSqr
nearWallFields
patchProbes
pressure
probes
processorField
psiReactionThermoMoleFractions
randomise
readFields
regionSizeDistribution
rhoReactionThermoMoleFractions
sets
streamLine
surfaceInterpolate
surfaceRegion
surfaces
turbulenceFields
volRegion
vorticity
wallBoundedStreamLine
wallShearStress
yPlus
)



    From function static Foam::autoPtr<Foam::functionObject> Foam::functionObject::New(const Foam::word&, const Foam::Time&, const Foam::dictionary&)
    in file db/functionObjects/functionObject/functionObject.C at line 100.

I have also tried the postProcessing utility:


postProcess -func 'flowRatePatch(name=inlet)'


That didnt work aswell, because phi is missing. Ofc I could create an output for phi, but since I would like to calculate the mass flow rate of a patch during runtime, this wouldnt solve the problem, besides I write out many time steps.


Does anyone know a solution?

Yann October 13, 2020 11:22

Hi,


Try using type surfaceRegion instead of surfaceFieldValue (the functions names tend to evolve from one version to another)

Code:

    inletMassFlow
  {
        type            surfaceRegion;
        functionObjectLibs ("libfieldFunctionObjects.so");
        enabled        true;
        writeControl    timeStep;
        writeInterval  100;
        log            true;
        writeFields    false;
        regionType      patch;
        name            inlet;
        operation      sum;
        fields
        (
            phi
        );
  }


Let us know if it solves your problem!

Yann

shock77 October 14, 2020 05:01

Hi Yann,


thank you very much for your help! It works like a charm. :)


It still takes a while until I can evaluate the results and see whether they are correct. I have another question about sum (phi):


Phi is calculated with rho * U. With the function sum, is the integral calculated over the area, which is approximated as the sum, or do I have to multiply the result by the area?







Kind regards,
shock77

Yann October 14, 2020 05:38

Hi Shock77,

Phi is the flux on each face of your patch. So sum(phi) is the total flux on the patch, there is no integration or area to take into account, you directly get the flowrate on the patch, either mass or volumetric flowrate depending on the solver.

With rhoCentralFoam it should be the mass flow rate but you can verify it by checking the units in the phi files.

Cheers,
Yann

shock77 October 14, 2020 07:03

Hi Yann,


thanks again, you are completely right!


Phi is indeed rho*U*A for compressible solvers, U*A for incompressible, since the momentum equation is divided by rho.


I have also found it in the rhoCentralFoam sourcecode of createFields.H:


Code:

surfaceScalarField phi("phi", fvc::flux(rhoU));

Info<< "Creating turbulence model\n" << endl;
autoPtr<compressible::turbulenceModel> turbulence
(
    compressible::turbulenceModel::New
    (
        rho,
        U,
        phi,
        thermo
    )
);


Is there actually a way to get the mass flow rate in x-direction instead of the total mass flow rate? Ofc it is possible to code it, just asking if there is an easy way to do it.



Kind regards,

shock77

Yann October 14, 2020 09:18

I'm not sure what you mean by "flow rate in x-direction" since, in my understanding, flow rate should be relative to the face normal.



Maybe you can manage to do it with function objects but I'm not sure how. You can still use the codedFunctionObject which is a convenient way to add a specific function and use it at runtime, but as you said you need to write the code to achieve what you want.



I'm not sure this is very helpful though!


Yann

shock77 October 14, 2020 09:47

I thought since U is a vector, the total flow rate is calculated. It might be interesting to be able to divide the flow rate in the x,y and z components.


Do you mean, that only the normal component relative to the face is used?

Yann October 14, 2020 10:26

Here is the expression of flow rate:

\dot{m}= \int\int_{S} \rho \vec{U} \vec{dS}

With

\vec{S}=S.\vec{n}

Where the n is a unit vector normal to the surface. So the flow rate is already the quantity of fluid passing through a surface. And it's a scalar quantity, not a vector.

So yes, only the normal component relative to the surface is used to get the flow rate.


Regards,

Yann

shock77 October 14, 2020 10:43

Thank you very much for the clarification and your kind help! :)


I got it now.

Ashish_KG October 25, 2023 08:08

Hey, I am doing the same case(sampling mass flow rate) on OpenFoam v11,

the contradict code is:

Code:

inMassFlow
    {
        type            surface;

        functionObjectLibs ("libfieldFunctionObjects.so");
        enabled        true;

//        writeControl    outputTime;
        writeControl  timeStep;
        writeInterval  1;

        log            true;

        writeFields    false;

        regionType          patch;
        name      in;

        operation      sum;
        fields
        (
            phi
        );
    }


But it seems this function is not available. moreover, only one valid function is shown to be available...
Code:

--> FOAM FATAL ERROR:
Unknown function type surface

Valid functions are :
1(fvModel)

    From function static Foam::autoPtr<Foam::functionObject> Foam::functionObject::New(const Foam::word&, const Foam::Time&, const Foam::dictionary&)
    in file db/functionObjects/functionObject/functionObject.C at line 108.

FOAM exiting

which is not working anyway.

can anyone help me regarding this.

shock77 October 25, 2023 08:19

I think its a simple naming issue. The name changed in the past various times, like surfaceFieldValue or surfaceRegion. I dont know how its names atm, since I wonly worked with OF up to OF 5, but you should find it in the source code.


Edit: From a quick search I think "sampledSurface" or "fieldValue" might be the types to look at. I hope it works!


All times are GMT -4. The time now is 21:22.