IOSS 2.0
Loading...
Searching...
No Matches
Ioad_DatabaseIO.h
Go to the documentation of this file.
1// Copyright(C) 1999-2020, 2022, 2023, 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 "ioad_export.h"
10
11#include "Ioss_DBUsage.h"
12#include "Ioss_DatabaseIO.h"
13#include "Ioss_EntitySet.h"
14#include "Ioss_Region.h" // for Region, SideSetContainer, etc
15#include "Ioss_SideSet.h" // for SideBlockContainer, SideSet
16
17#include "Ioss_Field.h" // for Field, etc
18#include <AdiosWrapper.h>
19
20namespace Ioss {
21 class Assembly;
22 class Blob;
23 class GroupingEntity;
24 class Region;
25 class EntityBlock;
26 class NodeBlock;
27 class SideBlock;
28 class ElementBlock;
29 class NodeSet;
30 class SideSet;
31 class CommSet;
32} // namespace Ioss
33
34/** \brief A namespace for the adios database format.
35 */
36namespace Ioad {
37
38 class IOAD_EXPORT DatabaseIO : public Ioss::DatabaseIO
39 {
40 public:
41 DatabaseIO(Ioss::Region *region, const std::string &filename, Ioss::DatabaseUsage db_usage,
42 Ioss_MPI_Comm communicator, const Ioss::PropertyManager &props);
43
44 std::string get_format() const override { return "ADIOS2"; }
45
46 bool begin_nl(Ioss::State state) override;
47 bool end_nl(Ioss::State state) override;
48
49 unsigned entity_field_support() const override;
50 int int_byte_size_db() const override;
51
52 private:
53 int64_t get_field_internal(const Ioss::Region *reg, const Ioss::Field &field, void *data,
54 size_t data_size) const override;
55 int64_t get_field_internal(const Ioss::NodeBlock *nb, const Ioss::Field &field, void *data,
56 size_t data_size) const override;
57 int64_t get_field_internal(const Ioss::EdgeBlock *eb, const Ioss::Field &field, void *data,
58 size_t data_size) const override;
59 int64_t get_field_internal(const Ioss::FaceBlock *fb, const Ioss::Field &field, void *data,
60 size_t data_size) const override;
61 int64_t get_field_internal(const Ioss::ElementBlock *eb, const Ioss::Field &field, void *data,
62 size_t data_size) const override;
63 int64_t get_field_internal(const Ioss::StructuredBlock * /* sb */,
64 const Ioss::Field & /*field*/, void * /*data*/,
65 size_t /*data_size*/) const override
66 {
67 return -1;
68 }
69 int64_t get_field_internal(const Ioss::Assembly * /*sb*/, const Ioss::Field & /*field*/,
70 void * /*data*/, size_t /*data_size*/) const override
71 {
72 return -1;
73 }
74 int64_t get_field_internal(const Ioss::Blob * /*sb*/, const Ioss::Field & /*field*/,
75 void * /*data*/, size_t /*data_size*/) const override
76 {
77 return -1;
78 }
79 int64_t get_field_internal(const Ioss::SideBlock *sb, const Ioss::Field &field, void *data,
80 size_t data_size) const override;
81 int64_t get_field_internal(const Ioss::NodeSet *ns, const Ioss::Field &field, void *data,
82 size_t data_size) const override;
83 int64_t get_field_internal(const Ioss::EdgeSet *es, const Ioss::Field &field, void *data,
84 size_t data_size) const override;
85 int64_t get_field_internal(const Ioss::FaceSet *fs, const Ioss::Field &field, void *data,
86 size_t data_size) const override;
87 int64_t get_field_internal(const Ioss::ElementSet *es, const Ioss::Field &field, void *data,
88 size_t data_size) const override;
89 int64_t get_field_internal(const Ioss::SideSet *ss, const Ioss::Field &field, void *data,
90 size_t data_size) const override;
91 int64_t get_field_internal(const Ioss::CommSet *cs, const Ioss::Field &field, void *data,
92 size_t data_size) const override;
93
94 int64_t get_field_internal_t(const Ioss::GroupingEntity *entity, const Ioss::Field &field,
95 void *data, size_t data_size) const;
96 template <typename T>
97 void get_data(void *data, const std::string &encoded_name,
98 bool use_step_selection = false) const;
99
100 int64_t put_field_internal(const Ioss::Region *reg, const Ioss::Field &field, void *data,
101 size_t data_size) const override;
102 int64_t put_field_internal(const Ioss::NodeBlock *nb, const Ioss::Field &field, void *data,
103 size_t data_size) const override;
104 int64_t put_field_internal(const Ioss::EdgeBlock *eb, const Ioss::Field &field, void *data,
105 size_t data_size) const override;
106 int64_t put_field_internal(const Ioss::FaceBlock *fb, const Ioss::Field &field, void *data,
107 size_t data_size) const override;
108 int64_t put_field_internal(const Ioss::ElementBlock *eb, const Ioss::Field &field, void *data,
109 size_t data_size) const override;
110 int64_t put_field_internal(const Ioss::SideBlock *sb, const Ioss::Field &field, void *data,
111 size_t data_size) const override;
112 int64_t put_field_internal(const Ioss::NodeSet *ns, const Ioss::Field &field, void *data,
113 size_t data_size) const override;
114 int64_t put_field_internal(const Ioss::EdgeSet *es, const Ioss::Field &field, void *data,
115 size_t data_size) const override;
116 int64_t put_field_internal(const Ioss::FaceSet *fs, const Ioss::Field &field, void *data,
117 size_t data_size) const override;
118 int64_t put_field_internal(const Ioss::ElementSet *es, const Ioss::Field &field, void *data,
119 size_t data_size) const override;
120 int64_t put_field_internal(const Ioss::SideSet *ss, const Ioss::Field &field, void *data,
121 size_t data_size) const override;
122 int64_t put_field_internal(const Ioss::CommSet *cs, const Ioss::Field &field, void *data,
123 size_t data_size) const override;
124 int64_t put_field_internal(const Ioss::StructuredBlock * /*sb*/, const Ioss::Field & /*field*/,
125 void * /*data*/, size_t /*data_size*/) const override
126 {
127 return -1;
128 }
129 int64_t put_field_internal(const Ioss::Assembly * /*sb*/, const Ioss::Field & /*field*/,
130 void * /*data*/, size_t /*data_size*/) const override
131 {
132 return -1;
133 }
134 int64_t put_field_internal(const Ioss::Blob * /*sb*/, const Ioss::Field & /*field*/,
135 void * /*data*/, size_t /*data_size*/) const override
136 {
137 return -1;
138 }
139 template <typename T>
140 int64_t put_field_internal_t(T entity, const Ioss::Field &field, void *data,
141 size_t data_size) const;
142 void define_model(Ioss::Field::RoleType *role = nullptr);
143 // Model definition that should not be re-defined when defining transient variables.
144 void define_global_variables();
145 template <typename T> T get_attribute(const std::string &attribute_name);
146
147 template <typename T> void put_data(void *data, const std::string &encoded_name) const;
148 template <typename T,
149 typename = typename std::enable_if_t<!std::is_base_of_v<Ioss::EntitySet, T>, T>>
150 void put_var_type(const Ioss::Field &field, const std::string &encoded_name,
151 bool transformed_field) const;
152 template <typename T>
153 void define_model_internal(const Ioss::Field &field, const std::string &encoded_name,
154 const std::string &entity_type, const std::string &field_name);
155 template <typename T>
156 void define_entity_internal(const T &entity_blocks, Ioss::Field::RoleType *role);
157
158 int get_current_state() const;
159
161 {
162 std::vector<size_t> steps;
163 adios2::Dims Count;
164 size_t global_size{0};
165 };
166
168 {
169 // Information contained in block infos.
170 std::vector<size_t> steps;
171 size_t node_boundaries_size = 0;
172 size_t component_count = 0;
173 // Contained in metavariables
175 std::string variable_type;
177 std::string topology;
178 std::string parent_topology;
179 };
180
181 template <typename T> BlockInfoType get_block_infos(const adios2::Variable<T> &var) const;
182
183 template <typename T> FieldInfoType get_variable_infos(const std::string &var_name) const;
184 using GlobalMapType = std::map<std::string, std::pair<std::string, std::string>>;
185 using EntityMapType = std::map<std::string, GlobalMapType>;
186 using FieldsMapType = std::map<std::string, EntityMapType>;
187
188 template <typename T>
189 std::string get_property_value(const FieldsMapType &properties_map,
190 const std::string &entity_type, const std::string &entity_name,
191 const std::string &property_name) const;
192
193 template <typename T>
194 FieldInfoType get_expected_variable_infos_from_map(const EntityMapType &fields_map,
195 const std::string &entity_type,
196 const std::string &entity_name,
197 const std::string &var_name) const;
198 FieldInfoType get_variable_infos_from_map(const EntityMapType &fields_map,
199 const std::string &entity_type,
200 const std::string &entity_name,
201 const std::string &var_name) const;
202
203 template <typename T>
204 using IsIossEntityBlock = typename std::enable_if_t<std::is_base_of_v<Ioss::EntityBlock, T>>;
205 template <typename T>
207 typename std::enable_if_t<!std::is_base_of_v<Ioss::EntityBlock, T>>;
208
209 template <typename T, typename = IsIossEntityBlock<T>>
210 void define_entity_meta_variables(const std::string &encoded_name);
211
212 template <typename T, typename = IsNotIossEntityBlock<T>, typename = void>
213 void define_entity_meta_variables(const std::string &encoded_name);
214
215 void define_field_meta_variables(const std::string &);
216 void define_coordinate_frames_internal(const Ioss::CoordinateFrameContainer &coordinate_frames);
217 std::string encoded_coordinate_frame_name(Ioss::CoordinateFrame coordinate_frame);
218
219 void put_meta_variables(const std::string &encoded_name, const Ioss::Field &field,
220 const std::string &entity_type, const std::string &field_name) const;
221 void write_meta_data();
222
223 template <typename T>
224 void add_entity_property(Ioss::GroupingEntity *ge, const std::string &encoded_name,
225 const std::string &var_name);
226 void add_entity_properties(Ioss::GroupingEntity *ge, const FieldsMapType &properties_map,
227 std::string name = "");
228
229 void write_properties(const Ioss::GroupingEntity *const entity,
230 const std::string &encoded_name);
231
232 template <typename T> int64_t write_meta_data_container(const T &entity_blocks);
233 std::pair<int64_t, int64_t>
234 write_meta_data_sideblockcontainer(const Ioss::SideBlockContainer &entity_blocks);
235
236 template <typename T>
237 int64_t get_entities(const FieldsMapType &fields_map, const FieldsMapType &properties_map);
238 std::string get_optional_string_variable(const std::string &field_name,
239 const std::string &string_variable) const;
240
241 void get_globals(const GlobalMapType &globals_map, const FieldsMapType &properties_map);
242 void compute_block_membership_nl(Ioss::SideBlock *efblock,
243 std::vector<std::string> &block_membership) const override;
244 void define_properties(const Ioss::GroupingEntity *entity_block,
245 const std::string &encoded_entity_name);
246
247 void read_meta_data_nl() override;
248 void read_communication_metadata();
249 void read_region(const FieldsMapType &fields_map);
250 void check_processor_info();
251 void check_model();
252
253 int RankInit();
254 bool begin_state_nl(int state, double time) override;
255 bool end_state_nl(int state, double time) override;
256 unsigned long rank; // rank needs to be declared first to be initialized before adios_wrapper.
257 mutable AdiosWrapper adios_wrapper; // adios_wrapper needs to be declared before bpio
258 // and bp_engine to be initialized first.
259 int spatialDimension{0};
260 int64_t edgeCount{0};
261 int64_t faceCount{0};
262 unsigned long number_proc;
265 };
266} // namespace Ioad
int Ioss_MPI_Comm
Definition Ioss_CodeTypes.h:64
Definition AdiosWrapper.h:19
Definition Ioad_DatabaseIO.h:39
int64_t get_field_internal(const Ioss::Assembly *, const Ioss::Field &, void *, size_t) const override
Definition Ioad_DatabaseIO.h:69
std::string get_format() const override
Definition Ioad_DatabaseIO.h:44
T get_attribute(const std::string &attribute_name)
int64_t put_field_internal(const Ioss::StructuredBlock *, const Ioss::Field &, void *, size_t) const override
Definition Ioad_DatabaseIO.h:124
double previous_time_streaming
Definition Ioad_DatabaseIO.h:264
int64_t put_field_internal(const Ioss::Assembly *, const Ioss::Field &, void *, size_t) const override
Definition Ioad_DatabaseIO.h:129
AdiosWrapper adios_wrapper
Definition Ioad_DatabaseIO.h:257
int64_t get_field_internal(const Ioss::Blob *, const Ioss::Field &, void *, size_t) const override
Definition Ioad_DatabaseIO.h:74
typename std::enable_if_t<!std::is_base_of_v< Ioss::EntityBlock, T > > IsNotIossEntityBlock
Definition Ioad_DatabaseIO.h:206
bool is_streaming
Definition Ioad_DatabaseIO.h:263
std::map< std::string, EntityMapType > FieldsMapType
Definition Ioad_DatabaseIO.h:186
int64_t get_field_internal(const Ioss::StructuredBlock *, const Ioss::Field &, void *, size_t) const override
Definition Ioad_DatabaseIO.h:63
void put_var_type(const Ioss::Field &field, const std::string &encoded_name, bool transformed_field) const
int64_t put_field_internal(const Ioss::Blob *, const Ioss::Field &, void *, size_t) const override
Definition Ioad_DatabaseIO.h:134
unsigned long number_proc
Definition Ioad_DatabaseIO.h:262
typename std::enable_if_t< std::is_base_of_v< Ioss::EntityBlock, T > > IsIossEntityBlock
Definition Ioad_DatabaseIO.h:204
std::map< std::string, GlobalMapType > EntityMapType
Definition Ioad_DatabaseIO.h:185
std::map< std::string, std::pair< std::string, std::string > > GlobalMapType
Definition Ioad_DatabaseIO.h:184
unsigned long rank
Definition Ioad_DatabaseIO.h:256
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
Definition Ioss_CoordinateFrame.h:19
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
BasicType
The basic data type held in the field.
Definition Ioss_Field.h:29
RoleType
Definition Ioss_Field.h:69
Base class for all 'grouping' entities. The following derived classes are typical:
Definition Ioss_GroupingEntity.h:67
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 adios database format.
Definition AdiosWrapper.C:11
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
std::vector< SideBlock * > SideBlockContainer
Definition Ioss_SideSet.h:24
std::vector< CoordinateFrame > CoordinateFrameContainer
Definition Ioex_Utils.h:46
Definition Ioad_DatabaseIO.h:161
adios2::Dims Count
Definition Ioad_DatabaseIO.h:163
std::vector< size_t > steps
Definition Ioad_DatabaseIO.h:162
Definition Ioad_DatabaseIO.h:168
std::vector< size_t > steps
Definition Ioad_DatabaseIO.h:170
Ioss::Field::RoleType role
Definition Ioad_DatabaseIO.h:174
std::string variable_type
Definition Ioad_DatabaseIO.h:175
std::string parent_topology
Definition Ioad_DatabaseIO.h:178
Ioss::Field::BasicType basic_type
Definition Ioad_DatabaseIO.h:176
std::string topology
Definition Ioad_DatabaseIO.h:177