31{
32 TCLAP::CmdLine cmd(
33 "Sets the property value of a mesh element to a given new value iff at "
34 "least one node of the element is within a polygonal region that is "
35 "given by a polygon. The documentation is available at "
36 "https://docs.opengeosys.org/docs/tools/model-preparation/"
37 "set-properties-in-polygonal-region.\n\n"
38 "OpenGeoSys-6 software, version " +
40 ".\n"
41 "Copyright (c) 2012-2025, OpenGeoSys Community "
42 "(http://www.opengeosys.org)",
44 TCLAP::ValueArg<std::string> mesh_out(
45 "o", "mesh-output-file",
46 "Output. The name of the file the mesh will be written to, format "
47 "depends on "
48 "the given file name extension",
49 true, "", "OUTPUT_FILE");
50 cmd.add(mesh_out);
51 TCLAP::ValueArg<std::string> polygon_name_arg(
52 "p", "polygon-name", "name of polygon in the geometry", true, "",
53 "string");
54 cmd.add(polygon_name_arg);
55 TCLAP::ValueArg<std::string> geometry_fname(
56 "g", "geometry",
57 "Input (.gli | .gml). The name of the file containing the input "
58 "geometry",
59 true, "", "INPUT_FILE");
60 cmd.add(geometry_fname);
61 TCLAP::SwitchArg any_of_arg(
62 "", "any_of",
63 "all nodes of an element has to be inside the polygon (default "
64 "behaviour without switch) or any node of an element has to be inside "
65 "(switch is given)",
66 false);
67 cmd.add(any_of_arg);
68 TCLAP::ValueArg<char> char_property_arg(
69 "c", "char-property-value", "new property value (data type char)",
70 false, 'A', "CHAR_PROPERTY_VALUE");
71 cmd.add(char_property_arg);
72 TCLAP::ValueArg<int> int_property_arg("i", "int-property-value",
73 "new property value (data type int)",
74 false, 0, "INT_PROPERTY_VALUE");
75 cmd.add(int_property_arg);
76 TCLAP::ValueArg<std::string> property_name_arg(
77 "n", "property-name", "name of property in the mesh", false,
78 "MaterialIDs", "PROPERTY_NAME");
79 cmd.add(property_name_arg);
80 TCLAP::ValueArg<int> restrict_arg(
81 "r", "restrict-to-MaterialID",
82 "Restrict resetting the property to the material id", false, -1,
83 "RESTRICT_MATERIAL_ID");
84 cmd.add(restrict_arg);
85 TCLAP::ValueArg<std::string> mesh_in(
86 "m", "mesh-input-file",
87 "Input (.vtu | .vtk | .msh). The name of the file containing the input "
88 "mesh",
89 true, "", "INPUT_FILE");
90 cmd.add(mesh_in);
91 TCLAP::ValueArg<std::string> gmsh_path_arg(
92 "", "gmsh-path", "Input (.msh). The path to the input binary", false,
93 "", "INPUT_FILE");
94 cmd.add(gmsh_path_arg);
95 cmd.parse(argc, argv);
96
98
99
102 gmsh_path_arg.getValue());
103
105
106
107
109 if (!plys)
110 {
111 ERR(
"Could not get vector of polylines out of geometry '{:s}'.",
112 geo_name);
113 return EXIT_FAILURE;
114 }
115
116
118 plys->getElementByName(polygon_name_arg.getValue()));
119 if (!ply)
120 {
121 ERR(
"Polyline '{:s}' not found.", polygon_name_arg.getValue());
122 return EXIT_FAILURE;
123 }
124
125
126 if (!ply->isClosed())
127 {
128 ERR(
"Polyline '{:s}' is not closed, i.e. does not describe a region.",
129 polygon_name_arg.getValue());
130 return EXIT_FAILURE;
131 }
132
134
135
136 auto mesh = std::unique_ptr<MeshLib::Mesh>(
138 if (!mesh)
139 {
140
141 return EXIT_FAILURE;
142 }
143 std::string const& property_name(property_name_arg.getValue());
144
145 if (char_property_arg.isSet())
146 {
148 *mesh, polygon, property_name, char_property_arg.getValue(),
149 restrict_arg.getValue(), any_of_arg.getValue());
150 }
151
152 if (int_property_arg.isSet())
153 {
155 *mesh, polygon, property_name, int_property_arg.getValue(),
156 restrict_arg.getValue(), any_of_arg.getValue());
157 }
158
160
162
163 return EXIT_SUCCESS;
164}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Container class for geometric objects.
std::vector< std::string > getGeometryNames() const
Returns the names of all geometry vectors.
const PolylineVec * getPolylineVecObj(const std::string &name) const
Class Polyline consists mainly of a reference to a point vector and a vector that stores the indices ...
The class TemplateVec takes a unique name and manages a std::vector of pointers to data elements of t...
void readGeometryFromFile(std::string const &fname, GeoLib::GEOObjects &geo_objs, std::string const &gmsh_path)
GITINFOLIB_EXPORT const std::string ogs_version
MeshLib::Mesh * readMeshFromFile(const std::string &file_name, bool const compute_element_neighbors)
int writeMeshToFile(const MeshLib::Mesh &mesh, std::filesystem::path const &file_path, std::set< std::string > variable_output_names)