84int main(
int argc,
char* argv[])
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 " +
94 "Copyright (c) 2012-2025, OpenGeoSys Community "
95 "(http://www.opengeosys.org)",
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");
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");
110 TCLAP::ValueArg<double> yLargeArg(
111 "",
"y-max",
"largest allowed extent in y-dimension",
false,
112 std::numeric_limits<double>::max(),
"MAX_EXTENT_Y");
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");
118 TCLAP::ValueArg<double> xLargeArg(
119 "",
"x-max",
"largest allowed extent in x-dimension",
false,
120 std::numeric_limits<double>::max(),
"MAX_EXTENT_X");
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");
128 TCLAP::SwitchArg zveArg(
"z",
"zero-volume",
"remove zero volume elements",
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);
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);
145 TCLAP::MultiArg<int> property_arg(
146 "",
"property-value",
"value of selected property to be removed",
false,
148 cmd.add(property_arg);
150 TCLAP::ValueArg<double> min_property_arg(
151 "",
"min-value",
"minimum value of range for selected property",
false,
153 cmd.add(min_property_arg);
155 TCLAP::ValueArg<double> max_property_arg(
156 "",
"max-value",
"maximum value of range for selected property",
false,
158 cmd.add(max_property_arg);
160 TCLAP::SwitchArg outside_property_arg(
161 "",
"outside",
"remove all elements outside the given property range");
162 cmd.add(outside_property_arg);
164 TCLAP::SwitchArg inside_property_arg(
165 "",
"inside",
"remove all elements inside the given property range");
166 cmd.add(inside_property_arg);
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,
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,
180 cmd.add(log_level_arg);
181 cmd.parse(argc, argv);
186 std::unique_ptr<MeshLib::Mesh const> mesh(
193 INFO(
"Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
194 mesh->getNumberOfElements());
202 if (eleTypeArg.isSet())
204 const std::vector<std::string> eleTypeNames = eleTypeArg.getValue();
205 for (
const auto& typeName : eleTypeNames)
213 INFO(
"{:d} {:s} elements found.",
218 if (property_name_arg.isSet() || property_arg.isSet() ||
219 min_property_arg.isSet() || max_property_arg.isSet())
221 if ((property_arg.isSet() || min_property_arg.isSet() ||
222 max_property_arg.isSet()) &&
223 !property_name_arg.isSet())
225 ERR(
"Specify a property name for the value/range selected.");
229 if (property_name_arg.isSet() &&
230 !((min_property_arg.isSet() && max_property_arg.isSet()) ||
231 property_arg.isSet()))
233 ERR(
"Specify a value or range ('-min-value' and '-max_value') for "
234 "the property selected.");
239 if (property_arg.isSet() && property_name_arg.isSet())
242 property_arg.getValue(), searcher);
246 if (property_name_arg.isSet() && min_property_arg.isSet() &&
247 max_property_arg.isSet())
249 if ((!outside_property_arg.isSet() &&
250 !inside_property_arg.isSet()) ||
251 (outside_property_arg.isSet() && inside_property_arg.isSet()))
253 ERR(
"Specify if the inside or the outside of the selected "
254 "range should be removed.");
258 bool const outside = outside_property_arg.isSet();
260 property_name_arg.getValue(), min_property_arg.getValue(),
261 max_property_arg.getValue(), outside, searcher);
265 if (xSmallArg.isSet() || xLargeArg.isSet() || ySmallArg.isSet() ||
266 yLargeArg.isSet() || zSmallArg.isSet() || zLargeArg.isSet())
269 bool aabb_error(
false);
270 if (xSmallArg.getValue() >= xLargeArg.getValue())
272 ERR(
"Minimum x-extent larger than maximum x-extent.");
275 if (ySmallArg.getValue() >= yLargeArg.getValue())
277 ERR(
"Minimum y-extent larger than maximum y-extent.");
280 if (zSmallArg.getValue() >= zLargeArg.getValue())
282 ERR(
"Minimum z-extent larger than maximum z-extent.");
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.",
300 invert_bounding_box_arg.getValue()));
307 if (new_mesh ==
nullptr)