diff --git a/src/OpenFOAM/meshes/polyMesh/polyMeshIO.C b/src/OpenFOAM/meshes/polyMesh/polyMeshIO.C index 35deca2de9..25bd755dc2 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyMeshIO.C +++ b/src/OpenFOAM/meshes/polyMesh/polyMeshIO.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -306,128 +306,69 @@ Foam::polyMesh::readUpdateState Foam::polyMesh::readUpdate() geometricD_ = Zero; solutionD_ = Zero; - // Zones - meshPointZones newPointZones - ( - IOobject + // pointZones + { + meshPointZones newPointZones ( - "pointZones", - facesInst, - meshSubDir, - *this, - IOobject::READ_IF_PRESENT, - IOobject::NO_WRITE, - false - ), - *this - ); - - label oldSize = pointZones_.size(); - - if (newPointZones.size() <= pointZones_.size()) - { - pointZones_.setSize(newPointZones.size()); - } - - // Reset existing ones - forAll(pointZones_, czI) - { - pointZones_[czI] = newPointZones[czI]; - } - - // Extend with extra ones - pointZones_.setSize(newPointZones.size()); - - for (label czI = oldSize; czI < newPointZones.size(); czI++) - { - pointZones_.set(czI, newPointZones[czI].clone(pointZones_)); - } - - pointZones_.instance() = facesInst; - - - meshFaceZones newFaceZones - ( - IOobject - ( - "faceZones", - facesInst, - meshSubDir, - *this, - IOobject::READ_IF_PRESENT, - IOobject::NO_WRITE, - false - ), - *this - ); - - oldSize = faceZones_.size(); - - if (newFaceZones.size() <= faceZones_.size()) - { - faceZones_.setSize(newFaceZones.size()); - } - - // Reset existing ones - forAll(faceZones_, fzI) - { - faceZones_[fzI].resetAddressing - ( - newFaceZones[fzI], - newFaceZones[fzI].flipMap() + IOobject + ( + "pointZones", + facesInst, + meshSubDir, + *this, + IOobject::READ_IF_PRESENT, + IOobject::NO_WRITE, + false + ), + *this ); + + pointZones_.swap(newPointZones); + pointZones_.instance() = facesInst; } - // Extend with extra ones - faceZones_.setSize(newFaceZones.size()); - - for (label fzI = oldSize; fzI < newFaceZones.size(); fzI++) + // faceZones { - faceZones_.set(fzI, newFaceZones[fzI].clone(faceZones_)); - } - - faceZones_.instance() = facesInst; - - - meshCellZones newCellZones - ( - IOobject + meshFaceZones newFaceZones ( - "cellZones", - facesInst, - meshSubDir, - *this, - IOobject::READ_IF_PRESENT, - IOobject::NO_WRITE, - false - ), - *this - ); + IOobject + ( + "faceZones", + facesInst, + meshSubDir, + *this, + IOobject::READ_IF_PRESENT, + IOobject::NO_WRITE, + false + ), + *this + ); - oldSize = cellZones_.size(); - - if (newCellZones.size() <= cellZones_.size()) - { - cellZones_.setSize(newCellZones.size()); + faceZones_.swap(newFaceZones); + faceZones_.instance() = facesInst; } - // Reset existing ones - forAll(cellZones_, czI) + // cellZones { - cellZones_[czI] = newCellZones[czI]; + meshCellZones newCellZones + ( + IOobject + ( + "cellZones", + facesInst, + meshSubDir, + *this, + IOobject::READ_IF_PRESENT, + IOobject::NO_WRITE, + false + ), + *this + ); + + cellZones_.swap(newCellZones); + cellZones_.instance() = facesInst; } - // Extend with extra ones - cellZones_.setSize(newCellZones.size()); - - for (label czI = oldSize; czI < newCellZones.size(); czI++) - { - cellZones_.set(czI, newCellZones[czI].clone(cellZones_)); - } - - cellZones_.instance() = facesInst; - - // Re-read tet base points tetBasePtIsPtr_ = readTetBasePtIs(); diff --git a/src/OpenFOAM/meshes/polyMesh/zones/MeshZones/MeshZones.C b/src/OpenFOAM/meshes/polyMesh/zones/MeshZones/MeshZones.C index 322c7219ab..f3696f7a51 100644 --- a/src/OpenFOAM/meshes/polyMesh/zones/MeshZones/MeshZones.C +++ b/src/OpenFOAM/meshes/polyMesh/zones/MeshZones/MeshZones.C @@ -270,35 +270,24 @@ Foam::wordList Foam::MeshZones::names() const template -Foam::labelList Foam::MeshZones::findIndices +bool Foam::MeshZones::found ( - const wordRe& key + const word& zoneName ) const { - labelList indices; - - if (!key.empty()) + if (zoneName != word::null) { - if (key.isPattern()) + forAll(*this, i) { - indices = findStrings(key, this->names()); - } - else - { - indices.setSize(this->size()); - label nFound = 0; - forAll(*this, i) + if (zoneName == operator[](i).name()) { - if (key == operator[](i).name()) - { - indices[nFound++] = i; - } + return true; } - indices.setSize(nFound); } } - return indices; + // Not found + return false; } @@ -337,6 +326,39 @@ Foam::label Foam::MeshZones::findIndex } +template +Foam::labelList Foam::MeshZones::findIndices +( + const wordRe& key +) const +{ + labelList indices; + + if (!key.empty()) + { + if (key.isPattern()) + { + indices = findStrings(key, this->names()); + } + else + { + indices.setSize(this->size()); + label nFound = 0; + forAll(*this, i) + { + if (key == operator[](i).name()) + { + indices[nFound++] = i; + } + } + indices.setSize(nFound); + } + } + + return indices; +} + + template Foam::label Foam::MeshZones::findZoneID ( @@ -384,6 +406,33 @@ Foam::PackedBoolList Foam::MeshZones::findMatching } +template +void Foam::MeshZones::append +( + const word& zoneName, + const labelList& cells +) const +{ + MeshZones& zones = + const_cast&>(*this); + + const label zoneID = zones.size(); + zones.setSize(zoneID + 1); + + zones.set + ( + zoneID, + new ZoneType + ( + zoneName, + cells, + zoneID, + *this + ) + ); +} + + template void Foam::MeshZones::clearAddressing() { diff --git a/src/OpenFOAM/meshes/polyMesh/zones/MeshZones/MeshZones.H b/src/OpenFOAM/meshes/polyMesh/zones/MeshZones/MeshZones.H index ec936515a2..be610a6dbd 100644 --- a/src/OpenFOAM/meshes/polyMesh/zones/MeshZones/MeshZones.H +++ b/src/OpenFOAM/meshes/polyMesh/zones/MeshZones/MeshZones.H @@ -143,18 +143,31 @@ public: //- Return a list of zone names wordList names() const; - //- Return zone indices for all matches - labelList findIndices(const wordRe&) const; + //- Return true if the given zoneName is present + bool found(const word& zoneName) const; //- Return zone index for the first match, return -1 if not found label findIndex(const wordRe&) const; + //- Return zone indices for all matches + labelList findIndices(const wordRe&) const; + //- Find zone index given a name label findZoneID(const word& zoneName) const; //- Mark cells that match the zone specification PackedBoolList findMatching(const wordRe&) const; + using PtrList::append; + + //- Append a zone + // Temporary function pending the rewrite of zones + void append + ( + const word& zoneName, + const labelList& cells + ) const; + //- Clear addressing void clearAddressing(); diff --git a/src/OpenFOAM/meshes/polyMesh/zones/faceZone/faceZone.C b/src/OpenFOAM/meshes/polyMesh/zones/faceZone/faceZone.C index 9fcf653998..e638a9743d 100644 --- a/src/OpenFOAM/meshes/polyMesh/zones/faceZone/faceZone.C +++ b/src/OpenFOAM/meshes/polyMesh/zones/faceZone/faceZone.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -518,6 +518,13 @@ bool Foam::faceZone::checkParallelSync(const bool report) const } +void Foam::faceZone::swap(faceZone& fz) +{ + zone::swap(fz); + flipMap_.swap(fz.flipMap_); +} + + void Foam::faceZone::movePoints(const pointField& p) { if (patchPtr_) @@ -526,6 +533,7 @@ void Foam::faceZone::movePoints(const pointField& p) } } + void Foam::faceZone::write(Ostream& os) const { os << nl << name() diff --git a/src/OpenFOAM/meshes/polyMesh/zones/faceZone/faceZone.H b/src/OpenFOAM/meshes/polyMesh/zones/faceZone/faceZone.H index bbc7e9cc24..ba29cc1348 100644 --- a/src/OpenFOAM/meshes/polyMesh/zones/faceZone/faceZone.H +++ b/src/OpenFOAM/meshes/polyMesh/zones/faceZone/faceZone.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -288,6 +288,9 @@ public: // true if in error. virtual bool checkParallelSync(const bool report = false) const; + //- Swap two faceZones + virtual void swap(faceZone&); + //- Correct patch after moving points virtual void movePoints(const pointField&); diff --git a/src/atmosphericModels/kEpsilonLopesdaCosta/kEpsilonLopesdaCosta.C b/src/atmosphericModels/kEpsilonLopesdaCosta/kEpsilonLopesdaCosta.C index 412b8260cb..f1f5951df2 100644 --- a/src/atmosphericModels/kEpsilonLopesdaCosta/kEpsilonLopesdaCosta.C +++ b/src/atmosphericModels/kEpsilonLopesdaCosta/kEpsilonLopesdaCosta.C @@ -47,20 +47,14 @@ void kEpsilonLopesdaCosta::setPorosityCoefficient { if (pm.dict().found(C.name())) { - const labelList& cellZoneIDs = pm.cellZoneIDs(); - const scalar Cpm = pm.dict().lookup(C.name()); - forAll(cellZoneIDs, zonei) - { - const labelList& cells = - this->mesh_.cellZones()[cellZoneIDs[zonei]]; + const labelList& cells = this->mesh_.cellZones()[pm.zoneName()]; - forAll(cells, i) - { - const label celli = cells[i]; - C[celli] = Cpm; - } + forAll(cells, i) + { + const label celli = cells[i]; + C[celli] = Cpm; } } } @@ -75,21 +69,16 @@ void kEpsilonLopesdaCosta::setCdAv { if (pm.dict().found(C.name())) { - const labelList& cellZoneIDs = pm.cellZoneIDs(); const scalarField& Av = pm.Av(); const scalar Cpm = pm.dict().lookup(C.name()); - forAll(cellZoneIDs, zonei) - { - const labelList& cells = - this->mesh_.cellZones()[cellZoneIDs[zonei]]; + const labelList& cells = this->mesh_.cellZones()[pm.zoneName()]; - forAll(cells, i) - { - const label celli = cells[i]; - C[celli] = Cpm*Av[celli]; - } + forAll(cells, i) + { + const label celli = cells[i]; + C[celli] = Cpm*Av[celli]; } } } diff --git a/src/atmosphericModels/porosityModels/powerLawLopesdaCosta/powerLawLopesdaCosta.C b/src/atmosphericModels/porosityModels/powerLawLopesdaCosta/powerLawLopesdaCosta.C index 4960100cd1..49e0c6b5d7 100644 --- a/src/atmosphericModels/porosityModels/powerLawLopesdaCosta/powerLawLopesdaCosta.C +++ b/src/atmosphericModels/porosityModels/powerLawLopesdaCosta/powerLawLopesdaCosta.C @@ -258,33 +258,15 @@ Foam::porosityModels::powerLawLopesdaCostaZone::powerLawLopesdaCostaZone } // Create the normalised height field - scalarField zNorm(zBottom/(zBottom + zTop)); + const scalarField zNorm(zBottom/(zBottom + zTop)); // Create the porosity surface area per unit volume zone field Av_ = AvFunc->value(zNorm); // Create the porous region cellZone and add to the mesh cellZones - - meshCellZones& cellZones = const_cast(mesh.cellZones()); - - label zoneID = cellZones.findZoneID(zoneName_); - - if (zoneID == -1) + if (!mesh.cellZones().found(zoneName_)) { - zoneID = cellZones.size(); - cellZones.setSize(zoneID + 1); - - cellZones.set - ( - zoneID, - new cellZone - ( - zoneName_, - porousCells, - zoneID, - cellZones - ) - ); + mesh.cellZones().append(zoneName_, porousCells); } else { diff --git a/src/atmosphericModels/porosityModels/powerLawLopesdaCosta/powerLawLopesdaCostaTemplates.C b/src/atmosphericModels/porosityModels/powerLawLopesdaCosta/powerLawLopesdaCostaTemplates.C index 83302a6c42..3824f114cd 100644 --- a/src/atmosphericModels/porosityModels/powerLawLopesdaCosta/powerLawLopesdaCostaTemplates.C +++ b/src/atmosphericModels/porosityModels/powerLawLopesdaCosta/powerLawLopesdaCostaTemplates.C @@ -38,18 +38,16 @@ void Foam::porosityModels::powerLawLopesdaCosta::apply { const scalar C1m1b2 = (C1_ - 1.0)/2.0; - forAll(cellZoneIDs_, zonei) + const labelList& cells = + mesh_.cellZones()[powerLawLopesdaCostaZone::zoneName_]; + + forAll(cells, i) { - const labelList& cells = mesh_.cellZones()[cellZoneIDs_[zonei]]; + const label celli = cells[i]; - forAll(cells, i) - { - const label celli = cells[i]; - - Udiag[celli] += - V[celli]*rho[celli] - *Cd_*Av_[i]*pow(magSqr(U[celli]), C1m1b2); - } + Udiag[celli] += + V[celli]*rho[celli] + *Cd_*Av_[i]*pow(magSqr(U[celli]), C1m1b2); } } @@ -64,22 +62,20 @@ void Foam::porosityModels::powerLawLopesdaCosta::apply { const scalar C1m1b2 = (C1_ - 1.0)/2.0; - forAll(cellZoneIDs_, zonei) + const labelList& cells = + mesh_.cellZones()[powerLawLopesdaCostaZone::zoneName_]; + + forAll(cells, i) { - const labelList& cells = mesh_.cellZones()[cellZoneIDs_[zonei]]; + const label celli = cells[i]; - forAll(cells, i) - { - const label celli = cells[i]; - - AU[celli] = - AU[celli] - + I - *( - 0.5*rho[celli]*Cd_*Av_[i] - *pow(magSqr(U[celli]), C1m1b2) - ); - } + AU[celli] = + AU[celli] + + I + *( + 0.5*rho[celli]*Cd_*Av_[i] + *pow(magSqr(U[celli]), C1m1b2) + ); } } diff --git a/src/finiteVolume/cfdTools/general/porosityModel/DarcyForchheimer/DarcyForchheimer.C b/src/finiteVolume/cfdTools/general/porosityModel/DarcyForchheimer/DarcyForchheimer.C index 1c41287a30..c136c1b169 100644 --- a/src/finiteVolume/cfdTools/general/porosityModel/DarcyForchheimer/DarcyForchheimer.C +++ b/src/finiteVolume/cfdTools/general/porosityModel/DarcyForchheimer/DarcyForchheimer.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2012-2022 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2012-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -54,8 +54,6 @@ Foam::porosityModels::DarcyForchheimer::DarcyForchheimer porosityModel(name, modelType, mesh, dict, cellZoneName), dXYZ_("d", dimless/sqr(dimLength), coeffs_), fXYZ_("f", dimless/dimLength, coeffs_), - D_(cellZoneIDs_.size()), - F_(cellZoneIDs_.size()), rhoName_(coeffs_.lookupOrDefault("rho", "rho")), muName_(coeffs_.lookupOrDefault("mu", "mu")), nuName_(coeffs_.lookupOrDefault("nu", "nu")) @@ -79,58 +77,52 @@ void Foam::porosityModels::DarcyForchheimer::calcTransformModelData() { if (coordSys_.R().uniform()) { - forAll(cellZoneIDs_, zoneI) - { - D_[zoneI].setSize(1); - F_[zoneI].setSize(1); + D_.setSize(1); + F_.setSize(1); - D_[zoneI][0] = Zero; - D_[zoneI][0].xx() = dXYZ_.value().x(); - D_[zoneI][0].yy() = dXYZ_.value().y(); - D_[zoneI][0].zz() = dXYZ_.value().z(); + D_[0] = Zero; + D_[0].xx() = dXYZ_.value().x(); + D_[0].yy() = dXYZ_.value().y(); + D_[0].zz() = dXYZ_.value().z(); - D_[zoneI][0] = coordSys_.R().transform(Zero, D_[zoneI][0]); + D_[0] = coordSys_.R().transform(Zero, D_[0]); - // leading 0.5 is from 1/2*rho - F_[zoneI][0] = Zero; - F_[zoneI][0].xx() = 0.5*fXYZ_.value().x(); - F_[zoneI][0].yy() = 0.5*fXYZ_.value().y(); - F_[zoneI][0].zz() = 0.5*fXYZ_.value().z(); + // leading 0.5 is from 1/2*rho + F_[0] = Zero; + F_[0].xx() = 0.5*fXYZ_.value().x(); + F_[0].yy() = 0.5*fXYZ_.value().y(); + F_[0].zz() = 0.5*fXYZ_.value().z(); - F_[zoneI][0] = coordSys_.R().transform(Zero, F_[zoneI][0]); - } + F_[0] = coordSys_.R().transform(Zero, F_[0]); } else { - forAll(cellZoneIDs_, zoneI) + const labelList& cells = mesh_.cellZones()[zoneName_]; + + D_.setSize(cells.size()); + F_.setSize(cells.size()); + + forAll(cells, i) { - const labelList& cells = mesh_.cellZones()[cellZoneIDs_[zoneI]]; + D_[i] = Zero; + D_[i].xx() = dXYZ_.value().x(); + D_[i].yy() = dXYZ_.value().y(); + D_[i].zz() = dXYZ_.value().z(); - D_[zoneI].setSize(cells.size()); - F_[zoneI].setSize(cells.size()); - - forAll(cells, i) - { - D_[zoneI][i] = Zero; - D_[zoneI][i].xx() = dXYZ_.value().x(); - D_[zoneI][i].yy() = dXYZ_.value().y(); - D_[zoneI][i].zz() = dXYZ_.value().z(); - - // leading 0.5 is from 1/2*rho - F_[zoneI][i] = Zero; - F_[zoneI][i].xx() = 0.5*fXYZ_.value().x(); - F_[zoneI][i].yy() = 0.5*fXYZ_.value().y(); - F_[zoneI][i].zz() = 0.5*fXYZ_.value().z(); - } - - const coordinateRotation& R = coordSys_.R - ( - UIndirectList(mesh_.C(), cells)() - ); - - D_[zoneI] = R.transform(D_[zoneI]); - F_[zoneI] = R.transform(F_[zoneI]); + // leading 0.5 is from 1/2*rho + F_[i] = Zero; + F_[i].xx() = 0.5*fXYZ_.value().x(); + F_[i].yy() = 0.5*fXYZ_.value().y(); + F_[i].zz() = 0.5*fXYZ_.value().z(); } + + const coordinateRotation& R = coordSys_.R + ( + UIndirectList(mesh_.C(), cells)() + ); + + D_ = R.transform(D_); + F_ = R.transform(F_); } if (debug && (mesh_.time().writeTime() || mesh_.time().timeIndex() == 0)) @@ -162,8 +154,8 @@ void Foam::porosityModels::DarcyForchheimer::calcTransformModelData() dimensionedTensor(fXYZ_.dimensions(), Zero) ); - UIndirectList(Dout, mesh_.cellZones()[cellZoneIDs_[0]]) = D_[0]; - UIndirectList(Fout, mesh_.cellZones()[cellZoneIDs_[0]]) = F_[0]; + UIndirectList(Dout, mesh_.cellZones()[zoneName_]) = D_; + UIndirectList(Fout, mesh_.cellZones()[zoneName_]) = F_; Dout.write(); Fout.write(); diff --git a/src/finiteVolume/cfdTools/general/porosityModel/DarcyForchheimer/DarcyForchheimer.H b/src/finiteVolume/cfdTools/general/porosityModel/DarcyForchheimer/DarcyForchheimer.H index f4cc42bf1c..c285af051b 100644 --- a/src/finiteVolume/cfdTools/general/porosityModel/DarcyForchheimer/DarcyForchheimer.H +++ b/src/finiteVolume/cfdTools/general/porosityModel/DarcyForchheimer/DarcyForchheimer.H @@ -79,10 +79,10 @@ class DarcyForchheimer dimensionedVector fXYZ_; //- Darcy coefficient - converted from dXYZ [1/m^2] - List D_; + tensorField D_; //- Forchheimer coefficient - converted from fXYZ [1/m] - List F_; + tensorField F_; //- Name of density field word rhoName_; diff --git a/src/finiteVolume/cfdTools/general/porosityModel/DarcyForchheimer/DarcyForchheimerTemplates.C b/src/finiteVolume/cfdTools/general/porosityModel/DarcyForchheimer/DarcyForchheimerTemplates.C index fbf633a843..42cc28ae4a 100644 --- a/src/finiteVolume/cfdTools/general/porosityModel/DarcyForchheimer/DarcyForchheimerTemplates.C +++ b/src/finiteVolume/cfdTools/general/porosityModel/DarcyForchheimer/DarcyForchheimerTemplates.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2012-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2012-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -36,25 +36,19 @@ void Foam::porosityModels::DarcyForchheimer::apply const vectorField& U ) const { - forAll(cellZoneIDs_, zoneI) + const labelList& cells = mesh_.cellZones()[zoneName_]; + + forAll(cells, i) { - const tensorField& dZones = D_[zoneI]; - const tensorField& fZones = F_[zoneI]; + const label celli = cells[i]; + const label j = this->fieldIndex(i); + const tensor Cd = + mu[celli]*D_[j] + (rho[celli]*mag(U[celli]))*F_[j]; - const labelList& cells = mesh_.cellZones()[cellZoneIDs_[zoneI]]; + const scalar isoCd = tr(Cd); - forAll(cells, i) - { - const label celli = cells[i]; - const label j = this->fieldIndex(i); - const tensor Cd = - mu[celli]*dZones[j] + (rho[celli]*mag(U[celli]))*fZones[j]; - - const scalar isoCd = tr(Cd); - - Udiag[celli] += V[celli]*isoCd; - Usource[celli] -= V[celli]*((Cd - I*isoCd) & U[celli]); - } + Udiag[celli] += V[celli]*isoCd; + Usource[celli] -= V[celli]*((Cd - I*isoCd) & U[celli]); } } @@ -68,22 +62,16 @@ void Foam::porosityModels::DarcyForchheimer::apply const vectorField& U ) const { - forAll(cellZoneIDs_, zoneI) + const labelList& cells = mesh_.cellZones()[zoneName_]; + + forAll(cells, i) { - const tensorField& dZones = D_[zoneI]; - const tensorField& fZones = F_[zoneI]; + const label celli = cells[i]; + const label j = this->fieldIndex(i); + const tensor D = D_[j]; + const tensor F = F_[j]; - const labelList& cells = mesh_.cellZones()[cellZoneIDs_[zoneI]]; - - forAll(cells, i) - { - const label celli = cells[i]; - const label j = this->fieldIndex(i); - const tensor D = dZones[j]; - const tensor F = fZones[j]; - - AU[celli] += mu[celli]*D + (rho[celli]*mag(U[celli]))*F; - } + AU[celli] += mu[celli]*D + (rho[celli]*mag(U[celli]))*F; } } diff --git a/src/finiteVolume/cfdTools/general/porosityModel/fixedCoeff/fixedCoeff.C b/src/finiteVolume/cfdTools/general/porosityModel/fixedCoeff/fixedCoeff.C index 3705514ee9..22be1fb0fe 100644 --- a/src/finiteVolume/cfdTools/general/porosityModel/fixedCoeff/fixedCoeff.C +++ b/src/finiteVolume/cfdTools/general/porosityModel/fixedCoeff/fixedCoeff.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2012-2022 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2012-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -50,23 +50,17 @@ void Foam::porosityModels::fixedCoeff::apply const scalar rho ) const { - forAll(cellZoneIDs_, zoneI) + const labelList& cells = mesh_.cellZones()[zoneName_]; + + forAll(cells, i) { - const tensorField& alphaZones = alpha_[zoneI]; - const tensorField& betaZones = beta_[zoneI]; + const label celli = cells[i]; + const label j = fieldIndex(i); + const tensor Cd = rho*(alpha_[j] + beta_[j]*mag(U[celli])); + const scalar isoCd = tr(Cd); - const labelList& cells = mesh_.cellZones()[cellZoneIDs_[zoneI]]; - - forAll(cells, i) - { - const label celli = cells[i]; - const label j = fieldIndex(i); - const tensor Cd = rho*(alphaZones[j] + betaZones[j]*mag(U[celli])); - const scalar isoCd = tr(Cd); - - Udiag[celli] += V[celli]*isoCd; - Usource[celli] -= V[celli]*((Cd - I*isoCd) & U[celli]); - } + Udiag[celli] += V[celli]*isoCd; + Usource[celli] -= V[celli]*((Cd - I*isoCd) & U[celli]); } } @@ -78,23 +72,16 @@ void Foam::porosityModels::fixedCoeff::apply const scalar rho ) const { + const labelList& cells = mesh_.cellZones()[zoneName_]; - forAll(cellZoneIDs_, zoneI) + forAll(cells, i) { - const tensorField& alphaZones = alpha_[zoneI]; - const tensorField& betaZones = beta_[zoneI]; + const label celli = cells[i]; + const label j = fieldIndex(i); + const tensor alpha = alpha_[j]; + const tensor beta = beta_[j]; - const labelList& cells = mesh_.cellZones()[cellZoneIDs_[zoneI]]; - - forAll(cells, i) - { - const label celli = cells[i]; - const label j = fieldIndex(i); - const tensor alpha = alphaZones[j]; - const tensor beta = betaZones[j]; - - AU[celli] += rho*(alpha + beta*mag(U[celli])); - } + AU[celli] += rho*(alpha + beta*mag(U[celli])); } } @@ -112,9 +99,7 @@ Foam::porosityModels::fixedCoeff::fixedCoeff : porosityModel(name, modelType, mesh, dict, cellZoneName), alphaXYZ_("alpha", dimless/dimTime, coeffs_), - betaXYZ_("beta", dimless/dimLength, coeffs_), - alpha_(cellZoneIDs_.size()), - beta_(cellZoneIDs_.size()) + betaXYZ_("beta", dimless/dimLength, coeffs_) { adjustNegativeResistance(alphaXYZ_); adjustNegativeResistance(betaXYZ_); @@ -135,54 +120,48 @@ void Foam::porosityModels::fixedCoeff::calcTransformModelData() { if (coordSys_.R().uniform()) { - forAll(cellZoneIDs_, zoneI) - { - alpha_[zoneI].setSize(1); - beta_[zoneI].setSize(1); + alpha_.setSize(1); + beta_.setSize(1); - alpha_[zoneI][0] = Zero; - alpha_[zoneI][0].xx() = alphaXYZ_.value().x(); - alpha_[zoneI][0].yy() = alphaXYZ_.value().y(); - alpha_[zoneI][0].zz() = alphaXYZ_.value().z(); - alpha_[zoneI][0] = coordSys_.R().transform(Zero, alpha_[zoneI][0]); + alpha_[0] = Zero; + alpha_[0].xx() = alphaXYZ_.value().x(); + alpha_[0].yy() = alphaXYZ_.value().y(); + alpha_[0].zz() = alphaXYZ_.value().z(); + alpha_[0] = coordSys_.R().transform(Zero, alpha_[0]); - beta_[zoneI][0] = Zero; - beta_[zoneI][0].xx() = betaXYZ_.value().x(); - beta_[zoneI][0].yy() = betaXYZ_.value().y(); - beta_[zoneI][0].zz() = betaXYZ_.value().z(); - beta_[zoneI][0] = coordSys_.R().transform(Zero, beta_[zoneI][0]); - } + beta_[0] = Zero; + beta_[0].xx() = betaXYZ_.value().x(); + beta_[0].yy() = betaXYZ_.value().y(); + beta_[0].zz() = betaXYZ_.value().z(); + beta_[0] = coordSys_.R().transform(Zero, beta_[0]); } else { - forAll(cellZoneIDs_, zoneI) + const labelList& cells = mesh_.cellZones()[zoneName_]; + + alpha_.setSize(cells.size()); + beta_.setSize(cells.size()); + + forAll(cells, i) { - const labelList& cells = mesh_.cellZones()[cellZoneIDs_[zoneI]]; + alpha_[i] = Zero; + alpha_[i].xx() = alphaXYZ_.value().x(); + alpha_[i].yy() = alphaXYZ_.value().y(); + alpha_[i].zz() = alphaXYZ_.value().z(); - alpha_[zoneI].setSize(cells.size()); - beta_[zoneI].setSize(cells.size()); - - forAll(cells, i) - { - alpha_[zoneI][i] = Zero; - alpha_[zoneI][i].xx() = alphaXYZ_.value().x(); - alpha_[zoneI][i].yy() = alphaXYZ_.value().y(); - alpha_[zoneI][i].zz() = alphaXYZ_.value().z(); - - beta_[zoneI][i] = Zero; - beta_[zoneI][i].xx() = betaXYZ_.value().x(); - beta_[zoneI][i].yy() = betaXYZ_.value().y(); - beta_[zoneI][i].zz() = betaXYZ_.value().z(); - } - - const coordinateRotation& R = coordSys_.R - ( - UIndirectList(mesh_.C(), cells)() - ); - - alpha_[zoneI] = R.transform(alpha_[zoneI]); - beta_[zoneI] = R.transform(beta_[zoneI]); + beta_[i] = Zero; + beta_[i].xx() = betaXYZ_.value().x(); + beta_[i].yy() = betaXYZ_.value().y(); + beta_[i].zz() = betaXYZ_.value().z(); } + + const coordinateRotation& R = coordSys_.R + ( + UIndirectList(mesh_.C(), cells)() + ); + + alpha_ = R.transform(alpha_); + beta_ = R.transform(beta_); } } diff --git a/src/finiteVolume/cfdTools/general/porosityModel/fixedCoeff/fixedCoeff.H b/src/finiteVolume/cfdTools/general/porosityModel/fixedCoeff/fixedCoeff.H index ec9eee5496..63fbdfec75 100644 --- a/src/finiteVolume/cfdTools/general/porosityModel/fixedCoeff/fixedCoeff.H +++ b/src/finiteVolume/cfdTools/general/porosityModel/fixedCoeff/fixedCoeff.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2012-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2012-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -69,10 +69,10 @@ class fixedCoeff dimensionedVector betaXYZ_; //- Model alpha coefficient - converted from alphaXYZ [1/s] - List alpha_; + tensorField alpha_; //- Model beta coefficient - converted from betaXYZ [1/m] - List beta_; + tensorField beta_; // Private Member Functions diff --git a/src/finiteVolume/cfdTools/general/porosityModel/porosityModel/porosityModel.C b/src/finiteVolume/cfdTools/general/porosityModel/porosityModel/porosityModel.C index e1c8d64790..c8d25be7fb 100644 --- a/src/finiteVolume/cfdTools/general/porosityModel/porosityModel/porosityModel.C +++ b/src/finiteVolume/cfdTools/general/porosityModel/porosityModel/porosityModel.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2012-2022 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2012-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -100,23 +100,17 @@ Foam::porosityModel::porosityModel mesh_(mesh), dict_(dict), coeffs_(dict.optionalSubDict(modelType + "Coeffs")), - zoneName_(cellZoneName), - cellZoneIDs_(), + zoneName_ + ( + cellZoneName != word::null + ? cellZoneName + : dict_.lookup("cellZone") + ), coordSys_(coordinateSystem::New(mesh, coeffs_)) { - if (zoneName_ == word::null) - { - dict_.lookup("cellZone") >> zoneName_; - } - - cellZoneIDs_ = mesh_.cellZones().findIndices(zoneName_); - Info<< " creating porous zone: " << zoneName_ << endl; - bool foundZone = !cellZoneIDs_.empty(); - reduce(foundZone, orOp()); - - if (!foundZone && Pstream::master()) + if (mesh_.cellZones().findIndex(zoneName_) == -1) { FatalErrorInFunction << "cannot find porous cellZone " << zoneName_ @@ -155,11 +149,7 @@ Foam::tmp Foam::porosityModel::porosityModel::force const_cast(*this).transformModelData(); tmp tforce(new vectorField(U.size(), Zero)); - - if (!cellZoneIDs_.empty()) - { - this->calcForce(U, rho, mu, tforce.ref()); - } + this->calcForce(U, rho, mu, tforce.ref()); return tforce; } @@ -167,11 +157,6 @@ Foam::tmp Foam::porosityModel::porosityModel::force void Foam::porosityModel::addResistance(fvVectorMatrix& UEqn) { - if (cellZoneIDs_.empty()) - { - return; - } - transformModelData(); this->correct(UEqn); } @@ -184,19 +169,14 @@ void Foam::porosityModel::addResistance bool correctAUprocBC ) { - if (cellZoneIDs_.empty()) - { - return; - } - transformModelData(); this->correct(UEqn, AU); if (correctAUprocBC) { - // Correct the boundary conditions of the tensorial diagonal to ensure - // processor boundaries are correctly handled when AU^-1 is interpolated - // for the pressure equation. + // Correct the boundary conditions of the tensorial diagonal to + // ensure processor boundaries are correctly handled when AU^-1 is + // interpolated for the pressure equation. AU.correctBoundaryConditions(); } } @@ -213,7 +193,6 @@ bool Foam::porosityModel::read(const dictionary& dict) coeffs_ = dict.optionalSubDict(type() + "Coeffs"); dict.lookup("cellZone") >> zoneName_; - cellZoneIDs_ = mesh_.cellZones().findIndices(zoneName_); return true; } diff --git a/src/finiteVolume/cfdTools/general/porosityModel/porosityModel/porosityModel.H b/src/finiteVolume/cfdTools/general/porosityModel/porosityModel/porosityModel.H index 5600893365..3a743454cc 100644 --- a/src/finiteVolume/cfdTools/general/porosityModel/porosityModel/porosityModel.H +++ b/src/finiteVolume/cfdTools/general/porosityModel/porosityModel/porosityModel.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2012-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2012-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -81,11 +81,8 @@ protected: //- Model coefficients dictionary dictionary coeffs_; - //- Name(s) of cell-zone - wordRe zoneName_; - - //- Cell zone IDs - labelList cellZoneIDs_; + //- Name of cellZone + word zoneName_; //- Local co-ordinate system coordinateSystem coordSys_; @@ -205,8 +202,8 @@ public: //- Return const access to the porosity model name inline const word& name() const; - //- Return const access to the cell zone IDs - inline const labelList& cellZoneIDs() const; + //- Return const access to the cell zone name + inline const word& zoneName() const; //- Return dictionary used for model construction const dictionary& dict() const; diff --git a/src/finiteVolume/cfdTools/general/porosityModel/porosityModel/porosityModelI.H b/src/finiteVolume/cfdTools/general/porosityModel/porosityModel/porosityModelI.H index 1c15082c0e..77005e6c15 100644 --- a/src/finiteVolume/cfdTools/general/porosityModel/porosityModel/porosityModelI.H +++ b/src/finiteVolume/cfdTools/general/porosityModel/porosityModel/porosityModelI.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2012-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2012-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -35,9 +35,9 @@ inline const Foam::dictionary& Foam::porosityModel::dict() const } -inline const Foam::labelList& Foam::porosityModel::cellZoneIDs() const +inline const Foam::word& Foam::porosityModel::zoneName() const { - return cellZoneIDs_; + return zoneName_; } diff --git a/src/finiteVolume/cfdTools/general/porosityModel/powerLaw/powerLawTemplates.C b/src/finiteVolume/cfdTools/general/porosityModel/powerLaw/powerLawTemplates.C index 7791e40d0d..9b655acb1f 100644 --- a/src/finiteVolume/cfdTools/general/porosityModel/powerLaw/powerLawTemplates.C +++ b/src/finiteVolume/cfdTools/general/porosityModel/powerLaw/powerLawTemplates.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2012-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2012-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -34,20 +34,17 @@ void Foam::porosityModels::powerLaw::apply const vectorField& U ) const { + const labelList& cells = mesh_.cellZones()[zoneName_]; + const scalar C0 = C0_; const scalar C1m1b2 = (C1_ - 1.0)/2.0; - forAll(cellZoneIDs_, zoneI) + forAll(cells, i) { - const labelList& cells = mesh_.cellZones()[cellZoneIDs_[zoneI]]; + const label celli = cells[i]; - forAll(cells, i) - { - const label celli = cells[i]; - - Udiag[celli] += - V[celli]*rho[celli]*C0*pow(magSqr(U[celli]), C1m1b2); - } + Udiag[celli] += + V[celli]*rho[celli]*C0*pow(magSqr(U[celli]), C1m1b2); } } @@ -60,20 +57,17 @@ void Foam::porosityModels::powerLaw::apply const vectorField& U ) const { + const labelList& cells = mesh_.cellZones()[zoneName_]; + const scalar C0 = C0_; const scalar C1m1b2 = (C1_ - 1.0)/2.0; - forAll(cellZoneIDs_, zoneI) + forAll(cells, i) { - const labelList& cells = mesh_.cellZones()[cellZoneIDs_[zoneI]]; + const label celli = cells[i]; - forAll(cells, i) - { - const label celli = cells[i]; - - AU[celli] = - AU[celli] + I*(rho[celli]*C0*pow(magSqr(U[celli]), C1m1b2)); - } + AU[celli] = + AU[celli] + I*(rho[celli]*C0*pow(magSqr(U[celli]), C1m1b2)); } } diff --git a/src/finiteVolume/cfdTools/general/porosityModel/solidification/solidificationTemplates.C b/src/finiteVolume/cfdTools/general/porosityModel/solidification/solidificationTemplates.C index d744d34a52..84f05fc40b 100644 --- a/src/finiteVolume/cfdTools/general/porosityModel/solidification/solidificationTemplates.C +++ b/src/finiteVolume/cfdTools/general/porosityModel/solidification/solidificationTemplates.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2017-2018 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2017-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -38,21 +38,18 @@ void Foam::porosityModels::solidification::apply const volVectorField& U ) const { + const labelList& cells = mesh_.cellZones()[zoneName_]; + const volScalarField& T = mesh_.lookupObject ( IOobject::groupName(TName_, U.group()) ); - forAll(cellZoneIDs_, zoneI) + forAll(cells, i) { - const labelList& cells = mesh_.cellZones()[cellZoneIDs_[zoneI]]; - - forAll(cells, i) - { - const label celli = cells[i]; - Udiag[celli] += - V[celli]*alpha[celli]*rho[celli]*D_->value(T[celli]); - } + const label celli = cells[i]; + Udiag[celli] += + V[celli]*alpha[celli]*rho[celli]*D_->value(T[celli]); } } @@ -66,21 +63,18 @@ void Foam::porosityModels::solidification::apply const volVectorField& U ) const { + const labelList& cells = mesh_.cellZones()[zoneName_]; + const volScalarField& T = mesh_.lookupObject ( IOobject::groupName(TName_, U.group()) ); - forAll(cellZoneIDs_, zoneI) + forAll(cells, i) { - const labelList& cells = mesh_.cellZones()[cellZoneIDs_[zoneI]]; - - forAll(cells, i) - { - const label celli = cells[i]; - AU[celli] += - tensor::I*alpha[celli]*rho[celli]*D_->value(T[celli]); - } + const label celli = cells[i]; + AU[celli] += + tensor::I*alpha[celli]*rho[celli]*D_->value(T[celli]); } } diff --git a/src/functionObjects/forces/forces/forces.C b/src/functionObjects/forces/forces/forces.C index f0410361c8..dea3cab218 100644 --- a/src/functionObjects/forces/forces/forces.C +++ b/src/functionObjects/forces/forces/forces.C @@ -991,21 +991,14 @@ void Foam::functionObjects::forces::calcForcesMoment() const vectorField fPTot(pm.force(U, rho, mu)); - const labelList& cellZoneIDs = pm.cellZoneIDs(); + const cellZone& cZone = mesh_.cellZones()[pm.zoneName()]; + const vectorField d(mesh_.C(), cZone); + const vectorField fP(fPTot, cZone); + const vectorField Md(d - coordSys_.origin()); - forAll(cellZoneIDs, i) - { - const label zoneI = cellZoneIDs[i]; - const cellZone& cZone = mesh_.cellZones()[zoneI]; + const vectorField fDummy(Md.size(), Zero); - const vectorField d(mesh_.C(), cZone); - const vectorField fP(fPTot, cZone); - const vectorField Md(d - coordSys_.origin()); - - const vectorField fDummy(Md.size(), Zero); - - applyBins(Md, fDummy, fDummy, fP, d); - } + applyBins(Md, fDummy, fDummy, fP, d); } } diff --git a/src/fvModels/derived/porosityForce/porosityForce.C b/src/fvModels/derived/porosityForce/porosityForce.C index f3f9ac16ed..1a1cadccc5 100644 --- a/src/fvModels/derived/porosityForce/porosityForce.C +++ b/src/fvModels/derived/porosityForce/porosityForce.C @@ -24,9 +24,8 @@ License \*---------------------------------------------------------------------------*/ #include "porosityForce.H" -#include "fvMesh.H" -#include "fvMatrices.H" #include "porosityModel.H" +#include "fvMatrices.H" #include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -51,6 +50,20 @@ namespace fv // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // +void Foam::fv::porosityForce::reset() +{ + porosityPtr_.reset + ( + porosityModel::New + ( + name(), + mesh(), + coeffs() + ).ptr() + ); +} + + void Foam::fv::porosityForce::readCoeffs() { if (coeffs().found("UNames")) @@ -62,20 +75,10 @@ void Foam::fv::porosityForce::readCoeffs() UNames_ = wordList(1, coeffs().lookupOrDefault("U", "U")); } - porosityPtr_.reset - ( - porosityModel::New - ( - name(), - mesh(), - coeffs(), - set_.cellSetName() - ).ptr() - ); + reset(); } - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::fv::porosityForce::porosityForce @@ -87,7 +90,6 @@ Foam::fv::porosityForce::porosityForce ) : fvModel(name, modelType, mesh, dict), - set_(mesh, coeffs()), UNames_(), porosityPtr_(nullptr) { @@ -144,20 +146,20 @@ void Foam::fv::porosityForce::addSup bool Foam::fv::porosityForce::movePoints() { - set_.movePoints(); + // Currently there is no mechanism to update the porous media orientation return true; } void Foam::fv::porosityForce::topoChange(const polyTopoChangeMap& map) { - set_.topoChange(map); + reset(); } void Foam::fv::porosityForce::mapMesh(const polyMeshMap& map) { - set_.mapMesh(map); + reset(); } @@ -166,7 +168,7 @@ void Foam::fv::porosityForce::distribute const polyDistributionMap& map ) { - set_.distribute(map); + reset(); } @@ -174,7 +176,6 @@ bool Foam::fv::porosityForce::read(const dictionary& dict) { if (fvModel::read(dict)) { - set_.read(coeffs()); readCoeffs(); return true; } diff --git a/src/fvModels/derived/porosityForce/porosityForce.H b/src/fvModels/derived/porosityForce/porosityForce.H index 29a601b955..7728e2ecf3 100644 --- a/src/fvModels/derived/porosityForce/porosityForce.H +++ b/src/fvModels/derived/porosityForce/porosityForce.H @@ -66,7 +66,6 @@ SourceFiles #define porosityForce_H #include "fvModel.H" -#include "fvCellSet.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -78,7 +77,6 @@ class porosityModel; namespace fv { - /*---------------------------------------------------------------------------*\ Class porosityForce Declaration \*---------------------------------------------------------------------------*/ @@ -89,9 +87,6 @@ class porosityForce { // Private data - //- The set of cells the fvConstraint applies to - fvCellSet set_; - //- Names of the velocity fields wordList UNames_; @@ -101,6 +96,10 @@ class porosityForce // Private Member Functions + //- Reset the porosity model + // during construction, re-reading and mesh-change + void reset(); + //- Non-virtual read void readCoeffs(); diff --git a/src/fvModels/interRegion/interRegionPorosityForce/interRegionPorosityForce.C b/src/fvModels/interRegion/interRegionPorosityForce/interRegionPorosityForce.C index 447c6f2104..960c73caa0 100644 --- a/src/fvModels/interRegion/interRegionPorosityForce/interRegionPorosityForce.C +++ b/src/fvModels/interRegion/interRegionPorosityForce/interRegionPorosityForce.C @@ -88,17 +88,8 @@ Foam::fv::interRegionPorosityForce::interRegionPorosityForce const word zoneName(name + ":porous"); - const meshCellZones& cellZones = mesh.cellZones(); - label zoneID = cellZones.findZoneID(zoneName); - - if (zoneID == -1) + if (!mesh.cellZones().found(zoneName)) { - meshCellZones& cz = const_cast(cellZones); - - zoneID = cz.size(); - - cz.setSize(zoneID + 1); - // Scan the porous region filter for all cells containing porosity labelList porousCells(mesh.nCells()); @@ -112,19 +103,7 @@ Foam::fv::interRegionPorosityForce::interRegionPorosityForce } porousCells.setSize(i); - cz.set - ( - zoneID, - new cellZone - ( - zoneName, - porousCells, - zoneID, - cellZones - ) - ); - - cz.clearAddressing(); + mesh.cellZones().append(zoneName, porousCells); } else { diff --git a/src/meshTools/cutPoly/cutPolyIsoSurface.C b/src/meshTools/cutPoly/cutPolyIsoSurface.C index 03af4e43f2..dc2e6788c2 100644 --- a/src/meshTools/cutPoly/cutPolyIsoSurface.C +++ b/src/meshTools/cutPoly/cutPolyIsoSurface.C @@ -44,7 +44,7 @@ Foam::cutPolyIsoSurface::cutPolyIsoSurface const polyMesh& mesh, const scalarField& pAlphas, const scalar isoAlpha, - const labelList& zoneIDs + const word& cellZoneName ) : points_(), @@ -89,14 +89,13 @@ Foam::cutPolyIsoSurface::cutPolyIsoSurface nCutCells += !cellCuts[celli].empty(); }; - if (!isNull(zoneIDs)) + + if (cellZoneName != word::null) { - forAll(zoneIDs, i) + const labelList& zoneCells = mesh.cellZones()[cellZoneName]; + forAll(zoneCells, zoneCelli) { - forAll(mesh.cellZones()[zoneIDs[i]], zoneCelli) - { - cutCell(mesh.cellZones()[zoneIDs[i]][zoneCelli]); - } + cutCell(zoneCells[zoneCelli]); } } else diff --git a/src/meshTools/cutPoly/cutPolyIsoSurface.H b/src/meshTools/cutPoly/cutPolyIsoSurface.H index dc000c2559..2bb9b8d654 100644 --- a/src/meshTools/cutPoly/cutPolyIsoSurface.H +++ b/src/meshTools/cutPoly/cutPolyIsoSurface.H @@ -81,7 +81,7 @@ public: const polyMesh& mesh, const scalarField& pAlphas, const scalar isoAlpha, - const labelList& zoneIDs = NullObjectRef() + const word& cellZoneName = word::null ); //- Construct by combining a list of iso-surfaces diff --git a/src/meshTools/sets/faceSources/zoneToFace/zoneToFace.H b/src/meshTools/sets/faceSources/zoneToFace/zoneToFace.H index adf7975006..a2d0415b22 100644 --- a/src/meshTools/sets/faceSources/zoneToFace/zoneToFace.H +++ b/src/meshTools/sets/faceSources/zoneToFace/zoneToFace.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,7 +25,7 @@ Class Foam::zoneToFace Description - A topoSetSource to select faces based on faceZone. + A topoSetSource to select faces from a faceZone. SourceFiles zoneToFace.C @@ -51,11 +51,9 @@ class zoneToFace : public topoSetSource { - // Private Data - - //- Name/regular expression of cellZone + //- Name/regular expression of faceZone wordRe zoneName_; @@ -102,7 +100,6 @@ public: const topoSetSource::setAction action, topoSet& ) const; - }; diff --git a/src/sampling/sampledSurface/sampledCutPlane/sampledCutPlane.C b/src/sampling/sampledSurface/sampledCutPlane/sampledCutPlane.C index 8af9d57ca7..a083e48b13 100644 --- a/src/sampling/sampledSurface/sampledCutPlane/sampledCutPlane.C +++ b/src/sampling/sampledSurface/sampledCutPlane/sampledCutPlane.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -66,7 +66,7 @@ Foam::sampledSurfaces::cutPlane::calcIsoSurf() const // Construct an iso-surface at the given distance return autoPtr ( - new cutPolyIsoSurface(mesh(), pointDistance, 0, zoneIDs()) + new cutPolyIsoSurface(mesh(), pointDistance, 0, zoneName()) ); } diff --git a/src/sampling/sampledSurface/sampledDistanceSurface/sampledDistanceSurface.C b/src/sampling/sampledSurface/sampledDistanceSurface/sampledDistanceSurface.C index 658c4d1ec0..bd2f0738f2 100644 --- a/src/sampling/sampledSurface/sampledDistanceSurface/sampledDistanceSurface.C +++ b/src/sampling/sampledSurface/sampledDistanceSurface/sampledDistanceSurface.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -90,7 +90,7 @@ Foam::sampledSurfaces::distanceSurface::calcIsoSurf() const // Construct an iso-surface at the given distance return autoPtr ( - new cutPolyIsoSurface(mesh(), pointDistance, distance_, zoneIDs()) + new cutPolyIsoSurface(mesh(), pointDistance, distance_, zoneName()) ); } diff --git a/src/sampling/sampledSurface/sampledIsoSurface/sampledIsoSurface.C b/src/sampling/sampledSurface/sampledIsoSurface/sampledIsoSurface.C index df31f9fcb3..c140adca5d 100644 --- a/src/sampling/sampledSurface/sampledIsoSurface/sampledIsoSurface.C +++ b/src/sampling/sampledSurface/sampledIsoSurface/sampledIsoSurface.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -60,7 +60,7 @@ Foam::sampledSurfaces::isoSurface::calcIsoSurf() const isoSurfs.set ( i, - new cutPolyIsoSurface(mesh(), pField, isoValues_[i], zoneIDs()) + new cutPolyIsoSurface(mesh(), pField, isoValues_[i], zoneName()) ); } diff --git a/src/sampling/sampledSurface/sampledIsoSurfaceSurface/sampledIsoSurfaceSurface.C b/src/sampling/sampledSurface/sampledIsoSurfaceSurface/sampledIsoSurfaceSurface.C index 7fdea80aa3..92a2a32519 100644 --- a/src/sampling/sampledSurface/sampledIsoSurfaceSurface/sampledIsoSurfaceSurface.C +++ b/src/sampling/sampledSurface/sampledIsoSurfaceSurface/sampledIsoSurfaceSurface.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2022 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2022-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -45,12 +45,11 @@ Foam::sampledSurfaces::sampledIsoSurfaceSurface::sampledIsoSurfaceSurface ) : sampledSurface(name, mesh, dict), - zoneName_(dict.lookupOrDefault("zone", wordRe::null)), - zoneIDs_(mesh.cellZones().findIndices(zoneName_)), + zoneName_(dict.lookupOrDefault("zone", word::null)), isoSurfPtr_(nullptr), isoSurfTimeIndex_(-1) { - if (zoneName_ != wordRe::null && zoneIDs_.empty()) + if (zoneName_ != word::null && !mesh.cellZones().found(zoneName_)) { WarningInFunction << "Cell zone " << zoneName_ diff --git a/src/sampling/sampledSurface/sampledIsoSurfaceSurface/sampledIsoSurfaceSurface.H b/src/sampling/sampledSurface/sampledIsoSurfaceSurface/sampledIsoSurfaceSurface.H index 912fbe3196..408aadb597 100644 --- a/src/sampling/sampledSurface/sampledIsoSurfaceSurface/sampledIsoSurfaceSurface.H +++ b/src/sampling/sampledSurface/sampledIsoSurfaceSurface/sampledIsoSurfaceSurface.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2022 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2022-2023 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -57,11 +57,8 @@ private: // Private Data - //- If restricted to zones, name of this zone or a regular expression - const wordRe zoneName_; - - //- If restricted to zones, the indices of the zones - const labelList zoneIDs_; + //- Optional name of the cellZone + const word zoneName_; //- Constructed iso surface mutable autoPtr isoSurfPtr_; @@ -91,10 +88,10 @@ protected: // Protected Member Functions - //- Access the zone indices - inline const labelList& zoneIDs() const + //- Access the zoneName + inline const word& zoneName() const { - return zoneIDs_.empty() ? NullObjectRef() : zoneIDs_; + return zoneName_; } //- Access the time index