openfoam中添加新变量并输出
-
各位老师好,由于openfoam里进行LES计算时,内置的field average只能输出雷诺应力,但是我的雷诺应力和经典文献结果对不上,所以我想在openfoam里增加速度二阶量UU及其时均值的计算。
但是我在controlDict的增加了function以后并没有在结果文件里看到我定义的物理量,不知道各位有没有过类似的工作的可以指点一下。感谢!以下是我的代码functions { velocityUU { libs ("libutilityFunctionObjects.so"); type coded; name velocityUU; // 将名称与输出文件的名称一致 region region0; enabled true; log true; executeControl timeStep; executeInterval 1; writeControl timeStep; writeInterval 1; codeInclude #{ #include "fvCFD.H" #include <cmath> #include <iostream> #}; codeOptions #{ -I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude #}; codeLibs #{ -lmeshTools \ -lfiniteVolume #}; codeExecute #{ // 获取速度场 U const volVectorField& U = mesh().lookupObject<volVectorField>("U"); // 计算速度场 U 的平方 volScalarField UXSquared = U[0] * U[0]; // 定义静态指针,用于存储 volScalarField 对象 static autoPtr<volScalarField> pField; // 如果指针无效,创建 volScalarField 对象 if (!pField.valid()) { pField.set( new volScalarField( IOobject( "velocityUU", // 输出文件的名称与函数名称一致 mesh().time().timeName(), U.mesh(), IOobject::NO_READ, IOobject::AUTO_WRITE ), UXSquared ) ); } // 获取 velocityUU 引用 volScalarField& result = pField(); // 将 result 标记为有效 result.checkIn(); // 更新 result 的值 result = UXSquared; #}; } }
-
我也不是很懂,从代码角度来看,貌似只有进入了if判断语句中才会进行变量的输出?是不是得把IO操作放在外层
2023年11月14日 16:10
1/3
2023年11月29日 02:06