35 std::string
const& id_area_fname, std::string
const& csv_fname,
36 std::vector<std::pair<std::size_t, double>>
const& ids_and_areas,
37 std::vector<MeshLib::Node*>
const& mesh_nodes)
39 std::ofstream ids_and_area_out(id_area_fname);
40 if (!ids_and_area_out)
42 OGS_FATAL(
"Unable to open the file '{:s}' - aborting.", id_area_fname);
44 std::ofstream csv_out(csv_fname);
47 OGS_FATAL(
"Unable to open the file '{:s}' - aborting.", csv_fname);
50 ids_and_area_out << std::setprecision(20);
51 csv_out << std::setprecision(20);
53 ids_and_area_out << ids_and_areas[0].first <<
" "
54 << ids_and_areas[0].second;
55 csv_out <<
"ID x y z area node_id\n";
56 csv_out << 0 <<
" " << *mesh_nodes[ids_and_areas[0].first]
57 << ids_and_areas[0].second <<
" " << ids_and_areas[0].first;
58 for (std::size_t k(1); k < ids_and_areas.size(); k++)
60 ids_and_area_out <<
"\n"
61 << ids_and_areas[k].first <<
" "
62 << ids_and_areas[k].second;
64 << k <<
" " << *mesh_nodes[ids_and_areas[k].first]
65 << ids_and_areas[k].second <<
" " << ids_and_areas[k].first;
67 ids_and_area_out <<
"\n";
71int main(
int argc,
char* argv[])
74 "Computes ids of mesh nodes that are in polygonal regions and resides "
75 "on the top surface. The polygonal regions have to be given in a gml- "
76 "or gli-file. The found mesh nodes and the associated area are written "
77 "as txt and csv data. The documentation is available at "
78 "https://docs.opengeosys.org/docs/tools/model-preparation/"
79 "computesurfacenodeidsinpolygonalregion.\n\n"
80 "OpenGeoSys-6 software, version " +
83 "Copyright (c) 2012-2025, OpenGeoSys Community "
84 "(http://www.opengeosys.org)",
86 TCLAP::ValueArg<std::string> mesh_in(
87 "m",
"mesh-input-file",
88 "the name of the file containing the input mesh",
true,
"",
89 "file name of input mesh");
91 TCLAP::ValueArg<std::string> geo_in(
92 "g",
"geo-file",
"the name of the gml file containing the polygons",
93 true,
"",
"file name of input geometry");
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);
104 std::unique_ptr<MeshLib::Mesh const> mesh(
106 INFO(
"Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
107 mesh->getNumberOfElements());
111 gmsh_path_arg.getValue());
113 INFO(
"Geometry '{:s}' read: {:d} points, {:d} polylines.",
118 Eigen::Vector3d
const dir({0.0, 0.0, -1.0});
121 auto computeElementTopSurfaceAreas =
122 [](
MeshLib::Mesh const& mesh, Eigen::Vector3d
const& d,
double angle)
124 std::unique_ptr<MeshLib::Mesh> surface_mesh(
131 std::vector<double> areas(computeElementTopSurfaceAreas(*mesh, dir, angle));
132 std::vector<MeshLib::Node*> all_sfc_nodes(
136 std::for_each(all_sfc_nodes.begin(), all_sfc_nodes.end(),
139 std::vector<MeshLib::Node*>
const& mesh_nodes(mesh->getNodes());
143 for (std::size_t j(0); j < plys.size(); j++)
145 if (!plys[j]->isClosed())
149 std::string polygon_name;
151 if (polygon_name.empty())
153 polygon_name =
"Polygon-" + std::to_string(j);
158 std::vector<std::pair<std::size_t, double>> ids_and_areas;
159 for (std::size_t k(0); k < all_sfc_nodes.size(); k++)
162 if (polygon.isPntInPolygon(surface_node))
164 ids_and_areas.emplace_back(surface_node.
getID(), areas[k]);
167 if (ids_and_areas.empty())
169 ERR(
"Polygonal part of surface '{:s}' doesn't contains nodes. No "
170 "output will be generated.",
176 std::string id_and_area_fname(out_path + polygon_name);
177 std::string csv_fname(out_path + polygon_name);
178 id_and_area_fname += std::to_string(j) +
".txt";
179 csv_fname += std::to_string(j) +
".csv";
181 "Polygonal part of surface '{}' contains {} nodes. Writing to "
182 "files '{}' and '{}'.",
184 ids_and_areas.size(),
187 writeToFile(id_and_area_fname, csv_fname, ids_and_areas, mesh_nodes);
190 std::for_each(all_sfc_nodes.begin(), all_sfc_nodes.end(),
191 std::default_delete<MeshLib::Node>());
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)