openFOAM中的Field

就是域的创建,速度域等等量直接在这里存储

他分别位于若干个位置,所以下面会单独罗列,其类间关系如下
在这里插入图片描述
这里对其中的Fields DimensionedFields GeometricFields进行解读

Field

其路径为src/OpenFOAM/fields/Fields/Field

他包含若干个头文件:

FieldFunctions.H
FieldFunctionsM.H
FieldM.H
Field.C
FieldFunctions.C
FieldFunctionsM.C

我们从头文件开始解读,代码如下:

template<class Type>
class Field
:
    public tmp<Field<Type>>::refCount,
    public List<Type>
{    static const char* const typeName;
      各类功能性函数
}

这个类并没有使用新的变量,而是直接继承了List<Type>,相当于存储结构是一维数组。主要功能性函数为:
1.构造与析构函数
2.map函数,replace函数,拷贝用函数
3.= += *= /= << >>的操作符重定义
我们给出一个构造函数的源码,可以看出这里的赋值和初始化操作主要依赖List中的构造函数:

template<class Type>
Foam::Field<Type>::Field(const label size)
:
    List<Type>(size)
{}

DimensionedField

其路径为src/OpenFOAM/fields/DimensionedFields

它包含若干个头文件:

DimensionedFieldI.H
DimensionedField.C
DimensionedFieldIO.C

我们首先看他的注释介绍:

Description
    Field with dimensions and associated with geometry type GeoMesh which is
    used to size the field and a reference to it is maintained.
    带有单位的域,并且和GeoMesh类型相关,用网格信息进行域的尺寸控制

头文件的源码如下:

template<class Type, class GeoMesh>
class DimensionedField
:
    public regIOobject,
    public Field<Type>
{    成员变量:
     //- Reference to mesh
     const Mesh& mesh_;
     //- Dimension set for this field
     dimensionSet dimensions_;
     成员函数:
     构造和析构函数
     域读取用的函数
     网格和单位的返回
     replace   T   average   weightedAverage函数
     =    +=    -=   /=   */    <<    >>的操作符重定义
};     

我们给出其中一个构造函数的源码,可以看出这个类的初始化,主要依赖一些基础类型的构造函数

template<class Type, class GeoMesh>
DimensionedField<Type, GeoMesh>::DimensionedField
(
    const IOobject& io,
    const Mesh& mesh,
    const dimensionSet& dims,
    const Field<Type>& field
)
:
    regIOobject(io),
    Field<Type>(field),
    mesh_(mesh),
    dimensions_(dims)
{
    if (field.size() && field.size() != GeoMesh::size(mesh))
    {
        FatalErrorInFunction
            << "size of field = " << field.size()
            << " is not the same as the size of mesh = "
            << GeoMesh::size(mesh)
            << abort(FatalError);
    }
}

可以看出io代表的是文件流的初始化,而Mesh dimensionSet Field<Type>也是直接通过构造函数初始化给它的成员变量。在初始化结束后,代码会检查当前的fieldsize是否和meshsize一致。

就是说这里除去域本身,还添加了文件流,和网格的变量。

GeometricField

其路径为src/OpenFOAM/fields/GeometricFields

它包含若干个头文件:

GeometricFieldI.H
GeometricField.C
Boundary.C
GeometricFieldFunctions.H
GeometricFieldFunctions.C

注释介绍就比较简单,只是说明我们最终使用的比较多的是这个类:

Description
    Generic GeometricField class.

它在前一个父类的基础上添加了更多的成员变量

template<class Type, template<class> class PatchField, class GeoMesh>
class GeometricField
:
    public DimensionedField<Type, GeoMesh> 
{    除去定义新的类型之外,还给定了一个新的类Boundary
     成员变量:
        //  Used to trigger(触发) the storing of the old-time value
        mutable label timeIndex_;
        //- Pointer to old time field
        mutable GeometricField<Type, PatchField, GeoMesh>* field0Ptr_;
        //-  Pointer to previous iteration (used for under-relaxation)
        mutable GeometricField<Type, PatchField, GeoMesh>* fieldPrevIterPtr_;
        //- Boundary Type field containing boundary field values
        Boundary boundaryField_;
      成员函数:
      读取文件
      构造函数和析构函数
      返回内部或者边界域
      返回时间戳
      松弛和替换
      最大最小值的返回
      =   ==   +=   -=   *=   /=   <<   >>
};

可以看出,除去原来的和文件流以及网格相关的量之外,还添加了边界和时间戳。并且通过成员变量中的指针,建立了不同时间戳的域之间的联系。

这里再给出一个构造函数的源码,可以看出这里的构造函数的初始化,仍然是主要依赖基础类的构造函数的

template<class Type, template<class> class PatchField, class GeoMesh>
Foam::GeometricField<Type, PatchField, GeoMesh>::GeometricField
(
    const IOobject& io,
    const Mesh& mesh,
    const dimensionSet& ds,
    const wordList& patchFieldTypes,
    const wordList& actualPatchTypes
)
:
    Internal(io, mesh, ds, false),
    timeIndex_(this->time().timeIndex()),
    field0Ptr_(nullptr),
    fieldPrevIterPtr_(nullptr),
    boundaryField_(mesh.boundary(), *this, patchFieldTypes, actualPatchTypes)
{
    if (debug)
    {
        InfoInFunction << "Creating temporary" << endl << this->info() << endl;
    }

    readIfPresent();
}
finiteVolume中的Field

其路径为src/finiteVolume/fields/

我们常用的一些类均在volFieldsFwd.H

//类的前置声明
class volMesh;
template<class Type>  class fvPatchField;
template<class Type, template<class> class PatchField, class GeoMesh>  class GeometricField;
//常用的类的类名定义
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;

这里主要用到了类GeometricField,其他类型作为模板中的类型使用。

这里简单进行一下总结:
1.Field是最基础的域,它继承了List的一维数组的结构用来存储域的元素
2.DimensionedField则是继承自Field,它在Field的基础上添加了和网格Mesh相关以及文件流regIOobject相关的量
3.GeometricField则是继承自DimensionedField,它又在DimensionedField的基础上添加了和边界相关的量以及时间戳,并建立了不同时间戳下的域之间的联系。
4.最终通过GeometricField的template模板中的类型指定为特定类型,定义出我们平时使用的域的类型

  • 6
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值