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 private:
92 // Check to see if database state is ok...
93 // If 'write_message' true, then output a warning message indicating the problem.
94 // If 'error_message' non-null, then put the warning message into the string and return it.
95 // If 'bad_count' non-null, it counts the number of processors where the file does not exist.
96 // if ok returns false, but *bad_count==0, then the routine does not support this argument.
97 bool ok__(bool write_message = false, std::string *error_msg = nullptr,
98 int *bad_count = nullptr) const override;
99
100 void get_step_times__() override;
101
102 bool open_input_file(bool write_message, std::string *error_msg, int *bad_count,
103 bool abort_if_error) const;
104 bool handle_output_file(bool write_message, std::string *error_msg, int *bad_count,
105 bool overwrite, bool abort_if_error) const;
106 bool check_valid_file_ptr(bool write_message, std::string *error_msg, int *bad_count,
107 bool abort_if_error) const;
108
109 int64_t get_field_internal(const Ioss::Region *reg, const Ioss::Field &field, void *data,
110 size_t data_size) const override;
111 int64_t get_field_internal(const Ioss::NodeBlock *nb, const Ioss::Field &field, void *data,
112 size_t data_size) const override;
113 int64_t get_field_internal(const Ioss::EdgeBlock *eb, const Ioss::Field &field, void *data,
114 size_t data_size) const override;
115 int64_t get_field_internal(const Ioss::FaceBlock *eb, const Ioss::Field &field, void *data,
116 size_t data_size) const override;
117 int64_t get_field_internal(const Ioss::ElementBlock *eb, const Ioss::Field &field, void *data,
118 size_t data_size) const override;
119 int64_t get_field_internal(const Ioss::StructuredBlock *sb, const Ioss::Field &field,
120 void *data, size_t data_size) const override
121 {
122 return -1;
123 }
124
125 int64_t get_field_internal(const Ioss::SideBlock *fb, const Ioss::Field &field, void *data,
126 size_t data_size) const override;
127 int64_t get_field_internal(const Ioss::NodeSet *ns, const Ioss::Field &field, void *data,
128 size_t data_size) const override;
129 int64_t get_field_internal(const Ioss::EdgeSet *ns, const Ioss::Field &field, void *data,
130 size_t data_size) const override;
131 int64_t get_field_internal(const Ioss::FaceSet *ns, const Ioss::Field &field, void *data,
132 size_t data_size) const override;
133 int64_t get_field_internal(const Ioss::ElementSet *ns, const Ioss::Field &field, void *data,
134 size_t data_size) const override;
135 int64_t get_field_internal(const Ioss::SideSet *fs, const Ioss::Field &field, void *data,
136 size_t data_size) const override;
137 int64_t get_field_internal(const Ioss::CommSet *cs, const Ioss::Field &field, void *data,
138 size_t data_size) const override;
139
140 int64_t put_field_internal(const Ioss::Region *reg, const Ioss::Field &field, void *data,
141 size_t data_size) const override;
142 int64_t put_field_internal(const Ioss::NodeBlock *nb, const Ioss::Field &field, void *data,
143 size_t data_size) const override;
144 int64_t put_field_internal(const Ioss::EdgeBlock *eb, const Ioss::Field &field, void *data,
145 size_t data_size) const override;
146 int64_t put_field_internal(const Ioss::FaceBlock *eb, const Ioss::Field &field, void *data,
147 size_t data_size) const override;
148 int64_t put_field_internal(const Ioss::ElementBlock *eb, const Ioss::Field &field, void *data,
149 size_t data_size) const override;
150 int64_t put_field_internal(const Ioss::SideBlock *fb, const Ioss::Field &field, void *data,
151 size_t data_size) const override;
152 int64_t put_field_internal(const Ioss::NodeSet *ns, const Ioss::Field &field, void *data,
153 size_t data_size) const override;
154 int64_t put_field_internal(const Ioss::EdgeSet *ns, const Ioss::Field &field, void *data,
155 size_t data_size) const override;
156 int64_t put_field_internal(const Ioss::FaceSet *ns, const Ioss::Field &field, void *data,
157 size_t data_size) const override;
158 int64_t put_field_internal(const Ioss::ElementSet *ns, const Ioss::Field &field, void *data,
159 size_t data_size) const override;
160 int64_t put_field_internal(const Ioss::SideSet *fs, const Ioss::Field &field, void *data,
161 size_t data_size) const override;
162 int64_t put_field_internal(const Ioss::CommSet *cs, const Ioss::Field &field, void *data,
163 size_t data_size) const override;
164
165 int64_t put_field_internal(const Ioss::StructuredBlock *sb, const Ioss::Field &field,
166 void *data, size_t data_size) const override
167 {
168 return -1;
169 }
170 int64_t put_Xset_field_internal(ex_entity_type type, const Ioss::EntitySet *ns,
171 const Ioss::Field &field, void *data, size_t data_size) const;
172 int64_t get_Xset_field_internal(ex_entity_type type, const Ioss::EntitySet *ns,
173 const Ioss::Field &field, void *data, size_t data_size) const;
174
175 public:
176 // Temporarily made public for use during Salinas transition
177 // to using Ioss
178 int get_file_pointer() const override; // Open file and set exodusFilePtr.
179 private:
180 int64_t read_nodal_coordinates();
181 void read_elements(const Ioss::ElementBlock &block);
182
183 void compute_node_status() const;
184
185 // Metadata-related functions.
186 void read_meta_data__() override;
187 void read_communication_metadata();
188
189 int64_t read_transient_field(ex_entity_type type, const Ioex::VariableNameMap &variables,
190 const Ioss::Field &field, const Ioss::GroupingEntity *ge,
191 void *data) const;
192
193 int64_t read_attribute_field(ex_entity_type type, const Ioss::Field &field,
194 const Ioss::GroupingEntity *ge, void *data) const;
195
196 int64_t write_attribute_field(ex_entity_type type, const Ioss::Field &field,
197 const Ioss::GroupingEntity *ge, void *data) const;
198
199 // Handles subsetting of side blocks.
200 int64_t read_ss_transient_field(const Ioss::Field &field, int64_t id, void *variables,
201 std::vector<int> &is_valid_side) const;
202
203 // Should be made more generic again so can rejoin with write_element_transient field
204 void write_nodal_transient_field(ex_entity_type type, const Ioss::Field &field,
205 const Ioss::NodeBlock *ge, int64_t count,
206 void *variables) const;
207 // Should be made more generic again so can rejoin with write_nodal_transient field
208 void write_entity_transient_field(ex_entity_type type, const Ioss::Field &field,
209 const Ioss::GroupingEntity *ge, int64_t count,
210 void *variables) const;
211 void write_meta_data() override;
212 void gather_communication_metadata(Ioex::CommunicationMetaData *meta);
213
214 // Read related metadata and store it in the region...
215 void read_region();
216 void get_edgeblocks();
217 void get_faceblocks();
218 void get_elemblocks();
219 void get_blocks(ex_entity_type entity_type, int rank_offset, const std::string &basename);
220
221 void get_sidesets();
222
223 template <typename T>
224 void get_sets(ex_entity_type type, int64_t count, const std::string &base,
225 const T * /*unused*/);
226 void get_nodesets();
227 void get_edgesets();
228 void get_facesets();
229 void get_elemsets();
230
231 void get_commsets();
232
233 // ID Mapping functions.
234 const Ioss::Map &get_map(ex_entity_type type) const;
235 const Ioss::Map &get_map(Ioss::Map &entity_map, int64_t entityCount, ex_entity_type entity_type,
236 ex_inquiry inquiry_type) const;
237
238 // Internal data handling
239 int64_t handle_node_ids(void *ids, int64_t num_to_get) const;
240 int64_t handle_element_ids(const Ioss::ElementBlock *eb, void *ids, size_t num_to_get) const;
241 int64_t handle_face_ids(const Ioss::FaceBlock *eb, void *ids, size_t num_to_get) const;
242 int64_t handle_edge_ids(const Ioss::EdgeBlock *eb, void *ids, size_t num_to_get) const;
243
244 int64_t get_side_connectivity(const Ioss::SideBlock *fb, int64_t id, int64_t my_side_count,
245 void *fconnect, bool map_ids) const;
246 template <typename INT>
247 int64_t get_side_connectivity_internal(const Ioss::SideBlock *fb, int64_t id,
248 int64_t side_count, INT *fconnect, bool map_ids) const;
249 int64_t get_side_distributions(const Ioss::SideBlock *fb, int64_t id, int64_t my_side_count,
250 double *dist_fact, size_t data_size) const;
251
252 int64_t get_side_field(const Ioss::SideBlock *ef_blk, const Ioss::Field &field, void *data,
253 size_t data_size) const;
254 int64_t put_side_field(const Ioss::SideBlock *fb, const Ioss::Field &field, void *data,
255 size_t data_size) const;
256
257 mutable bool isSerialParallel{
258 false}; //!< true if application code is controlling the processor id.
259 };
260 } // namespace Iofx
261 #endif
Ioss
The main namespace for the Ioss library.
Definition: Iocgns_DatabaseIO.h:50
Ioss_DBUsage.h
Ioss::EntitySet
Base class for all &#39;set&#39;-type grouping entities, which means that members of the set are not necessar...
Definition: Ioss_EntitySet.h:61
Ioss::NodeSet
A collection of nodes.
Definition: Ioss_NodeSet.h:53
Ioss::FaceBlock
A collection of element faces with the same topology.
Definition: Ioss_FaceBlock.h:53
Ioss::FaceSet
A collection of element faces.
Definition: Ioss_FaceSet.h:54
Ioss::GroupingEntity
Base class for all &#39;grouping&#39; entities. The following derived classes are typical: ...
Definition: Ioss_GroupingEntity.h:93
Ioss::EdgeSet
A collection of element edges.
Definition: Ioss_EdgeSet.h:54
Ioss_Map.h
Iofx::DatabaseIO::put_field_internal
int64_t put_field_internal(const Ioss::StructuredBlock *sb, const Ioss::Field &field, void *data, size_t data_size) const override
Definition: Iofx_DatabaseIO.h:165
Ioss::SideBlock
A collection of element sides having the same topology.
Definition: Ioss_SideBlock.h:61
Ioss::ElementBlock
A collection of elements having the same topology.
Definition: Ioss_ElementBlock.h:48
Ioex::VariableNameMap
std::map< std::string, int, std::less< std::string > > VariableNameMap
Definition: Ioex_DatabaseIO.h:80
Ioss::StructuredBlock
A structured zone – i,j,k.
Definition: Ioss_StructuredBlock.h:98
Ioss::ElementSet
A collection of elements.
Definition: Ioss_ElementSet.h:54
Iofx::DatabaseIO::get_field_internal
int64_t get_field_internal(const Ioss::StructuredBlock *sb, const Ioss::Field &field, void *data, size_t data_size) const override
Definition: Iofx_DatabaseIO.h:119
Ioss::DatabaseUsage
DatabaseUsage
Specifies how an Ioss::DatabaseIO object will be used.
Definition: Ioss_DBUsage.h:40
Ioss_Utils.h
Ioex
A namespace for the exodus database format.
Definition: Ioex_IOFactory.C:61
Ioss::NodeBlock
A collection of all nodes in the region.
Definition: Ioss_NodeBlock.h:53
INT
int INT
Definition: Ioss_StructuredBlock.h:53
Ioss::Map
Definition: Ioss_Map.h:52
Ioss::CommSet
Definition: Ioss_CommSet.h:51
Ioex_DatabaseIO.h
Ioss_Field.h
anonymous_namespace{Iodw_DatabaseIO.C}::get_file_pointer
int get_file_pointer()
Definition: Iodw_DatabaseIO.C:64
Ioss::Region
A grouping entity that contains other grouping entities.
Definition: Ioss_Region.h:98
Ioex::CommunicationMetaData
Definition: Ioex_Internals.h:370
Ioss::SideSet
A collection of element sides.
Definition: Ioss_SideSet.h:59
Ioss::Field
Holds metadata for bulk data associated with a GroupingEntity.
Definition: Ioss_Field.h:47
MPI_Comm
int MPI_Comm
Definition: Ioss_CodeTypes.h:79
Iofx::DatabaseIO
Definition: Iofx_DatabaseIO.h:82
Ioex::DatabaseIO
Definition: Ioex_DatabaseIO.h:96
Ioss::PropertyManager
A collection of Ioss::Property objects.
Definition: Ioss_PropertyManager.h:49
Iofx::DatabaseIO::~DatabaseIO
~DatabaseIO() override
Definition: Iofx_DatabaseIO.h:89
anonymous_namespace{Iovs_DatabaseIO.C}::entity_type
entity_type
Definition: Iovs_DatabaseIO.C:81
anonymous_namespace{Ioss_Utils.C}::data
std::vector< char > data
Definition: Ioss_Utils.C:78
Ioss::EdgeBlock
A collection of element edges with the same topology.
Definition: Ioss_EdgeBlock.h:53
Iofx
A namespace for the file-per-process version of the parallel exodus database format.
Definition: Iofx_DatabaseIO.C:157