29 #include <boost/filesystem.hpp> 42 #include <snappyMesh.H> 75 std::unique_ptr<getDicts> initFoam;
76 initFoam = std::unique_ptr<getDicts>(
new getDicts());
78 fvSchemes_ = initFoam->createFvSchemes(writeDicts);
79 fvSolution_ = initFoam->createFvSolution(writeDicts);
85 std::unique_ptr<Foam::Time>(
new Foam::Time(controlDict_.get(),
".",
"."));
88 Foam::argList::noParallel();
92 auto objMsh = snappyMesh();
100 fmesh_ = std::unique_ptr<Foam::fvMesh>(
108 auto fgm_ = std::unique_ptr<NEM::MSH::foamGeoMesh>(
110 gmData = std::unique_ptr<NEM::MSH::geoMeshBase>(
119 std::string contText =
121 /*--------------------------------*- C++ -*----------------------------------*\n\ 123 | \\\\ / F ield | NEMoSys: snappyHexMesh interface |\n\ 124 | \\\\ / O peration | |\n\ 126 | \\\\/ M anipulation | |\n\ 127 \\*---------------------------------------------------------------------------*/\n\ 134 location \"system\";\n\ 135 object snappyHexMeshDict;\n\ 140 "// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //\n\n";
144 contText +=
"\ncastellatedMesh true;\n";
146 contText +=
"\ncastellatedMesh false;\n";
150 contText +=
"\nsnap true;\n";
152 contText +=
"\nsnap false;\n";
156 contText +=
"\naddLayers true;\n";
158 contText +=
"\naddLayers false;\n";
162 contText +=
"\ngeometry\n{\n";
164 contText +=
"\n\t{\n\t\ttype\ttriSurfaceMesh;\n";
168 std::cerr <<
"Error reading in custom patches from JSON input!" 172 contText +=
"\t\tregions\n\t\t{\n";
175 contText +=
"\t\t\t" + pt->STLPatchName +
" \t{name " +
176 pt->snappyPatchName +
";}\n";
178 contText +=
"\t\t}\n";
187 contText +=
"\t\t" + (shape->patchName);
188 contText +=
"\n\t\t{";
189 contText +=
"\n\t\t\ttype " + (shape->getType()) +
";\n";
191 if (
auto box = std::dynamic_pointer_cast<shmSearchableBox>(shape)) {
192 contText +=
"\t\t\tmin (" + std::to_string(box->minBound.at(0)) +
" " +
193 std::to_string(box->minBound.at(1)) +
" " +
194 std::to_string(box->minBound.at(2)) +
");\n";
195 contText +=
"\t\t\tmax (" + std::to_string(box->maxBound.at(0)) +
" " +
196 std::to_string(box->maxBound.at(1)) +
" " +
197 std::to_string(box->maxBound.at(2)) +
");\n";
198 }
else if (
auto sphere =
199 std::dynamic_pointer_cast<shmSearchableSphere>(shape)) {
200 contText +=
"\t\t\tcentre (" + std::to_string(sphere->center.at(0)) +
201 " " + std::to_string(sphere->center.at(1)) +
" " +
202 std::to_string(sphere->center.at(2)) +
");\n";
203 contText +=
"\t\t\tradius " + std::to_string(sphere->radius) +
";\n";
204 }
else if (
auto cyl =
205 std::dynamic_pointer_cast<shmSearchableCylinder>(shape)) {
206 contText +=
"\t\t\tpoint1 (" + std::to_string(cyl->axisPoint1.at(0)) +
207 " " + std::to_string(cyl->axisPoint1.at(1)) +
" " +
208 std::to_string(cyl->axisPoint1.at(2)) +
");\n";
209 contText +=
"\t\t\tpoint2 (" + std::to_string(cyl->axisPoint2.at(0)) +
210 " " + std::to_string(cyl->axisPoint2.at(1)) +
" " +
211 std::to_string(cyl->axisPoint2.at(2)) +
");\n";
212 contText +=
"\t\t\tradius " + std::to_string(cyl->radius) +
";\n";
214 contText +=
"\n\t\t}\n";
222 contText +=
"\n\ncastellatedMeshControls\n{\n";
223 contText +=
"\tmaxLocalCells\t" +
225 contText +=
"\tmaxGlobalCells\t" +
227 contText +=
"\tnCellsBetweenLevels\t" +
229 contText +=
"\tminRefinementCells\t" +
233 contText +=
"\n\tfeatures\n\t(\n";
237 contText +=
"\t\t{\n";
238 contText +=
"\t\t\tfile \"" + pt->fileName +
"\";\n";
239 contText +=
"\t\t\tlevels ((" + std::to_string(pt->minLvl) +
" " +
240 std::to_string(pt->maxLvl) +
"));\n";
241 contText +=
"\t\t}\n";
244 contText +=
"\t);\n";
246 contText +=
"\n\trefinementSurfaces\n\t{\n";
252 contText +=
"\n\t\t\tlevel (" +
259 contText +=
"\t\t\tcellZoneInside\tinside;\n";
264 contText +=
"\n\t\t\tregions\n";
265 contText +=
"\t\t\t{";
269 if (pt->patchType ==
"NO") {
270 contText +=
"\n\t\t\t\t" + (pt->refPatchName) +
"\t{level (" +
271 std::to_string((
int)pt->minLvl) +
" " +
272 std::to_string(pt->maxLvl) +
273 "); patchInfo { type patch; }}";
275 contText +=
"\n\t\t\t\t" + (pt->refPatchName) +
"\t{level (" +
276 std::to_string((
int)pt->minLvl) +
" " +
277 std::to_string(pt->maxLvl) +
"); patchInfo { type " +
278 pt->patchType +
"; }}";
282 contText +=
"\n\t\t\t}\n";
286 contText +=
"\t\t}\n";
288 contText +=
"\t\tgapLevelIncrement " +
293 contText +=
"\tresolveFeatureAngle\t" +
296 contText +=
"\tgapLevelIncrement\t" +
299 contText +=
"\n\tplanarAngle " +
302 contText +=
"\n\trefinementRegions\n\t{\n";
307 contText +=
"\n\t\t" + (pt->patchName);
308 contText +=
"\n\t\t{";
309 contText +=
"\n\t\t\tmode " + (pt->mode) +
";\n";
310 contText +=
"\t\t\tlevels ((" + std::to_string(pt->minLvl) +
" " +
311 std::to_string(pt->maxLvl) +
"));\n";
312 contText +=
"\t\t}\n";
318 contText +=
"\n\tlocationInMesh\t(" +
323 contText +=
"\tallowFreeStandingZoneFaces\ttrue;\n";
325 contText +=
"\tallowFreeStandingZoneFaces\tfalse;\n";
329 contText +=
"\n\nsnapControls\n{\n";
330 contText +=
"\tnSmoothPatch\t" +
334 contText +=
"\tnSolveIter\t" +
336 contText +=
"\tnRelaxIter\t" +
340 contText +=
"\tnFeatureSnapIter\t" +
344 contText +=
"\timplicitFeatureSnap\t true;\n";
346 contText +=
"\timplicitFeatureSnap\t false;\n";
349 contText +=
"\texplicitFeatureSnap\t true;\n";
351 contText +=
"\texplicitFeatureSnap\t false;\n";
354 contText +=
"\tmultiRegionFeatureSnap\t true;\n";
356 contText +=
"\tmultiRegionFeatureSnap\t false;\n";
361 contText +=
"\n\naddLayersControls\n{\n";
363 contText +=
"\trelativeSizes\ttrue;\n";
365 contText +=
"\trelativeSizes\tfalse;\n";
368 contText +=
"\tlayers\n\t{\n";
372 contText +=
"\t\t" + pt->patchName +
"\n\t\t{\n";
374 "\t\t\tnSurfaceLayers " + std::to_string(pt->nSurfaceLayers) +
";\n";
376 "\t\t\texpansionRatio " + std::to_string(pt->expansionRatio) +
";\n";
377 contText +=
"\t\t\tfinalLayerThickness " +
378 std::to_string(pt->finalLayerThickness) +
";\n";
379 if (pt->firstLyrThickness > 0)
380 contText +=
"\t\t\tfirstLayerThickness " +
381 std::to_string(pt->firstLyrThickness) +
";\n";
382 if (pt->thickness > 0)
383 contText +=
"\t\t\tthickness " + std::to_string(pt->thickness) +
";\n";
385 "\t\t\tminThickness " + std::to_string(pt->minThickness) +
";\n";
386 contText +=
"\t\t}\n";
391 contText +=
"\texpansionRatio\t" +
393 contText +=
"\tfinalLayerThickness\t" +
395 contText +=
"\tminThickness\t" +
398 contText +=
"\tfirstLayerThickness\t" +
402 contText +=
"\tthickness\t" +
406 contText +=
"\tfeatureAngle\t" +
408 contText +=
"\tslipFeatureAngle\t" +
410 contText +=
"\tnRelaxIter\t" +
412 contText +=
"\tnSmoothSurfaceNormals\t" +
414 contText +=
"\tnSmoothNormals\t" +
416 contText +=
"\tnSmoothThickness\t" +
418 contText +=
"\tmaxFaceThicknessRatio\t" +
420 contText +=
"\tmaxThicknessToMedialRatio\t" +
422 contText +=
"\tminMedialAxisAngle\t" +
424 contText +=
"\tnBufferCellsNoExtrude\t" +
428 contText +=
"\tnRelaxedIter\t" +
431 contText +=
"\tnMedialAxisIter\t" +
434 contText +=
"\tnSmoothDisplacement\t" +
440 std::ostringstream minimumVol;
442 std::ostringstream minimumTetQuality;
445 contText +=
"\n\nmeshQualityControls\n{\n";
446 contText +=
"\tmaxNonOrtho\t" +
448 contText +=
"\tmaxBoundarySkewness\t" +
450 contText +=
"\tmaxInternalSkewness\t" +
452 contText +=
"\tmaxConcave\t" +
454 contText +=
"\tminVol\t" + minimumVol.str() +
";\n";
455 contText +=
"\tminTetQuality\t" + minimumTetQuality.str() +
";\n";
458 contText +=
"\tminTwist\t" +
460 contText +=
"\tminFaceWeight\t" +
462 contText +=
"\tminVolRatio\t" +
464 contText +=
"\tminDeterminant\t" +
466 contText +=
"\tminTriangleTwist\t" +
468 contText +=
"\tnSmoothScale\t" +
470 contText +=
"\terrorReduction\t" +
472 contText +=
"\trelaxed\n\t{\n";
473 contText +=
"\t\tmaxNonOrtho \t " +
480 contText +=
"writeFlags\n(\n";
481 contText +=
"\tscalarLevels\n";
482 contText +=
"\tlayerSets\n";
483 contText +=
"\tlayerFields\n);\n";
487 "// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //";
490 Foam::dictionary tmptmpDuc =
491 new Foam::dictionary(Foam::IStringStream(contText)(),
true);
493 new Foam::dictionary(
"snappyHexMeshDict"));
499 const char dir_path[] =
"./system";
500 boost::filesystem::path dir(dir_path);
502 boost::filesystem::create_directory(dir);
503 }
catch (boost::filesystem::filesystem_error &e) {
504 std::cerr <<
"Problem in creating system directory for the snappyHexMesh" 506 std::cerr << e.what() << std::endl;
511 std::ofstream contDict;
512 contDict.open(std::string(dir_path) +
"/snappyHexMeshDict");
513 contDict << contText;
int maxGCells
max local cells allowed (on 1 processor)
std::string singleSolidPatch
patch name for input surface file for when not _withMultiPatches
std::vector< shmSurfRefine > surfRefs
Vector for shmSurfRefine struct.
int nMedialAxisIter
Limits # of steps walking away from the surface.
int relaxIter
number of relaxation interations for layer addition
int cellsBetnLvls
number of cells between levels
double maxConc
Max Concativity.
shmMeshQualityControls qualityControls
Mesh Quality Controls.
snappymeshParams contains all parameters essential for mesh generation using snappymeshGen class meth...
double minVolRto
Minimum Volume Ratio.
std::unique_ptr< NEM::MSH::geoMeshBase > gmData
double featAngle
resolve feature angle
double expRatio
Expansion Ratio for layer addition.
int nIter
Number of layer interations for layer addition.
int nFeatureSnapIter
Feature snapping.
shmGeo geoDef
Geometry definition.
int planarAngle
Planar angle castallated mesh.
bool withSnap
Enables surface snapping option for snappymeshGen.
geoMeshBase * Read(const std::string &fileName)
Read a mesh from file.
int maxNonOrtho
Maximum non-orthogonality.
double minThick
Minimum Thickness for layer addition.
bool defaults
If enabled, generated mesh using default parameters.
bool multiRegionFeatureSnap
Multi-region feature snapping boolean.
int gapLvlInc
Gap level increment.
std::vector< shmSTLDefinition > stlPatchDefs
Vector for STL patches, if _withMultiPatches.
int createMeshFromSTL(const char *fname) override
Creates mesh from input STL file.
std::unique_ptr< Foam::Time > runTime_
double firstLyrThickness
First Layer Thickness.
shmSnapControls snapControls
Snapping controls.
int nSmoothPatch
Number of smoothing patches during snapping procedure.
std::unique_ptr< Foam::dictionary > fvSchemes_
double maxBndrySkew
Max Boundary Skewness.
bool isPackMesh
Boolean for packmesh.
double tolerance
Snapping tolerance at shared interface (affects conformality of mesh)
double maxThickTMR
Maximum thickness to medial ratio for layer addition.
std::vector< shmFeatureEdgeRef > ftrEdge
Vector for feature edge refinement.
std::string geomFileName
Input geometry STL name.
std::vector< shmLayers > layerVec
Vector for Layers.
bool implicitFeatureSnap
Implicit feature snaping boolean.
double minFaceW
Minimum Face Weight.
double minMedAngl
Minimum medial axis angle for layer addition.
bool relSize
Enables relative sizes option during layer addition.
std::vector< std::shared_ptr< shmSearchableShape > > srchShape
Vector for searchable shapes.
double minTwist
Minimum Twist.
int smthNorm
Number of smooth normals for layer addition.
double thickness
Thickness.
bool withMultiPatches
Boolean for if user wants whole STL as one solid of has different patches under STL.
double maxIntSkew
Max Internal Skewness.
double minVol
Minimum Cell Volume.
int nRelaxedIter
Relaxed iteration.
int smthThick
Number of smooth thickness for layer addition.
int bufferCells
Number of buffer cells no extrude for layer addition.
bool alwFreeZone
allows free standing zones if enabled
double minArea
Minimum Area.
int smoothScale
nSmoothScale
bool withLayers
Enables add layers option for snappymeshGen.
bool withCellZones
Enables defining cellzones and facezones.
std::unique_ptr< Foam::dictionary > snappyMshDict_
int minRefCells
minimum refinement cells
shmCastMeshControls castMeshControls
Castellated mesh controls.
bool explicitFeatureSnap
Explicit feature snapping boolean.
int maxLCells
max global cells allowed in mesh
double errReduction
Error Reduction.
double minTriTwist
Minimum Triangle Twist.
std::vector< shmRegionRefine > geomRefs
Vector for shmRegionRefine struct.
double mergeTol
merge tolerance for mesh
int nSolveIter
Maximum iterations during snapping procedure before ending the process.
shmLayerControls layerControls
Layer controls.
double maxFcTR
Maximum face thickness ratio for layer addition.
A concrete implementation of geoMeshBase representing a mesh in a fvMesh.
std::array< double, 3 > locMesh
location in Mesh (cells are kept in regions accessinble from this location)
std::unique_ptr< Foam::dictionary > fvSolution_
double minDet
Minimum Determinant.
int nRelaxIter
Maximum number of relaxation iterations for snapping procedure.
double featAngle
Feature Angle for layer addition.
double minTetQ
Minimum Tet Quality.
int castMeshGpLvl
Gap level increment.
~snappymeshGen()
snappymeshGen standard destructor
void createSnappyDict(const bool &write)
Creates snappyHexMeshDict for meshing operation.
int smthSurfNorm
Number of smooth surface normals for layer addition.
int nGrow
Growth rate of successive layers.
int refSurfLvlMin
minimum surface refinement
double finLThick
Final Layer Thickness for layer addition.
int slipFeatureAngle
Slip feature angles.
bool withCastMesh
Enables castellated mesh option for snappymeshGen.
std::unique_ptr< Foam::fvMesh > fmesh_
abstract class to specify geometry and mesh data
snappymeshParams * params_
snappymeshParams object Parameters
std::unique_ptr< Foam::dictionary > controlDict_
int nSmoothDisplacement
Smooth displacement after medial axis determination.
int refSurfLvlMax
maximum surface refinement
snappymeshGen()
snappymeshGen standard constructor
void initialize()
Initializes OpenFOAM environment.