49 updateSets<pointSet>(map);
50 updateSets<faceSet>(map);
51 updateSets<cellSet>(map);
55 void Foam::polyMeshFilter::copySets
61 copySets<pointSet>(oldMesh, newMesh);
62 copySets<faceSet>(oldMesh, newMesh);
63 copySets<cellSet>(oldMesh, newMesh);
78 mesh.polyMesh::instance(),
91 meshCopy().updateMesh(map);
97 copySets(mesh, meshCopy());
105 Foam::label Foam::polyMeshFilter::filterFacesLoop(
const label nOriginalBadFaces)
108 label nOuterIterations = 0;
111 labelList pointErrorCount(mesh_.nPoints(), 0);
117 meshQualityCoeffDict(),
121 bool newBadFaces =
true;
131 nOuterIterations < maxIterations()
136 Info<<
nl <<
"Outer Iteration = " << nOuterIterations++ <<
nl 139 printScalarFieldStats(
"Edge Filter Factor", minEdgeLen_);
140 printScalarFieldStats(
"Face Filter Factor", faceFilterFactor_);
143 newMeshPtr_ = copyMesh(mesh_);
144 fvMesh& newMesh = newMeshPtr_();
146 scalarField newMeshFaceFilterFactor = faceFilterFactor_;
147 pointPriority_.reset(
new labelList(originalPointPriority_));
152 label nInnerIterations = 0;
160 << nInnerIterations++ <<
nl << incrIndent <<
endl;
162 label nLocalCollapse = filterFaces
165 newMeshFaceFilterFactor,
166 origToCurrentPointMap
172 nLocalCollapse >= nPrevLocalCollapse
173 || nLocalCollapse == 0
181 nPrevLocalCollapse = nLocalCollapse;
189 label nInnerIterations = 0;
197 << nInnerIterations++ <<
nl << incrIndent <<
endl;
199 label nLocalCollapse = filterEdges
203 origToCurrentPointMap
209 nLocalCollapse >= nPrevLocalCollapse
210 || nLocalCollapse == 0
218 nPrevLocalCollapse = nLocalCollapse;
229 if (controlMeshQuality())
235 meshQualityCoeffDict(),
239 Info<<
nl <<
" Number of bad faces : " << nBadFaces <<
nl 240 <<
" Number of marked points : " 244 updatePointErrorCount
247 origToCurrentPointMap,
251 checkMeshEdgesAndRelaxEdges
254 origToCurrentPointMap,
259 checkMeshFacesAndRelaxEdges
262 origToCurrentPointMap,
268 forAll(mesh_.points(), pI)
272 origToCurrentPointMap[pI] >= 0
273 && isErrorPoint[origToCurrentPointMap[pI]]
276 if (!newErrorPoint[pI])
312 labelPair nCollapsedPtEdge = collapser.markSmallSliverFaces
314 newMeshFaceFilterFactor,
317 collapsePointToLocation
320 label nCollapsed = 0;
321 forAll(nCollapsedPtEdge, collapseTypeI)
323 nCollapsed += nCollapsedPtEdge[collapseTypeI];
332 <<
"Collapsing " << nCollapsed <<
" faces " 333 <<
"(to point = " << nToPoint <<
", to edge = " << nToEdge <<
")" 347 collapser.consistentCollapse
351 collapsePointToLocation,
360 <<
" edges after synchronisation and PointEdgeWave" <<
endl;
362 if (nLocalCollapse == 0)
372 collapser.setRefinement(allPointInfo, newMeshMod);
392 updatePointPriorities(newMesh, newMap.
pointMap());
394 mapOldMeshFaceFieldToNewMesh
398 newMeshFaceFilterFactor
401 updateOldToNewPointMap
404 origToCurrentPointMap
408 return nLocalCollapse;
430 label nSmallCollapsed = collapser.markSmallEdges
435 collapsePointToLocation
439 Info<<
indent <<
"Collapsing " << nSmallCollapsed
440 <<
" small edges" <<
endl;
443 label nMerged = collapser.markMergeEdges
448 collapsePointToLocation
452 Info<<
indent <<
"Collapsing " << nMerged <<
" in line edges" 455 if (nMerged + nSmallCollapsed == 0)
465 collapser.consistentCollapse
469 collapsePointToLocation,
478 <<
" edges after synchronisation and PointEdgeWave" <<
endl;
480 if (nLocalCollapse == 0)
489 collapser.setRefinement(allPointInfo, newMeshMod);
510 mapOldMeshEdgeFieldToNewMesh
517 updateOldToNewPointMap
520 origToCurrentPointMap
523 updatePointPriorities(newMesh, newMap.
pointMap());
525 return nLocalCollapse;
529 void Foam::polyMeshFilter::updatePointErrorCount
536 forAll(mesh_.points(), pI)
538 if (isErrorPoint[oldToNewMesh[pI]])
540 pointErrorCount[pI]++;
546 void Foam::polyMeshFilter::checkMeshEdgesAndRelaxEdges
554 const edgeList& edges = mesh_.edges();
558 const edge&
e = edges[edgeI];
559 label newStart = oldToNewMesh[e[0]];
560 label newEnd = oldToNewMesh[e[1]];
564 pointErrorCount[e[0]] >= maxPointErrorCount()
565 || pointErrorCount[e[1]] >= maxPointErrorCount()
568 minEdgeLen_[edgeI] = -1;
573 (newStart >= 0 && isErrorPoint[newStart])
574 || (newEnd >= 0 && isErrorPoint[newEnd])
577 minEdgeLen_[edgeI] *= edgeReductionFactor();
583 for (
label smoothIter = 0; smoothIter < maxSmoothIters(); ++smoothIter)
586 forAll(mesh_.edges(), edgeI)
588 const edge&
e = mesh_.edges()[edgeI];
590 scalar sumMinEdgeLen = 0;
595 const labelList& pEdges = mesh_.pointEdges()[e[pointI]];
599 const label pEdge = pEdges[pEdgeI];
600 sumMinEdgeLen += minEdgeLen_[pEdge];
605 minEdgeLen_[edgeI] =
min 623 void Foam::polyMeshFilter::checkMeshFacesAndRelaxEdges
631 const faceList& faces = mesh_.faces();
635 const face&
f = faces[faceI];
639 const label ptIndex = oldToNewMesh[f[fpI]];
641 if (pointErrorCount[f[fpI]] >= maxPointErrorCount())
643 faceFilterFactor_[faceI] = -1;
646 if (isErrorPoint[ptIndex])
648 faceFilterFactor_[faceI] *= faceReductionFactor();
657 for (
label smoothIter = 0; smoothIter < maxSmoothIters(); ++smoothIter)
662 const labelList& fEdges = mesh_.faceEdges()[faceI];
664 scalar sumFaceFilterFactors = 0;
669 bool skipFace =
true;
673 const labelList& eFaces = mesh_.edgeFaces()[fEdges[fEdgeI]];
677 const label eFace = eFaces[eFaceI];
679 const face&
f = faces[eFace];
683 const label ptIndex = oldToNewMesh[f[fpI]];
685 if (isErrorPoint[ptIndex])
694 sumFaceFilterFactors += faceFilterFactor_[eFace];
705 faceFilterFactor_[faceI] =
min 707 faceFilterFactor_[faceI],
708 sumFaceFilterFactors/nFaces
718 void Foam::polyMeshFilter::updatePointPriorities
725 const labelList& currPointPriority = pointPriority_();
727 forAll(newPointPriority, ptI)
729 const label newPointToOldPoint = pointMap[ptI];
730 const label origPointPriority = currPointPriority[newPointToOldPoint];
732 newPointPriority[ptI] =
max(origPointPriority, newPointPriority[ptI]);
743 pointPriority_.reset(
new labelList(newPointPriority));
747 void Foam::polyMeshFilter::printScalarFieldStats
754 scalar validElements = 0;
760 const scalar fldElement = fld[i];
766 if (fldElement < min)
771 if (fldElement > max)
788 <<
" av = " << sum/(validElements + SMALL)
789 <<
" max = " << max <<
nl 791 <<
" " << validElements <<
" / " << totFieldSize <<
" elements used" 796 void Foam::polyMeshFilter::mapOldMeshEdgeFieldToNewMesh
807 forAll(newEdges, newEdgeI)
809 const edge& newEdge = newEdges[newEdgeI];
815 newMeshMinEdgeLen[pointMap[pStart]],
816 newMeshMinEdgeLen[pointMap[pEnd]]
832 void Foam::polyMeshFilter::mapOldMeshFaceFieldToNewMesh
843 const label oldFaceI = faceMap[newFaceI];
845 tmp[newFaceI] = newMeshFaceFilterFactor[oldFaceI];
853 newMeshFaceFilterFactor,
859 void Foam::polyMeshFilter::updateOldToNewPointMap
865 forAll(origToCurrentPointMap, origPointI)
867 label oldPointI = origToCurrentPointMap[origPointI];
871 label newPointI = currToNew[oldPointI];
875 origToCurrentPointMap[origPointI] = newPointI;
877 else if (newPointI == -1)
879 origToCurrentPointMap[origPointI] = -1;
883 origToCurrentPointMap[origPointI] = -newPointI-2;
892 Foam::polyMeshFilter::polyMeshFilter(
const fvMesh& mesh)
919 Foam::polyMeshFilter::polyMeshFilter
941 originalPointPriority_(pointPriority),
963 return filterFacesLoop(nOriginalBadFaces);
972 forAll(faceFilterFactor_, fI)
976 faceFilterFactor_[fI] = -1;
980 return filterFacesLoop(0);
986 const label nOriginalBadFaces
991 label nOuterIterations = 0;
994 faceFilterFactor_.
resize(0);
1007 && nBadFaces > nOriginalBadFaces
1008 && nBadFaces < nPreviousBadFaces
1011 Info<<
nl <<
"Outer Iteration = " << nOuterIterations++ <<
nl 1014 printScalarFieldStats(
"Edge Filter Factor", minEdgeLen_);
1016 nPreviousBadFaces = nBadFaces;
1020 fvMesh& newMesh = newMeshPtr_();
1023 pointPriority_.reset(
new labelList(originalPointPriority_));
1029 label nInnerIterations = 0;
1035 <<
indent <<
"Inner iteration = " << nInnerIterations++ <<
nl 1036 << incrIndent <<
endl;
1038 label nLocalCollapse = filterEdges
1042 origToCurrentPointMap
1049 nLocalCollapse >= nPrevLocalCollapse
1050 || nLocalCollapse == 0
1058 nPrevLocalCollapse = nLocalCollapse;
1077 Info<<
nl <<
" Number of bad faces : " << nBadFaces <<
nl 1078 <<
" Number of marked points : " 1082 updatePointErrorCount
1085 origToCurrentPointMap,
1089 checkMeshEdgesAndRelaxEdges
1092 origToCurrentPointMap,
1116 return pointPriority_;
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
label collapseEdge(triSurface &surf, const scalar minLen)
Keep collapsing all edges < minLen.
Does polyTopoChanges to remove edges. Can remove faces due to edge collapse but can not remove cells ...
virtual void updateMesh(const mapPolyMesh &mpm)
Update the mesh corresponding to given map.
virtual tmp< scalarField > movePoints(const pointField &)
Move points, returns volumes swept by faces in motion.
Mesh data needed to do the Finite Volume discretisation.
const word & name() const
Return reference to name.
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
An ordered pair of two objects of type <T> with first() and second() elements.
void transfer(List< T > &)
Transfer the contents of the argument List into this list.
const edgeList & edges() const
Return mesh edges. Uses calcEdges.
static label checkMeshQuality(const polyMesh &mesh, const dictionary &meshQualityDict, PackedBoolList &isErrorPoint)
Check mesh and mark points on faces in error.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
const labelList & reversePointMap() const
Reverse point map.
Ostream & indent(Ostream &os)
Indent stream.
void writeSettings(Ostream &os) const
Write the settings to a stream.
autoPtr< mapPolyMesh > makeMesh(autoPtr< fvMesh > &newMesh, const IOobject &io, const polyMesh &mesh, const bool syncParallel=true, const bool orderCells=false, const bool orderPoints=false)
Create new mesh with old mesh patches.
const scalar & initialFaceLengthFactor() const
A HashTable to objects of type <T> with a label key.
bool hasMotionPoints() const
Has valid preMotionPoints?
const Type & second() const
Return second.
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
void size(const label)
Override size to be inconsistent with allocated storage.
static void syncEdgeList(const polyMesh &, List< T > &, const CombineOp &cop, const T &nullValue, const TransformOp &top)
Synchronize values on all mesh edges.
unsigned int count() const
Count number of bits set, O(log(n))
const label & maxIterations() const
static void syncFaceList(const polyMesh &mesh, UList< T > &l, const CombineOp &cop)
Synchronize values on all mesh faces.
An edge is a list of two point labels. The functionality it provides supports the discretisation on a...
const Time & time() const
Return the top-level database.
const Switch & controlMeshQuality() const
const pointField & preMotionPoints() const
Pre-motion point positions.
A face is a list of labels corresponding to mesh vertices.
Ostream & incrIndent(Ostream &os)
Increment the indent level.
const double e
Elementary charge.
Calculates points shared by more than two processor patches or cyclic patches.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
polyMeshFilterSettings(const dictionary &dict)
Construct from dictionary.
label filter(const label nOriginalBadFaces)
Filter edges and faces.
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
const autoPtr< fvMesh > & filteredMesh() const
Return reference to the filtered mesh. Does not check if the.
const labelList & faceMap() const
Old face map.
~polyMeshFilter()
Destructor.
Unit conversion functions.
static const label labelMin
labelList identity(const label len)
Create identity map (map[i] == i) of given length.
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
const autoPtr< labelList > & pointPriority() const
Return the new pointPriority list.
const scalar & minLen() const
static void syncPointList(const polyMesh &, List< T > &, const CombineOp &cop, const T &nullValue, const TransformOp &top)
Synchronize values on all mesh points.
static autoPtr< fvMesh > copyMesh(const fvMesh &mesh)
Return a copy of an fvMesh.
void resize(const label)
Alias for setSize(const label)
Mesh consisting of general polyhedral cells.
int system(const std::string &command)
Execute the specified command.
label end() const
Return end vertex label.
List< label > labelList
A List of labels.
const labelList & pointMap() const
Old point map.
const Type & first() const
Return first.
Direct mesh changes based on v1.3 polyTopoChange syntax.
label start() const
Return start vertex label.
const dictionary & meshQualityCoeffDict() const
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
Class to store the settings for the polyMeshFilter class.
bool found(const Key &) const
Return true if hashedEntry is found in table.
A class for managing temporary objects.
autoPtr< mapPolyMesh > changeMesh(polyMesh &mesh, const bool inflate, const bool syncParallel=true, const bool orderCells=false, const bool orderPoints=false)
Inplace changes mesh without change of patches.
defineTypeNameAndDebug(combustionModel, 0)
static const label labelMax
const word & system() const
Return system name.