OGS
AddLayer.cpp File Reference
#include <tclap/CmdLine.h>
#include <mpi.h>
#include <memory>
#include "BaseLib/FileTools.h"
#include "InfoLib/GitInfo.h"
#include "MeshLib/IO/readMeshFromFile.h"
#include "MeshLib/IO/writeMeshToFile.h"
#include "MeshLib/Mesh.h"
#include "MeshToolsLib/MeshEditing/AddLayerToMesh.h"
Include dependency graph for AddLayer.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 27 of file AddLayer.cpp.

28{
29 TCLAP::CmdLine cmd(
30 "Adds a layer to an existing mesh."
31 "The documentation is available at "
32 "https://www.opengeosys.org/docs/tools/meshing/addlayer."
33 "\n"
34 "OpenGeoSys-6 software, version " +
36 ".\n"
37 "Copyright (c) 2012-2024, OpenGeoSys Community "
38 "(https://www.opengeosys.org)",
40 TCLAP::ValueArg<std::string> mesh_arg(
41 "i", "input-mesh-file", "the name of the file containing the mesh",
42 true, "", "file name");
43 cmd.add(mesh_arg);
44
45 TCLAP::ValueArg<std::string> mesh_out_arg(
46 "o", "output-mesh-file",
47 "the name of the file the mesh should be written to (vtu format)", true,
48 "", "file name");
49 cmd.add(mesh_out_arg);
50
51 TCLAP::ValueArg<double> layer_thickness_arg(
52 "t", "layer-tickness", "the thickness of the new layer", false, 10,
53 "floating point value");
54 cmd.add(layer_thickness_arg);
55
56 TCLAP::SwitchArg layer_position_arg(
57 "", "add-layer-on-bottom",
58 "Per default the layer is add on the top, if this argument is set the "
59 "layer is add on the bottom.",
60 true);
61 cmd.add(layer_position_arg);
62
63 TCLAP::SwitchArg copy_material_ids_arg(
64 "", "copy-material-ids",
65 "Copy the existing material distribution of the layer which is to be "
66 "extended. If the switch isn't given a new material id will be "
67 "created.",
68 false);
69 cmd.add(copy_material_ids_arg);
70
71 TCLAP::ValueArg<int> set_material_arg("", "set-material-id",
72 "the material id of the new layer",
73 false, 0, "integer value");
74 cmd.add(set_material_arg);
75 cmd.parse(argc, argv);
76
77 if (set_material_arg.isSet() && copy_material_ids_arg.isSet())
78 {
79 ERR("It is not possible to set both options '--copy-material-ids' and "
80 "'--set-material-id'.");
81#ifdef USE_PETSC
82 MPI_Finalize();
83#endif
84 return EXIT_FAILURE;
85 }
86
87#ifdef USE_PETSC
88 MPI_Init(&argc, &argv);
89#endif
90
91 INFO("Reading mesh '{:s}' ... ", mesh_arg.getValue());
92 auto subsfc_mesh = std::unique_ptr<MeshLib::Mesh>(
93 MeshLib::IO::readMeshFromFile(mesh_arg.getValue(), true));
94 if (!subsfc_mesh)
95 {
96 ERR("Error reading mesh '{:s}'.", mesh_arg.getValue());
97#ifdef USE_PETSC
98 MPI_Finalize();
99#endif
100 return EXIT_FAILURE;
101 }
102 INFO("done.");
103
104 std::optional<int> layer_id;
105 if (set_material_arg.isSet())
106 {
107 layer_id = set_material_arg.getValue();
108 }
109
110 std::unique_ptr<MeshLib::Mesh> result(MeshToolsLib::addLayerToMesh(
111 *subsfc_mesh, layer_thickness_arg.getValue(), mesh_out_arg.getValue(),
112 layer_position_arg.getValue(), copy_material_ids_arg.getValue(),
113 layer_id));
114 if (!result)
115 {
116 ERR("Failure while adding layer.");
117#ifdef USE_PETSC
118 MPI_Finalize();
119#endif
120 return EXIT_FAILURE;
121 }
122
123 INFO("Writing mesh '{:s}' ... ", mesh_out_arg.getValue());
124 MeshLib::IO::writeMeshToFile(*result, mesh_out_arg.getValue());
125 INFO("done.");
126
127#ifdef USE_PETSC
128 MPI_Finalize();
129#endif
130 return EXIT_SUCCESS;
131}
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
GITINFOLIB_EXPORT const std::string ogs_version
MeshLib::Mesh * readMeshFromFile(const std::string &file_name, bool const compute_element_neighbors)
int writeMeshToFile(const MeshLib::Mesh &mesh, std::filesystem::path const &file_path, std::set< std::string > variable_output_names)
MeshLib::Mesh * addLayerToMesh(MeshLib::Mesh const &mesh, double const thickness, std::string const &name, bool const on_top, bool const copy_material_ids, std::optional< int > const layer_id)

References MeshToolsLib::addLayerToMesh(), ERR(), INFO(), GitInfoLib::GitInfo::ogs_version, MeshLib::IO::readMeshFromFile(), and MeshLib::IO::writeMeshToFile().