Go to the documentation of this file.
32 #include "surfaceInterpolate.H"
38 namespace functionObjects
44 stabilityBlendingFactor,
53 void Foam::functionObjects::stabilityBlendingFactor::calcStats
62 scalar i = indicator_[celli];
68 else if (i > (1 - tolerance_))
90 writeCommented(
os,
"Time");
91 writeTabbed(
os,
"Scheme1");
92 writeTabbed(
os,
"Scheme2");
93 writeTabbed(
os,
"Blended");
98 bool Foam::functionObjects::stabilityBlendingFactor::calc()
105 bool Foam::functionObjects::stabilityBlendingFactor::init(
bool first)
107 const auto* residualPtr = mesh_.findObject<IOField<scalar>>(residualName_);
114 <<
"Could not find residual field : " << residualName_
115 <<
". The residual mode won't be " <<
nl
116 <<
" considered for the blended field in the stability "
117 <<
"blending factor. " <<
nl
118 <<
" Please add the corresponding 'solverInfo'"
119 <<
" function object with 'writeResidualFields true'." <<
nl
120 <<
" If the solverInfo function object is already enabled "
121 <<
"you might need to wait " <<
nl
122 <<
" for the first iteration."
127 scalar meanRes =
gAverage(
mag(*residualPtr)) + VSMALL;
130 <<
" Average(mag(residuals)) : " << meanRes <<
endl;
133 oldErrorIntegral_ = errorIntegral_;
134 error_ =
mag(meanRes -
mag(*residualPtr));
135 errorIntegral_ = oldErrorIntegral_ + 0.5*(error_ + oldError_);
136 const scalarField errorDifferential(error_ - oldError_);
142 + D_*errorDifferential
151 mag(factorList - meanRes)/(maxResidual_*meanRes),
160 indicator_[i] = indicatorResidual[i];
168 if (nonOrthogonality_)
170 if (maxNonOrthogonality_ >= minNonOrthogonality_)
173 <<
" minNonOrthogonality should be larger than "
174 <<
"maxNonOrthogonality."
187 (*nonOrthPtr - maxNonOrthogonality_)
188 / (minNonOrthogonality_ - maxNonOrthogonality_)
196 Log <<
" Max non-orthogonality : " <<
max(*nonOrthPtr).value()
206 if (maxSkewness_ >= minSkewness_)
209 <<
" minSkewness should be larger than maxSkewness."
222 (*skewnessPtr - maxSkewness_)
223 / (minSkewness_ - maxSkewness_)
231 Log <<
" Max skewness : " <<
max(*skewnessPtr).value()
241 if (maxFaceWeight_ >= minFaceWeight_)
244 <<
" minFaceWeight should be larger than maxFaceWeight."
257 (minFaceWeight_ - *faceWeightsPtr)
258 / (minFaceWeight_ - maxFaceWeight_)
266 Log <<
" Min face weight: " <<
min(*faceWeightsPtr).value()
274 if (maxGradCc_ >= minGradCc_)
277 <<
" minGradCc should be larger than maxGradCc."
293 zeroGradientFvPatchScalarField::typeName
295 auto& magGradCC = tmagGradCC.ref();
305 mesh_.time().timeName(),
312 zeroGradientFvPatchScalarField::typeName
314 cci = mesh_.C().component(i);
315 cci.correctBoundaryConditions();
321 Log <<
" Max magGradCc : " <<
max(magGradCC.ref()).value()
334 (magGradCC - maxGradCc_)
335 / (minGradCc_ - maxGradCc_)
351 <<
" Co2 should be larger than Co1."
367 zeroGradientFvPatchScalarField::typeName
370 auto& Co = CoPtr.ref();
372 Co.primitiveFieldRef() =
373 mesh_.time().deltaT()*
mag(*UNamePtr)/
cbrt(mesh_.V());
379 min(
max(scalar(0), (Co - Co1_)/(Co2_ - Co1_)), scalar(1))
384 Log <<
" Max Co : " <<
max(Co).value()
396 label nCellsScheme1 = 0;
397 label nCellsScheme2 = 0;
398 label nCellsBlended = 0;
400 calcStats(nCellsScheme1, nCellsScheme2, nCellsBlended);
403 <<
" scheme 1 cells : " << nCellsScheme1 <<
nl
404 <<
" scheme 2 cells : " << nCellsScheme2 <<
nl
405 <<
" blended cells : " << nCellsBlended <<
nl
409 indicator_.correctBoundaryConditions();
438 "blendedIndicator" + fieldName_,
446 zeroGradientFvPatchScalarField::typeName
448 nonOrthogonality_(
dict.getOrDefault<
Switch>(
"switchNonOrtho", false)),
449 gradCc_(
dict.getOrDefault<
Switch>(
"switchGradCc", false)),
450 residuals_(
dict.getOrDefault<
Switch>(
"switchResiduals", false)),
451 faceWeight_(
dict.getOrDefault<
Switch>(
"switchFaceWeight", false)),
452 skewness_(
dict.getOrDefault<
Switch>(
"switchSkewness", false)),
453 Co_(
dict.getOrDefault<
Switch>(
"switchCo", false)),
457 dict.getOrDefault<scalar>(
"maxNonOrthogonality", 20.0)
461 dict.getOrDefault<scalar>(
"minNonOrthogonality", 60.0)
463 maxGradCc_(
dict.getOrDefault<scalar>(
"maxGradCc", 3.0)),
464 minGradCc_(
dict.getOrDefault<scalar>(
"minGradCc", 4.0)),
465 maxResidual_(
dict.getOrDefault<scalar>(
"maxResidual", 10.0)),
466 minFaceWeight_(
dict.getOrDefault<scalar>(
"minFaceWeight", 0.3)),
467 maxFaceWeight_(
dict.getOrDefault<scalar>(
"maxFaceWeight", 0.2)),
468 maxSkewness_(
dict.getOrDefault<scalar>(
"maxSkewness", 2.0)),
469 minSkewness_(
dict.getOrDefault<scalar>(
"minSkewness", 3.0)),
470 Co1_(
dict.getOrDefault<scalar>(
"Co1", 1.0)),
471 Co2_(
dict.getOrDefault<scalar>(
"Co2", 10.0)),
473 nonOrthogonalityName_
475 dict.getOrDefault<
word>(
"nonOrthogonality",
"nonOrthoAngle")
479 dict.getOrDefault<
word>(
"faceWeight",
"faceWeight")
483 dict.getOrDefault<
word>(
"skewness",
"skewness")
490 IOobject::scopedName(
"initialResidual",
"p")
499 error_(mesh_.nCells(),
Zero),
500 errorIntegral_(mesh_.nCells(),
Zero),
501 oldError_(mesh_.nCells(),
Zero),
502 oldErrorIntegral_(mesh_.nCells(),
Zero),
503 P_(
dict.getOrDefault<scalar>(
"P", 3)),
504 I_(
dict.getOrDefault<scalar>(
"I", 0.0)),
505 D_(
dict.getOrDefault<scalar>(
"D", 0.25))
528 if (nonOrthogonality_)
534 nonOrthogonalityName_,
544 mesh_.objectRegistry::store(vfPtr);
549 <<
" Field : " << nonOrthogonalityName_ <<
" not found."
550 <<
" The function object will not be used"
576 mesh_.objectRegistry::store(vfPtr);
581 <<
" Field : " << faceWeightName_ <<
" not found."
582 <<
" The function object will not be used"
607 mesh_.objectRegistry::store(vfPtr);
612 <<
" Field : " << skewnessName_ <<
" not found."
613 <<
" The function object will not be used"
643 dict.readEntry(
"switchNonOrtho", nonOrthogonality_);
644 dict.readEntry(
"switchGradCc", gradCc_);
645 dict.readEntry(
"switchResiduals", residuals_);
646 dict.readEntry(
"switchFaceWeight", faceWeight_);
647 dict.readEntry(
"switchSkewness", skewness_);
648 dict.readEntry(
"switchCo", Co_);
650 dict.readIfPresent(
"maxNonOrthogonality", maxNonOrthogonality_);
651 dict.readIfPresent(
"maxGradCc", maxGradCc_);
652 dict.readIfPresent(
"maxResidual", maxResidual_);
653 dict.readIfPresent(
"maxSkewness", maxSkewness_);
654 dict.readIfPresent(
"maxFaceWeight", maxFaceWeight_);
655 dict.readIfPresent(
"Co2", Co2_);
657 dict.readIfPresent(
"minFaceWeight", minFaceWeight_);
658 dict.readIfPresent(
"minNonOrthogonality", minNonOrthogonality_);
659 dict.readIfPresent(
"minGradCc", minGradCc_);
660 dict.readIfPresent(
"minSkewness", minSkewness_);
661 dict.readIfPresent(
"Co1", Co1_);
664 dict.readIfPresent(
"P", P_);
665 dict.readIfPresent(
"I", I_);
666 dict.readIfPresent(
"D", D_);
671 dict.readIfPresent(
"tolerance", tolerance_)
672 && (tolerance_ < 0 || tolerance_ > 1)
676 <<
"tolerance must be in the range 0 to 1. Supplied value: "
681 if (nonOrthogonality_)
683 Info<<
" Including nonOrthogonality between: "
684 << minNonOrthogonality_ <<
" and " << maxNonOrthogonality_
689 Info<<
" Including gradient between: "
690 << minGradCc_ <<
" and " << maxGradCc_ <<
endl;
694 Info<<
" Including residuals" <<
endl;
698 Info<<
" Including faceWeight between: "
699 << minFaceWeight_ <<
" and " << maxFaceWeight_ <<
endl;
703 Info<<
" Including skewness between: "
704 << minSkewness_ <<
" and " << maxSkewness_ <<
endl;
708 Info<<
" Including Co between: "
709 << Co2_ <<
" and " << Co1_ <<
endl;
721 label nCellsScheme1 = 0;
722 label nCellsScheme2 = 0;
723 label nCellsBlended = 0;
725 calcStats(nCellsScheme1, nCellsScheme2, nCellsBlended);
729 writeCurrentTime(file());
732 <<
tab << nCellsScheme1
733 <<
tab << nCellsScheme2
734 <<
tab << nCellsBlended
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh >> grad(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
A class for handling words, derived from Foam::string.
virtual OFstream & file()
A primitive field of type <T> with automated input and output.
static const char *const componentNames[]
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
static constexpr const zero Zero
Type gAverage(const FieldField< Field, Type > &f)
bool typeHeaderOk(const bool checkType=true, const bool search=true, const bool verbose=true)
bool read(const char *buf, int32_t &val)
static word timeName(const scalar t, const int precision=precision_)
virtual bool read(const dictionary &dict)
Ostream & endl(Ostream &os)
static void writeHeader(Ostream &os, const word &fieldName)
bool store(word &fieldName, const tmp< ObjectType > &tfield, bool cacheable=false)
label min(const labelHashSet &set, label minValue=labelMax)
virtual bool read(const dictionary &dict)
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
void setResultName(const word &typeName, const word &defaultArg)
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
GeometricField< scalar, fvPatchField, volMesh > volScalarField
label max(const labelHashSet &set, label maxValue=labelMin)
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
dimensionedScalar log(const dimensionedScalar &ds)
OBJstream os(runTime.globalPath()/outputName)
Macros for easy insertion into run-time selection tables.
Generic dimensioned Type class.
static tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > interpolate(const GeometricField< Type, fvPatchField, volMesh > &tvf, const surfaceScalarField &faceFlux, Istream &schemeData)
errorManipArg< error, int > exit(error &err, const int errNo=1)
GeometricField< vector, fvPatchField, volMesh > volVectorField
#define FatalErrorInFunction
const Type * findObject(const word &name, const bool recursive=false) const
Intermediate class for handling field expression function objects (e.g. blendingFactor etc....
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
addToRunTimeSelectionTable(functionObject, ObukhovLength, dictionary)
Calculate the gradient of the given field.
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
fileName::Type type(const fileName &name, const bool followLink=true)
static tmp< T > New(Args &&... args)
defineTypeNameAndDebug(ObukhovLength, 0)
word name(const expressions::valueTypeCode typeCode)
const Time & time() const
Computes the natural logarithm of an input volScalarField.
Base class for writing single files from the function objects.
stabilityBlendingFactor(const word &name, const Time &runTime, const dictionary &dict)
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
virtual bool read(const dictionary &)
static word scopedName(const std::string &scope, const word &name)
dimensionedScalar cbrt(const dimensionedScalar &ds)
const word & constant() const
Generic GeometricField class.
#define WarningInFunction
static constexpr direction nComponents
virtual void writeFileHeader(Ostream &os) const
const dimensionSet dimless