CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Post-Processing (https://www.cfd-online.com/Forums/openfoam-post-processing/)
-   -   Accessing phi field for sampling plane (https://www.cfd-online.com/Forums/openfoam-post-processing/86250-accessing-phi-field-sampling-plane.html)

francesco85 March 17, 2011 13:01

Accessing phi field for sampling plane
 
Hi all,

I'm trying to modify the "sampledPlane" function. I need to calculate the mean value of the sampled field by both an area-weighted average and a massflow-weighted average. In the first case everything works fine, while for calculating the mass flow I need to access to the "phi" field.

I've tried something like this:

const surfaceScalarField& phi=db().lookupObject<surfaceScalarField>("phi");

but I got the error:

sampledSurface/sampledPlane/sampledPlaneTemplates.C:52: error: there are no arguments to ‘db’ that depend on a template parameter, so a declaration of ‘db’ must be available


Then I tried to modify it as follows:

const surfaceScalarField& phi=vField().db().lookupObject<surfaceScalarField> ("phi");


and I got a different error:

sampledSurface/sampledPlane/sampledPlaneTemplates.C:52: error: expected primary-expression before ‘>’ token
sampledSurface/sampledPlane/sampledPlaneTemplates.C: In member function ‘Foam::tmp<Foam::Field<Type> > Foam::sampledPlane::sampleField(const Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>&) const [with Type = double]’:


Which is the primary-expression needed for? Is it correct to call the db() function?
Any help would be appreciated!

Francesco

CedricVH August 5, 2011 05:49

The database is not needed when working on top level code (like a utility or a solver). However, in lower level code, one should access the database and fetch the phi object with:

Code:

const objectRegistry& db = mesh.db();
const surfaceScalarField& phi=db.lookupObject<surfaceScalarField>("phi");

Normally, it should also work without a database:

Code:

const surfaceScalarField& phi=mesh.lookupObject<surfaceScalarField>("phi");


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