OGS
AddFaultToVoxelGrid.cpp File Reference

Detailed Description

Definition in file AddFaultToVoxelGrid.cpp.

#include <algorithm>
#include <memory>
#include <string>
#include <vector>
#include <tclap/CmdLine.h>
#include <mpi.h>
#include "InfoLib/GitInfo.h"
#include "MeshLib/IO/VtkIO/VtuInterface.h"
#include "MeshLib/IO/readMeshFromFile.h"
#include "MeshLib/Mesh.h"
#include "MeshToolsLib/MeshGenerators/AddFaultToVoxelGrid.h"
Include dependency graph for AddFaultToVoxelGrid.cpp:

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 28 of file AddFaultToVoxelGrid.cpp.

29{
30 constexpr int mat_not_set = std::numeric_limits<int>::max();
31
32 TCLAP::CmdLine cmd(
33 "Marks all elements in a voxel grid (i.e. a structured hex grid, for "
34 "instance created with Layers2Grid or Vtu2Grid) that are intersected "
35 "by a triangulated 2D mesh representing a fault or some other "
36 "significant structure. The material group for those intersected "
37 "elements can be explicitly specified, otherwise the largest existing "
38 "MaterialID will be increased by one.\n\n"
39 "OpenGeoSys-6 software, version " +
41 ".\n"
42 "Copyright (c) 2012-2024, OpenGeoSys Community "
43 "(http://www.opengeosys.org)",
45 TCLAP::ValueArg<int> id_arg("m", "material",
46 "material id for cells intersected by fault",
47 false, mat_not_set, "non-negative integer");
48 cmd.add(id_arg);
49
50 TCLAP::ValueArg<std::string> output_arg(
51 "o", "output", "name of output mesh (*.vtu)", true, "", "string");
52 cmd.add(output_arg);
53
54 TCLAP::ValueArg<std::string> fault_arg(
55 "f", "fault", "name of mesh representing fault (*.vtu)", true, "",
56 "string");
57 cmd.add(fault_arg);
58
59 TCLAP::ValueArg<std::string> input_arg(
60 "i", "input",
61 "name of the input file list containing the paths the all input layers "
62 "in correct order from top to bottom",
63 true, "", "string");
64 cmd.add(input_arg);
65 cmd.parse(argc, argv);
66
67#ifdef USE_PETSC
68 MPI_Init(&argc, &argv);
69#endif
70
71 std::string const input_name = input_arg.getValue();
72 std::string const fault_name = fault_arg.getValue();
73 std::string const output_name = output_arg.getValue();
74
76
77 std::unique_ptr<MeshLib::Mesh> mesh(
79 std::unique_ptr<MeshLib::Mesh> fault(
81 if (mesh == nullptr)
82 {
83 ERR("Input mesh not found...");
84#ifdef USE_PETSC
85 MPI_Finalize();
86#endif
87 return EXIT_FAILURE;
88 }
89 auto const& mat_ids = MeshLib::materialIDs(*mesh);
90 if (!mat_ids)
91 {
92#ifdef USE_PETSC
93 MPI_Finalize();
94#endif
95 ERR("Input mesh has no material IDs");
96 return EXIT_FAILURE;
97 }
98 int fault_id = id_arg.getValue();
99 if (!id_arg.isSet())
100 {
101 auto it = std::max_element(mat_ids->cbegin(), mat_ids->cend());
102 fault_id = *it + 1;
103 }
104 if (addFaultToVoxelGrid(mesh.get(), fault.get(), fault_id))
105 {
106 MeshLib::IO::VtuInterface vtu(mesh.get());
107 vtu.writeToFile(output_name);
108#ifdef USE_PETSC
109 MPI_Finalize();
110#endif
111 INFO("The fault was successfully added.");
112 return EXIT_SUCCESS;
113 }
114#ifdef USE_PETSC
115 MPI_Finalize();
116#endif
117 ERR("No fault could be added.");
118 return EXIT_FAILURE;
119}
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
Reads and writes VtkXMLUnstructuredGrid-files (vtu) to and from OGS data structures....
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
bool addFaultToVoxelGrid(MeshLib::Mesh *mesh, MeshLib::Mesh const *fault, int const fault_id)

References ERR(), INFO(), MeshLib::materialIDs(), GitInfoLib::GitInfo::ogs_version, MeshLib::IO::readMeshFromFile(), and MeshLib::IO::VtuInterface::writeToFile().