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)
278 if (fineToCoarse.
size() == 0)
283 if (fineToCoarse.
size() != patch.size())
286 <<
"restrict map does not correspond to fine level. " <<
endl 287 <<
" Sizes: restrictMap: " << fineToCoarse.
size()
288 <<
" nEqns: " << patch.size()
292 const label nCoarseI =
max(fineToCoarse)+1;
299 for (
label coarseI = 0; coarseI < nCoarseI; coarseI++)
301 const labelList& fineFaces = coarseToFine[coarseI];
310 if (upp.edgeLoops().size() != 1)
312 if (fineFaces.
size() == 2)
314 const edge e(fineFaces[0], fineFaces[1]);
317 else if (fineFaces.
size() == 3)
319 const edge e(fineFaces[0], fineFaces[1]);
320 const edge e1(fineFaces[0], fineFaces[2]);
321 const edge e2(fineFaces[2], fineFaces[1]);
330 patchFaces[coarseI] =
face 356 label nPairLevels = 0;
357 label nCreatedLevels = 1;
358 label nCoarseFaces = 0;
359 label nCoarseFacesOld = 0;
365 bool agglomOK =
false;
369 label nCoarseFacesPrev = nCoarseFaces;
371 finalAgglomPtr = agglomerateOneLevel
377 if (nCoarseFaces > 0 && nCoarseFaces != nCoarseFacesPrev)
382 agglomOK = agglomeratePatch
392 mapBaseToTopAgglom(nCreatedLevels);
393 setEdgeWeights(nCreatedLevels);
397 combineLevels(nCreatedLevels);
416 nFaces_[nCreatedLevels] = nCoarseFaces;
420 !continueAgglomerating(nCoarseFaces)
421 || (nCoarseFacesOld == nCoarseFaces)
427 nCoarseFacesOld = nCoarseFaces;
430 compactLevels(nCreatedLevels);
440 const label nFineFaces = patch.size();
451 const labelList& fFaces = faceFaces[facei];
453 if (coarseCellMap[facei] < 0)
455 label matchFaceNo = -1;
456 label matchFaceNeibNo = -1;
457 scalar maxFaceWeight = -GREAT;
462 label faceNeig = fFaces[i];
463 const edge edgeCommon =
edge(facei, faceNeig);
467 && coarseCellMap[faceNeig] < 0
473 matchFaceNeibNo = faceNeig;
478 if (matchFaceNo >= 0)
481 coarseCellMap[matchFaceNo] = nCoarseFaces;
482 coarseCellMap[matchFaceNeibNo] = nCoarseFaces;
489 label clusterMatchFaceNo = -1;
490 scalar clusterMaxFaceCoeff = -GREAT;
494 label faceNeig = fFaces[i];
495 const edge edgeCommon =
edge(facei, faceNeig);
500 && coarseCellMap[faceNeig] > 0
503 clusterMatchFaceNo = faceNeig;
508 if (clusterMatchFaceNo >= 0)
511 coarseCellMap[facei] = coarseCellMap[clusterMatchFaceNo];
516 coarseCellMap[facei] = nCoarseFaces;
525 for (
label facei=0; facei<nFineFaces; facei++)
527 if (coarseCellMap[facei] < 0)
531 <<
" is not part of a cluster" 536 return tcoarseCellMap;
540 void Foam::pairPatchAgglomeration::combineLevels(
const label curLevel)
542 label prevLevel = curLevel - 1;
555 prevResAddr[i] = curResAddr[prevResAddr[i]];
ListType renumber(const labelUList &oldToNew, const ListType &)
Renumber the values (not the indices) of a list.
List< labelList > labelListList
A List of labelList.
Field< label > labelField
Specialisation of Field<T> for label.
#define forAll(list, i)
Loop across all elements in list.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
errorManipArg< error, int > exit(error &err, const int errNo=1)
A face is a list of labels corresponding to mesh vertices.
const double e
Elementary charge.
A list of keyword definitions, which are a keyword followed by any number of values (e...
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
PtrList< labelField > restrictAddressing_
Cell restriction addressing array.
Unit conversion functions.
const List< Face > & localFaces() const
Return patch faces addressing into local point list.
labelListList invertOneToMany(const label len, const labelUList &)
Invert one-to-many map. Unmapped elements will be size 0.
void size(const label)
Override size to be inconsistent with allocated storage.
Ostream & endl(Ostream &os)
Add newline and flush stream.
const Field< PointType > & points() const
Return reference to global points.
labelList identity(const label len)
Create identity map (map[i] == i) of given length.
label k
Boltzmann constant.
PtrList< bPatch > patchLevels_
Hierarchy of patch addressing.
scalar degToRad(const scalar deg)
Conversion from degrees to radians.
~pairPatchAgglomeration()
bool insert(const Key &, const T &newElmt)
Insert a new hashedEntry.
A list of faces which address into the list of points.
A List obtained as a section of another List.
dimensionedScalar cos(const dimensionedScalar &ds)
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
void agglomerate()
Agglomerate patch.
void clear()
Clear all entries from table.
label nFacesInCoarsestLevel_
Number of faces in coarsest level.
List< label > labelList
A List of labels.
scalar featureAngle_
Feature angle.
PrimitivePatch< face, List, const pointField > bPatch
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
errorManip< error > abort(error &err)
label readLabel(Istream &is)
bool found(const Key &) const
Return true if hashedEntry is found in table.
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
const labelListList & faceFaces() const
Return face-face addressing.
void setSize(const label)
Reset size of List.
labelList restrictTopBottomAddressing_
Maps from finest to coarsest.
EdgeMap< scalar > facePairWeight_
Edge weights.
const bPatch & patchLevel(const label leveli) const
Return primitivePatch of given level.
labelList nFaces_
The number of faces in each level.
void resize(const label newSize)
Resize the hash table for efficiency.
A class for managing temporary objects.
label maxLevels_
Max number of levels.
A patch is a list of labels that address the faces in the global face list.
T & ref() const
Return non-const reference or generate a fatal error.
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
A List with indirect addressing.
label mergeLevels_
Number of levels to merge, 1 = don't merge, 2 = merge pairs etc.
const Field< PointType > & localPoints() const
Return pointField of points in patch.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.