OGS
AddLayer.cpp
Go to the documentation of this file.
1 /*
2  * \file
3  * \brief Adds a layer to an existing mesh.
4  *
5  * \copyright
6  * Copyright (c) 2012-2021, OpenGeoSys Community (http://www.opengeosys.org)
7  * Distributed under a Modified BSD License.
8  * See accompanying file LICENSE.txt or
9  * http://www.opengeosys.org/project/license
10  */
11 
12 #include <tclap/CmdLine.h>
13 
14 #include <memory>
15 
16 #include "BaseLib/FileTools.h"
17 #include "InfoLib/GitInfo.h"
20 #include "MeshLib/Mesh.h"
22 
23 int main(int argc, char* argv[])
24 {
25  TCLAP::CmdLine cmd(
26  "Adds a layer to an existing mesh."
27  "The documentation is available at "
28  "https://docs.opengeosys.org/docs/tools/meshing/addlayer.\n\n"
29  "OpenGeoSys-6 software, version " +
31  ".\n"
32  "Copyright (c) 2012-2021, OpenGeoSys Community "
33  "(http://www.opengeosys.org)",
35  TCLAP::ValueArg<std::string> mesh_arg(
36  "i", "input-mesh-file", "the name of the file containing the mesh",
37  true, "", "file name");
38  cmd.add(mesh_arg);
39 
40  TCLAP::ValueArg<std::string> mesh_out_arg(
41  "o", "output-mesh-file",
42  "the name of the file the mesh should be written to (vtu format)", true,
43  "", "file name");
44  cmd.add(mesh_out_arg);
45 
46  TCLAP::ValueArg<double> layer_thickness_arg(
47  "t", "layer-tickness", "the thickness of the new layer", false, 10,
48  "floating point value");
49  cmd.add(layer_thickness_arg);
50 
51  TCLAP::SwitchArg layer_position_arg(
52  "", "add-layer-on-bottom",
53  "Per default the layer is add on the top, if this argument is set the "
54  "layer is add on the bottom.",
55  true);
56  cmd.add(layer_position_arg);
57 
58  TCLAP::SwitchArg copy_material_ids_arg(
59  "", "copy-material-ids",
60  "Copy the existing material distribution of the layer which is to be "
61  "extended. If the switch isn't given a new material id will be "
62  "created.",
63  false);
64  cmd.add(copy_material_ids_arg);
65 
66  cmd.parse(argc, argv);
67 
68  INFO("Reading mesh '{:s}' ... ", mesh_arg.getValue());
69  auto subsfc_mesh = std::unique_ptr<MeshLib::Mesh>(
70  MeshLib::IO::readMeshFromFile(mesh_arg.getValue()));
71  if (!subsfc_mesh)
72  {
73  ERR("Error reading mesh '{:s}'.", mesh_arg.getValue());
74  return EXIT_FAILURE;
75  }
76  INFO("done.");
77 
78  std::unique_ptr<MeshLib::Mesh> result(MeshLib::addLayerToMesh(
79  *subsfc_mesh, layer_thickness_arg.getValue(), mesh_out_arg.getValue(),
80  layer_position_arg.getValue(), copy_material_ids_arg.getValue()));
81  if (!result)
82  {
83  ERR("Failure while adding layer.");
84  return EXIT_FAILURE;
85  }
86 
87  INFO("Writing mesh '{:s}' ... ", mesh_out_arg.getValue());
88  MeshLib::IO::writeMeshToFile(*result, mesh_out_arg.getValue());
89  INFO("done.");
90 
91  return EXIT_SUCCESS;
92 }
Definition of AddLayerToMesh class.
int main(int argc, char *argv[])
Definition: AddLayer.cpp:23
Filename manipulation routines.
Git information.
void INFO(char const *fmt, Args const &... args)
Definition: Logging.h:32
void ERR(char const *fmt, Args const &... args)
Definition: Logging.h:42
Definition of the Mesh class.
GITINFOLIB_EXPORT const std::string ogs_version
MeshLib::Mesh * readMeshFromFile(const std::string &file_name)
int writeMeshToFile(const MeshLib::Mesh &mesh, std::filesystem::path const &file_path, [[maybe_unused]] 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)
Definition of readMeshFromFile function.