NEMoSys  0.63.0
A modular, extensible resource with robust automated mesh generation, mesh quality analysis, adaptive mesh refinement, and data transfer between arbitrary meshes.
ConversionJson.H
Go to the documentation of this file.
1 /*******************************************************************************
2 * Promesh *
3 * Copyright (C) 2022, IllinoisRocstar LLC. All rights reserved. *
4 * *
5 * Promesh is the property of IllinoisRocstar LLC. *
6 * *
7 * IllinoisRocstar LLC *
8 * Champaign, IL *
9 * www.illinoisrocstar.com *
10 * promesh@illinoisrocstar.com *
11 *******************************************************************************/
12 /*******************************************************************************
13 * This file is part of Promesh *
14 * *
15 * This version of Promesh is free software: you can redistribute it and/or *
16 * modify it under the terms of the GNU Lesser General Public License as *
17 * published by the Free Software Foundation, either version 3 of the License, *
18 * or (at your option) any later version. *
19 * *
20 * Promesh is distributed in the hope that it will be useful, but WITHOUT ANY *
21 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more *
23 * details. *
24 * *
25 * You should have received a copy of the GNU Lesser General Public License *
26 * along with this program. If not, see <https://www.gnu.org/licenses/>. *
27 * *
28 *******************************************************************************/
29 #ifndef NEMOSYS_CONVERSIONJSON_H_
30 #define NEMOSYS_CONVERSIONJSON_H_
31 
32 #include <jsoncons/json.hpp>
33 #include <memory>
34 #include <numeric>
35 #include <string>
36 #include <utility>
37 #include <vector>
38 #include "Drivers/NemJsonMacros.H"
39 
49 
50 #ifdef HAVE_CFMSH
51 # define IF_CFMSH(a) a,
54 #else
55 # define IF_CFMSH(a)
56 #endif
57 
58 #if defined(HAVE_CFMSH) && defined(HAVE_GMSH)
59 # define IF_CFMSH_GMSH(a) a,
61 #else
62 # define IF_CFMSH_GMSH(a)
63 #endif
64 
65 namespace NEM {
66 namespace DRV {
67 namespace JSON {
68 
69 static constexpr auto convOptions = "Conversion Options";
70 static constexpr auto convMethod = "Method";
71 
72 inline std::vector<PNTMesh::surfaceBCTag> pntMeshBcTagFromJSON(
73  const std::string &input) {
74  return {PNTMesh::bcTagNum(input)};
75 }
76 
77 inline std::string pntMeshBcTagToJSON(
78  const std::vector<PNTMesh::surfaceBCTag> &input) {
79  return input.empty() ? std::string{} : PNTMesh::bcTagStr(input.at(0));
80 }
81 
82 inline std::vector<int> rangeToVec(const std::pair<int, int> &input) {
83  std::vector<int> out(input.second - input.first + 1);
84  std::iota(out.begin(), out.end(), input.first);
85  return out;
86 }
87 
88 } // namespace JSON
89 } // namespace DRV
90 } // namespace NEM
91 
92 // ConversionDriver
107  [](const jsoncons::string_view &x) {
109  }))
110 
111 #ifdef HAVE_CFMSH
112 #ifdef HAVE_GMSH
113 // FoamToMshConversionDriver
116  (getFiles, setFiles, NEM::DRV::JSON::meshFiles),
117  (getOpts, , NEM::DRV::JSON::convOptions, JSONCONS_RDONLY))
118 
119 JSONCONS_ALL_MEMBER_NAME_TRAITS(
121  (methodName, NEM::DRV::JSON::convMethod, JSONCONS_RDONLY,
122  [](const jsoncons::string_view &x) {
124  }))
125 #endif
126 
127 // FoamToVtkConversionDriver
130  (getFiles, setFiles, NEM::DRV::JSON::meshFiles),
131  (getOpts, , NEM::DRV::JSON::convOptions, JSONCONS_RDONLY))
132 
133 JSONCONS_ALL_MEMBER_NAME_TRAITS(
135  (methodName, NEM::DRV::JSON::convMethod, JSONCONS_RDONLY,
136  [](const jsoncons::string_view &x) {
138  }))
139 
140 // VtkToFoamConversionDriver
143  (getFiles, setFiles, NEM::DRV::JSON::meshFiles),
144  (getOpts, , NEM::DRV::JSON::convOptions, JSONCONS_RDONLY))
145 
146 JSONCONS_ALL_MEMBER_NAME_TRAITS(NEM::DRV::VtkToFoamConversionDriver::Files,
147  (inputMeshFile, NEM::DRV::JSON::inMeshFile))
148 
149 JSONCONS_ALL_MEMBER_NAME_TRAITS(
151  (methodName, NEM::DRV::JSON::convMethod, JSONCONS_RDONLY,
152  [](const jsoncons::string_view &x) {
154  }))
155 #endif
156 
157 // GmshToExoConversionDriver
159  NEM::DRV::GmshToExoConversionDriver, NEM::DRV::ConversionDriver, 2,
160  (getFiles, setFiles, NEM::DRV::JSON::meshFiles),
161  (getOpts, setOpts, NEM::DRV::JSON::convOptions, JSONCONS_RDWR))
162 
163 JSONCONS_N_MEMBER_NAME_TRAITS(
165  (methodName, NEM::DRV::JSON::convMethod, JSONCONS_RDONLY,
166  [](const jsoncons::string_view &x) {
168  }),
169  (numMeshes, "Number of Mesh"), (meshData, "Mesh Data"),
170  (needsPostProc, "Post Processing"), (numTasks, "Number of Tasks"),
171  (tasks, "Tasks"))
172 
173 JSONCONS_N_MEMBER_NAME_TRAITS(NEM::DRV::GmshToExoConversionDriver::MeshData, 1,
174  (meshFileName, "File"), (meshName, "Name"),
175  (usePhys, "Use Physical Groups"),
176  (makeFreeSurfSS, "Free Surface Side Set"),
177  (splitTopBotSS, "Split Top and Bottom"),
178  (sideSetNames, "Side Set Names"),
179  (elmBlkNames, "Element Block Names"),
180  (addGlobalNodeSet, "Add Global Node Set"))
181 
182 JSONCONS_ALL_MEMBER_NAME_TRAITS(
184 
185 // GmshToVtkConversionDriver
188  (getFiles, setFiles, NEM::DRV::JSON::meshFiles),
189  (getOpts, , NEM::DRV::JSON::convOptions, JSONCONS_RDONLY))
190 
191 JSONCONS_ALL_MEMBER_NAME_TRAITS(
193  (methodName , NEM::DRV::JSON::convMethod, JSONCONS_RDONLY,
194  [](const jsoncons::string_view &x) {
196  }))
197 
198 // ManipExoConversionDriver
201  (getFiles, setFiles, NEM::DRV::JSON::meshFiles),
202  (getOpts, setOpts, NEM::DRV::JSON::convOptions, JSONCONS_RDWR))
203 
204 JSONCONS_N_MEMBER_NAME_TRAITS(
206  (methodName, NEM::DRV::JSON::convMethod, JSONCONS_RDONLY,
207  [](const jsoncons::string_view &x) {
209  }),
210  (combineBlocks, "CombineBlocks"))
211 
212 JSONCONS_N_MEMBER_NAME_TRAITS(NEM::DRV::ManipExoConversionDriver::CombineBlocks,
213  0, (blockIds, "BlockIDs"), (newName, "Rename"))
214 
215 // SmartConversionDriver
218  (getFiles, setFiles, NEM::DRV::JSON::meshFiles),
219  (getOpts, , NEM::DRV::JSON::convOptions, JSONCONS_RDONLY))
220 
221 JSONCONS_ALL_MEMBER_NAME_TRAITS(
223  (methodName , NEM::DRV::JSON::convMethod, JSONCONS_RDONLY,
224  [](const jsoncons::string_view &x) {
226  }))
227 
228 // VtkHexToTetConversionDriver
231  (getFiles, setFiles, NEM::DRV::JSON::meshFiles),
232  (getOpts, , NEM::DRV::JSON::convOptions, JSONCONS_RDONLY))
233 
234 JSONCONS_ALL_MEMBER_NAME_TRAITS(
236  (methodName, NEM::DRV::JSON::convMethod, JSONCONS_RDONLY,
237  [](const jsoncons::string_view &x) {
239  }))
240 
241 // VtkToCobaltConversionDriver
244  (getFiles, setFiles, NEM::DRV::JSON::meshFiles),
245  (getOpts, , NEM::DRV::JSON::convOptions, JSONCONS_RDONLY))
246 
247 JSONCONS_ALL_MEMBER_NAME_TRAITS(NEM::DRV::VtkToCobaltConversionDriver::Files,
248  (inputMeshFile, NEM::DRV::JSON::inMeshFile),
249  (outputCgrFile, NEM::DRV::JSON::outMeshFile),
250  (outputCgiFile, "Output Patch Map File"))
251 
252 JSONCONS_ALL_MEMBER_NAME_TRAITS(
254  (methodName, NEM::DRV::JSON::convMethod, JSONCONS_RDONLY,
255  [](const jsoncons::string_view &x) {
257  }))
258 
259 // VtkToPatranConversionDriver
262  (getFiles, setFiles, NEM::DRV::JSON::meshFiles),
263  (getOpts, setOpts, NEM::DRV::JSON::convOptions, JSONCONS_RDWR))
264 
265 JSONCONS_N_MEMBER_NAME_TRAITS(
267  (methodName, NEM::DRV::JSON::convMethod, JSONCONS_RDONLY,
268  [](const jsoncons::string_view &x) {
270  }),
271  (bcInfo, "BC Info"), (nodePatchPreference, "Node Patch Preference"))
272 
277  1, (patchNum, "Patch Number"), (getBCType(), "BC Type", JSONCONS_RDONLY))
278 
280  std::shared_ptr)
281 
285  (rocFracFSIType, "Rocfrac FSI Type"),
286  (bcType, "BC Type", NEM_JSON_RDONLY_OVERRIDE,
287  [](const jsoncons::string_view &x) {
289  }))
290 
294  (rocfracControlType, "RocfracControl Type"), (structural, "Structural"),
295  (meshMotion, "Mesh Motion"), (thermal, "Thermal"),
296  (bcType, "BC Type", NEM_JSON_RDONLY_OVERRIDE,
297  [](const jsoncons::string_view &x) {
299  }))
300 
301 // VtkToPntConversionDriver
304  (getFiles, setFiles, NEM::DRV::JSON::meshFiles),
305  (getOpts, setOpts, NEM::DRV::JSON::convOptions, JSONCONS_RDWR))
306 
307 JSONCONS_N_MEMBER_NAME_TRAITS(
309  (methodName, NEM::DRV::JSON::convMethod, JSONCONS_RDONLY,
310  [](const jsoncons::string_view &x) {
312  }),
313  (dim, "Dimension"), (elemBlockMap, "Block Data"))
314 
315 // Function-like macro so that the Into parameter of the first elmIds clause
316 // knows the type to deserialize and then pass to rangeToVec. Not that the Into
317 // function is unused due to NEM_JSON_RDWR_OVERRIDE - so that the second elmIds
318 // "Element ID" clause is used to serialize
319 #define PAIR_INT_DUMMY_FUNC(X) \
320  std::pair<int, int> {}
322  PNTMesh::blockType, 5, (ordIntrp, "Element Order"),
323  (ordEquat, "Equation Order"),
324  (eTpe, "Element Type", JSONCONS_RDWR, NEM_JSON_CHECK_KEY_ONLY,
326  (srfBCTag, "BC Tag", JSONCONS_RDWR, NEM_JSON_CHECK_KEY_ONLY,
328  (regionName, "Name"),
329  (elmIds, "Element ID Range", NEM_JSON_RDWR_OVERRIDE,
331  (elmIds, "Element ID"))
332 #undef PAIR_INT_DUMMY_FUNC
333 
334 #undef IF_CFMSH
335 #undef IF_CFMSH_GMSH
336 
337 #endif // NEMOSYS_CONVERSIONJSON_H_
static constexpr auto convMethod
#define NEM_JSON_CHECK_KEY_ONLY(x)
static constexpr const char * programType
base class for drivers
Definition: NemDriver.H:46
std::vector< int > rangeToVec(const std::pair< int, int > &input)
static constexpr auto inMeshFile
#define NEM_JSON_RDWR_OVERRIDE(X)
Definition: NemJsonMacros.H:40
std::string elmTypeStr(elementType tag)
Definition: pntMesh.C:117
static constexpr auto outMeshFile
#define NEM_JSON_N_MEMBER_NAME_TRAITS_BASE(BaseClass, ChildClasses, NumMandatoryParams,...)
Manipulates an existing EXODUSII mesh.
#define IF_CFMSH(a)
#define NEM_JSON_N_MEMBER_NAME_TRAITS_FINAL(ValueType, ParentType, NumMandatoryParams,...)
Definition: NemJsonMacros.H:83
#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,...)
surfaceBCTag bcTagNum(const std::string &tag)
Definition: pntMesh.C:78
static constexpr auto convOptions
std::string pntMeshBcTagToJSON(const std::vector< PNTMesh::surfaceBCTag > &input)
std::vector< PNTMesh::surfaceBCTag > pntMeshBcTagFromJSON(const std::string &input)
#define IF_CFMSH_GMSH(a)
static constexpr auto programType
static constexpr const char * methodName
elementType elmTypeNum(const std::string &tag)
Definition: pntMesh.C:97
#define NEM_JSON_WRAP_SMART_PTR(BaseClass, PointerTempl)
#define PAIR_INT_DUMMY_FUNC(X)
static constexpr auto meshFiles
std::string bcTagStr(surfaceBCTag tag)
Definition: pntMesh.C:88
#define NEM_JSON_RDONLY_OVERRIDE(X)
Definition: NemJsonMacros.H:39
#define NEM_JSON_N_MEMBER_NAME_TRAITS_VAL(ValueType, NumMandatoryParams,...)