62{
63 TCLAP::CmdLine cmd(
64 "The tool computes the area per node of the surface mesh and writes "
65 "the information as txt and csv data.\n\n"
66 "OpenGeoSys-6 software, version " +
68 ".\n"
69 "Copyright (c) 2012-2025, OpenGeoSys Community "
70 "(http://www.opengeosys.org)",
72 TCLAP::ValueArg<std::string> mesh_in(
73 "i", "mesh-input-file",
74 "Input (.vtu). The name of the file containing the input mesh", true,
75 "", "INPUT_FILE");
76 cmd.add(mesh_in);
77
78 std::vector<std::string> allowed_types_vector{
79 "bulk_node_ids", "bulk_element_ids", "bulk_edge_ids", "bulk_face_ids"};
80 TCLAP::ValuesConstraint<std::string> allowed_types(allowed_types_vector);
81 TCLAP::ValueArg<std::string> id_prop_name(
82 "", "id-prop-name",
83 "the name of the property containing the id information", false,
84 "bulk_node_ids", &allowed_types);
85 cmd.add(id_prop_name);
86 TCLAP::ValueArg<std::string> out_base_fname(
87 "p", "output-base-name",
88 "Output (.csv | .txt). The path and base file name the output will be "
89 "written to",
90 false, "", "BASE_FILENAME_OUTPUT");
91 cmd.add(out_base_fname);
92
94 cmd.add(log_level_arg);
95 cmd.parse(argc, argv);
96
99
100 std::unique_ptr<MeshLib::Mesh> surface_mesh(
102 INFO(
"Mesh read: {:d} nodes, {:d} elements.",
103 surface_mesh->getNumberOfNodes(), surface_mesh->getNumberOfElements());
104
105
107
108
109 if (!surface_mesh->getProperties().existsPropertyVector<std::size_t>(
110 id_prop_name.getValue()))
111 {
112 orig_node_ids =
113 surface_mesh->getProperties().createNewPropertyVector<std::size_t>(
115 surface_mesh->getNumberOfNodes(), 1);
116 if (!orig_node_ids)
117 {
118 ERR(
"Fatal error: could not create property.");
119 return EXIT_FAILURE;
120 }
121 std::iota(orig_node_ids->begin(), orig_node_ids->end(), 0);
122 }
123 else
124 {
125 orig_node_ids =
126 surface_mesh->getProperties().getPropertyVector<std::size_t>(
127 id_prop_name.getValue());
128 }
129
130 std::vector<double> areas(
132 *surface_mesh));
133
134
135 std::vector<std::pair<std::size_t, double>> ids_and_areas;
136 std::transform(orig_node_ids->cbegin(), orig_node_ids->cend(),
137 areas.cbegin(), std::back_inserter(ids_and_areas),
138 std::make_pair<std::size_t const&, double const&>);
139
140
141 std::string path(out_base_fname.getValue());
142 if (path.empty())
143 {
145 }
146 std::string const id_and_area_fname(path + ".txt");
147 std::string const csv_fname(path + ".csv");
148
149 writeToFile(id_and_area_fname, csv_fname, ids_and_areas,
150 surface_mesh->getNodes());
151
152 return EXIT_SUCCESS;
153}
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)