各位老师好,由于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;
        #};
    }
}