零基础学习OpenFOAM-从纯对流算例出发

零基础学习OpenFOAM-从纯对流算例出发从零开始的 OpenFOAM 从纯对流案例出发学会 OpenFOAM openfoam

大家好,欢迎来到IT知识分享网。

初学者上手OpenFOAM总是一头雾水,下载好后无从入手,不懂别人的论文里的算例都是怎么算的,一个个文件又是什么意思。特别是有关数值格式的算法大多基于matlab,如何在openfoam中实现同样的目的也鲜有介绍。因此,本文的目的就是零基础教会使用OpenFOAM,并且附带了纯对流案例的文件方便理解和学习。 

0、案例已分享github和百度网盘

https://github.com/gxinnnnnnn/Example-of-a-pure-convection-in-OpenFOAM.git

https://pan.baidu.com/s/1jBZGJUNusaKZAC_gDwXUaQ

5cu8

1、OpenFOAM下载

推荐使用OpenFOAM-9,使用较为广泛,其他版本也可以,但会存在一些案例的微调,当然也可以下载多个版本。下载路径当然是CFD领域的好帮手——CFD中文网:

http://dyfluid.com/install.html

2、问题描述

物理意义:一个给定的以45度角倾斜于水平方向的均匀速度场对一个被动标量的对流传输。左侧为1,底侧为0,上、右侧零梯度。

零基础学习OpenFOAM-从纯对流算例出发

控制守恒方程:

零基础学习OpenFOAM-从纯对流算例出发

其中q是对流变量(算例中为T),u = 1和v = 1是给定速度向量的笛卡尔分量。

3、计算

1、将本文的算例复制到ubuntu主目录

2、打开one-sigrun(单独的纯对流阶梯剖面算例)

3、直接在该文件右键打开终端

4、输入./run即可得到计算结果和画好的图

零基础学习OpenFOAM-从纯对流算例出发

求解器为scalarTransportFoam,其中代码为:

 fvScalarMatrix TEqn ( fvm::ddt(T) + fvm::div(phi, T) - fvm::laplacian(DT, T) == fvModels.source(T) ); 

令DT为0即可实现纯对流问题的求解

4、后处理

要看云图可以在终端输入paraFoam

零基础学习OpenFOAM-从纯对流算例出发

5、详细介绍

5.1、算例结构

零基础学习OpenFOAM-从纯对流算例出发

  • 0存放初始条件和边界条件,
  • constant存放网格文件polyMesh和流体参数transportProperties,
  • system存放求解控制文件controlDict,数值格式fvSchemes,离散方程求解设置fvSolution,网格划分文件blockMesh,以及后处理取值文件sampleDict。
  • scripts是自己建立的文件夹用来存放解析解数据,方便后续画图。
  • run是计算脚本,p1是画图脚本。

5.2、文件详解

5.2.1 0文件

T
/*--------------------------------*- C++ -*----------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org \\ / A nd | Version: 9 \\/ M anipulation | \*---------------------------------------------------------------------------*/ FoamFile { version 2.0; format ascii; class volScalarField; object T; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // dimensions [0 0 0 0 0 0 0];//定义变量的单位 internalField uniform 0;//内部场 boundaryField//边界场,blockMesh中定义的5个面 { left { type fixedValue;//边界类型为定值,即狄利克雷边界条件 value uniform 1;//值为标量1 } top { type zeroGradient;//边界类型为零梯度,即纽曼边界条件 } right { type zeroGradient; } bottom { type fixedValue; value uniform 0; } frontAndBack { type empty;//空边界,确保计算时不求解第三方向 } } // * // 
U
/*--------------------------------*- C++ -*----------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org \\ / A nd | Version: 9 \\/ M anipulation | \*---------------------------------------------------------------------------*/ FoamFile { format ascii; class volVectorField; object U; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // dimensions [0 1 -1 0 0 0 0]; internalField uniform (1 1 0); boundaryField { top { type zeroGradient; } left { type fixedValue; value uniform (1 1 0);//速度斜向上45° } right { type zeroGradient; } bottom { type fixedValue; value uniform (1 1 0); } frontAndBack { type empty; } } // * // 

5.2.2 constant文件

 polyMesh

polyMesh由blockMesh操作生成,其中boundary中包含边界类型,face、neighbour、owner和points中分别包含面的标签、顺风单元标签、逆风单元标签和点的标签。

transportProperties

transportProperties中DT=0,即不考虑散度项,只用纯对流

5.2.3 system文件

blockMeshDict(网格生成文件)
/*--------------------------------*- C++ -*----------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org \\ / A nd | Version: 9 \\/ M anipulation | \*---------------------------------------------------------------------------*/ FoamFile { format ascii; class dictionary; object blockMeshDict; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // convertToMeters 1;//尺寸基准定义为1m vertices//定义组成六面体的8个点的坐标 ( (0 0 0) //0 (1 0 0) //1 (1 1 0) //2 (0 1 0) //3 (0 0 0.1) //4 (1 0 0.1) //5 (1 1 0.1) //6 (0 1 0.1) //7 ); blocks///hex表示用8个点组成六面体,有顺序的 ( hex (0 1 2 3 4 5 6 7) (60 60 1) simpleGrading (1 1 1)//x和y方向各自划分60个网格 );//simpleGrading (1 1 1)表示三个方向的网格膨胀率为1:1:1 edges//用于建立非直线的边 ( ); boundary//定义由点组成的面的名称 ( top { type wall; faces ( (3 7 6 2)//由3762四个点组成的面定义名称为top,边界类型是wall ); } left { type wall; faces ( (0 4 7 3) ); } right { type wall; faces ( (2 6 5 1) ); } bottom { type wall; faces ( (1 5 4 0) ); } frontAndBack { type empty; faces ( (0 3 2 1) (4 5 6 7) ); } ); mergePatchPairs//合并面操作 ( ); // * //
controlDict(计算控制)
/*--------------------------------*- C++ -*----------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org \\ / A nd | Version: 9 \\/ M anipulation | \*---------------------------------------------------------------------------*/ FoamFile { format ascii; class dictionary; object controlDict; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // application cvsimple;//无意义 startFrom startTime;//计算的开始时间,可选latestTime以续算算例 startTime 0; stopAt endTime;//在设置的endTime的时刻停止计算 endTime 5; deltaT 0.005; //时间步 writeControl runTime;//输出结果文件,每writeInterval的物理时间输出结果 writeInterval 1; purgeWrite 0;//覆盖写入 writeFormat ascii;//编码格式 writePrecision 8;//保留位数 writeCompression off;//是否压缩 timeFormat general;//显示格式,通用 timePrecision 6;//时间保留位数 runTimeModifiable no;//变时间步开关 // * // 
fvSchemes(数值格式)
/*--------------------------------*- C++ -*----------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org \\ / A nd | Version: 9 \\/ M anipulation | \*---------------------------------------------------------------------------*/ FoamFile { format ascii; class dictionary; object fvSchemes; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ddtSchemes//时间离散 { default Euler; } gradSchemes//梯度项离散 { default Gauss none; default cellLimited Gauss linear 1; } divSchemes//对流项离散 { default none; div(phi,T) Gauss Minmod; } laplacianSchemes//拉普拉斯项离散 { default none; laplacian(DT,T) Gauss linear limited 1; } interpolationSchemes//插值格式 { default linear; } snGradSchemes//面法相梯度格式 { default limited 1; } // * // 
fvSolution(离散方程求解设置)
/*--------------------------------*- C++ -*----------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org \\ / A nd | Version: 9 \\/ M anipulation | \*---------------------------------------------------------------------------*/ FoamFile { format ascii; class dictionary; object fvSolution; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // solvers//求解方程的求解器 { T { solver PBiCG;//预处理器双共轭梯度法 preconditioner DILU; tolerance 1e-06;//收敛残差 relTol 0;//相对残差 } } PISO//离散方程组的分离式求法 { nCorrectors 2; nNonOrthogonalCorrectors 1; } SIMPLE { nNonOrthogonalCorrectors 1; //1 } relaxationFactors//松弛因子 { U 1; T 1; } // * // 

sampleDict(取值)

/*--------------------------------*- C++ -*----------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org \\ / A nd | Version: 9 \\/ M anipulation | \*---------------------------------------------------------------------------*/ FoamFile { format ascii; class dictionary; object sampleDict; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // type sets; libs ("libsampling.so"); interpolationScheme cellPoint; setFormat raw; sets ( line_centreProfile//文件名 { type lineUniform;//类型,直线 axis distance;//轴,依据距离 start ( 0.5 0 0 );//起始点 end ( 0.5 1 0 );//终点 nPoints 120;//取点数 } ); fields ( T );//取值 // * //

5.3、脚本

run脚本中,

  • mkdir sol0生成一个sol0文件夹存放数据;
  • blockMesh画网格;scalarTransportFoam使用此求解器求解计算;
  • postProcess -func sampleDict -latestTime后处理取俩点连线上的值;
  • cp postProcessing/sampleDict/5/line_centreProfile_T.xy sol0/line_centreProfile_T.xy.0保存数据
  • ./p1画图(画图使用的gnuplot)

6、多数值格式

算例中one-muti为多种对流项数值格式的比较,原理类似,脚本有所改变,结果如图:

零基础学习OpenFOAM-从纯对流算例出发

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/118294.html

(0)
上一篇 2025-11-14 11:00
下一篇 2025-11-14 11:15

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注微信