IOSS 2.0
Loading...
Searching...
No Matches
Iocgns_ParallelDatabaseIO.h
Go to the documentation of this file.
1// Copyright(C) 1999-2024 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#pragma once
8
9#include "iocgns_export.h"
10
11#include <cgnsconfig.h>
12#if CG_BUILD_PARALLEL
13
14#include "Ioss_CodeTypes.h"
15#include "Ioss_DBUsage.h" // for DatabaseUsage
16#include "Ioss_DatabaseIO.h" // for DatabaseIO
17#include "Ioss_IOFactory.h" // for IOFactory
18#include "Ioss_Map.h" // for Map
19#include "Ioss_MeshType.h"
20#include "Ioss_State.h" // for State
21#include <cstddef> // for size_t
22#include <cstdint> // for int64_t
23#include <iostream> // for ostream
24#include <memory>
25#include <string> // for string
26
28#include "cgns/Iocgns_Defines.h"
29
30#include <cgnslib.h>
31
32namespace Ioss {
33 class Assembly;
34 class Blob;
35 class CommSet;
36 class EdgeBlock;
37 class EdgeSet;
38 class ElementBlock;
39 class ElementSet;
40 class ElementTopology;
41 class FaceBlock;
42 class FaceSet;
43 class Field;
44 class GroupingEntity;
45 class NodeBlock;
46 class NodeSet;
47 class Region;
48 class SideBlock;
49 class SideSet;
50 class EntityBlock;
51} // namespace Ioss
52
53namespace Iocgns {
54
55 class IOCGNS_EXPORT ParallelDatabaseIO : public Ioss::DatabaseIO
56 {
57 public:
58 enum class entity_type { NODE, ELEM };
59
60 ParallelDatabaseIO(Ioss::Region *region, const std::string &filename,
61 Ioss::DatabaseUsage db_usage, Ioss_MPI_Comm communicator,
62 const Ioss::PropertyManager &props);
63
64 ~ParallelDatabaseIO() override;
65
66 IOSS_NODISCARD std::string get_format() const override { return "CGNS"; }
67
68 // Check capabilities of input/output database... Returns an
69 // unsigned int with the supported Ioss::EntityTypes or'ed
70 // together. If "return_value & Ioss::EntityType" is set, then the
71 // database supports that type (e.g. return_value & Ioss::FACESET)
72 IOSS_NODISCARD unsigned entity_field_support() const override;
73
74 IOSS_NODISCARD int get_file_pointer() const override;
75
76 IOSS_NODISCARD bool node_major() const override { return false; }
77
78 IOSS_NODISCARD bool needs_shared_node_information() const override { return false; }
79
80 // This isn't quite true since a CGNS library with cgsize_t == 64-bits can read
81 // a file with 32-bit ints. However,...
82 IOSS_NODISCARD int int_byte_size_db() const override { return CG_SIZEOF_SIZE; }
83
84 // Metadata-related functions.
85 void write_meta_data();
86 void write_results_meta_data();
87
88 private:
89 void read_meta_data_nl() override;
90
91 IOSS_NODISCARD int64_t node_global_to_local_nl(int64_t global, bool must_exist) const override;
92 IOSS_NODISCARD int64_t element_global_to_local_nl(int64_t global) const override;
93
94 void release_memory_nl() override;
95
96 void open_state_file(int state);
97 void free_state_pointer();
98
99 void openDatabase_nl() const override;
100 void closeDatabase_nl() const override;
101 void closeBaseDatabase_nl() const;
102
103 bool begin_nl(Ioss::State state) override;
104 bool end_nl(Ioss::State state) override;
105
106 bool begin_state_nl(int state, double time) override;
107 bool end_state_nl(int state, double time) override;
108 void flush_database_nl() const override;
109
110 void handle_structured_blocks();
111 void handle_unstructured_blocks();
112 size_t finalize_structured_blocks();
113 int64_t handle_node_ids(void *ids, int64_t num_to_get) const;
114 void finalize_database() const override;
115 void get_step_times_nl() override;
116 std::vector<double> get_db_step_times_nl() override;
117 void write_adjacency_data();
118
119 int64_t get_field_internal(const Ioss::Region *reg, const Ioss::Field &field, void *data,
120 size_t data_size) const override;
121 int64_t get_field_internal(const Ioss::NodeBlock *nb, const Ioss::Field &field, void *data,
122 size_t data_size) const override;
123 int64_t get_field_internal(const Ioss::EdgeBlock *nb, const Ioss::Field &field, void *data,
124 size_t data_size) const override;
125 int64_t get_field_internal(const Ioss::FaceBlock *nb, const Ioss::Field &field, void *data,
126 size_t data_size) const override;
127 int64_t get_field_internal(const Ioss::ElementBlock *eb, const Ioss::Field &field, void *data,
128 size_t data_size) const override;
129 int64_t get_field_internal(const Ioss::StructuredBlock *sb, const Ioss::Field &field,
130 void *data, size_t data_size) const override;
131 int64_t get_field_internal(const Ioss::SideBlock *sb, const Ioss::Field &field, void *data,
132 size_t data_size) const override;
133 int64_t get_field_internal(const Ioss::NodeSet *ns, const Ioss::Field &field, void *data,
134 size_t data_size) const override;
135 int64_t get_field_internal(const Ioss::EdgeSet *ns, const Ioss::Field &field, void *data,
136 size_t data_size) const override;
137 int64_t get_field_internal(const Ioss::FaceSet *ns, const Ioss::Field &field, void *data,
138 size_t data_size) const override;
139 int64_t get_field_internal(const Ioss::ElementSet *ns, const Ioss::Field &field, void *data,
140 size_t data_size) const override;
141 int64_t get_field_internal(const Ioss::SideSet *fs, const Ioss::Field &field, void *data,
142 size_t data_size) const override;
143 int64_t get_field_internal(const Ioss::CommSet *cs, const Ioss::Field &field, void *data,
144 size_t data_size) const override;
145 int64_t get_field_internal(const Ioss::Assembly * /*sb*/, const Ioss::Field & /*field*/,
146 void * /*data*/, size_t /*data_size*/) const override
147 {
148 return 0;
149 }
150
151 int64_t get_field_internal(const Ioss::Blob * /*sb*/, const Ioss::Field & /*field*/,
152 void * /*data*/, size_t /*data_size*/) const override
153 {
154 return 0;
155 }
156
157 int64_t get_field_internal_sub_nb(const Ioss::NodeBlock *nb, const Ioss::Field &field,
158 void *data, size_t data_size) const;
159
160 int64_t put_field_internal(const Ioss::Region *reg, const Ioss::Field &field, void *data,
161 size_t data_size) const override;
162 int64_t put_field_internal(const Ioss::NodeBlock *nb, const Ioss::Field &field, void *data,
163 size_t data_size) const override;
164 int64_t put_field_internal(const Ioss::EdgeBlock *nb, const Ioss::Field &field, void *data,
165 size_t data_size) const override;
166 int64_t put_field_internal(const Ioss::FaceBlock *nb, const Ioss::Field &field, void *data,
167 size_t data_size) const override;
168 int64_t put_field_internal(const Ioss::ElementBlock *eb, const Ioss::Field &field, void *data,
169 size_t data_size) const override;
170 int64_t put_field_internal(const Ioss::StructuredBlock *sb, const Ioss::Field &field,
171 void *data, size_t data_size) const override;
172 int64_t put_field_internal(const Ioss::SideBlock *sb, const Ioss::Field &field, void *data,
173 size_t data_size) const override;
174 int64_t put_field_internal(const Ioss::NodeSet *ns, const Ioss::Field &field, void *data,
175 size_t data_size) const override;
176 int64_t put_field_internal(const Ioss::EdgeSet *ns, const Ioss::Field &field, void *data,
177 size_t data_size) const override;
178 int64_t put_field_internal(const Ioss::FaceSet *ns, const Ioss::Field &field, void *data,
179 size_t data_size) const override;
180 int64_t put_field_internal(const Ioss::ElementSet *ns, const Ioss::Field &field, void *data,
181 size_t data_size) const override;
182 int64_t put_field_internal(const Ioss::SideSet *fs, const Ioss::Field &field, void *data,
183 size_t data_size) const override;
184 int64_t put_field_internal(const Ioss::CommSet *cs, const Ioss::Field &field, void *data,
185 size_t data_size) const override;
186 int64_t put_field_internal(const Ioss::Assembly * /*sb*/, const Ioss::Field & /*field*/,
187 void * /*data*/, size_t /*data_size*/) const override
188 {
189 return 0;
190 }
191
192 int64_t put_field_internal(const Ioss::Blob * /*sb*/, const Ioss::Field & /*field*/,
193 void * /*data*/, size_t /*data_size*/) const override
194 {
195 return 0;
196 }
197
198 int64_t put_field_internal_sub_nb(const Ioss::NodeBlock *nb, const Ioss::Field &field,
199 void *data, size_t data_size) const;
200
201 // ID Mapping functions.
202 const Ioss::Map &get_map(entity_type type) const;
203 const Ioss::Map &get_map(Ioss::Map &entity_map, int64_t entity_count, int64_t file_offset,
204 int64_t file_count, entity_type type) const;
205
206 int64_t handle_element_ids(const Ioss::ElementBlock *eb, void *ids, size_t num_to_get,
207 size_t offset, size_t count) const;
208
209 // Bulk Data
210 void resolve_zone_shared_nodes(const CGNSIntVector &nodes, CGNSIntVector &connectivity_map,
211 size_t &owned_node_count, size_t &owned_node_offset) const;
212
213 std::vector<int64_t> get_processor_zone_node_offset() const;
214
215 mutable int m_cgnsFilePtr{-1};
216 mutable int m_cgnsBasePtr{-1};
218
219 mutable std::unique_ptr<DecompositionDataBase> decomp;
220
221 int m_flushInterval{0}; // Default is no flushing after each timestep
222 int m_currentVertexSolutionIndex{0};
223 int m_currentCellCenterSolutionIndex{0};
224 mutable bool m_dbFinalized{false};
225
226 mutable std::vector<size_t> m_zoneOffset; // Offset for local zone/block element ids to global.
227
228 mutable std::vector<size_t>
229 m_bcOffset; // The BC Section element offsets in unstructured output.
230 mutable std::vector<double> m_timesteps; // Should be able to get this from region?
231 std::map<std::string, int> m_zoneNameMap;
232 mutable std::map<int, Ioss::Map *> m_globalToBlockLocalNodeMap;
233 mutable CGNSIntVector
234 m_elemGlobalImplicitMap; // Position of this element in the global-implicit ordering
235 };
236} // namespace Iocgns
237#endif
std::vector< cgsize_t > CGNSIntVector
Definition Iocgns_Defines.h:12
#define IOSS_NODISCARD
Definition Ioss_CodeTypes.h:55
int Ioss_MPI_Comm
Definition Ioss_CodeTypes.h:64
A homogeneous collection of other GroupingEntities.
Definition Ioss_Assembly.h:31
A homogeneous collection of other GroupingEntities.
Definition Ioss_Blob.h:31
Definition Ioss_CommSet.h:27
An input or output Database.
Definition Ioss_DatabaseIO.h:63
A collection of element edges with the same topology.
Definition Ioss_EdgeBlock.h:29
A collection of element edges.
Definition Ioss_EdgeSet.h:30
A collection of elements having the same topology.
Definition Ioss_ElementBlock.h:29
A collection of elements.
Definition Ioss_ElementSet.h:30
A collection of element faces with the same topology.
Definition Ioss_FaceBlock.h:29
A collection of element faces.
Definition Ioss_FaceSet.h:30
Holds metadata for bulk data associated with a GroupingEntity.
Definition Ioss_Field.h:25
Definition Ioss_Map.h:46
A collection of all nodes in the region.
Definition Ioss_NodeBlock.h:33
A collection of nodes.
Definition Ioss_NodeSet.h:29
A collection of Ioss::Property objects.
Definition Ioss_PropertyManager.h:36
A grouping entity that contains other grouping entities.
Definition Ioss_Region.h:93
A collection of element sides having the same topology.
Definition Ioss_SideBlock.h:37
A collection of element sides.
Definition Ioss_SideSet.h:29
A structured zone – i,j,k.
Definition Ioss_StructuredBlock.h:91
A namespace for the CGNS database format.
Definition Iocgns_DatabaseIO.C:555
int get_file_pointer()
Definition Iofaodel_DatabaseIO.C:55
The main namespace for the Ioss library.
Definition Ioad_DatabaseIO.C:40
State
Access states for a database.
Definition Ioss_State.h:15
DatabaseUsage
Specifies how an Ioss::DatabaseIO object will be used.
Definition Ioss_DBUsage.h:13
MeshType
The mesh type – structured, unstructured, hybrid (future), or unknown.
Definition Ioss_MeshType.h:12