OpenFOAM定义方程和源项并求解

OpenFOAM的实质

OpenFOAM中的FOAMField Operation and Manipulation的缩写, 所以其实质是对标量场和矢量场进行运算和处理.
OpenFOAM中的场的定义方式如下.
方式一:从文件中读取场信息

volScalarField T
(
    IOobject
    (
        "T",					//输入输出的文件名称
        runTime.timeName(),		//输入输出的文件夹名称
        mesh,
        IOobject::MUST_READ,
        IOobject::AUTO_WRITE	//自动输出场信息
    ),
    mesh
);

方式二:在代码中初始化场

volScalarField source1(
	   IOobject(
	       "source1",
	       runTime.timeName(),
	       mesh,
	       IOobject::NO_READ,	//不从文件中读,而是直接在代码中生成
	       IOobject::NO_WRITE),
	   mesh,
	   dimensionedScalar("tmp", mydimension, 1.0));

一种方程的求解办法

求解如下非线性方程
∂ T ∂ t = α ▽ 2 T + κ ( 1 − ∣ ▽ T ∣ ) \frac{\partial T}{\partial t} =\alpha \bigtriangledown^2T+\kappa \left ( 1-\left | \bigtriangledown T \right | \right ) tT=α2T+κ(1T)其物理意义是波的平行层传播, T T T表示传播的距离, t t t表示伪时间, κ \kappa κ用于调整单位. 这里的非稳态项是用于增强迭代过程的稳定性.

代码

pefFoam.C文件包含main函数

/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Copyright (C) 2011-2021 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/>.

Application
    pefFoam

Description
    Solves a simple Possion equation to finish the burn-back analysis
    of propellant grain.

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

#include "fvCFD.H"
#include "simpleControl.H"

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

int main(int argc, char *argv[])
{
#include "setRootCaseLists.H"
#include "createTime.H"
#include "createMesh.H"

    simpleControl simple(mesh);

#include "createFields.H"

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

    Info << "\nCalculating temperature distribution\n"
         << endl;
    //定义单位m/s
    const dimensionSet mydimension(0, 1, -1, 0, 0, 0, 0);
    //定义源项souce1
    volScalarField source1(
        IOobject(
            "source1",
            runTime.timeName(),
            mesh,
            IOobject::NO_READ,
            IOobject::NO_WRITE),
        mesh,
        dimensionedScalar("tmp", mydimension, 1.0));
    //初始化源项souce2
    volScalarField source2(
        IOobject(
            "source2",
            runTime.timeName(),
            mesh,
            IOobject::NO_READ,
            IOobject::AUTO_WRITE),
        mesh,
        dimensionedScalar("tmp", mydimension, 0.0));
    //开始计算
    while (simple.loop(runTime))
    {
        Info << "Time = " << runTime.timeName() << nl << endl;
        source2 = mag(fvc::grad(T)) * dimensionedScalar("tmp", mydimension, 1.0);
        while (simple.correctNonOrthogonal())
        {
            fvScalarMatrix TEqn(
                fvm::ddt(T) == fvm::laplacian(DT, T) + source1 - source2);
            TEqn.solve();
        }

        runTime.write();

        Info << "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
             << "  ClockTime = " << runTime.elapsedClockTime() << " s"
             << nl << endl;
    }

    Info << "End\n"
         << endl;

    return 0;
}

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

createFields.H包含场的初始化读取

Info<< "Reading field T\n" << endl;

volScalarField T
(
    IOobject
    (
        "T",
        runTime.timeName(),
        mesh,
        IOobject::MUST_READ,
        IOobject::AUTO_WRITE
    ),
    mesh
);


Info<< "Reading transportProperties\n" << endl;

IOdictionary transportProperties
(
    IOobject
    (
        "transportProperties",
        runTime.constant(),
        mesh,
        IOobject::MUST_READ_IF_MODIFIED,
        IOobject::NO_WRITE
    )
);


Info<< "Reading diffusivity DT\n" << endl;

dimensionedScalar DT
(
    transportProperties.lookup("DT")
);

使用OpenFOAM自带的wmake命令编译
源代码和案例文件见https://gitee.com/jedi-knight/pef-foam
请添加图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

jedi-knight

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值