OpenFOAM手动网格分块
1. 通过OpenFOAM的格式自编程来对各个cell命名,确定他们所属的processor
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 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
scalar2Label
codeBy CloudBird, HIT,cloudbird7@foxmail.com
\*---------------------------------------------------------------------------*/
#include "fvCFD.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int main(int argc, char *argv[])
{
#include "setRootCase.H"
#include "createTime.H"
#include "createMesh.H"
const volVectorField& center = mesh.C();
labelIOList finalDecomp
(
IOobject
(
"manualDecomposition",
mesh.facesInstance(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE,
false
),
labelList (center.size())
);
Info<< "Making manualDecomposition file\n" << endl;
scalar x_=0,y_=0;
label num0 = 0, num1 = 0, num2 = 0, num3 = 0;
//这里是将网格分为四块,分块的依据是下边if的判断语句,也就是先挖一个小方框出来,然后对剩下的部分分成三块,并输出分块之后每一块的cell的数量。
forAll(center, cellID)
{
x_ = center[cellID].x();
y_ = center[cellID].y();
if (x_ > -0.75 && x_ < 0.75 &&y_>-0.75&&y_ < 0.75)
{
finalDecomp[cellID] = 0;
num0++;
}
else
{
if (x_ < 0)
{
finalDecomp[cellID] = 1;
num1++;
}
else if (x_ < 3)
{
finalDecomp[cellID] = 2;
num2++;
}
else
{
finalDecomp[cellID] = 3;
num3++;
}
}
}
Info << "num0 = " << num0 << nl << "num1 = " << num1 << nl << "num2 = " << num2 << nl << "num3 = " << num3 << nl;
finalDecomp.write();
Info<< "Done\n" << endl;
return 0;
}
// ************************************************************************* //
这样会在constant文件夹下边生成一个名为manualDecomposition的文件,这个文件本质上是一个标量文件,用于标记各个cell所属的processor。
2. 在system文件夹下的decomposeParDict中修改分割方式
numberOfSubdomains 4;
method manual;
manualCoeffs
{
dataFile "manualDecomposition";
}
其中dataFile的名字要改成我们生成的文件的名字,也就是maualDecomposition,还需要注意的一点是numberOfSubdomains的数量要和你在maulDecomposition中定义的数量一致。
3.之后直接decomposePar就是按照手动分割网格的方式对你定义的网格进行分割。




文件的编译按照一般OpenFOAM文件编译的方式进行,参考http://dyfluid.com/docs/book/_book/
参考文章:
https://blog.csdn.net/CloudBird07/article/details/105349031
https://www.dazhuanlan.com/2019/08/16/5d55fc7975c16/