55{
56 TCLAP::CmdLine cmd(
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 " +
61 ".\n"
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,
68 "", "INPUT_FILE");
69 cmd.add(mesh_in);
70
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(
75 "", "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 "
82 "written to",
83 false, "", "BASE_FILENAME_OUTPUT");
84 cmd.add(out_base_fname);
85
87 cmd.add(log_level_arg);
88 cmd.parse(argc, argv);
89
92
93 std::unique_ptr<MeshLib::Mesh> surface_mesh(
95 INFO(
"Mesh read: {:d} nodes, {:d} elements.",
96 surface_mesh->getNumberOfNodes(), surface_mesh->getNumberOfElements());
97
98
100
101
102 if (!surface_mesh->getProperties().existsPropertyVector<std::size_t>(
103 id_prop_name.getValue()))
104 {
105 orig_node_ids =
106 surface_mesh->getProperties().createNewPropertyVector<std::size_t>(
108 surface_mesh->getNumberOfNodes(), 1);
109 if (!orig_node_ids)
110 {
111 ERR(
"Fatal error: could not create property.");
112 return EXIT_FAILURE;
113 }
114 std::iota(orig_node_ids->begin(), orig_node_ids->end(), 0);
115 }
116 else
117 {
118 orig_node_ids =
119 surface_mesh->getProperties().getPropertyVector<std::size_t>(
120 id_prop_name.getValue());
121 }
122
123 std::vector<double> areas(
125 *surface_mesh));
126
127
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&>);
132
133
134 std::string path(out_base_fname.getValue());
135 if (path.empty())
136 {
138 }
139 std::string const id_and_area_fname(path + ".txt");
140 std::string const csv_fname(path + ".csv");
141
142 writeToFile(id_and_area_fname, csv_fname, ids_and_areas,
143 surface_mesh->getNodes());
144
145 return EXIT_SUCCESS;
146}
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)
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
TCLAP::ValueArg< std::string > makeLogLevelArg()
void initOGSLogger(std::string const &log_level)
std::string dropFileExtension(std::string const &filename)
GITINFOLIB_EXPORT const std::string ogs_version
MeshLib::Mesh * readMeshFromFile(const std::string &file_name, bool const compute_element_neighbors)