fvSchemes学习

1 前言

在学习fvSchemes之前,先得把CFD课程过一遍,不然很多格式都不知道是怎么回事。

打开终端,输入:

cd $FOAM_TUTORIALS
grep -r  "Schemes" * -h |sort -n|uniq

可以看到输出里面包含所有关键字:

d2dt2Schemes
ddtSchemes
divSchemes
    echo "Modifying the fvSchemes to contain only default schemes"
-e s/"\(fvSchemes[ \t]*\)\([0-9]\);"/"\1 1;"/g \
    for FV_SC in `find . -name fvSchemes`
gradSchemes
gradSchemes { default Gauss linear; }
    integrationSchemes
interpolationSchemes
    interpolationSchemes
interpolationSchemes { default linear; }
laplacianSchemes
laplacianSchemes { default Gauss linear corrected; }
* limited corrected 0.5 on all laplacianSchemes because the mesh is so poor
    object      fvSchemes;
SCHEMES_FILE="FvSchemes"
SCHEMES_TEMP="FvSchemes.temp"
setDefaultFvSchemes()
        setDefaultFvSchemes >> ${FV_SC}
snGradSchemes
snGradSchemes { default corrected; }
    solver setting in fvSolution and a div(phi,age) scheme in fvSchemes.

稍微整理下,关键字有:

d2dt2Schemes
ddtSchemes
divSchemes
gradSchemes
interpolationSchemes
laplacianSchemes
snGradSchemes

这里就涉及到一个小技巧,当不知道某一个关键词有哪些可选项的时候该怎么办

  1. banana方法
    我是在wolf dynamic的教程中学到的,即将一个选项的值替换成一个肯定不存在的值,如banana,这样就可以从输出信息中找到有哪些选项。(当然在某些情况这个方法不起作用)
  2. 利用Linux自身的强大查找命令,如grepfind…我还没怎么学会,平时就用用简单的grep。
  3. 利用OpenFOAM自带命令,如foamInfofoamSearch等,缺点是说明比较少,不知道哪些能搜到哪些搜不到,一切随缘。常见用法,如:
     foamSearch $FOAM_TUTORIALS fvSchemes ddtSchemes.default
     foamSearch $FOAM_TUTORIALS fvSchemes "divSchemes.div(phi,U)"
     foamSearch -c $FOAM_TUTORIALS fvSolution solvers.p.solver #-c 则会统计每个关键词信息出现的数量
     foamSearch $FOAM_TUTORIALS RAS.RASModel turbulenceProperties
    可见foamSearch这一命令用的好的话对学习OpenFOAM还是很有帮助的
  4. 直接从代码里找? 这个我没试过,因为C++还没到家,看着头疼,不过能看的懂代码的话应该会好很多。
  5. Vim里的vim-OpenFoam-syntax插件,带有自动提示补全功能,有一定作用但需要有一些经验才能很好使用。

2 总览

2.1 文件实例

//文件说明
FoamFile
{
version     2.0;                //版本号
format      ascii;              //文本格式
class       dictionary;         //类型为字典文件
location    "system";           //所在目录
object      fvSchemes;          //对象名
}
//时间一阶导项(非定常项)格式
ddtSchemes
{
default         Euler;
}
//梯度项格式
gradSchemes
{
default         Gauss linear;
grad(T)         Gauss linear;
}
//散度项格式
divSchemes
{
default         none;
}
//拉普拉斯项格式
laplacianSchemes
{
default         none;
laplacian(DT,T) Gauss linear corrected;
}
//插值格式
interpolationSchemes
{
default         linear;
}
//面法向梯度格式
snGradSchemes
{
default         corrected;
}
//需要用来计算通量的场
fluxRequired
{
default         no;
T;
}

2.2 keywords

子字典关键字 说明
interpolationSchemes 网格体心至面心插值格式
snGradSchemes 面法向梯度格式
timeScheme 时间导数项$\frac{\partial}{\partial t}$ $\frac{\partial ^2}{\partial t^2}$
divSchemes 散度(对流)项格式 $\nabla \cdot$
gradSchemes 梯度项格式$\nabla$
laplacianSchemes 拉普拉斯项格式$\nabla ^2$
fluxRequired 如(wallDist) 需要计算通量的场

以下结果与OpenFOAM版本有关,我用的是OpenFoam-dev(7)

Valid schemes are :

61
(
CoBlended
Gamma
GammaV
LUST
MUSCL
MUSCLV
Minmod
MinmodV
OSPRE
OSPREV
Phi
QUICK
QUICKV
SFCD
SFCDV
SuperBee
SuperBeeV
UMIST
UMISTV
biLinearFit
blended
cellCoBlended
clippedLinear
cubic
cubicUpwindFit
downwind
filteredLinear
filteredLinear2
filteredLinear2V
filteredLinear3
filteredLinear3V
fixedBlended
limitWith
limitedCubic
limitedCubicV
limitedLinear
limitedLinearV
limiterBlended
linear
linearFit
linearPureUpwindFit
linearUpwind
linearUpwindV
localBlended
localMax
localMin
midPoint
outletStabilised
pointLinear
quadraticFit
quadraticLinearFit
quadraticLinearUpwindFit
quadraticUpwindFit
reverseLinear
skewCorrected
upwind
vanAlbada
vanAlbadaV
vanLeer
vanLeerV
weighted
)

2.3 关于default

如果…Schemes 子字典中的 default关键词已经被指定, 那么子字典中所有的项都会应用这个格式。用户也可以指定 default 为 none。 这种情况下,用户必须强制为每个项指定离散格式。
推荐把default指定为none,这样的话强制用户对方程的每个需要离散的项进行设定,有助于对问题的理解。
总的来说就是从ERROR中学习

3 逐项分析

可参考OpenFOAM官网的Extended Code Guide,上面有一些说明。

3.1 ddtSchemes $\frac{\partial }{\partial t}\left(\phi\right)$

Valid ddt schemes are :

8
(
CoEuler
CrankNicolson
Euler
SLTS
backward
bounded
localEuler
steadyState
)

3.1.1 CoEuler

Courant number limited first-order Euler implicit/explicit ddt.
This scheme should only be used for steady-state computations using transient codes where local time-stepping is preferable to under-relaxation for transport consistency reasons.
例子,如:

default CoEuler phi rho 1;
  • phiName: Name of the flux field used to calculate the local time-step
  • rhoName: Name of the density field used to obtain the volumetric flux from the mass flux if required
  • maxCo: Maximum local Courant number

3.1.2 CrankNicolson

Second-order Crank-Nicolson implicit ddt using the current and previous time-step fields as well as the previous time-step ddt.
The Crank-Nicolson scheme is often unstable for complex flows in complex geometries and it is necessary to “off-centre” the scheme to stabilize it while retaining greater temporal accuracy than the first-order Euler-implicit scheme. Off-centering is specified via the mandatory coefficient \c ocCoeff in the range [0,1] following the scheme name e.g.

default         CrankNicolson 0.9;

or with an optional “ramp” function to transition from the Euler scheme to Crank-Nicolson over a initial period to avoid start-up problems, e.g.

default         CrankNicolson
ocCoeff
{
    type scale;
    scale linearRamp;
    duration 0.01;
    value 0.9;
};

With a coefficient of 1 the scheme is fully centred and second-order, with a coefficient of 0 the scheme is equivalent to Euler-implicit. A coefficient of 0.9 has been found to be suitable for a range of cases for which higher-order accuracy in time is needed and provides similar accuracy and stability to the backward scheme. However, the backward scheme has been found to be more robust and provides formal second-order accuracy in time.

The advantage of the Crank-Nicolson scheme over backward is that only the new and old-time values are needed, the additional terms relating to the fluxes and sources are evaluated at the mid-point of the time-step which provides the opportunity to limit the fluxes in such a way as to ensure boundedness while maintaining greater accuracy in time compared to the Euler-implicit scheme. This approach is now used with MULES in the interFoam family of solvers. Boundedness cannot be guaranteed with the backward scheme.
Note: The Crank-Nicolson coefficient for the implicit part of the RHS is related to the off-centering coefficient by cnCoeff = 1.0/(1.0 + ocCoeff);

Forward Euler:
$$
\frac{\partial }{\partial t}\left(\phi^{n}\right)\approx\frac{\phi^{n+1}-\phi^{n}}{\Delta t}
\tag{3-1}$$

Backward Euler:
$$
\frac{\partial }{\partial t}\left(\phi^{n}\right)\approx\frac{\phi^{n}-\phi^{n-1}}{\Delta t}
\tag{3-2}$$

Fully centred CN: Forward Euler + Backward Euler:

$$
\frac{\partial }{\partial t}\left(\phi^{n}\right)\approx\frac{\phi^{n+1}-\phi^{n}}{2\Delta t}
+\frac{\phi^{n}-\phi^{n-1}}{2\Delta t}=\frac{\phi^{n+1}-\phi^{n-1}}{2\Delta t}
\tag{3-3}$$
假设 ocCoeff: $\lambda$,则:
$$
\frac{\partial }{\partial t}\left(\phi^{n}\right)\approx\frac{\lambda}{1+\lambda}\frac{\phi^{n+1}-\phi^{n}}{\Delta t}+\frac{1}{1+\lambda}\frac{\phi^{n}-\phi^{n-1}}{\Delta t}
\tag{3-4}$$
显然,当 $\lambda=0$ ,退化成Backward Euler; $\lambda=1$,为完全的CrankNicolson格式。

突然发现有好多要学的,未完待续…  2019-12-16 00:03:56

Author: zcp
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint polocy. If reproduced, please indicate source zcp !
评论
Valine utteranc.es
 Previous
新的一年,还是写点什么吧
最近在忙着做presentation的PPT, 当做是这几个月的一个小节吧。接下来还有毕设的任务,到现在还没开始做也是慌得一匹,别人开题都开完了- -不过好在收获也挺多的,也算是体验了一下留学生活吧。日本过年过的是阳历,每年的最后一天叫啥大
Next 
  TOC