32 void Foam::pairPatchAgglomeration::compactLevels(
const label nCreatedLevels)
40 bool Foam::pairPatchAgglomeration::continueAgglomerating
42 const label nCoarseFaces
46 label localnCoarseFaces = nCoarseFaces;
52 void Foam::pairPatchAgglomeration::setBasedEdgeWeights()
55 forAll(coarsePatch.edges(), i)
57 if (coarsePatch.isInternalEdge(i))
60 coarsePatch.edges()[i].mag(coarsePatch.localPoints());
62 const labelList& eFaces = coarsePatch.edgeFaces()[i];
64 if (eFaces.size() == 2)
67 coarsePatch.faceNormals()[eFaces[0]]
68 & coarsePatch.faceNormals()[eFaces[1]];
70 const edge edgeCommon = edge(eFaces[0], eFaces[1]);
90 for (
label k = j+1;
k<eFaces.size();
k++)
94 edge(eFaces[j], eFaces[
k]),
105 void Foam::pairPatchAgglomeration::setEdgeWeights
107 const label fineLevelIndex
114 const label nCoarseI =
max(fineToCoarse) + 1;
117 HashSet<edge, Hash<edge> > fineFeaturedFaces(coarsePatch.nEdges()/10);
124 const edge e = iter.key();
125 const edge edgeFeatured
130 fineFeaturedFaces.insert(edgeFeatured);
138 forAll(coarsePatch.edges(), i)
140 if (coarsePatch.isInternalEdge(i))
143 coarsePatch.edges()[i].mag(coarsePatch.localPoints());
145 const labelList& eFaces = coarsePatch.edgeFaces()[i];
147 if (eFaces.size() == 2)
149 const edge edgeCommon = edge(eFaces[0], eFaces[1]);
162 if (fineFeaturedFaces.found(edgeCommon))
172 for (
label k = j+1;
k<eFaces.size();
k++)
176 edge(eFaces[j], eFaces[
k]),
189 Foam::pairPatchAgglomeration::pairPatchAgglomeration
193 const bool additionalWeights
230 setBasedEdgeWeights();
251 void Foam::pairPatchAgglomeration::mapBaseToTopAgglom
253 const label fineLevelIndex
265 bool Foam::pairPatchAgglomeration::agglomeratePatch
269 const label fineLevelIndex
272 if (
min(fineToCoarse) == -1)
276 "pairPatchAgglomeration::agglomeratePatch" 285 if (fineToCoarse.
size() == 0)
290 if (fineToCoarse.
size() != patch.size())
294 "pairPatchAgglomeration::agglomeratePatch" 300 ) <<
"restrict map does not correspond to fine level. " <<
endl 301 <<
" Sizes: restrictMap: " << fineToCoarse.
size()
302 <<
" nEqns: " << patch.size()
306 const label nCoarseI =
max(fineToCoarse)+1;
313 for (
label coarseI = 0; coarseI < nCoarseI; coarseI++)
315 const labelList& fineFaces = coarseToFine[coarseI];
324 if (upp.edgeLoops().size() != 1)
326 if (fineFaces.
size() == 2)
328 const edge e(fineFaces[0], fineFaces[1]);
331 else if (fineFaces.
size() == 3)
333 const edge e(fineFaces[0], fineFaces[1]);
334 const edge e1(fineFaces[0], fineFaces[2]);
335 const edge e2(fineFaces[2], fineFaces[1]);
344 patchFaces[coarseI] =
face 370 label nPairLevels = 0;
371 label nCreatedLevels = 1;
372 label nCoarseFaces = 0;
373 label nCoarseFacesOld = 0;
379 bool agglomOK =
false;
383 label nCoarseFacesPrev = nCoarseFaces;
385 finalAgglomPtr = agglomerateOneLevel
391 if (nCoarseFaces > 0 && nCoarseFaces != nCoarseFacesPrev)
396 agglomOK = agglomeratePatch
406 mapBaseToTopAgglom(nCreatedLevels);
407 setEdgeWeights(nCreatedLevels);
411 combineLevels(nCreatedLevels);
430 nFaces_[nCreatedLevels] = nCoarseFaces;
434 !continueAgglomerating(nCoarseFaces)
435 || (nCoarseFacesOld == nCoarseFaces)
441 nCoarseFacesOld = nCoarseFaces;
444 compactLevels(nCreatedLevels);
454 const label nFineFaces = patch.size();
465 const labelList& fFaces = faceFaces[facei];
467 if (coarseCellMap[facei] < 0)
469 label matchFaceNo = -1;
470 label matchFaceNeibNo = -1;
471 scalar maxFaceWeight = -GREAT;
476 label faceNeig = fFaces[i];
477 const edge edgeCommon =
edge(facei, faceNeig);
481 && coarseCellMap[faceNeig] < 0
487 matchFaceNeibNo = faceNeig;
492 if (matchFaceNo >= 0)
495 coarseCellMap[matchFaceNo] = nCoarseFaces;
496 coarseCellMap[matchFaceNeibNo] = nCoarseFaces;
503 label clusterMatchFaceNo = -1;
504 scalar clusterMaxFaceCoeff = -GREAT;
508 label faceNeig = fFaces[i];
509 const edge edgeCommon =
edge(facei, faceNeig);
514 && coarseCellMap[faceNeig] > 0
517 clusterMatchFaceNo = faceNeig;
522 if (clusterMatchFaceNo >= 0)
525 coarseCellMap[facei] = coarseCellMap[clusterMatchFaceNo];
530 coarseCellMap[facei] = nCoarseFaces;
539 for (
label facei=0; facei<nFineFaces; facei++)
541 if (coarseCellMap[facei] < 0)
545 "pairPatchAgglomeration::agglomerateOneLevel " 546 "(label&, const bPatch&) " 547 ) <<
" face " << facei
548 <<
" is not part of a cluster" 553 return tcoarseCellMap;
557 void Foam::pairPatchAgglomeration::combineLevels(
const label curLevel)
559 label prevLevel = curLevel - 1;
572 prevResAddr[i] = curResAddr[prevResAddr[i]];
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
A List with indirect addressing.
label maxLevels_
Max number of levels.
const labelListList & faceFaces() const
Return face-face addressing.
EdgeMap< scalar > facePairWeight_
Edge weights.
labelListList invertOneToMany(const label len, const labelUList &)
Invert one-to-many map. Unmapped elements will be size 0.
bool insert(const Key &, const T &newElmt)
Insert a new hashedEntry.
PtrList< labelField > restrictAddressing_
Cell restriction addressing array.
labelList nFaces_
The number of faces in each level.
Field< label > labelField
Specialisation of Field<T> for label.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
~pairPatchAgglomeration()
void resize(const label newSize)
Resize the hash table for efficiency.
void size(const label)
Override size to be inconsistent with allocated storage.
errorManipArg< error, int > exit(error &err, const int errNo=1)
A list of keyword definitions, which are a keyword followed by any number of values (e...
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
label readLabel(Istream &is)
A patch is a list of labels that address the faces in the global face list.
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
A face is a list of labels corresponding to mesh vertices.
const Field< PointType > & localPoints() const
Return pointField of points in patch.
const double e
Elementary charge.
void setSize(const label)
Reset size of List.
Ostream & endl(Ostream &os)
Add newline and flush stream.
void clear()
Clear all entries from table.
label nFacesInCoarsestLevel_
Number of faces in coarsest level.
label mergeLevels_
Number of levels to merge, 1 = don't merge, 2 = merge pairs etc.
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
label k
Boltzmann constant.
dimensionedScalar cos(const dimensionedScalar &ds)
ListType renumber(const labelUList &oldToNew, const ListType &)
Renumber the values (not the indices) of a list.
Unit conversion functions.
labelList identity(const label len)
Create identity map (map[i] == i) of given length.
errorManip< error > abort(error &err)
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
A list of faces which address into the list of points.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
List< label > labelList
A List of labels.
scalar degToRad(const scalar deg)
Conversion from degrees to radians.
const List< Face > & localFaces() const
Return patch faces addressing into local point list.
A List obtained as a section of another List.
scalar featureAngle_
Feature angle.
const bPatch & patchLevel(const label leveli) const
Return primitivePatch of given level.
void agglomerate()
Agglomerate patch.
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
List< labelList > labelListList
A List of labelList.
labelList restrictTopBottomAddressing_
Maps from finest to coarsest.
PrimitivePatch< face, List, const pointField > bPatch
PtrList< bPatch > patchLevels_
Hierarchy of patch addressing.
bool found(const Key &) const
Return true if hashedEntry is found in table.
A class for managing temporary objects.
const Field< PointType > & points() const
Return reference to global points.