ENH: simplify patchCellsSource name handling, enforce single field name

BUG: inconsistent "U" name on re-read (buoyancyEnergy)

STYLE: fix spelling inconsistencies
This commit is contained in:
Mark Olesen 2022-06-15 11:11:50 +02:00
parent c6c4ced741
commit dfc8c047b1
6 changed files with 83 additions and 107 deletions

View File

@ -289,7 +289,7 @@ void Foam::pressurePIDControlInletVelocityFvPatchVectorField::updateCoeffs()
else
{
WarningInFunction
<< "The pressure field name, \"pName\", is \"" << pName_ << "\", "
<< "The pressure field name, 'p' is \"" << pName_ << "\", "
<< "but a field of that name was not found. The inlet velocity "
<< "will be set to an analytical value calculated from the "
<< "specified pressure drop. No PID control will be done and "

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2015-2016 OpenFOAM Foundation
Copyright (C) 2018-2020 OpenCFD Ltd.
Copyright (C) 2018-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -90,7 +90,7 @@ bool Foam::fv::buoyancyEnergy::read(const dictionary& dict)
{
if (fv::option::read(dict))
{
coeffs_.readIfPresent("UName", UName_);
coeffs_.readIfPresent("U", UName_);
return true;
}

View File

@ -26,9 +26,9 @@ License
\*---------------------------------------------------------------------------*/
#include "patchCellsSource.H"
#include "boundarySourcePatch.H"
#include "fvMatrices.H"
#include "addToRunTimeSelectionTable.H"
#include "boundarySourcePatch.H"
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
@ -54,46 +54,46 @@ Foam::fv::patchCellsSource::patchCellsSource
:
fv::option(sourceName, modelType, dict, mesh),
curTimeIndex_(-1),
UName_(coeffs_.getOrDefault<word>("U", "none")),
hName_(coeffs_.getOrDefault<word>("he", "none")),
speciesName_(coeffs_.getOrDefault<word>("species", "none"))
isEnergySource_(false)
{
label nFields = 0;
if (UName_ != "none")
{
nFields++;
}
if (hName_ != "none")
{
nFields++;
}
if (speciesName_ != "none")
{
nFields++;
}
if (nFields > 1)
{
FatalErrorInFunction
<< "patchCellsSource : "
<< " cannot be used for more than one field."
<< exit(FatalError);
}
fieldNames_.resize(1);
if (speciesName_ != "none")
label nFields = 0;
if
(
coeffs_.readIfPresent("U", fieldNames_[0])
&& fieldNames_[0] != "none"
)
{
fieldNames_[0] = speciesName_;
++nFields;
}
if (UName_ != "none")
if
(
coeffs_.readIfPresent("he", fieldNames_[0])
&& fieldNames_[0] != "none"
)
{
fieldNames_[0] = UName_;
isEnergySource_ = true;
++nFields;
}
if (hName_ != "none")
if
(
coeffs_.readIfPresent("species", fieldNames_[0])
&& fieldNames_[0] != "none"
)
{
fieldNames_[0] = hName_;
++nFields;
}
if (nFields != 1)
{
FatalIOErrorInFunction(coeffs_)
<< "Must be specified for one field (U | he | species), but "
<< nFields << " fields were specified!" << endl
<< exit(FatalIOError);
}
fv::option::resetApplied();
@ -109,75 +109,56 @@ void Foam::fv::patchCellsSource::addSup
const label fieldi
)
{
if (curTimeIndex_ == mesh_.time().timeIndex())
{
return;
}
curTimeIndex_ = mesh_.time().timeIndex();
if (debug)
{
Info<< type() << ": applying source to " << eqn.psi().name() << endl;
}
if (curTimeIndex_ == mesh_.time().timeIndex())
{
return;
}
volScalarField* psiPtr;
// If source applied to he, we need to loop over T for BC's
if (hName_ != "none")
{
psiPtr = mesh_.getObjectPtr<volScalarField>("T");
}
else
{
auto* psi =
mesh_.getObjectPtr<volScalarField>(eqn.psi().name());
psiPtr = psi;
}
const volScalarField::Boundary& psib = psiPtr->boundaryField();
volScalarField mDot
auto tsu = DimensionedField<scalar, volMesh>::New
(
IOobject
(
"mDot",
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
name_ + eqn.psi().name() + "Su",
mesh_,
dimensionedScalar(eqn.dimensions()/dimVolume, Zero)
);
// If source applied to he, we need to loop over T for BC's
const volScalarField& psi =
(
isEnergySource_
? mesh_.lookupObject<volScalarField>("T")
: mesh_.lookupObject<volScalarField>(eqn.psi().name())
);
const auto& psib = psi.boundaryField();
forAll(psib, patchi)
{
if (isA<boundarySourcePatch>(psib[patchi]))
const auto* bpatchPtr = isA<boundarySourcePatch>(psib[patchi]);
if (bpatchPtr)
{
const boundarySourcePatch& pp =
refCast<const boundarySourcePatch>(psib[patchi]);
tmp<scalarField> tsbnd = bpatchPtr->patchSource();
const auto& sbnd = tsbnd.cref();
const labelUList& fc = mesh_.boundary()[patchi].faceCells();
tmp<scalarField> tsb = pp.patchSource();
const scalarField& sb = tsb.cref();
forAll(fc, facei)
{
const label celli = fc[facei];
mDot[celli] += sb[facei];
}
UIndirectList<scalar>
(
tsu.ref().field(),
mesh_.boundary()[patchi].faceCells()
) = sbnd;
}
}
eqn += mDot;
curTimeIndex_ = mesh_.time().timeIndex();
if (debug)
{
Info<< " Field source rate min/max : "
<< gMin(mDot) << " / " << gMax(mDot) << endl;
Info<< "Field source rate min/max : " << gMinMax(tsu()) << endl;
}
eqn += tsu;
}

View File

@ -42,7 +42,7 @@ Usage
// Mandatory entries
type patchCellsSource;
// Optional entries
// Optional entries (one only!)
U <word>;
he <word>;
species <word>;
@ -56,13 +56,13 @@ Usage
\table
Property | Description | Type | Reqd | Deflt
type | Type name: patchCellsSource | word | yes | -
U | Name of operand velocity field | word | no | none
he | Name of operand energy field | word | no | none
species | Name of operand species field | word | no | none
U | Name of operand velocity field | word | choice | -
he | Name of operand energy field | word | choice | -
species | Name of operand species field | word | choice | -
\endtable
The inherited entries are elaborated in:
- \link cellSetOption.H \endlink
- \link fvOption.H \endlink
SourceFiles
patchCellsSource.C
@ -96,14 +96,8 @@ class patchCellsSource
//- Current time index (used for updating)
label curTimeIndex_;
//- Name of operand velocity field
word UName_;
//- Name of operand energy field
word hName_;
//- Name of operand species field
word speciesName_;
//- Special handling energy field
bool isEnergySource_;
public:
@ -136,7 +130,8 @@ public:
// Member Functions
//- Add explicit contribution to compressible enthalpy equation
//- Add explicit contribution to compressible
//- (momentum, enthalpy, species) equation
virtual void addSup
(
const volScalarField& rho,

View File

@ -237,14 +237,14 @@ patchSource() const
const basicSpecieMixture& composition = thermo.composition();
const label speicesId =
const label speciesId =
thermo.composition().species()[speciesName_];
scalarField hsp(this->patch().size(), 0);
forAll(pp, facei)
{
hsp[facei] = composition.Hs(speicesId, pp[facei], Tp[facei]);
hsp[facei] = composition.Hs(speciesId, pp[facei], Tp[facei]);
}
dhdt += hsp*massb;

View File

@ -58,8 +58,8 @@ Foam::speciesSorptionFvPatchScalarField::kinematicModelTypeNames
Foam::tmp<Foam::scalarField>
Foam::speciesSorptionFvPatchScalarField::calcMoleFractions() const
{
auto tMole = tmp<scalarField>::New(patch().size(), 0);
scalarField& Mole = tMole.ref();
auto tMole = tmp<scalarField>::New(patch().size(), Zero);
auto& Mole = tMole.ref();
if (db().foundObject<rhoReactionThermo>(basicThermo::dictName))
{
@ -74,16 +74,16 @@ Foam::speciesSorptionFvPatchScalarField::calcMoleFractions() const
const labelUList& faceCells = patch().faceCells();
const label speicesId =
const label speciesId =
thermo.composition().species()[this->internalField().name()];
const dimensionedScalar Wi
(
dimMass/dimMoles,
thermo.composition().W(speicesId)
thermo.composition().W(speciesId)
);
const volScalarField X(W*Y[speicesId]/Wi);
const volScalarField X(W*Y[speciesId]/Wi);
forAll(faceCells, i)
{
@ -309,10 +309,10 @@ patchSource() const
basicThermo::dictName
);
const label speicesId =
const label speciesId =
thermo.composition().species()[this->internalField().name()];
const scalar Wi(thermo.composition().W(speicesId));
const scalar Wi(thermo.composition().W(speciesId));
const scalar t = db().time().timeOutputValue();