48 updateSets<pointSet>(map);
49 updateSets<faceSet>(map);
50 updateSets<cellSet>(map);
54 void Foam::polyMeshFilter::copySets
60 copySets<pointSet>(oldMesh, newMesh);
61 copySets<faceSet>(oldMesh, newMesh);
62 copySets<cellSet>(oldMesh, newMesh);
77 mesh.polyMesh::instance(),
90 meshCopy().topoChange(map);
92 copySets(mesh, meshCopy());
100 Foam::label Foam::polyMeshFilter::filterFacesLoop(
const label nOriginalBadFaces)
103 label nOuterIterations = 0;
106 labelList pointErrorCount(mesh_.nPoints(), 0);
112 meshQualityCoeffDict(),
116 bool newBadFaces =
true;
126 nOuterIterations < maxIterations()
131 Info<<
nl <<
"Outer Iteration = " << nOuterIterations++ <<
nl
134 printScalarFieldStats(
"Edge Filter Factor", minEdgeLen_);
135 printScalarFieldStats(
"Face Filter Factor", faceFilterFactor_);
138 newMeshPtr_ = copyMesh(mesh_);
139 fvMesh& newMesh = newMeshPtr_();
141 scalarField newMeshFaceFilterFactor = faceFilterFactor_;
147 label nInnerIterations = 0;
157 label nLocalCollapse = filterFaces
160 newMeshFaceFilterFactor,
161 origToCurrentPointMap
167 nLocalCollapse >= nPrevLocalCollapse
168 || nLocalCollapse == 0
176 nPrevLocalCollapse = nLocalCollapse;
184 label nInnerIterations = 0;
194 label nLocalCollapse = filterEdges
198 origToCurrentPointMap
204 nLocalCollapse >= nPrevLocalCollapse
205 || nLocalCollapse == 0
213 nPrevLocalCollapse = nLocalCollapse;
224 if (controlMeshQuality())
226 PackedBoolList isErrorPoint(newMesh.
nPoints());
230 meshQualityCoeffDict(),
234 Info<<
nl <<
" Number of bad faces : " << nBadFaces <<
nl
235 <<
" Number of marked points : "
236 <<
returnReduce(isErrorPoint.count(), sumOp<unsigned int>())
239 updatePointErrorCount
242 origToCurrentPointMap,
246 checkMeshEdgesAndRelaxEdges
249 origToCurrentPointMap,
254 checkMeshFacesAndRelaxEdges
257 origToCurrentPointMap,
263 forAll(mesh_.points(), pI)
267 origToCurrentPointMap[pI] >= 0
268 && isErrorPoint[origToCurrentPointMap[pI]]
271 if (!newErrorPoint[pI])
279 reduce(newBadFaces, orOp<bool>());
301 Map<point> collapsePointToLocation(newMesh.nPoints());
303 edgeCollapser collapser(newMesh, collapseFacesCoeffDict());
307 labelPair nCollapsedPtEdge = collapser.markSmallSliverFaces
309 newMeshFaceFilterFactor,
312 collapsePointToLocation
315 label nCollapsed = 0;
316 forAll(nCollapsedPtEdge, collapseTypeI)
318 nCollapsed += nCollapsedPtEdge[collapseTypeI];
321 reduce(nCollapsed, sumOp<label>());
327 <<
"Collapsing " << nCollapsed <<
" faces "
328 <<
"(to point = " << nToPoint <<
", to edge = " << nToEdge <<
")"
339 List<pointEdgeCollapse> allPointInfo;
340 const globalIndex globalPoints(newMesh.nPoints());
342 collapser.consistentCollapse
346 collapsePointToLocation,
353 reduce(nLocalCollapse, sumOp<label>());
355 <<
" edges after synchronisation and PointEdgeWave" <<
endl;
357 if (nLocalCollapse == 0)
364 polyTopoChange newMeshMod(newMesh);
367 collapser.setRefinement(allPointInfo, newMeshMod);
372 autoPtr<polyTopoChangeMap> newMapPtr = newMeshMod.changeMesh(newMesh);
373 const polyTopoChangeMap& newMap = newMapPtr();
376 newMesh.topoChange(newMap);
379 updatePointPriorities(newMesh, newMap.pointMap());
381 mapOldMeshFaceFieldToNewMesh
385 newMeshFaceFilterFactor
388 updateOldToNewPointMap
390 newMap.reversePointMap(),
391 origToCurrentPointMap
395 return nLocalCollapse;
409 Map<point> collapsePointToLocation(newMesh.nPoints());
411 edgeCollapser collapser(newMesh, collapseFacesCoeffDict());
417 label nSmallCollapsed = collapser.markSmallEdges
422 collapsePointToLocation
425 reduce(nSmallCollapsed, sumOp<label>());
426 Info<<
indent <<
"Collapsing " << nSmallCollapsed
427 <<
" small edges" <<
endl;
430 label nMerged = collapser.markMergeEdges
435 collapsePointToLocation
438 reduce(nMerged, sumOp<label>());
439 Info<<
indent <<
"Collapsing " << nMerged <<
" in line edges"
442 if (nMerged + nSmallCollapsed == 0)
449 List<pointEdgeCollapse> allPointInfo;
450 const globalIndex globalPoints(newMesh.nPoints());
452 collapser.consistentCollapse
456 collapsePointToLocation,
463 reduce(nLocalCollapse, sumOp<label>());
465 <<
" edges after synchronisation and PointEdgeWave" <<
endl;
467 if (nLocalCollapse == 0)
473 polyTopoChange newMeshMod(newMesh);
476 collapser.setRefinement(allPointInfo, newMeshMod);
481 autoPtr<polyTopoChangeMap> newMapPtr = newMeshMod.changeMesh(newMesh);
482 const polyTopoChangeMap& newMap = newMapPtr();
485 newMesh.topoChange(newMap);
489 mapOldMeshEdgeFieldToNewMesh
496 updateOldToNewPointMap
498 newMap.reversePointMap(),
499 origToCurrentPointMap
502 updatePointPriorities(newMesh, newMap.pointMap());
504 return nLocalCollapse;
508 void Foam::polyMeshFilter::updatePointErrorCount
510 const PackedBoolList& isErrorPoint,
515 forAll(mesh_.points(), pI)
517 if (isErrorPoint[oldToNewMesh[pI]])
519 pointErrorCount[pI]++;
525 void Foam::polyMeshFilter::checkMeshEdgesAndRelaxEdges
527 const polyMesh& newMesh,
529 const PackedBoolList& isErrorPoint,
533 const edgeList& edges = mesh_.edges();
537 const edge&
e = edges[edgeI];
538 label newStart = oldToNewMesh[
e[0]];
539 label newEnd = oldToNewMesh[
e[1]];
543 pointErrorCount[
e[0]] >= maxPointErrorCount()
544 || pointErrorCount[
e[1]] >= maxPointErrorCount()
547 minEdgeLen_[edgeI] = -1;
552 (newStart >= 0 && isErrorPoint[newStart])
553 || (newEnd >= 0 && isErrorPoint[newEnd])
556 minEdgeLen_[edgeI] *= edgeReductionFactor();
562 for (
label smoothIter = 0; smoothIter < maxSmoothIters(); ++smoothIter)
565 forAll(mesh_.edges(), edgeI)
567 const edge&
e = mesh_.edges()[edgeI];
569 scalar sumMinEdgeLen = 0;
574 const labelList& pEdges = mesh_.pointEdges()[
e[pointi]];
578 const label pEdge = pEdges[pEdgeI];
579 sumMinEdgeLen += minEdgeLen_[pEdge];
584 minEdgeLen_[edgeI] =
min
602 void Foam::polyMeshFilter::checkMeshFacesAndRelaxEdges
604 const polyMesh& newMesh,
606 const PackedBoolList& isErrorPoint,
610 const faceList& faces = mesh_.faces();
614 const face&
f = faces[facei];
618 const label ptIndex = oldToNewMesh[
f[fpI]];
620 if (pointErrorCount[
f[fpI]] >= maxPointErrorCount())
622 faceFilterFactor_[facei] = -1;
625 if (isErrorPoint[ptIndex])
627 faceFilterFactor_[facei] *= faceReductionFactor();
636 for (
label smoothIter = 0; smoothIter < maxSmoothIters(); ++smoothIter)
641 const labelList& fEdges = mesh_.faceEdges()[facei];
643 scalar sumFaceFilterFactors = 0;
648 bool skipFace =
true;
652 const labelList& eFaces = mesh_.edgeFaces()[fEdges[fEdgeI]];
656 const label eFace = eFaces[eFacei];
658 const face&
f = faces[eFace];
662 const label ptIndex = oldToNewMesh[
f[fpI]];
664 if (isErrorPoint[ptIndex])
673 sumFaceFilterFactors += faceFilterFactor_[eFace];
684 faceFilterFactor_[facei] =
min
686 faceFilterFactor_[facei],
687 sumFaceFilterFactors/nFaces
697 void Foam::polyMeshFilter::updatePointPriorities
699 const polyMesh& newMesh,
704 const labelList& currPointPriority = pointPriority_();
706 forAll(newPointPriority, ptI)
708 const label newPointToOldPoint = pointMap[ptI];
709 const label origPointPriority = currPointPriority[newPointToOldPoint];
711 newPointPriority[ptI] =
max(origPointPriority, newPointPriority[ptI]);
722 pointPriority_.reset(
new labelList(newPointPriority));
726 void Foam::polyMeshFilter::printScalarFieldStats
733 scalar validElements = 0;
739 const scalar fldElement =
fld[i];
745 if (fldElement <
min)
750 if (fldElement >
max)
762 reduce(validElements, sumOp<label>());
767 <<
" av = " <<
sum/(validElements + small)
768 <<
" max = " <<
max <<
nl
770 <<
" " << validElements <<
" / " << totFieldSize <<
" elements used"
775 void Foam::polyMeshFilter::mapOldMeshEdgeFieldToNewMesh
777 const polyMesh& newMesh,
784 const edgeList& newEdges = newMesh.edges();
786 forAll(newEdges, newEdgeI)
788 const edge& newEdge = newEdges[newEdgeI];
789 const label pStart = newEdge.start();
790 const label pEnd = newEdge.end();
794 newMeshMinEdgeLen[pointMap[pStart]],
795 newMeshMinEdgeLen[pointMap[pEnd]]
799 newMeshMinEdgeLen.transfer(tmp);
811 void Foam::polyMeshFilter::mapOldMeshFaceFieldToNewMesh
813 const polyMesh& newMesh,
824 tmp[newFacei] = newMeshFaceFilterFactor[oldFacei];
827 newMeshFaceFilterFactor.transfer(tmp);
832 newMeshFaceFilterFactor,
838 void Foam::polyMeshFilter::updateOldToNewPointMap
844 forAll(origToCurrentPointMap, origPointi)
846 label oldPointi = origToCurrentPointMap[origPointi];
854 origToCurrentPointMap[origPointi] =
newPointi;
858 origToCurrentPointMap[origPointi] = -1;
862 origToCurrentPointMap[origPointi] = -
newPointi-2;
920 originalPointPriority_(pointPriority),
938 originalPointPriority_(pointPriority),
957 minEdgeLen_.resize(mesh_.nEdges(), minLen());
958 faceFilterFactor_.resize(mesh_.nFaces(), initialFaceLengthFactor());
960 return filterFacesLoop(nOriginalBadFaces);
966 minEdgeLen_.resize(mesh_.nEdges(), minLen());
967 faceFilterFactor_.resize(mesh_.nFaces(), initialFaceLengthFactor());
969 forAll(faceFilterFactor_, fI)
973 faceFilterFactor_[fI] = -1;
977 return filterFacesLoop(0);
983 const label nOriginalBadFaces
988 label nOuterIterations = 0;
990 minEdgeLen_.resize(mesh_.nEdges(), minLen());
991 faceFilterFactor_.resize(0);
993 labelList pointErrorCount(mesh_.nPoints(), 0);
1003 nOuterIterations < maxIterations()
1004 && nBadFaces > nOriginalBadFaces
1005 && nBadFaces < nPreviousBadFaces
1008 Info<<
nl <<
"Outer Iteration = " << nOuterIterations++ <<
nl
1011 printScalarFieldStats(
"Edge Filter Factor", minEdgeLen_);
1013 nPreviousBadFaces = nBadFaces;
1016 newMeshPtr_ = copyMesh(mesh_);
1017 fvMesh& newMesh = newMeshPtr_();
1026 label nInnerIterations = 0;
1032 <<
indent <<
"Inner iteration = " << nInnerIterations++ <<
nl
1035 label nLocalCollapse = filterEdges
1039 origToCurrentPointMap
1046 nLocalCollapse >= nPrevLocalCollapse
1047 || nLocalCollapse == 0
1055 nPrevLocalCollapse = nLocalCollapse;
1064 if (controlMeshQuality())
1070 meshQualityCoeffDict(),
1074 Info<<
nl <<
" Number of bad faces : " << nBadFaces <<
nl
1075 <<
" Number of marked points : "
1079 updatePointErrorCount
1082 origToCurrentPointMap,
1086 checkMeshEdgesAndRelaxEdges
1089 origToCurrentPointMap,
1113 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.
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