diff --git a/src/finiteVolume/cfdTools/general/MRF/MRFZone.C b/src/finiteVolume/cfdTools/general/MRF/MRFZone.C index fa04a6baeecdffc868dd19a91daab33632ec425f..18b12dfceb094a8a3bf2fa45ca8a249f213ee87a 100644 --- a/src/finiteVolume/cfdTools/general/MRF/MRFZone.C +++ b/src/finiteVolume/cfdTools/general/MRF/MRFZone.C @@ -247,56 +247,15 @@ Foam::MRFZone::MRFZone mesh_(mesh), name_(name), coeffs_(dict), - active_(coeffs_.getOrDefault("active", true)), + active_(true), cellZoneName_(cellZoneName), - cellZoneID_(), - excludedPatchNames_ - ( - coeffs_.getOrDefault<wordRes>("nonRotatingPatches", wordRes()) - ), - origin_(coeffs_.get<vector>("origin")), - axis_(coeffs_.get<vector>("axis").normalise()), - omega_(Function1<scalar>::New("omega", coeffs_, &mesh_)) + cellZoneID_(-1), + excludedPatchNames_(wordRes()), + origin_(Zero), + axis_(Zero), + omega_(nullptr) { - if (cellZoneName_ == word::null) - { - coeffs_.readEntry("cellZone", cellZoneName_); - } - - if (!active_) - { - cellZoneID_ = -1; - } - else - { - cellZoneID_ = mesh_.cellZones().findZoneID(cellZoneName_); - - const labelHashSet excludedPatchSet - ( - mesh_.boundaryMesh().patchSet(excludedPatchNames_) - ); - - excludedPatchLabels_.setSize(excludedPatchSet.size()); - - label i = 0; - for (const label patchi : excludedPatchSet) - { - excludedPatchLabels_[i++] = patchi; - } - - bool cellZoneFound = (cellZoneID_ != -1); - - reduce(cellZoneFound, orOp<bool>()); - - if (!cellZoneFound) - { - FatalErrorInFunction - << "cannot find MRF cellZone " << cellZoneName_ - << exit(FatalError); - } - - setMRFFaces(); - } + read(dict); } @@ -593,9 +552,60 @@ bool Foam::MRFZone::read(const dictionary& dict) { coeffs_ = dict; - active_ = coeffs_.getOrDefault("active", true); - coeffs_.readEntry("cellZone", cellZoneName_); - cellZoneID_ = mesh_.cellZones().findZoneID(cellZoneName_); + coeffs_.readIfPresent("active", active_); + + if (!active_) + { + cellZoneID_ = -1; + return true; + } + + coeffs_.readIfPresent("nonRotatingPatches", excludedPatchNames_); + + origin_ = coeffs_.get<vector>("origin"); + axis_ = coeffs_.get<vector>("axis").normalise(); + omega_.reset(Function1<scalar>::New("omega", coeffs_, &mesh_)); + + const word oldCellZoneName = cellZoneName_; + if (cellZoneName_ == word::null) + { + coeffs_.readEntry("cellZone", cellZoneName_); + } + else + { + coeffs_.readIfPresent("cellZone", cellZoneName_); + } + + if (cellZoneID_ == -1 || oldCellZoneName != cellZoneName_) + { + cellZoneID_ = mesh_.cellZones().findZoneID(cellZoneName_); + + const labelHashSet excludedPatchSet + ( + mesh_.boundaryMesh().patchSet(excludedPatchNames_) + ); + + excludedPatchLabels_.setSize(excludedPatchSet.size()); + + label i = 0; + for (const label patchi : excludedPatchSet) + { + excludedPatchLabels_[i++] = patchi; + } + + bool cellZoneFound = (cellZoneID_ != -1); + + reduce(cellZoneFound, orOp<bool>()); + + if (!cellZoneFound) + { + FatalErrorInFunction + << "cannot find MRF cellZone " << cellZoneName_ + << exit(FatalError); + } + + setMRFFaces(); + } return true; } diff --git a/src/finiteVolume/cfdTools/general/MRF/MRFZone.H b/src/finiteVolume/cfdTools/general/MRF/MRFZone.H index 3c0df7be983e4cb7d325bca9fe305f263be89bb5..8e59fac5bb2e7bec0f867515643d3a91e194f73b 100644 --- a/src/finiteVolume/cfdTools/general/MRF/MRFZone.H +++ b/src/finiteVolume/cfdTools/general/MRF/MRFZone.H @@ -88,8 +88,10 @@ class MRFZone //- Cell zone ID label cellZoneID_; - const wordRes excludedPatchNames_; + //- Non-rotating patches + wordRes excludedPatchNames_; + //- Indices of non-rotating patches labelList excludedPatchLabels_; //- Internal faces that are part of MRF @@ -102,7 +104,7 @@ class MRFZone labelListList excludedFaces_; //- Origin of the axis - const vector origin_; + vector origin_; //- Axis vector vector axis_; diff --git a/src/finiteVolume/cfdTools/general/MRF/MRFZoneList.C b/src/finiteVolume/cfdTools/general/MRF/MRFZoneList.C index c9d6f099767b9088cd52847cc52d7826385c8603..54ec416cdeff200e20a858cb6171ed3ec1dbe291 100644 --- a/src/finiteVolume/cfdTools/general/MRF/MRFZoneList.C +++ b/src/finiteVolume/cfdTools/general/MRF/MRFZoneList.C @@ -104,16 +104,20 @@ const Foam::MRFZone& Foam::MRFZoneList::getFromName const word& name ) const { + DynamicList<word> names; for (const auto& mrf: *this) { if (mrf.name() == name) { return mrf; } + + names.append(mrf.name()); } FatalErrorInFunction << "Unable to find MRFZone " << name + << ". Available zones are: " << names << exit(FatalError); return first(); @@ -123,10 +127,9 @@ const Foam::MRFZone& Foam::MRFZoneList::getFromName bool Foam::MRFZoneList::read(const dictionary& dict) { bool allOk = true; - forAll(*this, i) + for (auto& mrf: *this) { - MRFZone& pm = this->operator[](i); - bool ok = pm.read(dict.subDict(pm.name())); + bool ok = mrf.read(dict.subDict(mrf.name())); allOk = (allOk && ok); } return allOk; @@ -135,10 +138,10 @@ bool Foam::MRFZoneList::read(const dictionary& dict) bool Foam::MRFZoneList::writeData(Ostream& os) const { - forAll(*this, i) + for (const auto& mrf: *this) { os << nl; - this->operator[](i).writeData(os); + mrf.writeData(os); } return os.good(); @@ -151,18 +154,18 @@ void Foam::MRFZoneList::addAcceleration volVectorField& ddtU ) const { - forAll(*this, i) - { - operator[](i).addCoriolis(U, ddtU); + for (const auto& mrf: *this) + { + mrf.addCoriolis(U, ddtU); } } void Foam::MRFZoneList::addAcceleration(fvVectorMatrix& UEqn) const { - forAll(*this, i) + for (const auto& mrf: *this) { - operator[](i).addCoriolis(UEqn); + mrf.addCoriolis(UEqn); } } @@ -173,9 +176,9 @@ void Foam::MRFZoneList::addAcceleration fvVectorMatrix& UEqn ) const { - forAll(*this, i) + for (const auto& mrf: *this) { - operator[](i).addCoriolis(rho, UEqn); + mrf.addCoriolis(rho, UEqn); } } @@ -185,9 +188,8 @@ Foam::tmp<Foam::volVectorField> Foam::MRFZoneList::DDt const volVectorField& U ) const { - tmp<volVectorField> tacceleration - ( - new volVectorField + auto tacceleration = + tmp<volVectorField>::New ( IOobject ( @@ -197,13 +199,12 @@ Foam::tmp<Foam::volVectorField> Foam::MRFZoneList::DDt ), U.mesh(), dimensionedVector(U.dimensions()/dimTime, Zero) - ) - ); - volVectorField& acceleration = tacceleration.ref(); + ); + auto& acceleration = tacceleration.ref(); - forAll(*this, i) + for (const auto& mrf: *this) { - operator[](i).addCoriolis(U, acceleration); + mrf.addCoriolis(U, acceleration); } return tacceleration; @@ -222,18 +223,18 @@ Foam::tmp<Foam::volVectorField> Foam::MRFZoneList::DDt void Foam::MRFZoneList::makeRelative(volVectorField& U) const { - forAll(*this, i) + for (const auto& mrf: *this) { - operator[](i).makeRelative(U); + mrf.makeRelative(U); } } void Foam::MRFZoneList::makeRelative(surfaceScalarField& phi) const { - forAll(*this, i) + for (const auto& mrf: *this) { - operator[](i).makeRelative(phi); + mrf.makeRelative(phi); } } @@ -279,9 +280,9 @@ Foam::MRFZoneList::relative { tmp<FieldField<fvsPatchField, scalar>> rphi(New(tphi, true)); - forAll(*this, i) + for (const auto& mrf: *this) { - operator[](i).makeRelative(rphi.ref()); + mrf.makeRelative(rphi.ref()); } tphi.clear(); @@ -306,9 +307,9 @@ Foam::MRFZoneList::relative { tmp<Field<scalar>> rphi(New(tphi, true)); - forAll(*this, i) + for (const auto& mrf: *this) { - operator[](i).makeRelative(rphi.ref(), patchi); + mrf.makeRelative(rphi.ref(), patchi); } tphi.clear(); @@ -328,27 +329,27 @@ void Foam::MRFZoneList::makeRelative surfaceScalarField& phi ) const { - forAll(*this, i) + for (const auto& mrf: *this) { - operator[](i).makeRelative(rho, phi); + mrf.makeRelative(rho, phi); } } void Foam::MRFZoneList::makeAbsolute(volVectorField& U) const { - forAll(*this, i) + for (const auto& mrf: *this) { - operator[](i).makeAbsolute(U); + mrf.makeAbsolute(U); } } void Foam::MRFZoneList::makeAbsolute(surfaceScalarField& phi) const { - forAll(*this, i) + for (const auto& mrf: *this) { - operator[](i).makeAbsolute(phi); + mrf.makeAbsolute(phi); } } @@ -390,18 +391,18 @@ void Foam::MRFZoneList::makeAbsolute surfaceScalarField& phi ) const { - forAll(*this, i) + for (const auto& mrf: *this) { - operator[](i).makeAbsolute(rho, phi); + mrf.makeAbsolute(rho, phi); } } void Foam::MRFZoneList::correctBoundaryVelocity(volVectorField& U) const { - forAll(*this, i) + for (const auto& mrf: *this) { - operator[](i).correctBoundaryVelocity(U); + mrf.correctBoundaryVelocity(U); } } @@ -417,15 +418,11 @@ void Foam::MRFZoneList::correctBoundaryFlux relative(mesh_.Sf().boundaryField() & U.boundaryField()) ); - surfaceScalarField::Boundary& phibf = phi.boundaryFieldRef(); forAll(mesh_.boundary(), patchi) { - if - ( - isA<fixedValueFvsPatchScalarField>(phibf[patchi]) - ) + if (isA<fixedValueFvsPatchScalarField>(phibf[patchi])) { phibf[patchi] == Uf[patchi]; } @@ -437,9 +434,9 @@ void Foam::MRFZoneList::update() { if (mesh_.topoChanging()) { - forAll(*this, i) + for (auto& mrf: *this) { - operator[](i).update(); + mrf.update(); } } }