From 7f71a9bcf6ddc7b1951537c12fba2795f16d5c41 Mon Sep 17 00:00:00 2001 From: mattijs Date: Fri, 27 Feb 2009 15:40:44 +0000 Subject: [PATCH 1/6] coupled faces included --- .../cfdTools/general/MRF/MRFZone.C | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/finiteVolume/cfdTools/general/MRF/MRFZone.C b/src/finiteVolume/cfdTools/general/MRF/MRFZone.C index ab9709e993..6250de7e24 100644 --- a/src/finiteVolume/cfdTools/general/MRF/MRFZone.C +++ b/src/finiteVolume/cfdTools/general/MRF/MRFZone.C @@ -32,8 +32,6 @@ License #include "PackedList.H" #include "syncTools.H" -#include "faceSet.H" - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::MRFZone::MRFZone(const fvMesh& mesh, Istream& is) @@ -106,6 +104,23 @@ Foam::MRFZone::MRFZone(const fvMesh& mesh, Istream& is) zoneFacesSet[faceI] = 1u; } } + forAll(patches, patchI) + { + const polyPatch& pp = patches[patchI]; + + if (pp.coupled()) + { + forAll(pp, i) + { + label faceI = pp.start()+i; + + if (zoneCell.get(own[faceI]) == 1u) + { + zoneFacesSet[faceI] = 1u; + } + } + } + } syncTools::syncFaceList(mesh_, zoneFacesSet, orEqOp()); From 0f7b03e69f199e4f0589a2500696f648cc264ba8 Mon Sep 17 00:00:00 2001 From: mattijs Date: Fri, 27 Feb 2009 15:41:09 +0000 Subject: [PATCH 2/6] operator== on result of operator[] behaves weird --- .../containers/Lists/PackedList/PackedList.H | 23 ++++++++-- .../containers/Lists/PackedList/PackedListI.H | 46 ++++++++++++++++++- 2 files changed, 62 insertions(+), 7 deletions(-) diff --git a/src/OpenFOAM/containers/Lists/PackedList/PackedList.H b/src/OpenFOAM/containers/Lists/PackedList/PackedList.H index 5f71976aa9..02bdae8da0 100644 --- a/src/OpenFOAM/containers/Lists/PackedList/PackedList.H +++ b/src/OpenFOAM/containers/Lists/PackedList/PackedList.H @@ -148,9 +148,11 @@ public: //- Masking for all bits below the offset inline static unsigned int maskLower(unsigned offset); - // Forward declaration of iteratorBase + // Forward declaration of iterators class iteratorBase; + class iterator; + class const_iterator; // Constructors @@ -328,7 +330,7 @@ public: // Member Operators - //- Compare positions + //- Compare values (not positions) inline bool operator==(const iteratorBase&) const; inline bool operator!=(const iteratorBase&) const; @@ -355,7 +357,10 @@ public: public iteratorBase { - //- Should never violate const-ness! + //- Disallow copy constructor from const_iterator - violates const-ness! + iterator(const const_iterator&); + + //- Disallow assignment from const_iterator - violates const-ness! void operator=(const const_iterator&); public: @@ -375,6 +380,10 @@ public: // Member Operators + //- Compare positions (not values) + inline bool operator==(const iteratorBase&) const; + inline bool operator!=(const iteratorBase&) const; + //- Assign from iteratorBase, eg iter = packedlist[i] // An out-of-range iterator is assigned end() inline iterator& operator=(const iteratorBase&); @@ -420,17 +429,21 @@ public: //- Construct from iterator base, eg iter(packedlist[i]) // but also "const_iterator iter = packedlist[i];" - // An out-of-range iterator is assigned end() + // An out-of-range iterator is assigned cend() inline const_iterator(const iteratorBase&); //- Construct from base list and position index inline const_iterator(const PackedList*, const label); - //- Construct from non-const iterator + //- Construct from iterator inline const_iterator(const iterator&); // Member operators + //- Compare positions (not values) + inline bool operator==(const iteratorBase&) const; + inline bool operator!=(const iteratorBase&) const; + //- Assign from iteratorBase or derived // eg, iter = packedlist[i] or even iter = list.begin() inline const_iterator& operator=(const iteratorBase&); diff --git a/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H b/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H index 929688ef24..3b76234c2c 100644 --- a/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H +++ b/src/OpenFOAM/containers/Lists/PackedList/PackedListI.H @@ -176,7 +176,7 @@ inline bool Foam::PackedList::iteratorBase::operator== const iteratorBase& iter ) const { - return this->index_ == iter.index_; + return this->get() == iter.get(); } @@ -186,7 +186,7 @@ inline bool Foam::PackedList::iteratorBase::operator!= const iteratorBase& iter ) const { - return this->index_ != iter.index_; + return this->get() != iter.get(); } @@ -311,6 +311,48 @@ inline Foam::PackedList::const_iterator::const_iterator {} +template +inline bool Foam::PackedList::iterator::operator== +( + const iteratorBase& iter +) const +{ + return this->index_ == iter.index_; +} + + +template +inline bool Foam::PackedList::iterator::operator!= +( + const iteratorBase& iter +) const +{ + return this->index_ != iter.index_; +} + + + +template +inline bool Foam::PackedList::const_iterator::operator== +( + const iteratorBase& iter +) const +{ + return this->index_ == iter.index_; +} + + +template +inline bool Foam::PackedList::const_iterator::operator!= +( + const iteratorBase& iter +) const +{ + return this->index_ != iter.index_; +} + + + template inline typename Foam::PackedList::iterator& Foam::PackedList::iterator::operator=(const iteratorBase& iter) From 7e735715a4189e02ea322cf507892f623474c018 Mon Sep 17 00:00:00 2001 From: mattijs Date: Tue, 3 Mar 2009 17:09:01 +0000 Subject: [PATCH 3/6] more flexible mrfzones modified: finiteVolume/cfdTools/general/MRF/MRFZone.C modified: finiteVolume/cfdTools/general/MRF/MRFZone.H modified: ../tutorials/incompressible/MRFSimpleFoam/mixerVessel2D/constant/MRFZones --- .../cfdTools/general/MRF/MRFZone.C | 441 +++++++++++++----- .../cfdTools/general/MRF/MRFZone.H | 36 +- .../mixerVessel2D/constant/MRFZones | 4 +- 3 files changed, 348 insertions(+), 133 deletions(-) diff --git a/src/finiteVolume/cfdTools/general/MRF/MRFZone.C b/src/finiteVolume/cfdTools/general/MRF/MRFZone.C index 6250de7e24..8b689d0d66 100644 --- a/src/finiteVolume/cfdTools/general/MRF/MRFZone.C +++ b/src/finiteVolume/cfdTools/general/MRF/MRFZone.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd. + \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -29,8 +29,264 @@ License #include "volFields.H" #include "surfaceFields.H" #include "fvMatrices.H" -#include "PackedList.H" #include "syncTools.H" +#include "faceSet.H" + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void Foam::MRFZone::setMRFFaces +( + labelList& faceType, + const labelList& excludedPatchIDs +) +{ + const polyBoundaryMesh& patches = mesh_.boundaryMesh(); + + // Knock out coupled patches + forAll(patches, patchi) + { + if (patches[patchi].coupled()) + { + const polyPatch& pp = patches[patchi]; + + forAll(pp, j) + { + label faceI = pp.start()+j; + + if (faceType[faceI] == 1) + { + faceType[faceI] = 2; + } + } + } + } + + // All explicitly provided exclusions + forAll(excludedPatchIDs, i) + { + const polyPatch& pp = patches[excludedPatchIDs[i]]; + + forAll(pp, j) + { + label faceI = pp.start()+j; + + if (faceType[faceI] == 1) + { + faceType[faceI] = 2; + } + } + } + + // Collect into lists per patch. + internalFaces_.setSize(mesh_.nFaces()); + label nInternal = 0; + + for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++) + { + if (faceType[faceI] == 1) + { + internalFaces_[nInternal++] = faceI; + } + } + internalFaces_.setSize(nInternal); + + labelList nIncludedFaces(patches.size(), 0); + labelList nExcludedFaces(patches.size(), 0); + + forAll(patches, patchi) + { + const polyPatch& pp = patches[patchi]; + + forAll(pp, patchFacei) + { + label faceI = pp.start()+patchFacei; + + if (faceType[faceI] == 1) + { + nIncludedFaces[patchi]++; + } + else if (faceType[faceI] == 2) + { + nExcludedFaces[patchi]++; + } + } + } + + includedFaces_.setSize(patches.size()); + excludedFaces_.setSize(patches.size()); + forAll(nIncludedFaces, patchi) + { + includedFaces_[patchi].setSize(nIncludedFaces[patchi]); + excludedFaces_[patchi].setSize(nExcludedFaces[patchi]); + } + nIncludedFaces = 0; + nExcludedFaces = 0; + + forAll(patches, patchi) + { + const polyPatch& pp = patches[patchi]; + + forAll(pp, patchFacei) + { + label faceI = pp.start()+patchFacei; + + if (faceType[faceI] == 1) + { + includedFaces_[patchi][nIncludedFaces[patchi]++] = patchFacei; + } + else if (faceType[faceI] == 2) + { + excludedFaces_[patchi][nExcludedFaces[patchi]++] = patchFacei; + } + } + } + + //if (debug) + //{ + // faceSet internalFaces(mesh_, "internalFaces", internalFaces_); + // Pout<< "Writing internal faces in MRF zone to faceSet " + // << internalFaces.name() << endl; + // internalFaces.write(); + //} + //{ + // faceSet MRFFaces(mesh_, "includedFaces", 100); + // forAll(includedFaces_, patchi) + // { + // forAll(includedFaces_[patchi], i) + // { + // label patchFacei = includedFaces_[patchi][i]; + // MRFFaces.insert(patches[patchi].start()+patchFacei); + // } + // } + // Pout<< "Writing patch faces in MRF zone to faceSet " + // << MRFFaces.name() << endl; + // MRFFaces.write(); + //} + //{ + // faceSet excludedFaces(mesh_, "excludedFaces", 100); + // forAll(excludedFaces_, patchi) + // { + // forAll(excludedFaces_[patchi], i) + // { + // label patchFacei = excludedFaces_[patchi][i]; + // excludedFaces.insert(patches[patchi].start()+patchFacei); + // } + // } + // Pout<< "Writing faces in MRF zone with special handling to faceSet " + // << excludedFaces.name() << endl; + // excludedFaces.write(); + //} +} + + +void Foam::MRFZone::setMRFFaces() +{ + const polyBoundaryMesh& patches = mesh_.boundaryMesh(); + + // Type per face: + // 0:not in zone + // 1:moving with frame + // 2:other + labelList faceType(mesh_.nFaces(), 0); + + bool faceZoneFound = (faceZoneID_ != -1); + reduce(faceZoneFound, orOp()); + + if (faceZoneFound) + { + // Explicitly provided faces. + if (faceZoneID_ != -1) + { + const labelList& zoneFaces = mesh_.faceZones()[faceZoneID_]; + + forAll(zoneFaces, i) + { + faceType[zoneFaces[i]] = 1; + } + + if (allPatchesMove_) + { + // Explicitly provided patches that do not move + setMRFFaces(faceType, patchLabels_); + } + else + { + setMRFFaces(faceType, labelList(0)); + } + } + } + else + { + // Determine faces in cell zone + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // (without constructing cells) + + const labelList& own = mesh_.faceOwner(); + const labelList& nei = mesh_.faceNeighbour(); + + // Cells in zone + boolList zoneCell(mesh_.nCells(), false); + + if (cellZoneID_ != -1) + { + const labelList& cellLabels = mesh_.cellZones()[cellZoneID_]; + forAll(cellLabels, i) + { + zoneCell[cellLabels[i]] = true; + } + } + + + label nZoneFaces = 0; + + for (label faceI = 0; faceI < mesh_.nInternalFaces(); faceI++) + { + if (zoneCell[own[faceI]] || zoneCell[nei[faceI]]) + { + faceType[faceI] = 1; + nZoneFaces++; + } + } + forAll(patches, patchI) + { + const polyPatch& pp = patches[patchI]; + + if (!isA(pp)) + { + forAll(pp, i) + { + label faceI = pp.start()+i; + + if (zoneCell[own[faceI]]) + { + faceType[faceI] = 1; + nZoneFaces++; + } + } + } + } + syncTools::syncFaceList(mesh_, faceType, maxEqOp