OGS
AddLayer.cpp File Reference
#include <tclap/CmdLine.h>
#include <memory>
#include "BaseLib/FileTools.h"
#include "BaseLib/Logging.h"
#include "BaseLib/MPI.h"
#include "BaseLib/TCLAPArguments.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 26 of file AddLayer.cpp.

27{
28 TCLAP::CmdLine cmd(
29 "Adds a layer to an existing mesh."
30 "The documentation is available at "
31 "https://www.opengeosys.org/docs/tools/meshing/addlayer."
32 "\n"
33 "OpenGeoSys-6 software, version " +
35 ".\n"
36 "Copyright (c) 2012-2025, OpenGeoSys Community "
37 "(https://www.opengeosys.org)",
39 TCLAP::ValueArg<std::string> mesh_arg("i", "input-mesh-file",
40 "Input (.vtu). The name of the file "
41 "containing the mesh",
42 true, "", "INPUT_FILE");
43 cmd.add(mesh_arg);
44
45 TCLAP::ValueArg<std::string> mesh_out_arg(
46 "o", "output-mesh-file",
47 "Output (.vtu). The name of the file the mesh should be written to",
48 true, "", "OUTPUT_FILE");
49 cmd.add(mesh_out_arg);
50
51 TCLAP::ValueArg<double> layer_thickness_arg(
52 "t", "layer-tickness",
53 "the thickness of the new layer, "
54 "(min = 0)",
55 false, 10, "LAYER_THICKNESS");
56 cmd.add(layer_thickness_arg);
57
58 TCLAP::SwitchArg layer_position_arg(
59 "", "add-layer-on-bottom",
60 "Per default the layer is add on the top, if this argument is set the "
61 "layer is add on the bottom.",
62 true);
63 cmd.add(layer_position_arg);
64
65 TCLAP::SwitchArg copy_material_ids_arg(
66 "", "copy-material-ids",
67 "Copy the existing material distribution of the layer which is to be "
68 "extended. If the switch isn't given a new material id will be "
69 "created.",
70 false);
71 cmd.add(copy_material_ids_arg);
72
73 TCLAP::ValueArg<int> set_material_arg(
74 "", "set-material-id", "the material id of the new layer, (min = 0)",
75 false, 0, "MATERIAL_ID");
76 cmd.add(set_material_arg);
77 auto log_level_arg = BaseLib::makeLogLevelArg();
78 cmd.add(log_level_arg);
79 cmd.parse(argc, argv);
80
81 BaseLib::MPI::Setup mpi_setup(argc, argv);
82 BaseLib::initOGSLogger(log_level_arg.getValue());
83
84 if (set_material_arg.isSet() && copy_material_ids_arg.isSet())
85 {
86 ERR("It is not possible to set both options '--copy-material-ids' and "
87 "'--set-material-id'.");
88 return EXIT_FAILURE;
89 }
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 return EXIT_FAILURE;
98 }
99 INFO("done.");
100
101 std::optional<int> layer_id;
102 if (set_material_arg.isSet())
103 {
104 layer_id = set_material_arg.getValue();
105 }
106
107 std::unique_ptr<MeshLib::Mesh> result(MeshToolsLib::addLayerToMesh(
108 *subsfc_mesh, layer_thickness_arg.getValue(), mesh_out_arg.getValue(),
109 layer_position_arg.getValue(), copy_material_ids_arg.getValue(),
110 layer_id));
111 if (!result)
112 {
113 ERR("Failure while adding layer.");
114 return EXIT_FAILURE;
115 }
116
117 INFO("Writing mesh '{:s}' ... ", mesh_out_arg.getValue());
118 MeshLib::IO::writeMeshToFile(*result, mesh_out_arg.getValue());
119 INFO("done.");
120
121 return EXIT_SUCCESS;
122}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:36
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:48
TCLAP::ValueArg< std::string > makeLogLevelArg()
void initOGSLogger(std::string const &log_level)
Definition Logging.cpp:64
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(), BaseLib::initOGSLogger(), BaseLib::makeLogLevelArg(), GitInfoLib::GitInfo::ogs_version, MeshLib::IO::readMeshFromFile(), and MeshLib::IO::writeMeshToFile().