OGS
ExtractBoundary.cpp
Go to the documentation of this file.
1 
12 #include <tclap/CmdLine.h>
13 
14 #include <algorithm>
15 #include <memory>
16 #include <string>
17 #include <vector>
18 
19 #include "BaseLib/FileTools.h"
20 #include "BaseLib/StringTools.h"
21 #include "InfoLib/GitInfo.h"
26 #include "MeshLib/Mesh.h"
28 #include "MeshLib/Node.h"
29 
30 int main(int argc, char* argv[])
31 {
32  TCLAP::CmdLine cmd(
33  "Tool extracts the boundary of the given mesh. The documentation is "
34  "available at "
35  "https://docs.opengeosys.org/docs/tools/meshing-submeshes/"
36  "extract-boundary.\n\n"
37  "OpenGeoSys-6 software, version " +
39  ".\n"
40  "Copyright (c) 2012-2021, OpenGeoSys Community "
41  "(http://www.opengeosys.org)",
43  TCLAP::ValueArg<std::string> mesh_in(
44  "i", "mesh-input-file",
45  "the name of the file containing the input mesh", true, "",
46  "file name of input mesh");
47  cmd.add(mesh_in);
48  TCLAP::ValueArg<std::string> mesh_out(
49  "o", "mesh-output-file",
50  "the name of the file the surface mesh should be written to", false, "",
51  "file name of output mesh");
52  cmd.add(mesh_out);
53 
54  TCLAP::ValueArg<std::string> node_prop_name(
55  "n", "node-property-name",
56  "the name of the data array the subsurface/bulk node id will be stored "
57  "to",
58  false, "bulk_node_ids", "string");
59  cmd.add(node_prop_name);
60  TCLAP::ValueArg<std::string> element_prop_name(
61  "e", "element-property-name",
62  "the name of the data array the subsurface/bulk element id will be "
63  "stored to",
64  false, "bulk_element_ids", "string");
65  cmd.add(element_prop_name);
66  TCLAP::ValueArg<std::string> face_prop_name(
67  "f", "face-property-name",
68  "the name of the data array the surface face id of the subsurface/bulk "
69  "element will be stored to",
70  false, "bulk_face_ids", "string");
71  cmd.add(face_prop_name);
72 
73  TCLAP::SwitchArg use_ascii_arg("", "ascii-output",
74  "If the switch is set use ascii instead of "
75  "binary format for data in the vtu output.",
76  false);
77  cmd.add(use_ascii_arg);
78 
79  cmd.parse(argc, argv);
80 
81  std::unique_ptr<MeshLib::Mesh const> mesh(
82  MeshLib::IO::readMeshFromFile(mesh_in.getValue()));
83 
84  if (!mesh)
85  {
86  return EXIT_FAILURE;
87  }
88 
89  INFO("Mesh read: {:d} nodes, {:d} elements.", mesh->getNumberOfNodes(),
90  mesh->getNumberOfElements());
91 
92  // extract surface
93  std::unique_ptr<MeshLib::Mesh> surface_mesh(
95  *mesh, node_prop_name.getValue(), element_prop_name.getValue(),
96  face_prop_name.getValue()));
97 
98  INFO("Created surface mesh: {:d} nodes, {:d} elements.",
99  surface_mesh->getNumberOfNodes(), surface_mesh->getNumberOfElements());
100 
101  std::string out_fname(mesh_out.getValue());
102  if (out_fname.empty())
103  {
104  out_fname = BaseLib::dropFileExtension(mesh_in.getValue()) + "_sfc.vtu";
105  }
106 
107  auto const data_mode =
108  use_ascii_arg.getValue() ? vtkXMLWriter::Ascii : vtkXMLWriter::Binary;
109  MeshLib::IO::writeVtu(*surface_mesh, out_fname, data_mode);
110 
111  return EXIT_SUCCESS;
112 }
Definition of the Element class.
int main(int argc, char *argv[])
Filename manipulation routines.
Git information.
void INFO(char const *fmt, Args const &... args)
Definition: Logging.h:32
Definition of the MeshSurfaceExtraction class.
Definition of the Mesh class.
Definition of the Node class.
Definition of string helper functions.
Implementation of the VtuInterface class.
std::string dropFileExtension(std::string const &filename)
Definition: FileTools.cpp:169
GITINFOLIB_EXPORT const std::string ogs_version
std::unique_ptr< MeshLib::Mesh > getBoundaryElementsAsMesh(MeshLib::Mesh const &bulk_mesh, std::string const &subsfc_node_id_prop_name, std::string const &subsfc_element_id_prop_name, std::string const &face_id_prop_name)
int writeVtu(MeshLib::Mesh const &mesh, std::string const &file_name, int const data_mode)
MeshLib::Mesh * readMeshFromFile(const std::string &file_name)
Definition of readMeshFromFile function.