“cannot be called for a calculatedFvPatchField“——OpenFOAM中实现ρU(rhoU)边界条件的源码学习

``````--> FOAM FATAL ERROR:
cannot be called for a calculatedFvPatchField
on patch CYLINDER of field f in file "/home/dyfluid/Desktop/cylinder/0.0002/f"
You are probably trying to solve for a field with a default boundary condition.

``````

rhoCentralFoam的实现方式

rhoCentralFoam求解的是无粘的NS方程（欧拉方程），使用显式离散进行求解。在rhoCentralFoam中，我们并不需要在0文件里面创建rho的文档并设置边界和初值，因为它在求解器里面通过psiThermo（psi是ψ，compressibility，即为ρ/p）进行创建的：

``````volScalarField rho
(
IOobject
(
"rho",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
thermo.rho()
);
``````

`````` // --- Solve density
solve(fvm::ddt(rho) + fvc::div(phi));
// --- Solve momentum
solve(fvm::ddt(rhoU) + fvc::div(phiUp));

U.ref() =rhoU()/rho();
U.correctBoundaryConditions();
rhoU.boundaryFieldRef() == rho.boundaryField()*U.boundaryField();
``````

rhoCentralFoam在求解完连续性方程（解ρ）动量方程（以ρU为守恒变量）之后，通过ρ导出了U。以correctBoundaryConditions()修正了U的边界条件，再对ρU的边界进行修正。

calculated边界条件

This boundary condition is not designed to be evaluated; it is assmued that the value is assigned via field assignment, and not via a call to e.g. \\c updateCoeffs or \\c evaluate.

This boundary condition supplies a fixed value constraint, and is the base class for a number of other boundary conditions.

This boundary condition applies a zero-gradient condition from the patch internal field onto the patch faces.

FOAM aborting
#0 Foam::error::printStack(Foam::Ostream&) at ??:?
#1 Foam::error::abort() at ??:?
#2 Foam::calculatedFvPatchField<Foam::Vector>::valueInternalCoeffs(Foam::tmp<Foam::Field > const&) const in"/home/dyfluid/OpenFOAM/OpenFOAM-7/platforms/linux64GccDPInt32Opt/bin/shenFoam"
#3 Foam::fv::gaussConvectionScheme<Foam::Vector>::fvmDiv(Foam::GeometricField<double, Foam::fvsPatchField, Foam::surfaceMesh> const&, Foam::GeometricField<Foam::Vector, Foam::fvPatchField, Foam::volMesh> const&) const at ??:?

创建ρU场

``````volScalarField rho
(
IOobject
(
"rho",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
thermo.rho()
);

volVectorField rhoU
(
IOobject
(
"rhoU",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
rho*U
);
``````

``````Foam::tmp<Foam::volScalarField> Foam::psiThermo::rho() const
{
return p_*psi_;
}
``````

``````Foam::basicThermo::basicThermo
(
const fvMesh& mesh,
const word& phaseName
)
:
IOdictionary
(
IOobject
(
phasePropertyName(dictName, phaseName),
mesh.time().constant(),
mesh,
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE
)
),

phaseName_(phaseName),
p_(lookupOrConstruct(mesh, "p")),
``````

``````    psi_
(
IOobject
(
phasePropertyName("thermo:psi"),
mesh.time().timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh,
dimensionSet(0, -2, 2, 0, 0)
),
``````

NO_READ!

``````volScalarField T
(
IOobject
(
"T",
runTime.timeName (),
mesh ,
IOobject ::NO_READ ,
IOobject :: AUTO_WRITE
),
mesh ,
dimensionedScalar("zero", dimensionSet (0, 0, 0, 0, 0), 0.0)
);
``````

``````volScalarField rho
(
IOobject
(
"rho",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh
);

volVectorField f
(
IOobject
(
"f",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
),
mesh
);
``````

``````rho==rho0+rhop;
f==rhop*U+rho*up;
``````

总结

“cannot be called for a calculatedFvPatchField”一方面可能是因为边界使用了calculated的边界条件而报错，另一方面可能是自己创建的场在定义时，传递了别的参数，使得这与其中的某些设置起到了冲突。因此在求解新的变量场时（如ρU这种形式），需要注意定义时不初始化，计算时再赋值。

© 版权声明
THE END

暂无评论内容