OGS 6.1.0-1699-ge946d4c5f
IdentifySubdomains.cpp
Go to the documentation of this file.
1 
10 #include <tclap/CmdLine.h>
11 
13 #include "BaseLib/BuildInfo.h"
19 #include "MeshLib/Mesh.h"
20 
21 std::vector<std::unique_ptr<MeshLib::Mesh>> readMeshes(
22  std::vector<std::string> const& filenames)
23 {
24  std::vector<std::unique_ptr<MeshLib::Mesh>> meshes;
25  meshes.reserve(filenames.size());
26 
27  for (auto const& filename : filenames)
28  {
29  auto mesh = MeshLib::IO::readMeshFromFile(filename);
30  if (mesh == nullptr)
31  {
32  OGS_FATAL("Could not read mesh from '%s' file.", filename.c_str());
33  }
34  meshes.emplace_back(mesh);
35  }
36  if (meshes.empty())
37  {
38  OGS_FATAL("No subdomain meshes were read.");
39  }
40  return meshes;
41 }
42 
43 int main(int argc, char* argv[])
44 {
45  ApplicationsLib::LogogSetup logog_setup;
46 
47  TCLAP::CmdLine cmd(
48  "Checks if the subdomain meshes are part of the bulk mesh and writes "
49  "the 'bulk_node_ids' and the 'bulk_element_ids' in each of them.\n\n"
50  "OpenGeoSys-6 software, version " +
52  ".\n"
53  "Copyright (c) 2012-2019, OpenGeoSys Community "
54  "(http://www.opengeosys.org)",
56 
57  TCLAP::ValueArg<bool> force_overwrite_arg(
58  "f",
59  "force",
60  "Overwrites the existing subdomain meshes. (default: do not "
61  "overwrite.)",
62  false,
63  false,
64  "true/false");
65  cmd.add(force_overwrite_arg);
66 
67  TCLAP::ValueArg<std::string> output_prefix_arg(
68  "o",
69  "output_prefix",
70  "Prefix the subdomain meshes' filenames with the output prefix/path.",
71  false,
72  "",
73  "path");
74  cmd.add(output_prefix_arg);
75 
76  TCLAP::ValueArg<double> search_length_arg(
77  "s",
78  "searchlength",
79  "search length determining radius for the node search algorithm. "
80  "Non-negative floating point number (default 1e-16) ",
81  false,
82  1e-16,
83  "float");
84  cmd.add(search_length_arg);
85 
86  TCLAP::ValueArg<std::string> bulk_mesh_arg(
87  "m", "mesh", "the file name of the bulk mesh", true, "", "mesh file");
88  cmd.add(bulk_mesh_arg);
89 
90  // All the remaining arguments are used as file names for boundary/subdomain
91  // meshes.
92  TCLAP::UnlabeledMultiArg<std::string> subdomain_meshes_filenames_arg(
93  "subdomain_meshes_filenames", "mesh file names.", true,
94  "subdomain mesh file");
95  cmd.add(subdomain_meshes_filenames_arg);
96  cmd.parse(argc, argv);
97 
98  //
99  // The bulk mesh.
100  //
101  std::unique_ptr<MeshLib::Mesh> bulk_mesh{
102  MeshLib::IO::readMeshFromFile(bulk_mesh_arg.getValue())};
103  if (bulk_mesh == nullptr)
104  {
105  OGS_FATAL("Could not read bulk mesh from '%s'",
106  bulk_mesh_arg.getValue().c_str());
107  }
108 
109  //
110  // Read the subdomain meshes.
111  //
112  auto const subdomain_meshes =
113  readMeshes(subdomain_meshes_filenames_arg.getValue());
114 
115  //
116  // Bulk mesh node searcher.
117  //
118  auto const& mesh_node_searcher =
120  *bulk_mesh,
121  std::make_unique<MeshGeoToolsLib::SearchLength>(
122  search_length_arg.getValue()));
123 
124  //
125  // Identify the subdomains in the bulk mesh.
126  //
127  for (auto& mesh_ptr : subdomain_meshes)
128  {
129  // If force overwrite is set or the output is to different mesh than
130  // the input mesh.
131  bool const overwrite_property_vectors =
132  force_overwrite_arg.getValue() ||
133  !output_prefix_arg.getValue().empty();
134  identifySubdomainMesh(*mesh_ptr, *bulk_mesh, mesh_node_searcher,
135  overwrite_property_vectors);
136  }
137 
138  //
139  // Output after the successful subdomain mesh identification.
140  //
141  for (auto const& mesh_ptr : subdomain_meshes)
142  {
144  *mesh_ptr,
145  output_prefix_arg.getValue() + mesh_ptr->getName() + ".vtu");
146  }
147 
148  return EXIT_SUCCESS;
149 }
Definition of the Mesh class.
void identifySubdomainMesh(MeshLib::Mesh &subdomain_mesh, MeshLib::Mesh const &bulk_mesh, MeshNodeSearcher const &mesh_node_searcher, bool const force_overwrite=false)
MeshLib::Mesh * readMeshFromFile(const std::string &file_name)
Initialization and shutting down of the logog library.
Definition: LogogSetup.h:24
Definition of readMeshFromFile function.
int writeMeshToFile(const MeshLib::Mesh &mesh, const std::string &file_name)
BASELIB_EXPORT const std::string git_describe
std::vector< std::unique_ptr< MeshLib::Mesh > > readMeshes(std::vector< std::string > const &filenames)
static MeshNodeSearcher const & getMeshNodeSearcher(MeshLib::Mesh const &mesh, std::unique_ptr< MeshGeoToolsLib::SearchLength > &&search_length_algorithm)
#define OGS_FATAL(fmt,...)
Definition: Error.h:71
int main(int argc, char *argv[])