82int main(
int argc,
char* argv[])
85 "Removes mesh elements based on element type, element volume, scalar "
86 "arrays, or bounding box . The documentation is available at "
87 "https://docs.opengeosys.org/docs/tools/meshing/"
88 "remove-mesh-elements.\n\n"
89 "OpenGeoSys-6 software, version " +
92 "Copyright (c) 2012-2024, OpenGeoSys Community "
93 "(http://www.opengeosys.org)",
97 TCLAP::SwitchArg invert_bounding_box_arg(
98 "",
"invert",
"inverts the specified bounding box",
false);
99 cmd.add(invert_bounding_box_arg);
100 TCLAP::ValueArg<double> zLargeArg(
101 "",
"z-max",
"largest allowed extent in z-dimension",
false,
102 std::numeric_limits<double>::max(),
"value");
104 TCLAP::ValueArg<double> zSmallArg(
105 "",
"z-min",
"smallest allowed extent in z-dimension",
false,
106 -1 * std::numeric_limits<double>::max(),
"value");
108 TCLAP::ValueArg<double> yLargeArg(
109 "",
"y-max",
"largest allowed extent in y-dimension",
false,
110 std::numeric_limits<double>::max(),
"value");
112 TCLAP::ValueArg<double> ySmallArg(
113 "",
"y-min",
"smallest allowed extent in y-dimension",
false,
114 -1 * std::numeric_limits<double>::max(),
"value");
116 TCLAP::ValueArg<double> xLargeArg(
117 "",
"x-max",
"largest allowed extent in x-dimension",
false,
118 std::numeric_limits<double>::max(),
"value");
120 TCLAP::ValueArg<double> xSmallArg(
121 "",
"x-min",
"smallest allowed extent in x-dimension",
false,
122 -1 * std::numeric_limits<double>::max(),
"value");
126 TCLAP::SwitchArg zveArg(
"z",
"zero-volume",
"remove zero volume elements",
130 std::vector<std::string> allowed_ele_types{
131 "point",
"line",
"tri",
"quad",
"hex",
"prism",
"tet",
"pyramid"};
132 TCLAP::ValuesConstraint<std::string> allowedVals{allowed_ele_types};
133 TCLAP::MultiArg<std::string> eleTypeArg(
135 "element type to be removed: point | line | tri | quad | hex | prism | "
137 false, &allowedVals);
141 TCLAP::ValueArg<std::string> property_name_arg(
142 "n",
"property-name",
"name of property in the mesh",
false,
143 "MaterialIDs",
"string");
144 cmd.add(property_name_arg);
146 TCLAP::MultiArg<int> property_arg(
147 "",
"property-value",
"value of selected property to be removed",
false,
149 cmd.add(property_arg);
151 TCLAP::ValueArg<double> min_property_arg(
152 "",
"min-value",
"minimum value of range for selected property",
false,
154 cmd.add(min_property_arg);
156 TCLAP::ValueArg<double> max_property_arg(
157 "",
"max-value",
"maximum value of range for selected property",
false,
159 cmd.add(max_property_arg);
161 TCLAP::SwitchArg outside_property_arg(
162 "",
"outside",
"remove all elements outside the given property range");
163 cmd.add(outside_property_arg);
165 TCLAP::SwitchArg inside_property_arg(
166 "",
"inside",
"remove all elements inside the given property range");
167 cmd.add(inside_property_arg);
170 TCLAP::ValueArg<std::string> mesh_out(
171 "o",
"mesh-output-file",
172 "the name of the file the mesh will be written to",
true,
"",
173 "file name of output mesh");
175 TCLAP::ValueArg<std::string> mesh_in(
176 "i",
"mesh-input-file",
177 "the name of the file containing the input mesh",
true,
"",
178 "file name of input mesh");
180 cmd.parse(argc, argv);
184 std::unique_ptr<MeshLib::Mesh const> mesh(
191 INFO(
"Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
192 mesh->getNumberOfElements());
200 if (eleTypeArg.isSet())
202 const std::vector<std::string> eleTypeNames = eleTypeArg.getValue();
203 for (
const auto& typeName : eleTypeNames)
211 INFO(
"{:d} {:s} elements found.",
216 if (property_name_arg.isSet() || property_arg.isSet() ||
217 min_property_arg.isSet() || max_property_arg.isSet())
219 if ((property_arg.isSet() || min_property_arg.isSet() ||
220 max_property_arg.isSet()) &&
221 !property_name_arg.isSet())
223 ERR(
"Specify a property name for the value/range selected.");
227 if (property_name_arg.isSet() &&
228 !((min_property_arg.isSet() && max_property_arg.isSet()) ||
229 property_arg.isSet()))
231 ERR(
"Specify a value or range ('-min-value' and '-max_value') for "
232 "the property selected.");
237 if (property_arg.isSet() && property_name_arg.isSet())
240 property_arg.getValue(), searcher);
244 if (property_name_arg.isSet() && min_property_arg.isSet() &&
245 max_property_arg.isSet())
247 if ((!outside_property_arg.isSet() &&
248 !inside_property_arg.isSet()) ||
249 (outside_property_arg.isSet() && inside_property_arg.isSet()))
251 ERR(
"Specify if the inside or the outside of the selected "
252 "range should be removed.");
256 bool const outside = outside_property_arg.isSet();
258 property_name_arg.getValue(), min_property_arg.getValue(),
259 max_property_arg.getValue(), outside, searcher);
263 if (xSmallArg.isSet() || xLargeArg.isSet() || ySmallArg.isSet() ||
264 yLargeArg.isSet() || zSmallArg.isSet() || zLargeArg.isSet())
267 bool aabb_error(
false);
268 if (xSmallArg.getValue() >= xLargeArg.getValue())
270 ERR(
"Minimum x-extent larger than maximum x-extent.");
273 if (ySmallArg.getValue() >= yLargeArg.getValue())
275 ERR(
"Minimum y-extent larger than maximum y-extent.");
278 if (zSmallArg.getValue() >= zLargeArg.getValue())
280 ERR(
"Minimum z-extent larger than maximum z-extent.");
288 std::array<MathLib::Point3d, 2> extent(
290 ySmallArg.getValue(),
291 zSmallArg.getValue()}}),
293 {xLargeArg.getValue(), yLargeArg.getValue(),
294 zLargeArg.getValue()}})}});
295 INFO(
"{:d} elements found.",
298 invert_bounding_box_arg.getValue()));
305 if (new_mesh ==
nullptr)