CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM (
-   -   volumeIntegrate ? (

T.D. April 12, 2011 11:28

volumeIntegrate ?
Hi Foamers,
any ideas how to code the volumeIntegrate function inside the solver, in order to get the volume integral on a group of cells, let's say for example "a sphere" inside the mesh ?



seboxx September 1, 2011 11:05

Hi T.D.

have you had any success on this one?
I am facing a pretty similiar question right now.

Can post my results once I have achieved something... was just wondering whether you got it already.



kmooney September 1, 2011 13:21

I've written a pre-Processing app that initializes a spherical vof field. I'm thinking you could do something like this:


        volVectorField positions
        volScalarField myScalarValueToIntegrate = 0;
        scalar integratedValue = 0;

      forAll(positions, cellI)
      if(mag(positions[cellI].x()*positions[cellI].x() + positions[cellI].y()*positions[cellI].y() + positions[cellI].z()*positions[cellI].z() < someRadius))
        integratedValue += myScalarValueToIntegrate[cellI];

flowman September 1, 2011 19:43

The OpenFOAM library provides a function to compute integrals over the domain: fvc::domainIntegrate.

To integrate a scalar solution variable (volScalarField) p over the domain and write the answer to the standard output, add the following line to the solver source code.


Info<< nl << "Integral of p: "
            << fvc::domainIntegrate(p).value () << endl;

seboxx September 5, 2011 04:25

Hi there,

thank you for the comments. I know that domainIntegrate works, but what if my problem is a little more complex.

Like, I wanna calculate an Integral of the Heaviside function over the domain.
I thought I can do a simple if(mag(u)>0) then add the volume of the cell that I am currently in.
But I am not quite sure how to get that to work.

My volScalarField is named u, and so far I can't access the magnitude of u, I simply don't know how to address it...

Then my idea was to do a for-loop over the whole domain, with the if condition check whether u is above a certain threshold, and when that is the case just add the volume over all those cells where the threshold condition is fulfilled.
How to I get the volume of that cell I am working with?

Any comment is greatly appreciated.


seboxx September 5, 2011 06:27

Oh it's actually not complex at all, after the hint of flowman at least ;)

All I did is something like:

Info<< nl << "Integral of p: "         
                << fvc::domainIntegrate(pos(p-1e-6)).value () << endl;

All the best,


All times are GMT -4. The time now is 10:49.