mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
BUG: stabilityBlendingFactor - indicator field to be owned by mesh. See #2511
This commit is contained in:
@ -50,6 +50,37 @@ namespace functionObjects
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Foam::volScalarField&
|
||||||
|
Foam::functionObjects::stabilityBlendingFactor::indicator()
|
||||||
|
{
|
||||||
|
const word fldName = "blendedIndicator" + fieldName_;
|
||||||
|
|
||||||
|
auto* fldPtr = mesh_.getObjectPtr<volScalarField>(fldName);
|
||||||
|
|
||||||
|
if (!fldPtr)
|
||||||
|
{
|
||||||
|
fldPtr = new volScalarField
|
||||||
|
(
|
||||||
|
IOobject
|
||||||
|
(
|
||||||
|
"blendedIndicator" + fieldName_,
|
||||||
|
time_.timeName(),
|
||||||
|
mesh_,
|
||||||
|
IOobject::NO_READ,
|
||||||
|
IOobject::NO_WRITE
|
||||||
|
),
|
||||||
|
mesh_,
|
||||||
|
dimensionedScalar(dimless, Zero),
|
||||||
|
zeroGradientFvPatchScalarField::typeName
|
||||||
|
);
|
||||||
|
|
||||||
|
mesh_.objectRegistry::store(fldPtr);
|
||||||
|
}
|
||||||
|
|
||||||
|
return *fldPtr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Foam::functionObjects::stabilityBlendingFactor::calcStats
|
void Foam::functionObjects::stabilityBlendingFactor::calcStats
|
||||||
(
|
(
|
||||||
label& nCellsScheme1,
|
label& nCellsScheme1,
|
||||||
@ -57,21 +88,31 @@ void Foam::functionObjects::stabilityBlendingFactor::calcStats
|
|||||||
label& nCellsBlended
|
label& nCellsBlended
|
||||||
) const
|
) const
|
||||||
{
|
{
|
||||||
forAll(indicator_, celli)
|
const auto* indicatorPtr =
|
||||||
{
|
mesh_.cfindObject<volScalarField>("blendedIndicator" + fieldName_);
|
||||||
scalar i = indicator_[celli];
|
|
||||||
|
|
||||||
|
if (!indicatorPtr)
|
||||||
|
{
|
||||||
|
FatalErrorInFunction
|
||||||
|
<< "Indicator field not set"
|
||||||
|
<< abort(FatalError);
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto& indicator = *indicatorPtr;
|
||||||
|
|
||||||
|
for (const scalar i : indicator)
|
||||||
|
{
|
||||||
if (i < tolerance_)
|
if (i < tolerance_)
|
||||||
{
|
{
|
||||||
nCellsScheme2++;
|
++nCellsScheme2;
|
||||||
}
|
}
|
||||||
else if (i > (1 - tolerance_))
|
else if (i > (1 - tolerance_))
|
||||||
{
|
{
|
||||||
nCellsScheme1++;
|
++nCellsScheme1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
nCellsBlended++;
|
++nCellsBlended;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,13 +147,15 @@ bool Foam::functionObjects::stabilityBlendingFactor::init(bool first)
|
|||||||
{
|
{
|
||||||
const auto* residualPtr = mesh_.findObject<IOField<scalar>>(residualName_);
|
const auto* residualPtr = mesh_.findObject<IOField<scalar>>(residualName_);
|
||||||
|
|
||||||
|
auto& indicator = this->indicator();
|
||||||
|
|
||||||
if (residuals_)
|
if (residuals_)
|
||||||
{
|
{
|
||||||
if (!residualPtr)
|
if (!residualPtr)
|
||||||
{
|
{
|
||||||
WarningInFunction
|
WarningInFunction
|
||||||
<< "Could not find residual field : " << residualName_
|
<< "Could not find residual field : " << residualName_
|
||||||
<< ". The residual mode won't be " << nl
|
<< ". The residual mode will not be " << nl
|
||||||
<< " considered for the blended field in the stability "
|
<< " considered for the blended field in the stability "
|
||||||
<< "blending factor. " << nl
|
<< "blending factor. " << nl
|
||||||
<< " Please add the corresponding 'solverInfo'"
|
<< " Please add the corresponding 'solverInfo'"
|
||||||
@ -155,9 +198,9 @@ bool Foam::functionObjects::stabilityBlendingFactor::init(bool first)
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
forAll(indicator_, i)
|
forAll(indicator, i)
|
||||||
{
|
{
|
||||||
indicator_[i] = indicatorResidual[i];
|
indicator[i] = indicatorResidual[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -170,26 +213,26 @@ bool Foam::functionObjects::stabilityBlendingFactor::init(bool first)
|
|||||||
if (maxNonOrthogonality_ >= minNonOrthogonality_)
|
if (maxNonOrthogonality_ >= minNonOrthogonality_)
|
||||||
{
|
{
|
||||||
FatalErrorInFunction
|
FatalErrorInFunction
|
||||||
<< " minNonOrthogonality should be larger than "
|
<< "minNonOrthogonality should be larger than "
|
||||||
<< "maxNonOrthogonality."
|
<< "maxNonOrthogonality."
|
||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
indicator_ =
|
indicator =
|
||||||
max
|
max
|
||||||
(
|
|
||||||
indicator_,
|
|
||||||
min
|
|
||||||
(
|
(
|
||||||
max
|
indicator,
|
||||||
|
min
|
||||||
(
|
(
|
||||||
scalar(0),
|
max
|
||||||
(*nonOrthPtr - maxNonOrthogonality_)
|
(
|
||||||
/ (minNonOrthogonality_ - maxNonOrthogonality_)
|
scalar(0),
|
||||||
),
|
(*nonOrthPtr - maxNonOrthogonality_)
|
||||||
scalar(1)
|
/ (minNonOrthogonality_ - maxNonOrthogonality_)
|
||||||
)
|
),
|
||||||
);
|
scalar(1)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
if (first)
|
if (first)
|
||||||
{
|
{
|
||||||
@ -198,33 +241,32 @@ bool Foam::functionObjects::stabilityBlendingFactor::init(bool first)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const volScalarField* skewnessPtr =
|
const auto* skewnessPtr = mesh_.cfindObject<volScalarField>(skewnessName_);
|
||||||
mesh_.findObject<volScalarField>(skewnessName_);
|
|
||||||
|
|
||||||
if (skewness_)
|
if (skewness_)
|
||||||
{
|
{
|
||||||
if (maxSkewness_ >= minSkewness_)
|
if (maxSkewness_ >= minSkewness_)
|
||||||
{
|
{
|
||||||
FatalErrorInFunction
|
FatalErrorInFunction
|
||||||
<< " minSkewness should be larger than maxSkewness."
|
<< "minSkewness should be larger than maxSkewness."
|
||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
indicator_ =
|
indicator =
|
||||||
max
|
max
|
||||||
(
|
|
||||||
indicator_,
|
|
||||||
min
|
|
||||||
(
|
(
|
||||||
max
|
indicator,
|
||||||
|
min
|
||||||
(
|
(
|
||||||
scalar(0),
|
max
|
||||||
(*skewnessPtr - maxSkewness_)
|
(
|
||||||
/ (minSkewness_ - maxSkewness_)
|
scalar(0),
|
||||||
),
|
(*skewnessPtr - maxSkewness_)
|
||||||
scalar(1)
|
/ (minSkewness_ - maxSkewness_)
|
||||||
)
|
),
|
||||||
);
|
scalar(1)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
if (first)
|
if (first)
|
||||||
{
|
{
|
||||||
@ -233,22 +275,22 @@ bool Foam::functionObjects::stabilityBlendingFactor::init(bool first)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const volScalarField* faceWeightsPtr =
|
const auto* faceWeightsPtr =
|
||||||
mesh_.findObject<volScalarField>(faceWeightName_);
|
mesh_.cfindObject<volScalarField>(faceWeightName_);
|
||||||
|
|
||||||
if (faceWeight_)
|
if (faceWeight_)
|
||||||
{
|
{
|
||||||
if (maxFaceWeight_ >= minFaceWeight_)
|
if (maxFaceWeight_ >= minFaceWeight_)
|
||||||
{
|
{
|
||||||
FatalErrorInFunction
|
FatalErrorInFunction
|
||||||
<< " minFaceWeight should be larger than maxFaceWeight."
|
<< "minFaceWeight should be larger than maxFaceWeight."
|
||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
indicator_ =
|
indicator =
|
||||||
max
|
max
|
||||||
(
|
(
|
||||||
indicator_,
|
indicator,
|
||||||
min
|
min
|
||||||
(
|
(
|
||||||
max
|
max
|
||||||
@ -274,7 +316,7 @@ bool Foam::functionObjects::stabilityBlendingFactor::init(bool first)
|
|||||||
if (maxGradCc_ >= minGradCc_)
|
if (maxGradCc_ >= minGradCc_)
|
||||||
{
|
{
|
||||||
FatalErrorInFunction
|
FatalErrorInFunction
|
||||||
<< " minGradCc should be larger than maxGradCc."
|
<< "minGradCc should be larger than maxGradCc."
|
||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -322,10 +364,10 @@ bool Foam::functionObjects::stabilityBlendingFactor::init(bool first)
|
|||||||
<< endl;
|
<< endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
indicator_ =
|
indicator =
|
||||||
max
|
max
|
||||||
(
|
(
|
||||||
indicator_,
|
indicator,
|
||||||
min
|
min
|
||||||
(
|
(
|
||||||
max
|
max
|
||||||
@ -340,15 +382,14 @@ bool Foam::functionObjects::stabilityBlendingFactor::init(bool first)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const volVectorField* UNamePtr =
|
const auto* UNamePtr = mesh_.findObject<volVectorField>(UName_);
|
||||||
mesh_.findObject<volVectorField>(UName_);
|
|
||||||
|
|
||||||
if (Co_)
|
if (Co_)
|
||||||
{
|
{
|
||||||
if (Co1_ >= Co2_)
|
if (Co1_ >= Co2_)
|
||||||
{
|
{
|
||||||
FatalErrorInFunction
|
FatalErrorInFunction
|
||||||
<< " Co2 should be larger than Co1."
|
<< "Co2 should be larger than Co1."
|
||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -372,10 +413,10 @@ bool Foam::functionObjects::stabilityBlendingFactor::init(bool first)
|
|||||||
Co.primitiveFieldRef() =
|
Co.primitiveFieldRef() =
|
||||||
mesh_.time().deltaT()*mag(*UNamePtr)/cbrt(mesh_.V());
|
mesh_.time().deltaT()*mag(*UNamePtr)/cbrt(mesh_.V());
|
||||||
|
|
||||||
indicator_ =
|
indicator =
|
||||||
max
|
max
|
||||||
(
|
(
|
||||||
indicator_,
|
indicator,
|
||||||
min(max(scalar(0), (Co - Co1_)/(Co2_ - Co1_)), scalar(1))
|
min(max(scalar(0), (Co - Co1_)/(Co2_ - Co1_)), scalar(1))
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -406,15 +447,14 @@ bool Foam::functionObjects::stabilityBlendingFactor::init(bool first)
|
|||||||
<< endl;
|
<< endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
indicator_.correctBoundaryConditions();
|
indicator.correctBoundaryConditions();
|
||||||
indicator_.min(1.0);
|
indicator.min(1.0);
|
||||||
indicator_.max(0.0);
|
indicator.max(0.0);
|
||||||
|
|
||||||
// Update the blended surface field
|
// Update the blended surface field
|
||||||
surfaceScalarField& surBlended =
|
auto& surBlended = mesh_.lookupObjectRef<surfaceScalarField>(resultName_);
|
||||||
mesh_.lookupObjectRef<surfaceScalarField>(resultName_);
|
|
||||||
|
|
||||||
surBlended = fvc::interpolate(indicator_);
|
surBlended = fvc::interpolate(indicator);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -431,20 +471,6 @@ Foam::functionObjects::stabilityBlendingFactor::stabilityBlendingFactor
|
|||||||
:
|
:
|
||||||
fieldExpression(name, runTime, dict),
|
fieldExpression(name, runTime, dict),
|
||||||
writeFile(obr_, name, typeName, dict),
|
writeFile(obr_, name, typeName, dict),
|
||||||
indicator_
|
|
||||||
(
|
|
||||||
IOobject
|
|
||||||
(
|
|
||||||
"blendedIndicator" + fieldName_,
|
|
||||||
time_.timeName(),
|
|
||||||
mesh_,
|
|
||||||
IOobject::NO_READ,
|
|
||||||
IOobject::NO_WRITE
|
|
||||||
),
|
|
||||||
mesh_,
|
|
||||||
dimensionedScalar(dimless, Zero),
|
|
||||||
zeroGradientFvPatchScalarField::typeName
|
|
||||||
),
|
|
||||||
nonOrthogonality_(dict.getOrDefault<Switch>("switchNonOrtho", false)),
|
nonOrthogonality_(dict.getOrDefault<Switch>("switchNonOrtho", false)),
|
||||||
gradCc_(dict.getOrDefault<Switch>("switchGradCc", false)),
|
gradCc_(dict.getOrDefault<Switch>("switchGradCc", false)),
|
||||||
residuals_(dict.getOrDefault<Switch>("switchResiduals", false)),
|
residuals_(dict.getOrDefault<Switch>("switchResiduals", false)),
|
||||||
@ -522,104 +548,93 @@ Foam::functionObjects::stabilityBlendingFactor::stabilityBlendingFactor
|
|||||||
);
|
);
|
||||||
store(resultName_, faceBlendedPtr);
|
store(resultName_, faceBlendedPtr);
|
||||||
|
|
||||||
const volScalarField* nonOrthPtr =
|
const auto* nonOrthPtr =
|
||||||
mesh_.findObject<volScalarField>(nonOrthogonalityName_);
|
mesh_.findObject<volScalarField>(nonOrthogonalityName_);
|
||||||
|
|
||||||
if (nonOrthogonality_)
|
if (nonOrthogonality_ && !nonOrthPtr)
|
||||||
{
|
{
|
||||||
if (!nonOrthPtr)
|
IOobject fieldHeader
|
||||||
{
|
(
|
||||||
IOobject fieldHeader
|
nonOrthogonalityName_,
|
||||||
(
|
mesh_.time().constant(),
|
||||||
nonOrthogonalityName_,
|
mesh_,
|
||||||
mesh_.time().constant(),
|
IOobject::MUST_READ,
|
||||||
mesh_,
|
IOobject::NO_WRITE
|
||||||
IOobject::MUST_READ,
|
);
|
||||||
IOobject::NO_WRITE
|
|
||||||
);
|
|
||||||
|
|
||||||
if (fieldHeader.typeHeaderOk<volScalarField>(true, true, false))
|
if (fieldHeader.typeHeaderOk<volScalarField>(true, true, false))
|
||||||
{
|
{
|
||||||
volScalarField* vfPtr(new volScalarField(fieldHeader, mesh_));
|
volScalarField* vfPtr = new volScalarField(fieldHeader, mesh_);
|
||||||
mesh_.objectRegistry::store(vfPtr);
|
mesh_.objectRegistry::store(vfPtr);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FatalErrorInFunction
|
FatalErrorInFunction
|
||||||
<< " Field : " << nonOrthogonalityName_ << " not found."
|
<< "Field : " << nonOrthogonalityName_ << " not found."
|
||||||
<< " The function object will not be used"
|
<< " The function object will not be used"
|
||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const volScalarField* faceWeightsPtr =
|
const auto* faceWeightsPtr =
|
||||||
mesh_.findObject<volScalarField>(faceWeightName_);
|
mesh_.findObject<volScalarField>(faceWeightName_);
|
||||||
|
|
||||||
if (faceWeight_)
|
if (faceWeight_ && !faceWeightsPtr)
|
||||||
{
|
{
|
||||||
if (!faceWeightsPtr)
|
IOobject fieldHeader
|
||||||
{
|
(
|
||||||
IOobject fieldHeader
|
faceWeightName_,
|
||||||
(
|
mesh_.time().constant(),
|
||||||
faceWeightName_,
|
mesh_,
|
||||||
mesh_.time().constant(),
|
IOobject::MUST_READ,
|
||||||
mesh_,
|
IOobject::NO_WRITE
|
||||||
IOobject::MUST_READ,
|
);
|
||||||
IOobject::NO_WRITE
|
|
||||||
);
|
|
||||||
|
|
||||||
if (fieldHeader.typeHeaderOk<volScalarField>(true, true, false))
|
if (fieldHeader.typeHeaderOk<volScalarField>(true, true, false))
|
||||||
{
|
{
|
||||||
volScalarField* vfPtr(new volScalarField(fieldHeader, mesh_));
|
volScalarField* vfPtr = new volScalarField(fieldHeader, mesh_);
|
||||||
mesh_.objectRegistry::store(vfPtr);
|
mesh_.objectRegistry::store(vfPtr);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FatalErrorInFunction
|
FatalErrorInFunction
|
||||||
<< " Field : " << faceWeightName_ << " not found."
|
<< "Field : " << faceWeightName_ << " not found."
|
||||||
<< " The function object will not be used"
|
<< " The function object will not be used"
|
||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const volScalarField* skewnessPtr =
|
const auto* skewnessPtr = mesh_.findObject<volScalarField>(skewnessName_);
|
||||||
mesh_.findObject<volScalarField>(skewnessName_);
|
|
||||||
|
|
||||||
if (skewness_)
|
if (skewness_ && !skewnessPtr)
|
||||||
{
|
{
|
||||||
if (!skewnessPtr)
|
IOobject fieldHeader
|
||||||
{
|
(
|
||||||
IOobject fieldHeader
|
skewnessName_,
|
||||||
(
|
mesh_.time().constant(),
|
||||||
skewnessName_,
|
mesh_,
|
||||||
mesh_.time().constant(),
|
IOobject::MUST_READ,
|
||||||
mesh_,
|
IOobject::NO_WRITE
|
||||||
IOobject::MUST_READ,
|
);
|
||||||
IOobject::NO_WRITE
|
|
||||||
);
|
|
||||||
|
|
||||||
if (fieldHeader.typeHeaderOk<volScalarField>(true, true, false))
|
if (fieldHeader.typeHeaderOk<volScalarField>(true, true, false))
|
||||||
{
|
{
|
||||||
volScalarField* vfPtr(new volScalarField(fieldHeader, mesh_));
|
volScalarField* vfPtr(new volScalarField(fieldHeader, mesh_));
|
||||||
mesh_.objectRegistry::store(vfPtr);
|
mesh_.objectRegistry::store(vfPtr);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FatalErrorInFunction
|
FatalErrorInFunction
|
||||||
<< " Field : " << skewnessName_ << " not found."
|
<< "Field : " << skewnessName_ << " not found."
|
||||||
<< " The function object will not be used"
|
<< " The function object will not be used"
|
||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (log)
|
if (log)
|
||||||
{
|
{
|
||||||
indicator_.writeOpt(IOobject::AUTO_WRITE);
|
indicator().writeOpt(IOobject::AUTO_WRITE);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (writeToFile_)
|
if (writeToFile_)
|
||||||
|
|||||||
@ -340,9 +340,6 @@ class stabilityBlendingFactor
|
|||||||
{
|
{
|
||||||
// Private Member Data
|
// Private Member Data
|
||||||
|
|
||||||
//- Cell based blended indicator
|
|
||||||
volScalarField indicator_;
|
|
||||||
|
|
||||||
// Switches
|
// Switches
|
||||||
|
|
||||||
//- Switch for non-orthogonality
|
//- Switch for non-orthogonality
|
||||||
@ -443,6 +440,9 @@ class stabilityBlendingFactor
|
|||||||
//- Init fields
|
//- Init fields
|
||||||
bool init(bool first);
|
bool init(bool first);
|
||||||
|
|
||||||
|
//- Return access to the indicator field
|
||||||
|
volScalarField& indicator();
|
||||||
|
|
||||||
//- Calculate statistics
|
//- Calculate statistics
|
||||||
void calcStats(label&, label&, label&) const ;
|
void calcStats(label&, label&, label&) const ;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user