38 #include <vtkIdList.h> 45 #include <cartesian2DMeshGenerator.H> 46 #include <triSurfaceDetectFeatureEdges.H> 47 #include <triSurfacePatchManipulator.H> 49 #include <tetMeshGenerator.H> 50 #include <polyMeshGenModifier.H> 51 #include <meshOptimizer.H> 52 #include <cartesianMeshGenerator.H> 53 #include <voronoiMeshGenerator.H> 75 std::cerr <<
"A problem occured during edge detection step!\n";
85 std::unique_ptr<getDicts> initFoam;
86 initFoam = std::unique_ptr<getDicts>(
new getDicts());
88 fvSchemes_ = initFoam->createFvSchemes(writeDicts);
89 fvSolution_ = initFoam->createFvSolution(writeDicts);
93 std::unique_ptr<Foam::Time>(
new Foam::Time(controlDict_.get(),
".",
"."));
96 Foam::argList::noParallel();
107 Foam::Info <<
"Generating mesh with cfMesh engine" << Foam::endl;
109 Foam::Module::cartesian2DMeshGenerator cmg(*
runTime_);
110 std::cout <<
"ExecutionTime = " <<
runTime_->elapsedCpuTime() <<
" s\n" 111 <<
"ClockTime = " <<
runTime_->elapsedClockTime() <<
" s" 115 Foam::Module::tetMeshGenerator tmg(*
runTime_);
116 std::cout <<
"ExecutionTime = " <<
runTime_->elapsedCpuTime() <<
" s\n" 117 <<
"ClockTime = " <<
runTime_->elapsedClockTime() <<
" s" 124 Foam::Module::cartesianMeshGenerator cmg(*
runTime_);
125 std::cout <<
"ExecutionTime = " <<
runTime_->elapsedCpuTime() <<
" s\n" 126 <<
"ClockTime = " <<
runTime_->elapsedClockTime() <<
" s" 130 Foam::Module::voronoiMeshGenerator pmg(*
runTime_);
131 std::cout <<
"ExecutionTime = " <<
runTime_->elapsedCpuTime() <<
" s\n" 132 <<
"ClockTime = " <<
runTime_->elapsedClockTime() <<
" s" 137 <<
" is not a supported mesh generator.\n";
146 auto fgm_ = std::unique_ptr<NEM::MSH::foamGeoMesh>(
148 gmData = std::unique_ptr<NEM::MSH::geoMeshBase>(
157 std::cout <<
"Performing surface feature edge detection.\n";
158 std::string of =
"./" +
caseName +
"_feature.ftr";
160 Foam::fileName outFileName(of);
162 if (outFileName == inFileName) {
163 std::cerr <<
"Output file " << outFileName
164 <<
" would overwrite the input file.\n";
169 std::cout <<
"Using " << tol <<
" deg angle\n";
171 Foam::Module::triSurf originalSurface(inFileName);
173 Foam::Module::triSurfaceDetectFeatureEdges edgeDetector(originalSurface, tol);
174 edgeDetector.detectFeatureEdges();
176 if (outFileName.ext() ==
"fms" || outFileName.ext() ==
"FMS") {
177 std::cout <<
"Writing : " << outFileName << std::endl;
178 originalSurface.writeSurface(outFileName);
180 Foam::Module::triSurfacePatchManipulator manipulator(originalSurface);
181 const Foam::Module::triSurf *newSurfPtr = manipulator.surfaceWithPatches();
183 std::cout <<
"Writing : " << outFileName << std::endl;
184 newSurfPtr->writeSurface(outFileName);
195 std::cout <<
"Performing mesh quality improvements.\n";
198 Foam::Module::polyMeshGen pmg(*
runTime_);
202 Foam::Module::meshOptimizer mOpt(pmg);
206 if ((meshQual.qltConCelSet) !=
"none") {
208 mOpt.lockCellsInSubset((meshQual.qltConCelSet));
211 Foam::Module::labelLongList lockedBndFaces, selectedCells;
213 const Foam::label sId = pmg.cellSubsetIndex((meshQual.qltConCelSet));
214 pmg.cellsInSubset(sId, selectedCells);
216 Foam::boolList activeCell(pmg.cells().size(),
false);
217 for (
int iCl = 0; iCl < selectedCells.size(); iCl++)
218 activeCell[selectedCells[iCl]] =
true;
222 pmg.clearAddressingData();
225 mOpt.optimizeMeshFV((meshQual.qltNLop), (meshQual.qltNLop),
226 (meshQual.qltNItr), (meshQual.qltNSrfItr));
229 mOpt.optimizeMeshFVBestQuality((meshQual.qltNLop), (meshQual.qltQltThr));
232 mOpt.untangleMeshFV((meshQual.qltNLop), (meshQual.qltNItr),
233 (meshQual.qltNSrfItr));
235 std::cout <<
"Finished optimization cycle\n";
243 std::unique_ptr<Foam::dictionary>(
new Foam::dictionary(
"meshDict"));
245 Foam::dictionary fmfle(
"FoamFile");
246 fmfle.add(
"version",
"2.0");
247 fmfle.add(
"format",
"ascii");
248 fmfle.add(
"class",
"dictionary");
249 fmfle.add(
"location",
"\"system\"");
250 fmfle.add(
"object",
"meshDict");
263 meshDict_->add(
"boundaryCellSizeRefinementThickness",
277 Foam::dictionary boundaryLayrs(
"boundaryLayers");
278 boundaryLayrs.add(
"nLayers", boundaryLayer.blNLyr);
279 boundaryLayrs.add(
"thicknessRatio", boundaryLayer.blThkRto);
280 if (boundaryLayer.maxFrstLyrThk > 0.0)
281 boundaryLayrs.add(
"maxFirstLayerThickness", boundaryLayer.maxFrstLyrThk);
283 if (boundaryLayer.alwDiscont) boundaryLayrs.add(
"allowDiscontinuity", 1);
286 if (!boundaryLayer.blPatches.empty()) {
287 Foam::dictionary patchBoundaryLayers(
"patchBoundaryLayers");
288 for (
auto pt = (boundaryLayer.blPatches).begin();
289 pt != (boundaryLayer.blPatches).end(); pt++) {
290 Foam::dictionary tmpDict1(pt->patchName);
291 if (pt->alwDiscont) tmpDict1.add(
"allowDiscontinuity", 1);
292 if ((pt->maxFrstLyrThk) > 0)
293 tmpDict1.add(
"maxFirstLayerThickness", pt->maxFrstLyrThk);
294 if ((pt->blNLyr) > 0) tmpDict1.add(
"nLayers", pt->blNLyr);
295 if ((pt->blThkRto) > 0) tmpDict1.add(
"thicknessRatio", pt->blThkRto);
296 patchBoundaryLayers.add(Foam::word(
"\"" + pt->patchName +
"\""),
299 boundaryLayrs.add(
"patchBoundaryLayers", patchBoundaryLayers);
301 meshDict_->add(
"boundaryLayers", boundaryLayrs);
305 Foam::dictionary objectRefinements(
"objectRefinements");
309 Foam::dictionary tmpDict1(ref->name);
310 for (
auto prm = (ref->params).begin(); prm != (ref->params).end();
312 tmpDict1.add(Foam::word(prm->first), Foam::word(prm->second));
314 objectRefinements.add(Foam::word(ref->name), tmpDict1);
316 meshDict_->add(
"objectRefinements", objectRefinements);
320 Foam::dictionary localRefinement(
"localRefinement");
324 Foam::dictionary tmpDict1(pt->patchName);
325 if ((pt->aditRefLvls) > 0)
326 tmpDict1.add(
"additionalRefinementLevels", pt->aditRefLvls);
327 if ((pt->refThickness) > 0)
328 tmpDict1.add(
"refinementThickness", pt->refThickness);
329 if ((pt->cellSize) > 0) tmpDict1.add(
"cellSize", pt->cellSize);
330 localRefinement.add(Foam::word(
"\"" + pt->patchName +
"\""), tmpDict1);
332 meshDict_->add(
"localRefinement", localRefinement);
336 Foam::dictionary renameBoundary(
"renameBoundary");
339 renameBoundary.add(
"defaultName", Foam::word((renBndry).defName));
340 renameBoundary.add(
"defaultType", Foam::word((renBndry).defType));
342 Foam::dictionary tmpDict1(
"newPatchNames");
344 for (
auto pt = (renBndry).newPatches.begin();
345 pt != (renBndry).newPatches.end(); pt++) {
346 Foam::dictionary tmpDict2(pt->name);
347 tmpDict2.add(
"newName", Foam::word(pt->newName));
348 tmpDict2.add(
"type", Foam::word(pt->newType));
349 tmpDict1.add(Foam::word(
"\"" + pt->name +
"\""), tmpDict2);
351 renameBoundary.add(
"newPatchNames", tmpDict1);
352 meshDict_->add(
"renameBoundary", renameBoundary);
357 Foam::fileName cfmeshDict_ =
"system/meshDict";
358 Foam::OFstream outcfmeshDict_(cfmeshDict_);
359 Foam::IOobject::writeBanner(outcfmeshDict_);
std::unique_ptr< Foam::dictionary > meshDict_
std::unique_ptr< NEM::MSH::geoMeshBase > gmData
jsoncons::optional< cfmBoundaryLayer > boundaryLayers
std::unique_ptr< Foam::dictionary > fvSchemes_
int createMeshFromSTL(const char *fname) override
geoMeshBase * Read(const std::string &fileName)
Read a mesh from file.
std::unique_ptr< Foam::fvMesh > fmesh_
jsoncons::optional< cfmRenBndry > renBndry
std::unique_ptr< Foam::dictionary > fvSolution_
double bndryCellSizeRefThk
jsoncons::optional< cfmMeshQual > improveMeshQuality
std::vector< cfmLclRefPatch > refPatches
std::vector< cfmObjRef > objRefLst
jsoncons::optional< cfmSrfFeatEdge > srfEdge
void createMshDict(const bool &write)
int surfaceFeatureEdgeDetect()
A concrete implementation of geoMeshBase representing a mesh in a fvMesh.
std::unique_ptr< Foam::dictionary > controlDict_
std::unique_ptr< Foam::Time > runTime_
abstract class to specify geometry and mesh data