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 cmd.parse(argc, argv);
72
73#ifdef USE_PETSC
74 MPI_Init(&argc, &argv);
75#endif
76
77 INFO("Reading mesh '{:s}' ... ", mesh_arg.getValue());
78 auto subsfc_mesh = std::unique_ptr<MeshLib::Mesh>(
79 MeshLib::IO::readMeshFromFile(mesh_arg.getValue()));
80 if (!subsfc_mesh)
81 {
82 ERR("Error reading mesh '{:s}'.", mesh_arg.getValue());
83#ifdef USE_PETSC
84 MPI_Finalize();
85#endif
86 return EXIT_FAILURE;
87 }
88 INFO("done.");
89
90 std::unique_ptr<MeshLib::Mesh> result(MeshToolsLib::addLayerToMesh(
91 *subsfc_mesh, layer_thickness_arg.getValue(), mesh_out_arg.getValue(),
92 layer_position_arg.getValue(), copy_material_ids_arg.getValue()));
93 if (!result)
94 {
95 ERR("Failure while adding layer.");
96#ifdef USE_PETSC
97 MPI_Finalize();
98#endif
99 return EXIT_FAILURE;
100 }
101
102 INFO("Writing mesh '{:s}' ... ", mesh_out_arg.getValue());
103 MeshLib::IO::writeMeshToFile(*result, mesh_out_arg.getValue());
104 INFO("done.");
105
106#ifdef USE_PETSC
107 MPI_Finalize();
108#endif
109 return EXIT_SUCCESS;
110}
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 thickness, std::string const &name, bool on_top, bool copy_material_ids)

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