当前位置:网站首页>OpenFOAM提取等职面并计算面积
OpenFOAM提取等职面并计算面积
2022-08-03 03:53:00 【jedi-knight】
OpenFOAM中的等值面类
OpenFOAMV9中的isoSurface类可以用来提取等值面。
该类的实例化方式为:
sampledSurfaces::isoSurface isosurf = sampledSurfaces::isoSurface(
"isoSurface",
mesh,
isoSurfaceDict);
"isoSurface"是一个自定义的名字(一般取对象名),mesh是所研究问题的网格,isoSurfaceDict是一个数据字典,该数据字典的内容如下
/*--------------------------------*- C++ -*----------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org \\ / A nd | Version: 9 \\/ M anipulation | ------------------------------------------------------------------------------- Description Writes out iso-surface files with interpolated field data in VTK format. \*---------------------------------------------------------------------------*/
FoamFile
{
format ascii;
class dictionary;
location "system";
object isoSurfaceDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
type isoSurface;
isoField p; //需要提取等值线的场,这里是压力场
isoValue 10; //等值线的数值,这里三10Pa
filter full;
interpolate yes;
// ************************************************************************* //
有了isosurf这个对象之后,可以用以下一行代码完成等值面提取的工作
isosurf.sample(p);
提取完成等值面后,可以获得等值面的面单元向量和等值面的顶点坐标
//等值面的面单元向量
faceList faces = isosurf.faces();
//等值面的顶点坐标
pointField points = isosurf.points();
points描述了该等值面是由哪些点构成的,提供了这些点的坐标信息。faces描述了这些点的连接关系。如果要访问第faceI个单元面的面积,可以使用以下代码:
mag(faces[faceI].area(points))
为了方便可视化,还可以将得到的等值面输出为VTK文件
vtkSurfaceWriter vtkWriter = vtkSurfaceWriter(IOstream::streamFormat::ASCII);
vtkWriter.write("postProcess",
"someContours",
points,
faces);
代码
教程案例
以教程案例pitzDaily为例子,将其复制到自己的文件夹。使用simpleFoam求解器完成求解,结果如下:
修改求解器
在simpleFoam求解器源代码的基础上添加有关等值面的内容,改进后的求解器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 isoSimpleFoam Description Steady-state solver for incompressible, turbulent flow, using the SIMPLE algorithm. \*---------------------------------------------------------------------------*/
#include "fvCFD.H"
#include "singlePhaseTransportModel.H"
#include "kinematicMomentumTransportModel.H"
#include "simpleControl.H"
#include "pressureReference.H"
#include "fvModels.H"
#include "fvConstraints.H"
//有关等值面的头文件
#include "sampledIsoSurface.H"
#include "vtkSurfaceWriter.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int main(int argc, char *argv[])
{
#include "postProcess.H"
#include "setRootCaseLists.H"
#include "createTime.H"
#include "createMesh.H"
#include "createControl.H"
#include "createFields.H"
#include "initContinuityErrs.H"
//读取等值线字典
dictionary isoSurfaceDict = IOdictionary(IOobject(
"isoSurfaceDict",
mesh.time().system(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE));
turbulence->validate();
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Info << "\nStarting time loop\n"
<< endl;
while (simple.loop(runTime))
{
Info << "Time = " << runTime.timeName() << nl << endl;
fvModels.correct();
// --- Pressure-velocity SIMPLE corrector
{
#include "UEqn.H"
#include "pEqn.H"
}
laminarTransport.correct();
turbulence->correct();
//修改等值线字典中的isoValue数值
isoSurfaceDict.set("isoValue", 7);
//实例化isoSurface对象
sampledSurfaces::isoSurface isosurf = sampledSurfaces::isoSurface(
"isoSurface",
mesh,
isoSurfaceDict);
//提取等值面
isosurf.sample(p);
//等值面的面单元向量
faceList faces = isosurf.faces();
//等值面的顶点坐标
pointField points = isosurf.points();
//计算等值面的面积
scalar area = 0;
forAll(faces, faceI)
{
area += mag(faces[faceI].area(points));
}
Info << "面积:" << area << endl;
//将等值面输出为VTK文件
vtkSurfaceWriter vtkWriter = vtkSurfaceWriter(IOstream::streamFormat::ASCII);
vtkWriter.write("postProcess",
"someContours",
points,
faces);
runTime.write();
Info << "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
<< " ClockTime = " << runTime.elapsedClockTime() << " s"
<< nl << endl;
}
Info << "End\n"
<< endl;
return 0;
}
// ************************************************************************* //
编译的过程见OpenFOAM用户手册,这里仅介绍基本步骤。
新建Make文件夹,在Make文件夹中新建files文件,写入编译信息
isoSimpleFoam.C
EXE = $(FOAM_USER_APPBIN)/isoSimpleFoam
在Make文件夹中新建options文件,写入依赖信息
EXE_INC = \
-I$(LIB_SRC)/MomentumTransportModels/momentumTransportModels/lnInclude \
-I$(LIB_SRC)/MomentumTransportModels/incompressible/lnInclude \
-I$(LIB_SRC)/transportModels/lnInclude \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/sampling/lnInclude \
-I$(LIB_SRC)/surfMesh/lnInclude
EXE_LIBS = \
-lmomentumTransportModels \
-lincompressibleMomentumTransportModels \
-ltransportModels \
-lfiniteVolume \
-lmeshTools \
-lfvModels \
-lfvConstraints \
-lsampling\
-lsurfMesh
使用wmake命令完成编译,得到isoSimpleFoam求解器。该求解器将计算pitzDaily案例中压力为7Pa的等值面面积,并输出为VTK文件。
7Pa等值面
计算完成后,使用paraview读取postProcess文件夹下的someContours.vtk文件,可得到下图
这就是提取得到的等值面,其面积为9.043e-05
边栏推荐
- v-on指令:为元素绑定事件
- Shell编程的条件语句
- Oracle EMCC可以独立安装吗?还是必须安装到数据库服务器上?
- Domino服务器SSL证书安装指南
- lc marathon 8.2
- SMP 需要考虑的事情
- ESP8266-Arduino编程实例-LED点阵驱动(基于Max7219)
- 自考六级雅思托福备战之路
- Chinese valentine's day??To the liver is the way!!!!!Auto. Js special position control method
- Ask next useful SQL server flink - SQL - connector - essentially a CDC - 2
猜你喜欢
随机推荐
基于flowable的upp(统一流程平台)运行性能优化(2)
lc marathon 8.2
高等代数_证明_矩阵乘以自身的转置的特征值不小于0
uniapp中动态修改导航栏标题
Mysql如何建立索引实现语句优化
肖sir__面试接口测试
ClickHouse uninstall and reinstall
肖sir___面试就业课程____app
How to write test cases in software testing technology (2)
软件测试技术之如何编写测试用例(2)
GD32学习笔记(3)NAND Flash管理
找不到符号@SuperBuilder,你以为真的是Lombok的问题?
PyTorch installation - error when building a virtual environment in conda before installing PyTorch
Chapter 8 Character Input Output and Input Validation
【leetcode热题Hot100】——任务调度器
【STM32】入门(四):外部中断-按键通过中断动作
DC-6靶场下载及渗透实战详细过程(DC靶场系列)
MATLAB(5)绘图
SeleniumWebDriver扩展插件开发
DOM破环和两个实验的复现









