Debian Codegraph @

packages/seacas/libraries/ioss/src/exonull/Ioexnl_IOFactory.C

raw
1 // Copyright(C) 1999-2023 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 "exonull/Ioexnl_DatabaseIO.h" // for Ioexnl DatabaseIO
8 #include "exonull/Ioexnl_IOFactory.h" // for Ioexnl IOFactory
9
10 #if defined(PARALLEL_AWARE_EXODUS) // Defined in exodusII.h
11 #include "exonull/Ioexnl_ParallelDatabaseIO.h" // for Ioexnl ParallelDatabaseIO
12 #endif
13 #include <string> // for string
14
15 #include "Ioss_CodeTypes.h" // for Ioss_MPI_Comm
16 #include "Ioss_DBUsage.h" // for DatabaseUsage
17 #include "Ioss_IOFactory.h" // for IOFactory
18
19 #if !defined(NO_PARMETIS_SUPPORT)
20 #include <parmetis.h>
21 #endif
22
23 #if defined(PARALLEL_AWARE_EXODUS)
24 namespace {
25 std::string check_decomposition_property(const Ioss::PropertyManager &properties,
26 Ioss::DatabaseUsage db_usage);
27 bool check_composition_property(const Ioss::PropertyManager &properties,
28 Ioss::DatabaseUsage db_usage);
29 } // namespace
30 #endif
31
32 namespace Ioexnl {
33
34 const IOFactory *IOFactory::factory()
35 {
36 static IOFactory registerThis;
37 return &registerThis;
38 }
39
40 IOFactory::IOFactory() : Ioss::IOFactory("exonull") {}
41
42 Ioss::DatabaseIO *IOFactory::make_IO(const std::string &filename, Ioss::DatabaseUsage db_usage,
43 Ioss_MPI_Comm communicator,
44 const Ioss::PropertyManager &properties) const
45 {
46 #if defined(PARALLEL_AWARE_EXODUS)
47 // The "exodus" and "parallel_exodus" databases can both be accessed
48 // from this factory. The "parallel_exodus" is returned only if the following
49 // are true:
50 // 0. The db_usage is 'READ_MODEL' (not officially supported for READ_RESTART yet)
51 // 1. Parallel run with >1 processor
52 // 2. There is a DECOMPOSITION_METHOD specified in 'properties'
53 // 3. The decomposition method is not "EXTERNAL"
54
55 Ioss::ParallelUtils pu(communicator);
56 int proc_count = pu.parallel_size();
57
58 bool decompose = false;
59 if (proc_count > 1) {
60 if (db_usage == Ioss::READ_MODEL || db_usage == Ioss::READ_RESTART) {
61 std::string method = check_decomposition_property(properties, db_usage);
62 if (!method.empty() && method != "EXTERNAL") {
63 decompose = true;
64 }
65 }
66 else if (db_usage == Ioss::WRITE_RESULTS || db_usage == Ioss::WRITE_RESTART) {
67 if (check_composition_property(properties, db_usage)) {
68 decompose = true;
69 }
70 }
71 }
72
73 // Could call Ioexnl::ParallelDatabaseIO constructor directly, but that leads to some circular
74 // dependencies and other yuks.
75 if (decompose)
76 return new Ioexnl::ParallelDatabaseIO(nullptr, filename, db_usage, communicator, properties);
77 else
78 #endif
79 return new Ioexnl::DatabaseIO(nullptr, filename, db_usage, communicator, properties);
80 }
81
82 std::string IOFactory::show_config() const { return ""; }
83 } // namespace Ioexnl
84
85 #if defined(PARALLEL_AWARE_EXODUS)
86 namespace {
87 std::string check_decomposition_property(const Ioss::PropertyManager &properties,
88 Ioss::DatabaseUsage db_usage)
89 {
90 std::string decomp_method;
91 std::string decomp_property;
92 if (db_usage == Ioss::READ_MODEL) {
93 decomp_property = "MODEL_DECOMPOSITION_METHOD";
94 }
95 else if (db_usage == Ioss::READ_RESTART) {
96 decomp_property = "RESTART_DECOMPOSITION_METHOD";
97 }
98
99 // Applies to either read_model or read_restart
100 if (properties.exists("DECOMPOSITION_METHOD")) {
101 std::string method = properties.get("DECOMPOSITION_METHOD").get_string();
102 return Ioss::Utils::uppercase(method);
103 }
104
105 // Check for property...
106 if (properties.exists(decomp_property)) {
107 std::string method = properties.get(decomp_property).get_string();
108 return Ioss::Utils::uppercase(method);
109 }
110 return decomp_method;
111 }
112
113 bool check_composition_property(const Ioss::PropertyManager &properties,
114 Ioss::DatabaseUsage db_usage)
115 {
116 bool compose = false;
117 std::string compose_property = "COMPOSE_INVALID";
118 if (db_usage == Ioss::WRITE_RESULTS) {
119 compose_property = "COMPOSE_RESULTS";
120 }
121 else if (db_usage == Ioss::WRITE_RESTART) {
122 compose_property = "COMPOSE_RESTART";
123 }
124
125 Ioss::Utils::check_set_bool_property(properties, compose_property, compose);
126 return compose;
127 }
128 } // namespace
129 #endif