57{
58 TCLAP::CmdLine cmd(
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 " +
65 ".\n"
66 "Copyright (c) 2012-2025, OpenGeoSys Community "
67 "(http://www.opengeosys.org)",
69
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(
80 "e", "element-type",
81 "element type to be created: line | tri | quad | hex | prism | tet | "
82 "pyramid",
83 true, "line", &allowedVals);
84 cmd.add(eleTypeArg);
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");
89 cmd.add(mesh_out);
90 TCLAP::ValueArg<double> lengthXArg(
91 "", "lx", "length of a domain in x direction", false, 10.0, "real");
92 cmd.add(lengthXArg);
93 TCLAP::ValueArg<double> lengthYArg(
94 "", "ly", "length of a domain in y direction", false, 10.0, "real");
95 cmd.add(lengthYArg);
96 TCLAP::ValueArg<double> lengthZArg(
97 "", "lz", "length of a domain in z direction", false, 10.0, "real");
98 cmd.add(lengthZArg);
99 TCLAP::ValueArg<unsigned> nsubdivXArg(
100 "", "nx", "the number of subdivision in x direction", false, 10,
101 "integer");
102 cmd.add(nsubdivXArg);
103 TCLAP::ValueArg<unsigned> nsubdivYArg(
104 "", "ny", "the number of subdivision in y direction", false, 10,
105 "integer");
106 cmd.add(nsubdivYArg);
107 TCLAP::ValueArg<unsigned> nsubdivZArg(
108 "", "nz", "the number of subdivision in z direction", false, 10,
109 "integer");
110 cmd.add(nsubdivZArg);
111
112 TCLAP::ValueArg<double> d0XArg(
113 "", "dx0", "initial cell length in x direction", false, 1, "real");
114 cmd.add(d0XArg);
115 TCLAP::ValueArg<double> d0YArg(
116 "", "dy0", "initial cell length in y direction", false, 1, "real");
117 cmd.add(d0YArg);
118 TCLAP::ValueArg<double> d0ZArg(
119 "", "dz0", "initial cell length in z direction", false, 1, "real");
120 cmd.add(d0ZArg);
121 TCLAP::ValueArg<double> dmaxXArg(
122 "", "dx-max", "maximum cell length in x direction", false,
123 std::numeric_limits<double>::max(), "real");
124 cmd.add(dmaxXArg);
125 TCLAP::ValueArg<double> dmaxYArg(
126 "", "dy-max", "maximum cell length in y direction", false,
127 std::numeric_limits<double>::max(), "real");
128 cmd.add(dmaxYArg);
129 TCLAP::ValueArg<double> dmaxZArg(
130 "", "dz-max", "maximum cell length in z direction", false,
131 std::numeric_limits<double>::max(), "real");
132 cmd.add(dmaxZArg);
133 TCLAP::ValueArg<double> multiXArg("", "mx", "multiplier in x direction",
134 false, 1, "real");
135 cmd.add(multiXArg);
136 TCLAP::ValueArg<double> multiYArg("", "my", "multiplier in y direction",
137 false, 1, "real");
138 cmd.add(multiYArg);
139 TCLAP::ValueArg<double> multiZArg("", "mz", "multiplier in z direction",
140 false, 1, "real");
141 cmd.add(multiZArg);
142 TCLAP::ValueArg<double> originXArg(
143 "", "ox", "mesh origin (lower left corner) in x direction", false, 0,
144 "real");
145 cmd.add(originXArg);
146 TCLAP::ValueArg<double> originYArg(
147 "", "oy", "mesh origin (lower left corner) in y direction", false, 0,
148 "real");
149 cmd.add(originYArg);
150 TCLAP::ValueArg<double> originZArg(
151 "", "oz", "mesh origin (lower left corner) in z direction", false, 0,
152 "real");
153 cmd.add(originZArg);
154
155
156 cmd.parse(argc, argv);
158 const std::string eleTypeName(eleTypeArg.getValue());
162
163 bool dim_used[3] = {false};
164 for (unsigned i = 0; i < dim; i++)
165 {
166 dim_used[i] = true;
167 }
168
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,
174 &d0ZArg};
175 std::vector<TCLAP::ValueArg<double>*> vec_dMaxArg = {&dmaxXArg, &dmaxYArg,
176 &dmaxZArg};
177 std::vector<TCLAP::ValueArg<double>*> vec_multiArg = {
178 &multiXArg, &multiYArg, &multiZArg};
180 {originXArg.getValue(), originYArg.getValue(), originZArg.getValue()});
181
182 const bool isLengthSet =
183 std::any_of(vec_lengthArg.begin(), vec_lengthArg.end(),
184 [&](TCLAP::ValueArg<double>* arg) { return arg->isSet(); });
185 if (!isLengthSet)
186 {
187 ERR(
"Missing input: Length information is not provided at all.");
188 return EXIT_FAILURE;
189 }
190 for (unsigned i = 0; i < 3; i++)
191 {
192 if (dim_used[i] && !vec_lengthArg[i]->isSet())
193 {
194 ERR(
"Missing input: Length for dimension [{:d}] is required but "
195 "missing.",
196 i);
197 return EXIT_FAILURE;
198 }
199 }
200
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++)
205 {
206 length[i] = vec_lengthArg[i]->getValue();
207 n_subdivision[i] = vec_ndivArg[i]->getValue();
208 vec_dx[i] = length[i] / n_subdivision[i];
209 }
210
211 std::vector<std::unique_ptr<BaseLib::ISubdivision>> vec_div;
212 vec_div.reserve(dim);
213 for (unsigned i = 0; i < dim; i++)
214 {
215 if (vec_multiArg[i]->isSet())
216 {
217 if (vec_ndivArg[i]->isSet())
218 {
219
220 if (vec_d0Arg[i]->isSet())
221 {
223 "Specifying all of --m?, --d?0 and --n? for coordinate "
224 "'?' is not supported.");
225 }
227 length[i], vec_ndivArg[i]->
getValue(),
229 }
230 else
231 {
233 length[i], vec_d0Arg[i]->
getValue(),
235 }
236 }
237 else
238 {
239 vec_div.emplace_back(
241 }
242 }
243
244
245 std::unique_ptr<MeshLib::Mesh> mesh;
246 switch (eleType)
247 {
250 *vec_div[0], origin));
251 break;
254 *vec_div[0], *vec_div[1], origin));
255 break;
258 *vec_div[0], *vec_div[1], origin));
259 break;
262 *vec_div[0], *vec_div[1], *vec_div[2], origin));
263 break;
266 length[0], length[1], length[2], n_subdivision[0],
267 n_subdivision[1], n_subdivision[2], origin));
268 break;
271 *vec_div[0], *vec_div[1], *vec_div[2], origin));
272 break;
275 *vec_div[0], *vec_div[1], *vec_div[2], origin));
276 break;
277 default:
278 ERR(
"Given element type is not supported.");
279 break;
280 }
281
282 if (mesh)
283 {
284 INFO(
"Mesh created: {:d} nodes, {:d} elements.",
285 mesh->getNumberOfNodes(), mesh->getNumberOfElements());
286
287
289 *(mesh.get()), std::filesystem::path(mesh_out.getValue()));
290 }
291
292 return EXIT_SUCCESS;
293}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
GITINFOLIB_EXPORT const std::string ogs_version
int writeMeshToFile(const MeshLib::Mesh &mesh, std::filesystem::path const &file_path, std::set< std::string > variable_output_names)
MeshElemType String2MeshElemType(const std::string &s)
Given a string of the shortened name of the element type, this returns the corresponding MeshElemType...
MeshElemType
Types of mesh elements supported by OpenGeoSys. Values are from VTKCellType enum.
unsigned getDimension(MeshLib::MeshElemType eleType)