56int main(
int argc,
char* argv[])
59 "Structured mesh generator.\n"
60 "The documentation is available at "
61 "https://docs.opengeosys.org/docs/tools/meshing/"
62 "structured-mesh-generation.\n\n"
63 "OpenGeoSys-6 software, version " +
66 "Copyright (c) 2012-2025, OpenGeoSys Community "
67 "(http://www.opengeosys.org)",
70 std::vector<std::string> allowed_ele_types;
71 allowed_ele_types.emplace_back(
"line");
72 allowed_ele_types.emplace_back(
"tri");
73 allowed_ele_types.emplace_back(
"quad");
74 allowed_ele_types.emplace_back(
"hex");
75 allowed_ele_types.emplace_back(
"prism");
76 allowed_ele_types.emplace_back(
"tet");
77 allowed_ele_types.emplace_back(
"pyramid");
78 TCLAP::ValuesConstraint<std::string> allowedVals(allowed_ele_types);
79 TCLAP::ValueArg<std::string> eleTypeArg(
81 "element type to be created: line | tri | quad | hex | prism | tet | "
83 true,
"line", &allowedVals);
85 TCLAP::ValueArg<std::string> mesh_out(
86 "o",
"mesh-output-file",
87 "the name of the file the mesh will be written to",
true,
"",
88 "file name of output mesh");
90 TCLAP::ValueArg<double> lengthXArg(
91 "",
"lx",
"length of a domain in x direction",
false, 10.0,
"real");
93 TCLAP::ValueArg<double> lengthYArg(
94 "",
"ly",
"length of a domain in y direction",
false, 10.0,
"real");
96 TCLAP::ValueArg<double> lengthZArg(
97 "",
"lz",
"length of a domain in z direction",
false, 10.0,
"real");
99 TCLAP::ValueArg<unsigned> nsubdivXArg(
100 "",
"nx",
"the number of subdivision in x direction",
false, 10,
102 cmd.add(nsubdivXArg);
103 TCLAP::ValueArg<unsigned> nsubdivYArg(
104 "",
"ny",
"the number of subdivision in y direction",
false, 10,
106 cmd.add(nsubdivYArg);
107 TCLAP::ValueArg<unsigned> nsubdivZArg(
108 "",
"nz",
"the number of subdivision in z direction",
false, 10,
110 cmd.add(nsubdivZArg);
112 TCLAP::ValueArg<double> d0XArg(
113 "",
"dx0",
"initial cell length in x direction",
false, 1,
"real");
115 TCLAP::ValueArg<double> d0YArg(
116 "",
"dy0",
"initial cell length in y direction",
false, 1,
"real");
118 TCLAP::ValueArg<double> d0ZArg(
119 "",
"dz0",
"initial cell length in z direction",
false, 1,
"real");
121 TCLAP::ValueArg<double> dmaxXArg(
122 "",
"dx-max",
"maximum cell length in x direction",
false,
123 std::numeric_limits<double>::max(),
"real");
125 TCLAP::ValueArg<double> dmaxYArg(
126 "",
"dy-max",
"maximum cell length in y direction",
false,
127 std::numeric_limits<double>::max(),
"real");
129 TCLAP::ValueArg<double> dmaxZArg(
130 "",
"dz-max",
"maximum cell length in z direction",
false,
131 std::numeric_limits<double>::max(),
"real");
133 TCLAP::ValueArg<double> multiXArg(
"",
"mx",
"multiplier in x direction",
136 TCLAP::ValueArg<double> multiYArg(
"",
"my",
"multiplier in y direction",
139 TCLAP::ValueArg<double> multiZArg(
"",
"mz",
"multiplier in z direction",
142 TCLAP::ValueArg<double> originXArg(
143 "",
"ox",
"mesh origin (lower left corner) in x direction",
false, 0,
146 TCLAP::ValueArg<double> originYArg(
147 "",
"oy",
"mesh origin (lower left corner) in y direction",
false, 0,
150 TCLAP::ValueArg<double> originZArg(
151 "",
"oz",
"mesh origin (lower left corner) in z direction",
false, 0,
156 cmd.parse(argc, argv);
158 const std::string eleTypeName(eleTypeArg.getValue());
163 bool dim_used[3] = {
false};
164 for (
unsigned i = 0; i < dim; i++)
169 std::vector<TCLAP::ValueArg<double>*> vec_lengthArg = {
170 &lengthXArg, &lengthYArg, &lengthZArg};
171 std::vector<TCLAP::ValueArg<unsigned>*> vec_ndivArg = {
172 &nsubdivXArg, &nsubdivYArg, &nsubdivZArg};
173 std::vector<TCLAP::ValueArg<double>*> vec_d0Arg = {&d0XArg, &d0YArg,
175 std::vector<TCLAP::ValueArg<double>*> vec_dMaxArg = {&dmaxXArg, &dmaxYArg,
177 std::vector<TCLAP::ValueArg<double>*> vec_multiArg = {
178 &multiXArg, &multiYArg, &multiZArg};
180 {originXArg.getValue(), originYArg.getValue(), originZArg.getValue()});
182 const bool isLengthSet =
183 std::any_of(vec_lengthArg.begin(), vec_lengthArg.end(),
184 [&](TCLAP::ValueArg<double>* arg) { return arg->isSet(); });
187 ERR(
"Missing input: Length information is not provided at all.");
190 for (
unsigned i = 0; i < 3; i++)
192 if (dim_used[i] && !vec_lengthArg[i]->isSet())
194 ERR(
"Missing input: Length for dimension [{:d}] is required but "
201 std::vector<double> length(dim);
202 std::vector<unsigned> n_subdivision(dim);
203 std::vector<double> vec_dx(dim);
204 for (
unsigned i = 0; i < dim; i++)
206 length[i] = vec_lengthArg[i]->getValue();
207 n_subdivision[i] = vec_ndivArg[i]->getValue();
208 vec_dx[i] = length[i] / n_subdivision[i];
211 std::vector<std::unique_ptr<BaseLib::ISubdivision>> vec_div;
212 vec_div.reserve(dim);
213 for (
unsigned i = 0; i < dim; i++)
215 if (vec_multiArg[i]->isSet())
217 if (vec_ndivArg[i]->isSet())
220 if (vec_d0Arg[i]->isSet())
223 "Specifying all of --m?, --d?0 and --n? for coordinate "
224 "'?' is not supported.");
227 length[i], vec_ndivArg[i]->
getValue(),
233 length[i], vec_d0Arg[i]->
getValue(),
239 vec_div.emplace_back(
245 std::unique_ptr<MeshLib::Mesh> mesh;
250 *vec_div[0], origin));
254 *vec_div[0], *vec_div[1], origin));
258 *vec_div[0], *vec_div[1], origin));
262 *vec_div[0], *vec_div[1], *vec_div[2], origin));
266 length[0], length[1], length[2], n_subdivision[0],
267 n_subdivision[1], n_subdivision[2], origin));
271 *vec_div[0], *vec_div[1], *vec_div[2], origin));
275 *vec_div[0], *vec_div[1], *vec_div[2], origin));
278 ERR(
"Given element type is not supported.");
284 INFO(
"Mesh created: {:d} nodes, {:d} elements.",
285 mesh->getNumberOfNodes(), mesh->getNumberOfElements());
289 *(mesh.get()), std::filesystem::path(mesh_out.getValue()));