CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Programming & Development (
-   -   read scalar field phi, get flux through faces (

peterwy July 28, 2010 13:23

read scalar field phi, get flux through faces

I've a question.

I write a program with the target to read the flux phi through some faces.
(I need this for a special report. The code is already able to find the necessary faces. So the import of the mesh itself works.)

But now I've no idea, how to read the flux phi through the faces, and especially everything I tried to source the field phi was not really successfully. Probably it's easy but I've no idea, how to do?

Thanks a lot already for your help & best Regards,


#include "argList.H"
#include "cellSet.H"
#include "topoSetSource.H"
#include "Time.H"
#include "globalMeshData.H"
#include <fstream> //to write out the stl file
#include <malloc.h>
#include <string.h>

using namespace Foam;
using namespace std; // for input/output file

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])

#include "setRootCase.H"

fileName sourceRootDir = ".";
fileName sourceCaseDir = ".";

Time runTime
#include "createPolyMesh.H"

MartinB July 28, 2010 14:33

Hi Peter,
can't you simply use:

surfaceScalarField phi
    linearInterpolate(U) & mesh.Sf()

Or if there is at least "U" in your time step:

#  include "createPhi.H"

peterwy July 29, 2010 02:30

phi is already present in the time step (from data side), but

in the program there're no fields sourced at the moment.

The point is that the class(?) surfaceScalarField is not known.
Probably the right #include file is missing but here I've the problem if I take other programs like simpleFoam (or someome with phi present, that swallow... thing) I get a couple of more errors. Than the topo functions working no longer because at the end of the code I build a cellset.

I need a method so that I can simple read the fields, especially the phi one, at that moment when I read the time step.

Hope it's clear what I want. I'm not a real c++ expert, but my knowledge becomes better by day ;-)

Thx & Best Regards,

kathrin_kissling August 3, 2010 03:44

Hi Peter,

is this a postprocessing routine or do you need to have the output in your solver?
If it is a postprocessing routine you could try to have a look in the applications/utilities/postprocessing routines. Mayby you could use a foam::calc function or you could try to just add
#include fvCFD.H

Maybe this could work.

Best Kathrin

peterwy August 4, 2010 16:36


thanks for your help.
I began again with the simpleFoam.C and beginning from this code I tried to solve my problem. At the end it was in fact the simple point to add fvCFD but additionaly the order of the include files was important as well.

Now it works.

Thanks a lot and bye

pvpnrao April 28, 2017 19:40


Can you share your code. Here is my problem:
in each pressure loop
I need to find the fluxes through the faces lying in a particular cellZone and then multiply them with zero. And then pass this upadted velocity field to the next pressure loop.

All times are GMT -4. The time now is 06:31.