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_State.h> // for State
42 #include <iostream> // for ostream
43 #include <memory>
44 #include <stddef.h> // for size_t
45 #include <stdint.h> // for int64_t
46 #include <string> // for string
47
48 #include <cgns/Iocgns_DecompositionData.h>
49
50 #include <cgnslib.h>
51
52 namespace Ioss {
53 class CommSet;
54 class EdgeBlock;
55 class EdgeSet;
56 class ElementBlock;
57 class ElementSet;
58 class ElementTopology;
59 class FaceBlock;
60 class FaceSet;
61 class Field;
62 class GroupingEntity;
63 class NodeBlock;
64 class NodeSet;
65 class Region;
66 class SideBlock;
67 class SideSet;
68 class EntityBlock;
69 } // namespace Ioss
70
71 namespace Iocgns {
72
73 using CGNSIntVector = std::vector<cgsize_t>;
74
75 class ParallelDatabaseIO : public Ioss::DatabaseIO
76 {
77 public:
78 enum class entity_type { NODE, ELEM };
79
80 ParallelDatabaseIO(Ioss::Region *region, const std::string &filename,
81 Ioss::DatabaseUsage db_usage, MPI_Comm communicator,
82 const Ioss::PropertyManager &props);
83
84 ~ParallelDatabaseIO();
85
86 // Check capabilities of input/output database... Returns an
87 // unsigned int with the supported Ioss::EntityTypes or'ed
88 // together. If "return_value & Ioss::EntityType" is set, then the
89 // database supports that type (e.g. return_value & Ioss::FACESET)
90 unsigned entity_field_support() const override;
91
92 int64_t node_global_to_local__(int64_t global, bool must_exist) const override;
93 int64_t element_global_to_local__(int64_t global) const override;
94
95 void release_memory__() override;
96
97 void openDatabase__() const override;
98 void closeDatabase__() const override;
99 bool node_major() const override { return false; }
100
101 bool needs_shared_node_information() const override { return false; }
102
103 // This isn't quite true since a CGNS library with cgsize_t == 64-bits can read
104 // a file with 32-bit ints. However,...
105 int int_byte_size_db() const override { return CG_SIZEOF_SIZE; }
106
107 bool begin__(Ioss::State state) override;
108 bool end__(Ioss::State state) override;
109
110 bool begin_state__(Ioss::Region *region, int state, double time) override;
111 bool end_state__(Ioss::Region *region, int state, double time) override;
112
113 // Metadata-related functions.
114 void read_meta_data__() override;
115 void write_meta_data();
116 void write_results_meta_data();
117
118 private:
119 void handle_structured_blocks();
120 void handle_unstructured_blocks();
121 size_t finalize_structured_blocks();
122 int64_t handle_node_ids(void *ids, int64_t num_to_get) const;
123 void finalize_database() override;
124 void get_step_times__() override;
125 void write_adjacency_data();
126
127 int64_t get_field_internal(const Ioss::Region *reg, const Ioss::Field &field, void *data,
128 size_t data_size) const override;
129 int64_t get_field_internal(const Ioss::NodeBlock *nb, const Ioss::Field &field, void *data,
130 size_t data_size) const override;
131 int64_t get_field_internal(const Ioss::EdgeBlock *nb, const Ioss::Field &field, void *data,
132 size_t data_size) const override;
133 int64_t get_field_internal(const Ioss::FaceBlock *nb, const Ioss::Field &field, void *data,
134 size_t data_size) const override;
135 int64_t get_field_internal(const Ioss::ElementBlock *eb, const Ioss::Field &field, void *data,
136 size_t data_size) const override;
137 int64_t get_field_internal(const Ioss::StructuredBlock *sb, const Ioss::Field &field,
138 void *data, size_t data_size) const override;
139 int64_t get_field_internal(const Ioss::SideBlock *sb, const Ioss::Field &field, void *data,
140 size_t data_size) const override;
141 int64_t get_field_internal(const Ioss::NodeSet *ns, const Ioss::Field &field, void *data,
142 size_t data_size) const override;
143 int64_t get_field_internal(const Ioss::EdgeSet *ns, const Ioss::Field &field, void *data,
144 size_t data_size) const override;
145 int64_t get_field_internal(const Ioss::FaceSet *ns, const Ioss::Field &field, void *data,
146 size_t data_size) const override;
147 int64_t get_field_internal(const Ioss::ElementSet *ns, const Ioss::Field &field, void *data,
148 size_t data_size) const override;
149 int64_t get_field_internal(const Ioss::SideSet *fs, const Ioss::Field &field, void *data,
150 size_t data_size) const override;
151 int64_t get_field_internal(const Ioss::CommSet *cs, const Ioss::Field &field, void *data,
152 size_t data_size) const override;
153
154 int64_t put_field_internal(const Ioss::Region *reg, const Ioss::Field &field, void *data,
155 size_t data_size) const override;
156 int64_t put_field_internal(const Ioss::NodeBlock *nb, const Ioss::Field &field, void *data,
157 size_t data_size) const override;
158 int64_t put_field_internal(const Ioss::EdgeBlock *nb, const Ioss::Field &field, void *data,
159 size_t data_size) const override;
160 int64_t put_field_internal(const Ioss::FaceBlock *nb, const Ioss::Field &field, void *data,
161 size_t data_size) const override;
162 int64_t put_field_internal(const Ioss::ElementBlock *eb, const Ioss::Field &field, void *data,
163 size_t data_size) const override;
164 int64_t put_field_internal(const Ioss::StructuredBlock *sb, const Ioss::Field &field,
165 void *data, size_t data_size) const override;
166 int64_t put_field_internal(const Ioss::SideBlock *fb, const Ioss::Field &field, void *data,
167 size_t data_size) const override;
168 int64_t put_field_internal(const Ioss::NodeSet *ns, const Ioss::Field &field, void *data,
169 size_t data_size) const override;
170 int64_t put_field_internal(const Ioss::EdgeSet *ns, const Ioss::Field &field, void *data,
171 size_t data_size) const override;
172 int64_t put_field_internal(const Ioss::FaceSet *ns, const Ioss::Field &field, void *data,
173 size_t data_size) const override;
174 int64_t put_field_internal(const Ioss::ElementSet *ns, const Ioss::Field &field, void *data,
175 size_t data_size) const override;
176 int64_t put_field_internal(const Ioss::SideSet *fs, const Ioss::Field &field, void *data,
177 size_t data_size) const override;
178 int64_t put_field_internal(const Ioss::CommSet *cs, const Ioss::Field &field, void *data,
179 size_t data_size) const override;
180
181 // ID Mapping functions.
182 const Ioss::Map &get_map(entity_type type) const;
183 const Ioss::Map &get_map(Ioss::Map &entity_map, int64_t entityCount, int64_t file_offset,
184 int64_t file_count, entity_type type) const;
185
186 int64_t handle_element_ids(const Ioss::ElementBlock *eb, void *ids, size_t num_to_get,
187 size_t offset, size_t count) const;
188
189 // Bulk Data
190 void resolve_zone_shared_nodes(const CGNSIntVector &nodes, CGNSIntVector &connectivity_map,
191 size_t &owned_node_count, size_t &owned_node_offset) const;
192
193 std::vector<int64_t> get_processor_zone_node_offset() const;
194
195 mutable int cgnsFilePtr{-1};
196 mutable int cgnsSerFilePtr{-1};
197 CG_ZoneType_t m_zoneType{CG_ZoneTypeNull};
198
199 mutable std::unique_ptr<DecompositionDataBase> decomp;
200
201 int m_currentVertexSolutionIndex = 0;
202 int m_currentCellCenterSolutionIndex = 0;
203
204 mutable std::vector<size_t> m_zoneOffset; // Offset for local zone/block element ids to global.
205
206 mutable std::vector<size_t>
207 m_bcOffset; // The BC Section element offsets in unstructured output.
208 mutable std::vector<double> m_timesteps; // Should be able to get this from region?
209 std::map<std::string, int> m_zoneNameMap;
210 mutable std::map<int, Ioss::Map *> m_globalToBlockLocalNodeMap;
211 mutable CGNSIntVector
212 m_elemGlobalImplicitMap; // Position of this element in the global-implicit ordering
213 };
214 } // namespace Iocgns
215 #endif
Iocgns::ParallelDatabaseIO::element_global_to_local__
int64_t element_global_to_local__(int64_t global) const override
Definition: Iocgns_ParallelDatabaseIO.C:308
Ioss_CodeTypes.h
Iocgns::ParallelDatabaseIO::write_results_meta_data
void write_results_meta_data()
Definition: Iocgns_ParallelDatabaseIO.C:2164
Iocgns::ParallelDatabaseIO::get_map
const Ioss::Map & get_map(entity_type type) const
Definition: Iocgns_ParallelDatabaseIO.C:910
Iocgns::ParallelDatabaseIO::m_elemGlobalImplicitMap
CGNSIntVector m_elemGlobalImplicitMap
Definition: Iocgns_ParallelDatabaseIO.h:212
Iocgns::ParallelDatabaseIO::write_adjacency_data
void write_adjacency_data()
Definition: Iocgns_ParallelDatabaseIO.C:727
Ioss
The main namespace for the Ioss library.
Definition: Iocgns_DatabaseIO.h:50
Ioss::DatabaseIO
An input or output Database.
Definition: Ioss_DatabaseIO.h:80
Ioss_DBUsage.h
Iocgns::ParallelDatabaseIO::closeDatabase__
void closeDatabase__() const override
Definition: Iocgns_ParallelDatabaseIO.C:270
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:167
Iocgns::ParallelDatabaseIO::handle_node_ids
int64_t handle_node_ids(void *ids, int64_t num_to_get) const
Definition: Iocgns_ParallelDatabaseIO.C:2172
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:559
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:101
Iocgns::ParallelDatabaseIO::finalize_structured_blocks
size_t finalize_structured_blocks()
Definition: Iocgns_ParallelDatabaseIO.C:442
Ioss::FaceBlock
A collection of element faces with the same topology.
Definition: Ioss_FaceBlock.h:53
Iocgns::ParallelDatabaseIO::begin_state__
bool begin_state__(Ioss::Region *region, int state, double time) override
Definition: Iocgns_ParallelDatabaseIO.C:890
Ioss::FaceSet
A collection of element faces.
Definition: Ioss_FaceSet.h:54
Iocgns
A namespace for the CGNS database format.
Definition: Iocgns_DatabaseIO.C:392
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:1444
Iocgns::ParallelDatabaseIO::read_meta_data__
void read_meta_data__() override
Definition: Iocgns_ParallelDatabaseIO.C:314
Ioss::EdgeSet
A collection of element edges.
Definition: Ioss_EdgeSet.h:54
Iocgns::ParallelDatabaseIO::finalize_database
void finalize_database() override
Definition: Iocgns_ParallelDatabaseIO.C:278
Ioss_Map.h
Iocgns::ParallelDatabaseIO::m_zoneOffset
std::vector< size_t > m_zoneOffset
Definition: Iocgns_ParallelDatabaseIO.h:204
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:105
Iocgns::CGNSIntVector
std::vector< cgsize_t > CGNSIntVector
Definition: Iocgns_ParallelDatabaseIO.h:73
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:207
Iocgns::ParallelDatabaseIO::entity_type
entity_type
Definition: Iocgns_ParallelDatabaseIO.h:78
Ioss_State.h
Ioss::ElementBlock
A collection of elements having the same topology.
Definition: Ioss_ElementBlock.h:48
Iocgns::ParallelDatabaseIO
Definition: Iocgns_ParallelDatabaseIO.h:75
Iocgns::ParallelDatabaseIO::get_step_times__
void get_step_times__() override
Definition: Iocgns_ParallelDatabaseIO.C:722
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:291
Iocgns::ParallelDatabaseIO::cgnsFilePtr
int cgnsFilePtr
Definition: Iocgns_ParallelDatabaseIO.h:195
Iocgns::ParallelDatabaseIO::begin__
bool begin__(Ioss::State state) override
Definition: Iocgns_ParallelDatabaseIO.C:859
Iocgns::ParallelDatabaseIO::~ParallelDatabaseIO
~ParallelDatabaseIO()
Definition: Iocgns_ParallelDatabaseIO.C:184
Iocgns::ParallelDatabaseIO::handle_structured_blocks
void handle_structured_blocks()
Definition: Iocgns_ParallelDatabaseIO.C:465
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:202
Iocgns::ParallelDatabaseIO::entity_field_support
unsigned entity_field_support() const override
Definition: Iocgns_ParallelDatabaseIO.C:2166
Iocgns::ParallelDatabaseIO::write_meta_data
void write_meta_data()
Definition: Iocgns_ParallelDatabaseIO.C:712
Iocgns::ParallelDatabaseIO::end__
bool end__(Ioss::State state) override
Definition: Iocgns_ParallelDatabaseIO.C:865
Ioss::Map
Definition: Ioss_Map.h:52
Iocgns::ParallelDatabaseIO::decomp
std::unique_ptr< DecompositionDataBase > decomp
Definition: Iocgns_ParallelDatabaseIO.h:199
Ioss::CommSet
Definition: Ioss_CommSet.h:51
Iocgns::ParallelDatabaseIO::m_globalToBlockLocalNodeMap
std::map< int, Ioss::Map * > m_globalToBlockLocalNodeMap
Definition: Iocgns_ParallelDatabaseIO.h:210
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_timesteps
std::vector< double > m_timesteps
Definition: Iocgns_ParallelDatabaseIO.h:208
Iocgns::ParallelDatabaseIO::m_zoneType
CG_ZoneType_t m_zoneType
Definition: Iocgns_ParallelDatabaseIO.h:197
Iocgns::ParallelDatabaseIO::m_zoneNameMap
std::map< std::string, int > m_zoneNameMap
Definition: Iocgns_ParallelDatabaseIO.h:209
Iocgns::ParallelDatabaseIO::openDatabase__
void openDatabase__() const override
Definition: Iocgns_ParallelDatabaseIO.C:198
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:80
Iocgns::ParallelDatabaseIO::m_currentVertexSolutionIndex
int m_currentVertexSolutionIndex
Definition: Iocgns_ParallelDatabaseIO.h:201
Iocgns::ParallelDatabaseIO::get_processor_zone_node_offset
std::vector< int64_t > get_processor_zone_node_offset() const
Definition: Iocgns_ParallelDatabaseIO.C:2231
Iocgns::ParallelDatabaseIO::entity_type::NODE
Iocgns::ParallelDatabaseIO::handle_unstructured_blocks
void handle_unstructured_blocks()
Definition: Iocgns_ParallelDatabaseIO.C:358
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:1475
Iocgns::ParallelDatabaseIO::node_major
bool node_major() const override
Definition: Iocgns_ParallelDatabaseIO.h:99
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:302
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:970
Iocgns::ParallelDatabaseIO::cgnsSerFilePtr
int cgnsSerFilePtr
Definition: Iocgns_ParallelDatabaseIO.h:196
Iocgns::ParallelDatabaseIO::end_state__
bool end_state__(Ioss::Region *region, int state, double time) override
Definition: Iocgns_ParallelDatabaseIO.C:901