34 std::string
const& id_area_fname, std::string
const& csv_fname,
35 std::vector<std::pair<std::size_t, double>>
const& ids_and_areas,
36 std::vector<MeshLib::Node*>
const& mesh_nodes)
38 std::ofstream ids_and_area_out(id_area_fname);
39 if (!ids_and_area_out)
41 OGS_FATAL(
"Unable to open the file '{:s}' - aborting.", id_area_fname);
43 std::ofstream csv_out(csv_fname);
46 OGS_FATAL(
"Unable to open the file '{:s}' - aborting.", csv_fname);
49 ids_and_area_out << std::setprecision(20);
50 csv_out << std::setprecision(20);
52 ids_and_area_out << ids_and_areas[0].first <<
" "
53 << ids_and_areas[0].second;
54 csv_out <<
"ID x y z area node_id\n";
55 csv_out << 0 <<
" " << *mesh_nodes[ids_and_areas[0].first]
56 << ids_and_areas[0].second <<
" " << ids_and_areas[0].first;
57 for (std::size_t k(1); k < ids_and_areas.size(); k++)
59 ids_and_area_out <<
"\n"
60 << ids_and_areas[k].first <<
" "
61 << ids_and_areas[k].second;
63 << k <<
" " << *mesh_nodes[ids_and_areas[k].first]
64 << ids_and_areas[k].second <<
" " << ids_and_areas[k].first;
66 ids_and_area_out <<
"\n";
70int main(
int argc,
char* argv[])
73 "Computes ids of mesh nodes that are in polygonal regions and resides "
74 "on the top surface. The polygonal regions have to be given in a gml- "
75 "or gli-file. The found mesh nodes and the associated area are written "
76 "as txt and csv data. The documentation is available at "
77 "https://docs.opengeosys.org/docs/tools/model-preparation/"
78 "computesurfacenodeidsinpolygonalregion.\n\n"
79 "OpenGeoSys-6 software, version " +
82 "Copyright (c) 2012-2024, OpenGeoSys Community "
83 "(http://www.opengeosys.org)",
85 TCLAP::ValueArg<std::string> mesh_in(
86 "m",
"mesh-input-file",
87 "the name of the file containing the input mesh",
true,
"",
88 "file name of input mesh");
90 TCLAP::ValueArg<std::string> geo_in(
91 "g",
"geo-file",
"the name of the gml file containing the polygons",
92 true,
"",
"file name of input geometry");
95 TCLAP::ValueArg<std::string> gmsh_path_arg(
"",
"gmsh-path",
96 "the path to the gmsh binary",
97 false,
"",
"path as string");
98 cmd.add(gmsh_path_arg);
99 cmd.parse(argc, argv);
103 std::unique_ptr<MeshLib::Mesh const> mesh(
105 INFO(
"Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
106 mesh->getNumberOfElements());
110 gmsh_path_arg.getValue());
112 INFO(
"Geometry '{:s}' read: {:d} points, {:d} polylines.",
117 Eigen::Vector3d
const dir({0.0, 0.0, -1.0});
120 auto computeElementTopSurfaceAreas =
121 [](
MeshLib::Mesh const& mesh, Eigen::Vector3d
const& d,
double angle)
123 std::unique_ptr<MeshLib::Mesh> surface_mesh(
130 std::vector<double> areas(computeElementTopSurfaceAreas(*mesh, dir, angle));
131 std::vector<MeshLib::Node*> all_sfc_nodes(
135 std::for_each(all_sfc_nodes.begin(), all_sfc_nodes.end(),
138 std::vector<MeshLib::Node*>
const& mesh_nodes(mesh->getNodes());
142 for (std::size_t j(0); j < plys.size(); j++)
144 if (!plys[j]->isClosed())
148 std::string polygon_name;
150 if (polygon_name.empty())
152 polygon_name =
"Polygon-" + std::to_string(j);
157 std::vector<std::pair<std::size_t, double>> ids_and_areas;
158 for (std::size_t k(0); k < all_sfc_nodes.size(); k++)
161 if (polygon.isPntInPolygon(surface_node))
163 ids_and_areas.emplace_back(surface_node.
getID(), areas[k]);
166 if (ids_and_areas.empty())
168 ERR(
"Polygonal part of surface '{:s}' doesn't contains nodes. No "
169 "output will be generated.",
175 std::string id_and_area_fname(out_path + polygon_name);
176 std::string csv_fname(out_path + polygon_name);
177 id_and_area_fname += std::to_string(j) +
".txt";
178 csv_fname += std::to_string(j) +
".csv";
180 "Polygonal part of surface '{}' contains {} nodes. Writing to "
181 "files '{}' and '{}'.",
183 ids_and_areas.size(),
186 writeToFile(id_and_area_fname, csv_fname, ids_and_areas, mesh_nodes);
189 std::for_each(all_sfc_nodes.begin(), all_sfc_nodes.end(),
190 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)