72 "Removes mesh elements based on element type, element volume, scalar "
73 "arrays, or bounding box . The documentation is available at "
74 "https://docs.opengeosys.org/docs/tools/meshing/"
75 "remove-mesh-elements.\n\n"
76 "OpenGeoSys-6 software, version " +
79 "Copyright (c) 2012-2021, OpenGeoSys Community "
80 "(http://www.opengeosys.org)",
84 TCLAP::ValueArg<double> zLargeArg(
85 "",
"z-max",
"largest allowed extent in z-dimension",
false,
86 std::numeric_limits<double>::max(),
"value");
88 TCLAP::ValueArg<double> zSmallArg(
89 "",
"z-min",
"smallest allowed extent in z-dimension",
false,
90 -1 * std::numeric_limits<double>::max(),
"value");
92 TCLAP::ValueArg<double> yLargeArg(
93 "",
"y-max",
"largest allowed extent in y-dimension",
false,
94 std::numeric_limits<double>::max(),
"value");
96 TCLAP::ValueArg<double> ySmallArg(
97 "",
"y-min",
"smallest allowed extent in y-dimension",
false,
98 -1 * std::numeric_limits<double>::max(),
"value");
100 TCLAP::ValueArg<double> xLargeArg(
101 "",
"x-max",
"largest allowed extent in x-dimension",
false,
102 std::numeric_limits<double>::max(),
"value");
104 TCLAP::ValueArg<double> xSmallArg(
105 "",
"x-min",
"smallest allowed extent in x-dimension",
false,
106 -1 * std::numeric_limits<double>::max(),
"value");
110 TCLAP::SwitchArg zveArg(
"z",
"zero-volume",
"remove zero volume elements",
114 std::vector<std::string> allowed_ele_types{
"line",
"tri",
"quad",
"hex",
115 "prism",
"tet",
"pyramid"};
116 TCLAP::ValuesConstraint<std::string> allowedVals{allowed_ele_types};
117 TCLAP::MultiArg<std::string> eleTypeArg(
119 "element type to be removed: line | tri | quad | hex | prism | tet | "
121 false, &allowedVals);
125 TCLAP::ValueArg<std::string> property_name_arg(
126 "n",
"property-name",
"name of property in the mesh",
false,
127 "MaterialIDs",
"string");
128 cmd.add(property_name_arg);
130 TCLAP::MultiArg<int> property_arg(
131 "",
"property-value",
"value of selected property to be removed",
false,
133 cmd.add(property_arg);
135 TCLAP::ValueArg<double> min_property_arg(
136 "",
"min-value",
"minimum value of range for selected property",
false,
138 cmd.add(min_property_arg);
140 TCLAP::ValueArg<double> max_property_arg(
141 "",
"max-value",
"maximum value of range for selected property",
false,
143 cmd.add(max_property_arg);
145 TCLAP::SwitchArg outside_property_arg(
146 "",
"outside",
"remove all elements outside the given property range");
147 cmd.add(outside_property_arg);
149 TCLAP::SwitchArg inside_property_arg(
150 "",
"inside",
"remove all elements inside the given property range");
151 cmd.add(inside_property_arg);
154 TCLAP::ValueArg<std::string> mesh_out(
155 "o",
"mesh-output-file",
156 "the name of the file the mesh will be written to",
true,
"",
157 "file name of output mesh");
159 TCLAP::ValueArg<std::string> mesh_in(
160 "i",
"mesh-input-file",
161 "the name of the file containing the input mesh",
true,
"",
162 "file name of input mesh");
164 cmd.parse(argc, argv);
166 std::unique_ptr<MeshLib::Mesh const> mesh(
173 INFO(
"Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
174 mesh->getNumberOfElements());
180 INFO(
"{:d} zero volume elements found.", searcher.searchByContent());
182 if (eleTypeArg.isSet())
184 const std::vector<std::string> eleTypeNames = eleTypeArg.getValue();
185 for (
const auto& typeName : eleTypeNames)
193 INFO(
"{:d} {:s} elements found.",
194 searcher.searchByElementType(type), typeName);
198 if (property_name_arg.isSet() || property_arg.isSet() ||
199 min_property_arg.isSet() || max_property_arg.isSet())
201 if ((property_arg.isSet() || min_property_arg.isSet() ||
202 max_property_arg.isSet()) &&
203 !property_name_arg.isSet())
205 ERR(
"Specify a property name for the value/range selected.");
209 if (property_name_arg.isSet() &&
210 !((min_property_arg.isSet() && max_property_arg.isSet()) ||
211 property_arg.isSet()))
213 ERR(
"Specify a value or range ('-min-value' and '-max_value') for "
214 "the property selected.");
219 if (property_arg.isSet() && property_name_arg.isSet())
222 property_arg.getValue(), searcher);
226 if (property_name_arg.isSet() && min_property_arg.isSet() &&
227 max_property_arg.isSet())
229 if ((!outside_property_arg.isSet() &&
230 !inside_property_arg.isSet()) ||
231 (outside_property_arg.isSet() && inside_property_arg.isSet()))
233 ERR(
"Specify if the inside or the outside of the selected "
234 "range should be removed.");
238 bool const outside = outside_property_arg.isSet();
240 property_name_arg.getValue(), min_property_arg.getValue(),
241 max_property_arg.getValue(), outside, searcher);
245 if (xSmallArg.isSet() || xLargeArg.isSet() || ySmallArg.isSet() ||
246 yLargeArg.isSet() || zSmallArg.isSet() || zLargeArg.isSet())
248 bool aabb_error(
false);
249 if (xSmallArg.getValue() >= xLargeArg.getValue())
251 ERR(
"Minimum x-extent larger than maximum x-extent.");
254 if (ySmallArg.getValue() >= yLargeArg.getValue())
256 ERR(
"Minimum y-extent larger than maximum y-extent.");
259 if (zSmallArg.getValue() >= zLargeArg.getValue())
261 ERR(
"Minimum z-extent larger than maximum z-extent.");
269 std::array<MathLib::Point3d, 2> extent(
271 ySmallArg.getValue(),
272 zSmallArg.getValue()}}),
274 {xLargeArg.getValue(), yLargeArg.getValue(),
275 zLargeArg.getValue()}})}});
276 INFO(
"{:d} elements found.",
277 searcher.searchByBoundingBox(
283 *mesh, searcher.getSearchedElementIDs(), mesh->getName()));
285 if (new_mesh ==
nullptr)
void INFO(char const *fmt, Args const &... args)
void ERR(char const *fmt, Args const &... args)
Class AABB is an axis aligned bounding box around a given set of geometric points of (template) type ...
GITINFOLIB_EXPORT const std::string ogs_version
MathLib::TemplatePoint< double, 3 > Point3d
MeshLib::Mesh * readMeshFromFile(const std::string &file_name)
int writeMeshToFile(const MeshLib::Mesh &mesh, std::filesystem::path const &file_path, [[maybe_unused]] std::set< std::string > variable_output_names)
MeshLib::Mesh * removeElements(const MeshLib::Mesh &mesh, const std::vector< std::size_t > &removed_element_ids, const std::string &new_mesh_name)
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 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)