OGS
identifySubdomains.cpp File Reference

Detailed Description

Definition in file identifySubdomains.cpp.

#include <tclap/CmdLine.h>
#include <mpi.h>
#include "BaseLib/RunTime.h"
#include "InfoLib/GitInfo.h"
#include "MeshGeoToolsLib/IdentifySubdomainMesh.h"
#include "MeshGeoToolsLib/MeshNodeSearcher.h"
#include "MeshGeoToolsLib/SearchLength.h"
#include "MeshLib/IO/readMeshFromFile.h"
#include "MeshLib/IO/writeMeshToFile.h"
#include "MeshLib/Mesh.h"
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 48 of file identifySubdomains.cpp.

49{
50 BaseLib::RunTime run_time;
51 run_time.start();
52
53 TCLAP::CmdLine cmd(
54 "Checks if the subdomain meshes are part of the bulk mesh and writes "
55 "the 'bulk_node_ids' and the 'bulk_element_ids' in each of them. The "
56 "documentation is available at "
57 "https://www.opengeosys.org/docs/tools/meshing-submeshes/"
58 "identifysubdomains/.\n\n"
59 "OpenGeoSys-6 software, version " +
61 ".\n"
62 "Copyright (c) 2012-2024, OpenGeoSys Community "
63 "(http://www.opengeosys.org)",
65
66 TCLAP::SwitchArg force_overwrite_arg(
67 "f", "force", "Overwriting existing subdomain meshes.");
68 cmd.add(force_overwrite_arg);
69
70 TCLAP::ValueArg<std::string> output_prefix_arg(
71 "o",
72 "output_prefix",
73 "Prefix the subdomain meshes' filenames with the output prefix/path.",
74 false,
75 "",
76 "path");
77 cmd.add(output_prefix_arg);
78
79 TCLAP::ValueArg<double> search_length_arg(
80 "s",
81 "searchlength",
82 "search length determining radius for the node search algorithm. "
83 "Non-negative floating point number (default 1e-16) ",
84 false,
85 1e-16,
86 "float");
87 cmd.add(search_length_arg);
88
89 TCLAP::ValueArg<std::string> bulk_mesh_arg(
90 "m", "mesh", "the file name of the bulk mesh", true, "", "mesh file");
91 cmd.add(bulk_mesh_arg);
92
93 // All the remaining arguments are used as file names for boundary/subdomain
94 // meshes.
95 TCLAP::UnlabeledMultiArg<std::string> subdomain_meshes_filenames_arg(
96 "subdomain_meshes_filenames", "mesh file names.", true,
97 "subdomain mesh file");
98 cmd.add(subdomain_meshes_filenames_arg);
99 cmd.parse(argc, argv);
100
101#ifdef USE_PETSC
102 MPI_Init(&argc, &argv);
103#endif
104
105 //
106 // The bulk mesh.
107 //
108 BaseLib::RunTime mesh_reading_time;
109 mesh_reading_time.start();
110 std::unique_ptr<MeshLib::Mesh> bulk_mesh{
111 MeshLib::IO::readMeshFromFile(bulk_mesh_arg.getValue())};
112 if (bulk_mesh == nullptr)
113 {
114 OGS_FATAL("Could not read bulk mesh from '{:s}'",
115 bulk_mesh_arg.getValue());
116 }
117
118 //
119 // Read the subdomain meshes.
120 //
121 auto const subdomain_meshes =
122 readMeshes(subdomain_meshes_filenames_arg.getValue());
123 INFO("Mesh reading time: {:g} s", mesh_reading_time.elapsed());
124
125 //
126 // Bulk mesh node searcher.
127 //
128 BaseLib::RunTime mesh_node_searcher_construction_time;
129 mesh_node_searcher_construction_time.start();
130 auto const& mesh_node_searcher =
132 *bulk_mesh,
133 std::make_unique<MeshGeoToolsLib::SearchLength>(
134 search_length_arg.getValue()));
135 INFO("MeshNodeSearcher construction time: {:g} s",
136 mesh_node_searcher_construction_time.elapsed());
137
138 //
139 // Identify the subdomains in the bulk mesh.
140 //
141 BaseLib::RunTime identify_subdomain_time;
142 identify_subdomain_time.start();
143 for (auto& mesh_ptr : subdomain_meshes)
144 {
145 // If force overwrite is set or the output is to different mesh than
146 // the input mesh.
147 bool const overwrite_property_vectors =
148 force_overwrite_arg.getValue() ||
149 !output_prefix_arg.getValue().empty();
150 identifySubdomainMesh(*mesh_ptr, *bulk_mesh, mesh_node_searcher,
151 overwrite_property_vectors);
152 }
153 INFO("identifySubdomains time: {:g} s", identify_subdomain_time.elapsed());
154
155 //
156 // Output after the successful subdomain mesh identification.
157 //
158 BaseLib::RunTime writing_time;
159 writing_time.start();
160 for (auto const& mesh_ptr : subdomain_meshes)
161 {
163 *mesh_ptr,
164 output_prefix_arg.getValue() + mesh_ptr->getName() + ".vtu");
165 }
166 INFO("writing time: {:g} s", writing_time.elapsed());
167
168#ifdef USE_PETSC
169 MPI_Finalize();
170#endif
171 INFO("Entire run time: {:g} s", run_time.elapsed());
172 return EXIT_SUCCESS;
173}
#define OGS_FATAL(...)
Definition Error.h:26
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
Count the running time.
Definition RunTime.h:29
double elapsed() const
Get the elapsed time in seconds.
Definition RunTime.h:42
void start()
Start the timer.
Definition RunTime.h:32
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, bool const compute_element_neighbors)
int writeMeshToFile(const MeshLib::Mesh &mesh, std::filesystem::path const &file_path, std::set< std::string > variable_output_names)

References BaseLib::RunTime::elapsed(), MeshGeoToolsLib::MeshNodeSearcher::getMeshNodeSearcher(), INFO(), OGS_FATAL, GitInfoLib::GitInfo::ogs_version, readMeshes(), MeshLib::IO::readMeshFromFile(), BaseLib::RunTime::start(), and MeshLib::IO::writeMeshToFile().

◆ readMeshes()

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

Definition at line 26 of file identifySubdomains.cpp.

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

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

Referenced by main().