ENH: avoid possible divide-by-zero (fixes #2025)

- based on fix supplied by Henning.Scheufler@dlr.de
This commit is contained in:
Mark Olesen
2021-03-15 18:11:06 +01:00
parent 88c256b86a
commit bf0a48d68e
8 changed files with 22 additions and 18 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2016 OpenFOAM Foundation
Copyright (C) 2017-2020 OpenCFD Ltd.
Copyright (C) 2017-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -114,7 +114,7 @@ void Foam::fixedMeanFvPatchField<Type>::updateCoeffs()
gSum(this->patch().magSf()*newValues)
/gSum(this->patch().magSf());
if (mag(meanValue) > SMALL && mag(meanValuePsi)/mag(meanValue) > 0.5)
if (mag(meanValue) > SMALL && mag(meanValuePsi) > 0.5*mag(meanValue))
{
newValues *= mag(meanValue)/mag(meanValuePsi);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2018 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -124,7 +124,7 @@ void Foam::fixedMeanOutletInletFvPatchField<Type>::updateCoeffs()
gSum(this->patch().magSf()*newValues)
/gSum(this->patch().magSf());
if (mag(meanValue) > SMALL && mag(meanValuePsi)/mag(meanValue) > 0.5)
if (mag(meanValue) > SMALL && mag(meanValuePsi) > 0.5*mag(meanValue))
{
newValues *= mag(meanValue)/mag(meanValuePsi);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2019-2020 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -30,6 +30,7 @@ License
#include "addToRunTimeSelectionTable.H"
#include "volFields.H"
#include "one.H"
#include "Switch.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -177,7 +178,7 @@ void Foam::flowRateInletVelocityFvPatchVectorField::updateValues
const scalar flowRate = flowRate_->value(t);
const scalar estimatedFlowRate = -gSum(rho*(this->patch().magSf()*nUp));
if (estimatedFlowRate/flowRate > 0.5)
if (estimatedFlowRate > 0.5*flowRate)
{
nUp *= (mag(flowRate)/mag(estimatedFlowRate));
}
@ -249,7 +250,10 @@ void Foam::flowRateInletVelocityFvPatchVectorField::write(Ostream& os) const
os.writeEntryIfDifferent<word>("rho", "rho", rhoName_);
os.writeEntryIfDifferent<scalar>("rhoInlet", -VGREAT, rhoInlet_);
}
os.writeEntry("extrapolateProfile", extrapolateProfile_);
if (extrapolateProfile_)
{
os.writeEntry("extrapolateProfile", extrapolateProfile_);
}
writeEntry("value", os);
}

View File

@ -117,7 +117,7 @@ class flowRateInletVelocityFvPatchVectorField
:
public fixedValueFvPatchVectorField
{
// Private data
// Private Data
//- Inlet integral flow rate
autoPtr<Function1<scalar>> flowRate_;
@ -135,7 +135,7 @@ class flowRateInletVelocityFvPatchVectorField
Switch extrapolateProfile_;
// Private member functions
// Private Member Functions
//- Update the patch values given the appropriate density type and value
template<class RhoType>
@ -211,7 +211,7 @@ public:
}
// Member functions
// Member Functions
//- Update the coefficients associated with the patch field
virtual void updateCoeffs();

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -166,7 +166,7 @@ void Foam::flowRateOutletVelocityFvPatchVectorField::updateValues
const scalar flowRate = flowRate_->value(t);
const scalar estimatedFlowRate = gSum(rho*(this->patch().magSf()*nUp));
if (estimatedFlowRate/flowRate > 0.5)
if (estimatedFlowRate > 0.5*flowRate)
{
nUp *= (mag(flowRate)/mag(estimatedFlowRate));
}

View File

@ -294,7 +294,7 @@ Foam::PatchFunction1Types::Sampled<Type>::value
averagePsi = gAverage(newValues);
}
if (mag(averagePsi)/mag(average_) > 0.5)
if (mag(averagePsi) > 0.5*mag(average_))
{
newValues *= mag(average_)/mag(averagePsi);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2013-2016 OpenFOAM Foundation
Copyright (C) 2018-2020 OpenCFD Ltd.
Copyright (C) 2018-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -630,7 +630,7 @@ Foam::mappedPatchFieldBase<Type>::mappedField
gSum(patchField_.patch().magSf()*newValues)
/gSum(patchField_.patch().magSf());
if (mag(averagePsi)/mag(average_) > 0.5)
if (mag(averagePsi) > 0.5*mag(average_))
{
newValues *= mag(average_)/mag(averagePsi);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -56,7 +56,7 @@ matchedFlowRateOutletVelocityFvPatchVectorField
)
:
fixedValueFvPatchField<vector>(p, iF, dict, false),
inletPatchName_(dict.lookup("inletPatch")),
inletPatchName_(dict.get<word>("inletPatch")),
volumetric_(dict.getOrDefault("volumetric", true))
{
if (volumetric_)
@ -174,7 +174,7 @@ void Foam::matchedFlowRateOutletVelocityFvPatchVectorField::updateValues
// Calculate the extrapolated outlet patch flow rate
const scalar estimatedFlowRate = gSum(rhoOutlet*(patch().magSf()*nUp));
if (estimatedFlowRate/flowRate > 0.5)
if (estimatedFlowRate > 0.5*flowRate)
{
nUp *= (mag(flowRate)/mag(estimatedFlowRate));
}