IOSS 2.0

Ioex_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_Ioex_DatabaseIO_h
35 #define IOSS_Ioex_DatabaseIO_h
36
37 #include <Ioss_DBUsage.h>
38 #include <Ioss_DatabaseIO.h>
39 #include <Ioss_Field.h>
40 #include <Ioss_Map.h>
41 #include <Ioss_Utils.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 /** \brief A namespace for the exodus database format.
75 */
76 namespace Ioex {
77 struct CommunicationMetaData;
78
79 // Used for variable name index mapping
80 using VariableNameMap = std::map<std::string, int, std::less<std::string>>;
81 using VNMValuePair = VariableNameMap::value_type;
82
83 // Used to store reduction variables
84 using ValueContainer = std::vector<double>;
85
86 // Used for persistent entity IDs
87 // The set contains a pair of <ex_entity_type, int>.
88 // The ex_entity_type is the exodus entity type defined in
89 // exodus's exodusII.h. A couple examples are:
90 // EX_ELEM_BLOCK element block and EX_NODE_SET nodeset.
91 //
92 // The 'int' is the entity id. The set is used for output databases
93 // to ensure that there are no id collisions.
94 using EntityIdSet = std::set<std::pair<int64_t, int64_t>>;
95
96 class DatabaseIO : public Ioss::DatabaseIO
97 {
98 public:
99 DatabaseIO(Ioss::Region *region, const std::string &filename, Ioss::DatabaseUsage db_usage,
100 MPI_Comm communicator, const Ioss::PropertyManager &props);
101 DatabaseIO(const DatabaseIO &from) = delete;
102 DatabaseIO &operator=(const DatabaseIO &from) = delete;
103
104 ~DatabaseIO() override;
105
106 // Check capabilities of input/output database... Returns an
107 // unsigned int with the supported Ioss::EntityTypes or'ed
108 // together. If "return_value & Ioss::EntityType" is set, then the
109 // database supports that type (e.g. return_value & Ioss::FACESET)
110 unsigned entity_field_support() const override;
111
112 protected:
113 // Check to see if database state is ok...
114 // If 'write_message' true, then output a warning message indicating the problem.
115 // If 'error_message' non-null, then put the warning message into the string and return it.
116 // If 'bad_count' non-null, it counts the number of processors where the file does not exist.
117 // if ok returns false, but *bad_count==0, then the routine does not support this argument.
118 bool ok__(bool write_message = false, std::string *error_message = nullptr,
119 int *bad_count = nullptr) const override = 0;
120
121 bool open_group__(const std::string &group_name) override;
122 bool create_subgroup__(const std::string &group_name) override;
123
124 bool begin__(Ioss::State state) override;
125 bool end__(Ioss::State state) override;
126
127 bool begin_state__(Ioss::Region *region, int state, double time) override;
128 bool end_state__(Ioss::Region *region, int state, double time) override;
129 void get_step_times__() override = 0;
130
131 int maximum_symbol_length() const override { return maximumNameLength; }
132
133 // NOTE: If this is called after write_meta_data, it will have no affect.
134 // Also, it only affects output databases, not input.
135 void set_maximum_symbol_length(int requested_symbol_size) override
136 {
137 if (!is_input()) {
138 maximumNameLength = requested_symbol_size;
139 }
140 }
141
142 size_t handle_block_ids(const Ioss::EntityBlock *eb, ex_entity_type map_type,
143 Ioss::Map &entity_map, void *ids, size_t num_to_get, size_t offset,
144 size_t count) const;
145
146 void compute_block_membership__(Ioss::SideBlock * efblock,
147 std::vector<std::string> &block_membership) const override;
148
149 int int_byte_size_db() const override;
150 void set_int_byte_size_api(Ioss::DataSize size) const override;
151
152 protected:
153 int64_t get_field_internal(const Ioss::Region *reg, const Ioss::Field &field, void *data,
154 size_t data_size) const override = 0;
155 int64_t get_field_internal(const Ioss::NodeBlock *nb, const Ioss::Field &field, void *data,
156 size_t data_size) const override = 0;
157 int64_t get_field_internal(const Ioss::EdgeBlock *nb, const Ioss::Field &field, void *data,
158 size_t data_size) const override = 0;
159 int64_t get_field_internal(const Ioss::FaceBlock *nb, const Ioss::Field &field, void *data,
160 size_t data_size) const override = 0;
161 int64_t get_field_internal(const Ioss::ElementBlock *eb, const Ioss::Field &field, void *data,
162 size_t data_size) const override = 0;
163 int64_t get_field_internal(const Ioss::StructuredBlock *sb, const Ioss::Field &field,
164 void *data, size_t data_size) const override = 0;
165 int64_t get_field_internal(const Ioss::SideBlock *fb, const Ioss::Field &field, void *data,
166 size_t data_size) const override = 0;
167 int64_t get_field_internal(const Ioss::NodeSet *ns, const Ioss::Field &field, void *data,
168 size_t data_size) const override = 0;
169 int64_t get_field_internal(const Ioss::EdgeSet *ns, const Ioss::Field &field, void *data,
170 size_t data_size) const override = 0;
171 int64_t get_field_internal(const Ioss::FaceSet *ns, const Ioss::Field &field, void *data,
172 size_t data_size) const override = 0;
173 int64_t get_field_internal(const Ioss::ElementSet *ns, const Ioss::Field &field, void *data,
174 size_t data_size) const override = 0;
175 int64_t get_field_internal(const Ioss::SideSet *fs, const Ioss::Field &field, void *data,
176 size_t data_size) const override = 0;
177 int64_t get_field_internal(const Ioss::CommSet *cs, const Ioss::Field &field, void *data,
178 size_t data_size) const override = 0;
179
180 int64_t put_field_internal(const Ioss::Region *reg, const Ioss::Field &field, void *data,
181 size_t data_size) const override = 0;
182 int64_t put_field_internal(const Ioss::NodeBlock *nb, const Ioss::Field &field, void *data,
183 size_t data_size) const override = 0;
184 int64_t put_field_internal(const Ioss::EdgeBlock *nb, const Ioss::Field &field, void *data,
185 size_t data_size) const override = 0;
186 int64_t put_field_internal(const Ioss::FaceBlock *nb, const Ioss::Field &field, void *data,
187 size_t data_size) const override = 0;
188 int64_t put_field_internal(const Ioss::ElementBlock *eb, const Ioss::Field &field, void *data,
189 size_t data_size) const override = 0;
190 int64_t put_field_internal(const Ioss::StructuredBlock *sb, const Ioss::Field &field,
191 void *data, size_t data_size) const override = 0;
192 int64_t put_field_internal(const Ioss::SideBlock *fb, const Ioss::Field &field, void *data,
193 size_t data_size) const override = 0;
194 int64_t put_field_internal(const Ioss::NodeSet *ns, const Ioss::Field &field, void *data,
195 size_t data_size) const override = 0;
196 int64_t put_field_internal(const Ioss::EdgeSet *ns, const Ioss::Field &field, void *data,
197 size_t data_size) const override = 0;
198 int64_t put_field_internal(const Ioss::FaceSet *ns, const Ioss::Field &field, void *data,
199 size_t data_size) const override = 0;
200 int64_t put_field_internal(const Ioss::ElementSet *ns, const Ioss::Field &field, void *data,
201 size_t data_size) const override = 0;
202 int64_t put_field_internal(const Ioss::SideSet *fs, const Ioss::Field &field, void *data,
203 size_t data_size) const override = 0;
204 int64_t put_field_internal(const Ioss::CommSet *cs, const Ioss::Field &field, void *data,
205 size_t data_size) const override = 0;
206
207 virtual void write_meta_data() = 0;
208 void write_results_metadata();
209
210 void openDatabase__() const override { get_file_pointer(); }
211
212 void closeDatabase__() const override { free_file_pointer(); }
213
214 public:
215 // Temporarily made public for use during Salinas transition
216 // to using Ioss
217 virtual int get_file_pointer() const = 0; // Open file and set exodusFilePtr.
218 protected:
219 virtual int free_file_pointer() const; // Close file and set exodusFilePtr.
220
221 int get_current_state() const; // Get current state with error checks and usage message.
222 void put_qa();
223 void put_info();
224
225 template <typename T>
226 void internal_write_results_metadata(ex_entity_type type, std::vector<T *> entities,
227 int &glob_index);
228
229 void generate_sideset_truth_table();
230
231 void output_results_names(ex_entity_type type, VariableNameMap &variables) const;
232 int gather_names(ex_entity_type type, VariableNameMap &variables,
233 const Ioss::GroupingEntity *ge, int index, bool reduction);
234
235 void get_nodeblocks();
236
237 void add_attribute_fields(ex_entity_type entity_type, Ioss::GroupingEntity *block,
238 int attribute_count, const std::string &type);
239
240 void output_other_meta_data();
241
242 int64_t internal_add_results_fields(ex_entity_type type, Ioss::GroupingEntity *entity,
243 int64_t position, int64_t block_count,
244 Ioss::IntVector & truth_table,
245 Ioex::VariableNameMap &variables);
246 int64_t add_results_fields(ex_entity_type type, Ioss::GroupingEntity *entity,
247 int64_t position = 0);
248
249 void add_region_fields();
250 void store_reduction_field(ex_entity_type type, const Ioss::Field &field,
251 const Ioss::GroupingEntity *ge, void *variables) const;
252
253 void get_reduction_field(ex_entity_type type, const Ioss::Field &field,
254 const Ioss::GroupingEntity *ge, void *variables) const;
255 void write_reduction_fields() const;
256 void read_reduction_fields() const;
257
258 // Handle special output time requests -- primarily restart (cycle, keep, overwrite)
259 // Given the global region step, return the step on the database...
260 int get_database_step(int global_step) const;
261
262 void flush_database__() const override;
263 void finalize_write(double sim_time);
264
265 // Private member data...
266 protected:
267 mutable int exodusFilePtr{-1};
268 mutable std::string m_groupName;
269
270 mutable EntityIdSet ids_;
271
272 mutable int exodusMode{EX_CLOBBER};
273 mutable int dbRealWordSize{8};
274
275 mutable int maximumNameLength{32};
276 int spatialDimension{0};
277
278 int64_t edgeCount{0};
279 int64_t faceCount{0};
280
281 mutable std::map<ex_entity_type, int> m_groupCount;
282
283 // Communication Set Data
284 Ioss::Int64Vector nodeCmapIds;
285 Ioss::Int64Vector nodeCmapNodeCnts;
286 Ioss::Int64Vector elemCmapIds;
287 Ioss::Int64Vector elemCmapElemCnts;
288 int64_t commsetNodeCount{0};
289 int64_t commsetElemCount{0};
290
291 // --- Nodal/Element/Attribute Variable Names -- Maps from sierra
292 // field names to index of nodal/element/attribute variable in
293 // exodusII. Note that the component suffix of the field is added on
294 // prior to searching the map for the index. For example, given the
295 // Sierra field 'displ' which is a VECTOR_3D, the names stored in
296 // 'elementMap' would be 'displ_x', 'displ_y' and 'displ_z'. All
297 // names are converted to lowercase.
298
299 mutable std::map<ex_entity_type, Ioss::IntVector> m_truthTable;
300 mutable std::map<ex_entity_type, VariableNameMap> m_variables;
301
302 mutable ValueContainer globalValues;
303
304 mutable std::vector<unsigned char> nodeConnectivityStatus;
305
306 // For a database with omitted blocks, this map contains the indices of the
307 // active nodes for each nodeset. If the nodeset is not reduced in size,
308 // the map's vector will be empty for that nodeset. If the vector is not
309 // empty, then some nodes on that nodeset are only connected to omitted elements.
310 mutable std::map<std::string, Ioss::Int64Vector> activeNodesetNodesIndex;
311
312 time_t timeLastFlush{0};
313
314 mutable bool fileExists{false}; // False if file has never been opened/created
315 mutable bool minimizeOpenFiles{false};
316
317 mutable bool blockAdjacenciesCalculated{false}; // True if the lazy creation of
318 // block adjacencies has been calculated.
319 mutable bool nodeConnectivityStatusCalculated{
320 false}; // True if the lazy creation of
321 // nodeConnectivityStatus has been calculated.
322 };
323 } // namespace Ioex
324 #endif
Ioex::ValueContainer
std::vector< double > ValueContainer
Definition: Ioex_DatabaseIO.h:84
Ioss
The main namespace for the Ioss library.
Definition: Iocgns_DatabaseIO.h:50
Iovs::handle_block_ids
size_t handle_block_ids(const Ioss::EntityBlock *eb, Ioss::State db_state, Ioss::Map &entity_map, void *ids, size_t int_byte_size, size_t num_to_get, int my_processor)
Definition: Iovs_DatabaseIO.C:854
Ioss::DatabaseIO
An input or output Database.
Definition: Ioss_DatabaseIO.h:80
Ioss_DBUsage.h
Ioss::DataSize
DataSize
The number of bytes used to store an integer type.
Definition: Ioss_DataSize.h:40
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
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
Ioex::EntityIdSet
std::set< std::pair< int64_t, int64_t > > EntityIdSet
Definition: Ioex_DatabaseIO.h:94
Ioex::DatabaseIO::elemCmapIds
Ioss::Int64Vector elemCmapIds
Definition: Ioex_DatabaseIO.h:286
Ioss_DatabaseIO.h
Ioex::DatabaseIO::elemCmapElemCnts
Ioss::Int64Vector elemCmapElemCnts
Definition: Ioex_DatabaseIO.h:287
Ioss::State
State
Access states for a database.
Definition: Ioss_State.h:42
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
Ioex::DatabaseIO::closeDatabase__
void closeDatabase__() const override
Definition: Ioex_DatabaseIO.h:212
Ioss::EntityBlock
Base class for all &#39;block&#39;-type grouping entities, which means all members of the block are similar o...
Definition: Ioss_EntityBlock.h:61
Ioss::DatabaseUsage
DatabaseUsage
Specifies how an Ioss::DatabaseIO object will be used.
Definition: Ioss_DBUsage.h:40
Ioex::DatabaseIO::openDatabase__
void openDatabase__() const override
Definition: Ioex_DatabaseIO.h:210
Ioss_Utils.h
Ioex::DatabaseIO::set_maximum_symbol_length
void set_maximum_symbol_length(int requested_symbol_size) override
Definition: Ioex_DatabaseIO.h:135
Ioex
A namespace for the exodus database format.
Definition: Ioex_IOFactory.C:61
Ioex::DatabaseIO::ids_
EntityIdSet ids_
Definition: Ioex_DatabaseIO.h:270
Ioss::NodeBlock
A collection of all nodes in the region.
Definition: Ioss_NodeBlock.h:53
Ioex::DatabaseIO::m_variables
std::map< ex_entity_type, VariableNameMap > m_variables
Definition: Ioex_DatabaseIO.h:300
Ioss::Int64Vector
std::vector< int64_t > Int64Vector
Definition: Ioss_CodeTypes.h:43
Ioex::DatabaseIO::globalValues
ValueContainer globalValues
Definition: Ioex_DatabaseIO.h:302
Ioss::Map
Definition: Ioss_Map.h:52
Ioss::CommSet
Definition: Ioss_CommSet.h:51
Ioss_Field.h
anonymous_namespace{Iodw_DatabaseIO.C}::get_file_pointer
int get_file_pointer()
Definition: Iodw_DatabaseIO.C:64
Ioex::VNMValuePair
VariableNameMap::value_type VNMValuePair
Definition: Ioex_DatabaseIO.h:81
Ioss::Region
A grouping entity that contains other grouping entities.
Definition: Ioss_Region.h:98
Ioex::DatabaseIO::nodeCmapIds
Ioss::Int64Vector nodeCmapIds
Definition: Ioex_DatabaseIO.h:284
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
Ioex::DatabaseIO::m_truthTable
std::map< ex_entity_type, Ioss::IntVector > m_truthTable
Definition: Ioex_DatabaseIO.h:299
MPI_Comm
int MPI_Comm
Definition: Ioss_CodeTypes.h:79
Ioex::DatabaseIO::nodeCmapNodeCnts
Ioss::Int64Vector nodeCmapNodeCnts
Definition: Ioex_DatabaseIO.h:285
Ioex::DatabaseIO::m_groupName
std::string m_groupName
Definition: Ioex_DatabaseIO.h:268
Ioex::DatabaseIO
Definition: Ioex_DatabaseIO.h:96
Ioex::DatabaseIO::maximum_symbol_length
int maximum_symbol_length() const override
Get the length of the longest name in the database file.
Definition: Ioex_DatabaseIO.h:131
Ioex::DatabaseIO::nodeConnectivityStatus
std::vector< unsigned char > nodeConnectivityStatus
Definition: Ioex_DatabaseIO.h:304
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
Ioex::DatabaseIO::activeNodesetNodesIndex
std::map< std::string, Ioss::Int64Vector > activeNodesetNodesIndex
Definition: Ioex_DatabaseIO.h:310
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
Ioex::DatabaseIO::m_groupCount
std::map< ex_entity_type, int > m_groupCount
Definition: Ioex_DatabaseIO.h:281
anonymous_namespace{Ioss_Field.C}::error_message
void error_message(const Ioss::Field &field, Ioss::Field::BasicType requested_type)
Definition: Ioss_Field.C:63