29 #ifndef NEMOSYS_MESHGENJSON_H_ 30 #define NEMOSYS_MESHGENJSON_H_ 35 #include <jsoncons/json.hpp> 46 # define IF_CFMSH(a) a, 56 # define IF_NGEN(a) a, 64 # define IF_GMSH(a) a, 71 # error "No mesh generators enabled. Check configuration settings." 78 static constexpr
auto meshGenOpts =
"Mesh Generation Options";
87 const std::map<std::array<int, 3>, std::string> &colorMap) {
88 std::vector<colorMapPair> out(colorMap.size());
89 std::transform(colorMap.begin(), colorMap.end(), out.begin(),
90 [](
const std::pair<const std::array<int, 3>, std::string> &x) {
97 const std::vector<colorMapPair> &colorMap) {
98 std::map<std::array<int, 3>, std::string> out;
99 for (
const auto &
color : colorMap) {
124 [](
const jsoncons::string_view &x) {
139 JSONCONS_ALL_MEMBER_NAME_TRAITS(
142 [](
const jsoncons::string_view &x) {
147 JSONCONS_N_MEMBER_NAME_TRAITS(
149 (ownBlockMshDict,
"Input Dict File"), (cellSize,
"Cell_Size"),
150 (nCells,
"NumCells"),
152 std::dynamic_pointer_cast<bmBox>,
153 (std::dynamic_pointer_cast<bmShape, bmBox>)),
155 std::dynamic_pointer_cast<bmSphere>,
156 (std::dynamic_pointer_cast<bmShape, bmSphere>)),
157 (shape,
"Cylinder/Tapered_Cone Parameters", JSONCONS_RDWR,
159 (std::dynamic_pointer_cast<bmShape, bmCylTaperedCone>)))
161 JSONCONS_N_MEMBER_NAME_TRAITS(
bmBox, 0, (autoGenerate,
"Auto_Generate"),
162 (init,
"InitialPoint"), (len,
"Length"),
163 (smplGrading,
"Grading"))
167 JSONCONS_N_MEMBER_NAME_TRAITS(
bmAutoGenBox, 0, (packFileName,
"InputPackFile"),
170 JSONCONS_N_MEMBER_NAME_TRAITS(
bmSphere, 2, (center,
"Center"),
171 (radius,
"Radius"), (sphrGrading,
"Grading"))
176 (height,
"Height"), (radius1,
"Radius1"),
177 (radius2,
"Radius2"), (cylGrading,
"Grading"))
187 JSONCONS_ALL_MEMBER_NAME_TRAITS(
190 [](
const jsoncons::string_view &x) {
193 (params,
"CFMesh Parameters"))
195 JSONCONS_N_MEMBER_NAME_TRAITS(
196 cfmeshParams, 1, (generator,
"Generator"), (maxCellSize,
"MaxCellSize"),
197 (minCellSize,
"MinCellSize"), (bndryCellSize,
"BoundaryCellSize"),
198 (bndryCellSizeRefThk,
"BoundaryCellSizeRefinementThickness"),
199 (keepCellIB,
"KeepCellsIntersectingBoundary"),
200 (chkGluMsh,
"CheckForGluedMesh"),
201 (alwDiscDomains,
"AllowDisconnectedDomains"),
202 (boundaryLayers,
"BoundaryLayers"), (srfEdge,
"SurfaceFeatureEdges"),
203 (objRefLst,
"ObjectRefinements"),
204 (improveMeshQuality,
"ImproveMeshQuality"), (refPatches,
"LocalRefinement"),
205 (renBndry,
"RenameBoundary"))
208 (blThkRto,
"ThicknessRatio"),
209 (maxFrstLyrThk,
"MaxFirstLayerThickness"),
210 (alwDiscont,
"AllowDiscontinuity"),
211 (blPatches,
"PatchBoundaryLayers"))
213 JSONCONS_N_MEMBER_NAME_TRAITS(
cfmPtchBndLyr, 1, (patchName,
"PatchName"),
214 (alwDiscont,
"AllowDiscontinuity"),
215 (maxFrstLyrThk,
"MaxFirstLayerThickness"),
216 (blNLyr,
"NLayers"), (blThkRto,
"ThicknessRatio"))
218 JSONCONS_N_MEMBER_NAME_TRAITS(
cfmSrfFeatEdge, 0, (srfEdgAng,
"Angle"))
220 JSONCONS_ALL_MEMBER_NAME_TRAITS(
cfmObjRef, (name,
"Name"), (params,
"Params"))
222 JSONCONS_N_MEMBER_NAME_TRAITS(
cfmMeshQual, 4, (qltNItr,
"NIterations"),
224 (qltQltThr,
"QualityThreshold"),
225 (qltNSrfItr,
"NSurfaceIterations"),
226 (qltConCelSet,
"ConstrainedCellsSet"))
228 JSONCONS_N_MEMBER_NAME_TRAITS(
cfmLclRefPatch, 1, (patchName,
"PatchName"),
229 (aditRefLvls,
"AdditionalRefinementLevels"),
230 (refThickness,
"RefinementThickness"),
231 (cellSize,
"CellSize"))
233 JSONCONS_ALL_MEMBER_NAME_TRAITS(
cfmRenBndry, (defName,
"DefaultName"),
234 (defType,
"DefaultType"),
235 (newPatches,
"NewPatchNames"))
237 JSONCONS_ALL_MEMBER_NAME_TRAITS(
cfmNewPatch, (name,
"Name"),
238 (newName,
"NewName"), (newType,
"NewType"))
246 JSONCONS_ALL_MEMBER_NAME_TRAITS(
249 [](
const jsoncons::string_view &x) {
254 JSONCONS_N_MEMBER_NAME_TRAITS(
256 (withSnap,
"Snapping"), (withLayers,
"Layer Addition"),
257 (mergeTol,
"mergeTolerance"), (geoDef,
"Geometry Definition"),
258 (castMeshControls,
"Castellated Mesh Controls"),
259 (snapControls,
"Snapping Controls"), (layerControls,
"Layer Controls"),
260 (qualityControls,
"Mesh Quality Controls"))
262 JSONCONS_N_MEMBER_NAME_TRAITS(
shmGeo, 1,
263 (withMultiPatches,
"Enable Multi Patches"),
264 (singleSolidPatch,
"InputPatchName"),
265 (stlPatchDefs,
"Geometry Patches"),
266 (srchShape,
"Custom Patches"))
269 (STLPatchName,
"Geometry Patch Name"),
270 (snappyPatchName,
"Output Patch Name"))
275 2, (patchName,
"Custom Patch Name"),
276 (getType(),
"Searchable Shape",
282 (minBound,
"minimum bound"),
283 (maxBound,
"maximum bound"))
286 3, (axisPoint1,
"Axis Point 1"),
287 (axisPoint2,
"Axis Point 2"),
291 (center,
"Center"), (radius,
"Radius"))
293 JSONCONS_N_MEMBER_NAME_TRAITS(
295 (castMeshGpLvl,
"GeneralGapLevelIncrement"), (maxLCells,
"maxLocalCells"),
296 (maxGCells,
"maxGlobalCells"), (minRefCells,
"minRefCells"),
297 (cellsBetnLvls,
"nCellsBetweenLevels"),
298 (refSurfLvlMin,
"surfaceRefinementLvlMin"),
299 (refSurfLvlMax,
"surfaceRefinementLvlMax"),
300 (featAngle,
"resolveFeatureAngle"), (gapLvlInc,
"gapLevelIncrement"),
301 (planarAngle,
"planarAngle"), (locMesh,
"locationInMesh"),
302 (alwFreeZone,
"allowFreeStandingZoneFaces"), (ftrEdge,
"Feature File"),
303 (surfRefs,
"SurfaceRefinementRegions"), (geomRefs,
"GeomRefinementRegions"))
306 (maxLvl,
"MaxLevel"), (minLvl,
"MinLevel"))
308 JSONCONS_N_MEMBER_NAME_TRAITS(
shmSurfRefine, 2, (refPatchName,
"Patch Name"),
309 (maxLvl,
"MaxLevel"), (patchType,
"Patch Type"),
310 (minLvl,
"MinLevel"))
312 JSONCONS_ALL_MEMBER_NAME_TRAITS(
shmRegionRefine, (patchName,
"Patch Name"),
313 (mode,
"Mode"), (minLvl,
"MinLevel"),
314 (maxLvl,
"MaxLevel"))
316 JSONCONS_N_MEMBER_NAME_TRAITS(
318 (tolerance,
"tolerance"), (nSolveIter,
"snapSolveIter"),
319 (nRelaxIter,
"snapRelaxIter"), (nFeatureSnapIter,
"nFeatureSnapIter"),
320 (implicitFeatureSnap,
"implicitFeatureSnap"),
321 (explicitFeatureSnap,
"explicitFeatureSnap"),
322 (multiRegionFeatureSnap,
"multiRegionFeatureSnap"))
324 JSONCONS_N_MEMBER_NAME_TRAITS(
326 (expRatio,
"expansionRatio"), (finLThick,
"finalLayerThickness"),
327 (minThick,
"minThickness"), (firstLyrThickness,
"firstLayerThickness"),
328 (thickness,
"thickness"), (nGrow,
"nGrow"), (featAngle,
"featureAngle"),
329 (relaxIter,
"nRelaxIter"), (smthSurfNorm,
"nSmoothSurfaceNormals"),
330 (smthNorm,
"nSmoothNormals"), (smthThick,
"nSmoothThickness"),
331 (maxFcTR,
"maxFaceThicknessRatio"),
332 (maxThickTMR,
"maxThicknessToMedialRatio"),
333 (minMedAngl,
"minMedialAxisAngle"), (bufferCells,
"nBufferCellsNoExtrude"),
334 (nIter,
"nLayerIter"), (nRelaxedIter,
"nRelaxedIter"),
335 (slipFeatureAngle,
"slipFeatureAngle"),
336 (nMedialAxisIter,
"nMedialAxisIter"),
337 (nSmoothDisplacement,
"nSmoothDisplacement"), (layerVec,
"Layers"))
339 JSONCONS_N_MEMBER_NAME_TRAITS(
shmLayers, 1, (patchName,
"Patch Name"),
340 (nSurfaceLayers,
"nSurfaceLayers"),
341 (expansionRatio,
"expansionRatio"),
342 (finalLayerThickness,
"finalLayerThickness"),
343 (firstLyrThickness,
"firstLyrThickness"),
344 (thickness,
"thickness"),
345 (minThickness,
"minThickness"))
347 JSONCONS_N_MEMBER_NAME_TRAITS(
349 (maxBndrySkew,
"maxBoundarySkewness"), (maxIntSkew,
"maxInternalSkewness"),
350 (maxConc,
"maxConcave"), (minVol,
"minVol"), (minTetQ,
"minTetQuality"),
351 (minArea,
"minArea"), (minTwist,
"minTwist"), (minFaceW,
"minFaceWeight"),
352 (minVolRto,
"minVolRatio"), (minDet,
"minDeterminant"),
353 (minTriTwist,
"minTriangleTwist"), (smoothScale,
"qcnSmoothScale"),
354 (errReduction,
"errorReduction"))
364 JSONCONS_ALL_MEMBER_NAME_TRAITS(
367 [](
const jsoncons::string_view &x) {
370 (params,
"Netgen Parameters"))
372 JSONCONS_N_MEMBER_NAME_TRAITS(
373 netgenParams, 0, (uselocalh,
"uselocalh"), (maxh,
"maxh"),
374 (fineness,
"fineness"), (grading,
"grading"),
375 (elementsperedge,
"elementsperedge"),
376 (elementspercurve,
"elementspercurve"),
377 (closeedgeenable,
"closeedgeenable"), (closeedgefact,
"closeedgefact"),
378 (second_order,
"second_order"), (meshsize_filename,
"meshsize_filename"),
379 (quad_dominated,
"quad_dominated"), (optvolmeshenable,
"optvolmeshenable"),
380 (optsteps_2d,
"optsteps_2d"), (optsteps_3d,
"optsteps_3d"),
381 (invert_tets,
"invert_tets"), (invert_trigs,
"invert_trigs"),
382 (check_overlap,
"check_overlap"),
383 (check_overlapping_boundary,
"check_overlapping_boundary"),
384 (refine_with_geom,
"refine_with_geometry_adaptation"),
385 (refine_without_geom,
"refine_without_geometry_adaptation"))
395 JSONCONS_ALL_MEMBER_NAME_TRAITS(
398 [](
const jsoncons::string_view &x) {
401 (params,
"Gmsh Parameters"))
403 JSONCONS_N_MEMBER_NAME_TRAITS(
405 (algo2D,
"surfaceAlgorithm"), (algo3D,
"volumeAlgorithm"),
406 (extSizeFromBoundary,
"extendSizeFromBoundary"),
407 (sizeFromCurvature,
"sizeFromCurvature"),
408 (minElePer2Pi,
"minElementsPer2Pi"), (optimize,
"optimize"),
409 (optimizeThreshold,
"optimizeThreshold"), (sizeFields,
"SizeFields"),
410 (bgField,
"BackgroundField"), (elementOrder,
"elementOrder"),
411 (subdivisionAlg,
"subdivisionAlgorithm"), (saveAll,
"saveAll"),
412 (fragmentAll,
"fragment"),
415 (transfiniteBlocks,
"TransfiniteBlocks"))
421 template <
typename Json>
424 using allocator_type =
typename Json::allocator_type;
425 static constexpr
auto idStr =
"Volume";
426 static constexpr
auto axisStr =
"Axis";
427 static constexpr
auto vertStr =
"Vertices";
428 static constexpr
auto progStr =
"Progression";
429 static constexpr
auto bumpStr =
"Bump";
430 static bool is(
const Json &ajson) noexcept {
431 return ajson.is_object() && ajson.contains(idStr) &&
432 ajson.contains(axisStr) && ajson.contains(
"x") &&
433 ajson.contains(
"y") && ajson.contains(
"z");
435 static value_type as(
const Json &ajson) {
436 static const std::array<std::pair<jsoncons::string_view, int>, 3> axisMap{
437 {{
"x", 0}, {
"y", 1}, {
"z", 2}}};
439 throw convert_error(convert_errc::conversion_failed,
440 "Not a NEM::GEN::TransfiniteBlock");
442 json_traits_helper<Json>::set_udt_member(ajson, idStr, aval.id);
443 json_traits_helper<Json>::set_udt_member(ajson, axisStr, aval.axis);
444 for (
int i = 0; i < 3; ++i) {
445 auto &axis = aval.axis[i];
447 std::sqrt(axis[0] * axis[0] + axis[1] * axis[1] + axis[2] * axis[2]);
448 if (axis_len < 1e-3) {
450 <<
"Axis " << i <<
" for block " << aval.id
451 <<
" is too small. Please prescribe an axis with length > 1e-3" 455 for (
auto &val : axis) {
459 for (
const auto &axis : axisMap) {
460 const auto &axisJson = ajson[axis.first];
461 aval.vert[axis.second] = axisJson[vertStr].template as<int>();
462 if (axisJson.contains(bumpStr)) {
463 aval.type[axis.second] = bumpStr;
464 aval.coef[axis.second] = axisJson[bumpStr].as_double();
465 }
else if (axisJson.contains(progStr)) {
466 aval.type[axis.second] = progStr;
467 aval.coef[axis.second] = axisJson[progStr].as_double();
472 static Json to_json(
const value_type &aval,
473 allocator_type alloc = allocator_type()) {
474 static const std::array<std::pair<jsoncons::string_view, int>, 3> axisMap{
475 {{
"x", 0}, {
"y", 1}, {
"z", 2}}};
476 Json ajson(json_object_arg, semantic_tag::none, alloc);
477 ajson.try_emplace(idStr, aval.id);
478 ajson.try_emplace(axisStr, aval.axis);
479 for (
const auto &axis : axisMap) {
480 auto &axisJson = ajson[axis.first];
481 axisJson.try_emplace(vertStr, aval.vert[axis.second]);
482 axisJson.try_emplace(aval.type[axis.second], aval.coef[axis.second]);
489 :
public std::true_type {};
493 template <
typename Json>
496 using allocator_type =
typename Json::allocator_type;
497 static bool is(
const Json &ajson) noexcept {
498 return ajson.is_object() && ajson.contains(
"Type") &&
499 ajson.contains(
"ID") && ajson.contains(
"Params");
501 static value_type as(
const Json &ajson) {
503 throw convert_error(convert_errc::conversion_failed,
504 "Not a NEM::GEN::volSizeField");
506 json_traits_helper<Json>::set_udt_member(ajson,
"Type", aval.type);
507 json_traits_helper<Json>::set_udt_member(ajson,
"ID", aval.id);
508 for (
const auto ¶m : ajson.at(
"Params").object_range()) {
509 const auto &val = param.value();
510 if (val.is_array()) {
511 if (val.at(0).is_string()) {
512 aval.strg_list_params.emplace_back(
513 param.key(), val.template as<std::vector<std::string>>());
515 aval.num_list_params.emplace_back(
516 param.key(), val.template as<std::vector<double>>());
519 aval.params.emplace_back(param.key(), val.as_double());
524 static Json to_json(
const value_type &aval,
525 allocator_type alloc = allocator_type()) {
526 Json ajson(json_object_arg, semantic_tag::none, alloc);
527 ajson.try_emplace(
"Type", aval.type);
528 ajson.try_emplace(
"ID", aval.id);
529 auto ¶ms = ajson[
"Params"];
530 for (
const auto ¶m : aval.strg_list_params) {
531 params.try_emplace(param.first, param.second);
533 for (
const auto ¶m : aval.num_list_params) {
534 params.try_emplace(param.first, param.second);
536 for (
const auto ¶m : aval.params) {
537 params.try_emplace(param.first, param.second);
544 :
public std::true_type {};
553 #endif // NEMOSYS_MESHGENJSON_H_ static constexpr const char * meshEngine
snappymeshParams contains all parameters essential for mesh generation using snappymeshGen class meth...
A structure for STL definition.
static constexpr const char * programType
#define NEM_JSON_CHECK_KEY_ONLY(x)
Castellated Mesh Controls.
static constexpr auto inGeoFile
#define NEM_JSON_SMART_PTR_VAL(BaseClass, PointerTempl)
static constexpr auto meshGenOpts
std::map< std::array< int, 3 >, std::string > gmshColorMapFromJSON(const std::vector< colorMapPair > &colorMap)
A structure to respresent regions refining capability in snappymeshGen.
blockMeshParams contains the parameters important for automatic meshing using blockMeshGen class...
A struct for defining hexahedral transfinite volumes.
static constexpr auto outMeshFile
#define NEM_JSON_N_MEMBER_NAME_TRAITS_BASE(BaseClass, ChildClasses, NumMandatoryParams,...)
static constexpr auto bmParams
#define NEM_JSON_N_MEMBER_NAME_TRAITS_FINAL(ValueType, ParentType, NumMandatoryParams,...)
std::vector< colorMapPair > gmshColorMapToJSON(const std::map< std::array< int, 3 >, std::string > &colorMap)
#define NEM_JSON_N_GETTER_SETTER_NAME_TRAITS_FINAL(ValueType, ParentType, NumMandatoryParams,...)
#define NEM_JSON_N_GETTER_SETTER_NAME_TRAITS_INTERMEDIATE(BaseClass, ChildClasses, ParentClass, NumMandatoryParams,...)
static constexpr auto smParams
gmshParams contains all parameters essential for mesh generation using gmshGen class methods...
static constexpr const char * meshEngine
A structure to respresent shape patches defining capability in snappymeshGen.
A structure for feature edge refinement.
A structure to represent geometry surface refining capability in snappymeshgGen.
std::array< int, 3 > color
static constexpr const char * meshEngine
static constexpr auto programType
#define NEM_JSON_WRAP_SMART_PTR(BaseClass, PointerTempl)
A structure for defining volumetric mesh size fields.
static constexpr const char * meshEngine
static constexpr auto meshFiles
#define NEM_JSON_RDONLY_OVERRIDE(X)
static constexpr auto meshGenEngine
A struct for layer addition.
static constexpr const char * meshEngine