IOSS 2.0
Loading...
Searching...
No Matches
Ioex_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// -*- Mode: c++ -*-
8#pragma once
9
10#include "Ioss_DBUsage.h"
11#include "Ioss_Field.h"
12#include "Ioss_Map.h"
13#include "Ioss_Utils.h"
15#include <algorithm>
16#include <cstdint>
17#include <ctime>
18#include <exodusII.h>
19#include <map>
20#include <set>
21#include <sstream>
22#include <string>
23#include <vector>
24
25#include "Ioss_CodeTypes.h"
26#include "ioex_export.h"
27
28namespace Ioss {
29 class GroupingEntity;
30 class Region;
31 class EntityBlock;
32 class NodeBlock;
33 class EdgeBlock;
34 class FaceBlock;
35 class ElementBlock;
36 class EntitySet;
37 class NodeSet;
38 class EdgeSet;
39 class FaceSet;
40 class ElementSet;
41 class SideBlock;
42 class SideSet;
43 class StructuredBlock;
44 class CommSet;
45 class ElementTopology;
46 class Assembly;
47 class Blob;
48 class Field;
49 class Map;
50 class PropertyManager;
51} // namespace Ioss
52
53namespace Ioex {
54 struct CommunicationMetaData;
55} // namespace Ioex
56
57/** \brief A namespace for the file-per-process version of the
58 * parallel exodus database format.
59 */
60namespace Ioex {
61 class IOEX_EXPORT DatabaseIO : public Ioex::BaseDatabaseIO
62 {
63 public:
64 DatabaseIO(Ioss::Region *region, const std::string &filename, Ioss::DatabaseUsage db_usage,
65 Ioss_MPI_Comm communicator, const Ioss::PropertyManager &props);
66
67 // Kluge -- a few applications need access so can directly access exodus API
68 IOSS_NODISCARD int get_file_pointer() const override; // Open file and set exodusFilePtr.
69
70 private:
71 void get_step_times_nl() override;
72 std::vector<double> get_db_step_times_nl() override;
73 std::vector<double> internal_get_step_times_nl(bool setRegionTimeSteps);
74
75 bool open_input_file(bool write_message, std::string *error_msg, int *bad_count,
76 bool abort_if_error) const override;
77 bool handle_output_file(bool write_message, std::string *error_msg, int *bad_count,
78 bool overwrite, bool abort_if_error) const override;
79 IOSS_NODISCARD bool check_valid_file_ptr(bool write_message, std::string *error_msg,
80 int *bad_count, bool abort_if_error) const;
81
82 int64_t get_field_internal(const Ioss::Region *reg, const Ioss::Field &field, void *data,
83 size_t data_size) const override;
84 int64_t get_field_internal(const Ioss::Blob *blob, const Ioss::Field &field, void *data,
85 size_t data_size) const override;
86 int64_t get_field_internal(const Ioss::Assembly *assem, const Ioss::Field &field, void *data,
87 size_t data_size) const override;
88 int64_t get_field_internal(const Ioss::NodeBlock *nb, const Ioss::Field &field, void *data,
89 size_t data_size) const override;
90 int64_t get_field_internal(const Ioss::EdgeBlock *eb, const Ioss::Field &field, void *data,
91 size_t data_size) const override;
92 int64_t get_field_internal(const Ioss::FaceBlock *eb, const Ioss::Field &field, void *data,
93 size_t data_size) const override;
94 int64_t get_field_internal(const Ioss::ElementBlock *eb, const Ioss::Field &field, void *data,
95 size_t data_size) const override;
96 int64_t get_field_internal(const Ioss::StructuredBlock * /* sb */,
97 const Ioss::Field & /* field */, void * /* data */,
98 size_t /* data_size */) const override
99 {
100 return -1;
101 }
102
103 int64_t get_field_internal(const Ioss::SideBlock *fb, const Ioss::Field &field, void *data,
104 size_t data_size) const override;
105 int64_t get_field_internal(const Ioss::NodeSet *ns, const Ioss::Field &field, void *data,
106 size_t data_size) const override;
107 int64_t get_field_internal(const Ioss::EdgeSet *ns, const Ioss::Field &field, void *data,
108 size_t data_size) const override;
109 int64_t get_field_internal(const Ioss::FaceSet *ns, const Ioss::Field &field, void *data,
110 size_t data_size) const override;
111 int64_t get_field_internal(const Ioss::ElementSet *ns, const Ioss::Field &field, void *data,
112 size_t data_size) const override;
113 int64_t get_field_internal(const Ioss::SideSet *ss, const Ioss::Field &field, void *data,
114 size_t data_size) const override;
115 int64_t get_field_internal(const Ioss::CommSet *cs, const Ioss::Field &field, void *data,
116 size_t data_size) const override;
117
118 int64_t put_field_internal(const Ioss::Region *reg, const Ioss::Field &field, void *data,
119 size_t data_size) const override;
120 int64_t put_field_internal(const Ioss::Blob *blob, const Ioss::Field &field, void *data,
121 size_t data_size) const override;
122 int64_t put_field_internal(const Ioss::Assembly *assem, const Ioss::Field &field, void *data,
123 size_t data_size) const override;
124 int64_t put_field_internal(const Ioss::NodeBlock *nb, const Ioss::Field &field, void *data,
125 size_t data_size) const override;
126 int64_t put_field_internal(const Ioss::EdgeBlock *eb, const Ioss::Field &field, void *data,
127 size_t data_size) const override;
128 int64_t put_field_internal(const Ioss::FaceBlock *eb, const Ioss::Field &field, void *data,
129 size_t data_size) const override;
130 int64_t put_field_internal(const Ioss::ElementBlock *eb, const Ioss::Field &field, void *data,
131 size_t data_size) const override;
132 int64_t put_field_internal(const Ioss::SideBlock *fb, const Ioss::Field &field, void *data,
133 size_t data_size) const override;
134 int64_t put_field_internal(const Ioss::NodeSet *ns, const Ioss::Field &field, void *data,
135 size_t data_size) const override;
136 int64_t put_field_internal(const Ioss::EdgeSet *ns, const Ioss::Field &field, void *data,
137 size_t data_size) const override;
138 int64_t put_field_internal(const Ioss::FaceSet *ns, const Ioss::Field &field, void *data,
139 size_t data_size) const override;
140 int64_t put_field_internal(const Ioss::ElementSet *ns, const Ioss::Field &field, void *data,
141 size_t data_size) const override;
142 int64_t put_field_internal(const Ioss::SideSet *ss, const Ioss::Field &field, void *data,
143 size_t data_size) const override;
144 int64_t put_field_internal(const Ioss::CommSet *cs, const Ioss::Field &field, void *data,
145 size_t data_size) const override;
146
148 const Ioss::Field & /* field */, void * /* data */,
149 size_t /* data_size */) const override
150 {
151 return -1;
152 }
153 int64_t put_Xset_field_internal(const Ioss::EntitySet *ns, const Ioss::Field &field, void *data,
154 size_t data_size) const;
155 int64_t get_Xset_field_internal(const Ioss::EntitySet *ns, const Ioss::Field &field, void *data,
156 size_t data_size) const;
157
158 private:
161
162 void compute_node_status() const;
163
164 // Metadata-related functions.
165 void read_meta_data_nl() override;
166 void read_communication_metadata();
167
168 int64_t read_transient_field(const Ioex::VariableNameMap &variables, const Ioss::Field &field,
169 const Ioss::GroupingEntity *ge, void *data) const;
170
171 int64_t read_attribute_field(const Ioss::Field &field, const Ioss::GroupingEntity *ge,
172 void *data) const;
173
174 int64_t write_attribute_field(const Ioss::Field &field, const Ioss::GroupingEntity *ge,
175 void *data) const;
176
177 // Handles subsetting of side blocks.
178 int64_t read_ss_transient_field(const Ioss::Field &field, int64_t id, void *variables,
179 std::vector<int> &is_valid_side) const;
180
181 // Should be made more generic again so can rejoin with write_element_transient field
182 void write_nodal_transient_field(const Ioss::Field &field, const Ioss::NodeBlock *ge,
183 int64_t count, void *variables) const;
184 // Should be made more generic again so can rejoin with write_nodal_transient field
185 void write_entity_transient_field(const Ioss::Field &field, const Ioss::GroupingEntity *ge,
186 int64_t count, void *variables) const;
187 void write_meta_data(Ioss::IfDatabaseExistsBehavior behavior) override;
188 void gather_communication_metadata(Ioex::CommunicationMetaData *meta);
189
190 // Read related metadata and store it in the region...
191 void read_region();
192 void get_edgeblocks();
193 void get_faceblocks();
194 void get_elemblocks();
195 void get_blocks(ex_entity_type entity_type, int rank_offset, const std::string &basename);
196
197 void get_sidesets();
198
199 template <typename T>
200 void get_sets(ex_entity_type type, int64_t count, const std::string &base,
201 const T * /*unused*/);
202 void get_nodesets();
203 void get_edgesets();
204 void get_facesets();
205 void get_elemsets();
206
207 void get_commsets();
208
209 // ID Mapping functions.
210 IOSS_NODISCARD const Ioss::Map &get_map(ex_entity_type type) const;
211 IOSS_NODISCARD const Ioss::Map &get_map(Ioss::Map &entity_map, int64_t entity_count,
212 ex_entity_type entity_type,
213 ex_inquiry inquiry_type) const;
214
215 // Internal data handling
216 int64_t handle_node_ids(void *ids, int64_t num_to_get) const;
217 int64_t handle_element_ids(const Ioss::ElementBlock *eb, void *ids, size_t num_to_get) const;
218 int64_t handle_face_ids(const Ioss::FaceBlock *eb, void *ids, size_t num_to_get) const;
219 int64_t handle_edge_ids(const Ioss::EdgeBlock *eb, void *ids, size_t num_to_get) const;
220
221 int64_t get_side_connectivity(const Ioss::SideBlock *sd_blk, int64_t id, int64_t my_side_count,
222 void *fconnect, bool map_ids) const;
223 template <typename INT>
224 int64_t get_side_connectivity_internal(const Ioss::SideBlock *sd_blk, int64_t id,
225 int64_t side_count, INT *fconnect, bool map_ids) const;
226 int64_t get_side_distributions(const Ioss::SideBlock *sd_blk, int64_t id, int64_t my_side_count,
227 double *dist_fact, size_t data_size) const;
228
229 int64_t get_side_field(const Ioss::SideBlock *sd_blk, const Ioss::Field &field, void *data,
230 size_t data_size) const;
231 int64_t put_side_field(const Ioss::SideBlock *sd_blk, const Ioss::Field &field, void *data,
232 size_t data_size) const;
233
234 //!< true if application code is controlling the processor id.
235 mutable bool isSerialParallel{false};
236 };
237} // namespace Ioex
#define IOSS_NODISCARD
Definition Ioss_CodeTypes.h:55
int Ioss_MPI_Comm
Definition Ioss_CodeTypes.h:64
Definition Ioex_BaseDatabaseIO.h:78
Definition Ioex_DatabaseIO.h:62
void read_elements(const Ioss::ElementBlock &block)
int64_t get_field_internal(const Ioss::StructuredBlock *, const Ioss::Field &, void *, size_t) const override
Definition Ioex_DatabaseIO.h:96
int64_t get_side_field(const Ioss::SideBlock *sd_blk, const Ioss::Field &field, void *data, size_t data_size) const
int64_t put_side_field(const Ioss::SideBlock *sd_blk, const Ioss::Field &field, void *data, size_t data_size) const
true if application code is controlling the processor id.
int64_t read_nodal_coordinates()
int64_t put_field_internal(const Ioss::StructuredBlock *, const Ioss::Field &, void *, size_t) const override
Definition Ioex_DatabaseIO.h:147
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
The main namespace for the Ioss library.
Definition Ioad_DatabaseIO.C:40
DatabaseUsage
Specifies how an Ioss::DatabaseIO object will be used.
Definition Ioss_DBUsage.h:13
IfDatabaseExistsBehavior
Definition Ioss_DBUsage.h:32
Definition Ioex_Internals.h:264