IOSS 2.0

Iocgns_ParallelDatabaseIO.h
Go to the documentation of this file.
1 // Copyright(C) 1999-2017 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 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // * Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following
14 // disclaimer in the documentation and/or other materials provided
15 // with the distribution.
16 //
17 // * Neither the name of NTESS nor the names of its
18 // contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
33 #ifndef IOSS_Iocgns_ParallelDatabaseIO_h
34 #define IOSS_Iocgns_ParallelDatabaseIO_h
35
36 #include <Ioss_CodeTypes.h>
37 #include <Ioss_DBUsage.h> // for DatabaseUsage
38 #include <Ioss_DatabaseIO.h> // for DatabaseIO
39 #include <Ioss_IOFactory.h> // for IOFactory
40 #include <Ioss_Map.h> // for Map
41 #include <Ioss_MeshType.h>
42 #include <Ioss_State.h> // for State
43 #include <iostream> // for ostream
44 #include <memory>
45 #include <stddef.h> // for size_t
46 #include <stdint.h> // for int64_t
47 #include <string> // for string
48
49 #include <cgns/Iocgns_DecompositionData.h>
50
51 #include <cgnslib.h>
52
53 namespace Ioss {
54 class CommSet;
55 class EdgeBlock;
56 class EdgeSet;
57 class ElementBlock;
58 class ElementSet;
59 class ElementTopology;
60 class FaceBlock;
61 class FaceSet;
62 class Field;
63 class GroupingEntity;
64 class NodeBlock;
65 class NodeSet;
66 class Region;
67 class SideBlock;
68 class SideSet;
69 class EntityBlock;
70 } // namespace Ioss
71
72 namespace Iocgns {
73
74 using CGNSIntVector = std::vector<cgsize_t>;
75
76 class ParallelDatabaseIO : public Ioss::DatabaseIO
77 {
78 public:
79 enum class entity_type { NODE, ELEM };
80
81 ParallelDatabaseIO(Ioss::Region *region, const std::string &filename,
82 Ioss::DatabaseUsage db_usage, MPI_Comm communicator,
83 const Ioss::PropertyManager &props);
84
85 ~ParallelDatabaseIO();
86
87 // Check capabilities of input/output database... Returns an
88 // unsigned int with the supported Ioss::EntityTypes or'ed
89 // together. If "return_value & Ioss::EntityType" is set, then the
90 // database supports that type (e.g. return_value & Ioss::FACESET)
91 unsigned entity_field_support() const override;
92
93 int64_t node_global_to_local__(int64_t global, bool must_exist) const override;
94 int64_t element_global_to_local__(int64_t global) const override;
95
96 void release_memory__() override;
97
98 int get_file_pointer() const override;
99
100 bool node_major() const override { return false; }
101
102 bool needs_shared_node_information() const override { return false; }
103
104 // This isn't quite true since a CGNS library with cgsize_t == 64-bits can read
105 // a file with 32-bit ints. However,...
106 int int_byte_size_db() const override { return CG_SIZEOF_SIZE; }
107
108 // Metadata-related functions.
109 void read_meta_data__() override;
110 void write_meta_data();
111 void write_results_meta_data();
112
113 private:
114 void openDatabase__() const override;
115 void closeDatabase__() const override;
116
117 bool begin__(Ioss::State state) override;
118 bool end__(Ioss::State state) override;
119
120 bool begin_state__(int state, double time) override;
121 bool end_state__(int state, double time) override;
122 void flush_database__() const override;
123
124 void handle_structured_blocks();
125 void handle_unstructured_blocks();
126 size_t finalize_structured_blocks();
127 int64_t handle_node_ids(void *ids, int64_t num_to_get) const;
128 void finalize_database() override;
129 void get_step_times__() override;
130 void write_adjacency_data();
131
132 int64_t get_field_internal(const Ioss::Region *reg, const Ioss::Field &field, void *data,
133 size_t data_size) const override;
134 int64_t get_field_internal(const Ioss::NodeBlock *nb, const Ioss::Field &field, void *data,
135 size_t data_size) const override;
136 int64_t get_field_internal(const Ioss::EdgeBlock *nb, const Ioss::Field &field, void *data,
137 size_t data_size) const override;
138 int64_t get_field_internal(const Ioss::FaceBlock *nb, const Ioss::Field &field, void *data,
139 size_t data_size) const override;
140 int64_t get_field_internal(const Ioss::ElementBlock *eb, const Ioss::Field &field, void *data,
141 size_t data_size) const override;
142 int64_t get_field_internal(const Ioss::StructuredBlock *sb, const Ioss::Field &field,
143 void *data, size_t data_size) const override;
144 int64_t get_field_internal(const Ioss::SideBlock *sb, const Ioss::Field &field, void *data,
145 size_t data_size) const override;
146 int64_t get_field_internal(const Ioss::NodeSet *ns, const Ioss::Field &field, void *data,
147 size_t data_size) const override;
148 int64_t get_field_internal(const Ioss::EdgeSet *ns, const Ioss::Field &field, void *data,
149 size_t data_size) const override;
150 int64_t get_field_internal(const Ioss::FaceSet *ns, const Ioss::Field &field, void *data,
151 size_t data_size) const override;
152 int64_t get_field_internal(const Ioss::ElementSet *ns, const Ioss::Field &field, void *data,
153 size_t data_size) const override;
154 int64_t get_field_internal(const Ioss::SideSet *fs, const Ioss::Field &field, void *data,
155 size_t data_size) const override;
156 int64_t get_field_internal(const Ioss::CommSet *cs, const Ioss::Field &field, void *data,
157 size_t data_size) const override;
158
159 int64_t put_field_internal(const Ioss::Region *reg, const Ioss::Field &field, void *data,
160 size_t data_size) const override;
161 int64_t put_field_internal(const Ioss::NodeBlock *nb, const Ioss::Field &field, void *data,
162 size_t data_size) const override;
163 int64_t put_field_internal(const Ioss::EdgeBlock *nb, const Ioss::Field &field, void *data,
164 size_t data_size) const override;
165 int64_t put_field_internal(const Ioss::FaceBlock *nb, const Ioss::Field &field, void *data,
166 size_t data_size) const override;
167 int64_t put_field_internal(const Ioss::ElementBlock *eb, const Ioss::Field &field, void *data,
168 size_t data_size) const override;
169 int64_t put_field_internal(const Ioss::StructuredBlock *sb, const Ioss::Field &field,
170 void *data, size_t data_size) const override;
171 int64_t put_field_internal(const Ioss::SideBlock *fb, const Ioss::Field &field, void *data,
172 size_t data_size) const override;
173 int64_t put_field_internal(const Ioss::NodeSet *ns, const Ioss::Field &field, void *data,
174 size_t data_size) const override;
175 int64_t put_field_internal(const Ioss::EdgeSet *ns, const Ioss::Field &field, void *data,
176 size_t data_size) const override;
177 int64_t put_field_internal(const Ioss::FaceSet *ns, const Ioss::Field &field, void *data,
178 size_t data_size) const override;
179 int64_t put_field_internal(const Ioss::ElementSet *ns, const Ioss::Field &field, void *data,
180 size_t data_size) const override;
181 int64_t put_field_internal(const Ioss::SideSet *fs, const Ioss::Field &field, void *data,
182 size_t data_size) const override;
183 int64_t put_field_internal(const Ioss::CommSet *cs, const Ioss::Field &field, void *data,
184 size_t data_size) const override;
185
186 // ID Mapping functions.
187 const Ioss::Map &get_map(entity_type type) const;
188 const Ioss::Map &get_map(Ioss::Map &entity_map, int64_t entityCount, int64_t file_offset,
189 int64_t file_count, entity_type type) const;
190
191 int64_t handle_element_ids(const Ioss::ElementBlock *eb, void *ids, size_t num_to_get,
192 size_t offset, size_t count) const;
193
194 // Bulk Data
195 void resolve_zone_shared_nodes(const CGNSIntVector &nodes, CGNSIntVector &connectivity_map,
196 size_t &owned_node_count, size_t &owned_node_offset) const;
197
198 std::vector<int64_t> get_processor_zone_node_offset() const;
199
200 mutable int m_cgnsFilePtr{-1};
201 Ioss::MeshType m_meshType{Ioss::MeshType::UNKNOWN};
202
203 mutable std::unique_ptr<DecompositionDataBase> decomp;
204
205 int m_flushInterval{0}; // Default is no flushing after each timestep
206 int m_currentVertexSolutionIndex = 0;
207 int m_currentCellCenterSolutionIndex = 0;
208
209 mutable std::vector<size_t> m_zoneOffset; // Offset for local zone/block element ids to global.
210
211 mutable std::vector<size_t>
212 m_bcOffset; // The BC Section element offsets in unstructured output.
213 mutable std::vector<double> m_timesteps; // Should be able to get this from region?
214 std::map<std::string, int> m_zoneNameMap;
215 mutable std::map<int, Ioss::Map *> m_globalToBlockLocalNodeMap;
216 mutable CGNSIntVector
217 m_elemGlobalImplicitMap; // Position of this element in the global-implicit ordering
218 };
219 } // namespace Iocgns
220 #endif
Iocgns::ParallelDatabaseIO::element_global_to_local__
int64_t element_global_to_local__(int64_t global) const override
Definition: Iocgns_ParallelDatabaseIO.C:352
Ioss_CodeTypes.h
Iocgns::ParallelDatabaseIO::write_results_meta_data
void write_results_meta_data()
Definition: Iocgns_ParallelDatabaseIO.C:2265
Iocgns::ParallelDatabaseIO::get_map
const Ioss::Map & get_map(entity_type type) const
Definition: Iocgns_ParallelDatabaseIO.C:989
Iocgns::ParallelDatabaseIO::m_elemGlobalImplicitMap
CGNSIntVector m_elemGlobalImplicitMap
Definition: Iocgns_ParallelDatabaseIO.h:217
Iocgns::ParallelDatabaseIO::write_adjacency_data
void write_adjacency_data()
Definition: Iocgns_ParallelDatabaseIO.C:784
Ioss
The main namespace for the Ioss library.
Definition: Ioad_DatabaseIO.C:66
Ioss::DatabaseIO
An input or output Database.
Definition: Ioss_DatabaseIO.h:82
Ioss_DBUsage.h
Iocgns::ParallelDatabaseIO::closeDatabase__
void closeDatabase__() const override
Definition: Iocgns_ParallelDatabaseIO.C:301
Iocgns::ParallelDatabaseIO::m_cgnsFilePtr
int m_cgnsFilePtr
Definition: Iocgns_ParallelDatabaseIO.h:200
Iocgns::ParallelDatabaseIO::ParallelDatabaseIO
ParallelDatabaseIO(Ioss::Region *region, const std::string &filename, Ioss::DatabaseUsage db_usage, MPI_Comm communicator, const Ioss::PropertyManager &props)
Definition: Iocgns_ParallelDatabaseIO.C:173
Iocgns::ParallelDatabaseIO::handle_node_ids
int64_t handle_node_ids(void *ids, int64_t num_to_get) const
Definition: Iocgns_ParallelDatabaseIO.C:2273
Ioss::NodeSet
A collection of nodes.
Definition: Ioss_NodeSet.h:53
Iocgns::ParallelDatabaseIO::resolve_zone_shared_nodes
void resolve_zone_shared_nodes(const CGNSIntVector &nodes, CGNSIntVector &connectivity_map, size_t &owned_node_count, size_t &owned_node_offset) const
Definition: Iocgns_ParallelDatabaseIO.C:614
Iocgns::ParallelDatabaseIO::needs_shared_node_information
bool needs_shared_node_information() const override
Determine whether the database needs information about process ownership of nodes.
Definition: Iocgns_ParallelDatabaseIO.h:102
Iocgns::ParallelDatabaseIO::finalize_structured_blocks
size_t finalize_structured_blocks()
Definition: Iocgns_ParallelDatabaseIO.C:497
Ioss::FaceBlock
A collection of element faces with the same topology.
Definition: Ioss_FaceBlock.h:53
Iocgns::ParallelDatabaseIO::end_state__
bool end_state__(int state, double time) override
Definition: Iocgns_ParallelDatabaseIO.C:956
Ioss::FaceSet
A collection of element faces.
Definition: Ioss_FaceSet.h:54
Iocgns
A namespace for the CGNS database format.
Definition: Iocgns_DatabaseIO.C:444
Iocgns::ParallelDatabaseIO::handle_element_ids
int64_t handle_element_ids(const Ioss::ElementBlock *eb, void *ids, size_t num_to_get, size_t offset, size_t count) const
Definition: Iocgns_ParallelDatabaseIO.C:1529
Iocgns::ParallelDatabaseIO::read_meta_data__
void read_meta_data__() override
Definition: Iocgns_ParallelDatabaseIO.C:358
Ioss::EdgeSet
A collection of element edges.
Definition: Ioss_EdgeSet.h:54
Iocgns::ParallelDatabaseIO::finalize_database
void finalize_database() override
Definition: Iocgns_ParallelDatabaseIO.C:322
Ioss_Map.h
Iocgns::ParallelDatabaseIO::m_zoneOffset
std::vector< size_t > m_zoneOffset
Definition: Iocgns_ParallelDatabaseIO.h:209
Ioss::SideBlock
A collection of element sides having the same topology.
Definition: Ioss_SideBlock.h:61
Iocgns::ParallelDatabaseIO::int_byte_size_db
int int_byte_size_db() const override
Definition: Iocgns_ParallelDatabaseIO.h:106
Iocgns::CGNSIntVector
std::vector< cgsize_t > CGNSIntVector
Definition: Iocgns_ParallelDatabaseIO.h:74
Ioss_MeshType.h
Ioss_DatabaseIO.h
Ioss::State
State
Access states for a database.
Definition: Ioss_State.h:42
Iocgns::ParallelDatabaseIO::m_bcOffset
std::vector< size_t > m_bcOffset
Definition: Iocgns_ParallelDatabaseIO.h:212
Iocgns::ParallelDatabaseIO::entity_type
entity_type
Definition: Iocgns_ParallelDatabaseIO.h:79
Ioss_State.h
Ioss::ElementBlock
A collection of elements having the same topology.
Definition: Ioss_ElementBlock.h:48
Iocgns::ParallelDatabaseIO
Definition: Iocgns_ParallelDatabaseIO.h:76
Iocgns::ParallelDatabaseIO::get_step_times__
void get_step_times__() override
Definition: Iocgns_ParallelDatabaseIO.C:778
Ioss::StructuredBlock
A structured zone – i,j,k.
Definition: Ioss_StructuredBlock.h:103
Ioss::ElementSet
A collection of elements.
Definition: Ioss_ElementSet.h:54
Ioss::DatabaseUsage
DatabaseUsage
Specifies how an Ioss::DatabaseIO object will be used.
Definition: Ioss_DBUsage.h:40
Iocgns::ParallelDatabaseIO::release_memory__
void release_memory__() override
Definition: Iocgns_ParallelDatabaseIO.C:335
Iocgns::ParallelDatabaseIO::begin__
bool begin__(Ioss::State state) override
Definition: Iocgns_ParallelDatabaseIO.C:914
Ioss::ElementShape::UNKNOWN
Iocgns::ParallelDatabaseIO::~ParallelDatabaseIO
~ParallelDatabaseIO()
Definition: Iocgns_ParallelDatabaseIO.C:197
Iocgns::ParallelDatabaseIO::handle_structured_blocks
void handle_structured_blocks()
Definition: Iocgns_ParallelDatabaseIO.C:520
Ioss::NodeBlock
A collection of all nodes in the region.
Definition: Ioss_NodeBlock.h:53
Iocgns::ParallelDatabaseIO::m_currentCellCenterSolutionIndex
int m_currentCellCenterSolutionIndex
Definition: Iocgns_ParallelDatabaseIO.h:207
Iocgns::ParallelDatabaseIO::begin_state__
bool begin_state__(int state, double time) override
Definition: Iocgns_ParallelDatabaseIO.C:945
Iocgns::ParallelDatabaseIO::entity_field_support
unsigned entity_field_support() const override
Definition: Iocgns_ParallelDatabaseIO.C:2267
Iocgns::ParallelDatabaseIO::m_flushInterval
int m_flushInterval
Definition: Iocgns_ParallelDatabaseIO.h:205
Iocgns::ParallelDatabaseIO::write_meta_data
void write_meta_data()
Definition: Iocgns_ParallelDatabaseIO.C:767
Iocgns::ParallelDatabaseIO::end__
bool end__(Ioss::State state) override
Definition: Iocgns_ParallelDatabaseIO.C:920
Ioss::Map
Definition: Ioss_Map.h:52
Iocgns::ParallelDatabaseIO::decomp
std::unique_ptr< DecompositionDataBase > decomp
Definition: Iocgns_ParallelDatabaseIO.h:203
Ioss::CommSet
Definition: Ioss_CommSet.h:51
Iocgns::ParallelDatabaseIO::m_globalToBlockLocalNodeMap
std::map< int, Ioss::Map * > m_globalToBlockLocalNodeMap
Definition: Iocgns_ParallelDatabaseIO.h:215
Iocgns::ParallelDatabaseIO::entity_type::ELEM
anonymous_namespace{cth_pressure_map.C}::data
std::vector< char > data
Definition: cth_pressure_map.C:73
Ioss::Region
A grouping entity that contains other grouping entities.
Definition: Ioss_Region.h:98
Iocgns::ParallelDatabaseIO::m_meshType
Ioss::MeshType m_meshType
Definition: Iocgns_ParallelDatabaseIO.h:201
Iocgns::ParallelDatabaseIO::m_timesteps
std::vector< double > m_timesteps
Definition: Iocgns_ParallelDatabaseIO.h:213
Iocgns::ParallelDatabaseIO::m_zoneNameMap
std::map< std::string, int > m_zoneNameMap
Definition: Iocgns_ParallelDatabaseIO.h:214
Iocgns::ParallelDatabaseIO::openDatabase__
void openDatabase__() const override
Definition: Iocgns_ParallelDatabaseIO.C:217
Ioss::SideSet
A collection of element sides.
Definition: Ioss_SideSet.h:59
Ioss::Field
Holds metadata for bulk data associated with a GroupingEntity.
Definition: Ioss_Field.h:47
Iocgns_DecompositionData.h
Ioss_IOFactory.h
MPI_Comm
int MPI_Comm
Definition: Ioss_CodeTypes.h:88
Iocgns::ParallelDatabaseIO::m_currentVertexSolutionIndex
int m_currentVertexSolutionIndex
Definition: Iocgns_ParallelDatabaseIO.h:206
Ioss::MeshType
MeshType
The mesh type – structured, unstructured, hybrid (future), or unknown.
Definition: Ioss_MeshType.h:39
Iocgns::ParallelDatabaseIO::get_processor_zone_node_offset
std::vector< int64_t > get_processor_zone_node_offset() const
Definition: Iocgns_ParallelDatabaseIO.C:2332
Iocgns::ParallelDatabaseIO::entity_type::NODE
Iocgns::ParallelDatabaseIO::get_file_pointer
int get_file_pointer() const override
Definition: Iocgns_ParallelDatabaseIO.C:209
Iocgns::ParallelDatabaseIO::flush_database__
void flush_database__() const override
Definition: Iocgns_ParallelDatabaseIO.C:979
Iocgns::ParallelDatabaseIO::handle_unstructured_blocks
void handle_unstructured_blocks()
Definition: Iocgns_ParallelDatabaseIO.C:415
Ioss::PropertyManager
A collection of Ioss::Property objects.
Definition: Ioss_PropertyManager.h:49
Iocgns::ParallelDatabaseIO::put_field_internal
int64_t put_field_internal(const Ioss::Region *reg, const Ioss::Field &field, void *data, size_t data_size) const override
Definition: Iocgns_ParallelDatabaseIO.C:1560
Iocgns::ParallelDatabaseIO::node_major
bool node_major() const override
Definition: Iocgns_ParallelDatabaseIO.h:100
Ioss::EdgeBlock
A collection of element edges with the same topology.
Definition: Ioss_EdgeBlock.h:53
Iocgns::ParallelDatabaseIO::node_global_to_local__
int64_t node_global_to_local__(int64_t global, bool must_exist) const override
Definition: Iocgns_ParallelDatabaseIO.C:346
Iocgns::ParallelDatabaseIO::get_field_internal
int64_t get_field_internal(const Ioss::Region *reg, const Ioss::Field &field, void *data, size_t data_size) const override
Definition: Iocgns_ParallelDatabaseIO.C:1049