13#include <tclap/CmdLine.h>
28 std::vector<std::size_t> elem_list;
29 std::vector<int>
const mat_ids =
31 std::size_t
const n_elems = mat_ids.size();
32 for (std::size_t i = 0; i < n_elems; ++i)
34 if (mat_ids[i] != mat_id)
36 elem_list.push_back(i);
40 if (elem_list.empty())
48int main(
int argc,
char* argv[])
51 "Takes a mesh with multiple MaterialIDs and writes elements of a given "
52 "ID into a new mesh. If no ID is specified, meshes for each existing "
53 "MaterialID are created.\n\n"
54 "OpenGeoSys-6 software, version " +
57 "Copyright (c) 2012-2024, OpenGeoSys Community "
58 "(http://www.opengeosys.org)",
60 TCLAP::ValueArg<std::size_t> arg_mat_id(
62 "The MaterialID for which elements should be extracted into a new "
64 false, 0,
"Number specifying the MaterialID");
66 TCLAP::ValueArg<std::string> output_arg(
"o",
"output",
67 "Name of the output mesh (*.vtu)",
68 true,
"",
"output file name");
70 TCLAP::ValueArg<std::string> input_arg(
"i",
"input",
71 "Name of the input mesh (*.vtu)",
72 true,
"",
"input file name");
74 cmd.parse(argc, argv);
77 MPI_Init(&argc, &argv);
80 std::string
const input_name = input_arg.getValue();
81 std::string
const output_name = output_arg.getValue();
85 std::unique_ptr<MeshLib::Mesh>
const mesh(
89 ERR(
"Error reading input mesh. Aborting...");
97 if (mat_ids ==
nullptr)
99 ERR(
"No material IDs found in mesh. Aborting...");
106 auto id_range = std::minmax_element(mat_ids->cbegin(), mat_ids->cend());
107 if (id_range.first == id_range.second)
109 ERR(
"Mesh only contains one material, no extraction required.");
116 if (arg_mat_id.isSet())
118 min_id =
static_cast<int>(arg_mat_id.getValue());
119 if (min_id < *id_range.first || min_id > *id_range.second)
121 ERR(
"Specified material ID does not exist.");
131 min_id = *id_range.first;
132 max_id = *id_range.second;
135 std::ofstream ostream;
136 if (min_id != max_id)
138 ostream.open(base_name +
"_Layers.txt");
141 for (
int i = min_id; i <= max_id; ++i)
143 INFO(
"Extracting material group {:d}...", i);
145 if (mat_group ==
nullptr)
147 WARN(
"No elements with material group {:d} found.", i);
151 std::string
const file_name(base_name +
"_Layer" + std::to_string(i) +
154 if (ostream.is_open())
156 ostream << file_name <<
"\n";
159 if (ostream.is_open())
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition of the Mesh class.
Implementation of the VtuInterface class.
Reads and writes VtkXMLUnstructuredGrid-files (vtu) to and from OGS data structures....
bool writeToFile(std::filesystem::path const &file_path)
Properties & getProperties()
PropertyVector< T > const * getPropertyVector(std::string_view name) const
std::string getFileExtension(const std::string &path)
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)
PropertyVector< int > const * materialIDs(Mesh const &mesh)
Definition of readMeshFromFile function.