24 std::string
const& id_area_fname, std::string
const& csv_fname,
25 std::vector<std::pair<std::size_t, double>>
const& ids_and_areas,
26 std::vector<MeshLib::Node*>
const& mesh_nodes)
28 std::ofstream ids_and_area_out(id_area_fname);
29 if (!ids_and_area_out)
31 OGS_FATAL(
"Unable to open the file '{:s}' - aborting.", id_area_fname);
33 std::ofstream csv_out(csv_fname);
36 OGS_FATAL(
"Unable to open the file '{:s}' - aborting.", csv_fname);
39 ids_and_area_out.precision(std::numeric_limits<double>::max_digits10);
40 csv_out.precision(std::numeric_limits<double>::max_digits10);
42 csv_out <<
"ID x y z area node_id\n";
43 for (std::size_t k(0); k < ids_and_areas.size(); k++)
45 ids_and_area_out << ids_and_areas[k].first <<
" "
46 << ids_and_areas[k].second <<
"\n";
47 csv_out << k <<
" " << *(mesh_nodes[k]) << ids_and_areas[k].second
48 <<
" " << ids_and_areas[k].first <<
"\n";
50 ids_and_area_out <<
"\n";
54int main(
int argc,
char* argv[])
57 "The tool computes the area per node of the surface mesh and writes "
58 "the information as txt and csv data.\n\n"
59 "OpenGeoSys-6 software, version " +
62 "Copyright (c) 2012-2026, OpenGeoSys Community "
63 "(http://www.opengeosys.org)",
65 TCLAP::ValueArg<std::string> mesh_in(
66 "i",
"mesh-input-file",
67 "Input (.vtu). The name of the file containing the input mesh",
true,
71 std::vector<std::string> allowed_types_vector{
72 "bulk_node_ids",
"bulk_element_ids",
"bulk_edge_ids",
"bulk_face_ids"};
73 TCLAP::ValuesConstraint<std::string> allowed_types(allowed_types_vector);
74 TCLAP::ValueArg<std::string> id_prop_name(
76 "the name of the property containing the id information",
false,
77 "bulk_node_ids", &allowed_types);
78 cmd.add(id_prop_name);
79 TCLAP::ValueArg<std::string> out_base_fname(
80 "p",
"output-base-name",
81 "Output (.csv | .txt). The path and base file name the output will be "
83 false,
"",
"BASE_FILENAME_OUTPUT");
84 cmd.add(out_base_fname);
87 cmd.add(log_level_arg);
88 cmd.parse(argc, argv);
93 std::unique_ptr<MeshLib::Mesh> surface_mesh(
95 INFO(
"Mesh read: {:d} nodes, {:d} elements.",
96 surface_mesh->getNumberOfNodes(), surface_mesh->getNumberOfElements());
102 if (!surface_mesh->getProperties().existsPropertyVector<std::size_t>(
103 id_prop_name.getValue()))
106 surface_mesh->getProperties().createNewPropertyVector<std::size_t>(
108 surface_mesh->getNumberOfNodes(), 1);
111 ERR(
"Fatal error: could not create property.");
114 std::iota(orig_node_ids->
begin(), orig_node_ids->
end(), 0);
119 surface_mesh->getProperties().getPropertyVector<std::size_t>(
120 id_prop_name.getValue());
123 std::vector<double> areas(
128 std::vector<std::pair<std::size_t, double>> ids_and_areas;
129 std::transform(orig_node_ids->
cbegin(), orig_node_ids->
cend(),
130 areas.cbegin(), std::back_inserter(ids_and_areas),
131 std::make_pair<std::size_t const&, double const&>);
134 std::string path(out_base_fname.getValue());
139 std::string
const id_and_area_fname(path +
".txt");
140 std::string
const csv_fname(path +
".csv");
142 writeToFile(id_and_area_fname, csv_fname, ids_and_areas,
143 surface_mesh->getNodes());
static 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)