37 std::string
const& id_area_fname, std::string
const& csv_fname,
38 std::vector<std::pair<std::size_t, double>>
const& ids_and_areas,
39 std::vector<MeshLib::Node*>
const& mesh_nodes)
41 std::ofstream ids_and_area_out(id_area_fname);
42 if (!ids_and_area_out)
44 OGS_FATAL(
"Unable to open the file '{:s}' - aborting.", id_area_fname);
46 std::ofstream csv_out(csv_fname);
49 OGS_FATAL(
"Unable to open the file '{:s}' - aborting.", csv_fname);
52 ids_and_area_out << std::setprecision(20);
53 csv_out << std::setprecision(20);
55 ids_and_area_out << ids_and_areas[0].first <<
" "
56 << ids_and_areas[0].second;
57 csv_out <<
"ID x y z area node_id\n";
58 csv_out << 0 <<
" " << *mesh_nodes[ids_and_areas[0].first]
59 << ids_and_areas[0].second <<
" " << ids_and_areas[0].first;
60 for (std::size_t k(1); k < ids_and_areas.size(); k++)
62 ids_and_area_out <<
"\n"
63 << ids_and_areas[k].first <<
" "
64 << ids_and_areas[k].second;
66 << k <<
" " << *mesh_nodes[ids_and_areas[k].first]
67 << ids_and_areas[k].second <<
" " << ids_and_areas[k].first;
69 ids_and_area_out <<
"\n";
73int main(
int argc,
char* argv[])
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 " +
85 "Copyright (c) 2012-2024, OpenGeoSys Community "
86 "(http://www.opengeosys.org)",
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 of input mesh");
93 TCLAP::ValueArg<std::string> geo_in(
94 "g",
"geo-file",
"the name of the gml file containing the polygons",
95 true,
"",
"file name of input geometry");
98 TCLAP::ValueArg<std::string> gmsh_path_arg(
"",
"gmsh-path",
99 "the path to the gmsh binary",
100 false,
"",
"path as string");
101 cmd.add(gmsh_path_arg);
102 cmd.parse(argc, argv);
105 MPI_Init(&argc, &argv);
108 std::unique_ptr<MeshLib::Mesh const> mesh(
110 INFO(
"Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
111 mesh->getNumberOfElements());
115 gmsh_path_arg.getValue());
117 INFO(
"Geometry '{:s}' read: {:d} points, {:d} polylines.",
122 Eigen::Vector3d
const dir({0.0, 0.0, -1.0});
125 auto computeElementTopSurfaceAreas =
126 [](
MeshLib::Mesh const& mesh, Eigen::Vector3d
const& d,
double angle)
128 std::unique_ptr<MeshLib::Mesh> surface_mesh(
135 std::vector<double> areas(computeElementTopSurfaceAreas(*mesh, dir, angle));
136 std::vector<MeshLib::Node*> all_sfc_nodes(
140 std::for_each(all_sfc_nodes.begin(), all_sfc_nodes.end(),
143 std::vector<MeshLib::Node*>
const& mesh_nodes(mesh->getNodes());
147 for (std::size_t j(0); j < plys.size(); j++)
149 if (!plys[j]->isClosed())
153 std::string polygon_name;
155 if (polygon_name.empty())
157 polygon_name =
"Polygon-" + std::to_string(j);
162 std::vector<std::pair<std::size_t, double>> ids_and_areas;
163 for (std::size_t k(0); k < all_sfc_nodes.size(); k++)
166 if (polygon.isPntInPolygon(surface_node))
168 ids_and_areas.emplace_back(surface_node.
getID(), areas[k]);
171 if (ids_and_areas.empty())
173 ERR(
"Polygonal part of surface '{:s}' doesn't contains nodes. No "
174 "output will be generated.",
180 std::string id_and_area_fname(out_path + polygon_name);
181 std::string csv_fname(out_path + polygon_name);
182 id_and_area_fname += std::to_string(j) +
".txt";
183 csv_fname += std::to_string(j) +
".csv";
185 "Polygonal part of surface '{}' contains {} nodes. Writing to "
186 "files '{}' and '{}'.",
188 ids_and_areas.size(),
191 writeToFile(id_and_area_fname, csv_fname, ids_and_areas, mesh_nodes);
194 std::for_each(all_sfc_nodes.begin(), all_sfc_nodes.end(),
195 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)