IOSS 2.0

Iopx_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_Iopx_DatabaseIO_h
35 #define IOSS_Iopx_DatabaseIO_h
36
37 #include <Ioss_CodeTypes.h>
38 #include <Ioss_DBUsage.h> // for DatabaseUsage
39 #include <Ioss_Map.h> // for Map
40 #include <Ioss_State.h> // for State
41 #include <exodus/Ioex_DatabaseIO.h> // for DatabaseIO
42 #include <exodusII.h> // for ex_entity_type, etc
43 #include <functional> // for less
44 #include <map> // for map, map<>::value_compare
45 #include <memory>
46 #include <set> // for set
47 #include <stddef.h> // for size_t
48 #include <stdint.h> // for int64_t
49 #include <string> // for string, operator<
50 #include <time.h> // for nullptr, time_t
51 #include <utility> // for pair
52 #include <vector> // for vector
53 namespace Iopx {
54 class DecompositionDataBase;
55 }
56 namespace Iopx {
57 template <typename INT> class DecompositionData;
58 }
59
60 namespace Ioss {
61 class EntityBlock;
62 class ElementTopology;
63 class CommSet;
64 class EdgeBlock;
65 class EdgeSet;
66 class ElementBlock;
67 class ElementSet;
68 class EntitySet;
69 class FaceBlock;
70 class FaceSet;
71 class Field;
72 class GroupingEntity;
73 class NodeBlock;
74 class NodeSet;
75 class PropertyManager;
76 class Region;
77 class SideBlock;
78 class SideSet;
79 class StructuredBlock;
80 } // namespace Ioss
81
82 /** \brief A namespace for the decompose-on-the-fly version of the
83 * parallel exodus database format.
84 */
85 namespace Iopx {
86 class DatabaseIO : public Ioex::DatabaseIO
87 {
88 public:
89 DatabaseIO(Ioss::Region *region, const std::string &filename, Ioss::DatabaseUsage db_usage,
90 MPI_Comm communicator, const Ioss::PropertyManager &properties);
91 DatabaseIO(const DatabaseIO &from) = delete;
92 DatabaseIO &operator=(const DatabaseIO &from) = delete;
93 ~DatabaseIO();
94
95 bool needs_shared_node_information() const override { return true; }
96
97 private:
98 void compute_node_status() const;
99
100 void release_memory__() override;
101
102 // Check to see if database state is ok...
103 // If 'write_message' true, then output a warning message indicating the problem.
104 // If 'error_message' non-null, then put the warning message into the string and return it.
105 // If 'bad_count' non-null, it counts the number of processors where the file does not exist.
106 // if ok returns false, but *bad_count==0, then the routine does not support this argument.
107 bool ok__(bool write_message = false, std::string *error_message = nullptr,
108 int *bad_count = nullptr) const override;
109
110 void get_step_times__() override;
111
112 bool open_input_file(bool write_message, std::string *error_msg, int *bad_count,
113 bool abort_if_error) const;
114 bool handle_output_file(bool write_message, std::string *error_msg, int *bad_count,
115 bool overwrite, bool abort_if_error) const;
116 bool check_valid_file_ptr(bool write_message, std::string *error_msg, int *bad_count,
117 bool abort_if_error) const;
118
119 int64_t get_field_internal(const Ioss::Region *reg, const Ioss::Field &field, void *data,
120 size_t data_size) const override;
121 int64_t get_field_internal(const Ioss::NodeBlock *nb, const Ioss::Field &field, void *data,
122 size_t data_size) const override;
123 int64_t get_field_internal(const Ioss::EdgeBlock *eb, const Ioss::Field &field, void *data,
124 size_t data_size) const override;
125 int64_t get_field_internal(const Ioss::FaceBlock *eb, const Ioss::Field &field, void *data,
126 size_t data_size) const override;
127 int64_t get_field_internal(const Ioss::ElementBlock *eb, const Ioss::Field &field, void *data,
128 size_t data_size) const override;
129 int64_t get_field_internal(const Ioss::StructuredBlock *sb, const Ioss::Field &field,
130 void *data, size_t data_size) const override
131 {
132 return -1;
133 }
134 int64_t get_field_internal(const Ioss::SideBlock *fb, const Ioss::Field &field, void *data,
135 size_t data_size) const override;
136 int64_t get_field_internal(const Ioss::NodeSet *ns, const Ioss::Field &field, void *data,
137 size_t data_size) const override;
138 int64_t get_field_internal(const Ioss::EdgeSet *ns, const Ioss::Field &field, void *data,
139 size_t data_size) const override;
140 int64_t get_field_internal(const Ioss::FaceSet *ns, const Ioss::Field &field, void *data,
141 size_t data_size) const override;
142 int64_t get_field_internal(const Ioss::ElementSet *ns, const Ioss::Field &field, void *data,
143 size_t data_size) const override;
144 int64_t get_field_internal(const Ioss::SideSet *fs, const Ioss::Field &field, void *data,
145 size_t data_size) const override;
146 int64_t get_field_internal(const Ioss::CommSet *cs, const Ioss::Field &field, void *data,
147 size_t data_size) const override;
148
149 int64_t put_field_internal(const Ioss::Region *reg, const Ioss::Field &field, void *data,
150 size_t data_size) const override;
151 int64_t put_field_internal(const Ioss::NodeBlock *nb, const Ioss::Field &field, void *data,
152 size_t data_size) const override;
153 int64_t put_field_internal(const Ioss::EdgeBlock *eb, const Ioss::Field &field, void *data,
154 size_t data_size) const override;
155 int64_t put_field_internal(const Ioss::FaceBlock *eb, const Ioss::Field &field, void *data,
156 size_t data_size) const override;
157 int64_t put_field_internal(const Ioss::ElementBlock *eb, const Ioss::Field &field, void *data,
158 size_t data_size) const override;
159 int64_t put_field_internal(const Ioss::SideBlock *fb, const Ioss::Field &field, void *data,
160 size_t data_size) const override;
161 int64_t put_field_internal(const Ioss::NodeSet *ns, const Ioss::Field &field, void *data,
162 size_t data_size) const override;
163 int64_t put_field_internal(const Ioss::EdgeSet *ns, const Ioss::Field &field, void *data,
164 size_t data_size) const override;
165 int64_t put_field_internal(const Ioss::FaceSet *ns, const Ioss::Field &field, void *data,
166 size_t data_size) const override;
167 int64_t put_field_internal(const Ioss::ElementSet *ns, const Ioss::Field &field, void *data,
168 size_t data_size) const override;
169 int64_t put_field_internal(const Ioss::SideSet *fs, const Ioss::Field &field, void *data,
170 size_t data_size) const override;
171 int64_t put_field_internal(const Ioss::CommSet *cs, const Ioss::Field &field, void *data,
172 size_t data_size) const override;
173 int64_t put_field_internal(const Ioss::StructuredBlock *sb, const Ioss::Field &field,
174 void *data, size_t data_size) const override
175 {
176 return -1;
177 }
178
179 int64_t put_Xset_field_internal(ex_entity_type type, const Ioss::EntitySet *ns,
180 const Ioss::Field &field, void *data, size_t data_size) const;
181 int64_t get_Xset_field_internal(ex_entity_type type, const Ioss::EntitySet *ns,
182 const Ioss::Field &field, void *data, size_t data_size) const;
183
184 int get_file_pointer() const override; // Open file and set exodusFilePtr.
185 int free_file_pointer() const override;
186
187 int64_t read_nodal_coordinates();
188 void read_elements(const Ioss::ElementBlock &block);
189
190 void create_implicit_global_map() const;
191 void output_node_map() const;
192
193 // Metadata-related functions.
194 void read_meta_data__() override;
195
196 int64_t read_transient_field(ex_entity_type type, const Ioex::VariableNameMap &variables,
197 const Ioss::Field &field, const Ioss::GroupingEntity *ge,
198 void *data) const;
199
200 int64_t read_attribute_field(ex_entity_type type, const Ioss::Field &field,
201 const Ioss::GroupingEntity *ge, void *data) const;
202
203 int64_t write_attribute_field(ex_entity_type type, const Ioss::Field &field,
204 const Ioss::GroupingEntity *ge, void *data) const;
205
206 // Handles subsetting of side blocks.
207 int64_t read_ss_transient_field(const Ioss::Field &field, int64_t id, void *variables,
208 std::vector<int> &is_valid_side) const;
209
210 // Should be made more generic again so can rejoin with write_element_transient field
211 void write_nodal_transient_field(ex_entity_type type, const Ioss::Field &field,
212 const Ioss::NodeBlock *nb, int64_t count,
213 void *variables) const;
214 // Should be made more generic again so can rejoin with write_nodal_transient field
215 void write_entity_transient_field(ex_entity_type type, const Ioss::Field &field,
216 const Ioss::GroupingEntity *ge, int64_t count,
217 void *variables) const;
218 void write_meta_data() override;
219
220 // Read related metadata and store it in the region...
221 void read_region();
222 void get_edgeblocks();
223 void get_faceblocks();
224 void get_elemblocks();
225 void get_blocks(ex_entity_type entity_type, int rank_offset, const std::string &basename);
226
227 void get_sidesets();
228
229 template <typename T>
230 void get_sets(ex_entity_type type, int64_t count, const std::string &base, const T *);
231 void get_nodesets();
232 void get_edgesets();
233 void get_facesets();
234 void get_elemsets();
235
236 void get_commsets();
237
238 // ID Mapping functions.
239 const Ioss::Map &get_map(ex_entity_type type) const;
240 const Ioss::Map &get_map(Ioss::Map &entity_map, int64_t entityCount, int64_t file_offset,
241 int64_t file_count, ex_entity_type entity_type,
242 ex_inquiry inquiry_type) const;
243
244 // Internal data handling
245 int64_t handle_node_ids(void *ids, int64_t num_to_get, size_t offset, size_t count) const;
246 int64_t handle_element_ids(const Ioss::ElementBlock *eb, void *ids, size_t num_to_get,
247 size_t offset, size_t count) const;
248 int64_t handle_face_ids(const Ioss::FaceBlock *eb, void *ids, size_t num_to_get) const;
249 int64_t handle_edge_ids(const Ioss::EdgeBlock *eb, void *ids, size_t num_to_get) const;
250
251 int64_t get_side_connectivity(const Ioss::SideBlock *fb, int64_t id, int64_t side_count,
252 void *fconnect, bool map_ids) const;
253 int64_t get_side_distributions(const Ioss::SideBlock *fb, int64_t id, int64_t my_side_count,
254 double *dist_fact, size_t data_size) const;
255
256 int64_t get_side_field(const Ioss::SideBlock *ef_blk, const Ioss::Field &field, void *data,
257 size_t data_size) const;
258 int64_t put_side_field(const Ioss::SideBlock *fb, const Ioss::Field &field, void *data,
259 size_t data_size) const;
260
261 // Private member data...
262 mutable std::unique_ptr<DecompositionDataBase> decomp;
263
264 mutable Ioss::IntVector nodeOwningProcessor; // Processor that owns each node on this processor
265 mutable Ioss::Int64Vector
266 nodeGlobalImplicitMap; // Position of this node in the global-implicit ordering
267 mutable Ioss::Int64Vector
268 elemGlobalImplicitMap; // Position of this element in the global-implicit ordering
269
270 // Contains the indices of all owned nodes in each nodeset on this processor to pull data
271 // from the global list down to the file list.
272 // NOTE: Even though map type is GroupingEntity*, it is only valid
273 // for a GroupingEntity* which is a NodeSet*
274 mutable std::map<const Ioss::GroupingEntity *, Ioss::Int64Vector> nodesetOwnedNodes;
275
276 mutable bool metaDataWritten{false};
277 };
278 } // namespace Iopx
279 #endif
Ioss_CodeTypes.h
Iopx::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: Iopx_DatabaseIO.h:173
Ioss
The main namespace for the Ioss library.
Definition: Iocgns_DatabaseIO.h:50
Ioss_DBUsage.h
Iopx::DatabaseIO::nodeGlobalImplicitMap
Ioss::Int64Vector nodeGlobalImplicitMap
Definition: Iopx_DatabaseIO.h:266
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
Iopx::DatabaseIO::nodesetOwnedNodes
std::map< const Ioss::GroupingEntity *, Ioss::Int64Vector > nodesetOwnedNodes
Definition: Iopx_DatabaseIO.h:274
Ioss::EdgeSet
A collection of element edges.
Definition: Ioss_EdgeSet.h:54
Iopx::DatabaseIO::elemGlobalImplicitMap
Ioss::Int64Vector elemGlobalImplicitMap
Definition: Iopx_DatabaseIO.h:268
Ioss_Map.h
Ioss::SideBlock
A collection of element sides having the same topology.
Definition: Ioss_SideBlock.h:61
Ioss::IntVector
std::vector< int > IntVector
Definition: Ioss_CodeTypes.h:42
Ioss_State.h
Iopx::DatabaseIO
Definition: Iopx_DatabaseIO.h:86
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
Iopx::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: Iopx_DatabaseIO.h:129
Ioss::StructuredBlock
A structured zone – i,j,k.
Definition: Ioss_StructuredBlock.h:98
Ioss::ElementSet
A collection of elements.
Definition: Ioss_ElementSet.h:54
Ioss::DatabaseUsage
DatabaseUsage
Specifies how an Ioss::DatabaseIO object will be used.
Definition: Ioss_DBUsage.h:40
Iopx::DecompositionData
Definition: Iopx_DatabaseIO.h:57
Ioss::NodeBlock
A collection of all nodes in the region.
Definition: Ioss_NodeBlock.h:53
Iopx::DatabaseIO::needs_shared_node_information
bool needs_shared_node_information() const override
Determine whether the database needs information about process ownership of nodes.
Definition: Iopx_DatabaseIO.h:95
Ioss::Int64Vector
std::vector< int64_t > Int64Vector
Definition: Ioss_CodeTypes.h:43
Iopx::DatabaseIO::decomp
std::unique_ptr< DecompositionDataBase > decomp
Definition: Iopx_DatabaseIO.h:262
Ioss::Map
Definition: Ioss_Map.h:52
Iopx::DatabaseIO::nodeOwningProcessor
Ioss::IntVector nodeOwningProcessor
Definition: Iopx_DatabaseIO.h:264
Ioss::CommSet
Definition: Ioss_CommSet.h:51
Ioex_DatabaseIO.h
Iopx
A namespace for the decompose-on-the-fly version of the parallel exodus database format.
Definition: Iopx_DatabaseIO.C:249
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
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
Ioex::DatabaseIO
Definition: Ioex_DatabaseIO.h:96
Ioss::PropertyManager
A collection of Ioss::Property objects.
Definition: Ioss_PropertyManager.h:49
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
anonymous_namespace{Ioss_Field.C}::error_message
void error_message(const Ioss::Field &field, Ioss::Field::BasicType requested_type)
Definition: Ioss_Field.C:63