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 const std::string get_format() const override {return "CGNS";}
94
95 // This isn't quite true since a CGNS library with cgsize_t == 64-bits can read
96 // a file with 32-bit ints. However,...
97 int int_byte_size_db() const override { return CG_SIZEOF_SIZE; }
98
99 bool node_major() const override { return false; }
100
101 // Metadata-related functions.
102 void read_meta_data__() override;
103 void write_meta_data();
104 void write_results_meta_data();
105
106 int get_file_pointer() const override;
107
108 private:
109 void openDatabase__() const override;
110 void closeDatabase__() const override;
111
112 bool begin__(Ioss::State state) override;
113 bool end__(Ioss::State state) override;
114
115 bool begin_state__(int state, double time) override;
116 bool end_state__(int state, double time) override;
117 void flush_database__() const override;
118
119 bool check_valid_file_open(int status) const;
120 void create_structured_block(int base, int zone, size_t &num_node);
121 void create_structured_block_fpp(int base, int zone, size_t &num_node);
122 size_t finalize_structured_blocks();
123 void finalize_database() override;
124 void get_step_times__() override;
125
126 void create_unstructured_block(int base, int zone, size_t &num_node);
127 void write_adjacency_data();
128
129 int64_t get_field_internal(const Ioss::Region *reg, const Ioss::Field &field, void *data,
130 size_t data_size) const override;
131 int64_t get_field_internal(const Ioss::NodeBlock *nb, const Ioss::Field &field, void *data,
132 size_t data_size) const override;
133 int64_t get_field_internal(const Ioss::EdgeBlock *eb, const Ioss::Field &field, void *data,
134 size_t data_size) const override;
135 int64_t get_field_internal(const Ioss::FaceBlock *fb, const Ioss::Field &field, void *data,
136 size_t data_size) const override;
137 int64_t get_field_internal(const Ioss::ElementBlock *eb, const Ioss::Field &field, void *data,
138 size_t data_size) const override;
139 int64_t get_field_internal(const Ioss::StructuredBlock *sb, const Ioss::Field &field,
140 void *data, size_t data_size) const override;
141 int64_t get_field_internal(const Ioss::SideBlock *sb, const Ioss::Field &field, void *data,
142 size_t data_size) const override;
143 int64_t get_field_internal(const Ioss::NodeSet *ns, const Ioss::Field &field, void *data,
144 size_t data_size) const override;
145 int64_t get_field_internal(const Ioss::EdgeSet *es, const Ioss::Field &field, void *data,
146 size_t data_size) const override;
147 int64_t get_field_internal(const Ioss::FaceSet *fs, const Ioss::Field &field, void *data,
148 size_t data_size) const override;
149 int64_t get_field_internal(const Ioss::ElementSet *es, const Ioss::Field &field, void *data,
150 size_t data_size) const override;
151 int64_t get_field_internal(const Ioss::SideSet *fs, const Ioss::Field &field, void *data,
152 size_t data_size) const override;
153 int64_t get_field_internal(const Ioss::CommSet *cs, const Ioss::Field &field, void *data,
154 size_t data_size) const override;
155
156 int64_t get_field_internal_sub_nb(const Ioss::NodeBlock *nb, const Ioss::Field &field,
157 void *data, size_t data_size) const;
158
159 int64_t put_field_internal(const Ioss::Region *region, const Ioss::Field &field, void *data,
160 size_t data_size) const override;
161 int64_t put_field_internal(const Ioss::NodeBlock *nb, const Ioss::Field &field, void *data,
162 size_t data_size) const override;
163 int64_t put_field_internal(const Ioss::EdgeBlock *eb, const Ioss::Field &field, void *data,
164 size_t data_size) const override;
165 int64_t put_field_internal(const Ioss::FaceBlock *fb, const Ioss::Field &field, void *data,
166 size_t data_size) const override;
167 int64_t put_field_internal(const Ioss::ElementBlock *eb, const Ioss::Field &field, void *data,
168 size_t data_size) const override;
169 int64_t put_field_internal(const Ioss::SideBlock *sb, const Ioss::Field &field, void *data,
170 size_t data_size) const override;
171 int64_t put_field_internal(const Ioss::NodeSet *ns, const Ioss::Field &field, void *data,
172 size_t data_size) const override;
173 int64_t put_field_internal(const Ioss::EdgeSet *es, const Ioss::Field &field, void *data,
174 size_t data_size) const override;
175 int64_t put_field_internal(const Ioss::FaceSet *fs, const Ioss::Field &field, void *data,
176 size_t data_size) const override;
177 int64_t put_field_internal(const Ioss::ElementSet *es, const Ioss::Field &field, void *data,
178 size_t data_size) const override;
179 int64_t put_field_internal(const Ioss::SideSet *ss, const Ioss::Field &field, void *data,
180 size_t data_size) const override;
181 int64_t put_field_internal(const Ioss::CommSet *cs, const Ioss::Field &field, void *data,
182 size_t data_size) const override;
183 int64_t put_field_internal(const Ioss::StructuredBlock *sb, const Ioss::Field &field,
184 void *data, size_t data_size) const override;
185
186 int64_t put_field_internal_sub_nb(const Ioss::NodeBlock *nb, const Ioss::Field &field,
187 void *data, size_t data_size) const;
188
189 // ID Mapping functions.
190 const Ioss::Map &get_map(entity_type type) const;
191 const Ioss::Map &get_map(Ioss::Map &entity_map, int64_t entityCount, int64_t file_offset,
192 int64_t file_count, entity_type type) const;
193
194 private:
195 mutable int m_cgnsFilePtr{-1};
196
197 int m_flushInterval{0}; // Default is no flushing after each timestep
198 int m_currentVertexSolutionIndex = 0;
199 int m_currentCellCenterSolutionIndex = 0;
200
201 mutable std::vector<size_t> m_zoneOffset; // Offset for local zone/block element ids to global.
202 mutable std::vector<size_t>
203 m_bcOffset; // The BC Section element offsets in unstructured output.
204 mutable std::vector<double> m_timesteps;
205 std::vector<std::vector<cgsize_t>> m_blockLocalNodeMap;
206 std::map<std::string, int> m_zoneNameMap;
207 mutable std::map<int, Ioss::Map *> m_globalToBlockLocalNodeMap;
208 };
209 } // namespace Iocgns
210 #endif
Iocgns::DatabaseIO::get_file_pointer
int get_file_pointer() const override
Definition: Iocgns_DatabaseIO.C:479
Iocgns::DatabaseIO::m_timesteps
std::vector< double > m_timesteps
Definition: Iocgns_DatabaseIO.h:204
Iocgns::DatabaseIO::write_results_meta_data
void write_results_meta_data()
Definition: Iocgns_DatabaseIO.C:2825
Iocgns::DatabaseIO::m_cgnsFilePtr
int m_cgnsFilePtr
Definition: Iocgns_DatabaseIO.h:195
Ioss_DBUsage.h
Iocgns::DatabaseIO::m_globalToBlockLocalNodeMap
std::map< int, Ioss::Map * > m_globalToBlockLocalNodeMap
Definition: Iocgns_DatabaseIO.h:207
Iocgns::DatabaseIO::node_major
bool node_major() const override
Definition: Iocgns_DatabaseIO.h:99
Ioss::Field
Holds metadata for bulk data associated with a GroupingEntity.
Definition: Ioss_Field.h:47
Iocgns::DatabaseIO::create_structured_block
void create_structured_block(int base, int zone, size_t &num_node)
Definition: Iocgns_DatabaseIO.C:974
Iocgns::DatabaseIO::entity_type::NODE
Ioss_Map.h
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:2205
Iocgns::DatabaseIO::m_zoneOffset
std::vector< size_t > m_zoneOffset
Definition: Iocgns_DatabaseIO.h:201
Ioss::EdgeBlock
A collection of element edges with the same topology.
Definition: Ioss_EdgeBlock.h:53
Ioss::DatabaseUsage
DatabaseUsage
Specifies how an Ioss::DatabaseIO object will be used.
Definition: Ioss_DBUsage.h:40
Ioss
The main namespace for the Ioss library.
Definition: Ioad_DatabaseIO.C:66
Iocgns::DatabaseIO::end_state__
bool end_state__(int state, double time) override
Definition: Iocgns_DatabaseIO.C:1505
Iocgns::DatabaseIO::get_format
const std::string get_format() const override
Definition: Iocgns_DatabaseIO.h:93
Ioss::State
State
Access states for a database.
Definition: Ioss_State.h:42
Iocgns::DatabaseIO::m_bcOffset
std::vector< size_t > m_bcOffset
Definition: Iocgns_DatabaseIO.h:203
Iocgns::DatabaseIO::int_byte_size_db
int int_byte_size_db() const override
Definition: Iocgns_DatabaseIO.h:97
Ioss::Region
A grouping entity that contains other grouping entities.
Definition: Ioss_Region.h:98
Ioss::NodeSet
A collection of nodes.
Definition: Ioss_NodeSet.h:53
Iocgns::DatabaseIO::m_zoneNameMap
std::map< std::string, int > m_zoneNameMap
Definition: Iocgns_DatabaseIO.h:206
Ioss::FaceSet
A collection of element faces.
Definition: Ioss_FaceSet.h:54
Ioss::StructuredBlock
A structured zone – i,j,k.
Definition: Ioss_StructuredBlock.h:103
Ioss::PropertyManager
A collection of Ioss::Property objects.
Definition: Ioss_PropertyManager.h:49
Iocgns::DatabaseIO::get_step_times__
void get_step_times__() override
Definition: Iocgns_DatabaseIO.C:1386
Ioss::EdgeSet
A collection of element edges.
Definition: Ioss_EdgeSet.h:54
Ioss::ElementSet
A collection of elements.
Definition: Ioss_ElementSet.h:54
Ioss::CommSet
Definition: Ioss_CommSet.h:51
Iocgns::DatabaseIO::get_field_internal_sub_nb
int64_t get_field_internal_sub_nb(const Ioss::NodeBlock *nb, const Ioss::Field &field, void *data, size_t data_size) const
Definition: Iocgns_DatabaseIO.C:1708
Iocgns::DatabaseIO::node_global_to_local__
int64_t node_global_to_local__(int64_t global, bool must_exist) const override
Definition: Iocgns_DatabaseIO.C:643
Ioss::FaceBlock
A collection of element faces with the same topology.
Definition: Ioss_FaceBlock.h:53
Iocgns::DatabaseIO::entity_type
entity_type
Definition: Iocgns_DatabaseIO.h:77
Iocgns::DatabaseIO::finalize_database
void finalize_database() override
Definition: Iocgns_DatabaseIO.C:630
Ioss::DatabaseIO
An input or output Database.
Definition: Ioss_DatabaseIO.h:82
Ioss::DatabaseIO::DatabaseIO
DatabaseIO()=delete
Iocgns::DatabaseIO::write_meta_data
void write_meta_data()
Definition: Iocgns_DatabaseIO.C:1375
Iocgns::DatabaseIO::m_blockLocalNodeMap
std::vector< std::vector< cgsize_t > > m_blockLocalNodeMap
Definition: Iocgns_DatabaseIO.h:205
Iocgns::DatabaseIO::m_flushInterval
int m_flushInterval
Definition: Iocgns_DatabaseIO.h:197
Ioss_State.h
Ioss::SideBlock
A collection of element sides having the same topology.
Definition: Ioss_SideBlock.h:59
Iocgns::DatabaseIO::get_map
const Ioss::Map & get_map(entity_type type) const
Iocgns::DatabaseIO::finalize_structured_blocks
size_t finalize_structured_blocks()
Definition: Iocgns_DatabaseIO.C:1058
Iocgns::DatabaseIO::create_structured_block_fpp
void create_structured_block_fpp(int base, int zone, size_t &num_node)
Definition: Iocgns_DatabaseIO.C:650
Iocgns::DatabaseIO::openDatabase__
void openDatabase__() const override
Definition: Iocgns_DatabaseIO.C:487
Iocgns::DatabaseIO::closeDatabase__
void closeDatabase__() const override
Definition: Iocgns_DatabaseIO.C:559
Iocgns::DatabaseIO::begin__
bool begin__(Ioss::State state) override
Definition: Iocgns_DatabaseIO.C:1460
Ioss_IOFactory.h
Ioss::ElementBlock
A collection of elements having the same topology.
Definition: Ioss_ElementBlock.h:48
Iocgns::DatabaseIO::m_currentCellCenterSolutionIndex
int m_currentCellCenterSolutionIndex
Definition: Iocgns_DatabaseIO.h:199
Iocgns::DatabaseIO::write_adjacency_data
void write_adjacency_data()
Definition: Iocgns_DatabaseIO.C:1392
Iocgns::DatabaseIO::check_valid_file_open
bool check_valid_file_open(int status) const
Definition: Iocgns_DatabaseIO.C:568
Ioss::Map
Definition: Ioss_Map.h:52
Iocgns::DatabaseIO::read_meta_data__
void read_meta_data__() override
Definition: Iocgns_DatabaseIO.C:1291
Iocgns::DatabaseIO::m_currentVertexSolutionIndex
int m_currentVertexSolutionIndex
Definition: Iocgns_DatabaseIO.h:198
Iocgns::DatabaseIO::entity_type::ELEM
Iocgns::DatabaseIO::put_field_internal_sub_nb
int64_t put_field_internal_sub_nb(const Ioss::NodeBlock *nb, const Ioss::Field &field, void *data, size_t data_size) const
Definition: Iocgns_DatabaseIO.C:2649
Iocgns::DatabaseIO::end__
bool end__(Ioss::State state) override
Definition: Iocgns_DatabaseIO.C:1466
anonymous_namespace{cth_pressure_map.C}::data
std::vector< char > data
Definition: cth_pressure_map.C:74
Iocgns::DatabaseIO::begin_state__
bool begin_state__(int state, double time) override
Definition: Iocgns_DatabaseIO.C:1493
Iocgns::DatabaseIO::~DatabaseIO
~DatabaseIO() override
Definition: Iocgns_DatabaseIO.C:467
Iocgns::DatabaseIO::entity_field_support
unsigned entity_field_support() const override
Definition: Iocgns_DatabaseIO.C:2827
Iocgns::DatabaseIO::create_unstructured_block
void create_unstructured_block(int base, int zone, size_t &num_node)
Definition: Iocgns_DatabaseIO.C:1115
Ioss::NodeBlock
A collection of all nodes in the region.
Definition: Ioss_NodeBlock.h:53
Iocgns::DatabaseIO::flush_database__
void flush_database__() const override
Definition: Iocgns_DatabaseIO.C:1528
MPI_Comm
int MPI_Comm
Definition: Ioss_CodeTypes.h:96
Iocgns::DatabaseIO::element_global_to_local__
int64_t element_global_to_local__(int64_t global) const override
Definition: Iocgns_DatabaseIO.C:648
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:1538
Iocgns
A namespace for the CGNS database format.
Definition: Iocgns_DatabaseIO.C:444
Ioss::SideSet
A collection of element sides.
Definition: Ioss_SideSet.h:53
Ioss_CodeTypes.h
Ioss_DatabaseIO.h
Iocgns::DatabaseIO
Definition: Iocgns_DatabaseIO.h:74