OpenFoam-6 导入并编译一个新湍流模型

OpenFoam-6 导入并编译一个新湍流模型

本文参考了以下链接
http://hassankassem.me/posts/newturbulencemodel/#new-version
https://pingpong.chalmers.se/public/courseId/7056/lang-en/publicPage.do?item=3256524
https://www.cfd-online.com/Forums/openfoam-programming-development/181508-addition-new-turbulence-models-giviing-errors.html#post660305
https://www.cfd-online.com/Forums/openfoam/199105-error-during-add-turbulence-model-openfoam-5-0-a.html
https://www.cfd-online.com/Forums/openfoam-programming-development/191446-symbol-lookup-error-simplefoam.html

一 准备原始模型

首先,在终端在定位到你的工作目录,然后执行以下操作(如果你不熟悉命令行操作,也可以按注释进行图形界面的操作)

#从$FOAM_SRC/TurbulenceModels/turbulenceModels/RAS/ 中复制kOmegaSST文件夹并改名为newkOmegaSST
cp  -r $FOAM_SRC/TurbulenceModels/turbulenceModels/RAS/kOmegaSST $FOAM_RUN/newkOmegaSST   
# 进入你新建的文件夹
cd newkOmegaSST  
# 将文件夹中的kOmegaSST.H命名为newkOmegaSST.H
mv kOmegaSST.H newkOmegaSST.H
# 将文件夹中的kOmegaSST.C命名为newkOmegaSST.C
mv kOmegaSST.C newkOmegaSST.C
# 复制 $FOAM_SRC/TurbulenceModels/incompressible中的Make文件夹到你的工作目录
cp -r $FOAM_SRC/TurbulenceModels/incompressible/Make/ .  
cp -r $FOAM_SRC/TurbulenceModels/incompressible/turbulentTransportModels/turbulentTransportModels.C maketurbulentTransportModels.C

二 修改编译配置

在前述操作中,你从OpenFOAM的源文件中复制了一个名为turbulentTransportModels.C的文件,并将其命名为maketurbulentTransportModels.C
现在打开该文件,仅保留第一个#include声明及第一个宏命令,其余内容全部删除,并添加下述内容:

#include "newkOmegaSST.H"
makeRASModel(newkOmegaSST);

修改完成后的文件如下所示
在这里插入图片描述
接着你应当修改Make文件夹下的files文件
首先打开这个文件,并清空里面的内容,并加入如下代码,最后保存退出
这段代码表示了.so文件的生成路径,也可以生成在当前目录下,需要调用的时候指定.so文件所在目录就行

maketurbulentTransportModels.C
LIB = $(FOAM_USER_LIBBIN)/libmyincompressibleTurbulenceModels

如下图所示

在这里插入图片描述
对Make文件夹下的options作如下操作
清空该文件原始内容,并添加如下代码,保存退出.

EXE_INC = \
    -I$(LIB_SRC)/TurbulenceModels/turbulenceModels/lnInclude \
    -I$(LIB_SRC)/TurbulenceModels/incompressible/lnInclude \
    -I$(LIB_SRC)/transportModels \
    -I$(LIB_SRC)/finiteVolume/lnInclude \
    -I$(LIB_SRC)/meshTools/lnInclude \

LIB_LIBS = \
    -lincompressibleTransportModels \
    -lturbulenceModels \
    -lfiniteVolume \
    -lmeshTools

如下图所示
在这里插入图片描述

三 修改.H 和.C 文件

采用gedit命令分别打开newkOmegaSST.H和newkOmegaSST.C文件,将原有出现kOmegaSST的地方使用newkOmegaSST进行替换,但使用sed命令进行替换时需要注意不要将基类替换,这里需要替换的地方较少我采用手动替换,以便清楚展示。
newkOmegaSST.H

/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Copyright (C) 2016-2018 OpenFOAM Foundation
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.

\*---------------------------------------------------------------------------*/

#include "newkOmegaSST.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{
namespace RASModels
{

// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

template<class BasicTurbulenceModel>
newkOmegaSST<BasicTurbulenceModel>::newkOmegaSST
(
    const alphaField& alpha,
    const rhoField& rho,
    const volVectorField& U,
    const surfaceScalarField& alphaRhoPhi,
    const surfaceScalarField& phi,
    const transportModel& transport,
    const word& propertiesName,
    const word& type
)
:
    Foam::kOmegaSST
    <
        eddyViscosity<RASModel<BasicTurbulenceModel>>,
        BasicTurbulenceModel
    >
    (
        type,
        alpha,
        rho,
        U,
        alphaRhoPhi,
        phi,
        transport,
        propertiesName
    )
{
    if (type == typeName)
    {
        this->printCoeffs(type);
    }
}


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace RASModels
} // End namespace Foam

// ************************************************************************* //

newkOmegaSST.H

/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Copyright (C) 2016-2018 OpenFOAM Foundation
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.

Class
    Foam::RASModels::kOmegaSST

Description
    Specialisation for RAS of the generic kOmegaSSTBase base class.
    For more information, see Description of kOmegaSSTBase.H

See also
    Foam::kOmegaSST

SourceFiles
    kOmegaSST.C

\*---------------------------------------------------------------------------*/

#ifndef newkOmegaSST_H
#define newkOmegaSST_H

#include "kOmegaSSTBase.H"
#include "RASModel.H"
#include "eddyViscosity.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{
namespace RASModels
{

/*---------------------------------------------------------------------------*\
                          Class kOmegaSST Declaration
\*---------------------------------------------------------------------------*/

template<class BasicTurbulenceModel>
class newkOmegaSST
:
    public Foam::kOmegaSST
    <
        eddyViscosity<RASModel<BasicTurbulenceModel>>,
        BasicTurbulenceModel
    >
{

public:

    typedef typename BasicTurbulenceModel::alphaField alphaField;
    typedef typename BasicTurbulenceModel::rhoField rhoField;
    typedef typename BasicTurbulenceModel::transportModel transportModel;


    //- Runtime type information
    TypeName("newkOmegaSST");


    // Constructors

        //- Construct from components
        newkOmegaSST
        (
            const alphaField& alpha,
            const rhoField& rho,
            const volVectorField& U,
            const surfaceScalarField& alphaRhoPhi,
            const surfaceScalarField& phi,
            const transportModel& transport,
            const word& propertiesName = turbulenceModel::propertiesName,
            const word& type = typeName
        );


    //- Destructor
    virtual ~newkOmegaSST()
    {}
};


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace RASModels
} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
    #include "newkOmegaSST.C"
#endif

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif

// ************************************************************************* //

四 编译

定位到newkOmegaSST文件夹,wclean,wmake进行编译
如图所示
在这里插入图片描述

五 调用新模型计算

复制simpleFoam中的pitzDaily算例至$FOAM_RUN文件夹,在system文件夹中的controlDict文件中添加以下语句

libs ("libmyincompressibleTurbulenceModels.so");

如图所示
在这里插入图片描述
如果之前自定义了生成的.so文件路径,则需要加上路径。

接下来打开constant文件夹中的turbulenceProperties替换湍流模型为newkOmegaSST
在这里插入图片描述
定位到pitzDaily文件夹,在终端执行计算命令,成功出现结果。
在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值