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]),
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);
417 nFaces_[nCreatedLevels] = nCoarseFaces;
421 !continueAgglomerating(nCoarseFaces)
422 || (nCoarseFacesOld == nCoarseFaces)
428 nCoarseFacesOld = nCoarseFaces;
431 compactLevels(nCreatedLevels);
441 const label nFineFaces = patch.size();
452 const labelList& fFaces = faceFaces[facei];
454 if (coarseCellMap[facei] < 0)
456 label matchFaceNo = -1;
457 label matchFaceNeibNo = -1;
458 scalar maxFaceWeight = -great;
463 label faceNeig = fFaces[i];
464 const edge edgeCommon =
edge(facei, faceNeig);
468 && coarseCellMap[faceNeig] < 0
474 matchFaceNeibNo = faceNeig;
479 if (matchFaceNo >= 0)
482 coarseCellMap[matchFaceNo] = nCoarseFaces;
483 coarseCellMap[matchFaceNeibNo] = nCoarseFaces;
490 label clusterMatchFaceNo = -1;
491 scalar clusterMaxFaceCoeff = -great;
495 label faceNeig = fFaces[i];
496 const edge edgeCommon =
edge(facei, faceNeig);
501 && coarseCellMap[faceNeig] > 0
504 clusterMatchFaceNo = faceNeig;
509 if (clusterMatchFaceNo >= 0)
512 coarseCellMap[facei] = coarseCellMap[clusterMatchFaceNo];
517 coarseCellMap[facei] = nCoarseFaces;
526 for (
label facei=0; facei<nFineFaces; facei++)
528 if (coarseCellMap[facei] < 0)
532 <<
" is not part of a cluster" 537 return tcoarseCellMap;
541 void Foam::pairPatchAgglomeration::combineLevels(
const label curLevel)
543 label prevLevel = curLevel - 1;
556 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.
pairPatchAgglomeration(const polyPatch &patch, const dictionary &controlDict, const bool additionalWeights=false)
Construct given mesh and controls.
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.
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.
T & ref() const
Return non-const reference or generate a fatal error.
Unit conversion functions.
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.
labelList identity(const label len)
Create identity map (map[i] == i) of given length.
label k
Boltzmann constant.
const Field< PointType > & localPoints() const
Return pointField of points in patch.
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.
const labelListList & faceFaces() const
Return face-face addressing.
dimensionedScalar cos(const dimensionedScalar &ds)
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
bool found(const Key &) const
Return true if hashedEntry is found in table.
void agglomerate()
Agglomerate patch.
void clear()
Clear all entries from table.
const Field< PointType > & points() const
Return reference to global points.
label nFacesInCoarsestLevel_
Number of faces in coarsest level.
List< label > labelList
A List of labels.
scalar featureAngle_
Feature angle.
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
errorManip< error > abort(error &err)
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 bPatch & patchLevel(const label leveli) const
Return primitivePatch of given level.
void setSize(const label)
Reset size of List.
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
labelList restrictTopBottomAddressing_
Maps from finest to coarsest.
const List< FaceType > & localFaces() const
Return patch faces addressing into local point list.
EdgeMap< scalar > facePairWeight_
Edge weights.
labelList nFaces_
The number of faces in each level.
PrimitivePatch< faceList, const pointField > bPatch
void resize(const label newSize)
Resize the hash table for efficiency.
const doubleScalar e
Elementary charge.
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.
A List with indirect addressing.
label mergeLevels_
Number of levels to merge, 1 = don't merge, 2 = merge pairs etc.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.