63 meshRefiner_(meshRefiner),
64 decomposer_(decomposer),
65 distributor_(distributor),
66 globalToMasterPatch_(globalToMasterPatch),
67 globalToSlavePatch_(globalToSlavePatch)
73 Foam::label Foam::snappyRefineDriver::featureEdgeRefine
80 const fvMesh& mesh = meshRefiner_.mesh();
84 if (meshRefiner_.features().size() && maxIter > 0)
86 for (; iter < maxIter; iter++)
89 <<
"Feature refinement iteration " << iter <<
nl
90 <<
"------------------------------" <<
nl
95 meshRefiner_.refineCandidates
113 meshRefiner_.meshCutter().consistentRefinement
119 Info<<
"Determined cells to refine in = "
124 label nCellsToRefine = cellsToRefine.size();
127 Info<<
"Selected for feature refinement : " << nCellsToRefine
131 if (nCellsToRefine <= minRefine)
133 Info<<
"Stopping refining since too few cells selected."
141 const_cast<Time&
>(mesh.
time())++;
154 meshRefiner_.balanceAndRefine
156 "feature refinement iteration " +
name(iter),
165 meshRefiner_.refineAndBalance
167 "feature refinement iteration " +
name(iter),
180 Foam::label Foam::snappyRefineDriver::surfaceOnlyRefine
182 const refinementParameters& refineParams,
186 const fvMesh& mesh = meshRefiner_.mesh();
190 label overallMaxLevel =
max(meshRefiner_.surfaces().maxLevel());
193 for (iter = 0; iter < maxIter; iter++)
196 <<
"Surface refinement iteration " << iter <<
nl
197 <<
"------------------------------" <<
nl
208 meshRefiner_.refineCandidates
210 refineParams.selectionPoints().inside(),
211 refineParams.curvature(),
212 refineParams.planarAngle(),
220 refineParams.maxGlobalCells(),
221 refineParams.maxLocalCells()
226 meshRefiner_.meshCutter().consistentRefinement
232 Info<<
"Determined cells to refine in = "
233 << mesh.time().cpuTimeIncrement() <<
" s" <<
endl;
236 label nCellsToRefine = cellsToRefine.size();
237 reduce(nCellsToRefine, sumOp<label>());
239 Info<<
"Selected for refinement : " << nCellsToRefine
240 <<
" cells (out of " << mesh.globalData().nTotalCells()
249 iter >= overallMaxLevel
250 && nCellsToRefine <= refineParams.minRefineCells()
254 Info<<
"Stopping refining since too few cells selected."
262 const_cast<Time&
>(mesh.time())++;
270 (mesh.nCells() >= refineParams.maxLocalCells()),
275 meshRefiner_.balanceAndRefine
277 "surface refinement iteration " +
name(iter),
281 refineParams.maxLoadUnbalance()
286 meshRefiner_.refineAndBalance
288 "surface refinement iteration " +
name(iter),
292 refineParams.maxLoadUnbalance()
300 Foam::label Foam::snappyRefineDriver::gapOnlyRefine
302 const refinementParameters& refineParams,
306 const fvMesh& mesh = meshRefiner_.mesh();
311 label maxIncrement = 0;
312 const labelList& maxLevel = meshRefiner_.surfaces().maxLevel();
313 const labelList& gapLevel = meshRefiner_.surfaces().gapLevel();
317 maxIncrement =
max(maxIncrement, gapLevel[i]-maxLevel[i]);
322 if (maxIncrement == 0)
327 for (iter = 0; iter < maxIter; iter++)
330 <<
"Gap refinement iteration " << iter <<
nl
331 <<
"--------------------------" <<
nl
342 meshRefiner_.refineCandidates
344 refineParams.selectionPoints().inside(),
345 refineParams.curvature(),
346 refineParams.planarAngle(),
354 refineParams.maxGlobalCells(),
355 refineParams.maxLocalCells()
361 Pout<<
"Dumping " << candidateCells.size()
362 <<
" cells to cellSet candidateCellsFromGap." <<
endl;
363 cellSet
c(mesh,
"candidateCellsFromGap", candidateCells);
364 c.instance() = meshRefiner_.
name();
370 boolList isCandidateCell(mesh.nCells(),
false);
373 isCandidateCell[candidateCells[i]] =
true;
376 for (
label i=0; i<1; i++)
378 boolList newIsCandidateCell(isCandidateCell);
381 for (
label facei = 0; facei < mesh.nInternalFaces(); facei++)
383 label own = mesh.faceOwner()[facei];
384 label nei = mesh.faceNeighbour()[facei];
386 if (isCandidateCell[own] != isCandidateCell[nei])
388 newIsCandidateCell[own] =
true;
389 newIsCandidateCell[nei] =
true;
405 label facei = mesh.nInternalFaces();
406 facei < mesh.nFaces();
410 label own = mesh.faceOwner()[facei];
411 label bFacei = facei-mesh.nInternalFaces();
413 if (isCandidateCell[own] != neiisCandidateCell[bFacei])
415 newIsCandidateCell[own] =
true;
419 isCandidateCell.transfer(newIsCandidateCell);
423 forAll(isCandidateCell, celli)
425 if (isCandidateCell[celli])
430 candidateCells.setSize(
n);
432 forAll(isCandidateCell, celli)
434 if (isCandidateCell[celli])
436 candidateCells[
n++] = celli;
444 Pout<<
"Dumping " << candidateCells.size()
445 <<
" cells to cellSet candidateCellsFromGapPlusBuffer." <<
endl;
446 cellSet
c(mesh,
"candidateCellsFromGapPlusBuffer", candidateCells);
447 c.instance() = meshRefiner_.
name();
454 meshRefiner_.meshCutter().consistentRefinement
460 Info<<
"Determined cells to refine in = "
461 << mesh.time().cpuTimeIncrement() <<
" s" <<
endl;
464 label nCellsToRefine = cellsToRefine.size();
465 reduce(nCellsToRefine, sumOp<label>());
467 Info<<
"Selected for refinement : " << nCellsToRefine
468 <<
" cells (out of " << mesh.globalData().nTotalCells()
478 && nCellsToRefine <= refineParams.minRefineCells()
482 Info<<
"Stopping refining since too few cells selected."
490 const_cast<Time&
>(mesh.time())++;
498 (mesh.nCells() >= refineParams.maxLocalCells()),
503 meshRefiner_.balanceAndRefine
505 "gap refinement iteration " +
name(iter),
509 refineParams.maxLoadUnbalance()
514 meshRefiner_.refineAndBalance
516 "gap refinement iteration " +
name(iter),
520 refineParams.maxLoadUnbalance()
528 Foam::label Foam::snappyRefineDriver::danglingCellRefine
530 const refinementParameters& refineParams,
535 const fvMesh& mesh = meshRefiner_.mesh();
538 for (iter = 0; iter < maxIter; iter++)
541 <<
"Dangling coarse cells refinement iteration " << iter <<
nl
542 <<
"--------------------------------------------" <<
nl
550 const polyBoundaryMesh& pbm = mesh.boundaryMesh();
554 cellSet candidateCellSet(mesh,
"candidateCells",
cells.
size()/1000);
558 const cell& cFaces =
cells[celli];
563 label bFacei = cFaces[i]-mesh.nInternalFaces();
571 if (pbm[
patchi].coupled())
578 if (nIntFaces == nFaces)
580 candidateCellSet.insert(celli);
586 Pout<<
"Dumping " << candidateCellSet.size()
587 <<
" cells to cellSet candidateCellSet." <<
endl;
588 candidateCellSet.instance() = meshRefiner_.
name();
589 candidateCellSet.write();
591 candidateCells = candidateCellSet.toc();
598 meshRefiner_.meshCutter().consistentRefinement
604 Info<<
"Determined cells to refine in = "
605 << mesh.time().cpuTimeIncrement() <<
" s" <<
endl;
608 label nCellsToRefine = cellsToRefine.size();
609 reduce(nCellsToRefine, sumOp<label>());
611 Info<<
"Selected for refinement : " << nCellsToRefine
612 <<
" cells (out of " << mesh.globalData().nTotalCells()
622 && nCellsToRefine <= refineParams.minRefineCells()
626 Info<<
"Stopping refining since too few cells selected."
634 const_cast<Time&
>(mesh.time())++;
642 (mesh.nCells() >= refineParams.maxLocalCells()),
647 meshRefiner_.balanceAndRefine
649 "coarse cell refinement iteration " +
name(iter),
653 refineParams.maxLoadUnbalance()
658 meshRefiner_.refineAndBalance
660 "coarse cell refinement iteration " +
name(iter),
664 refineParams.maxLoadUnbalance()
672 void Foam::snappyRefineDriver::removeInsideCells
674 const refinementParameters& refineParams,
675 const label nBufferLayers
679 <<
"Removing mesh beyond surface intersections" <<
nl
680 <<
"------------------------------------------" <<
nl
683 const fvMesh& mesh = meshRefiner_.mesh();
687 const_cast<Time&
>(mesh.time())++;
690 meshRefiner_.splitMesh
693 globalToMasterPatch_,
695 refineParams.selectionPoints()
700 Pout<<
"Writing subsetted mesh to time "
701 << meshRefiner_.
name() <<
'.' <<
endl;
710 mesh.time().path()/meshRefiner_.name()
712 Pout<<
"Dumped mesh in = "
713 << mesh.time().cpuTimeIncrement() <<
" s\n" <<
nl <<
endl;
720 const refinementParameters& refineParams,
724 const fvMesh& mesh = meshRefiner_.mesh();
727 meshRefiner_.userFaceData().setSize(1);
731 meshRefiner_.userFaceData()[0].second() = createWithValues<labelList>
735 meshRefiner_.intersectedFaces(),
742 label overallMaxShellLevel = meshRefiner_.shells().maxLevel();
745 for (iter = 0; iter < maxIter; iter++)
748 <<
"Shell refinement iteration " << iter <<
nl
749 <<
"----------------------------" <<
nl
754 meshRefiner_.refineCandidates
756 refineParams.selectionPoints().inside(),
757 refineParams.curvature(),
758 refineParams.planarAngle(),
766 refineParams.maxGlobalCells(),
767 refineParams.maxLocalCells()
773 Pout<<
"Dumping " << candidateCells.size()
774 <<
" cells to cellSet candidateCellsFromShells." <<
endl;
776 cellSet
c(mesh,
"candidateCellsFromShells", candidateCells);
777 c.instance() = meshRefiner_.
name();
790 findIndices(meshRefiner_.userFaceData()[0].second(), 0)
798 if (refineParams.nBufferLayers() <= 2)
800 cellsToRefine = meshRefiner_.meshCutter().consistentSlowRefinement
802 refineParams.nBufferLayers(),
806 meshRefiner_.intersectedPoints()
811 cellsToRefine = meshRefiner_.meshCutter().consistentSlowRefinement2
813 refineParams.nBufferLayers(),
819 Info<<
"Determined cells to refine in = "
820 << mesh.time().cpuTimeIncrement() <<
" s" <<
endl;
823 label nCellsToRefine = cellsToRefine.size();
824 reduce(nCellsToRefine, sumOp<label>());
826 Info<<
"Selected for internal refinement : " << nCellsToRefine
827 <<
" cells (out of " << mesh.globalData().nTotalCells()
836 iter >= overallMaxShellLevel
837 && nCellsToRefine <= refineParams.minRefineCells()
841 Info<<
"Stopping refining since too few cells selected."
849 const_cast<Time&
>(mesh.time())++;
856 (mesh.nCells() >= refineParams.maxLocalCells()),
861 meshRefiner_.balanceAndRefine
863 "shell refinement iteration " +
name(iter),
867 refineParams.maxLoadUnbalance()
872 meshRefiner_.refineAndBalance
874 "shell refinement iteration " +
name(iter),
878 refineParams.maxLoadUnbalance()
882 meshRefiner_.userFaceData().clear();
888 void Foam::snappyRefineDriver::baffleAndSplitMesh
890 const refinementParameters& refineParams,
891 const snapParameters& snapParams,
892 const bool handleSnapProblems,
893 const dictionary& motionDict
897 <<
"Splitting mesh at surface intersections" <<
nl
898 <<
"---------------------------------------" <<
nl
901 const fvMesh& mesh = meshRefiner_.mesh();
906 meshRefiner_.baffleAndSplitMesh
912 refineParams.useTopologicalSnapDetection(),
918 refineParams.planarAngle(),
921 const_cast<Time&
>(mesh.time()),
922 globalToMasterPatch_,
924 refineParams.selectionPoints()
929 void Foam::snappyRefineDriver::zonify
931 const refinementParameters& refineParams
943 if (namedSurfaces.size())
946 <<
"Introducing zones for interfaces" <<
nl
947 <<
"--------------------------------" <<
nl
950 const fvMesh& mesh = meshRefiner_.mesh();
954 const_cast<Time&
>(mesh.time())++;
959 refineParams.selectionPoints().inside(),
960 refineParams.allowFreeStandingZoneFaces()
965 Pout<<
"Writing zoned mesh to time "
966 << meshRefiner_.
name() <<
'.' <<
endl;
975 mesh.time().path()/meshRefiner_.name()
985 void Foam::snappyRefineDriver::splitAndMergeBaffles
987 const refinementParameters& refineParams,
988 const snapParameters& snapParams,
989 const bool handleSnapProblems,
990 const dictionary& motionDict
994 <<
"Handling cells with snap problems" <<
nl
995 <<
"---------------------------------" <<
nl
998 const fvMesh& mesh = meshRefiner_.mesh();
1003 const_cast<Time&
>(mesh.time())++;
1006 const scalarField& perpAngle = meshRefiner_.surfaces().perpendicularAngle();
1008 meshRefiner_.baffleAndSplitMesh
1014 refineParams.useTopologicalSnapDetection(),
1020 refineParams.planarAngle(),
1023 const_cast<Time&
>(mesh.time()),
1024 globalToMasterPatch_,
1025 globalToSlavePatch_,
1026 refineParams.selectionPoints()
1031 const_cast<Time&
>(mesh.time())++;
1036 meshRefiner_.dupNonManifoldPoints();
1044 Info<<
"Detected unsplittable baffles : " << nCouples <<
endl;
1051 meshRefiner_.mergeBaffles(couples);
1056 meshRefiner_.checkData();
1060 meshRefiner_.splitMeshRegions
1062 globalToMasterPatch_,
1063 globalToSlavePatch_,
1064 refineParams.selectionPoints()
1070 meshRefiner_.checkData();
1073 Info<<
"Merged free-standing baffles in = "
1074 << mesh.time().cpuTimeIncrement() <<
" s." <<
endl;
1079 Pout<<
"Writing handleProblemCells mesh to time "
1080 << meshRefiner_.
name() <<
'.' <<
endl;
1089 mesh.time().path()/meshRefiner_.name()
1095 void Foam::snappyRefineDriver::mergePatchFaces
1097 const refinementParameters& refineParams,
1098 const dictionary& motionDict
1102 <<
"Merge refined boundary faces" <<
nl
1103 <<
"----------------------------" <<
nl
1106 const fvMesh& mesh = meshRefiner_.mesh();
1108 meshRefiner_.mergePatchFacesUndo
1112 meshRefiner_.meshedPatches(),
1119 meshRefiner_.checkData();
1126 meshRefiner_.checkData();
1136 const bool prepareForSnapping,
1141 <<
"Refinement phase" <<
nl
1142 <<
"----------------" <<
nl
1145 const fvMesh& mesh = meshRefiner_.mesh();
1210 zonify(refineParams);
1213 splitAndMergeBaffles
1222 if (prepareForSnapping)
1224 mergePatchFaces(refineParams, motionDict);
1231 <<
"Doing final balancing" <<
nl
1232 <<
"---------------------" <<
nl
1243 meshRefiner_.balance
1255 meshRefiner_.checkZoneFaces();
#define forAll(list, i)
Loop across all elements in list.
virtual const fileName & name() const
Return the name of the stream.
void size(const label)
Override size to be inconsistent with allocated storage.
virtual const fileName & name() const
Return the name of the stream.
virtual Ostream & write(const char)=0
Write character.
static bool & parRun()
Is this a parallel run?
double cpuTimeIncrement() const
Return CPU time (in seconds) since last call to cpuTimeIncrement()
Abstract base class for decomposition.
A list of keyword definitions, which are a keyword followed by any number of values (e....
const word & name() const
Return const reference to name.
Sends/receives parts of mesh+fvfields to neighbouring processors. Used in load balancing.
Mesh data needed to do the Finite Volume discretisation.
const Time & time() const
Return the top-level database.
label nTotalCells() const
Return total number of cells in decomposed mesh.
static labelPairList findDuplicateFacePairs(const polyMesh &)
Helper routine to find all baffles (two boundary faces.
Helper class which maintains intersections of (changing) mesh with (static) surfaces.
@ REMOVE
set value to -1 any face that was refined
static void checkCoupledFaceZones(const polyMesh &)
Helper function: check that face zones are synced.
static writeType writeLevel()
Get/set write level.
const globalMeshData & globalData() const
Return parallel info.
const List< point > & inside() const
Return the points inside the surface regions to selected cells.
Simple container to keep together refinement specific information.
scalar planarAngle() const
Angle when two intersections are considered to be planar.
label maxLocalCells() const
Per processor max number of cells.
scalar curvature() const
Curvature.
scalar maxLoadUnbalance() const
Allowed load unbalance.
label maxGlobalCells() const
Total number of cells.
const cellSelectionPoints & selectionPoints() const
Return the points to select cells inside and outside.
labelList findCells(const polyMesh &) const
Checks that cells are in mesh. Returns cells they are in.
Simple container to keep together snap specific information.
void doRefine(const dictionary &refineDict, const refinementParameters &refineParams, const snapParameters &snapParams, const bool prepareForSnapping, const dictionary &motionDict)
Do all the refinement.
snappyRefineDriver(meshRefinement &meshRefiner, decompositionMethod &decomposer, fvMeshDistribute &distributor, const labelList &globalToMasterPatch, const labelList &globalToSlavePatch)
Construct from components.
static labelList getNamedSurfaces(const PtrList< surfaceZonesInfo > &surfList)
Get indices of named surfaces (surfaces with faceZoneName)
const dimensionedScalar c
Speed of light in a vacuum.
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.
List< cell > cellList
list of cells
Ostream & endl(Ostream &os)
Add newline and flush stream.
word name(const bool)
Return a word representation of a bool.
labelList findIndices(const ListType &, typename ListType::const_reference, const label start=0)
Find all occurrences of given element. Linear search.
List< bool > boolList
Bool container classes.
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
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)
prefixOSstream Pout(cout, "Pout")
dimensionedScalar cos(const dimensionedScalar &ds)
scalar degToRad(const scalar deg)
Conversion from degrees to radians.
Unit conversion functions.