52 Foam::label Foam::autoRefineDriver::readFeatureEdges
54 const PtrList<dictionary>& featDicts,
55 PtrList<featureEdgeMesh>& featureMeshes,
59 Info<<
"Reading external feature lines." <<
endl;
61 const fvMesh&
mesh = meshRefiner_.
mesh();
63 featureMeshes.setSize(featDicts.size());
64 featureLevels.setSize(featDicts.size());
68 const dictionary& dict = featDicts[i];
70 fileName featFileName(dict.lookup(
"file"));
82 mesh.time().constant(),
93 featureLevels[i] = readLabel(dict.lookup(
"level"));
95 Info<<
"Refinement level " << featureLevels[i]
96 <<
" for all cells crossed by feature " << featFileName
97 <<
" (" << featureMeshes[i].points().size() <<
" points, "
98 << featureMeshes[i].edges().size() <<
" edges)." <<
endl;
101 Info<<
"Read feature lines in = "
102 << mesh.time().cpuTimeIncrement() <<
" s" <<
nl <<
endl;
104 return featureMeshes.size();
111 Foam::autoRefineDriver::autoRefineDriver
119 meshRefiner_(meshRefiner),
120 decomposer_(decomposer),
121 distributor_(distributor),
122 globalToPatch_(globalToPatch)
128 Foam::label Foam::autoRefineDriver::featureEdgeRefine
133 const label minRefine
136 const fvMesh& mesh = meshRefiner_.mesh();
142 readFeatureEdges(featDicts, featureMeshes, featureLevels);
147 if (featureMeshes.
size() && maxIter > 0)
149 for (; iter < maxIter; iter++)
152 <<
"Feature refinement iteration " << iter <<
nl
153 <<
"------------------------------" <<
nl
158 meshRefiner_.refineCandidates
176 meshRefiner_.meshCutter().consistentRefinement
182 Info<<
"Determined cells to refine in = "
187 label nCellsToRefine = cellsToRefine.size();
190 Info<<
"Selected for feature refinement : " << nCellsToRefine
194 if (nCellsToRefine <= minRefine)
196 Info<<
"Stopping refining since too few cells selected."
204 const_cast<Time&
>(mesh.
time())++;
217 meshRefiner_.balanceAndRefine
219 "feature refinement iteration " +
name(iter),
228 meshRefiner_.refineAndBalance
230 "feature refinement iteration " +
name(iter),
243 Foam::label Foam::autoRefineDriver::surfaceOnlyRefine
245 const refinementParameters& refineParams,
249 const fvMesh& mesh = meshRefiner_.mesh();
253 label overallMaxLevel =
max(meshRefiner_.surfaces().maxLevel());
256 for (iter = 0; iter < maxIter; iter++)
259 <<
"Surface refinement iteration " << iter <<
nl
260 <<
"------------------------------" <<
nl
269 const PtrList<featureEdgeMesh> dummyFeatures;
273 meshRefiner_.refineCandidates
275 refineParams.keepPoints()[0],
276 refineParams.curvature(),
285 refineParams.maxGlobalCells(),
286 refineParams.maxLocalCells()
291 meshRefiner_.meshCutter().consistentRefinement
297 Info<<
"Determined cells to refine in = "
298 << mesh.time().cpuTimeIncrement() <<
" s" <<
endl;
301 label nCellsToRefine = cellsToRefine.size();
302 reduce(nCellsToRefine, sumOp<label>());
304 Info<<
"Selected for refinement : " << nCellsToRefine
305 <<
" cells (out of " << mesh.globalData().nTotalCells()
314 iter >= overallMaxLevel
315 && nCellsToRefine <= refineParams.minRefineCells()
319 Info<<
"Stopping refining since too few cells selected."
327 const_cast<Time&
>(mesh.time())++;
335 (mesh.nCells() >= refineParams.maxLocalCells()),
340 meshRefiner_.balanceAndRefine
342 "surface refinement iteration " +
name(iter),
346 refineParams.maxLoadUnbalance()
351 meshRefiner_.refineAndBalance
353 "surface refinement iteration " +
name(iter),
357 refineParams.maxLoadUnbalance()
365 void Foam::autoRefineDriver::removeInsideCells
367 const refinementParameters& refineParams,
368 const label nBufferLayers
372 <<
"Removing mesh beyond surface intersections" <<
nl
373 <<
"------------------------------------------" <<
nl
376 const fvMesh& mesh = meshRefiner_.mesh();
380 const_cast<Time&
>(mesh.time())++;
383 meshRefiner_.splitMesh
387 refineParams.keepPoints()[0]
392 Pout<<
"Writing subsetted mesh to time "
393 << meshRefiner_.timeName() <<
'.' <<
endl;
394 meshRefiner_.
write(debug, mesh.time().path()/meshRefiner_.timeName());
395 Pout<<
"Dumped mesh in = "
396 << mesh.time().cpuTimeIncrement() <<
" s\n" <<
nl <<
endl;
401 Foam::label Foam::autoRefineDriver::shellRefine
403 const refinementParameters& refineParams,
407 const fvMesh& mesh = meshRefiner_.mesh();
410 meshRefiner_.userFaceData().setSize(1);
414 meshRefiner_.userFaceData()[0].second() = createWithValues<labelList>
418 meshRefiner_.intersectedFaces(),
425 label overallMaxShellLevel = meshRefiner_.shells().maxLevel();
428 for (iter = 0; iter < maxIter; iter++)
431 <<
"Shell refinement iteration " << iter <<
nl
432 <<
"----------------------------" <<
nl
435 const PtrList<featureEdgeMesh> dummyFeatures;
439 meshRefiner_.refineCandidates
441 refineParams.keepPoints()[0],
442 refineParams.curvature(),
451 refineParams.maxGlobalCells(),
452 refineParams.maxLocalCells()
458 Pout<<
"Dumping " << candidateCells.size()
459 <<
" cells to cellSet candidateCellsFromShells." <<
endl;
461 cellSet(mesh,
"candidateCellsFromShells", candidateCells).
write();
473 findIndices(meshRefiner_.userFaceData()[0].second(), 0)
481 if (refineParams.nBufferLayers() <= 2)
483 cellsToRefine = meshRefiner_.meshCutter().consistentSlowRefinement
485 refineParams.nBufferLayers(),
489 meshRefiner_.intersectedPoints()
494 cellsToRefine = meshRefiner_.meshCutter().consistentSlowRefinement2
496 refineParams.nBufferLayers(),
502 Info<<
"Determined cells to refine in = "
503 << mesh.time().cpuTimeIncrement() <<
" s" <<
endl;
506 label nCellsToRefine = cellsToRefine.size();
507 reduce(nCellsToRefine, sumOp<label>());
509 Info<<
"Selected for internal refinement : " << nCellsToRefine
510 <<
" cells (out of " << mesh.globalData().nTotalCells()
519 iter >= overallMaxShellLevel
520 && nCellsToRefine <= refineParams.minRefineCells()
524 Info<<
"Stopping refining since too few cells selected."
532 const_cast<Time&
>(mesh.time())++;
539 (mesh.nCells() >= refineParams.maxLocalCells()),
544 meshRefiner_.balanceAndRefine
546 "shell refinement iteration " +
name(iter),
550 refineParams.maxLoadUnbalance()
555 meshRefiner_.refineAndBalance
557 "shell refinement iteration " +
name(iter),
561 refineParams.maxLoadUnbalance()
565 meshRefiner_.userFaceData().clear();
571 void Foam::autoRefineDriver::baffleAndSplitMesh
573 const refinementParameters& refineParams,
574 const bool handleSnapProblems,
575 const dictionary& motionDict
579 <<
"Splitting mesh at surface intersections" <<
nl
580 <<
"---------------------------------------" <<
nl
583 const fvMesh& mesh = meshRefiner_.mesh();
588 meshRefiner_.baffleAndSplitMesh
595 const_cast<Time&>(mesh.time()),
597 refineParams.keepPoints()[0]
602 void Foam::autoRefineDriver::zonify
604 const refinementParameters& refineParams
613 if (meshRefiner_.surfaces().getNamedSurfaces().size())
616 <<
"Introducing zones for interfaces" <<
nl
617 <<
"--------------------------------" <<
nl
620 const fvMesh& mesh = meshRefiner_.mesh();
624 const_cast<Time&
>(mesh.time())++;
629 refineParams.keepPoints()[0],
630 refineParams.allowFreeStandingZoneFaces()
635 Pout<<
"Writing zoned mesh to time "
636 << meshRefiner_.timeName() <<
'.' <<
endl;
640 mesh.time().path()/meshRefiner_.timeName()
650 void Foam::autoRefineDriver::splitAndMergeBaffles
652 const refinementParameters& refineParams,
653 const bool handleSnapProblems,
654 const dictionary& motionDict
658 <<
"Handling cells with snap problems" <<
nl
659 <<
"---------------------------------" <<
nl
662 const fvMesh& mesh = meshRefiner_.mesh();
667 const_cast<Time&
>(mesh.time())++;
670 const scalarField& perpAngle = meshRefiner_.surfaces().perpendicularAngle();
672 meshRefiner_.baffleAndSplitMesh
679 const_cast<Time&>(mesh.time()),
681 refineParams.keepPoints()[0]
686 const_cast<Time&
>(mesh.time())++;
691 meshRefiner_.dupNonManifoldPoints();
695 List<labelPair> couples
697 meshRefiner_.getDuplicateFaces
699 identity(mesh.nFaces()-mesh.nInternalFaces())
700 + mesh.nInternalFaces()
704 label nCouples =
returnReduce(couples.size(), sumOp<label>());
706 Info<<
"Detected unsplittable baffles : "
714 meshRefiner_.mergeBaffles(couples);
719 meshRefiner_.checkData();
721 Info<<
"Merged free-standing baffles in = "
722 << mesh.time().cpuTimeIncrement() <<
" s." <<
endl;
727 Pout<<
"Writing handleProblemCells mesh to time "
728 << meshRefiner_.timeName() <<
'.' <<
endl;
729 meshRefiner_.
write(debug, mesh.time().path()/meshRefiner_.timeName());
734 void Foam::autoRefineDriver::mergePatchFaces
736 const refinementParameters& refineParams
739 const fvMesh& mesh = meshRefiner_.mesh();
742 <<
"Merge refined boundary faces" <<
nl
743 <<
"----------------------------" <<
nl
748 const_cast<Time&
>(mesh.time())++;
751 meshRefiner_.mergePatchFaces
755 meshRefiner_.meshedPatches()
760 meshRefiner_.checkData();
767 meshRefiner_.checkData();
776 const bool prepareForSnapping,
781 <<
"Refinement phase" <<
nl
782 <<
"----------------" <<
nl
785 const fvMesh& mesh = meshRefiner_.mesh();
823 baffleAndSplitMesh(refineParams, prepareForSnapping, motionDict);
826 zonify(refineParams);
829 splitAndMergeBaffles(refineParams, prepareForSnapping, motionDict);
832 if (prepareForSnapping)
834 mergePatchFaces(refineParams);
841 <<
"Doing final balancing" <<
nl
842 <<
"---------------------" <<
nl