74int main(
int argc,
char* argv[])
77 "Removes mesh elements based on element type, element volume, scalar "
78 "arrays, or bounding box . The documentation is available at "
79 "https://docs.opengeosys.org/docs/tools/meshing/"
80 "remove-mesh-elements.\n\n"
81 "OpenGeoSys-6 software, version " +
84 "Copyright (c) 2012-2026, OpenGeoSys Community "
85 "(http://www.opengeosys.org)",
89 TCLAP::SwitchArg invert_bounding_box_arg(
90 "",
"invert",
"inverts the specified bounding box",
false);
91 cmd.add(invert_bounding_box_arg);
92 TCLAP::ValueArg<double> zLargeArg(
93 "",
"z-max",
"largest allowed extent in z-dimension",
false,
94 std::numeric_limits<double>::max(),
"MAX_EXTENT_Z");
96 TCLAP::ValueArg<double> zSmallArg(
97 "",
"z-min",
"smallest allowed extent in z-dimension",
false,
98 -1 * std::numeric_limits<double>::max(),
"MIN_EXTENT_Z");
100 TCLAP::ValueArg<double> yLargeArg(
101 "",
"y-max",
"largest allowed extent in y-dimension",
false,
102 std::numeric_limits<double>::max(),
"MAX_EXTENT_Y");
104 TCLAP::ValueArg<double> ySmallArg(
105 "",
"y-min",
"smallest allowed extent in y-dimension",
false,
106 -1 * std::numeric_limits<double>::max(),
"MIN_EXTENT_Y");
108 TCLAP::ValueArg<double> xLargeArg(
109 "",
"x-max",
"largest allowed extent in x-dimension",
false,
110 std::numeric_limits<double>::max(),
"MAX_EXTENT_X");
112 TCLAP::ValueArg<double> xSmallArg(
113 "",
"x-min",
"smallest allowed extent in x-dimension",
false,
114 -1 * std::numeric_limits<double>::max(),
"MIN_EXTENT_X");
118 TCLAP::SwitchArg zveArg(
"z",
"zero-volume",
"remove zero volume elements",
122 std::vector<std::string> allowed_ele_types{
123 "point",
"line",
"tri",
"quad",
"hex",
"prism",
"tet",
"pyramid"};
124 TCLAP::ValuesConstraint<std::string> allowedVals{allowed_ele_types};
125 TCLAP::MultiArg<std::string> eleTypeArg(
126 "t",
"element-type",
"element type to be removed",
false, &allowedVals);
130 TCLAP::ValueArg<std::string> property_name_arg(
131 "n",
"property-name",
"name of property in the mesh",
false,
132 "MaterialIDs",
"PROPERTY_NAME");
133 cmd.add(property_name_arg);
135 TCLAP::MultiArg<int> property_arg(
136 "",
"property-value",
"value of selected property to be removed",
false,
138 cmd.add(property_arg);
140 TCLAP::ValueArg<double> min_property_arg(
141 "",
"min-value",
"minimum value of range for selected property",
false,
143 cmd.add(min_property_arg);
145 TCLAP::ValueArg<double> max_property_arg(
146 "",
"max-value",
"maximum value of range for selected property",
false,
148 cmd.add(max_property_arg);
150 TCLAP::SwitchArg outside_property_arg(
151 "",
"outside",
"remove all elements outside the given property range");
152 cmd.add(outside_property_arg);
154 TCLAP::SwitchArg inside_property_arg(
155 "",
"inside",
"remove all elements inside the given property range");
156 cmd.add(inside_property_arg);
159 TCLAP::ValueArg<std::string> mesh_out(
160 "o",
"mesh-output-file",
161 "Output (.vtu). The name of the file the mesh will be written to",
true,
164 TCLAP::ValueArg<std::string> mesh_in(
165 "i",
"mesh-input-file",
166 "Input (.vtu). The name of the file containing the input mesh",
true,
170 cmd.add(log_level_arg);
171 cmd.parse(argc, argv);
176 std::unique_ptr<MeshLib::Mesh const> mesh(
183 INFO(
"Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
184 mesh->getNumberOfElements());
192 if (eleTypeArg.isSet())
194 const std::vector<std::string> eleTypeNames = eleTypeArg.getValue();
195 for (
const auto& typeName : eleTypeNames)
203 INFO(
"{:d} {:s} elements found.",
208 if (property_name_arg.isSet() || property_arg.isSet() ||
209 min_property_arg.isSet() || max_property_arg.isSet())
211 if ((property_arg.isSet() || min_property_arg.isSet() ||
212 max_property_arg.isSet()) &&
213 !property_name_arg.isSet())
215 ERR(
"Specify a property name for the value/range selected.");
219 if (property_name_arg.isSet() &&
220 !((min_property_arg.isSet() && max_property_arg.isSet()) ||
221 property_arg.isSet()))
223 ERR(
"Specify a value or range ('-min-value' and '-max_value') for "
224 "the property selected.");
229 if (property_arg.isSet() && property_name_arg.isSet())
232 property_arg.getValue(), searcher);
236 if (property_name_arg.isSet() && min_property_arg.isSet() &&
237 max_property_arg.isSet())
239 if ((!outside_property_arg.isSet() &&
240 !inside_property_arg.isSet()) ||
241 (outside_property_arg.isSet() && inside_property_arg.isSet()))
243 ERR(
"Specify if the inside or the outside of the selected "
244 "range should be removed.");
248 bool const outside = outside_property_arg.isSet();
250 property_name_arg.getValue(), min_property_arg.getValue(),
251 max_property_arg.getValue(), outside, searcher);
255 if (xSmallArg.isSet() || xLargeArg.isSet() || ySmallArg.isSet() ||
256 yLargeArg.isSet() || zSmallArg.isSet() || zLargeArg.isSet())
259 bool aabb_error(
false);
260 if (xSmallArg.getValue() >= xLargeArg.getValue())
262 ERR(
"Minimum x-extent larger than maximum x-extent.");
265 if (ySmallArg.getValue() >= yLargeArg.getValue())
267 ERR(
"Minimum y-extent larger than maximum y-extent.");
270 if (zSmallArg.getValue() >= zLargeArg.getValue())
272 ERR(
"Minimum z-extent larger than maximum z-extent.");
280 std::array<MathLib::Point3d, 2> extent(
282 ySmallArg.getValue(),
283 zSmallArg.getValue()}}),
285 {xLargeArg.getValue(), yLargeArg.getValue(),
286 zLargeArg.getValue()}})}});
287 INFO(
"{:d} elements found.",
290 invert_bounding_box_arg.getValue()));
297 if (new_mesh ==
nullptr)