IOSS 2.0
Loading...
Searching...
No Matches
Iocgns_DatabaseIO.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 "Ioss_CodeTypes.h"
10#include "Ioss_DBUsage.h" // for DatabaseUsage
11#include "Ioss_DatabaseIO.h" // for DatabaseIO
12#include "Ioss_FaceGenerator.h"
13#include "Ioss_IOFactory.h" // for IOFactory
14#include "Ioss_Map.h" // for Map
15#include "Ioss_State.h" // for State
16#include "cgns/Iocgns_Defines.h"
17#include <cgnslib.h>
18#include <cgnstypes.h>
19#include <cstddef> // for size_t
20#include <cstdint> // for int64_t
21#include <iostream> // for ostream
22#include <map>
23#include <string> // for string
24#include <vector>
25
26#include "iocgns_export.h"
27
28namespace Ioss {
29 class Assembly;
30 class Blob;
31 class CommSet;
32 class EdgeBlock;
33 class EdgeSet;
34 class ElementBlock;
35 class ElementSet;
36 class ElementTopology;
37 class FaceBlock;
38 class FaceSet;
39 class Field;
40 class GroupingEntity;
41 class NodeBlock;
42 class NodeSet;
43 class Region;
44 class SideBlock;
45 class SideSet;
46 class EntityBlock;
47 class StructuredBlock;
48 class Map;
49 class PropertyManager;
50} // namespace Ioss
51
52/** \brief A namespace for the CGNS database format.
53 */
54namespace Iocgns {
55
56 class IOCGNS_EXPORT DatabaseIO : public Ioss::DatabaseIO
57 {
58 public:
59 enum class entity_type { NODE, ELEM };
60
61 DatabaseIO(Ioss::Region *region, const std::string &filename, Ioss::DatabaseUsage db_usage,
62 Ioss_MPI_Comm communicator, const Ioss::PropertyManager &props);
63
64 // Check capabilities of input/output database... Returns an
65 // unsigned int with the supported Ioss::EntityTypes or'ed
66 // together. If "return_value & Ioss::EntityType" is set, then the
67 // database supports that type (e.g. return_value & Ioss::FACESET)
68 IOSS_NODISCARD unsigned entity_field_support() const override;
69
70 ~DatabaseIO() override;
71
72 IOSS_NODISCARD std::string get_format() const override { return "CGNS"; }
73
74 // This isn't quite true since a CGNS library with cgsize_t == 64-bits can read
75 // a file with 32-bit ints. However,...
76 IOSS_NODISCARD int int_byte_size_db() const override { return CG_SIZEOF_SIZE; }
77
78 IOSS_NODISCARD bool node_major() const override { return false; }
79
80 // Metadata-related functions.
81 void write_meta_data();
82 void write_results_meta_data();
83
84 IOSS_NODISCARD int get_file_pointer() const override;
85
86 private:
87 IOSS_NODISCARD int64_t node_global_to_local_nl(int64_t global, bool must_exist) const override;
88 IOSS_NODISCARD int64_t element_global_to_local_nl(int64_t global) const override;
89
90 void read_meta_data_nl() override;
91
92 void open_state_file(int state);
93 void free_state_pointer();
94
95 void openDatabase_nl() const override;
96 void closeDatabase_nl() const override;
97
98 IOSS_NODISCARD bool begin_nl(Ioss::State state) override;
99 IOSS_NODISCARD bool end_nl(Ioss::State state) override;
100
101 IOSS_NODISCARD bool begin_state_nl(int state, double time) override;
102 IOSS_NODISCARD bool end_state_nl(int state, double time) override;
103 void flush_database_nl() const override;
104
105 bool check_valid_file_open(int status) const;
106 void create_structured_block(int base, int zone, size_t &num_node);
107 void create_structured_block_fpp(int base, int num_zones, size_t &num_node);
108 size_t finalize_structured_blocks();
109 void finalize_database() const override;
110 void get_step_times_nl() override;
111 std::vector<double> get_db_step_times_nl() override;
112
113 void create_unstructured_block(int base, int zone, size_t &num_node);
114 void write_adjacency_data();
115
116 int64_t get_field_internal(const Ioss::Region *reg, const Ioss::Field &field, void *data,
117 size_t data_size) const override;
118 int64_t get_field_internal(const Ioss::NodeBlock *nb, const Ioss::Field &field, void *data,
119 size_t data_size) const override;
120 int64_t get_field_internal(const Ioss::EdgeBlock *eb, const Ioss::Field &field, void *data,
121 size_t data_size) const override;
122 int64_t get_field_internal(const Ioss::FaceBlock *fb, const Ioss::Field &field, void *data,
123 size_t data_size) const override;
124 int64_t get_field_internal(const Ioss::ElementBlock *eb, const Ioss::Field &field, void *data,
125 size_t data_size) const override;
126 int64_t get_field_internal(const Ioss::StructuredBlock *sb, const Ioss::Field &field,
127 void *data, size_t data_size) const override;
128 int64_t get_field_internal(const Ioss::SideBlock *sb, const Ioss::Field &field, void *data,
129 size_t data_size) const override;
130 int64_t get_field_internal(const Ioss::NodeSet *ns, const Ioss::Field &field, void *data,
131 size_t data_size) const override;
132 int64_t get_field_internal(const Ioss::EdgeSet *es, const Ioss::Field &field, void *data,
133 size_t data_size) const override;
134 int64_t get_field_internal(const Ioss::FaceSet *fs, const Ioss::Field &field, void *data,
135 size_t data_size) const override;
136 int64_t get_field_internal(const Ioss::ElementSet *es, const Ioss::Field &field, void *data,
137 size_t data_size) const override;
138 int64_t get_field_internal(const Ioss::SideSet *fs, const Ioss::Field &field, void *data,
139 size_t data_size) const override;
140 int64_t get_field_internal(const Ioss::CommSet *cs, const Ioss::Field &field, void *data,
141 size_t data_size) const override;
142 int64_t get_field_internal(const Ioss::Assembly * /*sb*/, const Ioss::Field & /*field*/,
143 void * /*data*/, size_t /*data_size*/) const override
144 {
145 return 0;
146 }
147
148 int64_t get_field_internal(const Ioss::Blob * /*sb*/, const Ioss::Field & /*field*/,
149 void * /*data*/, size_t /*data_size*/) const override
150 {
151 return 0;
152 }
153
154 int64_t get_field_internal_sub_nb(const Ioss::NodeBlock *nb, const Ioss::Field &field,
155 void *data, size_t data_size) const;
156
157 int64_t put_field_internal(const Ioss::Region *region, const Ioss::Field &field, void *data,
158 size_t data_size) const override;
159 int64_t put_field_internal(const Ioss::NodeBlock *nb, const Ioss::Field &field, void *data,
160 size_t data_size) const override;
161 int64_t put_field_internal(const Ioss::EdgeBlock *eb, const Ioss::Field &field, void *data,
162 size_t data_size) const override;
163 int64_t put_field_internal(const Ioss::FaceBlock *fb, const Ioss::Field &field, void *data,
164 size_t data_size) const override;
165 int64_t put_field_internal(const Ioss::ElementBlock *eb, const Ioss::Field &field, void *data,
166 size_t data_size) const override;
167 int64_t put_field_internal(const Ioss::SideBlock *sb, const Ioss::Field &field, void *data,
168 size_t data_size) const override;
169 int64_t put_field_internal(const Ioss::NodeSet *ns, const Ioss::Field &field, void *data,
170 size_t data_size) const override;
171 int64_t put_field_internal(const Ioss::EdgeSet *es, const Ioss::Field &field, void *data,
172 size_t data_size) const override;
173 int64_t put_field_internal(const Ioss::FaceSet *fs, const Ioss::Field &field, void *data,
174 size_t data_size) const override;
175 int64_t put_field_internal(const Ioss::ElementSet *es, const Ioss::Field &field, void *data,
176 size_t data_size) const override;
177 int64_t put_field_internal(const Ioss::SideSet *ss, const Ioss::Field &field, void *data,
178 size_t data_size) const override;
179 int64_t put_field_internal(const Ioss::CommSet *cs, const Ioss::Field &field, void *data,
180 size_t data_size) const override;
181 int64_t put_field_internal(const Ioss::StructuredBlock *sb, const Ioss::Field &field,
182 void *data, size_t data_size) const override;
183 int64_t put_field_internal(const Ioss::Assembly * /*sb*/, const Ioss::Field & /*field*/,
184 void * /*data*/, size_t /*data_size*/) const override
185 {
186 return 0;
187 }
188
189 int64_t put_field_internal(const Ioss::Blob * /*sb*/, const Ioss::Field & /*field*/,
190 void * /*data*/, size_t /*data_size*/) const override
191 {
192 return 0;
193 }
194
195 int64_t put_field_internal_sub_nb(const Ioss::NodeBlock *nb, const Ioss::Field &field,
196 void *data, size_t data_size) const;
197
198 // ID Mapping functions.
200 IOSS_NODISCARD const Ioss::Map &get_map(Ioss::Map &entity_map, int64_t entityCount,
201 int64_t file_offset, int64_t file_count,
202 entity_type type) const;
203
204 mutable int m_cgnsFilePtr{-1};
205 mutable int m_cgnsBasePtr{
206 -1}; // If using links to file-per-state, the file pointer for "base" file.
207
208 int m_flushInterval{0}; // Default is no flushing after each timestep
209 int m_currentVertexSolutionIndex{0};
210 int m_currentCellCenterSolutionIndex{0};
211 mutable bool m_dbFinalized{false};
212
213 mutable std::vector<size_t> m_zoneOffset; // Offset for local zone/block element ids to global.
214 mutable std::vector<size_t>
215 m_bcOffset; // The BC Section element offsets in unstructured output.
216 mutable std::vector<double> m_timesteps;
217 std::vector<CGNSIntVector> m_blockLocalNodeMap;
218 std::map<std::string, int> m_zoneNameMap;
219 mutable std::map<int, Ioss::Map *> m_globalToBlockLocalNodeMap;
220 mutable std::map<std::string, Ioss::FaceUnorderedSet> m_boundaryFaces;
221 };
222} // namespace Iocgns
#define IOSS_NODISCARD
Definition Ioss_CodeTypes.h:55
int Ioss_MPI_Comm
Definition Ioss_CodeTypes.h:64
Definition Iocgns_DatabaseIO.h:57
IOSS_NODISCARD int int_byte_size_db() const override
Definition Iocgns_DatabaseIO.h:76
int64_t put_field_internal(const Ioss::Blob *, const Ioss::Field &, void *, size_t) const override
Definition Iocgns_DatabaseIO.h:189
int64_t get_field_internal(const Ioss::Assembly *, const Ioss::Field &, void *, size_t) const override
Definition Iocgns_DatabaseIO.h:142
IOSS_NODISCARD const Ioss::Map & get_map(entity_type type) const
IOSS_NODISCARD bool node_major() const override
Definition Iocgns_DatabaseIO.h:78
entity_type
Definition Iocgns_DatabaseIO.h:59
std::vector< size_t > m_zoneOffset
Definition Iocgns_DatabaseIO.h:213
IOSS_NODISCARD const Ioss::Map & get_map(Ioss::Map &entity_map, int64_t entityCount, int64_t file_offset, int64_t file_count, entity_type type) const
std::vector< CGNSIntVector > m_blockLocalNodeMap
Definition Iocgns_DatabaseIO.h:217
std::map< std::string, int > m_zoneNameMap
Definition Iocgns_DatabaseIO.h:218
IOSS_NODISCARD std::string get_format() const override
Definition Iocgns_DatabaseIO.h:72
std::vector< double > m_timesteps
Definition Iocgns_DatabaseIO.h:216
std::map< int, Ioss::Map * > m_globalToBlockLocalNodeMap
Definition Iocgns_DatabaseIO.h:219
std::map< std::string, Ioss::FaceUnorderedSet > m_boundaryFaces
Definition Iocgns_DatabaseIO.h:220
int64_t get_field_internal(const Ioss::Blob *, const Ioss::Field &, void *, size_t) const override
Definition Iocgns_DatabaseIO.h:148
std::vector< size_t > m_bcOffset
Definition Iocgns_DatabaseIO.h:215
int64_t put_field_internal(const Ioss::Assembly *, const Ioss::Field &, void *, size_t) const override
Definition Iocgns_DatabaseIO.h:183
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
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