Code of the Week #31: type empty

#201918

在 OpenFOAM 中,如果使用二维 (或一维) 仿真时,要求在第三个方向使用一个网格的厚度,同时在边界上使用以下设置:

boundaryNAME
{
    type            empty;
}

empty 是一个特殊的边界,意思是在这一边界所在的法向上的未知数不做求解,并且为 0 。我们来看一看 empty 是如何实现的。

在第 28 期 Code of the Week #28: type fixedValue,我们谈到一个边界上有四个系数要确定,当这四个系数确定了,这个边界也就确定了。再将这四个系数及其公式表述一下:

边界上的值或梯度,一般采用以下方式

\phi_f = A_1 \phi_c + B_1\\ \nabla\phi_f = A_2 \phi_c + B_2

其中 \phi_c 表示边界所在的网格的中心值,其余为系数。

OpenFOAM 中,对应于上式中的四个系数的函数有

Func Coefficient
valueInternalCoeffs A_1
valueBoundaryCoeffs B_1
gradientInternalCoeffs A_2
gradientBoundaryCoeffs B_2

那么,对于 empty 边界,这四个系数要怎么确定呢?根据要求,这四个系数都需要设为 0,在 OpenFOAM 中,不对其值进行设置,而是对其边界中所存在的 Field 的长度使用 0。因此,在代码中
src/finiteVolume/fields/fvPatchFields/constraint/empty/emptyFvPatchField.H

#include "emptyFvPatch.H"
...
        // Evaluation functions

            //- Update the coefficients associated with the patch field
            //  This only checks to see the case is actually 1D or 2D
            //  for which this boundary condition is valid
            void updateCoeffs();


            //- Return the matrix diagonal coefficients corresponding to the
            //  evaluation of the value of this patchField with given weights
            virtual tmp<Field<Type> > valueInternalCoeffs
            (
                const tmp<scalarField>&
            ) const
            {
                return tmp<Field<Type> >(new Field<Type>(0));
            }

            //- Return the matrix source coefficients corresponding to the
            //  evaluation of the value of this patchField with given weights
            virtual tmp<Field<Type> > valueBoundaryCoeffs
            (
                const tmp<scalarField>&
            ) const
            {
                return tmp<Field<Type> >(new Field<Type>(0));
            }

            //- Return the matrix diagonal coefficients corresponding to the
            //  evaluation of the gradient of this patchField
            tmp<Field<Type> > gradientInternalCoeffs() const
            {
                return tmp<Field<Type> >(new Field<Type>(0));
            }

            //- Return the matrix source coefficients corresponding to the
            //  evaluation of the gradient of this patchField
            tmp<Field<Type> > gradientBoundaryCoeffs() const
            {
                return tmp<Field<Type> >(new Field<Type>(0));
            }

emptyFvPatch.H 位于 src/finiteVolume/fvMesh/fvPatches/constraint/empty,规定了该类边界的数据长度为 0。

class emptyFvPatch
:
    public fvPatch
{
    // Private data

        //- Dummy face-cell addressing
        const labelList::subList faceCells_;

    ...
    // Member Functions

        // Access

            virtual label size() const
            {
                return 0;
            }

            //- Return faceCells of zero size
            virtual const unallocLabelList& faceCells() const;
};

而对于 emptyFvPatchField.H 里面的 new Field<Type>(0) 则是对该项进行初始化,该数据的长度为 0 。该段程序位于 src/OpenFOAM/fields/Fields/Field/Field.H

         //- Construct given size
         //  For temporary fields that are initialised after construction
         inline explicit Field(const label len);