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

25{
26 TCLAP::CmdLine cmd(
27 "Adds a layer to an existing mesh."
28 "The documentation is available at "
29 "https://www.opengeosys.org/docs/tools/meshing/addlayer."
30 "\n"
31 "OpenGeoSys-6 software, version " +
33 ".\n"
34 "Copyright (c) 2012-2025, OpenGeoSys Community "
35 "(https://www.opengeosys.org)",
37 TCLAP::ValueArg<std::string> mesh_arg("i", "input-mesh-file",
38 "Input (.vtu). The name of the file "
39 "containing the mesh",
40 true, "", "INPUT_FILE");
41 cmd.add(mesh_arg);
42
43 TCLAP::ValueArg<std::string> mesh_out_arg(
44 "o", "output-mesh-file",
45 "Output (.vtu). The name of the file the mesh should be written to",
46 true, "", "OUTPUT_FILE");
47 cmd.add(mesh_out_arg);
48
49 TCLAP::ValueArg<double> layer_thickness_arg(
50 "t", "layer-tickness",
51 "the thickness of the new layer, "
52 "(min = 0)",
53 false, 10, "LAYER_THICKNESS");
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(
72 "", "set-material-id", "the material id of the new layer, (min = 0)",
73 false, 0, "MATERIAL_ID");
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 return EXIT_FAILURE;
82 }
83
84 BaseLib::MPI::Setup mpi_setup(argc, argv);
85
86 INFO("Reading mesh '{:s}' ... ", mesh_arg.getValue());
87 auto subsfc_mesh = std::unique_ptr<MeshLib::Mesh>(
88 MeshLib::IO::readMeshFromFile(mesh_arg.getValue(), true));
89 if (!subsfc_mesh)
90 {
91 ERR("Error reading mesh '{:s}'.", mesh_arg.getValue());
92 return EXIT_FAILURE;
93 }
94 INFO("done.");
95
96 std::optional<int> layer_id;
97 if (set_material_arg.isSet())
98 {
99 layer_id = set_material_arg.getValue();
100 }
101
102 std::unique_ptr<MeshLib::Mesh> result(MeshToolsLib::addLayerToMesh(
103 *subsfc_mesh, layer_thickness_arg.getValue(), mesh_out_arg.getValue(),
104 layer_position_arg.getValue(), copy_material_ids_arg.getValue(),
105 layer_id));
106 if (!result)
107 {
108 ERR("Failure while adding layer.");
109 return EXIT_FAILURE;
110 }
111
112 INFO("Writing mesh '{:s}' ... ", mesh_out_arg.getValue());
113 MeshLib::IO::writeMeshToFile(*result, mesh_out_arg.getValue());
114 INFO("done.");
115
116 return EXIT_SUCCESS;
117}
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().