85int main(
int argc,
char* argv[])
88 "Removes mesh elements based on element type, element volume, scalar "
89 "arrays, or bounding box . The documentation is available at "
90 "https://docs.opengeosys.org/docs/tools/meshing/"
91 "remove-mesh-elements.\n\n"
92 "OpenGeoSys-6 software, version " +
95 "Copyright (c) 2012-2024, OpenGeoSys Community "
96 "(http://www.opengeosys.org)",
100 TCLAP::SwitchArg invert_bounding_box_arg(
101 "",
"invert",
"inverts the specified bounding box",
false);
102 cmd.add(invert_bounding_box_arg);
103 TCLAP::ValueArg<double> zLargeArg(
104 "",
"z-max",
"largest allowed extent in z-dimension",
false,
105 std::numeric_limits<double>::max(),
"value");
107 TCLAP::ValueArg<double> zSmallArg(
108 "",
"z-min",
"smallest allowed extent in z-dimension",
false,
109 -1 * std::numeric_limits<double>::max(),
"value");
111 TCLAP::ValueArg<double> yLargeArg(
112 "",
"y-max",
"largest allowed extent in y-dimension",
false,
113 std::numeric_limits<double>::max(),
"value");
115 TCLAP::ValueArg<double> ySmallArg(
116 "",
"y-min",
"smallest allowed extent in y-dimension",
false,
117 -1 * std::numeric_limits<double>::max(),
"value");
119 TCLAP::ValueArg<double> xLargeArg(
120 "",
"x-max",
"largest allowed extent in x-dimension",
false,
121 std::numeric_limits<double>::max(),
"value");
123 TCLAP::ValueArg<double> xSmallArg(
124 "",
"x-min",
"smallest allowed extent in x-dimension",
false,
125 -1 * std::numeric_limits<double>::max(),
"value");
129 TCLAP::SwitchArg zveArg(
"z",
"zero-volume",
"remove zero volume elements",
133 std::vector<std::string> allowed_ele_types{
134 "point",
"line",
"tri",
"quad",
"hex",
"prism",
"tet",
"pyramid"};
135 TCLAP::ValuesConstraint<std::string> allowedVals{allowed_ele_types};
136 TCLAP::MultiArg<std::string> eleTypeArg(
138 "element type to be removed: point | line | tri | quad | hex | prism | "
140 false, &allowedVals);
144 TCLAP::ValueArg<std::string> property_name_arg(
145 "n",
"property-name",
"name of property in the mesh",
false,
146 "MaterialIDs",
"string");
147 cmd.add(property_name_arg);
149 TCLAP::MultiArg<int> property_arg(
150 "",
"property-value",
"value of selected property to be removed",
false,
152 cmd.add(property_arg);
154 TCLAP::ValueArg<double> min_property_arg(
155 "",
"min-value",
"minimum value of range for selected property",
false,
157 cmd.add(min_property_arg);
159 TCLAP::ValueArg<double> max_property_arg(
160 "",
"max-value",
"maximum value of range for selected property",
false,
162 cmd.add(max_property_arg);
164 TCLAP::SwitchArg outside_property_arg(
165 "",
"outside",
"remove all elements outside the given property range");
166 cmd.add(outside_property_arg);
168 TCLAP::SwitchArg inside_property_arg(
169 "",
"inside",
"remove all elements inside the given property range");
170 cmd.add(inside_property_arg);
173 TCLAP::ValueArg<std::string> mesh_out(
174 "o",
"mesh-output-file",
175 "the name of the file the mesh will be written to",
true,
"",
176 "file name of output mesh");
178 TCLAP::ValueArg<std::string> mesh_in(
179 "i",
"mesh-input-file",
180 "the name of the file containing the input mesh",
true,
"",
181 "file name of input mesh");
183 cmd.parse(argc, argv);
186 MPI_Init(&argc, &argv);
189 std::unique_ptr<MeshLib::Mesh const> mesh(
199 INFO(
"Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
200 mesh->getNumberOfElements());
208 if (eleTypeArg.isSet())
210 const std::vector<std::string> eleTypeNames = eleTypeArg.getValue();
211 for (
const auto& typeName : eleTypeNames)
219 INFO(
"{:d} {:s} elements found.",
224 if (property_name_arg.isSet() || property_arg.isSet() ||
225 min_property_arg.isSet() || max_property_arg.isSet())
227 if ((property_arg.isSet() || min_property_arg.isSet() ||
228 max_property_arg.isSet()) &&
229 !property_name_arg.isSet())
231 ERR(
"Specify a property name for the value/range selected.");
238 if (property_name_arg.isSet() &&
239 !((min_property_arg.isSet() && max_property_arg.isSet()) ||
240 property_arg.isSet()))
242 ERR(
"Specify a value or range ('-min-value' and '-max_value') for "
243 "the property selected.");
251 if (property_arg.isSet() && property_name_arg.isSet())
254 property_arg.getValue(), searcher);
258 if (property_name_arg.isSet() && min_property_arg.isSet() &&
259 max_property_arg.isSet())
261 if ((!outside_property_arg.isSet() &&
262 !inside_property_arg.isSet()) ||
263 (outside_property_arg.isSet() && inside_property_arg.isSet()))
265 ERR(
"Specify if the inside or the outside of the selected "
266 "range should be removed.");
273 bool const outside = outside_property_arg.isSet();
275 property_name_arg.getValue(), min_property_arg.getValue(),
276 max_property_arg.getValue(), outside, searcher);
280 if (xSmallArg.isSet() || xLargeArg.isSet() || ySmallArg.isSet() ||
281 yLargeArg.isSet() || zSmallArg.isSet() || zLargeArg.isSet())
284 bool aabb_error(
false);
285 if (xSmallArg.getValue() >= xLargeArg.getValue())
287 ERR(
"Minimum x-extent larger than maximum x-extent.");
290 if (ySmallArg.getValue() >= yLargeArg.getValue())
292 ERR(
"Minimum y-extent larger than maximum y-extent.");
295 if (zSmallArg.getValue() >= zLargeArg.getValue())
297 ERR(
"Minimum z-extent larger than maximum z-extent.");
308 std::array<MathLib::Point3d, 2> extent(
310 ySmallArg.getValue(),
311 zSmallArg.getValue()}}),
313 {xLargeArg.getValue(), yLargeArg.getValue(),
314 zLargeArg.getValue()}})}});
315 INFO(
"{:d} elements found.",
318 invert_bounding_box_arg.getValue()));
325 if (new_mesh ==
nullptr)