74{
75 TCLAP::CmdLine cmd(
76 "Computes ids of mesh nodes that are in polygonal regions and resides "
77 "on the top surface. The polygonal regions have to be given in a gml- "
78 "or gli-file. The found mesh nodes and the associated area are written "
79 "as txt and csv data. The documentation is available at "
80 "https://docs.opengeosys.org/docs/tools/model-preparation/"
81 "computesurfacenodeidsinpolygonalregion.\n\n"
82 "OpenGeoSys-6 software, version " +
84 ".\n"
85 "Copyright (c) 2012-2025, OpenGeoSys Community "
86 "(http://www.opengeosys.org)",
88 TCLAP::ValueArg<std::string> mesh_in(
89 "m", "mesh-input-file",
90 "Input (.vtu). The name of the file containing the input mesh", true,
91 "", "INPUT_FILE");
92 cmd.add(mesh_in);
93 TCLAP::ValueArg<std::string> geo_in(
94 "g", "geo-file",
95 "Input (.gml). The name of the input file containing the polygons",
96 true, "", "INPUT_FILE");
97 cmd.add(geo_in);
98
99 TCLAP::ValueArg<std::string> gmsh_path_arg(
100 "", "gmsh-path", "Input (.msh). The path to the input binary file",
101 false, "", "INPUT_FILE");
102 cmd.add(gmsh_path_arg);
104 cmd.add(log_level_arg);
105 cmd.parse(argc, argv);
106
109
110 std::unique_ptr<MeshLib::Mesh const> mesh(
112 INFO(
"Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
113 mesh->getNumberOfElements());
114
117 gmsh_path_arg.getValue());
119 INFO(
"Geometry '{:s}' read: {:d} points, {:d} polylines.",
120 geo_name,
123
124 Eigen::Vector3d const dir({0.0, 0.0, -1.0});
125 double angle(90);
126
127 auto computeElementTopSurfaceAreas =
128 [](
MeshLib::Mesh const& mesh, Eigen::Vector3d
const& d,
double angle)
129 {
130 std::unique_ptr<MeshLib::Mesh> surface_mesh(
132 angle));
134 *surface_mesh);
135 };
136
137 std::vector<double> areas(computeElementTopSurfaceAreas(*mesh, dir, angle));
138 std::vector<MeshLib::Node*> all_sfc_nodes(
140 angle));
141
142 std::for_each(all_sfc_nodes.begin(), all_sfc_nodes.end(),
144
145 std::vector<MeshLib::Node*>
const& mesh_nodes(mesh->
getNodes());
147 auto const& plys(ply_vec->getVector());
148
149 for (std::size_t j(0); j < plys.size(); j++)
150 {
151 if (!plys[j]->isClosed())
152 {
153 continue;
154 }
155 std::string polygon_name;
156 ply_vec->getNameOfElement(plys[j], polygon_name);
157 if (polygon_name.empty())
158 {
159 polygon_name = "Polygon-" + std::to_string(j);
160 }
161
163
164 std::vector<std::pair<std::size_t, double>> ids_and_areas;
165 for (std::size_t k(0); k < all_sfc_nodes.size(); k++)
166 {
168 if (polygon.isPntInPolygon(surface_node))
169 {
170 ids_and_areas.emplace_back(surface_node.getID(), areas[k]);
171 }
172 }
173 if (ids_and_areas.empty())
174 {
175 ERR(
"Polygonal part of surface '{:s}' doesn't contains nodes. No "
176 "output will be generated.",
177 polygon_name);
178 continue;
179 }
180
182 std::string id_and_area_fname(out_path + polygon_name);
183 std::string csv_fname(out_path + polygon_name);
184 id_and_area_fname += std::to_string(j) + ".txt";
185 csv_fname += std::to_string(j) + ".csv";
187 "Polygonal part of surface '{}' contains {} nodes. Writing to "
188 "files '{}' and '{}'.",
189 polygon_name,
190 ids_and_areas.size(),
191 id_and_area_fname,
192 csv_fname);
193 writeToFile(id_and_area_fname, csv_fname, ids_and_areas, mesh_nodes);
194 }
195
196 std::for_each(all_sfc_nodes.begin(), all_sfc_nodes.end(),
197 std::default_delete<MeshLib::Node>());
198
199 return EXIT_SUCCESS;
200}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
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 std::vector< Point * > * getPointVec(const std::string &name) const
const PolylineVec * getPolylineVecObj(const std::string &name) const
const std::vector< Polyline * > * getPolylineVec(const std::string &name) const
The class TemplateVec takes a unique name and manages a std::vector of pointers to data elements of t...
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
void writeToFile(std::string const &id_area_fname, std::string const &csv_fname, std::vector< std::pair< std::size_t, double > > const &ids_and_areas, std::vector< MeshLib::Node * > const &mesh_nodes)
TCLAP::ValueArg< std::string > makeLogLevelArg()
void initOGSLogger(std::string const &log_level)
std::string extractPath(std::string const &pathname)
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)