14 #include <tclap/CmdLine.h>
28 template <
typename PROPERTY_TYPE>
30 std::vector<PROPERTY_TYPE>
const& property_values,
33 for (
auto const& property_value : property_values)
36 property_name, property_value);
37 if (n_marked_elements == 0)
40 property_name, property_value);
43 INFO(
"{:d} elements with property value {:s} found.", n_marked_elements,
44 std::to_string(property_value));
49 double const& min_value,
double const& max_value,
54 property_name, min_value, max_value, outside);
56 if (n_marked_elements == 0)
59 property_name,
static_cast<int>(min_value),
60 static_cast<int>(max_value), outside);
65 INFO(
"{:d} elements in range [{:s}, {:s}] found.", n_marked_elements,
66 std::to_string(min_value), std::to_string(max_value));
69 int main(
int argc,
char* argv[])
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());
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.",
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.",
285 if (new_mesh ==
nullptr)
Definition of the Element class.
void INFO(char const *fmt, Args const &... args)
void ERR(char const *fmt, Args const &... args)
Definition of mesh-related Enumerations.
Definition of the Mesh class.
Definition of the Node class.
Class AABB is an axis aligned bounding box around a given set of geometric points of (template) type ...
std::size_t searchByElementType(MeshElemType eleType)
Marks all elements of the given element type.
std::size_t searchByPropertyValueRange(std::string const &property_name, PROPERTY_TYPE const min_property_value, PROPERTY_TYPE const max_property_value, bool outside_of)
std::size_t searchByContent(double eps=std::numeric_limits< double >::epsilon())
Marks all elements with a volume smaller than eps.
std::size_t searchByBoundingBox(GeoLib::AABB const &aabb)
Marks all elements with at least one node outside the bounding box spanned by x1 and x2;.
std::size_t searchByPropertyValue(std::string const &property_name, PROPERTY_TYPE const property_value)
const std::vector< std::size_t > & getSearchedElementIDs() const
return marked elements
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.
Definition of readMeshFromFile function.
int main(int argc, char *argv[])
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)