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().topoChange(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_;
152 label nInnerIterations = 0;
162 label nLocalCollapse = filterFaces
165 newMeshFaceFilterFactor,
166 origToCurrentPointMap
172 nLocalCollapse >= nPrevLocalCollapse
173 || nLocalCollapse == 0
181 nPrevLocalCollapse = nLocalCollapse;
189 label nInnerIterations = 0;
199 label nLocalCollapse = filterEdges
203 origToCurrentPointMap
209 nLocalCollapse >= nPrevLocalCollapse
210 || nLocalCollapse == 0
218 nPrevLocalCollapse = nLocalCollapse;
229 if (controlMeshQuality())
231 PackedBoolList isErrorPoint(newMesh.
nPoints());
235 meshQualityCoeffDict(),
239 Info<<
nl <<
" Number of bad faces : " << nBadFaces <<
nl
240 <<
" Number of marked points : "
241 <<
returnReduce(isErrorPoint.count(), sumOp<unsigned int>())
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])
284 reduce(newBadFaces, orOp<bool>());
306 Map<point> collapsePointToLocation(newMesh.nPoints());
308 edgeCollapser collapser(newMesh, collapseFacesCoeffDict());
312 labelPair nCollapsedPtEdge = collapser.markSmallSliverFaces
314 newMeshFaceFilterFactor,
317 collapsePointToLocation
320 label nCollapsed = 0;
321 forAll(nCollapsedPtEdge, collapseTypeI)
323 nCollapsed += nCollapsedPtEdge[collapseTypeI];
326 reduce(nCollapsed, sumOp<label>());
332 <<
"Collapsing " << nCollapsed <<
" faces "
333 <<
"(to point = " << nToPoint <<
", to edge = " << nToEdge <<
")"
344 List<pointEdgeCollapse> allPointInfo;
345 const globalIndex globalPoints(newMesh.nPoints());
347 collapser.consistentCollapse
351 collapsePointToLocation,
358 reduce(nLocalCollapse, sumOp<label>());
360 <<
" edges after synchronisation and PointEdgeWave" <<
endl;
362 if (nLocalCollapse == 0)
369 polyTopoChange newMeshMod(newMesh);
372 collapser.setRefinement(allPointInfo, newMeshMod);
377 autoPtr<polyTopoChangeMap> newMapPtr = newMeshMod.changeMesh
382 const polyTopoChangeMap& newMap = newMapPtr();
385 newMesh.topoChange(newMap);
386 if (newMap.hasMotionPoints())
388 newMesh.movePoints(newMap.preMotionPoints());
392 updatePointPriorities(newMesh, newMap.pointMap());
394 mapOldMeshFaceFieldToNewMesh
398 newMeshFaceFilterFactor
401 updateOldToNewPointMap
403 newMap.reversePointMap(),
404 origToCurrentPointMap
408 return nLocalCollapse;
422 Map<point> collapsePointToLocation(newMesh.nPoints());
424 edgeCollapser collapser(newMesh, collapseFacesCoeffDict());
430 label nSmallCollapsed = collapser.markSmallEdges
435 collapsePointToLocation
438 reduce(nSmallCollapsed, sumOp<label>());
439 Info<<
indent <<
"Collapsing " << nSmallCollapsed
440 <<
" small edges" <<
endl;
443 label nMerged = collapser.markMergeEdges
448 collapsePointToLocation
451 reduce(nMerged, sumOp<label>());
452 Info<<
indent <<
"Collapsing " << nMerged <<
" in line edges"
455 if (nMerged + nSmallCollapsed == 0)
462 List<pointEdgeCollapse> allPointInfo;
463 const globalIndex globalPoints(newMesh.nPoints());
465 collapser.consistentCollapse
469 collapsePointToLocation,
476 reduce(nLocalCollapse, sumOp<label>());
478 <<
" edges after synchronisation and PointEdgeWave" <<
endl;
480 if (nLocalCollapse == 0)
486 polyTopoChange newMeshMod(newMesh);
489 collapser.setRefinement(allPointInfo, newMeshMod);
494 autoPtr<polyTopoChangeMap> newMapPtr = newMeshMod.changeMesh
499 const polyTopoChangeMap& newMap = newMapPtr();
502 newMesh.topoChange(newMap);
503 if (newMap.hasMotionPoints())
505 newMesh.movePoints(newMap.preMotionPoints());
510 mapOldMeshEdgeFieldToNewMesh
517 updateOldToNewPointMap
519 newMap.reversePointMap(),
520 origToCurrentPointMap
523 updatePointPriorities(newMesh, newMap.pointMap());
525 return nLocalCollapse;
529 void Foam::polyMeshFilter::updatePointErrorCount
531 const PackedBoolList& isErrorPoint,
536 forAll(mesh_.points(), pI)
538 if (isErrorPoint[oldToNewMesh[pI]])
540 pointErrorCount[pI]++;
546 void Foam::polyMeshFilter::checkMeshEdgesAndRelaxEdges
548 const polyMesh& newMesh,
550 const PackedBoolList& isErrorPoint,
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
625 const polyMesh& newMesh,
627 const PackedBoolList& isErrorPoint,
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
720 const polyMesh& newMesh,
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)
783 reduce(validElements, sumOp<label>());
788 <<
" av = " <<
sum/(validElements + small)
789 <<
" max = " <<
max <<
nl
791 <<
" " << validElements <<
" / " << totFieldSize <<
" elements used"
796 void Foam::polyMeshFilter::mapOldMeshEdgeFieldToNewMesh
798 const polyMesh& newMesh,
805 const edgeList& newEdges = newMesh.edges();
807 forAll(newEdges, newEdgeI)
809 const edge& newEdge = newEdges[newEdgeI];
810 const label pStart = newEdge.start();
811 const label pEnd = newEdge.end();
815 newMeshMinEdgeLen[pointMap[pStart]],
816 newMeshMinEdgeLen[pointMap[pEnd]]
820 newMeshMinEdgeLen.transfer(tmp);
832 void Foam::polyMeshFilter::mapOldMeshFaceFieldToNewMesh
834 const polyMesh& newMesh,
845 tmp[newFacei] = newMeshFaceFilterFactor[oldFacei];
848 newMeshFaceFilterFactor.transfer(tmp);
853 newMeshFaceFilterFactor,
859 void Foam::polyMeshFilter::updateOldToNewPointMap
865 forAll(origToCurrentPointMap, origPointi)
867 label oldPointi = origToCurrentPointMap[origPointi];
875 origToCurrentPointMap[origPointi] =
newPointi;
879 origToCurrentPointMap[origPointi] = -1;
883 origToCurrentPointMap[origPointi] = -
newPointi-2;
941 originalPointPriority_(pointPriority),
959 originalPointPriority_(pointPriority),
978 minEdgeLen_.resize(mesh_.nEdges(), minLen());
979 faceFilterFactor_.resize(mesh_.nFaces(), initialFaceLengthFactor());
981 return filterFacesLoop(nOriginalBadFaces);
987 minEdgeLen_.resize(mesh_.nEdges(), minLen());
988 faceFilterFactor_.resize(mesh_.nFaces(), initialFaceLengthFactor());
990 forAll(faceFilterFactor_, fI)
994 faceFilterFactor_[fI] = -1;
998 return filterFacesLoop(0);
1004 const label nOriginalBadFaces
1009 label nOuterIterations = 0;
1011 minEdgeLen_.resize(mesh_.nEdges(), minLen());
1012 faceFilterFactor_.resize(0);
1014 labelList pointErrorCount(mesh_.nPoints(), 0);
1024 nOuterIterations < maxIterations()
1025 && nBadFaces > nOriginalBadFaces
1026 && nBadFaces < nPreviousBadFaces
1029 Info<<
nl <<
"Outer Iteration = " << nOuterIterations++ <<
nl
1032 printScalarFieldStats(
"Edge Filter Factor", minEdgeLen_);
1034 nPreviousBadFaces = nBadFaces;
1037 newMeshPtr_ = copyMesh(mesh_);
1038 fvMesh& newMesh = newMeshPtr_();
1047 label nInnerIterations = 0;
1053 <<
indent <<
"Inner iteration = " << nInnerIterations++ <<
nl
1056 label nLocalCollapse = filterEdges
1060 origToCurrentPointMap
1067 nLocalCollapse >= nPrevLocalCollapse
1068 || nLocalCollapse == 0
1076 nPrevLocalCollapse = nLocalCollapse;
1085 if (controlMeshQuality())
1091 meshQualityCoeffDict(),
1095 Info<<
nl <<
" Number of bad faces : " << nBadFaces <<
nl
1096 <<
" Number of marked points : "
1100 updatePointErrorCount
1103 origToCurrentPointMap,
1107 checkMeshEdgesAndRelaxEdges
1110 origToCurrentPointMap,
1134 return pointPriority_;
#define forAll(list, i)
Loop across all elements in list.
void reset(const Field< Type > &)
Reset the field values to the given field.
bool found(const Key &) const
Return true if hashedEntry is found in table.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
unsigned int count() const
Count number of bits set, O(log(n))
A list of keyword definitions, which are a keyword followed by any number of values (e....
static label checkMeshQuality(const polyMesh &mesh, const dictionary &meshQualityDict, PackedBoolList &isErrorPoint)
Check mesh and mark points on faces in error.
Mesh data needed to do the Finite Volume discretisation.
const Time & time() const
Return the top-level database.
const word & name() const
Return reference to name.
Class to store the settings for the polyMeshFilter class.
void writeSettings(Ostream &os) const
Write the settings to a stream.
Remove the edges and faces of a polyMesh whilst satisfying the given mesh quality criteria.
polyMeshFilter(const fvMesh &mesh)
Construct from fvMesh.
const autoPtr< labelList > & pointPriority() const
Return the new pointPriority list.
~polyMeshFilter()
Destructor.
label filter(const label nOriginalBadFaces)
Filter edges and faces.
static autoPtr< fvMesh > copyMesh(const fvMesh &mesh)
Return a copy of an fvMesh.
const autoPtr< fvMesh > & filteredMesh() const
Return reference to the filtered mesh. Does not check if the.
Mesh consisting of general polyhedral cells.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
const pointField & preMotionPoints() const
Pre-motion point positions.
bool hasMotionPoints() const
Has valid preMotionPoints?
Direct mesh changes based on v1.3 polyTopoChange syntax.
autoPtr< polyTopoChangeMap > 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.
label collapseEdge(triSurface &surf, const scalar minLen)
Keep collapsing all edges < minLen.
gmvFile<< "tracers "<< particles.size()<< nl;{ pointField positions(particles.size());label particlei=0;forAllConstIter(Cloud< passiveParticle >, particles, iter) { positions[particlei++]=iter().position(mesh);} for(i=0;i< pTraits< point >::nComponents;i++) { forAll(positions, particlei) { gmvFile<< component(positions[particlei], i)<< ' ';} gmvFile<< nl;}}forAll(lagrangianScalarNames, i){ const word &name=lagrangianScalarNames[i];IOField< scalar > fld(IOobject(name, runTime.name(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
int system(const std::string &command)
Execute the specified command.
Pair< label > labelPair
Label pair.
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
List< label > labelList
A List of labels.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Ostream & endl(Ostream &os)
Add newline and flush stream.
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
defineTypeNameAndDebug(combustionModel, 0)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
static const label labelMax
labelList identityMap(const label len)
Create identity map (map[i] == i) of given length.
Ostream & indent(Ostream &os)
Indent stream.
static const label labelMin
Unit conversion functions.