OGS
ResetPropertiesInPolygonalRegion.cpp File Reference
#include <tclap/CmdLine.h>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include "Applications/FileIO/readGeometryFromFile.h"
#include "BaseLib/MPI.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 30 of file ResetPropertiesInPolygonalRegion.cpp.

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-2024, OpenGeoSys Community "
42 "(http://www.opengeosys.org)",
44 TCLAP::ValueArg<std::string> mesh_out(
45 "o", "mesh-output-file",
46 "the name of the file the mesh will be written to, format depends on "
47 "the given file name extension",
48 true, "", "file name");
49 cmd.add(mesh_out);
50 TCLAP::ValueArg<std::string> polygon_name_arg(
51 "p", "polygon-name", "name of polygon in the geometry", true, "",
52 "string");
53 cmd.add(polygon_name_arg);
54 TCLAP::ValueArg<std::string> geometry_fname(
55 "g", "geometry",
56 "the name of the file containing the input geometry (gli or gml "
57 "format)",
58 true, "", "file name");
59 cmd.add(geometry_fname);
60 TCLAP::SwitchArg any_of_arg(
61 "", "any_of",
62 "all nodes of an element has to be inside the polygon (default "
63 "behaviour without switch) or any node of an element has to be inside "
64 "(switch is given)",
65 false);
66 cmd.add(any_of_arg);
67 TCLAP::ValueArg<char> char_property_arg(
68 "c", "char-property-value", "new property value (data type char)",
69 false, 'A', "character");
70 cmd.add(char_property_arg);
71 TCLAP::ValueArg<int> int_property_arg("i", "int-property-value",
72 "new property value (data type int)",
73 false, 0, "number");
74 cmd.add(int_property_arg);
75 TCLAP::ValueArg<bool> bool_property_arg(
76 "b", "bool-property-value", "new property value (data type bool)",
77 false, false, "boolean value");
78 cmd.add(bool_property_arg);
79 TCLAP::ValueArg<std::string> property_name_arg(
80 "n", "property-name", "name of property in the mesh", false,
81 "MaterialIDs", "string");
82 cmd.add(property_name_arg);
83 TCLAP::ValueArg<int> restrict_arg(
84 "r", "restrict-to-MaterialID",
85 "Restrict resetting the property to the material id", false, -1,
86 "MaterialID");
87 cmd.add(restrict_arg);
88 TCLAP::ValueArg<std::string> mesh_in(
89 "m", "mesh-input-file",
90 "the name of the file containing the input mesh", true, "",
91 "file name");
92 cmd.add(mesh_in);
93 TCLAP::ValueArg<std::string> gmsh_path_arg("", "gmsh-path",
94 "the path to the gmsh binary",
95 false, "", "path as string");
96 cmd.add(gmsh_path_arg);
97 cmd.parse(argc, argv);
98
99 BaseLib::MPI::Setup mpi_setup(argc, argv);
100
101 // *** read geometry
102 GeoLib::GEOObjects geometries;
103 FileIO::readGeometryFromFile(geometry_fname.getValue(), geometries,
104 gmsh_path_arg.getValue());
105
106 auto const geo_name = geometries.getGeometryNames()[0];
107
108 // *** check if the data is usable
109 // *** get vector of polylines
110 GeoLib::PolylineVec const* plys(geometries.getPolylineVecObj(geo_name));
111 if (!plys)
112 {
113 ERR("Could not get vector of polylines out of geometry '{:s}'.",
114 geo_name);
115 return EXIT_FAILURE;
116 }
117
118 // *** get polygon
119 GeoLib::Polyline const* ply(
120 plys->getElementByName(polygon_name_arg.getValue()));
121 if (!ply)
122 {
123 ERR("Polyline '{:s}' not found.", polygon_name_arg.getValue());
124 return EXIT_FAILURE;
125 }
126
127 // *** check if the polyline is closed (i.e. is a polygon)
128 if (!ply->isClosed())
129 {
130 ERR("Polyline '{:s}' is not closed, i.e. does not describe a region.",
131 polygon_name_arg.getValue());
132 return EXIT_FAILURE;
133 }
134
135 GeoLib::Polygon const polygon(*(ply));
136
137 // *** read mesh
138 auto mesh = std::unique_ptr<MeshLib::Mesh>(
139 MeshLib::IO::readMeshFromFile(mesh_in.getValue()));
140 if (!mesh)
141 {
142 // error message written already by readMeshFromFile
143 return EXIT_FAILURE;
144 }
145 std::string const& property_name(property_name_arg.getValue());
146
147 if (char_property_arg.isSet())
148 {
150 *mesh, polygon, property_name, char_property_arg.getValue(),
151 restrict_arg.getValue(), any_of_arg.getValue());
152 }
153
154 if (int_property_arg.isSet())
155 {
157 *mesh, polygon, property_name, int_property_arg.getValue(),
158 restrict_arg.getValue(), any_of_arg.getValue());
159 }
160
161 if (bool_property_arg.isSet())
162 {
164 *mesh, polygon, property_name, bool_property_arg.getValue(),
165 restrict_arg.getValue(), any_of_arg.getValue());
166 }
167
169
170 MeshLib::IO::writeMeshToFile(*mesh, mesh_out.getValue());
171
172 return EXIT_SUCCESS;
173}
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...
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().