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