volMesh class in OpenFOAM

volMesh class in OpenFOAM

The volMesh class is defined in volMesh.H:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class volMesh
:
public GeoMesh<fvMesh>
{

public:

// Constructors

//- Construct from fvMesh
explicit volMesh(const fvMesh& mesh)
:
GeoMesh<fvMesh>(mesh)
{}


// Member Functions

//- Return size
label size() const
{
return size(mesh_);
}

//- Return size
static label size(const Mesh& mesh)
{
return mesh.nCells();
}

//- Return cell centres
const volVectorField& C()
{
return mesh_.C();
}
};

It is a subclass of GeoMesh when the template type of GeoMesh is fvMesh. The class GeoMesh is defined in GeoMesh.H as:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
template<class MESH>
class GeoMesh
{

protected:

// Protected data

//- Reference to Mesh
const MESH& mesh_;


public:

// Public Typedefs

typedef MESH Mesh;
typedef typename MESH::BoundaryMesh BoundaryMesh;


// Constructors

//- Construct from MESH
explicit GeoMesh(const MESH& mesh)
:
mesh_(mesh)
{}


// Member Functions

//- Return the object registry
const objectRegistry& thisDb() const
{
return mesh_;
}


// Member Operators

//- Return reference to polyMesh
const MESH& operator()() const
{
return mesh_;
}
};

The MESH here will be substitute as fvMesh. The fvMesh is also a class defined in fvMesh.H:

1
2
3
4
5
6
7
8
9
10
11
class fvMesh
:
public polyMesh,
public lduMesh,
public surfaceInterpolation,
public fvSchemes,
public fvSolution,
public data
{
........
}

The reason why I dig into this part of the code is because when e.g. we have a object called vf with a type of GeometricField<Type, fvPatchField, volMesh>& vf. And if we call vf.mesh(), it will try to call mesh() function of the GeometricField class. It should be noted here, the GeoMesh has a type of volMesh. But GeometricField dose not have a function called mesh(). But GeometricField inherits class DimensionedField:

1
2
3
4
5
6
7
template<class Type, template<class> class PatchField, class GeoMesh> // GeoMesh <=> volMesh
class GeometricField
:
public DimensionedField<Type, GeoMesh>
{
......
}

And unsurprisingly, in DimensionedField has a access member function called mesh():

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// in DimensionedField.H

//- Reference to mesh
const Mesh& mesh_;

//- Return mesh
inline const Mesh& mesh() const;

// in DimensionedFieldI.H
template<class Type, class GeoMesh>
inline const typename GeoMesh::Mesh&
Foam::DimensionedField<Type, GeoMesh>::mesh() const
{
return mesh_;
}

And the type Mesh is defined as:

1
typedef typename GeoMesh::Mesh Mesh;

As what it shown before, GeoMesh::Mesh is defined in class GeoMesh as:

1
typedef MESH Mesh;

Here the MESH need to be specified with a certain type. As specified in volMesh class, the MESH type here is fvMesh. Therefore, MESH, Mesh are all fvMesh. So, vf.mesh() has a type of fvMesh.