167{
168 TCLAP::CmdLine cmd(
169 "Structured mesh generator.\n"
170 "The documentation is available at "
171 "https://docs.opengeosys.org/docs/tools/meshing/"
172 "structured-mesh-generation.\n\n"
173 "OpenGeoSys-6 software, version " +
175 ".\n"
176 "Copyright (c) 2012-2026, OpenGeoSys Community "
177 "(http://www.opengeosys.org)",
179
180 std::vector<std::string> allowed_ele_types;
181 allowed_ele_types.emplace_back("line");
182 allowed_ele_types.emplace_back("tri");
183 allowed_ele_types.emplace_back("quad");
184 allowed_ele_types.emplace_back("hex");
185 allowed_ele_types.emplace_back("prism");
186 allowed_ele_types.emplace_back("tet");
187 allowed_ele_types.emplace_back("pyramid");
188 TCLAP::ValuesConstraint<std::string> allowedVals(allowed_ele_types);
189 TCLAP::ValueArg<std::string> eleTypeArg("e", "element-type",
190 "element type to be created", true,
191 "line", &allowedVals);
192 cmd.add(eleTypeArg);
193 TCLAP::ValueArg<std::string> mesh_out(
194 "o", "mesh-output-file",
195 "Output (.vtu). The name of the file the mesh will be written to", true,
196 "", "OUTPUT_FILE");
197 cmd.add(mesh_out);
198 TCLAP::ValueArg<double> lengthXArg("", "lx",
199 "length of a domain in x direction, "
200 "(min = 0)",
201 false, 10.0, "LENGTH_X");
202 cmd.add(lengthXArg);
203 TCLAP::ValueArg<double> lengthYArg("", "ly",
204 "length of a domain in y direction, "
205 "(min = 0)",
206 false, 10.0, "LENGTH_Y");
207 cmd.add(lengthYArg);
208 TCLAP::ValueArg<double> lengthZArg("", "lz",
209 "length of a domain in z direction, "
210 "(min = 0)",
211 false, 10.0, "LENGTH_Z");
212 cmd.add(lengthZArg);
213 TCLAP::ValueArg<unsigned> nsubdivXArg(
214 "", "nx",
215 "the number of subdivision in x direction, "
216 "(min = 0)",
217 false, 10, "SUBDIVISIONS_X");
218 cmd.add(nsubdivXArg);
219 TCLAP::ValueArg<unsigned> nsubdivYArg(
220 "", "ny",
221 "the number of subdivision in y direction, "
222 "(min = 0)",
223 false, 10, "SUBDIVISIONS_Y");
224 cmd.add(nsubdivYArg);
225 TCLAP::ValueArg<unsigned> nsubdivZArg(
226 "", "nz",
227 "the number of subdivision in z direction, "
228 "(min = 0)",
229 false, 10, "SUBDIVISIONS_Z");
230 cmd.add(nsubdivZArg);
231
232 TCLAP::ValueArg<double> d0XArg("", "dx0",
233 "initial cell length in x direction, "
234 "(min = 0)",
235 false, 1, "INITIAL_X");
236 cmd.add(d0XArg);
237 TCLAP::ValueArg<double> d0YArg("", "dy0",
238 "initial cell length in y direction, "
239 "(min = 0)",
240 false, 1, "INITIAL_Y");
241 cmd.add(d0YArg);
242 TCLAP::ValueArg<double> d0ZArg("", "dz0",
243 "initial cell length in z direction, "
244 "(min = 0)",
245 false, 1, "INITIAL_Z");
246 cmd.add(d0ZArg);
247 TCLAP::ValueArg<double> dmaxXArg("", "dx-max",
248 "maximum cell length in x direction, "
249 "(min = 0)",
250 false, std::numeric_limits<double>::max(),
251 "MAX_X");
252 cmd.add(dmaxXArg);
253 TCLAP::ValueArg<double> dmaxYArg("", "dy-max",
254 "maximum cell length in y direction, "
255 "(min = 0)",
256 false, std::numeric_limits<double>::max(),
257 "MAX_Y");
258 cmd.add(dmaxYArg);
259 TCLAP::ValueArg<double> dmaxZArg("", "dz-max",
260 "maximum cell length in z direction, "
261 "(min = 0)",
262 false, std::numeric_limits<double>::max(),
263 "MAX_Z");
264 cmd.add(dmaxZArg);
265 TCLAP::ValueArg<double> multiXArg("", "mx", "multiplier in x direction",
266 false, 1, "MULTIPLIER_X");
267 cmd.add(multiXArg);
268 TCLAP::ValueArg<double> multiYArg("", "my", "multiplier in y direction",
269 false, 1, "MULTIPLIER_Y");
270 cmd.add(multiYArg);
271 TCLAP::ValueArg<double> multiZArg("", "mz", "multiplier in z direction",
272 false, 1, "MULTIPLIER_Z");
273 cmd.add(multiZArg);
274 TCLAP::ValueArg<double> originXArg(
275 "", "ox", "mesh origin (lower left corner) in x direction", false, 0,
276 "ORIGIN_X");
277 cmd.add(originXArg);
278 TCLAP::ValueArg<double> originYArg(
279 "", "oy", "mesh origin (lower left corner) in y direction", false, 0,
280 "ORIGIN_Y");
281 cmd.add(originYArg);
282 TCLAP::ValueArg<double> originZArg(
283 "", "oz", "mesh origin (lower left corner) in z direction", false, 0,
284 "ORIGIN_Z");
285 cmd.add(originZArg);
286
288 cmd.add(log_level_arg);
289 cmd.parse(argc, argv);
292
293 const std::string eleTypeName(eleTypeArg.getValue());
297
298 bool dim_used[3] = {false};
299 for (unsigned i = 0; i < dim; i++)
300 {
301 dim_used[i] = true;
302 }
303
304 std::vector<TCLAP::ValueArg<double>*> vec_lengthArg = {
305 &lengthXArg, &lengthYArg, &lengthZArg};
306 std::vector<TCLAP::ValueArg<unsigned>*> vec_ndivArg = {
307 &nsubdivXArg, &nsubdivYArg, &nsubdivZArg};
308 std::vector<TCLAP::ValueArg<double>*> vec_d0Arg = {&d0XArg, &d0YArg,
309 &d0ZArg};
310 std::vector<TCLAP::ValueArg<double>*> vec_dMaxArg = {&dmaxXArg, &dmaxYArg,
311 &dmaxZArg};
312 std::vector<TCLAP::ValueArg<double>*> vec_multiArg = {
313 &multiXArg, &multiYArg, &multiZArg};
315 {originXArg.getValue(), originYArg.getValue(), originZArg.getValue()});
316
317 const bool isLengthSet =
318 std::any_of(vec_lengthArg.begin(), vec_lengthArg.end(),
319 [&](TCLAP::ValueArg<double>* arg) { return arg->isSet(); });
320 if (!isLengthSet)
321 {
322 ERR(
"Missing input: Length information is not provided at all.");
323 return EXIT_FAILURE;
324 }
325 for (unsigned i = 0; i < 3; i++)
326 {
327 if (dim_used[i] && !vec_lengthArg[i]->isSet())
328 {
329 ERR(
"Missing input: Length for dimension [{:d}] is required but "
330 "missing.",
331 i);
332 return EXIT_FAILURE;
333 }
334 }
335
336 std::vector<double> length(dim);
337 std::vector<unsigned> n_subdivision(dim);
338 std::vector<double> vec_dx(dim);
339 for (unsigned i = 0; i < dim; i++)
340 {
341 length[i] = vec_lengthArg[i]->getValue();
342 n_subdivision[i] = vec_ndivArg[i]->getValue();
343 vec_dx[i] = length[i] / n_subdivision[i];
344 }
345
346 std::vector<std::unique_ptr<BaseLib::ISubdivision>> vec_div;
347 vec_div.reserve(dim);
348 for (unsigned i = 0; i < dim; i++)
349 {
350 if (vec_multiArg[i]->isSet())
351 {
352 if (vec_ndivArg[i]->isSet())
353 {
354
355 if (vec_d0Arg[i]->isSet())
356 {
358 "Specifying all of --m?, --d?0 and --n? for coordinate "
359 "'?' is not supported.");
360 }
362 length[i], vec_ndivArg[i]->
getValue(),
364 }
365 else
366 {
368 length[i], vec_d0Arg[i]->
getValue(),
370 }
371 }
372 else
373 {
374 vec_div.emplace_back(
376 }
377 }
378
379
380 std::unique_ptr<MeshLib::Mesh> mesh;
381 switch (eleType)
382 {
385 *vec_div[0], origin));
386 break;
389 *vec_div[0], *vec_div[1], origin));
390 break;
393 *vec_div[0], *vec_div[1], origin));
394 break;
397 *vec_div[0], *vec_div[1], *vec_div[2], origin));
398 break;
401 length[0], length[1], length[2], n_subdivision[0],
402 n_subdivision[1], n_subdivision[2], origin));
403 break;
406 *vec_div[0], *vec_div[1], *vec_div[2], origin));
407 break;
410 *vec_div[0], *vec_div[1], *vec_div[2], origin));
411 break;
412 default:
413 ERR(
"Given element type is not supported.");
414 break;
415 }
416
417 if (!mesh)
418 {
419 return EXIT_FAILURE;
420 }
421
422 INFO(
"Mesh created: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
423 mesh->getNumberOfElements());
424
425 auto const out_path = std::filesystem::path(mesh_out.getValue());
427 {
428 return EXIT_FAILURE;
429 }
430
431 auto const base = (out_path.parent_path() / out_path.stem()).string();
432
433 if (dim == 1)
434 {
436 }
437 else if (dim >= 2)
438 {
440 }
441
442 return EXIT_SUCCESS;
443}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
TCLAP::ValueArg< std::string > makeLogLevelArg()
void initOGSLogger(std::string const &log_level)
GITINFOLIB_EXPORT const std::string ogs_version
int writeMeshToFile(const MeshLib::Mesh &mesh, std::filesystem::path const &file_path, std::set< std::string > output_variable_names, bool const use_compression, int const data_mode)
MeshElemType String2MeshElemType(const std::string &s)
constexpr unsigned getDimension(MeshElemType t)
Returns the dimension of the given MeshElemType.
MeshElemType
Types of mesh elements supported by OpenGeoSys. Values are from VTKCellType enum.
void extract2D3DBoundaryMeshes(MeshLib::Mesh const &mesh, unsigned dim, MathLib::Point3d const &origin, std::vector< double > const &length, std::string const &base)
void extract1DBoundaryMeshes(MeshLib::Mesh const &mesh, MathLib::Point3d const &origin, std::vector< double > const &length, std::string const &base)