IOSS 2.0
Loading...
Searching...
No Matches
Ioex_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// -*- Mode: c++ -*-
8#pragma once
9
10#include <exodusII.h>
11
12#include "ioex_export.h"
13#if defined PARALLEL_AWARE_EXODUS
14#include "Ioss_CodeTypes.h"
15#include "Ioss_DBUsage.h" // for DatabaseUsage
16#include "Ioss_Map.h" // for Map
17#include "Ioss_State.h" // for State
18#include "exodus/Ioex_BaseDatabaseIO.h" // for DatabaseIO
19#include <functional> // for less
20#include <map> // for map, map<>::value_compare
21#include <memory>
22#include <set> // for set
23#include <stddef.h> // for size_t
24#include <stdint.h> // for int64_t
25#include <string> // for string, operator<
26#include <time.h> // for nullptr, time_t
27#include <utility> // for pair
28#include <vector> // for vector
29
30namespace Ioex {
31 class DecompositionDataBase;
32 struct BlockFieldData;
33} // namespace Ioex
34namespace Ioex {
35 template <typename INT> class DecompositionData;
36}
37
38namespace Ioss {
39 class Assembly;
40 class Blob;
41 class EntityBlock;
42 class ElementTopology;
43 class CommSet;
44 class EdgeBlock;
45 class EdgeSet;
46 class ElementBlock;
47 class ElementSet;
48 class EntitySet;
49 class FaceBlock;
50 class FaceSet;
51 class Field;
52 class GroupingEntity;
53 class NodeBlock;
54 class NodeSet;
55 class PropertyManager;
56 class Region;
57 class SideBlock;
58 class SideSet;
59 class StructuredBlock;
60} // namespace Ioss
61
62/** \brief A namespace for the decompose-on-the-fly version of the
63 * parallel exodus database format.
64 */
65namespace Ioex {
66 class IOEX_EXPORT ParallelDatabaseIO : public Ioex::BaseDatabaseIO
67 {
68 public:
69 ParallelDatabaseIO(Ioss::Region *region, const std::string &filename,
70 Ioss::DatabaseUsage db_usage, Ioss_MPI_Comm communicator,
71 const Ioss::PropertyManager &properties);
72 ~ParallelDatabaseIO();
73
74 IOSS_NODISCARD int get_file_pointer() const override; // Open file and set exodusFilePtr.
75 IOSS_NODISCARD bool needs_shared_node_information() const override { return true; }
76
77 std::vector<size_t> get_entity_field_data(const std::string &field_name,
78 const std::vector<Ioss::ElementBlock *> &elem_blocks,
79 void *data, size_t data_size) const override;
80
81 private:
82 void compute_node_status() const;
83
84 void release_memory_nl() override;
85
86 void get_step_times_nl() override;
87
88 std::vector<double> get_db_step_times_nl() override;
89
90 std::vector<double> internal_get_step_times_nl(bool setRegionTimeSteps);
91
92 bool open_input_file(bool write_message, std::string *error_msg, int *bad_count,
93 bool abort_if_error) const override;
94 bool handle_output_file(bool write_message, std::string *error_msg, int *bad_count,
95 bool overwrite, bool abort_if_error) const override;
96 bool check_valid_file_ptr(bool write_message, std::string *error_msg, int *bad_count,
97 bool abort_if_error) const;
98
99 int64_t get_field_internal(const Ioss::Region *reg, const Ioss::Field &field, void *data,
100 size_t data_size) const override;
101 int64_t get_field_internal(const Ioss::NodeBlock *nb, const Ioss::Field &field, void *data,
102 size_t data_size) const override;
103 int64_t get_field_internal(const Ioss::EdgeBlock *eb, const Ioss::Field &field, void *data,
104 size_t data_size) const override;
105 int64_t get_field_internal(const Ioss::FaceBlock *eb, const Ioss::Field &field, void *data,
106 size_t data_size) const override;
107 int64_t get_field_internal(const Ioss::ElementBlock *eb, const Ioss::Field &field, void *data,
108 size_t data_size) const override;
109 int64_t get_field_internal(const Ioss::StructuredBlock * /* sb */,
110 const Ioss::Field & /* field */, void * /* data */,
111 size_t /* data_size */) const override
112 {
113 return -1;
114 }
115 int64_t get_field_internal(const Ioss::SideBlock *sb, const Ioss::Field &field, void *data,
116 size_t data_size) const override;
117 int64_t get_field_internal(const Ioss::NodeSet *ns, const Ioss::Field &field, void *data,
118 size_t data_size) const override;
119 int64_t get_field_internal(const Ioss::EdgeSet *ns, const Ioss::Field &field, void *data,
120 size_t data_size) const override;
121 int64_t get_field_internal(const Ioss::FaceSet *ns, const Ioss::Field &field, void *data,
122 size_t data_size) const override;
123 int64_t get_field_internal(const Ioss::ElementSet *ns, const Ioss::Field &field, void *data,
124 size_t data_size) const override;
125 int64_t get_field_internal(const Ioss::SideSet *fs, const Ioss::Field &field, void *data,
126 size_t data_size) const override;
127 int64_t get_field_internal(const Ioss::CommSet *cs, const Ioss::Field &field, void *data,
128 size_t data_size) const override;
129 int64_t get_field_internal(const Ioss::Assembly *sb, const Ioss::Field &field, void *data,
130 size_t data_size) const override;
131 int64_t get_field_internal(const Ioss::Blob *sb, const Ioss::Field &field, void *data,
132 size_t data_size) const override;
133 int64_t put_field_internal(const Ioss::Region *reg, const Ioss::Field &field, void *data,
134 size_t data_size) const override;
135 int64_t put_field_internal(const Ioss::NodeBlock *nb, const Ioss::Field &field, void *data,
136 size_t data_size) const override;
137 int64_t put_field_internal(const Ioss::EdgeBlock *eb, const Ioss::Field &field, void *data,
138 size_t data_size) const override;
139 int64_t put_field_internal(const Ioss::FaceBlock *eb, const Ioss::Field &field, void *data,
140 size_t data_size) const override;
141 int64_t put_field_internal(const Ioss::ElementBlock *eb, const Ioss::Field &field, void *data,
142 size_t data_size) const override;
143 int64_t put_field_internal(const Ioss::SideBlock *sb, const Ioss::Field &field, void *data,
144 size_t data_size) const override;
145 int64_t put_field_internal(const Ioss::NodeSet *ns, const Ioss::Field &field, void *data,
146 size_t data_size) const override;
147 int64_t put_field_internal(const Ioss::EdgeSet *ns, const Ioss::Field &field, void *data,
148 size_t data_size) const override;
149 int64_t put_field_internal(const Ioss::FaceSet *ns, const Ioss::Field &field, void *data,
150 size_t data_size) const override;
151 int64_t put_field_internal(const Ioss::ElementSet *ns, const Ioss::Field &field, void *data,
152 size_t data_size) const override;
153 int64_t put_field_internal(const Ioss::SideSet *ss, const Ioss::Field &field, void *data,
154 size_t data_size) const override;
155 int64_t put_field_internal(const Ioss::CommSet *cs, const Ioss::Field &field, void *data,
156 size_t data_size) const override;
157 int64_t put_field_internal(const Ioss::Assembly *sb, const Ioss::Field &field, void *data,
158 size_t data_size) const override;
159 int64_t put_field_internal(const Ioss::Blob *sb, const Ioss::Field &field, void *data,
160 size_t data_size) const override;
161 int64_t put_field_internal(const Ioss::StructuredBlock * /* sb */,
162 const Ioss::Field & /* field */, void * /* data */,
163 size_t /* data_size */) const override
164 {
165 return -1;
166 }
167
168 int64_t put_Xset_field_internal(const Ioss::EntitySet *ns, const Ioss::Field &field, void *data,
169 size_t data_size) const;
170 int64_t get_Xset_field_internal(const Ioss::EntitySet *ns, const Ioss::Field &field, void *data,
171 size_t data_size) const;
172
173 int free_file_pointer() const override;
174
175 int64_t read_nodal_coordinates();
176 void read_elements(const Ioss::ElementBlock &block);
177
178 void create_implicit_global_map() const;
179 void output_node_map() const;
180
181 // Metadata-related functions.
182 void read_meta_data_nl() override;
183
184 int64_t read_transient_field(const Ioex::VariableNameMap &variables, const Ioss::Field &field,
185 const Ioss::GroupingEntity *ge, void *data) const;
186
187 int64_t read_attribute_field(const Ioss::Field &field, const Ioss::GroupingEntity *ge,
188 void *data) const;
189
190 int64_t write_attribute_field(const Ioss::Field &field, const Ioss::GroupingEntity *ge,
191 void *data) const;
192
193 // Handles subsetting of side blocks.
194 int64_t read_ss_transient_field(const Ioss::Field &field, int64_t id, void *variables,
195 std::vector<int> &is_valid_side) const;
196
197 // Should be made more generic again so can rejoin with write_element_transient field
198 void write_nodal_transient_field(const Ioss::Field &field, const Ioss::NodeBlock *nb,
199 int64_t count, void *variables) const;
200 // Should be made more generic again so can rejoin with write_nodal_transient field
201 void write_entity_transient_field(const Ioss::Field &field, const Ioss::GroupingEntity *ge,
202 int64_t count, void *variables) const;
203 void write_meta_data(Ioss::IfDatabaseExistsBehavior behavior) override;
204 template <typename INT> void output_processor_id_map(Ioss::Region *region);
205
206 // Read related metadata and store it in the region...
207 void read_region();
208 void get_edgeblocks();
209 void get_faceblocks();
210 void get_elemblocks();
211 void get_blocks(ex_entity_type entity_type, int rank_offset, const std::string &basename);
212
213 void get_sidesets();
214
215 template <typename T>
216 void get_sets(ex_entity_type type, int64_t count, const std::string &base, const T *);
217 void get_nodesets();
218 void get_edgesets();
219 void get_facesets();
220 void get_elemsets();
221
222 void get_commsets();
223
224 void check_valid_values() const;
225
226 // ID Mapping functions.
227 IOSS_NODISCARD const Ioss::Map &get_map(ex_entity_type type) const;
228 IOSS_NODISCARD const Ioss::Map &get_map(Ioss::Map &entity_map, int64_t entityCount,
229 int64_t file_offset, int64_t file_count,
230 ex_entity_type entity_type,
231 ex_inquiry inquiry_type) const;
232
233 // Internal data handling
234 int64_t handle_node_ids(void *ids, int64_t num_to_get, size_t offset, size_t count) const;
235 int64_t handle_element_ids(const Ioss::ElementBlock *eb, void *ids, size_t num_to_get,
236 size_t offset, size_t count) const;
237 int64_t handle_face_ids(const Ioss::FaceBlock *eb, void *ids, size_t num_to_get) const;
238 int64_t handle_edge_ids(const Ioss::EdgeBlock *eb, void *ids, size_t num_to_get) const;
239
240 int64_t get_side_connectivity(const Ioss::SideBlock *sd_blk, int64_t id, int64_t side_count,
241 void *fconnect, bool map_ids) const;
242 int64_t get_side_distributions(const Ioss::SideBlock *sd_blk, int64_t id, int64_t my_side_count,
243 double *dist_fact, size_t data_size) const;
244
245 int64_t get_side_field(const Ioss::SideBlock *sd_blk, const Ioss::Field &field, void *data,
246 size_t data_size) const;
247 int64_t put_side_field(const Ioss::SideBlock *sd_blk, const Ioss::Field &field, void *data,
248 size_t data_size) const;
249
250 template <typename T>
251 std::vector<Ioex::BlockFieldData>
252 get_entity_block_field_data(const Ioex::VariableNameMap &variables,
253 const std::string &field_name,
254 const std::vector<T *> &entity_container) const;
255
256 std::vector<size_t>
257 get_entity_connectivity_field_data(const std::string &field_name,
258 const std::vector<Ioss::ElementBlock *> &elem_blocks,
259 void *data, size_t data_size) const;
260
261 std::vector<size_t> get_entity_transient_field_data(
262 const Ioex::VariableNameMap &variables, const std::string &field_name,
263 const std::vector<Ioss::ElementBlock *> &elem_blocks, void *data) const;
264
265 // Private member data...
266 mutable std::unique_ptr<DecompositionDataBase> decomp;
267
268 mutable Ioss::IntVector nodeOwningProcessor; // Processor that owns each node on this processor
269 mutable Ioss::Int64Vector
270 nodeGlobalImplicitMap; // Position of this node in the global-implicit ordering
271 mutable Ioss::Int64Vector
272 elemGlobalImplicitMap; // Position of this element in the global-implicit ordering
273
274 // Contains the indices of all owned nodes in each nodeset on this processor to pull data
275 // from the global list down to the file list.
276 // NOTE: Even though map type is GroupingEntity*, it is only valid
277 // for a GroupingEntity* which is a NodeSet*
278 mutable std::map<const Ioss::GroupingEntity *, Ioss::Int64Vector> nodesetOwnedNodes;
279
280 mutable bool metaDataWritten{false};
281 mutable bool nodeGlobalImplicitMapDefined{false};
282 mutable bool elemGlobalImplicitMapDefined{false};
283 };
284} // namespace Ioex
285#endif
#define IOSS_NODISCARD
Definition Ioss_CodeTypes.h:55
int Ioss_MPI_Comm
Definition Ioss_CodeTypes.h:64
Definition Ioex_BaseDatabaseIO.h:78
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
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
Base class for all 'set'-type grouping entities, which means that members of the set are not necessar...
Definition Ioss_EntitySet.h:38
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
Base class for all 'grouping' entities. The following derived classes are typical:
Definition Ioss_GroupingEntity.h:67
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 exodus database format.
Definition Ioex_BaseDatabaseIO.C:209
std::map< std::string, int, std::less<> > VariableNameMap
Definition Ioex_BaseDatabaseIO.h:61
int get_file_pointer()
Definition Iofaodel_DatabaseIO.C:55
The main namespace for the Ioss library.
Definition Ioad_DatabaseIO.C:40
std::vector< int64_t > Int64Vector
Definition Ioss_CodeTypes.h:22
DatabaseUsage
Specifies how an Ioss::DatabaseIO object will be used.
Definition Ioss_DBUsage.h:13
std::vector< int > IntVector
Definition Ioss_CodeTypes.h:21
IfDatabaseExistsBehavior
Definition Ioss_DBUsage.h:32