通常在流体计算中需要对某个特定区域进行处理(比如添加源项,可参考这篇文章OpenFOAM编程:VOF法与多孔介质模型相结合),这是就需要用到cellZone.
通常有两种产生cellZone的方式:
(1)从其他划分网格的工具中导入时,自然会对不同实体用cellZone区分。可参考这篇文章将fluentMeshing网格转换为openFoam网格
(2)在已有的网格上使用topoSet
命令生成cellZone
本文只关心第二种方式
本文使用icoFoam的cavity案例
为了告诉openFoam哪个区域要设置成cellZone,需要在system目录下编写topoSetDict文件
/*--------------------------------*- C++ -*----------------------------------*\========= |\\ / F ield | OpenFOAM: The Open Source CFD Toolbox\\ / O peration | Website: https://openfoam.org\\ / A nd | Version: 8\\/ M anipulation |
\*---------------------------------------------------------------------------*/
FoamFile
{version 2.0;format ascii;class dictionary;object topoSetDict;
}// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //actions
({name g; // 单元集合命名为gtype cellSet;action new;source cylinderToCell; // 圆柱区域sourceInfo{p1 (0.0 0.0 0); // 圆柱体上表面的中心点p2 (0.05 0 0); // 圆柱体下表面的中心点radius 0.03; // 圆柱半径}}{name grain; // 区域命名graintype cellZoneSet; action new;source setToCellZone;sourceInfo{set g; // 给定source信息,来自单元集合g}}
);// ************************************************************************* //
首先生成一个单元集合g,g由一个圆柱体确定。然后根据g再生成名称为grain的cellZone
接下来运行topoSet
命令即可获得名称为grain的cellZone
使用paraFoam
命令检查一下网格
下图是划分前的网格
下图是划分后的网格
蓝色区域就是名称为grain的cellZone
cellZone本质上是一个列表,每个元素记录了cell的序号。所以可以通过访问cellZone来设置给定区域的物理量。比如为了将grain处的压力p设置为30,可以将如下代码插入到icoFoam
求解器当中
labelUList cellListOfGrain=mesh.cellZones()["grain"];forAll(cellListOfGrain,i)
{p[cellListOfGrain[i]]=30;
}
p.write();
运行编译后的icoFoam
,可以得到如下结果