OGS
ResetPropertiesInPolygonalRegion.cpp File Reference
#include <tclap/CmdLine.h>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <mpi.h>
#include "Applications/FileIO/readGeometryFromFile.h"
#include "GeoLib/GEOObjects.h"
#include "GeoLib/Polygon.h"
#include "InfoLib/GitInfo.h"
#include "MeshGeoToolsLib/MeshEditing/ResetMeshElementProperty.h"
#include "MeshLib/IO/readMeshFromFile.h"
#include "MeshLib/IO/writeMeshToFile.h"
#include "MeshLib/Mesh.h"
#include "MeshToolsLib/MeshInformation.h"
Include dependency graph for ResetPropertiesInPolygonalRegion.cpp:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 33 of file ResetPropertiesInPolygonalRegion.cpp.

34{
35 TCLAP::CmdLine cmd(
36 "Sets the property value of a mesh element to a given new value iff at "
37 "least one node of the element is within a polygonal region that is "
38 "given by a polygon. The documentation is available at "
39 "https://docs.opengeosys.org/docs/tools/model-preparation/"
40 "set-properties-in-polygonal-region.\n\n"
41 "OpenGeoSys-6 software, version " +
43 ".\n"
44 "Copyright (c) 2012-2024, OpenGeoSys Community "
45 "(http://www.opengeosys.org)",
47 TCLAP::ValueArg<std::string> mesh_out(
48 "o", "mesh-output-file",
49 "the name of the file the mesh will be written to, format depends on "
50 "the given file name extension",
51 true, "", "file name");
52 cmd.add(mesh_out);
53 TCLAP::ValueArg<std::string> polygon_name_arg(
54 "p", "polygon-name", "name of polygon in the geometry", true, "",
55 "string");
56 cmd.add(polygon_name_arg);
57 TCLAP::ValueArg<std::string> geometry_fname(
58 "g", "geometry",
59 "the name of the file containing the input geometry (gli or gml "
60 "format)",
61 true, "", "file name");
62 cmd.add(geometry_fname);
63 TCLAP::SwitchArg any_of_arg(
64 "", "any_of",
65 "all nodes of an element has to be inside the polygon (default "
66 "behaviour without switch) or any node of an element has to be inside "
67 "(switch is given)",
68 false);
69 cmd.add(any_of_arg);
70 TCLAP::ValueArg<char> char_property_arg(
71 "c", "char-property-value", "new property value (data type char)",
72 false, 'A', "character");
73 cmd.add(char_property_arg);
74 TCLAP::ValueArg<int> int_property_arg("i", "int-property-value",
75 "new property value (data type int)",
76 false, 0, "number");
77 cmd.add(int_property_arg);
78 TCLAP::ValueArg<bool> bool_property_arg(
79 "b", "bool-property-value", "new property value (data type bool)",
80 false, false, "boolean value");
81 cmd.add(bool_property_arg);
82 TCLAP::ValueArg<std::string> property_name_arg(
83 "n", "property-name", "name of property in the mesh", false,
84 "MaterialIDs", "string");
85 cmd.add(property_name_arg);
86 TCLAP::ValueArg<int> restrict_arg(
87 "r", "restrict-to-MaterialID",
88 "Restrict resetting the property to the material id", false, -1,
89 "MaterialID");
90 cmd.add(restrict_arg);
91 TCLAP::ValueArg<std::string> mesh_in(
92 "m", "mesh-input-file",
93 "the name of the file containing the input mesh", true, "",
94 "file name");
95 cmd.add(mesh_in);
96 TCLAP::ValueArg<std::string> gmsh_path_arg("", "gmsh-path",
97 "the path to the gmsh binary",
98 false, "", "path as string");
99 cmd.add(gmsh_path_arg);
100 cmd.parse(argc, argv);
101
102#ifdef USE_PETSC
103 MPI_Init(&argc, &argv);
104#endif
105
106 // *** read geometry
107 GeoLib::GEOObjects geometries;
108 FileIO::readGeometryFromFile(geometry_fname.getValue(), geometries,
109 gmsh_path_arg.getValue());
110
111 auto const geo_name = geometries.getGeometryNames()[0];
112
113 // *** check if the data is usable
114 // *** get vector of polylines
115 GeoLib::PolylineVec const* plys(geometries.getPolylineVecObj(geo_name));
116 if (!plys)
117 {
118 ERR("Could not get vector of polylines out of geometry '{:s}'.",
119 geo_name);
120#ifdef USE_PETSC
121 MPI_Finalize();
122#endif
123 return EXIT_FAILURE;
124 }
125
126 // *** get polygon
127 GeoLib::Polyline const* ply(
128 plys->getElementByName(polygon_name_arg.getValue()));
129 if (!ply)
130 {
131 ERR("Polyline '{:s}' not found.", polygon_name_arg.getValue());
132#ifdef USE_PETSC
133 MPI_Finalize();
134#endif
135 return EXIT_FAILURE;
136 }
137
138 // *** check if the polyline is closed (i.e. is a polygon)
139 if (!ply->isClosed())
140 {
141 ERR("Polyline '{:s}' is not closed, i.e. does not describe a region.",
142 polygon_name_arg.getValue());
143#ifdef USE_PETSC
144 MPI_Finalize();
145#endif
146 return EXIT_FAILURE;
147 }
148
149 GeoLib::Polygon const polygon(*(ply));
150
151 // *** read mesh
152 auto mesh = std::unique_ptr<MeshLib::Mesh>(
153 MeshLib::IO::readMeshFromFile(mesh_in.getValue()));
154 if (!mesh)
155 {
156 // error message written already by readMeshFromFile
157#ifdef USE_PETSC
158 MPI_Finalize();
159#endif
160 return EXIT_FAILURE;
161 }
162 std::string const& property_name(property_name_arg.getValue());
163
164 if (char_property_arg.isSet())
165 {
167 *mesh, polygon, property_name, char_property_arg.getValue(),
168 restrict_arg.getValue(), any_of_arg.getValue());
169 }
170
171 if (int_property_arg.isSet())
172 {
174 *mesh, polygon, property_name, int_property_arg.getValue(),
175 restrict_arg.getValue(), any_of_arg.getValue());
176 }
177
178 if (bool_property_arg.isSet())
179 {
181 *mesh, polygon, property_name, bool_property_arg.getValue(),
182 restrict_arg.getValue(), any_of_arg.getValue());
183 }
184
186
187 MeshLib::IO::writeMeshToFile(*mesh, mesh_out.getValue());
188
189#ifdef USE_PETSC
190 MPI_Finalize();
191#endif
192 return EXIT_SUCCESS;
193}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45
Container class for geometric objects.
Definition GEOObjects.h:57
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 ...
Definition Polyline.h:40
The class TemplateVec takes a unique name and manages a std::vector of pointers to data elements of t...
Definition TemplateVec.h:38
static void writePropertyVectorInformation(const MeshLib::Mesh &mesh)
writes out property vector information
void readGeometryFromFile(std::string const &fname, GeoLib::GEOObjects &geo_objs, std::string const &gmsh_path)
GITINFOLIB_EXPORT const std::string ogs_version
void resetMeshElementProperty(MeshLib::Mesh &mesh, GeoLib::Polygon const &polygon, std::string const &property_name, PT new_property_value, int restrict_to_material_id, bool const any_of)
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)

References ERR(), GeoLib::TemplateVec< T >::getElementByName(), GeoLib::GEOObjects::getGeometryNames(), GeoLib::GEOObjects::getPolylineVecObj(), GeoLib::Polyline::isClosed(), GitInfoLib::GitInfo::ogs_version, FileIO::readGeometryFromFile(), MeshLib::IO::readMeshFromFile(), MeshGeoToolsLib::resetMeshElementProperty(), MeshLib::IO::writeMeshToFile(), and MeshToolsLib::MeshInformation::writePropertyVectorInformation().