Debian Codegraph @

packages/seacas/libraries/ioss/src/exodus/Ioex_IOFactory.C

raw
1 // Copyright(C) 1999-2022 National Technology & Engineering Solutions
2 // of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
3 // NTESS, the U.S. Government retains certain rights in this software.
4 //
5 // See packages/seacas/LICENSE for details
6
7 #include "exodus/Ioex_DatabaseIO.h" // for Ioex DatabaseIO
8 #include "exodus/Ioex_IOFactory.h" // for Ioex IOFactory
9
10 #if defined(PARALLEL_AWARE_EXODUS) // Defined in exodusII.h
11 #include "exodus/Ioex_ParallelDatabaseIO.h" // for Ioex ParallelDatabaseIO
12 #endif
13 #include <exodusII.h>
14 #include <fmt/ostream.h>
15 #include <ostream>
16 #include <string> // for string
17
18 #include "Ioss_CodeTypes.h" // for Ioss_MPI_Comm
19 #include "Ioss_DBUsage.h" // for DatabaseUsage
20 #include "Ioss_IOFactory.h" // for IOFactory
21
22 #if !defined(NO_PARMETIS_SUPPORT)
23 #include <parmetis.h>
24 #endif
25
26 #if defined(PARALLEL_AWARE_EXODUS)
27 namespace {
28 std::string check_decomposition_property(const Ioss::PropertyManager &properties,
29 Ioss::DatabaseUsage db_usage);
30 bool check_composition_property(const Ioss::PropertyManager &properties,
31 Ioss::DatabaseUsage db_usage);
32 } // namespace
33 #endif
34
35 namespace Ioex {
36
37 const IOFactory *IOFactory::factory()
38 {
39 static IOFactory registerThis;
40 return &registerThis;
41 }
42
43 IOFactory::IOFactory() : Ioss::IOFactory("exodus")
44 {
45 Ioss::IOFactory::alias("exodus", "exodusii");
46 Ioss::IOFactory::alias("exodus", "exodusII");
47 Ioss::IOFactory::alias("exodus", "genesis");
48 #if defined(PARALLEL_AWARE_EXODUS)
49 Ioss::IOFactory::alias("exodus", "dof_exodus");
50 Ioss::IOFactory::alias("exodus", "dof");
51 #endif
52 }
53
54 Ioss::DatabaseIO *IOFactory::make_IO(const std::string &filename, Ioss::DatabaseUsage db_usage,
55 Ioss_MPI_Comm communicator,
56 const Ioss::PropertyManager &properties) const
57 {
58 #if defined(PARALLEL_AWARE_EXODUS)
59 // The "exodus" and "parallel_exodus" databases can both be accessed
60 // from this factory. The "parallel_exodus" is returned only if the following
61 // are true:
62 // 0. The db_usage is an input type.
63 // 1. Parallel run with >1 processor
64 // 2. There is a DECOMPOSITION_METHOD specified in 'properties'
65 // 3. The decomposition method is not "EXTERNAL"
66
67 Ioss::ParallelUtils pu(communicator);
68 int proc_count = pu.parallel_size();
69
70 bool decompose = false;
71 if (proc_count > 1) {
72 if (is_input_event(db_usage)) {
73 std::string method = check_decomposition_property(properties, db_usage);
74 if (!method.empty() && method != "EXTERNAL") {
75 decompose = true;
76 }
77 }
78 else {
79 if (check_composition_property(properties, db_usage)) {
80 decompose = true;
81 }
82 }
83 }
84
85 // Could call Ioex::ParallelDatabaseIO constructor directly, but that leads to some circular
86 // dependencies and other yuks.
87 if (decompose)
88 return new Ioex::ParallelDatabaseIO(nullptr, filename, db_usage, communicator, properties);
89 else
90 #endif
91 return new Ioex::DatabaseIO(nullptr, filename, db_usage, communicator, properties);
92 }
93
94 std::string IOFactory::show_config() const
95 {
96 std::stringstream config;
97 config << ex_config();
98 #if !defined(NO_PARMETIS_SUPPORT)
99 fmt::print(config,
100 "\tParMetis Library Version: {}.{}.{} (Parallel Decomposition)\n"
101 "\t\tInteger Size is {}, Real Size is {}\n\n",
102 PARMETIS_MAJOR_VERSION, PARMETIS_MINOR_VERSION, PARMETIS_SUBMINOR_VERSION,
103 IDXTYPEWIDTH, REALTYPEWIDTH);
104 #else
105 fmt::print(config, "\tParMetis Library is NOT Available for Parallel Decomposition.\n\n");
106 #endif
107 #if !defined(NO_ZOLTAN_SUPPORT)
108 fmt::print(config, "\tZoltan Library is Available for Parallel Decomposition.\n\n");
109 #else
110 fmt::print(config, "\tZoltan Library is NOT Available for Parallel Decomposition.\n\n");
111 #endif
112 return config.str();
113 }
114 } // namespace Ioex
115
116 #if defined(PARALLEL_AWARE_EXODUS)
117 namespace {
118 std::string check_decomposition_property(const Ioss::PropertyManager &properties,
119 Ioss::DatabaseUsage db_usage)
120 {
121 std::string decomp_method;
122 std::string decomp_property;
123 if (db_usage == Ioss::READ_MODEL) {
124 decomp_property = "MODEL_DECOMPOSITION_METHOD";
125 }
126 else if (db_usage == Ioss::READ_RESTART || db_usage == Ioss::QUERY_TIMESTEPS_ONLY) {
127 decomp_property = "RESTART_DECOMPOSITION_METHOD";
128 }
129
130 // Applies to either read_model or read_restart
131 if (properties.exists("DECOMPOSITION_METHOD")) {
132 std::string method = properties.get("DECOMPOSITION_METHOD").get_string();
133 return Ioss::Utils::uppercase(method);
134 }
135
136 // Check for property...
137 if (properties.exists(decomp_property)) {
138 std::string method = properties.get(decomp_property).get_string();
139 return Ioss::Utils::uppercase(method);
140 }
141 return decomp_method;
142 }
143
144 bool check_composition_property(const Ioss::PropertyManager &properties,
145 Ioss::DatabaseUsage db_usage)
146 {
147 bool compose = false;
148 std::string compose_property = "COMPOSE_INVALID";
149 if (db_usage == Ioss::WRITE_RESULTS) {
150 compose_property = "COMPOSE_RESULTS";
151 }
152 else if (db_usage == Ioss::WRITE_RESTART) {
153 compose_property = "COMPOSE_RESTART";
154 }
155
156 Ioss::Utils::check_set_bool_property(properties, compose_property, compose);
157 return compose;
158 }
159 } // namespace
160 #endif