IOSS 2.0

Iocgns_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 #ifndef IOSS_Iocgns_DatabaseIO_h
34 #define IOSS_Iocgns_DatabaseIO_h
35
36 #include <Ioss_CodeTypes.h>
37 #include <Ioss_DBUsage.h> // for DatabaseUsage
38 #include <Ioss_DatabaseIO.h> // for DatabaseIO
39 #include <Ioss_IOFactory.h> // for IOFactory
40 #include <Ioss_Map.h> // for Map
41 #include <Ioss_State.h> // for State
42 #include <cstddef> // for size_t
43 #include <cstdint> // for int64_t
44 #include <iostream> // for ostream
45 #include <map>
46 #include <string> // for string
47
48 #include <cgnslib.h>
49
50 namespace Ioss {
51 class CommSet;
52 class EdgeBlock;
53 class EdgeSet;
54 class ElementBlock;
55 class ElementSet;
56 class ElementTopology;
57 class FaceBlock;
58 class FaceSet;
59 class Field;
60 class GroupingEntity;
61 class NodeBlock;
62 class NodeSet;
63 class Region;
64 class SideBlock;
65 class SideSet;
66 class EntityBlock;
67 class StructuredBlock;
68 } // namespace Ioss
69
70 /** \brief A namespace for the CGNS database format.
71 */
72 namespace Iocgns {
73
74 class DatabaseIO : public Ioss::DatabaseIO
75 {
76 public:
77 enum class entity_type { NODE, ELEM };
78
79 DatabaseIO(Ioss::Region *region, const std::string &filename, Ioss::DatabaseUsage db_usage,
80 MPI_Comm communicator, const Ioss::PropertyManager &props);
81
82 // Check capabilities of input/output database... Returns an
83 // unsigned int with the supported Ioss::EntityTypes or'ed
84 // together. If "return_value & Ioss::EntityType" is set, then the
85 // database supports that type (e.g. return_value & Ioss::FACESET)
86 unsigned entity_field_support() const override;
87
88 int64_t node_global_to_local__(int64_t global, bool must_exist) const override;
89 int64_t element_global_to_local__(int64_t global) const override;
90
91 ~DatabaseIO() override;
92
93 // This isn't quite true since a CGNS library with cgsize_t == 64-bits can read
94 // a file with 32-bit ints. However,...
95 int int_byte_size_db() const override { return CG_SIZEOF_SIZE; }
96
97 bool node_major() const override { return false; }
98
99 void openDatabase__() const override;
100 void closeDatabase__() const override;
101
102 bool begin__(Ioss::State state) override;
103 bool end__(Ioss::State state) override;
104
105 bool begin_state__(Ioss::Region *region, int state, double time) override;
106 bool end_state__(Ioss::Region *region, int state, double time) override;
107
108 // Metadata-related functions.
109 void read_meta_data__() override;
110 void write_meta_data();
111 void write_results_meta_data();
112
113 private:
114 void create_structured_block(int base, int zone, size_t &num_node);
115 size_t finalize_structured_blocks();
116 void finalize_database() override;
117 void get_step_times__() override;
118
119 void create_unstructured_block(int base, int zone, size_t &num_node);
120 void write_adjacency_data();
121
122 int64_t get_field_internal(const Ioss::Region *reg, const Ioss::Field &field, void *data,
123 size_t data_size) const override;
124 int64_t get_field_internal(const Ioss::NodeBlock *nb, const Ioss::Field &field, void *data,
125 size_t data_size) const override;
126 int64_t get_field_internal(const Ioss::EdgeBlock *eb, const Ioss::Field &field, void *data,
127 size_t data_size) const override;
128 int64_t get_field_internal(const Ioss::FaceBlock *fb, const Ioss::Field &field, void *data,
129 size_t data_size) const override;
130 int64_t get_field_internal(const Ioss::ElementBlock *eb, const Ioss::Field &field, void *data,
131 size_t data_size) const override;
132 int64_t get_field_internal(const Ioss::StructuredBlock *sb, const Ioss::Field &field,
133 void *data, size_t data_size) const override;
134 int64_t get_field_internal(const Ioss::SideBlock *sb, 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 *es, const Ioss::Field &field, void *data,
139 size_t data_size) const override;
140 int64_t get_field_internal(const Ioss::FaceSet *fs, const Ioss::Field &field, void *data,
141 size_t data_size) const override;
142 int64_t get_field_internal(const Ioss::ElementSet *es, 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 *region, 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 *fb, 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 *sb, 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 *es, const Ioss::Field &field, void *data,
164 size_t data_size) const override;
165 int64_t put_field_internal(const Ioss::FaceSet *fs, const Ioss::Field &field, void *data,
166 size_t data_size) const override;
167 int64_t put_field_internal(const Ioss::ElementSet *es, const Ioss::Field &field, void *data,
168 size_t data_size) const override;
169 int64_t put_field_internal(const Ioss::SideSet *ss, 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 // ID Mapping functions.
177 const Ioss::Map &get_map(entity_type type) const;
178 const Ioss::Map &get_map(Ioss::Map &entity_map, int64_t entityCount, int64_t file_offset,
179 int64_t file_count, entity_type type) const;
180
181 mutable int cgnsFilePtr{-1};
182
183 int m_currentVertexSolutionIndex = 0;
184 int m_currentCellCenterSolutionIndex = 0;
185
186 mutable std::vector<size_t> m_zoneOffset; // Offset for local zone/block element ids to global.
187 mutable std::vector<size_t>
188 m_bcOffset; // The BC Section element offsets in unstructured output.
189 mutable std::vector<double> m_timesteps;
190 std::vector<std::vector<cgsize_t>> m_blockLocalNodeMap;
191 std::map<std::string, int> m_zoneNameMap;
192 mutable std::map<int, Ioss::Map *> m_globalToBlockLocalNodeMap;
193 };
194 } // namespace Iocgns
195 #endif
Ioss_CodeTypes.h
Ioss::ElementTopology
Represents an element topology.
Definition: Ioss_ElementTopology.h:72
Iocgns::DatabaseIO::node_major
bool node_major() const override
Definition: Iocgns_DatabaseIO.h:97
Ioss
The main namespace for the Ioss library.
Definition: Iocgns_DatabaseIO.h:50
Ioss::DatabaseIO
An input or output Database.
Definition: Ioss_DatabaseIO.h:80
Ioss_DBUsage.h
Iocgns::DatabaseIO::m_timesteps
std::vector< double > m_timesteps
Definition: Iocgns_DatabaseIO.h:189
Iocgns::DatabaseIO::m_zoneNameMap
std::map< std::string, int > m_zoneNameMap
Definition: Iocgns_DatabaseIO.h:191
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
Iocgns
A namespace for the CGNS database format.
Definition: Iocgns_DatabaseIO.C:89
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
Iocgns::DatabaseIO::entity_type
entity_type
Definition: Iocgns_DatabaseIO.h:77
Ioss_DatabaseIO.h
Iocgns::DatabaseIO
Definition: Iocgns_DatabaseIO.h:74
Ioss::State
State
Access states for a database.
Definition: Ioss_State.h:42
Ioss_State.h
Ioss::ElementBlock
A collection of elements having the same topology.
Definition: Ioss_ElementBlock.h:48
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::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
Iocgns::DatabaseIO::m_bcOffset
std::vector< size_t > m_bcOffset
Definition: Iocgns_DatabaseIO.h:188
Ioss::NodeBlock
A collection of all nodes in the region.
Definition: Ioss_NodeBlock.h:53
Iocgns::DatabaseIO::m_blockLocalNodeMap
std::vector< std::vector< cgsize_t > > m_blockLocalNodeMap
Definition: Iocgns_DatabaseIO.h:190
Iocgns::DatabaseIO::int_byte_size_db
int int_byte_size_db() const override
Definition: Iocgns_DatabaseIO.h:95
Iocgns::DatabaseIO::m_globalToBlockLocalNodeMap
std::map< int, Ioss::Map * > m_globalToBlockLocalNodeMap
Definition: Iocgns_DatabaseIO.h:192
Ioss::Map
Definition: Ioss_Map.h:52
Ioss::CommSet
Definition: Ioss_CommSet.h:51
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
Ioss_IOFactory.h
MPI_Comm
int MPI_Comm
Definition: Ioss_CodeTypes.h:79
Iocgns::DatabaseIO::m_zoneOffset
std::vector< size_t > m_zoneOffset
Definition: Iocgns_DatabaseIO.h:186
Ioss::PropertyManager
A collection of Ioss::Property objects.
Definition: Ioss_PropertyManager.h:49
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