OGS
AddFaultToVoxelGrid.cpp File Reference
#include "MeshToolsLib/MeshGenerators/AddFaultToVoxelGrid.h"
#include <tclap/CmdLine.h>
#include <algorithm>
#include <memory>
#include <string>
#include <vector>
#include "BaseLib/Logging.h"
#include "BaseLib/MPI.h"
#include "BaseLib/TCLAPArguments.h"
#include "InfoLib/GitInfo.h"
#include "MeshLib/IO/VtkIO/VtuInterface.h"
#include "MeshLib/IO/readMeshFromFile.h"
#include "MeshLib/Mesh.h"
Include dependency graph for Applications/Utils/MeshEdit/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 21 of file Applications/Utils/MeshEdit/AddFaultToVoxelGrid.cpp.

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

References MeshToolsLib::MeshGenerator::AddFaultToVoxelGrid::addFaultToVoxelGrid(), ERR(), INFO(), BaseLib::initOGSLogger(), BaseLib::makeLogLevelArg(), MeshLib::materialIDs(), GitInfoLib::GitInfo::ogs_version, MeshLib::IO::readMeshFromFile(), and MeshLib::IO::VtuInterface::writeToFile().