@疏影横斜水清浅 参考下下边这个代码吧。
coded
{
libs ( "libutilityFunctionObjects.so" );
enabled true;
type coded;
name printMinU;
executeControl timeStep;
executeInterval 200;
writeControl timeStep;
writeInterval 200;
codeOptions
#{
-I$(LIB_SRC)/meshTools/lnInclude
#};
codeExecute
#{
const volScalarField& T
(
mesh().lookupObject<volScalarField>("T")
);
const fvPatchList& patches = mesh().boundary();
std::ofstream file;
file.open ("nus", std::ofstream::out | std::ofstream::app);
forAll(patches, patchi)
{
const fvPatch& currPatch = patches[patchi];
if (currPatch.name() == "bottomWall")
{
fvPatchScalarField nus = T.boundaryField()[patchi];
scalar L = 0.1;
scalar Timp = 343;
const volScalarField& T = mesh().lookupObject<volScalarField>("T");
scalarField Tinternal = T.internalField();
scalar sumT = gSum(Tinternal * mesh().V());
scalar V = gSum(mesh().V());
scalar avgT = sumT / V;
nus = T.boundaryField()[patchi].snGrad()*L/(Timp - avgT);
//nus2file << "Time: " << mesh().time().timeName() << " " << nus << nl;
forAll(T.boundaryField()[patchi], facei)
{
//Pout << mesh().C().boundaryField()[patchi][facei].x()/0.1
// << " " << nus[facei] << nl;
file << "Time: " << mesh().time().timeName() << " " << mesh().C().boundaryField()[patchi][facei].x() << " " << mesh().C().boundaryField()[patchi][facei].z() << " " << nus[facei] << std::endl;
}
}
}
file.close();
#};
}