codedSource
{
type coded;
selectionMode all;
fields (h); //对哪一个场添加源项,你用 U
name sourceTime; //名字随便起一个
codeAddSup
#{
const Time& time = mesh().time(); //获取时间
const scalarField& V = mesh_.V(); //获取网格的体积
scalarField& heSource = eqn.source(); //获取h的方程的源项的引用,之后在这个scalarField上面加上具体的量就可以了
// Start time
const scalar startTime = 2.0;
// Retrieve the x component of the cell centres
const scalarField& cellx = mesh_.C().component(0);//获取网格的x坐标
// Only apply when we have reached the start time
if (time.value() > startTime)
{
// Apply the source
forAll(cellx, i)
{
// cell volume specific source
heSource[i] += 1e5*sin(200*cellx[i])*V[i]; //forAll所有网格的循环,加上这个源项
};
}
#};
}
在foam-extend4.1的ibm里折腾了两三个月,发现用foam-extend4.1的浸没边界法计算升阻力系数产生震荡是其本身的问题。具体原因可以参考这篇论文Sources of spurious force oscillations from an immersed boundary
method for moving-body problems
这篇论文提到了三个解决方法:1、在力源项后面再增加一个质量源项以抑制动边界的力震荡 2、增大时间步长 3、将动边界所处位置的网格加密
目前我只是用了后面两种方法可以有效的减少其震荡,但震荡还是会存在,如果想获得一条平滑曲线,可能需要与第一种方法结合。第一种方法涉及到一些算法问题,鉴于目前的水平有限还不会在openfoam中实现,希望有大佬能够实现并给大伙解惑。
用paraview打开sparyFoam求解的aachenBomb案例文件,结果有这样的报错:
ERROR: In C:\bbd\8fbebceb\build\superbuild\paraview\src\VTK\IO\Geometry\vtkOpenFOAMReader.cxx, line 7891
vtkOpenFOAMReaderPrivate (0000022DE32F20E0): Error reading line 20 of E:\OpenFOAM\OpenFOAM-8\sprayFoam\aachenBomb\5e-05/lagrangian/sprayCloud/positions: Expected punctuation token ')', found f
我用的是Windows环境下的paraview5.11.0。路过的大佬,帮忙看看。