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 const std::string get_format() const override {return "CGNS";}
88
89 // Check capabilities of input/output database... Returns an
90 // unsigned int with the supported Ioss::EntityTypes or'ed
91 // together. If "return_value & Ioss::EntityType" is set, then the
92 // database supports that type (e.g. return_value & Ioss::FACESET)
93 unsigned entity_field_support() const override;
94
95 int64_t node_global_to_local__(int64_t global, bool must_exist) const override;
96 int64_t element_global_to_local__(int64_t global) const override;
97
98 void release_memory__() override;
99
100 int get_file_pointer() const override;
101
102 bool node_major() const override { return false; }
103
104 bool needs_shared_node_information() const override { return false; }
105
106 // This isn't quite true since a CGNS library with cgsize_t == 64-bits can read
107 // a file with 32-bit ints. However,...
108 int int_byte_size_db() const override { return CG_SIZEOF_SIZE; }
109
110 // Metadata-related functions.
111 void read_meta_data__() override;
112 void write_meta_data();
113 void write_results_meta_data();
114
115 private:
116 void openDatabase__() const override;
117 void closeDatabase__() const override;
118
119 bool begin__(Ioss::State state) override;
120 bool end__(Ioss::State state) override;
121
122 bool begin_state__(int state, double time) override;
123 bool end_state__(int state, double time) override;
124 void flush_database__() const override;
125
126 void handle_structured_blocks();
127 void handle_unstructured_blocks();
128 size_t finalize_structured_blocks();
129 int64_t handle_node_ids(void *ids, int64_t num_to_get) const;
130 void finalize_database() override;
131 void get_step_times__() override;
132 void write_adjacency_data();
133
134 int64_t get_field_internal(const Ioss::Region *reg, const Ioss::Field &field, void *data,
135 size_t data_size) const override;
136 int64_t get_field_internal(const Ioss::NodeBlock *nb, const Ioss::Field &field, void *data,
137 size_t data_size) const override;
138 int64_t get_field_internal(const Ioss::EdgeBlock *nb, const Ioss::Field &field, void *data,
139 size_t data_size) const override;
140 int64_t get_field_internal(const Ioss::FaceBlock *nb, const Ioss::Field &field, void *data,
141 size_t data_size) const override;
142 int64_t get_field_internal(const Ioss::ElementBlock *eb, const Ioss::Field &field, void *data,
143 size_t data_size) const override;
144 int64_t get_field_internal(const Ioss::StructuredBlock *sb, const Ioss::Field &field,
145 void *data, size_t data_size) const override;
146 int64_t get_field_internal(const Ioss::SideBlock *sb, const Ioss::Field &field, void *data,
147 size_t data_size) const override;
148 int64_t get_field_internal(const Ioss::NodeSet *ns, const Ioss::Field &field, void *data,
149 size_t data_size) const override;
150 int64_t get_field_internal(const Ioss::EdgeSet *ns, const Ioss::Field &field, void *data,
151 size_t data_size) const override;
152 int64_t get_field_internal(const Ioss::FaceSet *ns, const Ioss::Field &field, void *data,
153 size_t data_size) const override;
154 int64_t get_field_internal(const Ioss::ElementSet *ns, const Ioss::Field &field, void *data,
155 size_t data_size) const override;
156 int64_t get_field_internal(const Ioss::SideSet *fs, const Ioss::Field &field, void *data,
157 size_t data_size) const override;
158 int64_t get_field_internal(const Ioss::CommSet *cs, const Ioss::Field &field, void *data,
159 size_t data_size) const override;
160
161 int64_t get_field_internal_sub_nb(const Ioss::NodeBlock *nb, const Ioss::Field &field,
162 void *data, size_t data_size) const;
163
164 int64_t put_field_internal(const Ioss::Region *reg, const Ioss::Field &field, void *data,
165 size_t data_size) const override;
166 int64_t put_field_internal(const Ioss::NodeBlock *nb, const Ioss::Field &field, void *data,
167 size_t data_size) const override;
168 int64_t put_field_internal(const Ioss::EdgeBlock *nb, const Ioss::Field &field, void *data,
169 size_t data_size) const override;
170 int64_t put_field_internal(const Ioss::FaceBlock *nb, const Ioss::Field &field, void *data,
171 size_t data_size) const override;
172 int64_t put_field_internal(const Ioss::ElementBlock *eb, const Ioss::Field &field, void *data,
173 size_t data_size) const override;
174 int64_t put_field_internal(const Ioss::StructuredBlock *sb, const Ioss::Field &field,
175 void *data, size_t data_size) const override;
176 int64_t put_field_internal(const Ioss::SideBlock *fb, const Ioss::Field &field, void *data,
177 size_t data_size) const override;
178 int64_t put_field_internal(const Ioss::NodeSet *ns, const Ioss::Field &field, void *data,
179 size_t data_size) const override;
180 int64_t put_field_internal(const Ioss::EdgeSet *ns, const Ioss::Field &field, void *data,
181 size_t data_size) const override;
182 int64_t put_field_internal(const Ioss::FaceSet *ns, const Ioss::Field &field, void *data,
183 size_t data_size) const override;
184 int64_t put_field_internal(const Ioss::ElementSet *ns, const Ioss::Field &field, void *data,
185 size_t data_size) const override;
186 int64_t put_field_internal(const Ioss::SideSet *fs, const Ioss::Field &field, void *data,
187 size_t data_size) const override;
188 int64_t put_field_internal(const Ioss::CommSet *cs, const Ioss::Field &field, void *data,
189 size_t data_size) const override;
190
191 int64_t put_field_internal_sub_nb(const Ioss::NodeBlock *nb, const Ioss::Field &field,
192 void *data, size_t data_size) const;
193
194 // ID Mapping functions.
195 const Ioss::Map &get_map(entity_type type) const;
196 const Ioss::Map &get_map(Ioss::Map &entity_map, int64_t entityCount, int64_t file_offset,
197 int64_t file_count, entity_type type) const;
198
199 int64_t handle_element_ids(const Ioss::ElementBlock *eb, void *ids, size_t num_to_get,
200 size_t offset, size_t count) const;
201
202 // Bulk Data
203 void resolve_zone_shared_nodes(const CGNSIntVector &nodes, CGNSIntVector &connectivity_map,
204 size_t &owned_node_count, size_t &owned_node_offset) const;
205
206 std::vector<int64_t> get_processor_zone_node_offset() const;
207
208 mutable int m_cgnsFilePtr{-1};
209 Ioss::MeshType m_meshType{Ioss::MeshType::UNKNOWN};
210
211 mutable std::unique_ptr<DecompositionDataBase> decomp;
212
213 int m_flushInterval{0}; // Default is no flushing after each timestep
214 int m_currentVertexSolutionIndex = 0;
215 int m_currentCellCenterSolutionIndex = 0;
216
217 mutable std::vector<size_t> m_zoneOffset; // Offset for local zone/block element ids to global.
218
219 mutable std::vector<size_t>
220 m_bcOffset; // The BC Section element offsets in unstructured output.
221 mutable std::vector<double> m_timesteps; // Should be able to get this from region?
222 std::map<std::string, int> m_zoneNameMap;
223 mutable std::map<int, Ioss::Map *> m_globalToBlockLocalNodeMap;
224 mutable CGNSIntVector
225 m_elemGlobalImplicitMap; // Position of this element in the global-implicit ordering
226 };
227 } // namespace Iocgns
228 #endif
Iocgns::ParallelDatabaseIO::handle_node_ids
int64_t handle_node_ids(void *ids, int64_t num_to_get) const
Definition: Iocgns_ParallelDatabaseIO.C:2426
Iocgns::ParallelDatabaseIO::read_meta_data__
void read_meta_data__() override
Definition: Iocgns_ParallelDatabaseIO.C:352
Iocgns::ParallelDatabaseIO::begin_state__
bool begin_state__(int state, double time) override
Definition: Iocgns_ParallelDatabaseIO.C:939
Ioss::MeshType
MeshType
The mesh type – structured, unstructured, hybrid (future), or unknown.
Definition: Ioss_MeshType.h:39
Ioss_DBUsage.h
Iocgns::ParallelDatabaseIO::m_globalToBlockLocalNodeMap
std::map< int, Ioss::Map * > m_globalToBlockLocalNodeMap
Definition: Iocgns_ParallelDatabaseIO.h:223
Iocgns::ParallelDatabaseIO::get_format
const std::string get_format() const override
Definition: Iocgns_ParallelDatabaseIO.h:87
Ioss::Field
Holds metadata for bulk data associated with a GroupingEntity.
Definition: Ioss_Field.h:47
Iocgns::ParallelDatabaseIO::entity_field_support
unsigned entity_field_support() const override
Definition: Iocgns_ParallelDatabaseIO.C:2420
Iocgns::ParallelDatabaseIO::m_cgnsFilePtr
int m_cgnsFilePtr
Definition: Iocgns_ParallelDatabaseIO.h:208
Iocgns::ParallelDatabaseIO::write_adjacency_data
void write_adjacency_data()
Definition: Iocgns_ParallelDatabaseIO.C:778
Ioss_Map.h
Iocgns::ParallelDatabaseIO::write_meta_data
void write_meta_data()
Definition: Iocgns_ParallelDatabaseIO.C:761
Iocgns::ParallelDatabaseIO::entity_type::NODE
Iocgns::ParallelDatabaseIO::get_field_internal_sub_nb
int64_t get_field_internal_sub_nb(const Ioss::NodeBlock *nb, const Ioss::Field &field, void *data, size_t data_size) const
Definition: Iocgns_ParallelDatabaseIO.C:1183
Iocgns::ParallelDatabaseIO::m_timesteps
std::vector< double > m_timesteps
Definition: Iocgns_ParallelDatabaseIO.h:221
Iocgns::ParallelDatabaseIO
Definition: Iocgns_ParallelDatabaseIO.h:76
Ioss::EdgeBlock
A collection of element edges with the same topology.
Definition: Ioss_EdgeBlock.h:53
Ioss::DatabaseUsage
DatabaseUsage
Specifies how an Ioss::DatabaseIO object will be used.
Definition: Ioss_DBUsage.h:40
Ioss
The main namespace for the Ioss library.
Definition: Ioad_DatabaseIO.C:66
Iocgns::ParallelDatabaseIO::m_zoneNameMap
std::map< std::string, int > m_zoneNameMap
Definition: Iocgns_ParallelDatabaseIO.h:222
Ioss::State
State
Access states for a database.
Definition: Ioss_State.h:42
Iocgns::ParallelDatabaseIO::flush_database__
void flush_database__() const override
Definition: Iocgns_ParallelDatabaseIO.C:973
Iocgns::ParallelDatabaseIO::int_byte_size_db
int int_byte_size_db() const override
Definition: Iocgns_ParallelDatabaseIO.h:108
Ioss::Region
A grouping entity that contains other grouping entities.
Definition: Ioss_Region.h:98
Iocgns::ParallelDatabaseIO::entity_type::ELEM
Iocgns::ParallelDatabaseIO::handle_structured_blocks
void handle_structured_blocks()
Definition: Iocgns_ParallelDatabaseIO.C:514
Ioss::NodeSet
A collection of nodes.
Definition: Ioss_NodeSet.h:53
Ioss::ElementShape::UNKNOWN
Ioss::FaceSet
A collection of element faces.
Definition: Ioss_FaceSet.h:54
Ioss::StructuredBlock
A structured zone – i,j,k.
Definition: Ioss_StructuredBlock.h:103
Iocgns::ParallelDatabaseIO::m_elemGlobalImplicitMap
CGNSIntVector m_elemGlobalImplicitMap
Definition: Iocgns_ParallelDatabaseIO.h:225
Ioss::PropertyManager
A collection of Ioss::Property objects.
Definition: Ioss_PropertyManager.h:49
Iocgns::ParallelDatabaseIO::m_flushInterval
int m_flushInterval
Definition: Iocgns_ParallelDatabaseIO.h:213
Ioss::EdgeSet
A collection of element edges.
Definition: Ioss_EdgeSet.h:54
Ioss::ElementSet
A collection of elements.
Definition: Ioss_ElementSet.h:54
Iocgns::ParallelDatabaseIO::get_map
const Ioss::Map & get_map(entity_type type) const
Definition: Iocgns_ParallelDatabaseIO.C:983
Ioss::CommSet
Definition: Ioss_CommSet.h:51
Iocgns::ParallelDatabaseIO::finalize_structured_blocks
size_t finalize_structured_blocks()
Definition: Iocgns_ParallelDatabaseIO.C:491
Iocgns::ParallelDatabaseIO::get_processor_zone_node_offset
std::vector< int64_t > get_processor_zone_node_offset() const
Definition: Iocgns_ParallelDatabaseIO.C:2485
Iocgns::CGNSIntVector
std::vector< cgsize_t > CGNSIntVector
Definition: Iocgns_ParallelDatabaseIO.h:74
Ioss::FaceBlock
A collection of element faces with the same topology.
Definition: Ioss_FaceBlock.h:53
Ioss_MeshType.h
Iocgns::ParallelDatabaseIO::openDatabase__
void openDatabase__() const override
Definition: Iocgns_ParallelDatabaseIO.C:211
Iocgns::ParallelDatabaseIO::release_memory__
void release_memory__() override
Definition: Iocgns_ParallelDatabaseIO.C:329
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:1632
Ioss::DatabaseIO
An input or output Database.
Definition: Ioss_DatabaseIO.h:82
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:608
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:1601
Iocgns_DecompositionData.h
Iocgns::ParallelDatabaseIO::m_currentCellCenterSolutionIndex
int m_currentCellCenterSolutionIndex
Definition: Iocgns_ParallelDatabaseIO.h:215
Ioss_State.h
Ioss::SideBlock
A collection of element sides having the same topology.
Definition: Ioss_SideBlock.h:59
Iocgns::ParallelDatabaseIO::begin__
bool begin__(Ioss::State state) override
Definition: Iocgns_ParallelDatabaseIO.C:908
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:1043
Iocgns::ParallelDatabaseIO::handle_unstructured_blocks
void handle_unstructured_blocks()
Definition: Iocgns_ParallelDatabaseIO.C:409
Iocgns::ParallelDatabaseIO::write_results_meta_data
void write_results_meta_data()
Definition: Iocgns_ParallelDatabaseIO.C:2418
Ioss_IOFactory.h
Ioss::ElementBlock
A collection of elements having the same topology.
Definition: Ioss_ElementBlock.h:48
Ioss::Map
Definition: Ioss_Map.h:52
Iocgns::ParallelDatabaseIO::element_global_to_local__
int64_t element_global_to_local__(int64_t global) const override
Definition: Iocgns_ParallelDatabaseIO.C:346
Iocgns::ParallelDatabaseIO::m_bcOffset
std::vector< size_t > m_bcOffset
Definition: Iocgns_ParallelDatabaseIO.h:220
anonymous_namespace{cth_pressure_map.C}::data
std::vector< char > data
Definition: cth_pressure_map.C:74
Iocgns::ParallelDatabaseIO::node_global_to_local__
int64_t node_global_to_local__(int64_t global, bool must_exist) const override
Definition: Iocgns_ParallelDatabaseIO.C:340
Iocgns::ParallelDatabaseIO::finalize_database
void finalize_database() override
Definition: Iocgns_ParallelDatabaseIO.C:316
Iocgns::ParallelDatabaseIO::end__
bool end__(Ioss::State state) override
Definition: Iocgns_ParallelDatabaseIO.C:914
Iocgns::ParallelDatabaseIO::m_currentVertexSolutionIndex
int m_currentVertexSolutionIndex
Definition: Iocgns_ParallelDatabaseIO.h:214
Iocgns::ParallelDatabaseIO::entity_type
entity_type
Definition: Iocgns_ParallelDatabaseIO.h:79
Ioss::NodeBlock
A collection of all nodes in the region.
Definition: Ioss_NodeBlock.h:53
Iocgns::ParallelDatabaseIO::end_state__
bool end_state__(int state, double time) override
Definition: Iocgns_ParallelDatabaseIO.C:950
Iocgns::ParallelDatabaseIO::get_step_times__
void get_step_times__() override
Definition: Iocgns_ParallelDatabaseIO.C:772
MPI_Comm
int MPI_Comm
Definition: Ioss_CodeTypes.h:96
Iocgns::ParallelDatabaseIO::m_meshType
Ioss::MeshType m_meshType
Definition: Iocgns_ParallelDatabaseIO.h:209
Iocgns::ParallelDatabaseIO::get_file_pointer
int get_file_pointer() const override
Definition: Iocgns_ParallelDatabaseIO.C:203
Iocgns::ParallelDatabaseIO::~ParallelDatabaseIO
~ParallelDatabaseIO()
Definition: Iocgns_ParallelDatabaseIO.C:191
Iocgns
A namespace for the CGNS database format.
Definition: Iocgns_DatabaseIO.C:444
Ioss::SideSet
A collection of element sides.
Definition: Ioss_SideSet.h:53
Ioss_CodeTypes.h
Iocgns::ParallelDatabaseIO::closeDatabase__
void closeDatabase__() const override
Definition: Iocgns_ParallelDatabaseIO.C:295
Iocgns::ParallelDatabaseIO::m_zoneOffset
std::vector< size_t > m_zoneOffset
Definition: Iocgns_ParallelDatabaseIO.h:217
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::decomp
std::unique_ptr< DecompositionDataBase > decomp
Definition: Iocgns_ParallelDatabaseIO.h:211
Iocgns::ParallelDatabaseIO::node_major
bool node_major() const override
Definition: Iocgns_ParallelDatabaseIO.h:102
Ioss_DatabaseIO.h
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:104
Iocgns::ParallelDatabaseIO::put_field_internal_sub_nb
int64_t put_field_internal_sub_nb(const Ioss::NodeBlock *nb, const Ioss::Field &field, void *data, size_t data_size) const
Definition: Iocgns_ParallelDatabaseIO.C:1845