OGS
AddFaultToVoxelGrid.cpp
Go to the documentation of this file.
1
10#include <algorithm>
11#include <memory>
12#include <string>
13#include <vector>
14
15// ThirdParty
16#include <tclap/CmdLine.h>
17
18#include "BaseLib/MPI.h"
19#include "InfoLib/GitInfo.h"
22#include "MeshLib/Mesh.h"
24
25int main(int argc, char* argv[])
26{
27 constexpr int mat_not_set = std::numeric_limits<int>::max();
28
29 TCLAP::CmdLine cmd(
30 "Marks all elements in a voxel grid (i.e. a structured hex grid, for "
31 "instance created with Layers2Grid or Vtu2Grid) that are intersected "
32 "by a triangulated 2D mesh representing a fault or some other "
33 "significant structure. The material group for those intersected "
34 "elements can be explicitly specified, otherwise the largest existing "
35 "MaterialID will be increased by one.\n\n"
36 "OpenGeoSys-6 software, version " +
38 ".\n"
39 "Copyright (c) 2012-2024, OpenGeoSys Community "
40 "(http://www.opengeosys.org)",
42 TCLAP::ValueArg<int> id_arg("m", "material",
43 "material id for cells intersected by fault",
44 false, mat_not_set, "non-negative integer");
45 cmd.add(id_arg);
46
47 TCLAP::ValueArg<std::string> output_arg(
48 "o", "output", "name of output mesh (*.vtu)", true, "", "string");
49 cmd.add(output_arg);
50
51 TCLAP::ValueArg<std::string> fault_arg(
52 "f", "fault", "name of mesh representing fault (*.vtu)", true, "",
53 "string");
54 cmd.add(fault_arg);
55
56 TCLAP::ValueArg<std::string> input_arg(
57 "i", "input",
58 "name of the input file list containing the paths the all input layers "
59 "in correct order from top to bottom",
60 true, "", "string");
61 cmd.add(input_arg);
62 cmd.parse(argc, argv);
63
64 BaseLib::MPI::Setup mpi_setup(argc, argv);
65
66 std::string const input_name = input_arg.getValue();
67 std::string const fault_name = fault_arg.getValue();
68 std::string const output_name = output_arg.getValue();
69
71
72 std::unique_ptr<MeshLib::Mesh> mesh(
74 std::unique_ptr<MeshLib::Mesh> fault(
76 if (mesh == nullptr)
77 {
78 ERR("Input mesh not found...");
79 return EXIT_FAILURE;
80 }
81 auto const& mat_ids = MeshLib::materialIDs(*mesh);
82 if (!mat_ids)
83 {
84 ERR("Input mesh has no material IDs");
85 return EXIT_FAILURE;
86 }
87 int fault_id = id_arg.getValue();
88 if (!id_arg.isSet())
89 {
90 auto it = std::max_element(mat_ids->cbegin(), mat_ids->cend());
91 fault_id = *it + 1;
92 }
93 if (addFaultToVoxelGrid(mesh.get(), fault.get(), fault_id))
94 {
95 MeshLib::IO::VtuInterface vtu(mesh.get());
96 vtu.writeToFile(output_name);
97 INFO("The fault was successfully added.");
98 return EXIT_SUCCESS;
99 }
100 ERR("No fault could be added.");
101 return EXIT_FAILURE;
102}
int main(int argc, char *argv[])
Git information.
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45
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)
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 Mesh.cpp:268
Definition of readMeshFromFile function.