85{
86 TCLAP::CmdLine cmd(
87 "Removes mesh elements based on element type, element volume, scalar "
88 "arrays, or bounding box . The documentation is available at "
89 "https://docs.opengeosys.org/docs/tools/meshing/"
90 "remove-mesh-elements.\n\n"
91 "OpenGeoSys-6 software, version " +
93 ".\n"
94 "Copyright (c) 2012-2025, OpenGeoSys Community "
95 "(http://www.opengeosys.org)",
97
98
99 TCLAP::SwitchArg invert_bounding_box_arg(
100 "", "invert", "inverts the specified bounding box", false);
101 cmd.add(invert_bounding_box_arg);
102 TCLAP::ValueArg<double> zLargeArg(
103 "", "z-max", "largest allowed extent in z-dimension", false,
104 std::numeric_limits<double>::max(), "MAX_EXTENT_Z");
105 cmd.add(zLargeArg);
106 TCLAP::ValueArg<double> zSmallArg(
107 "", "z-min", "smallest allowed extent in z-dimension", false,
108 -1 * std::numeric_limits<double>::max(), "MIN_EXTENT_Z");
109 cmd.add(zSmallArg);
110 TCLAP::ValueArg<double> yLargeArg(
111 "", "y-max", "largest allowed extent in y-dimension", false,
112 std::numeric_limits<double>::max(), "MAX_EXTENT_Y");
113 cmd.add(yLargeArg);
114 TCLAP::ValueArg<double> ySmallArg(
115 "", "y-min", "smallest allowed extent in y-dimension", false,
116 -1 * std::numeric_limits<double>::max(), "MIN_EXTENT_Y");
117 cmd.add(ySmallArg);
118 TCLAP::ValueArg<double> xLargeArg(
119 "", "x-max", "largest allowed extent in x-dimension", false,
120 std::numeric_limits<double>::max(), "MAX_EXTENT_X");
121 cmd.add(xLargeArg);
122 TCLAP::ValueArg<double> xSmallArg(
123 "", "x-min", "smallest allowed extent in x-dimension", false,
124 -1 * std::numeric_limits<double>::max(), "MIN_EXTENT_X");
125 cmd.add(xSmallArg);
126
127
128 TCLAP::SwitchArg zveArg("z", "zero-volume", "remove zero volume elements",
129 false);
130 cmd.add(zveArg);
131
132 std::vector<std::string> allowed_ele_types{
133 "point", "line", "tri", "quad", "hex", "prism", "tet", "pyramid"};
134 TCLAP::ValuesConstraint<std::string> allowedVals{allowed_ele_types};
135 TCLAP::MultiArg<std::string> eleTypeArg(
136 "t", "element-type", "element type to be removed", false, &allowedVals);
137 cmd.add(eleTypeArg);
138
139
140 TCLAP::ValueArg<std::string> property_name_arg(
141 "n", "property-name", "name of property in the mesh", false,
142 "MaterialIDs", "PROPERTY_NAME");
143 cmd.add(property_name_arg);
144
145 TCLAP::MultiArg<int> property_arg(
146 "", "property-value", "value of selected property to be removed", false,
147 "PROPERTY_VALUE");
148 cmd.add(property_arg);
149
150 TCLAP::ValueArg<double> min_property_arg(
151 "", "min-value", "minimum value of range for selected property", false,
152 0, "MIN_RANGE");
153 cmd.add(min_property_arg);
154
155 TCLAP::ValueArg<double> max_property_arg(
156 "", "max-value", "maximum value of range for selected property", false,
157 0, "MAX_RANGE");
158 cmd.add(max_property_arg);
159
160 TCLAP::SwitchArg outside_property_arg(
161 "", "outside", "remove all elements outside the given property range");
162 cmd.add(outside_property_arg);
163
164 TCLAP::SwitchArg inside_property_arg(
165 "", "inside", "remove all elements inside the given property range");
166 cmd.add(inside_property_arg);
167
168
169 TCLAP::ValueArg<std::string> mesh_out(
170 "o", "mesh-output-file",
171 "Output (.vtu). The name of the file the mesh will be written to", true,
172 "", "OUTPUT_FILE");
173 cmd.add(mesh_out);
174 TCLAP::ValueArg<std::string> mesh_in(
175 "i", "mesh-input-file",
176 "Input (.vtu). The name of the file containing the input mesh", true,
177 "", "INPUT_FILE");
178 cmd.add(mesh_in);
180 cmd.add(log_level_arg);
181 cmd.parse(argc, argv);
182
185
186 std::unique_ptr<MeshLib::Mesh const> mesh(
188 if (mesh == nullptr)
189 {
190 return EXIT_FAILURE;
191 }
192
193 INFO(
"Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
194 mesh->getNumberOfElements());
196
197
198 if (zveArg.isSet())
199 {
200 INFO(
"{:d} zero volume elements found.", searcher.searchByContent());
201 }
202 if (eleTypeArg.isSet())
203 {
204 const std::vector<std::string> eleTypeNames = eleTypeArg.getValue();
205 for (const auto& typeName : eleTypeNames)
206 {
210 {
211 continue;
212 }
213 INFO(
"{:d} {:s} elements found.",
214 searcher.searchByElementType(type), typeName);
215 }
216 }
217
218 if (property_name_arg.isSet() || property_arg.isSet() ||
219 min_property_arg.isSet() || max_property_arg.isSet())
220 {
221 if ((property_arg.isSet() || min_property_arg.isSet() ||
222 max_property_arg.isSet()) &&
223 !property_name_arg.isSet())
224 {
225 ERR(
"Specify a property name for the value/range selected.");
226 return EXIT_FAILURE;
227 }
228
229 if (property_name_arg.isSet() &&
230 !((min_property_arg.isSet() && max_property_arg.isSet()) ||
231 property_arg.isSet()))
232 {
233 ERR(
"Specify a value or range ('-min-value' and '-max_value') for "
234 "the property selected.");
235 return EXIT_FAILURE;
236 }
237
238
239 if (property_arg.isSet() && property_name_arg.isSet())
240 {
242 property_arg.getValue(), searcher);
243 }
244
245
246 if (property_name_arg.isSet() && min_property_arg.isSet() &&
247 max_property_arg.isSet())
248 {
249 if ((!outside_property_arg.isSet() &&
250 !inside_property_arg.isSet()) ||
251 (outside_property_arg.isSet() && inside_property_arg.isSet()))
252 {
253 ERR(
"Specify if the inside or the outside of the selected "
254 "range should be removed.");
255 return EXIT_FAILURE;
256 }
257
258 bool const outside = outside_property_arg.isSet();
260 property_name_arg.getValue(), min_property_arg.getValue(),
261 max_property_arg.getValue(), outside, searcher);
262 }
263 }
264
265 if (xSmallArg.isSet() || xLargeArg.isSet() || ySmallArg.isSet() ||
266 yLargeArg.isSet() || zSmallArg.isSet() || zLargeArg.isSet())
267 {
269 bool aabb_error(false);
270 if (xSmallArg.getValue() >= xLargeArg.getValue())
271 {
272 ERR(
"Minimum x-extent larger than maximum x-extent.");
273 aabb_error = true;
274 }
275 if (ySmallArg.getValue() >= yLargeArg.getValue())
276 {
277 ERR(
"Minimum y-extent larger than maximum y-extent.");
278 aabb_error = true;
279 }
280 if (zSmallArg.getValue() >= zLargeArg.getValue())
281 {
282 ERR(
"Minimum z-extent larger than maximum z-extent.");
283 aabb_error = true;
284 }
285 if (aabb_error)
286 {
287 return EXIT_FAILURE;
288 }
289
290 std::array<MathLib::Point3d, 2> extent(
292 ySmallArg.getValue(),
293 zSmallArg.getValue()}}),
295 {xLargeArg.getValue(), yLargeArg.getValue(),
296 zLargeArg.getValue()}})}});
297 INFO(
"{:d} elements found.",
298 searcher.searchByBoundingBox(
300 invert_bounding_box_arg.getValue()));
301 }
302
303
305 *mesh, searcher.getSearchedElementIDs(), mesh->getName()));
306
307 if (new_mesh == nullptr)
308 {
309 return EXIT_FAILURE;
310 }
311
312
314
315 return EXIT_SUCCESS;
316}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Class AABB is an axis aligned bounding box around a given set of geometric points of (template) type ...
TCLAP::ValueArg< std::string > makeLogLevelArg()
void initOGSLogger(std::string const &log_level)
GITINFOLIB_EXPORT const std::string ogs_version
MeshLib::Mesh * readMeshFromFile(const std::string &file_name, bool const compute_element_neighbors)
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.
void outputAABB(MeshLib::Mesh const &mesh)
void searchByPropertyValue(std::string const &property_name, std::vector< PROPERTY_TYPE > const &property_values, MeshLib::ElementSearch &searcher)
void searchByPropertyRange(std::string const &property_name, double const &min_value, double const &max_value, bool const &outside, MeshLib::ElementSearch &searcher)