13 #include <tclap/CmdLine.h>
24 std::vector<std::size_t> elem_list;
25 std::vector<int>
const mat_ids =
27 std::size_t
const n_elems = mat_ids.
size();
28 for (std::size_t i = 0; i < n_elems; ++i)
30 if (mat_ids[i] != mat_id)
32 elem_list.push_back(i);
36 if (elem_list.empty())
44 int main(
int argc,
char* argv[])
47 "Takes a mesh with multiple MaterialIDs and writes elements of a given "
48 "ID into a new mesh. If no ID is specified, meshes for each existing "
49 "MaterialID are created.\n\n"
50 "OpenGeoSys-6 software, version " +
53 "Copyright (c) 2012-2021, OpenGeoSys Community "
54 "(http://www.opengeosys.org)",
56 TCLAP::ValueArg<std::size_t> arg_mat_id(
58 "The MaterialID for which elements should be extracted into a new "
60 false, 0,
"Number specifying the MaterialID");
62 TCLAP::ValueArg<std::string> output_arg(
"o",
"output",
63 "Name of the output mesh (*.vtu)",
64 true,
"",
"output file name");
66 TCLAP::ValueArg<std::string> input_arg(
"i",
"input",
67 "Name of the input mesh (*.vtu)",
68 true,
"",
"input file name");
70 cmd.parse(argc, argv);
72 std::string
const input_name = input_arg.getValue();
73 std::string
const output_name = output_arg.getValue();
77 std::unique_ptr<MeshLib::Mesh>
const mesh(
81 ERR(
"Error reading input mesh. Aborting...");
86 if (mat_ids ==
nullptr)
88 ERR(
"No material IDs found in mesh. Aborting...");
92 auto id_range = std::minmax_element(mat_ids->cbegin(), mat_ids->cend());
93 if (id_range.first == id_range.second)
95 ERR(
"Mesh only contains one material, no extraction required.");
99 if (arg_mat_id.isSet())
101 min_id =
static_cast<int>(arg_mat_id.getValue());
102 if (min_id < *id_range.first || min_id > *id_range.second)
104 ERR(
"Specified material ID does not exist.");
111 min_id = *id_range.first;
112 max_id = *id_range.second;
115 std::ofstream ostream;
116 if (min_id != max_id)
118 ostream.open(base_name +
"_Layers.txt");
121 for (
int i = min_id; i <= max_id; ++i)
123 INFO(
"Extracting material group {:d}...", i);
125 if (mat_group ==
nullptr)
127 WARN(
"No elements with material group {:d} found.", i);
131 std::string
const file_name(base_name +
"_Layer" + std::to_string(i) +
134 if (ostream.is_open())
136 ostream << file_name <<
"\n";
139 if (ostream.is_open())
void INFO(char const *fmt, Args const &... args)
void ERR(char const *fmt, Args const &... args)
void WARN(char const *fmt, Args const &... 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 const &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)
MeshLib::Mesh * removeElements(const MeshLib::Mesh &mesh, const std::vector< std::size_t > &removed_element_ids, const std::string &new_mesh_name)
PropertyVector< int > const * materialIDs(Mesh const &mesh)
Definition of readMeshFromFile function.