Loading [MathJax]/extensions/tex2jax.js
OGS
identifySubdomains.cpp File Reference
Include dependency graph for identifySubdomains.cpp:

Go to the source code of this file.

Functions

std::vector< std::unique_ptr< MeshLib::Mesh > > readMeshes (std::vector< std::string > const &filenames)
 
int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 42 of file identifySubdomains.cpp.

43 {
44  TCLAP::CmdLine cmd(
45  "Checks if the subdomain meshes are part of the bulk mesh and writes "
46  "the 'bulk_node_ids' and the 'bulk_element_ids' in each of them. The "
47  "documentation is available at "
48  "https://www.opengeosys.org/docs/tools/meshing-submeshes/"
49  "identifysubdomains/.\n\n"
50  "OpenGeoSys-6 software, version " +
52  ".\n"
53  "Copyright (c) 2012-2021, OpenGeoSys Community "
54  "(http://www.opengeosys.org)",
56 
57  TCLAP::SwitchArg force_overwrite_arg(
58  "f", "force", "Overwriting existing subdomain meshes.");
59  cmd.add(force_overwrite_arg);
60 
61  TCLAP::ValueArg<std::string> output_prefix_arg(
62  "o",
63  "output_prefix",
64  "Prefix the subdomain meshes' filenames with the output prefix/path.",
65  false,
66  "",
67  "path");
68  cmd.add(output_prefix_arg);
69 
70  TCLAP::ValueArg<double> search_length_arg(
71  "s",
72  "searchlength",
73  "search length determining radius for the node search algorithm. "
74  "Non-negative floating point number (default 1e-16) ",
75  false,
76  1e-16,
77  "float");
78  cmd.add(search_length_arg);
79 
80  TCLAP::ValueArg<std::string> bulk_mesh_arg(
81  "m", "mesh", "the file name of the bulk mesh", true, "", "mesh file");
82  cmd.add(bulk_mesh_arg);
83 
84  // All the remaining arguments are used as file names for boundary/subdomain
85  // meshes.
86  TCLAP::UnlabeledMultiArg<std::string> subdomain_meshes_filenames_arg(
87  "subdomain_meshes_filenames", "mesh file names.", true,
88  "subdomain mesh file");
89  cmd.add(subdomain_meshes_filenames_arg);
90  cmd.parse(argc, argv);
91 
92  //
93  // The bulk mesh.
94  //
95  std::unique_ptr<MeshLib::Mesh> bulk_mesh{
96  MeshLib::IO::readMeshFromFile(bulk_mesh_arg.getValue())};
97  if (bulk_mesh == nullptr)
98  {
99  OGS_FATAL("Could not read bulk mesh from '{:s}'",
100  bulk_mesh_arg.getValue());
101  }
102 
103  //
104  // Read the subdomain meshes.
105  //
106  auto const subdomain_meshes =
107  readMeshes(subdomain_meshes_filenames_arg.getValue());
108 
109  //
110  // Bulk mesh node searcher.
111  //
112  auto const& mesh_node_searcher =
114  *bulk_mesh,
115  std::make_unique<MeshGeoToolsLib::SearchLength>(
116  search_length_arg.getValue()));
117 
118  //
119  // Identify the subdomains in the bulk mesh.
120  //
121  for (auto& mesh_ptr : subdomain_meshes)
122  {
123  // If force overwrite is set or the output is to different mesh than
124  // the input mesh.
125  bool const overwrite_property_vectors =
126  force_overwrite_arg.getValue() ||
127  !output_prefix_arg.getValue().empty();
128  identifySubdomainMesh(*mesh_ptr, *bulk_mesh, mesh_node_searcher,
129  overwrite_property_vectors);
130  }
131 
132  //
133  // Output after the successful subdomain mesh identification.
134  //
135  for (auto const& mesh_ptr : subdomain_meshes)
136  {
138  *mesh_ptr,
139  output_prefix_arg.getValue() + mesh_ptr->getName() + ".vtu");
140  }
141 
142  return EXIT_SUCCESS;
143 }
#define OGS_FATAL(...)
Definition: Error.h:26
static MeshNodeSearcher const & getMeshNodeSearcher(MeshLib::Mesh const &mesh, std::unique_ptr< MeshGeoToolsLib::SearchLength > &&search_length_algorithm)
std::vector< std::unique_ptr< MeshLib::Mesh > > readMeshes(std::vector< std::string > const &filenames)
GITINFOLIB_EXPORT const std::string ogs_version
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)
int writeMeshToFile(const MeshLib::Mesh &mesh, std::filesystem::path const &file_path, [[maybe_unused]] std::set< std::string > variable_output_names)

References MeshGeoToolsLib::MeshNodeSearcher::getMeshNodeSearcher(), MeshGeoToolsLib::identifySubdomainMesh(), OGS_FATAL, GitInfoLib::GitInfo::ogs_version, readMeshes(), MeshLib::IO::readMeshFromFile(), and MeshLib::IO::writeMeshToFile().

◆ readMeshes()

std::vector<std::unique_ptr<MeshLib::Mesh> > readMeshes ( std::vector< std::string > const &  filenames)

Definition at line 20 of file identifySubdomains.cpp.

22 {
23  std::vector<std::unique_ptr<MeshLib::Mesh>> meshes;
24  meshes.reserve(filenames.size());
25 
26  for (auto const& filename : filenames)
27  {
28  auto mesh = MeshLib::IO::readMeshFromFile(filename);
29  if (mesh == nullptr)
30  {
31  OGS_FATAL("Could not read mesh from '{:s}' file.", filename);
32  }
33  meshes.emplace_back(mesh);
34  }
35  if (meshes.empty())
36  {
37  OGS_FATAL("No subdomain meshes were read.");
38  }
39  return meshes;
40 }

References OGS_FATAL, and MeshLib::IO::readMeshFromFile().

Referenced by main().