OGS
MergeMeshToBulkMesh.cpp File Reference
#include "MeshToolsLib/MeshEditing/MergeMeshToBulkMesh.h"
#include <tclap/CmdLine.h>
#include <algorithm>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
#include "BaseLib/FileTools.h"
#include "BaseLib/Logging.h"
#include "BaseLib/MPI.h"
#include "BaseLib/RunTime.h"
#include "BaseLib/StringTools.h"
#include "BaseLib/TCLAPArguments.h"
#include "InfoLib/GitInfo.h"
#include "MeshLib/Elements/Element.h"
#include "MeshLib/IO/VtkIO/VtuInterface.h"
#include "MeshLib/IO/readMeshFromFile.h"
#include "MeshLib/IO/writeMeshToFile.h"
#include "MeshLib/Mesh.h"
#include "MeshLib/Node.h"
Include dependency graph for Applications/Utils/MeshEdit/MergeMeshToBulkMesh/MergeMeshToBulkMesh.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 Applications/Utils/MeshEdit/MergeMeshToBulkMesh/MergeMeshToBulkMesh.cpp.

29{
30 TCLAP::CmdLine cmd(
31 "Tool merges one mesh to a bulk mesh.\n\n"
32 "OpenGeoSys-6 software, version " +
34 ".\n"
35 "Copyright (c) 2012-2026, OpenGeoSys Community "
36 "(http://www.opengeosys.org)",
38 TCLAP::ValueArg<std::string> bulk_mesh_in(
39 "b", "bulk-mesh-input-file",
40 "Input (.vtk | .msh). The name of the file containing the input bulk "
41 "mesh",
42 true, "", "INPUT_FILE");
43 cmd.add(bulk_mesh_in);
44 TCLAP::ValueArg<std::string> mesh_in(
45 "i", "mesh-input-file",
46 "Input (.vtk | .msh). The name of the file containing the input mesh "
47 "to be merged",
48 true, "", "INPUT_FILE");
49 cmd.add(mesh_in);
50 TCLAP::ValueArg<std::string> mesh_out(
51 "o", "mesh-output-file",
52 "Output (.vtk | .msh). The name of the file the merged mesh should be "
53 "written to",
54 true, "", "OUTPUT_FILE");
55 cmd.add(mesh_out);
56
57 TCLAP::ValueArg<double> p("", "pressure",
58 "initial pressure value in the mesh to be merged",
59 false, 0.0, "PRESSURE");
60 cmd.add(p);
61
62 TCLAP::ValueArg<double> pg(
63 "", "gas_pressure",
64 "initial gas pressure value in the mesh to be merged", false, 0.0,
65 "GAS_PRESSURE");
66 cmd.add(pg);
67
68 TCLAP::ValueArg<double> pc(
69 "", "capillary_pressure",
70 "initial capillary pressure value in the mesh to be merged", false, 0.0,
71 "CAPILLARY_PRESSURE");
72 cmd.add(pc);
73
74 TCLAP::ValueArg<double> T(
75 "", "temperature", "initial temperature value in the mesh to be merged",
76 false, 290.0, "TEMPERATURE");
77 cmd.add(T);
78
79 TCLAP::ValueArg<double> sxx(
80 "", "sigma_xx", "initial stress xx value in the mesh to be merged",
81 false, 0.0, "SIGMA_XX");
82 cmd.add(sxx);
83 TCLAP::ValueArg<double> syy(
84 "", "sigma_yy", "initial stress yy value in the mesh to be merged",
85 false, 0.0, "SIGMA_YY");
86 cmd.add(syy);
87 TCLAP::ValueArg<double> szz(
88 "", "sigma_zz", "initial stress zz value in the mesh to be merged",
89 false, 0.0, "SIGMA_ZZ");
90 cmd.add(szz);
91
92 TCLAP::ValueArg<int> mat_id(
93 "", "material_id", "Material ID of the mesh to be merged, (min = 0)",
94 false, 0.0, "MATERIAL_ID");
95 cmd.add(mat_id);
96 auto log_level_arg = BaseLib::makeLogLevelArg();
97 cmd.add(log_level_arg);
98
99 cmd.parse(argc, argv);
100
101 BaseLib::MPI::Setup mpi_setup(argc, argv);
102 BaseLib::initOGSLogger(log_level_arg.getValue());
103
104 BaseLib::RunTime timer;
105 timer.start();
106
107 std::unordered_map<std::string, double> initial_value_dict;
108 initial_value_dict.insert({"p", p.getValue()});
109 initial_value_dict.insert({"pg", pg.getValue()});
110 initial_value_dict.insert({"pc", pc.getValue()});
111 initial_value_dict.insert({"T", T.getValue()});
112 initial_value_dict.insert({"sxx", sxx.getValue()});
113 initial_value_dict.insert({"syy", syy.getValue()});
114 initial_value_dict.insert({"szz", szz.getValue()});
115 initial_value_dict.insert({"mat_id", mat_id.getValue()});
116
117 auto read_mesh = [](std::string const& mesh_file_name)
118 {
119 std::unique_ptr<MeshLib::Mesh> mesh(MeshLib::IO::readMeshFromFile(
120 mesh_file_name, true /* compute_element_neighbors */));
121
122 if (!mesh)
123 {
124 OGS_FATAL("Could not read the mesh {:s}", mesh_file_name);
125 }
126
127 INFO("Read {:s}: {:d} nodes, {:d} elements.", mesh_file_name,
128 mesh->getNumberOfNodes(), mesh->getNumberOfElements());
129 return mesh;
130 };
131
132 auto bulk_mesh = read_mesh(bulk_mesh_in.getValue());
133 auto const mesh_to_be_merged = read_mesh(mesh_in.getValue());
134
135 auto merged_mesh = MeshToolsLib::mergeMeshToBulkMesh(
136 *bulk_mesh, *mesh_to_be_merged, initial_value_dict);
137
138 MeshLib::IO::VtuInterface writer(merged_mesh.get());
139
140 auto const result = writer.writeToFile(mesh_out.getValue());
141 if (!result)
142 {
143 ERR("Could not write mesh to '{:s}'.", mesh_out.getValue());
144 return EXIT_FAILURE;
145 }
146 INFO("It took {} s", timer.elapsed());
147
148 // The merged nodes are moved to the new mesh, and the duplicated nodes on
149 // the mesh interface have already been deleted in
150 // MeshToolsLib::mergeMeshToBulkMesh. The elements are also moved to the
151 // merged mesh. The merged mesh object handles the release of the memory
152 // allocated for nodes and elements. Therefore, shallowClean is called.
153 mesh_to_be_merged->shallowClean();
154 bulk_mesh->shallowClean();
155
156 return EXIT_SUCCESS;
157}
#define OGS_FATAL(...)
Definition Error.h:19
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
Count the running time.
Definition RunTime.h:18
double elapsed() const
Get the elapsed time in seconds.
Definition RunTime.h:31
void start()
Start the timer.
Definition RunTime.h:21
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)
std::unique_ptr< MeshLib::Mesh > mergeMeshToBulkMesh(MeshLib::Mesh const &bulk_mesh, MeshLib::Mesh const &other_mesh, std::unordered_map< std::string, double > &initial_value_dict)

References BaseLib::RunTime::elapsed(), ERR(), INFO(), BaseLib::initOGSLogger(), BaseLib::makeLogLevelArg(), MeshToolsLib::mergeMeshToBulkMesh(), OGS_FATAL, GitInfoLib::GitInfo::ogs_version, MeshLib::IO::readMeshFromFile(), BaseLib::RunTime::start(), and MeshLib::IO::VtuInterface::writeToFile().