CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM (http://www.cfd-online.com/Forums/openfoam/)
-   -   Reference "mesh" inside a class (http://www.cfd-online.com/Forums/openfoam/81727-reference-mesh-inside-class.html)

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_.

Thanks,

Tony

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

Kathrin

ngj November 5, 2010 05:21

Hi Tony

Alternatively, your constructor call could be

Code:

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

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


}

where mesh_ is defined as follows in your header file:
Code:

const fvMesh & mesh_;
Best regards,

Niels

tonyuprm November 5, 2010 11:30

Thanks Kathrin,

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

Tony


All times are GMT -4. The time now is 22:53.