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 // Metadata-related functions.
100 void read_meta_data__() override;
101 void write_meta_data();
102 void write_results_meta_data();
103
104 int get_file_pointer() const override;
105
106 private:
107 void openDatabase__() const override;
108 void closeDatabase__() const override;
109
110 bool begin__(Ioss::State state) override;
111 bool end__(Ioss::State state) override;
112
113 bool begin_state__(int state, double time) override;
114 bool end_state__(int state, double time) override;
115 void flush_database__() const override;
116
117 bool check_valid_file_open(int status) const;
118 void create_structured_block(int base, int zone, size_t &num_node);
119 void create_structured_block_fpp(int base, int zone, size_t &num_node);
120 size_t finalize_structured_blocks();
121 void finalize_database() override;
122 void get_step_times__() override;
123
124 void create_unstructured_block(int base, int zone, size_t &num_node);
125 void write_adjacency_data();
126
127 int64_t get_field_internal(const Ioss::Region *reg, const Ioss::Field &field, void *data,
128 size_t data_size) const override;
129 int64_t get_field_internal(const Ioss::NodeBlock *nb, const Ioss::Field &field, void *data,
130 size_t data_size) const override;
131 int64_t get_field_internal(const Ioss::EdgeBlock *eb, const Ioss::Field &field, void *data,
132 size_t data_size) const override;
133 int64_t get_field_internal(const Ioss::FaceBlock *fb, const Ioss::Field &field, void *data,
134 size_t data_size) const override;
135 int64_t get_field_internal(const Ioss::ElementBlock *eb, const Ioss::Field &field, void *data,
136 size_t data_size) const override;
137 int64_t get_field_internal(const Ioss::StructuredBlock *sb, const Ioss::Field &field,
138 void *data, size_t data_size) const override;
139 int64_t get_field_internal(const Ioss::SideBlock *sb, const Ioss::Field &field, void *data,
140 size_t data_size) const override;
141 int64_t get_field_internal(const Ioss::NodeSet *ns, const Ioss::Field &field, void *data,
142 size_t data_size) const override;
143 int64_t get_field_internal(const Ioss::EdgeSet *es, const Ioss::Field &field, void *data,
144 size_t data_size) const override;
145 int64_t get_field_internal(const Ioss::FaceSet *fs, const Ioss::Field &field, void *data,
146 size_t data_size) const override;
147 int64_t get_field_internal(const Ioss::ElementSet *es, const Ioss::Field &field, void *data,
148 size_t data_size) const override;
149 int64_t get_field_internal(const Ioss::SideSet *fs, const Ioss::Field &field, void *data,
150 size_t data_size) const override;
151 int64_t get_field_internal(const Ioss::CommSet *cs, const Ioss::Field &field, void *data,
152 size_t data_size) const override;
153
154 int64_t put_field_internal(const Ioss::Region *region, const Ioss::Field &field, void *data,
155 size_t data_size) const override;
156 int64_t put_field_internal(const Ioss::NodeBlock *nb, const Ioss::Field &field, void *data,
157 size_t data_size) const override;
158 int64_t put_field_internal(const Ioss::EdgeBlock *eb, const Ioss::Field &field, void *data,
159 size_t data_size) const override;
160 int64_t put_field_internal(const Ioss::FaceBlock *fb, const Ioss::Field &field, void *data,
161 size_t data_size) const override;
162 int64_t put_field_internal(const Ioss::ElementBlock *eb, const Ioss::Field &field, void *data,
163 size_t data_size) const override;
164 int64_t put_field_internal(const Ioss::SideBlock *sb, const Ioss::Field &field, void *data,
165 size_t data_size) const override;
166 int64_t put_field_internal(const Ioss::NodeSet *ns, const Ioss::Field &field, void *data,
167 size_t data_size) const override;
168 int64_t put_field_internal(const Ioss::EdgeSet *es, const Ioss::Field &field, void *data,
169 size_t data_size) const override;
170 int64_t put_field_internal(const Ioss::FaceSet *fs, const Ioss::Field &field, void *data,
171 size_t data_size) const override;
172 int64_t put_field_internal(const Ioss::ElementSet *es, const Ioss::Field &field, void *data,
173 size_t data_size) const override;
174 int64_t put_field_internal(const Ioss::SideSet *ss, const Ioss::Field &field, void *data,
175 size_t data_size) const override;
176 int64_t put_field_internal(const Ioss::CommSet *cs, const Ioss::Field &field, void *data,
177 size_t data_size) const override;
178 int64_t put_field_internal(const Ioss::StructuredBlock *sb, const Ioss::Field &field,
179 void *data, size_t data_size) const override;
180
181 // ID Mapping functions.
182 const Ioss::Map &get_map(entity_type type) const;
183 const Ioss::Map &get_map(Ioss::Map &entity_map, int64_t entityCount, int64_t file_offset,
184 int64_t file_count, entity_type type) const;
185
186 private:
187 mutable int m_cgnsFilePtr{-1};
188
189 int m_flushInterval{0}; // Default is no flushing after each timestep
190 int m_currentVertexSolutionIndex = 0;
191 int m_currentCellCenterSolutionIndex = 0;
192
193 mutable std::vector<size_t> m_zoneOffset; // Offset for local zone/block element ids to global.
194 mutable std::vector<size_t>
195 m_bcOffset; // The BC Section element offsets in unstructured output.
196 mutable std::vector<double> m_timesteps;
197 std::vector<std::vector<cgsize_t>> m_blockLocalNodeMap;
198 std::map<std::string, int> m_zoneNameMap;
199 mutable std::map<int, Ioss::Map *> m_globalToBlockLocalNodeMap;
200 };
201 } // namespace Iocgns
202 #endif
Iocgns::DatabaseIO::begin_state__
bool begin_state__(int state, double time) override
Definition: Iocgns_DatabaseIO.C:1491
Ioss_CodeTypes.h
Iocgns::DatabaseIO::write_results_meta_data
void write_results_meta_data()
Definition: Iocgns_DatabaseIO.C:2668
Iocgns::DatabaseIO::node_major
bool node_major() const override
Definition: Iocgns_DatabaseIO.h:97
Ioss
The main namespace for the Ioss library.
Definition: Ioad_DatabaseIO.C:66
Ioss::DatabaseIO
An input or output Database.
Definition: Ioss_DatabaseIO.h:82
Ioss_DBUsage.h
Iocgns::DatabaseIO::m_timesteps
std::vector< double > m_timesteps
Definition: Iocgns_DatabaseIO.h:196
Iocgns::DatabaseIO::get_field_internal
int64_t get_field_internal(const Ioss::Region *reg, const Ioss::Field &field, void *data, size_t data_size) const override
Definition: Iocgns_DatabaseIO.C:1536
Iocgns::DatabaseIO::openDatabase__
void openDatabase__() const override
Definition: Iocgns_DatabaseIO.C:487
Iocgns::DatabaseIO::end__
bool end__(Ioss::State state) override
Definition: Iocgns_DatabaseIO.C:1464
Iocgns::DatabaseIO::m_zoneNameMap
std::map< std::string, int > m_zoneNameMap
Definition: Iocgns_DatabaseIO.h:198
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
Iocgns
A namespace for the CGNS database format.
Definition: Iocgns_DatabaseIO.C:444
Iocgns::DatabaseIO::get_file_pointer
int get_file_pointer() const override
Definition: Iocgns_DatabaseIO.C:479
Iocgns::DatabaseIO::write_adjacency_data
void write_adjacency_data()
Definition: Iocgns_DatabaseIO.C:1390
Iocgns::DatabaseIO::m_currentVertexSolutionIndex
int m_currentVertexSolutionIndex
Definition: Iocgns_DatabaseIO.h:190
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::check_valid_file_open
bool check_valid_file_open(int status) const
Definition: Iocgns_DatabaseIO.C:566
Iocgns::DatabaseIO::finalize_structured_blocks
size_t finalize_structured_blocks()
Definition: Iocgns_DatabaseIO.C:1056
Iocgns::DatabaseIO::entity_type
entity_type
Definition: Iocgns_DatabaseIO.h:77
Iocgns::DatabaseIO::get_step_times__
void get_step_times__() override
Definition: Iocgns_DatabaseIO.C:1384
Ioss_DatabaseIO.h
Iocgns::DatabaseIO
Definition: Iocgns_DatabaseIO.h:74
Ioss::State
State
Access states for a database.
Definition: Ioss_State.h:42
Ioss::DatabaseIO::DatabaseIO
DatabaseIO()=delete
Ioss_State.h
Ioss::ElementBlock
A collection of elements having the same topology.
Definition: Ioss_ElementBlock.h:48
Iocgns::DatabaseIO::write_meta_data
void write_meta_data()
Definition: Iocgns_DatabaseIO.C:1373
Ioss::StructuredBlock
A structured zone – i,j,k.
Definition: Ioss_StructuredBlock.h:103
Ioss::ElementSet
A collection of elements.
Definition: Ioss_ElementSet.h:54
Iocgns::DatabaseIO::entity_field_support
unsigned entity_field_support() const override
Definition: Iocgns_DatabaseIO.C:2670
Ioss::DatabaseUsage
DatabaseUsage
Specifies how an Ioss::DatabaseIO object will be used.
Definition: Ioss_DBUsage.h:40
Iocgns::DatabaseIO::flush_database__
void flush_database__() const override
Definition: Iocgns_DatabaseIO.C:1526
Iocgns::DatabaseIO::m_bcOffset
std::vector< size_t > m_bcOffset
Definition: Iocgns_DatabaseIO.h:195
Iocgns::DatabaseIO::get_map
const Ioss::Map & get_map(entity_type type) const
Iocgns::DatabaseIO::closeDatabase__
void closeDatabase__() const override
Definition: Iocgns_DatabaseIO.C:557
Iocgns::DatabaseIO::entity_type::ELEM
Iocgns::DatabaseIO::node_global_to_local__
int64_t node_global_to_local__(int64_t global, bool must_exist) const override
Definition: Iocgns_DatabaseIO.C:641
Iocgns::DatabaseIO::end_state__
bool end_state__(int state, double time) override
Definition: Iocgns_DatabaseIO.C:1503
Ioss::NodeBlock
A collection of all nodes in the region.
Definition: Ioss_NodeBlock.h:53
Iocgns::DatabaseIO::create_unstructured_block
void create_unstructured_block(int base, int zone, size_t &num_node)
Definition: Iocgns_DatabaseIO.C:1113
Iocgns::DatabaseIO::m_currentCellCenterSolutionIndex
int m_currentCellCenterSolutionIndex
Definition: Iocgns_DatabaseIO.h:191
Iocgns::DatabaseIO::create_structured_block
void create_structured_block(int base, int zone, size_t &num_node)
Definition: Iocgns_DatabaseIO.C:972
Iocgns::DatabaseIO::begin__
bool begin__(Ioss::State state) override
Definition: Iocgns_DatabaseIO.C:1458
Iocgns::DatabaseIO::m_blockLocalNodeMap
std::vector< std::vector< cgsize_t > > m_blockLocalNodeMap
Definition: Iocgns_DatabaseIO.h:197
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:199
Ioss::Map
Definition: Ioss_Map.h:52
Iocgns::DatabaseIO::create_structured_block_fpp
void create_structured_block_fpp(int base, int zone, size_t &num_node)
Definition: Iocgns_DatabaseIO.C:648
Ioss::CommSet
Definition: Ioss_CommSet.h:51
anonymous_namespace{cth_pressure_map.C}::data
std::vector< char > data
Definition: cth_pressure_map.C:73
Ioss::Region
A grouping entity that contains other grouping entities.
Definition: Ioss_Region.h:98
Iocgns::DatabaseIO::m_flushInterval
int m_flushInterval
Definition: Iocgns_DatabaseIO.h:189
Iocgns::DatabaseIO::~DatabaseIO
~DatabaseIO() override
Definition: Iocgns_DatabaseIO.C:467
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:88
Iocgns::DatabaseIO::read_meta_data__
void read_meta_data__() override
Definition: Iocgns_DatabaseIO.C:1289
Iocgns::DatabaseIO::m_zoneOffset
std::vector< size_t > m_zoneOffset
Definition: Iocgns_DatabaseIO.h:193
Iocgns::DatabaseIO::finalize_database
void finalize_database() override
Definition: Iocgns_DatabaseIO.C:628
Iocgns::DatabaseIO::put_field_internal
int64_t put_field_internal(const Ioss::Region *region, const Ioss::Field &field, void *data, size_t data_size) const override
Definition: Iocgns_DatabaseIO.C:2113
Iocgns::DatabaseIO::element_global_to_local__
int64_t element_global_to_local__(int64_t global) const override
Definition: Iocgns_DatabaseIO.C:646
Ioss::PropertyManager
A collection of Ioss::Property objects.
Definition: Ioss_PropertyManager.h:49
Iocgns::DatabaseIO::m_cgnsFilePtr
int m_cgnsFilePtr
Definition: Iocgns_DatabaseIO.h:187
Ioss::EdgeBlock
A collection of element edges with the same topology.
Definition: Ioss_EdgeBlock.h:53
Iocgns::DatabaseIO::entity_type::NODE