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 Rate Over a Sampled Surface (http://www.cfd-online.com/Forums/openfoam-post-processing/109941-mass-flow-rate-over-sampled-surface.html)

GRAUPS November 30, 2012 11:35

Mass Flow Rate Over a Sampled Surface
 
Hey guys,

I'm looking to calculate the mass flow rate over a sampled surface. The current function I'm using in controlDict looks like this...

Code:

faceObj1
    {
        type            faceSource;
        functionObjectLibs ("libfieldFunctionObjects.so");
        enabled        true;       
        outputControl  timeStep;
        // Output to log&file (true) or to file only
        log            true;

        // Output field values as well
        valueOutput    false;

        // Type of source: patch/faceZone/sampledSurface
        source          sampledSurface;

        // if patch or faceZone: name of patch or faceZone
        //sourceName      movingWall;

        //// if sampledSurface: dictionary with a sampledSurface
        //// Note: will not sample surface fields.
        sampledSurfaceDict
        {
          // Sampling on triSurface
          type        sampledTriSurfaceMesh;
          surface    int_1.stl;
          source      cells;  // sample cells or boundaryFaces
          interpolate true;
        }

        // Operation: areaAverage/sum/weightedAverage ...
        operation      sum;
       
        fields
        (
            phi
        );
    }

However, this does not provide any output (or errors). When I change the function to use a patch instead of a sampled surface (example: inlet), it is fine and outputs mass flow correctly. I have internal faces defined by stl files that I would like to sample though, and for some reason it does not provide the same behavior.

When changing the function to use a weighted average based on a sample surface and phi, I can get it to produce the following error.

Code:

--> FOAM FATAL ERROR:
[3] Field phi not found in database
[3]
[3]    From function Foam::tmp<Foam::Field<Type> > Foam::fieldValues::faceSource::getFieldValues(const word&, const bool) const
[3]    in file fieldValues/faceSource/faceSourceTemplates.C at line 120.

It almost seems as if phi is inaccessible to the sampled surface or is not being made available by the solver. However, after the first time step, I see a file phi being outputted. Can anyone tell me what I may be doing wrong? Or suggest a better way to do this, perhaps using swak4foam?

gschaider November 30, 2012 12:29

Quote:

Originally Posted by GRAUPS (Post 395058)
Hey guys,

I'm looking to calculate the mass flow rate over a sampled surface. The current function I'm using in controlDict looks like this...

Code:

faceObj1
    {
        type            faceSource;
        functionObjectLibs ("libfieldFunctionObjects.so");
        enabled        true;       
        outputControl  timeStep;
        // Output to log&file (true) or to file only
        log            true;

        // Output field values as well
        valueOutput    false;

        // Type of source: patch/faceZone/sampledSurface
        source          sampledSurface;

        // if patch or faceZone: name of patch or faceZone
        //sourceName      movingWall;

        //// if sampledSurface: dictionary with a sampledSurface
        //// Note: will not sample surface fields.
        sampledSurfaceDict
        {
          // Sampling on triSurface
          type        sampledTriSurfaceMesh;
          surface    int_1.stl;
          source      cells;  // sample cells or boundaryFaces
          interpolate true;
        }

        // Operation: areaAverage/sum/weightedAverage ...
        operation      sum;
       
        fields
        (
            phi
        );
    }

However, this does not provide any output (or errors). When I change the function to use a patch instead of a sampled surface (example: inlet), it is fine and outputs mass flow correctly. I have internal faces defined by stl files that I would like to sample though, and for some reason it does not provide the same behavior.

When changing the function to use a weighted average based on a sample surface and phi, I can get it to produce the following error.

Code:

--> FOAM FATAL ERROR:
[3] Field phi not found in database
[3]
[3]    From function Foam::tmp<Foam::Field<Type> > Foam::fieldValues::faceSource::getFieldValues(const word&, const bool) const
[3]    in file fieldValues/faceSource/faceSourceTemplates.C at line 120.

It almost seems as if phi is inaccessible to the sampled surface or is not being made available by the solver. However, after the first time step, I see a file phi being outputted. Can anyone tell me what I may be doing wrong? Or suggest a better way to do this, perhaps using swak4foam?

Haven't looked at the source, but AFAIK these things only work for volume-fields and phi is a surface-field. I don't think that OF even supports interpolation for surfaceFields. And even if it would you'd not be happy with the result: the definition of phi depends on the orientation of the cell faces and during the interpolation that information would get lost.

That being said: something like this could be done in swak4Foam. But for the reason given above (no interpolation, orientation) using phi won't work. Instead you'd have to "emulate" it with an expression like "rho*U & Sf()" (Sf() is the surface vector of a phase) and sum it

GRAUPS December 6, 2012 14:20

Bernhard, thank you for your response. This is what I have so far...

Code:

flowBeforeSet
    {
        type swakExpression;
        valueType surface;
        surfaceName internal;       
        surface
        {
            type sampledTriSurfaceMesh;
            surface    int_1.stl;
            source      cells;  // sample cells or boundaryFaces
            interpolate false;           
        }       
        expression "rho*U & Sf()";
        accumulations (
            sum
        );
        verbose true;
    }

This outputs mass flow values, however they seem a little off. The example case I'm using is a straight pipe with constant mass Flow in. I'm sampling mass flow at the center of the pipe. Shouldn't the mass flow at the center be the same as the mass flow coming in? I'm getting about a three percent difference between in flow and the sampled flow.

Do you know what could be causing this difference? Does the inclusion of Sf() in the swakExpression mean that only the values normal to the surface are being taken into account? Also, is it possible to interpolate the values being used for the mass flow calculation to perhaps get a more accurate results? When I turn interpolate on it throws an error at me. Thanks!

gschaider December 7, 2012 05:36

Quote:

Originally Posted by GRAUPS (Post 396168)
Bernhard, thank you for your response. This is what I have so far...

Code:

flowBeforeSet
    {
        type swakExpression;
        valueType surface;
        surfaceName internal;       
        surface
        {
            type sampledTriSurfaceMesh;
            surface    int_1.stl;
            source      cells;  // sample cells or boundaryFaces
            interpolate false;           
        }       
        expression "rho*U & Sf()";
        accumulations (
            sum
        );
        verbose true;
    }

This outputs mass flow values, however they seem a little off. The example case I'm using is a straight pipe with constant mass Flow in. I'm sampling mass flow at the center of the pipe. Shouldn't the mass flow at the center be the same as the mass flow coming in? I'm getting about a three percent difference between in flow and the sampled flow.

Do you know what could be causing this difference? Does the inclusion of Sf() in the swakExpression mean that only the values normal to the surface are being taken into account? Also, is it possible to interpolate the values being used for the mass flow calculation to perhaps get a more accurate results? When I turn interpolate on it throws an error at me. Thanks!

Yep. "U&Sf()" is the component in normal direction. But the regular phi is calculated the same way ... and the pressure correction is done for that. So that value should be conservative ... on the faces (if you have for instance a faceZone going through the pipe - just consider the flip()-problematic discussed elsewhere). But for a sampled set you might have interpolation issues ... which depend on the amount of flow that doesn't go perpendicular over your surface and the alignment of the surface to the cell faces. You might want to check the ratio of velocity that doesn't go your way with something like (this is unchecked and assumes that no face has velocity 0) "mag(U-normal()*(U & normal())/mag(U)" and accumulations min/max/average and see whether this might be the problem.

GRAUPS December 7, 2012 10:33

Quote:

Originally Posted by gschaider (Post 396229)
You might want to check the ratio of velocity that doesn't go your way with something like (this is unchecked and assumes that no face has velocity 0) "mag(U-normal()*(U & normal())/mag(U)" and accumulations min/max/average and see whether this might be the problem.

Ok, I added the check for the ratio of velocity that is not normal... here is the output after a converged solution has been reached...

Code:

Expression Ratio_not_Normal :  min=0.8991376591 max=0.96846234 average=0.9064741362
Expression Sampled_Mass_Flow :  sum=2.775649376
Expression patchMassFlow on inlet:  sum=-2.69375
Expression patchMassFlow on outlet:  sum=2.693749998

So it looks like about 90% of the flow isn't completely normal to the surface? Assuming I'm reading your expression correct. Or does this normal represent the flow going through each cell cut by my sample surface, not the surface itself? And what does this mean for the accuracy of the Sampled_Mass_Flow?

Also, for reference, this is the error I receive when I turn interpolation on for the Sampled_Mass_Flow...

Code:

--> FOAM FATAL ERROR:
 Parser Error at "1.12-11" :"Operands have different sizes: 24 and 22"
"rho*U & Sf()"
"            "

    From function parsingValue
    in file lnInclude/CommonValueExpressionDriverI.H at line 802.

FOAM exiting

Thanks again for your help.

gschaider December 7, 2012 20:03

Quote:

Originally Posted by GRAUPS (Post 396286)
Ok, I added the check for the ratio of velocity that is not normal... here is the output after a converged solution has been reached...

Code:

Expression Ratio_not_Normal :  min=0.8991376591 max=0.96846234 average=0.9064741362
Expression Sampled_Mass_Flow :  sum=2.775649376
Expression patchMassFlow on inlet:  sum=-2.69375
Expression patchMassFlow on outlet:  sum=2.693749998

So it looks like about 90% of the flow isn't completely normal to the surface? Assuming I'm reading your expression correct. Or does this normal represent the flow going through each cell cut by my sample surface, not the surface itself? And what does this mean for the accuracy of the Sampled_Mass_Flow?

Well. I only suggest the equations. It's your simulation so you have to judge whether they are correct. Have you had a look in paraview whether the 90% are plausible?

With control surfaces that are not aligned to the cell faces you always have got to expect an error. How big it is depends on the circumstances but if the 90% are correct they are not favourable

Quote:

Originally Posted by GRAUPS (Post 396286)
Also, for reference, this is the error I receive when I turn interpolation on for the Sampled_Mass_Flow...

Code:

--> FOAM FATAL ERROR:
 Parser Error at "1.12-11" :"Operands have different sizes: 24 and 22"
"rho*U & Sf()"
"            "

    From function parsingValue
    in file lnInclude/CommonValueExpressionDriverI.H at line 802.

FOAM exiting

Thanks again for your help.

That is strange. And looks like a bug. Sf() has as many values as there are faces on the surface and rho and U should get interpolated (and have the same number)

GRAUPS December 11, 2012 17:15

Quote:

Originally Posted by gschaider (Post 396357)
Well. I only suggest the equations. It's your simulation so you have to judge whether they are correct. Have you had a look in paraview whether the 90% are plausible?

I would say the 90% is not plausible, as this is a straight 3 meter pipe with constant inflow. When I get the time to come back to this problem, I'll post back with some paraview pics.

Quote:

Originally Posted by gschaider (Post 396357)
That is strange. And looks like a bug. Sf() has as many values as there are faces on the surface and rho and U should get interpolated (and have the same number)

I just realized I'm a version behind on swak4foam, and reading the release changes, some of my problems have a chance of being fixed in the new release. When I get the time to recompile and update, I'll try to post back with some more recent tests. Thanks again for your help.

gschaider December 12, 2012 12:15

Quote:

Originally Posted by GRAUPS (Post 397033)
I would say the 90% is not plausible, as this is a straight 3 meter pipe with constant inflow. When I get the time to come back to this problem, I'll post back with some paraview pics.

Maybe there's an error in the expression although I don't see where (but it is always the simple things that are problematic).

Quote:

Originally Posted by GRAUPS (Post 397033)
I just realized I'm a version behind on swak4foam, and reading the release changes, some of my problems have a chance of being fixed in the new release. When I get the time to recompile and update, I'll try to post back with some more recent tests. Thanks again for your help.

Hoping for the best (I love bugs that are already fixed)


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