Debian Codegraph @

packages/seacas/libraries/ioss/src/cgns/Iocgns_IOFactory.C

raw
1 // Copyright(C) 1999-2020, 2022, 2023, 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 "cgns/Iocgns_DatabaseIO.h" // for DatabaseIO -- serial
8 #include "cgns/Iocgns_IOFactory.h"
9 #include "cgns/Iocgns_Utils.h"
10 #include <cgnstypes.h>
11 #include <string> // for string
12
13 #include "Ioss_CodeTypes.h"
14 #include "Ioss_DBUsage.h" // for DatabaseUsage
15 #include "Ioss_IOFactory.h" // for IOFactory
16 #if CG_BUILD_PARALLEL
17 #include "cgns/Iocgns_ParallelDatabaseIO.h" // for DatabaseIO -- parallel
18 #endif
19
20 namespace Ioss {
21 class PropertyManager;
22 } // namespace Ioss
23
24 #if CG_BUILD_PARALLEL
25 namespace {
26 std::string check_decomposition_property(const Ioss::PropertyManager &properties,
27 Ioss::DatabaseUsage db_usage);
28 bool check_composition_property(const Ioss::PropertyManager &properties,
29 Ioss::DatabaseUsage db_usage);
30 } // namespace
31 #endif
32
33 namespace Iocgns {
34
35 const IOFactory *IOFactory::factory()
36 {
37 static IOFactory registerThis;
38 return &registerThis;
39 }
40
41 IOFactory::IOFactory() : Ioss::IOFactory("cgns")
42 {
43 #if CG_BUILD_PARALLEL
44 Ioss::IOFactory::alias("cgns", "dof_cgns");
45 Ioss::IOFactory::alias("cgns", "par_cgns");
46 #endif
47 }
48
49 Ioss::DatabaseIO *IOFactory::make_IO(const std::string &filename, Ioss::DatabaseUsage db_usage,
50 Ioss_MPI_Comm communicator,
51 const Ioss::PropertyManager &properties) const
52 {
53 // The "cgns" and "parallel_cgns" databases can both be accessed from
54 // this factory. The "parallel_cgns" is returned if being run on more
55 // than 1 processor unless the decomposition property is set and the
56 // value is "external" or the composition property is set with value "external"
57 #if CG_BUILD_PARALLEL
58 Ioss::ParallelUtils pu(communicator);
59 int proc_count = pu.parallel_size();
60
61 bool decompose = false;
62
63 if (proc_count > 1) {
64 decompose = true; // Default to decompose instead of file-per-processor if parallel.
65 if (db_usage == Ioss::READ_MODEL || db_usage == Ioss::READ_RESTART) {
66 std::string method = check_decomposition_property(properties, db_usage);
67 if (!method.empty() && method == "EXTERNAL") {
68 decompose = false;
69 }
70 }
71 else if (db_usage == Ioss::WRITE_RESULTS || db_usage == Ioss::WRITE_RESTART) {
72 decompose = check_composition_property(properties, db_usage);
73 }
74 }
75
76 if (decompose)
77 return new Iocgns::ParallelDatabaseIO(nullptr, filename, db_usage, communicator, properties);
78 else
79 #endif
80 return new Iocgns::DatabaseIO(nullptr, filename, db_usage, communicator, properties);
81 }
82
83 std::string IOFactory::show_config() const { return Iocgns::Utils::show_config(); }
84 } // namespace Iocgns
85
86 #if CG_BUILD_PARALLEL
87 namespace {
88 std::string check_decomposition_property(const Ioss::PropertyManager &properties,
89 Ioss::DatabaseUsage db_usage)
90 {
91 std::string decomp_method;
92 std::string decomp_property;
93 if (db_usage == Ioss::READ_MODEL) {
94 decomp_property = "MODEL_DECOMPOSITION_METHOD";
95 }
96 else if (db_usage == Ioss::READ_RESTART) {
97 decomp_property = "RESTART_DECOMPOSITION_METHOD";
98 }
99
100 // Applies to either read_model or read_restart
101 if (properties.exists("DECOMPOSITION_METHOD")) {
102 std::string method = properties.get("DECOMPOSITION_METHOD").get_string();
103 return Ioss::Utils::uppercase(method);
104 }
105
106 // Check for property...
107 if (properties.exists(decomp_property)) {
108 std::string method = properties.get(decomp_property).get_string();
109 return Ioss::Utils::uppercase(method);
110 }
111 return decomp_method;
112 }
113
114 bool check_composition_property(const Ioss::PropertyManager &properties,
115 Ioss::DatabaseUsage db_usage)
116 {
117 bool compose = true;
118 std::string compose_property = "COMPOSE_INVALID";
119 if (db_usage == Ioss::WRITE_RESULTS) {
120 compose_property = "COMPOSE_RESULTS";
121 }
122 else if (db_usage == Ioss::WRITE_RESTART) {
123 compose_property = "COMPOSE_RESTART";
124 }
125
126 Ioss::Utils::check_set_bool_property(properties, compose_property, compose);
127 return compose;
128 }
129 } // namespace
130 #endif