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];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -175,10 +218,10 @@ bool Foam::functionObjects::stabilityBlendingFactor::init(bool first)
|
|||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
indicator_ =
|
indicator =
|
||||||
max
|
max
|
||||||
(
|
(
|
||||||
indicator_,
|
indicator,
|
||||||
min
|
min
|
||||||
(
|
(
|
||||||
max
|
max
|
||||||
@ -198,8 +241,7 @@ 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_)
|
||||||
{
|
{
|
||||||
@ -210,10 +252,10 @@ bool Foam::functionObjects::stabilityBlendingFactor::init(bool first)
|
|||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
indicator_ =
|
indicator =
|
||||||
max
|
max
|
||||||
(
|
(
|
||||||
indicator_,
|
indicator,
|
||||||
min
|
min
|
||||||
(
|
(
|
||||||
max
|
max
|
||||||
@ -233,8 +275,8 @@ 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_)
|
||||||
{
|
{
|
||||||
@ -245,10 +287,10 @@ bool Foam::functionObjects::stabilityBlendingFactor::init(bool first)
|
|||||||
<< exit(FatalError);
|
<< exit(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
indicator_ =
|
indicator =
|
||||||
max
|
max
|
||||||
(
|
(
|
||||||
indicator_,
|
indicator,
|
||||||
min
|
min
|
||||||
(
|
(
|
||||||
max
|
max
|
||||||
@ -322,10 +364,10 @@ bool Foam::functionObjects::stabilityBlendingFactor::init(bool first)
|
|||||||
<< endl;
|
<< endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
indicator_ =
|
indicator =
|
||||||
max
|
max
|
||||||
(
|
(
|
||||||
indicator_,
|
indicator,
|
||||||
min
|
min
|
||||||
(
|
(
|
||||||
max
|
max
|
||||||
@ -340,8 +382,7 @@ 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_)
|
||||||
{
|
{
|
||||||
@ -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,12 +548,10 @@ 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
|
||||||
(
|
(
|
||||||
@ -540,7 +564,7 @@ Foam::functionObjects::stabilityBlendingFactor::stabilityBlendingFactor
|
|||||||
|
|
||||||
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
|
||||||
@ -551,15 +575,12 @@ Foam::functionObjects::stabilityBlendingFactor::stabilityBlendingFactor
|
|||||||
<< 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
|
||||||
(
|
(
|
||||||
@ -572,7 +593,7 @@ Foam::functionObjects::stabilityBlendingFactor::stabilityBlendingFactor
|
|||||||
|
|
||||||
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
|
||||||
@ -583,14 +604,10 @@ Foam::functionObjects::stabilityBlendingFactor::stabilityBlendingFactor
|
|||||||
<< 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
|
||||||
(
|
(
|
||||||
@ -614,12 +631,10 @@ Foam::functionObjects::stabilityBlendingFactor::stabilityBlendingFactor
|
|||||||
<< 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