IOSS 2.0
Loading...
Searching...
No Matches
Ioexnl_BaseDatabaseIO.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_DatabaseIO.h"
12#include "Ioss_Field.h"
13#include "Ioss_Map.h"
14#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 "Ioss_DataSize.h"
27#include "Ioss_State.h"
28#include "ioexnl_export.h"
29
30namespace Ioss {
31 class Assembly;
32 class Blob;
33 class GroupingEntity;
34 class Region;
35 class EntityBlock;
36 class NodeBlock;
37 class EdgeBlock;
38 class FaceBlock;
39 class ElementBlock;
40 class EntitySet;
41 class NodeSet;
42 class EdgeSet;
43 class FaceSet;
44 class ElementSet;
45 class SideBlock;
46 class SideSet;
47 class StructuredBlock;
48 class CommSet;
49 class ElementTopology;
50 class Field;
51 class Map;
52 class PropertyManager;
53} // namespace Ioss
54
55/** \brief A namespace for the exodus database format.
56 */
57namespace Ioexnl {
58 struct CommunicationMetaData;
59
60 // Used for variable name index mapping
61 using VariableNameMap = std::map<std::string, int, std::less<>>;
62 using VNMValuePair = VariableNameMap::value_type;
63
64 // Used to store reduction variables
65 using ValueContainer = std::vector<double>;
66
67 // Used for persistent entity IDs
68 // The set contains a pair of <ex_entity_type, int>.
69 // The ex_entity_type is the exodus entity type defined in
70 // exodus's exodusII.h. A couple examples are:
71 // EX_ELEM_BLOCK element block and EX_NODE_SET nodeset.
72 //
73 // The 'int' is the entity id. The set is used for output databases
74 // to ensure that there are no id collisions.
75 using EntityIdSet = std::set<std::pair<int64_t, int64_t>>;
76
77 class IOEXNL_EXPORT BaseDatabaseIO : public Ioss::DatabaseIO
78 {
79 public:
80 BaseDatabaseIO(Ioss::Region *region, const std::string &filename, Ioss::DatabaseUsage db_usage,
81 Ioss_MPI_Comm communicator, const Ioss::PropertyManager &props);
82
83 IOSS_NODISCARD std::string get_format() const override { return "ExoNull"; }
84
85 // Check capabilities of input/output database... Returns an
86 // unsigned int with the supported Ioss::EntityTypes or'ed
87 // together. If "return_value & Ioss::EntityType" is set, then the
88 // database supports that type (e.g. return_value & Ioss::FACESET)
89 IOSS_NODISCARD unsigned entity_field_support() const override;
90
91 protected:
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 IOSS_NODISCARD bool ok_nl(bool write_message = false, std::string *error_message = nullptr,
98 int *bad_count = nullptr) const override;
99
100 IOSS_NODISCARD bool begin_nl(Ioss::State state) override;
101 IOSS_NODISCARD bool end_nl(Ioss::State state) override;
102
103 void open_state_file(int state);
104
105 bool begin_state_nl(int state, double time) override;
106 bool end_state_nl(int state, double time) override;
107 void get_step_times_nl() override = 0;
108
109 IOSS_NODISCARD int maximum_symbol_length() const override { return maximumNameLength; }
110
111 // NOTE: If this is called after write_meta_data, it will have no affect.
112 // Also, it only affects output databases, not input.
113 void set_maximum_symbol_length(int requested_symbol_size) override
114 {
115 if (!is_input()) {
116 maximumNameLength = requested_symbol_size;
117 }
118 }
119
120 size_t handle_block_ids(const Ioss::EntityBlock *eb, ex_entity_type map_type,
121 Ioss::Map &entity_map, void *ids, size_t num_to_get,
122 size_t offset) const;
123
124 void compute_block_membership_nl(Ioss::SideBlock *efblock,
125 Ioss::NameList &block_membership) const override;
126
127 IOSS_NODISCARD int int_byte_size_db() const override;
128 void set_int_byte_size_api(Ioss::DataSize size) const override;
129
145
146 int64_t put_field_internal(const Ioss::Region *reg, const Ioss::Field &field, void *data,
147 size_t data_size) const override = 0;
148 int64_t put_field_internal(const Ioss::NodeBlock *nb, const Ioss::Field &field, void *data,
149 size_t data_size) const override = 0;
150 int64_t put_field_internal(const Ioss::EdgeBlock *nb, const Ioss::Field &field, void *data,
151 size_t data_size) const override = 0;
152 int64_t put_field_internal(const Ioss::FaceBlock *nb, const Ioss::Field &field, void *data,
153 size_t data_size) const override = 0;
154 int64_t put_field_internal(const Ioss::ElementBlock *eb, const Ioss::Field &field, void *data,
155 size_t data_size) const override = 0;
156 int64_t put_field_internal(const Ioss::StructuredBlock *sb, const Ioss::Field &field,
157 void *data, size_t data_size) const override = 0;
158 int64_t put_field_internal(const Ioss::SideBlock *fb, const Ioss::Field &field, void *data,
159 size_t data_size) const override = 0;
160 int64_t put_field_internal(const Ioss::NodeSet *ns, const Ioss::Field &field, void *data,
161 size_t data_size) const override = 0;
162 int64_t put_field_internal(const Ioss::EdgeSet *ns, const Ioss::Field &field, void *data,
163 size_t data_size) const override = 0;
164 int64_t put_field_internal(const Ioss::FaceSet *ns, const Ioss::Field &field, void *data,
165 size_t data_size) const override = 0;
166 int64_t put_field_internal(const Ioss::ElementSet *ns, const Ioss::Field &field, void *data,
167 size_t data_size) const override = 0;
168 int64_t put_field_internal(const Ioss::SideSet *fs, const Ioss::Field &field, void *data,
169 size_t data_size) const override = 0;
170 int64_t put_field_internal(const Ioss::CommSet *cs, const Ioss::Field &field, void *data,
171 size_t data_size) const override = 0;
172 int64_t put_field_internal(const Ioss::Assembly *as, const Ioss::Field &field, void *data,
173 size_t data_size) const override = 0;
174 int64_t put_field_internal(const Ioss::Blob *blob, const Ioss::Field &field, void *data,
175 size_t data_size) const override = 0;
176
178 void write_results_metadata(bool gather_data, Ioss::IfDatabaseExistsBehavior behavior);
179
180 void openDatabase_nl() const override { (void)get_file_pointer(); }
181
182 void closeDatabase_nl() const override
183 {
184 free_file_pointer();
185 close_dw();
186 }
187
188 IOSS_NODISCARD int get_file_pointer() const override = 0; // Open file and set exodusFilePtr.
189
190 virtual int free_file_pointer() const; // Close file and set exodusFilePtr.
191
192 virtual bool handle_output_file(bool write_message, std::string *error_msg, int *bad_count,
193 bool overwrite, bool abort_if_error) const = 0;
194
196 get_current_state() const; // Get current state with error checks and usage message.
197 void put_qa();
198 void put_info();
199
200 template <typename T>
201 void internal_gather_results_metadata(ex_entity_type type, std::vector<T *> entities);
202
203 void generate_sideset_truth_table();
204
205 void output_results_names(ex_entity_type type, VariableNameMap &variables,
206 bool reduction) const;
207 int gather_names(VariableNameMap &variables, const Ioss::GroupingEntity *ge, int index,
208 bool reduction);
209
212 void get_blobs();
213
215
216 void add_attribute_fields(Ioss::GroupingEntity *block, int attribute_count,
217 const std::string &type);
218
219 void common_write_metadata(Ioss::IfDatabaseExistsBehavior behavior);
220 void output_other_metadata();
221
222 int64_t internal_add_results_fields(ex_entity_type type, Ioss::GroupingEntity *entity,
223 int64_t position, int64_t block_count,
224 Ioss::IntVector &truth_table,
225 Ioexnl::VariableNameMap &variables);
226 int64_t add_results_fields(Ioss::GroupingEntity *entity, int64_t position = 0);
229
231 void store_reduction_field(const Ioss::Field &field, const Ioss::GroupingEntity *ge,
232 void *variables) const;
233
234 void get_reduction_field(const Ioss::Field &field, const Ioss::GroupingEntity *ge,
235 void *variables) const;
236 void write_reduction_fields() const;
238
239 // Handle special output time requests -- primarily restart (cycle, keep, overwrite)
240 // Given the global region step, return the step on the database...
241 IOSS_NODISCARD int get_database_step(int global_step) const;
242
243 void flush_database_nl() const override;
244 void finalize_write(int state, double sim_time);
245
246 mutable int m_exodusFilePtr{-1};
247 // If using links to file-per-state, the file pointer for "base" file.
248 mutable int m_exodusBasePtr{-1};
249
250 mutable std::string m_groupName;
251
253
254 mutable int exodusMode{EX_CLOBBER};
255 mutable int dbRealWordSize{8};
256
257 mutable int maximumNameLength{32};
258 int spatialDimension{0};
259
260 int64_t edgeCount{0};
261 int64_t faceCount{0};
262
263 mutable std::map<ex_entity_type, int> m_groupCount;
264
265 // Communication Set Data
270 int64_t commsetNodeCount{0};
271 int64_t commsetElemCount{0};
272
273 // --- Nodal/Element/Attribute Variable Names -- Maps from sierra
274 // field names to index of nodal/element/attribute variable in
275 // exodusII. Note that the component suffix of the field is added on
276 // prior to searching the map for the index. For example, given the
277 // Sierra field 'displ' which is a VECTOR_3D, the names stored in
278 // 'elementMap' would be 'displ_x', 'displ_y' and 'displ_z'. All
279 // names are converted to lowercase.
280
281 mutable std::map<ex_entity_type, Ioss::IntVector> m_truthTable;
282 mutable std::map<ex_entity_type, VariableNameMap> m_variables;
283 mutable std::map<ex_entity_type, VariableNameMap> m_reductionVariables;
284
285 mutable std::map<ex_entity_type, std::map<int64_t, ValueContainer>> m_reductionValues;
286
287 mutable std::vector<unsigned char> nodeConnectivityStatus;
288
289 // For a database with omitted blocks, this map contains the indices of the
290 // active nodes for each nodeset. If the nodeset is not reduced in size,
291 // the map's vector will be empty for that nodeset. If the vector is not
292 // empty, then some nodes on that nodeset are only connected to omitted elements.
293 mutable std::map<std::string, Ioss::Int64Vector> activeNodeSetNodesIndex;
294
295 time_t timeLastFlush{0};
296 int flushInterval{-1};
297
298 mutable bool fileExists{false}; // False if file has never been opened/created
299 mutable bool minimizeOpenFiles{false};
300
301 mutable bool blockAdjacenciesCalculated{false}; // True if the lazy creation of
302 // block adjacencies has been calculated.
303 mutable bool nodeConnectivityStatusCalculated{
304 false}; // True if the lazy creation of
305 // nodeConnectivityStatus has been calculated.
306 };
307} // namespace Ioexnl
#define IOSS_NODISCARD
Definition Ioss_CodeTypes.h:55
int Ioss_MPI_Comm
Definition Ioss_CodeTypes.h:64
#define IOSS_NOOP_GFI(type)
Definition Ioss_CodeTypes.h:114
Definition Ioexnl_BaseDatabaseIO.h:78
std::map< std::string, Ioss::Int64Vector > activeNodeSetNodesIndex
Definition Ioexnl_BaseDatabaseIO.h:293
void add_attribute_fields(Ioss::GroupingEntity *block, int attribute_count, const std::string &type)
int64_t put_field_internal(const Ioss::CommSet *cs, const Ioss::Field &field, void *data, size_t data_size) const override=0
int64_t put_field_internal(const Ioss::NodeSet *ns, const Ioss::Field &field, void *data, size_t data_size) const override=0
IOSS_NODISCARD int maximum_symbol_length() const override
Get the length of the longest name in the database file.
Definition Ioexnl_BaseDatabaseIO.h:109
Ioss::Int64Vector elemCmapElemCnts
Definition Ioexnl_BaseDatabaseIO.h:269
int64_t put_field_internal(const Ioss::FaceBlock *nb, const Ioss::Field &field, void *data, size_t data_size) const override=0
void open_state_file(int state)
std::map< ex_entity_type, int > m_groupCount
Definition Ioexnl_BaseDatabaseIO.h:263
int64_t put_field_internal(const Ioss::EdgeSet *ns, const Ioss::Field &field, void *data, size_t data_size) const override=0
int64_t put_field_internal(const Ioss::Blob *blob, const Ioss::Field &field, void *data, size_t data_size) const override=0
int64_t put_field_internal(const Ioss::FaceSet *ns, const Ioss::Field &field, void *data, size_t data_size) const override=0
std::map< ex_entity_type, VariableNameMap > m_variables
Definition Ioexnl_BaseDatabaseIO.h:282
int64_t put_field_internal(const Ioss::StructuredBlock *sb, const Ioss::Field &field, void *data, size_t data_size) const override=0
int64_t put_field_internal(const Ioss::ElementBlock *eb, const Ioss::Field &field, void *data, size_t data_size) const override=0
int64_t put_field_internal(const Ioss::NodeBlock *nb, const Ioss::Field &field, void *data, size_t data_size) const override=0
int64_t put_field_internal(const Ioss::SideBlock *fb, const Ioss::Field &field, void *data, size_t data_size) const override=0
Ioss::Int64Vector elemCmapIds
Definition Ioexnl_BaseDatabaseIO.h:268
std::vector< unsigned char > nodeConnectivityStatus
Definition Ioexnl_BaseDatabaseIO.h:287
int64_t internal_add_results_fields(ex_entity_type type, Ioss::GroupingEntity *entity, int64_t position, int64_t block_count, Ioss::IntVector &truth_table, Ioexnl::VariableNameMap &variables)
virtual void write_meta_data(Ioss::IfDatabaseExistsBehavior behavior)=0
void set_maximum_symbol_length(int requested_symbol_size) override
Definition Ioexnl_BaseDatabaseIO.h:113
EntityIdSet ids_
Definition Ioexnl_BaseDatabaseIO.h:252
void read_reduction_fields() const
int64_t put_field_internal(const Ioss::ElementSet *ns, const Ioss::Field &field, void *data, size_t data_size) const override=0
virtual bool handle_output_file(bool write_message, std::string *error_msg, int *bad_count, bool overwrite, bool abort_if_error) const =0
int64_t add_results_fields(Ioss::GroupingEntity *entity, int64_t position=0)
std::map< ex_entity_type, VariableNameMap > m_reductionVariables
Definition Ioexnl_BaseDatabaseIO.h:283
void update_block_omissions_from_assemblies()
int64_t put_field_internal(const Ioss::Assembly *as, const Ioss::Field &field, void *data, size_t data_size) const override=0
Ioss::Int64Vector nodeCmapIds
Definition Ioexnl_BaseDatabaseIO.h:266
int64_t add_reduction_results_fields(Ioss::GroupingEntity *entity)
IOSS_NODISCARD std::string get_format() const override
Definition Ioexnl_BaseDatabaseIO.h:83
int64_t put_field_internal(const Ioss::EdgeBlock *nb, const Ioss::Field &field, void *data, size_t data_size) const override=0
std::string m_groupName
Definition Ioexnl_BaseDatabaseIO.h:250
void add_mesh_reduction_fields(int64_t id, Ioss::GroupingEntity *entity)
void openDatabase_nl() const override
Definition Ioexnl_BaseDatabaseIO.h:180
void get_step_times_nl() override=0
std::map< ex_entity_type, Ioss::IntVector > m_truthTable
Definition Ioexnl_BaseDatabaseIO.h:281
void closeDatabase_nl() const override
Definition Ioexnl_BaseDatabaseIO.h:182
Ioss::Int64Vector nodeCmapNodeCnts
Definition Ioexnl_BaseDatabaseIO.h:267
std::map< ex_entity_type, std::map< int64_t, ValueContainer > > m_reductionValues
Definition Ioexnl_BaseDatabaseIO.h:285
int64_t put_field_internal(const Ioss::SideSet *fs, const Ioss::Field &field, void *data, size_t data_size) const override=0
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
An input or output Database.
Definition Ioss_DatabaseIO.h:63
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 'block'-type grouping entities, which means all members of the block are similar o...
Definition Ioss_EntityBlock.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 Ioexnl_BaseDatabaseIO.C:93
std::set< std::pair< int64_t, int64_t > > EntityIdSet
Definition Ioexnl_BaseDatabaseIO.h:75
std::map< std::string, int, std::less<> > VariableNameMap
Definition Ioexnl_BaseDatabaseIO.h:61
std::vector< double > ValueContainer
Definition Ioexnl_BaseDatabaseIO.h:65
The main namespace for the Ioss library.
Definition Ioad_DatabaseIO.C:40
State
Access states for a database.
Definition Ioss_State.h:15
std::vector< int64_t > Int64Vector
Definition Ioss_CodeTypes.h:22
Ioss::NameList NameList
Definition Ioss_ChangeSetFactory.h:25
DataSize
The number of bytes used to store an integer type.
Definition Ioss_DataSize.h:13
DatabaseUsage
Specifies how an Ioss::DatabaseIO object will be used.
Definition Ioss_DBUsage.h:13
std::vector< int > IntVector
Definition Ioss_CodeTypes.h:21
IfDatabaseExistsBehavior
Definition Ioss_DBUsage.h:32