CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM (
-   -   Reference "mesh" inside a class (

tonyuprm November 4, 2010 17:31

Reference "mesh" inside a class
Hi all,

I'm trying to create a class which references the "mesh" class within itself. I want to call mesh.cells and mesh.C from within the class. Is there a way to use some kind of pointer within the constructor to do this? For other variables (like U) it can be done because its is of type volVectorField and the code is like:

myClass::myClass(volVectorField& U_)

I want to include a reference to the mesh class instead of the U_.



kathrin_kissling November 5, 2010 03:10

Hi Tony,

you can just do U_.mesh() and you have the reference to the mesh class.

Hope this helps


ngj November 5, 2010 05:21

Hi Tony

Alternatively, your constructor call could be


myClass::myClass(const fvMesh & mesh, volVectorField & U);
and within the constructor do

myClass::myClass(const fvMesh & mesh, volVectorField & U)
... etc


where mesh_ is defined as follows in your header file:

const fvMesh & mesh_;
Best regards,


tonyuprm November 5, 2010 11:30

Thanks Kathrin,

That worked just fine. Thanks for the reply Niels, I will use the first approach though.


All times are GMT -4. The time now is 07:50.