Part1 网格
primitive系列
1 Foam::primitiveMesh
Foam::primitiveMesh
这个类的官方介绍是
Cell-face mesh analysis engine
是一个抽象类,用于组织网格并处理网格的基本计算,如面积、体积。它的构造函数很简单,如下
//- Construct from components
primitiveMesh
(
const label nPoints,
const label nInternalFaces,
const label nFaces,
const label nCells
);
甚至其中一些函数是纯虚函数,只有函数原型,只能在派生类中定义
// Primitive mesh data
//- Return mesh points
virtual const pointField& points() const = 0;
//- Return faces
virtual const faceList& faces() const = 0;
//- Face face-owner addressing
virtual const labelList& faceOwner() const = 0;
//- Face face-neighbour addressing
virtual const labelList& faceNeighbour() const = 0;
//- Return old points for mesh motion
virtual const pointField& oldPoints() const = 0;
2 Foam::PrimitivePatch
与Foam::primitiveMesh
类比较类似的是Foam::PrimitivePatch
,其官方介绍为:
A list of faces which address into the list of points.
The class is templated on the face type (e.g. triangle, polygon etc.)
and on the list type of faces and points so that it can refer to
existing lists using UList and const pointField& or hold the storage
using List and pointField.
用于储存一个边界面(patch)的点坐标和面,可以执行一些基本几何计算,构造函数很简单
//- Construct from components
PrimitivePatch
(
const FaceList& faces,
const Field<PointType>& points
);
poly系列
1 Foam::polyMesh
Foam::polyMesh
是Foam::primitiveMesh
的唯一派生类。其官方介绍为
Mesh consisting of general polyhedral cells.
可以根据IOobject构造
//- Construct from IOobject
explicit polyMesh(const IOobject& io);
该构造函数的实现见https://cpp.openfoam.org/v9/polyMesh_8C_source.html#l00163
也就是Foam::polyMesh
可以从文件中读取网格,这是基类Foam::primitiveMesh
不能做到的。除此之外,Foam::polyMesh
还定义了基类中的纯虚函数
//- Return raw points
virtual const pointField& points() const;
//- Return raw faces
virtual const faceList& faces() const;
//- Return face owner
virtual const labelList& faceOwner() const;
//- Return face neighbour
virtual const labelList& faceNeighbour() const;
//- Return old points for mesh motion
virtual const pointField& oldPoints() const;
还需注意的是,该类的私有数据成员包含了边界网格
//- Boundary mesh
mutable polyBoundaryMesh boundary_;
Foam::polyBoundaryMesh
派生自Foam::polyPatchList
,而Foam::polyPatchList
是Foam::polyPatch
的列表。Foam::polyPatch
派生自上文中提及的Foam::PrimitivePatch
。
简单理解:polyBoundaryMesh
是一个列表,该列表中的每一个元素都是polyPatch
类型的,而polyPatch
类型来自PrimitivePatch
2 Foam::polyPatch
Foam::polyPatch
派生自Foam::primitivePatch
,其官方介绍为:
A patch is a list of labels that address the faces in the global face list.
The patch can calculate its own edges based on the global faces.
Patch also contains all addressing between the faces.
构造函数如下:
//- Construct from components
polyPatch
(
const word& name,
const label size,
const label start,
const label index,
const polyBoundaryMesh& bm,
const word& patchType
);
//- Construct from dictionary
polyPatch
(
const word& name,
const dictionary& dict,
const label index,
const polyBoundaryMesh& bm,
const word& patchType
);
也就是说,该类可以从文件(dictionary)构造,形成边界网格
fv系列
1 Foam::fvMesh
Foam::fvMesh
派生自Foam::polyMesh
(当然也派生自其他基类),是最重要也最常用的网格类。其官方介绍如下:
Mesh data needed to do the Finite Volume discretisation.
NOTE ON USAGE:
fvMesh contains all the topological and geometric information
related to the mesh. It is also responsible for keeping the data
up-to-date. This is done by deleting the cell volume, face area,
cell/face centre, addressing and other derived information as
required and recalculating it as necessary. The fvMesh therefore
reserves the right to delete the derived information upon every
topological (mesh refinement/morphing) or geometric change (mesh
motion). It is therefore unsafe to keep local references to the
derived data outside of the time loop.
可从IOobject构造
//- Construct from IOobject
explicit fvMesh(const IOobject& io);
一个经典的例子是位于/opt/openfoam9/src/OpenFOAM/include
的createMesh.H
文件。该文件包含了创建fvMesh网格的代码,是所有求解器必须使用的
Foam::Info
<< "Create mesh for time = "
<< runTime.timeName() << Foam::nl << Foam::endl;
Foam::fvMesh mesh
(
Foam::IOobject
(
Foam::fvMesh::defaultRegion,
runTime.timeName(),
runTime,
Foam::IOobject::MUST_READ
)
);
所以说,读取网格文件是很简单的,如果项目中有网格文件const/polyMesh
(该文件一般由blockMesh命令生成,具体见手册),那么只要运行上述代码,即可读入网格对象。
需要注意的是,Foam::fvMesh
中包含有关边界的私有数据
//- Boundary mesh
fvBoundaryMesh boundary_;
Foam::fvBoundaryMesh
派生自Foam::fvPatchList
,而Foam::fvPatchList
是Foam::fvPatch
的列表。有趣的是,Foam::fvPatch
并不派生自上文中提及的Foam::polyPatch
。
简单理解:fvBoundaryMesh
是一个列表,该列表中的每一个元素都是fvPatch
类型的。
2 Foam::fvPatch
Foam::fvPatch
并不是派生自Foam::polyPatch
,其官方介绍如下:
A finiteVolume patch using a polyPatch and a fvBoundaryMesh
构造函数如下
//- Construct from polyPatch and fvBoundaryMesh
fvPatch(const polyPatch&, const fvBoundaryMesh&);
Part2 场
记住:场就是增强版本的数组
Foam::Field
派生自List<Type>
,是一个数组(列表),既没有网格也没有量纲,但是可以完成场之间的计算(比如max,sum,sqr,pow,+,- )
对于不同类型的场,Foam::Field
的别名如下:
template<class Type> class Field;
typedef Field<label> labelField;
typedef Field<scalar> scalarField;
typedef Field<vector> vectorField;
typedef Field<sphericalTensor> sphericalTensorField;
typedef Field<symmTensor> symmTensorField;
typedef Field<tensor> tensorField;
Foam::DimensionedField
派生自Foam::Field
,添加了网格和量纲,但是没有边界条件
Foam::GeometricField
派生自Foam::DimensionedField
,内置boundary类,考虑了边界条件,是使用最广泛的场类型,它有许多别名:
typedef GeometricField<scalar, fvPatchField, volMesh> volScalarField;
typedef GeometricField<vector, fvPatchField, volMesh> volVectorField;
typedef GeometricField<sphericalTensor, fvPatchField, volMesh>
volSphericalTensorField;
typedef GeometricField<symmTensor, fvPatchField, volMesh> volSymmTensorField;
typedef GeometricField<tensor, fvPatchField, volMesh> volTensorField;
typedef GeometricField<scalar, fvsPatchField, surfaceMesh> surfaceScalarField;
typedef GeometricField<vector, fvsPatchField, surfaceMesh> surfaceVectorField;
typedef GeometricField<sphericalTensor, fvsPatchField, surfaceMesh>
surfaceSphericalTensorField;
typedef GeometricField<symmTensor, fvsPatchField, surfaceMesh>
surfaceSymmTensorField;
typedef GeometricField<tensor, fvsPatchField, surfaceMesh> surfaceTensorField;
typedef GeometricField<scalar, pointPatchField, pointMesh> pointScalarField;
typedef GeometricField<vector, pointPatchField, pointMesh> pointVectorField;
typedef GeometricField<sphericalTensor, pointPatchField, pointMesh>
pointSphericalTensorField;
typedef GeometricField<symmTensor, pointPatchField, pointMesh>
pointSymmTensorField;
typedef GeometricField<tensor, pointPatchField, pointMesh> pointTensorField;
其中类Foam::fvPatchField
和Foam::fvsPatchField
用于考虑边界条件
一个经典的案例是读取初始温度场:
Info << "Reading field T\n"
<< endl;
volScalarField T //温度场
(
IOobject(
"T",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE),
mesh);