62 meshRefiner_(meshRefiner),
63 decomposer_(decomposer),
64 distributor_(distributor),
65 globalToMasterPatch_(globalToMasterPatch),
66 globalToSlavePatch_(globalToSlavePatch)
72 Foam::label Foam::snappyRefineDriver::featureEdgeRefine
83 if (meshRefiner_.features().size() && maxIter > 0)
85 for (; iter < maxIter; iter++)
88 <<
"Feature refinement iteration " << iter <<
nl
89 <<
"------------------------------" <<
nl
94 meshRefiner_.refineCandidates
112 meshRefiner_.meshCutter().consistentRefinement
118 Info<<
"Determined cells to refine in = "
123 label nCellsToRefine = cellsToRefine.size();
126 Info<<
"Selected for feature refinement : " << nCellsToRefine
130 if (nCellsToRefine <= minRefine)
132 Info<<
"Stopping refining since too few cells selected."
140 const_cast<Time&
>(mesh.
time())++;
153 meshRefiner_.balanceAndRefine
155 "feature refinement iteration " +
name(iter),
164 meshRefiner_.refineAndBalance
166 "feature refinement iteration " +
name(iter),
179 Foam::label Foam::snappyRefineDriver::surfaceOnlyRefine
181 const refinementParameters& refineParams,
185 const fvMesh& mesh = meshRefiner_.
mesh();
189 label overallMaxLevel =
max(meshRefiner_.surfaces().maxLevel());
192 for (iter = 0; iter < maxIter; iter++)
195 <<
"Surface refinement iteration " << iter <<
nl
196 <<
"------------------------------" <<
nl
207 meshRefiner_.refineCandidates
209 refineParams.selectionPoints().inside(),
210 refineParams.curvature(),
211 refineParams.planarAngle(),
219 refineParams.maxGlobalCells(),
220 refineParams.maxLocalCells()
225 meshRefiner_.meshCutter().consistentRefinement
231 Info<<
"Determined cells to refine in = "
232 << mesh.time().cpuTimeIncrement() <<
" s" <<
endl;
235 label nCellsToRefine = cellsToRefine.size();
236 reduce(nCellsToRefine, sumOp<label>());
238 Info<<
"Selected for refinement : " << nCellsToRefine
239 <<
" cells (out of " << mesh.globalData().nTotalCells()
248 iter >= overallMaxLevel
249 && nCellsToRefine <= refineParams.minRefineCells()
253 Info<<
"Stopping refining since too few cells selected."
261 const_cast<Time&
>(mesh.time())++;
269 (mesh.nCells() >= refineParams.maxLocalCells()),
274 meshRefiner_.balanceAndRefine
276 "surface refinement iteration " +
name(iter),
280 refineParams.maxLoadUnbalance()
285 meshRefiner_.refineAndBalance
287 "surface refinement iteration " +
name(iter),
291 refineParams.maxLoadUnbalance()
299 Foam::label Foam::snappyRefineDriver::gapOnlyRefine
301 const refinementParameters& refineParams,
305 const fvMesh& mesh = meshRefiner_.mesh();
310 label maxIncrement = 0;
311 const labelList& maxLevel = meshRefiner_.surfaces().maxLevel();
312 const labelList& gapLevel = meshRefiner_.surfaces().gapLevel();
316 maxIncrement =
max(maxIncrement, gapLevel[i]-maxLevel[i]);
321 if (maxIncrement == 0)
326 for (iter = 0; iter < maxIter; iter++)
329 <<
"Gap refinement iteration " << iter <<
nl
330 <<
"--------------------------" <<
nl
341 meshRefiner_.refineCandidates
343 refineParams.selectionPoints().inside(),
344 refineParams.curvature(),
345 refineParams.planarAngle(),
353 refineParams.maxGlobalCells(),
354 refineParams.maxLocalCells()
360 Pout<<
"Dumping " << candidateCells.size()
361 <<
" cells to cellSet candidateCellsFromGap." <<
endl;
362 cellSet
c(mesh,
"candidateCellsFromGap", candidateCells);
363 c.instance() = meshRefiner_.
name();
369 boolList isCandidateCell(mesh.nCells(),
false);
372 isCandidateCell[candidateCells[i]] =
true;
375 for (
label i=0; i<1; i++)
377 boolList newIsCandidateCell(isCandidateCell);
380 for (
label facei = 0; facei < mesh.nInternalFaces(); facei++)
382 label own = mesh.faceOwner()[facei];
383 label nei = mesh.faceNeighbour()[facei];
385 if (isCandidateCell[own] != isCandidateCell[nei])
387 newIsCandidateCell[own] =
true;
388 newIsCandidateCell[nei] =
true;
404 label facei = mesh.nInternalFaces();
405 facei < mesh.nFaces();
409 label own = mesh.faceOwner()[facei];
410 label bFacei = facei-mesh.nInternalFaces();
412 if (isCandidateCell[own] != neiisCandidateCell[bFacei])
414 newIsCandidateCell[own] =
true;
418 isCandidateCell.transfer(newIsCandidateCell);
422 forAll(isCandidateCell, celli)
424 if (isCandidateCell[celli])
429 candidateCells.setSize(
n);
431 forAll(isCandidateCell, celli)
433 if (isCandidateCell[celli])
435 candidateCells[
n++] = celli;
443 Pout<<
"Dumping " << candidateCells.size()
444 <<
" cells to cellSet candidateCellsFromGapPlusBuffer." <<
endl;
445 cellSet
c(mesh,
"candidateCellsFromGapPlusBuffer", candidateCells);
446 c.instance() = meshRefiner_.
name();
453 meshRefiner_.meshCutter().consistentRefinement
459 Info<<
"Determined cells to refine in = "
460 << mesh.time().cpuTimeIncrement() <<
" s" <<
endl;
463 label nCellsToRefine = cellsToRefine.size();
464 reduce(nCellsToRefine, sumOp<label>());
466 Info<<
"Selected for refinement : " << nCellsToRefine
467 <<
" cells (out of " << mesh.globalData().nTotalCells()
477 && nCellsToRefine <= refineParams.minRefineCells()
481 Info<<
"Stopping refining since too few cells selected."
489 const_cast<Time&
>(mesh.time())++;
497 (mesh.nCells() >= refineParams.maxLocalCells()),
502 meshRefiner_.balanceAndRefine
504 "gap refinement iteration " +
name(iter),
508 refineParams.maxLoadUnbalance()
513 meshRefiner_.refineAndBalance
515 "gap refinement iteration " +
name(iter),
519 refineParams.maxLoadUnbalance()
527 Foam::label Foam::snappyRefineDriver::danglingCellRefine
529 const refinementParameters& refineParams,
534 const fvMesh& mesh = meshRefiner_.mesh();
537 for (iter = 0; iter < maxIter; iter++)
540 <<
"Dangling coarse cells refinement iteration " << iter <<
nl
541 <<
"--------------------------------------------" <<
nl
549 const polyBoundaryMesh& pbm = mesh.boundaryMesh();
553 cellSet candidateCellSet(mesh,
"candidateCells",
cells.
size()/1000);
557 const cell& cFaces =
cells[celli];
562 label bFacei = cFaces[i]-mesh.nInternalFaces();
570 if (pbm[
patchi].coupled())
577 if (nIntFaces == nFaces)
579 candidateCellSet.insert(celli);
585 Pout<<
"Dumping " << candidateCellSet.size()
586 <<
" cells to cellSet candidateCellSet." <<
endl;
587 candidateCellSet.instance() = meshRefiner_.
name();
588 candidateCellSet.write();
590 candidateCells = candidateCellSet.toc();
597 meshRefiner_.meshCutter().consistentRefinement
603 Info<<
"Determined cells to refine in = "
604 << mesh.time().cpuTimeIncrement() <<
" s" <<
endl;
607 label nCellsToRefine = cellsToRefine.size();
608 reduce(nCellsToRefine, sumOp<label>());
610 Info<<
"Selected for refinement : " << nCellsToRefine
611 <<
" cells (out of " << mesh.globalData().nTotalCells()
621 && nCellsToRefine <= refineParams.minRefineCells()
625 Info<<
"Stopping refining since too few cells selected."
633 const_cast<Time&
>(mesh.time())++;
641 (mesh.nCells() >= refineParams.maxLocalCells()),
646 meshRefiner_.balanceAndRefine
648 "coarse cell refinement iteration " +
name(iter),
652 refineParams.maxLoadUnbalance()
657 meshRefiner_.refineAndBalance
659 "coarse cell refinement iteration " +
name(iter),
663 refineParams.maxLoadUnbalance()
671 void Foam::snappyRefineDriver::removeInsideCells
673 const refinementParameters& refineParams,
674 const label nBufferLayers
678 <<
"Removing mesh beyond surface intersections" <<
nl
679 <<
"------------------------------------------" <<
nl
682 const fvMesh& mesh = meshRefiner_.mesh();
686 const_cast<Time&
>(mesh.time())++;
689 meshRefiner_.splitMesh
692 globalToMasterPatch_,
694 refineParams.selectionPoints()
699 Pout<<
"Writing subsetted mesh to time "
700 << meshRefiner_.
name() <<
'.' <<
endl;
709 mesh.time().path()/meshRefiner_.name()
711 Pout<<
"Dumped mesh in = "
712 << mesh.time().cpuTimeIncrement() <<
" s\n" <<
nl <<
endl;
719 const refinementParameters& refineParams,
723 const fvMesh& mesh = meshRefiner_.mesh();
726 meshRefiner_.userFaceData().setSize(1);
730 meshRefiner_.userFaceData()[0].second() = createWithValues<labelList>
734 meshRefiner_.intersectedFaces(),
741 label overallMaxShellLevel = meshRefiner_.shells().maxLevel();
744 for (iter = 0; iter < maxIter; iter++)
747 <<
"Shell refinement iteration " << iter <<
nl
748 <<
"----------------------------" <<
nl
753 meshRefiner_.refineCandidates
755 refineParams.selectionPoints().inside(),
756 refineParams.curvature(),
757 refineParams.planarAngle(),
765 refineParams.maxGlobalCells(),
766 refineParams.maxLocalCells()
772 Pout<<
"Dumping " << candidateCells.size()
773 <<
" cells to cellSet candidateCellsFromShells." <<
endl;
775 cellSet
c(mesh,
"candidateCellsFromShells", candidateCells);
776 c.instance() = meshRefiner_.
name();
789 findIndices(meshRefiner_.userFaceData()[0].second(), 0)
797 if (refineParams.nBufferLayers() <= 2)
799 cellsToRefine = meshRefiner_.meshCutter().consistentSlowRefinement
801 refineParams.nBufferLayers(),
805 meshRefiner_.intersectedPoints()
810 cellsToRefine = meshRefiner_.meshCutter().consistentSlowRefinement2
812 refineParams.nBufferLayers(),
818 Info<<
"Determined cells to refine in = "
819 << mesh.time().cpuTimeIncrement() <<
" s" <<
endl;
822 label nCellsToRefine = cellsToRefine.size();
823 reduce(nCellsToRefine, sumOp<label>());
825 Info<<
"Selected for internal refinement : " << nCellsToRefine
826 <<
" cells (out of " << mesh.globalData().nTotalCells()
835 iter >= overallMaxShellLevel
836 && nCellsToRefine <= refineParams.minRefineCells()
840 Info<<
"Stopping refining since too few cells selected."
848 const_cast<Time&
>(mesh.time())++;
855 (mesh.nCells() >= refineParams.maxLocalCells()),
860 meshRefiner_.balanceAndRefine
862 "shell refinement iteration " +
name(iter),
866 refineParams.maxLoadUnbalance()
871 meshRefiner_.refineAndBalance
873 "shell refinement iteration " +
name(iter),
877 refineParams.maxLoadUnbalance()
881 meshRefiner_.userFaceData().clear();
887 void Foam::snappyRefineDriver::baffleAndSplitMesh
889 const refinementParameters& refineParams,
890 const snapParameters& snapParams,
891 const bool handleSnapProblems,
892 const dictionary& motionDict
896 <<
"Splitting mesh at surface intersections" <<
nl
897 <<
"---------------------------------------" <<
nl
900 const fvMesh& mesh = meshRefiner_.mesh();
905 meshRefiner_.baffleAndSplitMesh
911 refineParams.useTopologicalSnapDetection(),
917 refineParams.planarAngle(),
920 const_cast<Time&
>(mesh.time()),
921 globalToMasterPatch_,
923 refineParams.selectionPoints()
928 void Foam::snappyRefineDriver::zonify
930 const refinementParameters& refineParams
942 if (namedSurfaces.size())
945 <<
"Introducing zones for interfaces" <<
nl
946 <<
"--------------------------------" <<
nl
949 const fvMesh& mesh = meshRefiner_.mesh();
953 const_cast<Time&
>(mesh.time())++;
958 refineParams.selectionPoints().inside(),
959 refineParams.allowFreeStandingZoneFaces()
964 Pout<<
"Writing zoned mesh to time "
965 << meshRefiner_.
name() <<
'.' <<
endl;
974 mesh.time().path()/meshRefiner_.name()
984 void Foam::snappyRefineDriver::splitAndMergeBaffles
986 const refinementParameters& refineParams,
987 const snapParameters& snapParams,
988 const bool handleSnapProblems,
989 const dictionary& motionDict
993 <<
"Handling cells with snap problems" <<
nl
994 <<
"---------------------------------" <<
nl
997 const fvMesh& mesh = meshRefiner_.mesh();
1002 const_cast<Time&
>(mesh.time())++;
1005 const scalarField& perpAngle = meshRefiner_.surfaces().perpendicularAngle();
1007 meshRefiner_.baffleAndSplitMesh
1013 refineParams.useTopologicalSnapDetection(),
1019 refineParams.planarAngle(),
1022 const_cast<Time&
>(mesh.time()),
1023 globalToMasterPatch_,
1024 globalToSlavePatch_,
1025 refineParams.selectionPoints()
1030 const_cast<Time&
>(mesh.time())++;
1035 meshRefiner_.dupNonManifoldPoints();
1043 Info<<
"Detected unsplittable baffles : " << nCouples <<
endl;
1050 meshRefiner_.mergeBaffles(couples);
1055 meshRefiner_.checkData();
1059 meshRefiner_.splitMeshRegions
1061 globalToMasterPatch_,
1062 globalToSlavePatch_,
1063 refineParams.selectionPoints()
1069 meshRefiner_.checkData();
1072 Info<<
"Merged free-standing baffles in = "
1073 << mesh.time().cpuTimeIncrement() <<
" s." <<
endl;
1078 Pout<<
"Writing handleProblemCells mesh to time "
1079 << meshRefiner_.
name() <<
'.' <<
endl;
1088 mesh.time().path()/meshRefiner_.name()
1094 void Foam::snappyRefineDriver::mergePatchFaces
1096 const refinementParameters& refineParams,
1097 const dictionary& motionDict
1101 <<
"Merge refined boundary faces" <<
nl
1102 <<
"----------------------------" <<
nl
1105 const fvMesh& mesh = meshRefiner_.mesh();
1107 meshRefiner_.mergePatchFacesUndo
1111 meshRefiner_.meshedPatches(),
1118 meshRefiner_.checkData();
1125 meshRefiner_.checkData();
1135 const bool prepareForSnapping,
1140 <<
"Refinement phase" <<
nl
1141 <<
"----------------" <<
nl
1209 zonify(refineParams);
1212 splitAndMergeBaffles
1221 if (prepareForSnapping)
1223 mergePatchFaces(refineParams, motionDict);
1230 <<
"Doing final balancing" <<
nl
1231 <<
"---------------------" <<
nl
1242 meshRefiner_.balance
1254 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.
const polyMesh & mesh() const
Return reference to polyMesh.
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.
scalar degToRad(const scalar deg)
Convert degrees to radians.
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)