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 40 of file identifySubdomains.cpp.

41{
42 TCLAP::CmdLine cmd(
43 "Checks if the subdomain meshes are part of the bulk mesh and writes "
44 "the 'bulk_node_ids' and the 'bulk_element_ids' in each of them. The "
45 "documentation is available at "
46 "https://www.opengeosys.org/docs/tools/meshing-submeshes/"
47 "identifysubdomains/.\n\n"
48 "OpenGeoSys-6 software, version " +
50 ".\n"
51 "Copyright (c) 2012-2026, OpenGeoSys Community "
52 "(http://www.opengeosys.org)",
54
55 TCLAP::SwitchArg force_overwrite_arg(
56 "f", "force", "Overwriting existing subdomain meshes.");
57 cmd.add(force_overwrite_arg);
58
59 TCLAP::ValueArg<std::string> output_prefix_arg(
60 "o",
61 "output_prefix",
62 "Output (.vtu). Prefix the subdomain meshes' filenames with the output "
63 "prefix/path.",
64 false,
65 "",
66 "BASE_FILENAME_OUTPUT");
67 cmd.add(output_prefix_arg);
68
69 TCLAP::ValueArg<double> search_length_arg(
70 "s",
71 "searchlength",
72 "search length determining radius for the node search algorithm. "
73 "Non-negative floating point number (min = 0) ",
74 false,
75 1e-16,
76 "SEARCH_LENGTH");
77 cmd.add(search_length_arg);
78
79 TCLAP::ValueArg<std::string> bulk_mesh_arg(
80 "m", "mesh", "Input (.vtu). The file name of the bulk mesh", true, "",
81 "INPUT_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_NAME");
89 cmd.add(subdomain_meshes_filenames_arg);
90 auto log_level_arg = BaseLib::makeLogLevelArg();
91 cmd.add(log_level_arg);
92 cmd.parse(argc, argv);
93
94 BaseLib::MPI::Setup mpi_setup(argc, argv);
95 BaseLib::initOGSLogger(log_level_arg.getValue());
96
97 // Started only here: with PETSc RunTime uses MPI_Wtime(), which is
98 // undefined before MPI_Init() and on macOS returns a value from a
99 // different epoch than the post-init clock, yielding a negative elapsed
100 // time.
101 BaseLib::RunTime run_time;
102 run_time.start();
103
104 //
105 // The bulk mesh.
106 //
107 BaseLib::RunTime mesh_reading_time;
108 mesh_reading_time.start();
109 std::unique_ptr<MeshLib::Mesh> bulk_mesh{
110 MeshLib::IO::readMeshFromFile(bulk_mesh_arg.getValue())};
111 if (bulk_mesh == nullptr)
112 {
113 OGS_FATAL("Could not read bulk mesh from '{:s}'",
114 bulk_mesh_arg.getValue());
115 }
116
117 //
118 // Read the subdomain meshes.
119 //
120 auto const subdomain_meshes =
121 readMeshes(subdomain_meshes_filenames_arg.getValue());
122 INFO("Mesh reading time: {:g} s", mesh_reading_time.elapsed());
123
124 //
125 // Bulk mesh node searcher.
126 //
127 BaseLib::RunTime mesh_node_searcher_construction_time;
128 mesh_node_searcher_construction_time.start();
129 auto const& mesh_node_searcher =
131 *bulk_mesh,
132 std::make_unique<MeshGeoToolsLib::SearchLength>(
133 search_length_arg.getValue()));
134 INFO("MeshNodeSearcher construction time: {:g} s",
135 mesh_node_searcher_construction_time.elapsed());
136
137 //
138 // Identify the subdomains in the bulk mesh.
139 //
140 BaseLib::RunTime identify_subdomain_time;
141 identify_subdomain_time.start();
142 for (auto& mesh_ptr : subdomain_meshes)
143 {
144 // If force overwrite is set or the output is to different mesh than
145 // the input mesh.
146 bool const overwrite_property_vectors =
147 force_overwrite_arg.getValue() ||
148 !output_prefix_arg.getValue().empty();
149 identifySubdomainMesh(*mesh_ptr, *bulk_mesh, mesh_node_searcher,
150 overwrite_property_vectors);
151 }
152 INFO("identifySubdomains time: {:g} s", identify_subdomain_time.elapsed());
153
154 //
155 // Output after the successful subdomain mesh identification.
156 //
157 BaseLib::RunTime writing_time;
158 writing_time.start();
159 for (auto const& mesh_ptr : subdomain_meshes)
160 {
161 if (MeshLib::IO::writeMeshToFile(*mesh_ptr,
162 output_prefix_arg.getValue() +
163 mesh_ptr->getName() + ".vtu") != 0)
164 {
165 return EXIT_FAILURE;
166 }
167 }
168 INFO("writing time: {:g} s", writing_time.elapsed());
169
170 INFO("Entire run time: {:g} s", run_time.elapsed());
171 return EXIT_SUCCESS;
172}
#define OGS_FATAL(...)
Definition Error.h:10
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:28
Count the running time.
Definition RunTime.h:18
double elapsed() const
Get the elapsed time in seconds.
Definition RunTime.h:31
void start()
Start the timer.
Definition RunTime.h:21
static OGS_NO_DANGLING 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)
TCLAP::ValueArg< std::string > makeLogLevelArg()
void initOGSLogger(std::string const &log_level)
Definition Logging.cpp:104
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 > output_variable_names, bool const use_compression, int const data_mode)

References BaseLib::RunTime::elapsed(), MeshGeoToolsLib::MeshNodeSearcher::getMeshNodeSearcher(), INFO(), BaseLib::initOGSLogger(), BaseLib::makeLogLevelArg(), 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 18 of file identifySubdomains.cpp.

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

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

Referenced by ProjectData::ProjectData(), and main().