IOSS 2.0

Iofx_DatabaseIO.h
Go to the documentation of this file.
1 // Copyright(C) 1999-2017 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 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // * Redistributions in binary form must reproduce the above
13 // copyright notice, this list of conditions and the following
14 // disclaimer in the documentation and/or other materials provided
15 // with the distribution.
16 //
17 // * Neither the name of NTESS nor the names of its
18 // contributors may be used to endorse or promote products derived
19 // from this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
33 // -*- Mode: c++ -*-
34 #ifndef IOSS_Iofx_DatabaseIO_h
35 #define IOSS_Iofx_DatabaseIO_h
36
37 #include <Ioss_DBUsage.h>
38 #include <Ioss_Field.h>
39 #include <Ioss_Map.h>
40 #include <Ioss_Utils.h>
41 #include <exodus/Ioex_DatabaseIO.h>
42
43 #include <exodusII.h>
44
45 #include <algorithm>
46 #include <cstdint>
47 #include <ctime>
48 #include <map>
49 #include <set>
50 #include <sstream>
51 #include <string>
52 #include <vector>
53
54 namespace Ioss {
55 class GroupingEntity;
56 class Region;
57 class EntityBlock;
58 class NodeBlock;
59 class EdgeBlock;
60 class FaceBlock;
61 class ElementBlock;
62 class EntitySet;
63 class NodeSet;
64 class EdgeSet;
65 class FaceSet;
66 class ElementSet;
67 class SideBlock;
68 class SideSet;
69 class StructuredBlock;
70 class CommSet;
71 class ElementTopology;
72 } // namespace Ioss
73
74 namespace Ioex {
75 struct CommunicationMetaData;
76 } // namespace Ioex
77
78 /** \brief A namespace for the file-per-process version of the
79 * parallel exodus database format.
80 */
81 namespace Iofx {
82 class DatabaseIO : public Ioex::DatabaseIO
83 {
84 public:
85 DatabaseIO(Ioss::Region *region, const std::string &filename, Ioss::DatabaseUsage db_usage,
86 MPI_Comm communicator, const Ioss::PropertyManager &props);
87 DatabaseIO(const DatabaseIO &from) = delete;
88 DatabaseIO &operator=(const DatabaseIO &from) = delete;
89 ~DatabaseIO() override{};
90
91 // Kluge -- a few applications need access so can diretly access exodus API
92 int get_file_pointer() const override; // Open file and set exodusFilePtr.
93
94 private:
95 void get_step_times__() override;
96
97 bool open_input_file(bool write_message, std::string *error_msg, int *bad_count,
98 bool abort_if_error) const override;
99 bool handle_output_file(bool write_message, std::string *error_msg, int *bad_count,
100 bool overwrite, bool abort_if_error) const override;
101 bool check_valid_file_ptr(bool write_message, std::string *error_msg, int *bad_count,
102 bool abort_if_error) const;
103
104 int64_t get_field_internal(const Ioss::Region *reg, const Ioss::Field &field, void *data,
105 size_t data_size) const override;
106 int64_t get_field_internal(const Ioss::NodeBlock *nb, const Ioss::Field &field, void *data,
107 size_t data_size) const override;
108 int64_t get_field_internal(const Ioss::EdgeBlock *eb, const Ioss::Field &field, void *data,
109 size_t data_size) const override;
110 int64_t get_field_internal(const Ioss::FaceBlock *eb, const Ioss::Field &field, void *data,
111 size_t data_size) const override;
112 int64_t get_field_internal(const Ioss::ElementBlock *eb, const Ioss::Field &field, void *data,
113 size_t data_size) const override;
114 int64_t get_field_internal(const Ioss::StructuredBlock * /* sb */,
115 const Ioss::Field & /* field */, void * /* data */,
116 size_t /* data_size */) const override
117 {
118 return -1;
119 }
120
121 int64_t get_field_internal(const Ioss::SideBlock *fb, const Ioss::Field &field, void *data,
122 size_t data_size) const override;
123 int64_t get_field_internal(const Ioss::NodeSet *ns, const Ioss::Field &field, void *data,
124 size_t data_size) const override;
125 int64_t get_field_internal(const Ioss::EdgeSet *ns, const Ioss::Field &field, void *data,
126 size_t data_size) const override;
127 int64_t get_field_internal(const Ioss::FaceSet *ns, const Ioss::Field &field, void *data,
128 size_t data_size) const override;
129 int64_t get_field_internal(const Ioss::ElementSet *ns, const Ioss::Field &field, void *data,
130 size_t data_size) const override;
131 int64_t get_field_internal(const Ioss::SideSet *fs, const Ioss::Field &field, void *data,
132 size_t data_size) const override;
133 int64_t get_field_internal(const Ioss::CommSet *cs, const Ioss::Field &field, void *data,
134 size_t data_size) const override;
135
136 int64_t put_field_internal(const Ioss::Region *reg, const Ioss::Field &field, void *data,
137 size_t data_size) const override;
138 int64_t put_field_internal(const Ioss::NodeBlock *nb, const Ioss::Field &field, void *data,
139 size_t data_size) const override;
140 int64_t put_field_internal(const Ioss::EdgeBlock *eb, const Ioss::Field &field, void *data,
141 size_t data_size) const override;
142 int64_t put_field_internal(const Ioss::FaceBlock *eb, const Ioss::Field &field, void *data,
143 size_t data_size) const override;
144 int64_t put_field_internal(const Ioss::ElementBlock *eb, const Ioss::Field &field, void *data,
145 size_t data_size) const override;
146 int64_t put_field_internal(const Ioss::SideBlock *fb, const Ioss::Field &field, void *data,
147 size_t data_size) const override;
148 int64_t put_field_internal(const Ioss::NodeSet *ns, const Ioss::Field &field, void *data,
149 size_t data_size) const override;
150 int64_t put_field_internal(const Ioss::EdgeSet *ns, const Ioss::Field &field, void *data,
151 size_t data_size) const override;
152 int64_t put_field_internal(const Ioss::FaceSet *ns, const Ioss::Field &field, void *data,
153 size_t data_size) const override;
154 int64_t put_field_internal(const Ioss::ElementSet *ns, const Ioss::Field &field, void *data,
155 size_t data_size) const override;
156 int64_t put_field_internal(const Ioss::SideSet *fs, const Ioss::Field &field, void *data,
157 size_t data_size) const override;
158 int64_t put_field_internal(const Ioss::CommSet *cs, const Ioss::Field &field, void *data,
159 size_t data_size) const override;
160
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 int64_t put_Xset_field_internal(ex_entity_type type, const Ioss::EntitySet *ns,
168 const Ioss::Field &field, void *data, size_t data_size) const;
169 int64_t get_Xset_field_internal(ex_entity_type type, const Ioss::EntitySet *ns,
170 const Ioss::Field &field, void *data, size_t data_size) const;
171
172 private:
173 int64_t read_nodal_coordinates();
174 void read_elements(const Ioss::ElementBlock &block);
175
176 void compute_node_status() const;
177
178 // Metadata-related functions.
179 void read_meta_data__() override;
180 void read_communication_metadata();
181
182 int64_t read_transient_field(ex_entity_type type, const Ioex::VariableNameMap &variables,
183 const Ioss::Field &field, const Ioss::GroupingEntity *ge,
184 void *data) const;
185
186 int64_t read_attribute_field(ex_entity_type type, const Ioss::Field &field,
187 const Ioss::GroupingEntity *ge, void *data) const;
188
189 int64_t write_attribute_field(ex_entity_type type, const Ioss::Field &field,
190 const Ioss::GroupingEntity *ge, void *data) const;
191
192 // Handles subsetting of side blocks.
193 int64_t read_ss_transient_field(const Ioss::Field &field, int64_t id, void *variables,
194 std::vector<int> &is_valid_side) const;
195
196 // Should be made more generic again so can rejoin with write_element_transient field
197 void write_nodal_transient_field(ex_entity_type type, const Ioss::Field &field,
198 const Ioss::NodeBlock *ge, int64_t count,
199 void *variables) const;
200 // Should be made more generic again so can rejoin with write_nodal_transient field
201 void write_entity_transient_field(ex_entity_type type, const Ioss::Field &field,
202 const Ioss::GroupingEntity *ge, int64_t count,
203 void *variables) const;
204 void write_meta_data() override;
205 void gather_communication_metadata(Ioex::CommunicationMetaData *meta);
206
207 // Read related metadata and store it in the region...
208 void read_region();
209 void get_edgeblocks();
210 void get_faceblocks();
211 void get_elemblocks();
212 void get_blocks(ex_entity_type entity_type, int rank_offset, const std::string &basename);
213
214 void get_sidesets();
215
216 template <typename T>
217 void get_sets(ex_entity_type type, int64_t count, const std::string &base,
218 const T * /*unused*/);
219 void get_nodesets();
220 void get_edgesets();
221 void get_facesets();
222 void get_elemsets();
223
224 void get_commsets();
225
226 // ID Mapping functions.
227 const Ioss::Map &get_map(ex_entity_type type) const;
228 const Ioss::Map &get_map(Ioss::Map &entity_map, int64_t entityCount, ex_entity_type entity_type,
229 ex_inquiry inquiry_type) const;
230
231 // Internal data handling
232 int64_t handle_node_ids(void *ids, int64_t num_to_get) const;
233 int64_t handle_element_ids(const Ioss::ElementBlock *eb, void *ids, size_t num_to_get) const;
234 int64_t handle_face_ids(const Ioss::FaceBlock *eb, void *ids, size_t num_to_get) const;
235 int64_t handle_edge_ids(const Ioss::EdgeBlock *eb, void *ids, size_t num_to_get) const;
236
237 int64_t get_side_connectivity(const Ioss::SideBlock *fb, int64_t id, int64_t my_side_count,
238 void *fconnect, bool map_ids) const;
239 template <typename INT>
240 int64_t get_side_connectivity_internal(const Ioss::SideBlock *fb, int64_t id,
241 int64_t side_count, INT *fconnect, bool map_ids) const;
242 int64_t get_side_distributions(const Ioss::SideBlock *fb, 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 *ef_blk, const Ioss::Field &field, void *data,
246 size_t data_size) const;
247 int64_t put_side_field(const Ioss::SideBlock *fb, const Ioss::Field &field, void *data,
248 size_t data_size) const;
249
250 mutable bool isSerialParallel{
251 false}; //!< true if application code is controlling the processor id.
252 };
253 } // namespace Iofx
254 #endif
Iofx::DatabaseIO::get_side_distributions
int64_t get_side_distributions(const Ioss::SideBlock *fb, int64_t id, int64_t my_side_count, double *dist_fact, size_t data_size) const
Definition: Iofx_DatabaseIO.C:3643
Ioss_DBUsage.h
Iofx
A namespace for the file-per-process version of the parallel exodus database format.
Definition: Iofx_DatabaseIO.C:176
Ioss::Field
Holds metadata for bulk data associated with a GroupingEntity.
Definition: Ioss_Field.h:47
Iofx::DatabaseIO::read_nodal_coordinates
int64_t read_nodal_coordinates()
Iofx::DatabaseIO::handle_element_ids
int64_t handle_element_ids(const Ioss::ElementBlock *eb, void *ids, size_t num_to_get) const
Definition: Iofx_DatabaseIO.C:4305
Iofx::DatabaseIO::get_blocks
void get_blocks(ex_entity_type entity_type, int rank_offset, const std::string &basename)
Definition: Iofx_DatabaseIO.C:994
Ioss_Map.h
Iofx::DatabaseIO::read_transient_field
int64_t read_transient_field(ex_entity_type type, const Ioex::VariableNameMap &variables, const Ioss::Field &field, const Ioss::GroupingEntity *ge, void *data) const
Definition: Iofx_DatabaseIO.C:3377
Ioex::VariableNameMap
std::map< std::string, int, std::less< std::string > > VariableNameMap
Definition: Ioex_DatabaseIO.h:80
Iofx::DatabaseIO::get_side_connectivity
int64_t get_side_connectivity(const Ioss::SideBlock *fb, int64_t id, int64_t my_side_count, void *fconnect, bool map_ids) const
Definition: Iofx_DatabaseIO.C:3631
Iofx::DatabaseIO::handle_face_ids
int64_t handle_face_ids(const Ioss::FaceBlock *eb, void *ids, size_t num_to_get) const
Definition: Iofx_DatabaseIO.C:4313
Iofx::DatabaseIO::get_faceblocks
void get_faceblocks()
Definition: Iofx_DatabaseIO.C:990
Iofx::DatabaseIO::put_field_internal
int64_t put_field_internal(const Ioss::StructuredBlock *, const Ioss::Field &, void *, size_t) const override
Definition: Iofx_DatabaseIO.h:161
Iofx::DatabaseIO::write_meta_data
void write_meta_data() override
Definition: Iofx_DatabaseIO.C:5014
Iofx::DatabaseIO
Definition: Iofx_DatabaseIO.h:82
Ioss::EdgeBlock
A collection of element edges with the same topology.
Definition: Ioss_EdgeBlock.h:53
Ioss::DatabaseUsage
DatabaseUsage
Specifies how an Ioss::DatabaseIO object will be used.
Definition: Ioss_DBUsage.h:40
Ioss
The main namespace for the Ioss library.
Definition: Ioad_DatabaseIO.C:66
Ioex::DatabaseIO
Definition: Ioex_DatabaseIO.h:96
Iofx::DatabaseIO::write_entity_transient_field
void write_entity_transient_field(ex_entity_type type, const Ioss::Field &field, const Ioss::GroupingEntity *ge, int64_t count, void *variables) const
Definition: Iofx_DatabaseIO.C:4419
Ioex::CommunicationMetaData
Definition: Ioex_Internals.h:338
anonymous_namespace{Iovs_DatabaseIO.C}::entity_type
entity_type
Definition: Iovs_DatabaseIO.C:81
Iofx::DatabaseIO::compute_node_status
void compute_node_status() const
Definition: Iofx_DatabaseIO.C:1274
Ioss::Region
A grouping entity that contains other grouping entities.
Definition: Ioss_Region.h:98
Ioss::NodeSet
A collection of nodes.
Definition: Ioss_NodeSet.h:53
Ioex_DatabaseIO.h
Ioss::FaceSet
A collection of element faces.
Definition: Ioss_FaceSet.h:54
Ioss::StructuredBlock
A structured zone – i,j,k.
Definition: Ioss_StructuredBlock.h:103
Iofx::DatabaseIO::operator=
DatabaseIO & operator=(const DatabaseIO &from)=delete
Iofx::DatabaseIO::get_step_times__
void get_step_times__() override
Definition: Iofx_DatabaseIO.C:620
Iofx::DatabaseIO::read_meta_data__
void read_meta_data__() override
Definition: Iofx_DatabaseIO.C:445
INT
int INT
Definition: Ioss_StructuredBlock.h:53
Ioss::PropertyManager
A collection of Ioss::Property objects.
Definition: Ioss_PropertyManager.h:49
Ioss::EdgeSet
A collection of element edges.
Definition: Ioss_EdgeSet.h:54
Ioss::ElementSet
A collection of elements.
Definition: Ioss_ElementSet.h:54
Ioss::CommSet
Definition: Ioss_CommSet.h:51
Iofx::DatabaseIO::get_map
const Ioss::Map & get_map(ex_entity_type type) const
Definition: Iofx_DatabaseIO.C:889
Iofx::DatabaseIO::handle_edge_ids
int64_t handle_edge_ids(const Ioss::EdgeBlock *eb, void *ids, size_t num_to_get) const
Definition: Iofx_DatabaseIO.C:4320
Iofx::DatabaseIO::get_sets
void get_sets(ex_entity_type type, int64_t count, const std::string &base, const T *)
Definition: Iofx_DatabaseIO.C:1755
Iofx::DatabaseIO::get_sidesets
void get_sidesets()
Definition: Iofx_DatabaseIO.C:1323
Ioss::FaceBlock
A collection of element faces with the same topology.
Definition: Ioss_FaceBlock.h:53
Iofx::DatabaseIO::get_facesets
void get_facesets()
Definition: Iofx_DatabaseIO.C:1897
Iofx::DatabaseIO::get_field_internal
int64_t get_field_internal(const Ioss::Region *reg, const Ioss::Field &field, void *data, size_t data_size) const override
Definition: Iofx_DatabaseIO.C:1983
Ioss::DatabaseIO::DatabaseIO
DatabaseIO()=delete
Ioex
A namespace for the exodus database format.
Definition: Ioex_IOFactory.C:62
Iofx::DatabaseIO::~DatabaseIO
~DatabaseIO() override
Definition: Iofx_DatabaseIO.h:89
Iofx::DatabaseIO::get_elemblocks
void get_elemblocks()
Definition: Iofx_DatabaseIO.C:988
Ioss_Utils.h
Ioss::SideBlock
A collection of element sides having the same topology.
Definition: Ioss_SideBlock.h:59
Iofx::DatabaseIO::get_edgeblocks
void get_edgeblocks()
Definition: Iofx_DatabaseIO.C:992
Ioss_Field.h
Iofx::DatabaseIO::gather_communication_metadata
void gather_communication_metadata(Ioex::CommunicationMetaData *meta)
Definition: Iofx_DatabaseIO.C:5205
Iofx::DatabaseIO::read_elements
void read_elements(const Ioss::ElementBlock &block)
Iofx::DatabaseIO::open_input_file
bool open_input_file(bool write_message, std::string *error_msg, int *bad_count, bool abort_if_error) const override
Definition: Iofx_DatabaseIO.C:290
Iofx::DatabaseIO::put_Xset_field_internal
int64_t put_Xset_field_internal(ex_entity_type type, const Ioss::EntitySet *ns, const Ioss::Field &field, void *data, size_t data_size) const
Definition: Iofx_DatabaseIO.C:4539
Iofx::DatabaseIO::get_file_pointer
int get_file_pointer() const override
Definition: Iofx_DatabaseIO.C:422
Iofx::DatabaseIO::read_ss_transient_field
int64_t read_ss_transient_field(const Ioss::Field &field, int64_t id, void *variables, std::vector< int > &is_valid_side) const
Definition: Iofx_DatabaseIO.C:3458
Ioss::EntitySet
Base class for all 'set'-type grouping entities, which means that members of the set are not necessar...
Definition: Ioss_EntitySet.h:61
Ioss::ElementBlock
A collection of elements having the same topology.
Definition: Ioss_ElementBlock.h:48
Iofx::DatabaseIO::get_Xset_field_internal
int64_t get_Xset_field_internal(ex_entity_type type, const Ioss::EntitySet *ns, const Ioss::Field &field, void *data, size_t data_size) const
Definition: Iofx_DatabaseIO.C:2495
Iofx::DatabaseIO::isSerialParallel
bool isSerialParallel
true if application code is controlling the processor id.
Definition: Iofx_DatabaseIO.h:250
Iofx::DatabaseIO::get_edgesets
void get_edgesets()
Definition: Iofx_DatabaseIO.C:1892
Iofx::DatabaseIO::put_field_internal
int64_t put_field_internal(const Ioss::Region *reg, const Ioss::Field &field, void *data, size_t data_size) const override
Definition: Iofx_DatabaseIO.C:3823
Iofx::DatabaseIO::check_valid_file_ptr
bool check_valid_file_ptr(bool write_message, std::string *error_msg, int *bad_count, bool abort_if_error) const
Definition: Iofx_DatabaseIO.C:210
Ioss::Map
Definition: Ioss_Map.h:52
Iofx::DatabaseIO::get_side_field
int64_t get_side_field(const Ioss::SideBlock *ef_blk, const Ioss::Field &field, void *data, size_t data_size) const
anonymous_namespace{cth_pressure_map.C}::data
std::vector< char > data
Definition: cth_pressure_map.C:74
Iofx::DatabaseIO::get_commsets
void get_commsets()
Definition: Iofx_DatabaseIO.C:1907
Iofx::DatabaseIO::get_nodesets
void get_nodesets()
Definition: Iofx_DatabaseIO.C:1887
Iofx::DatabaseIO::write_nodal_transient_field
void write_nodal_transient_field(ex_entity_type type, const Ioss::Field &field, const Ioss::NodeBlock *ge, int64_t count, void *variables) const
Definition: Iofx_DatabaseIO.C:4327
Ioss::NodeBlock
A collection of all nodes in the region.
Definition: Ioss_NodeBlock.h:53
MPI_Comm
int MPI_Comm
Definition: Ioss_CodeTypes.h:96
Iofx::DatabaseIO::read_communication_metadata
void read_communication_metadata()
Definition: Iofx_DatabaseIO.C:744
Iofx::DatabaseIO::handle_output_file
bool handle_output_file(bool write_message, std::string *error_msg, int *bad_count, bool overwrite, bool abort_if_error) const override
Definition: Iofx_DatabaseIO.C:332
Iofx::DatabaseIO::read_attribute_field
int64_t read_attribute_field(ex_entity_type type, const Ioss::Field &field, const Ioss::GroupingEntity *ge, void *data) const
Definition: Iofx_DatabaseIO.C:3312
Iofx::DatabaseIO::put_side_field
int64_t put_side_field(const Ioss::SideBlock *fb, const Ioss::Field &field, void *data, size_t data_size) const
Ioss::SideSet
A collection of element sides.
Definition: Ioss_SideSet.h:53
Ioss::GroupingEntity
Base class for all 'grouping' entities. The following derived classes are typical:
Definition: Ioss_GroupingEntity.h:93
Iofx::DatabaseIO::write_attribute_field
int64_t write_attribute_field(ex_entity_type type, const Ioss::Field &field, const Ioss::GroupingEntity *ge, void *data) const
Definition: Iofx_DatabaseIO.C:3218
Iofx::DatabaseIO::get_side_connectivity_internal
int64_t get_side_connectivity_internal(const Ioss::SideBlock *fb, int64_t id, int64_t side_count, INT *fconnect, bool map_ids) const
Definition: Iofx_DatabaseIO.C:3532
Iofx::DatabaseIO::read_region
void read_region()
Definition: Iofx_DatabaseIO.C:506
Iofx::DatabaseIO::get_elemsets
void get_elemsets()
Definition: Iofx_DatabaseIO.C:1902
Iofx::DatabaseIO::get_field_internal
int64_t get_field_internal(const Ioss::StructuredBlock *, const Ioss::Field &, void *, size_t) const override
Definition: Iofx_DatabaseIO.h:114
Iofx::DatabaseIO::handle_node_ids
int64_t handle_node_ids(void *ids, int64_t num_to_get) const
Definition: Iofx_DatabaseIO.C:4242