10 #include <tclap/CmdLine.h>
55 int main(
int argc,
char* argv[])
58 "Structured mesh generator.\n"
59 "The documentation is available at "
60 "https://docs.opengeosys.org/docs/tools/meshing/"
61 "structured-mesh-generation.\n\n"
62 "OpenGeoSys-6 software, version " +
65 "Copyright (c) 2012-2021, OpenGeoSys Community "
66 "(http://www.opengeosys.org)",
69 auto tclapOutput = std::make_unique<BaseLib::TCLAPCustomOutput>();
70 cmd.setOutput(tclapOutput.get());
72 std::vector<std::string> allowed_ele_types;
73 allowed_ele_types.emplace_back(
"line");
74 allowed_ele_types.emplace_back(
"tri");
75 allowed_ele_types.emplace_back(
"quad");
76 allowed_ele_types.emplace_back(
"hex");
77 allowed_ele_types.emplace_back(
"prism");
78 allowed_ele_types.emplace_back(
"tet");
79 allowed_ele_types.emplace_back(
"pyramid");
80 TCLAP::ValuesConstraint<std::string> allowedVals(allowed_ele_types);
81 TCLAP::ValueArg<std::string> eleTypeArg(
83 "element type to be created: line | tri | quad | hex | prism | tet | "
85 true,
"line", &allowedVals);
87 TCLAP::ValueArg<std::string> mesh_out(
88 "o",
"mesh-output-file",
89 "the name of the file the mesh will be written to",
true,
"",
90 "file name of output mesh");
92 TCLAP::ValueArg<double> lengthXArg(
93 "",
"lx",
"length of a domain in x direction",
false, 10.0,
"real");
95 TCLAP::ValueArg<double> lengthYArg(
96 "",
"ly",
"length of a domain in y direction",
false, 10.0,
"real");
98 TCLAP::ValueArg<double> lengthZArg(
99 "",
"lz",
"length of a domain in z direction",
false, 10.0,
"real");
101 TCLAP::ValueArg<unsigned> nsubdivXArg(
102 "",
"nx",
"the number of subdivision in x direction",
false, 10,
104 cmd.add(nsubdivXArg);
105 TCLAP::ValueArg<unsigned> nsubdivYArg(
106 "",
"ny",
"the number of subdivision in y direction",
false, 10,
108 cmd.add(nsubdivYArg);
109 TCLAP::ValueArg<unsigned> nsubdivZArg(
110 "",
"nz",
"the number of subdivision in z direction",
false, 10,
112 cmd.add(nsubdivZArg);
114 TCLAP::ValueArg<double> d0XArg(
115 "",
"dx0",
"initial cell length in x direction",
false, 1,
"real");
117 TCLAP::ValueArg<double> d0YArg(
118 "",
"dy0",
"initial cell length in y direction",
false, 1,
"real");
120 TCLAP::ValueArg<double> d0ZArg(
121 "",
"dz0",
"initial cell length in z direction",
false, 1,
"real");
123 TCLAP::ValueArg<double> dmaxXArg(
124 "",
"dx-max",
"maximum cell length in x direction",
false,
125 std::numeric_limits<double>::max(),
"real");
127 TCLAP::ValueArg<double> dmaxYArg(
128 "",
"dy-max",
"maximum cell length in y direction",
false,
129 std::numeric_limits<double>::max(),
"real");
131 TCLAP::ValueArg<double> dmaxZArg(
132 "",
"dz-max",
"maximum cell length in z direction",
false,
133 std::numeric_limits<double>::max(),
"real");
135 TCLAP::ValueArg<double> multiXArg(
"",
"mx",
"multiplier in x direction",
138 TCLAP::ValueArg<double> multiYArg(
"",
"my",
"multiplier in y direction",
141 TCLAP::ValueArg<double> multiZArg(
"",
"mz",
"multiplier in z direction",
146 cmd.parse(argc, argv);
147 const std::string eleTypeName(eleTypeArg.getValue());
152 bool dim_used[3] = {
false};
153 for (
unsigned i = 0; i < dim; i++)
158 std::vector<TCLAP::ValueArg<double>*> vec_lengthArg = {
159 &lengthXArg, &lengthYArg, &lengthZArg};
160 std::vector<TCLAP::ValueArg<unsigned>*> vec_ndivArg = {
161 &nsubdivXArg, &nsubdivYArg, &nsubdivZArg};
162 std::vector<TCLAP::ValueArg<double>*> vec_d0Arg = {&d0XArg, &d0YArg,
164 std::vector<TCLAP::ValueArg<double>*> vec_dMaxArg = {&dmaxXArg, &dmaxYArg,
166 std::vector<TCLAP::ValueArg<double>*> vec_multiArg = {
167 &multiXArg, &multiYArg, &multiZArg};
169 const bool isLengthSet =
170 std::any_of(vec_lengthArg.begin(), vec_lengthArg.end(),
171 [&](TCLAP::ValueArg<double>* arg) { return arg->isSet(); });
174 ERR(
"Missing input: Length information is not provided at all.");
177 for (
unsigned i = 0; i < 3; i++)
179 if (dim_used[i] && !vec_lengthArg[i]->isSet())
181 ERR(
"Missing input: Length for dimension [{:d}] is required but "
188 std::vector<double> length(dim);
189 std::vector<unsigned> n_subdivision(dim);
190 std::vector<double> vec_dx(dim);
191 for (
unsigned i = 0; i < dim; i++)
193 length[i] = vec_lengthArg[i]->getValue();
194 n_subdivision[i] = vec_ndivArg[i]->getValue();
195 vec_dx[i] = length[i] / n_subdivision[i];
198 std::vector<std::unique_ptr<BaseLib::ISubdivision>> vec_div;
199 vec_div.reserve(dim);
200 for (
unsigned i = 0; i < dim; i++)
202 if (vec_multiArg[i]->isSet())
204 if (vec_ndivArg[i]->isSet())
207 if (vec_d0Arg[i]->isSet())
210 "Specifying all of --m?, --d?0 and --n? for coordinate "
211 "'?' is not supported.");
214 length[i], vec_ndivArg[i]->
getValue(),
220 length[i], vec_d0Arg[i]->
getValue(),
226 vec_div.emplace_back(
232 std::unique_ptr<MeshLib::Mesh> mesh;
240 *vec_div[0], *vec_div[1]));
244 *vec_div[0], *vec_div[1]));
248 *vec_div[0], *vec_div[1], *vec_div[2]));
252 length[0], length[1], length[2], n_subdivision[0],
253 n_subdivision[1], n_subdivision[2]));
257 *vec_div[0], *vec_div[1], *vec_div[2]));
261 *vec_div[0], *vec_div[1], *vec_div[2]));
264 ERR(
"Given element type is not supported.");
270 INFO(
"Mesh created: {:d} nodes, {:d} elements.",
271 mesh->getNumberOfNodes(), mesh->getNumberOfElements());
275 *(mesh.get()), std::filesystem::path(mesh_out.getValue()));
Definition of the Element class.
void INFO(char const *fmt, Args const &... args)
void ERR(char const *fmt, Args const &... args)
Definition of mesh-related Enumerations.
Definition of the Mesh class.
Definition of the Node class.
int main(int argc, char *argv[])
GITINFOLIB_EXPORT const std::string ogs_version
int writeMeshToFile(const MeshLib::Mesh &mesh, std::filesystem::path const &file_path, [[maybe_unused]] std::set< std::string > variable_output_names)
Mesh * generateRegularPrismMesh(const double x_length, const double y_length, const double z_length, const std::size_t x_subdivision, const std::size_t y_subdivision, const std::size_t z_subdivision, MathLib::Point3d const &origin=MathLib::ORIGIN, std::string const &mesh_name="mesh")
Mesh * generateLineMesh(const BaseLib::ISubdivision &div, MathLib::Point3d const &origin=MathLib::ORIGIN, std::string const &mesh_name="mesh")
Mesh * generateRegularTriMesh(const BaseLib::ISubdivision &div_x, const BaseLib::ISubdivision &div_y, MathLib::Point3d const &origin=MathLib::ORIGIN, std::string const &mesh_name="mesh")
Mesh * generateRegularQuadMesh(const BaseLib::ISubdivision &div_x, const BaseLib::ISubdivision &div_y, MathLib::Point3d const &origin=MathLib::ORIGIN, std::string const &mesh_name="mesh")
Mesh * generateRegularPyramidMesh(const BaseLib::ISubdivision &div_x, const BaseLib::ISubdivision &div_y, const BaseLib::ISubdivision &div_z, MathLib::Point3d const &origin=MathLib::ORIGIN, std::string const &mesh_name="mesh")
Mesh * generateRegularTetMesh(const BaseLib::ISubdivision &div_x, const BaseLib::ISubdivision &div_y, const BaseLib::ISubdivision &div_z, MathLib::Point3d const &origin=MathLib::ORIGIN, std::string const &mesh_name="mesh")
Mesh * generateRegularHexMesh(const BaseLib::ISubdivision &div_x, const BaseLib::ISubdivision &div_y, const BaseLib::ISubdivision &div_z, MathLib::Point3d const &origin=MathLib::ORIGIN, std::string const &mesh_name="mesh")
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)