52int main(
int argc,
char* argv[])
55 "Structured mesh generator.\n"
56 "The documentation is available at "
57 "https://docs.opengeosys.org/docs/tools/meshing/"
58 "structured-mesh-generation.\n\n"
59 "OpenGeoSys-6 software, version " +
62 "Copyright (c) 2012-2026, OpenGeoSys Community "
63 "(http://www.opengeosys.org)",
66 std::vector<std::string> allowed_ele_types;
67 allowed_ele_types.emplace_back(
"line");
68 allowed_ele_types.emplace_back(
"tri");
69 allowed_ele_types.emplace_back(
"quad");
70 allowed_ele_types.emplace_back(
"hex");
71 allowed_ele_types.emplace_back(
"prism");
72 allowed_ele_types.emplace_back(
"tet");
73 allowed_ele_types.emplace_back(
"pyramid");
74 TCLAP::ValuesConstraint<std::string> allowedVals(allowed_ele_types);
75 TCLAP::ValueArg<std::string> eleTypeArg(
"e",
"element-type",
76 "element type to be created",
true,
77 "line", &allowedVals);
79 TCLAP::ValueArg<std::string> mesh_out(
80 "o",
"mesh-output-file",
81 "Output (.vtu). The name of the file the mesh will be written to",
true,
84 TCLAP::ValueArg<double> lengthXArg(
"",
"lx",
85 "length of a domain in x direction, "
87 false, 10.0,
"LENGTH_X");
89 TCLAP::ValueArg<double> lengthYArg(
"",
"ly",
90 "length of a domain in y direction, "
92 false, 10.0,
"LENGTH_Y");
94 TCLAP::ValueArg<double> lengthZArg(
"",
"lz",
95 "length of a domain in z direction, "
97 false, 10.0,
"LENGTH_Z");
99 TCLAP::ValueArg<unsigned> nsubdivXArg(
101 "the number of subdivision in x direction, "
103 false, 10,
"SUBDIVISIONS_X");
104 cmd.add(nsubdivXArg);
105 TCLAP::ValueArg<unsigned> nsubdivYArg(
107 "the number of subdivision in y direction, "
109 false, 10,
"SUBDIVISIONS_Y");
110 cmd.add(nsubdivYArg);
111 TCLAP::ValueArg<unsigned> nsubdivZArg(
113 "the number of subdivision in z direction, "
115 false, 10,
"SUBDIVISIONS_Z");
116 cmd.add(nsubdivZArg);
118 TCLAP::ValueArg<double> d0XArg(
"",
"dx0",
119 "initial cell length in x direction, "
121 false, 1,
"INITIAL_X");
123 TCLAP::ValueArg<double> d0YArg(
"",
"dy0",
124 "initial cell length in y direction, "
126 false, 1,
"INITIAL_Y");
128 TCLAP::ValueArg<double> d0ZArg(
"",
"dz0",
129 "initial cell length in z direction, "
131 false, 1,
"INITIAL_Z");
133 TCLAP::ValueArg<double> dmaxXArg(
"",
"dx-max",
134 "maximum cell length in x direction, "
136 false, std::numeric_limits<double>::max(),
139 TCLAP::ValueArg<double> dmaxYArg(
"",
"dy-max",
140 "maximum cell length in y direction, "
142 false, std::numeric_limits<double>::max(),
145 TCLAP::ValueArg<double> dmaxZArg(
"",
"dz-max",
146 "maximum cell length in z direction, "
148 false, std::numeric_limits<double>::max(),
151 TCLAP::ValueArg<double> multiXArg(
"",
"mx",
"multiplier in x direction",
152 false, 1,
"MULTIPLIER_X");
154 TCLAP::ValueArg<double> multiYArg(
"",
"my",
"multiplier in y direction",
155 false, 1,
"MULTIPLIER_Y");
157 TCLAP::ValueArg<double> multiZArg(
"",
"mz",
"multiplier in z direction",
158 false, 1,
"MULTIPLIER_Z");
160 TCLAP::ValueArg<double> originXArg(
161 "",
"ox",
"mesh origin (lower left corner) in x direction",
false, 0,
164 TCLAP::ValueArg<double> originYArg(
165 "",
"oy",
"mesh origin (lower left corner) in y direction",
false, 0,
168 TCLAP::ValueArg<double> originZArg(
169 "",
"oz",
"mesh origin (lower left corner) in z direction",
false, 0,
175 cmd.add(log_level_arg);
176 cmd.parse(argc, argv);
180 const std::string eleTypeName(eleTypeArg.getValue());
185 bool dim_used[3] = {
false};
186 for (
unsigned i = 0; i < dim; i++)
191 std::vector<TCLAP::ValueArg<double>*> vec_lengthArg = {
192 &lengthXArg, &lengthYArg, &lengthZArg};
193 std::vector<TCLAP::ValueArg<unsigned>*> vec_ndivArg = {
194 &nsubdivXArg, &nsubdivYArg, &nsubdivZArg};
195 std::vector<TCLAP::ValueArg<double>*> vec_d0Arg = {&d0XArg, &d0YArg,
197 std::vector<TCLAP::ValueArg<double>*> vec_dMaxArg = {&dmaxXArg, &dmaxYArg,
199 std::vector<TCLAP::ValueArg<double>*> vec_multiArg = {
200 &multiXArg, &multiYArg, &multiZArg};
202 {originXArg.getValue(), originYArg.getValue(), originZArg.getValue()});
204 const bool isLengthSet =
205 std::any_of(vec_lengthArg.begin(), vec_lengthArg.end(),
206 [&](TCLAP::ValueArg<double>* arg) { return arg->isSet(); });
209 ERR(
"Missing input: Length information is not provided at all.");
212 for (
unsigned i = 0; i < 3; i++)
214 if (dim_used[i] && !vec_lengthArg[i]->isSet())
216 ERR(
"Missing input: Length for dimension [{:d}] is required but "
223 std::vector<double> length(dim);
224 std::vector<unsigned> n_subdivision(dim);
225 std::vector<double> vec_dx(dim);
226 for (
unsigned i = 0; i < dim; i++)
228 length[i] = vec_lengthArg[i]->getValue();
229 n_subdivision[i] = vec_ndivArg[i]->getValue();
230 vec_dx[i] = length[i] / n_subdivision[i];
233 std::vector<std::unique_ptr<BaseLib::ISubdivision>> vec_div;
234 vec_div.reserve(dim);
235 for (
unsigned i = 0; i < dim; i++)
237 if (vec_multiArg[i]->isSet())
239 if (vec_ndivArg[i]->isSet())
242 if (vec_d0Arg[i]->isSet())
245 "Specifying all of --m?, --d?0 and --n? for coordinate "
246 "'?' is not supported.");
249 length[i], vec_ndivArg[i]->
getValue(),
255 length[i], vec_d0Arg[i]->
getValue(),
261 vec_div.emplace_back(
267 std::unique_ptr<MeshLib::Mesh> mesh;
272 *vec_div[0], origin));
276 *vec_div[0], *vec_div[1], origin));
280 *vec_div[0], *vec_div[1], origin));
284 *vec_div[0], *vec_div[1], *vec_div[2], origin));
288 length[0], length[1], length[2], n_subdivision[0],
289 n_subdivision[1], n_subdivision[2], origin));
293 *vec_div[0], *vec_div[1], *vec_div[2], origin));
297 *vec_div[0], *vec_div[1], *vec_div[2], origin));
300 ERR(
"Given element type is not supported.");
306 INFO(
"Mesh created: {:d} nodes, {:d} elements.",
307 mesh->getNumberOfNodes(), mesh->getNumberOfElements());
311 *(mesh.get()), std::filesystem::path(mesh_out.getValue()));