65{
66 TCLAP::CmdLine cmd(
67 "Computes ids of mesh nodes that are in polygonal regions and resides "
68 "on the top surface. The polygonal regions have to be given in a gml- "
69 "or gli-file. The found mesh nodes and the associated area are written "
70 "as txt and csv data. The documentation is available at "
71 "https://docs.opengeosys.org/docs/tools/model-preparation/"
72 "computesurfacenodeidsinpolygonalregion.\n\n"
73 "OpenGeoSys-6 software, version " +
75 ".\n"
76 "Copyright (c) 2012-2026, OpenGeoSys Community "
77 "(http://www.opengeosys.org)",
79 TCLAP::ValueArg<std::string> mesh_in(
80 "m", "mesh-input-file",
81 "Input (.vtu). The name of the file containing the input mesh", true,
82 "", "INPUT_FILE");
83 cmd.add(mesh_in);
84 TCLAP::ValueArg<std::string> geo_in(
85 "g", "geo-file",
86 "Input (.gml). The name of the input file containing the polygons",
87 true, "", "INPUT_FILE");
88 cmd.add(geo_in);
89
90 TCLAP::ValueArg<std::string> gmsh_path_arg(
91 "", "gmsh-path", "Input (.msh). The path to the input binary file",
92 false, "", "INPUT_FILE");
93 cmd.add(gmsh_path_arg);
95 cmd.add(log_level_arg);
96 cmd.parse(argc, argv);
97
100
101 std::unique_ptr<MeshLib::Mesh const> mesh(
103 INFO(
"Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
104 mesh->getNumberOfElements());
105
108 gmsh_path_arg.getValue());
110 INFO(
"Geometry '{:s}' read: {:d} points, {:d} polylines.",
111 geo_name,
114
115 Eigen::Vector3d const dir({0.0, 0.0, -1.0});
116 double angle(90);
117
118 auto computeElementTopSurfaceAreas =
119 [](
MeshLib::Mesh const& mesh, Eigen::Vector3d
const& d,
double angle)
120 {
121 std::unique_ptr<MeshLib::Mesh> surface_mesh(
123 angle));
125 *surface_mesh);
126 };
127
128 std::vector<double> areas(computeElementTopSurfaceAreas(*mesh, dir, angle));
129 std::vector<MeshLib::Node*> all_sfc_nodes(
131 angle));
132
133 std::for_each(all_sfc_nodes.begin(), all_sfc_nodes.end(),
135
136 std::vector<MeshLib::Node*>
const& mesh_nodes(mesh->
getNodes());
138 auto const& plys(ply_vec->getVector());
139
140 for (std::size_t j(0); j < plys.size(); j++)
141 {
142 if (!plys[j]->isClosed())
143 {
144 continue;
145 }
146 std::string polygon_name;
147 ply_vec->getNameOfElement(plys[j], polygon_name);
148 if (polygon_name.empty())
149 {
150 polygon_name = "Polygon-" + std::to_string(j);
151 }
152
154
155 std::vector<std::pair<std::size_t, double>> ids_and_areas;
156 for (std::size_t k(0); k < all_sfc_nodes.size(); k++)
157 {
160 {
161 ids_and_areas.emplace_back(surface_node.getID(), areas[k]);
162 }
163 }
164 if (ids_and_areas.empty())
165 {
166 ERR(
"Polygonal part of surface '{:s}' doesn't contains nodes. No "
167 "output will be generated.",
168 polygon_name);
169 continue;
170 }
171
173 std::string id_and_area_fname(out_path + polygon_name);
174 std::string csv_fname(out_path + polygon_name);
175 id_and_area_fname += std::to_string(j) + ".txt";
176 csv_fname += std::to_string(j) + ".csv";
178 "Polygonal part of surface '{}' contains {} nodes. Writing to "
179 "files '{}' and '{}'.",
180 polygon_name,
181 ids_and_areas.size(),
182 id_and_area_fname,
183 csv_fname);
184 writeToFile(id_and_area_fname, csv_fname, ids_and_areas, mesh_nodes);
185 }
186
187 std::for_each(all_sfc_nodes.begin(), all_sfc_nodes.end(),
188 std::default_delete<MeshLib::Node>());
189
190 return EXIT_SUCCESS;
191}
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
bool isPntInPolygon(MathLib::Point3d const &pnt) const
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)
TemplateVec< GeoLib::Polyline > PolylineVec
class PolylineVec encapsulate a std::vector of Polylines additional one can give the vector of polyli...
GITINFOLIB_EXPORT const std::string ogs_version
MeshLib::Mesh * readMeshFromFile(const std::string &file_name, bool const compute_element_neighbors)