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 bool check_valid_file_open(int status) const;
115 void create_structured_block(int base, int zone, size_t &num_node);
116 void create_structured_block_fpp(int base, int zone, size_t &num_node);
117 size_t finalize_structured_blocks();
118 void finalize_database() override;
119 void get_step_times__() override;
120
121 void create_unstructured_block(int base, int zone, size_t &num_node);
122 void write_adjacency_data();
123
124 int64_t get_field_internal(const Ioss::Region *reg, const Ioss::Field &field, void *data,
125 size_t data_size) const override;
126 int64_t get_field_internal(const Ioss::NodeBlock *nb, const Ioss::Field &field, void *data,
127 size_t data_size) const override;
128 int64_t get_field_internal(const Ioss::EdgeBlock *eb, const Ioss::Field &field, void *data,
129 size_t data_size) const override;
130 int64_t get_field_internal(const Ioss::FaceBlock *fb, const Ioss::Field &field, void *data,
131 size_t data_size) const override;
132 int64_t get_field_internal(const Ioss::ElementBlock *eb, const Ioss::Field &field, void *data,
133 size_t data_size) const override;
134 int64_t get_field_internal(const Ioss::StructuredBlock *sb, const Ioss::Field &field,
135 void *data, size_t data_size) const override;
136 int64_t get_field_internal(const Ioss::SideBlock *sb, const Ioss::Field &field, void *data,
137 size_t data_size) const override;
138 int64_t get_field_internal(const Ioss::NodeSet *ns, const Ioss::Field &field, void *data,
139 size_t data_size) const override;
140 int64_t get_field_internal(const Ioss::EdgeSet *es, const Ioss::Field &field, void *data,
141 size_t data_size) const override;
142 int64_t get_field_internal(const Ioss::FaceSet *fs, const Ioss::Field &field, void *data,
143 size_t data_size) const override;
144 int64_t get_field_internal(const Ioss::ElementSet *es, const Ioss::Field &field, void *data,
145 size_t data_size) const override;
146 int64_t get_field_internal(const Ioss::SideSet *fs, const Ioss::Field &field, void *data,
147 size_t data_size) const override;
148 int64_t get_field_internal(const Ioss::CommSet *cs, const Ioss::Field &field, void *data,
149 size_t data_size) const override;
150
151 int64_t put_field_internal(const Ioss::Region *region, const Ioss::Field &field, void *data,
152 size_t data_size) const override;
153 int64_t put_field_internal(const Ioss::NodeBlock *nb, const Ioss::Field &field, void *data,
154 size_t data_size) const override;
155 int64_t put_field_internal(const Ioss::EdgeBlock *eb, const Ioss::Field &field, void *data,
156 size_t data_size) const override;
157 int64_t put_field_internal(const Ioss::FaceBlock *fb, const Ioss::Field &field, void *data,
158 size_t data_size) const override;
159 int64_t put_field_internal(const Ioss::ElementBlock *eb, const Ioss::Field &field, void *data,
160 size_t data_size) const override;
161 int64_t put_field_internal(const Ioss::SideBlock *sb, const Ioss::Field &field, void *data,
162 size_t data_size) const override;
163 int64_t put_field_internal(const Ioss::NodeSet *ns, const Ioss::Field &field, void *data,
164 size_t data_size) const override;
165 int64_t put_field_internal(const Ioss::EdgeSet *es, const Ioss::Field &field, void *data,
166 size_t data_size) const override;
167 int64_t put_field_internal(const Ioss::FaceSet *fs, const Ioss::Field &field, void *data,
168 size_t data_size) const override;
169 int64_t put_field_internal(const Ioss::ElementSet *es, const Ioss::Field &field, void *data,
170 size_t data_size) const override;
171 int64_t put_field_internal(const Ioss::SideSet *ss, const Ioss::Field &field, void *data,
172 size_t data_size) const override;
173 int64_t put_field_internal(const Ioss::CommSet *cs, const Ioss::Field &field, void *data,
174 size_t data_size) const override;
175 int64_t put_field_internal(const Ioss::StructuredBlock *sb, const Ioss::Field &field,
176 void *data, size_t data_size) const override;
177
178 // ID Mapping functions.
179 const Ioss::Map &get_map(entity_type type) const;
180 const Ioss::Map &get_map(Ioss::Map &entity_map, int64_t entityCount, int64_t file_offset,
181 int64_t file_count, entity_type type) const;
182
183 mutable int cgnsFilePtr{-1};
184
185 int m_currentVertexSolutionIndex = 0;
186 int m_currentCellCenterSolutionIndex = 0;
187
188 mutable std::vector<size_t> m_zoneOffset; // Offset for local zone/block element ids to global.
189 mutable std::vector<size_t>
190 m_bcOffset; // The BC Section element offsets in unstructured output.
191 mutable std::vector<double> m_timesteps;
192 std::vector<std::vector<cgsize_t>> m_blockLocalNodeMap;
193 std::map<std::string, int> m_zoneNameMap;
194 mutable std::map<int, Ioss::Map *> m_globalToBlockLocalNodeMap;
195 };
196 } // namespace Iocgns
197 #endif
Ioss_CodeTypes.h
Ioss::ElementTopology
Represents an element topology.
Definition: Ioss_ElementTopology.h:72
Iocgns::DatabaseIO::write_results_meta_data
void write_results_meta_data()
Definition: Iocgns_DatabaseIO.C:2522
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:191
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:1420
Iocgns::DatabaseIO::openDatabase__
void openDatabase__() const override
Definition: Iocgns_DatabaseIO.C:417
Iocgns::DatabaseIO::end__
bool end__(Ioss::State state) override
Definition: Iocgns_DatabaseIO.C:1372
Iocgns::DatabaseIO::m_zoneNameMap
std::map< std::string, int > m_zoneNameMap
Definition: Iocgns_DatabaseIO.h:193
Iocgns::DatabaseIO::end_state__
bool end_state__(Ioss::Region *region, int state, double time) override
Definition: Iocgns_DatabaseIO.C:1411
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
Iocgns::DatabaseIO::begin_state__
bool begin_state__(Ioss::Region *region, int state, double time) override
Definition: Iocgns_DatabaseIO.C:1399
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::DatabaseIO::cgnsFilePtr
int cgnsFilePtr
Definition: Iocgns_DatabaseIO.h:183
Iocgns
A namespace for the CGNS database format.
Definition: Iocgns_DatabaseIO.C:392
Iocgns::DatabaseIO::write_adjacency_data
void write_adjacency_data()
Definition: Iocgns_DatabaseIO.C:1298
Iocgns::DatabaseIO::m_currentVertexSolutionIndex
int m_currentVertexSolutionIndex
Definition: Iocgns_DatabaseIO.h:185
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:474
Iocgns::DatabaseIO::finalize_structured_blocks
size_t finalize_structured_blocks()
Definition: Iocgns_DatabaseIO.C:969
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:1293
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:1283
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:2524
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:190
Iocgns::DatabaseIO::get_map
const Ioss::Map & get_map(entity_type type) const
Iocgns::DatabaseIO::closeDatabase__
void closeDatabase__() const override
Definition: Iocgns_DatabaseIO.C:466
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:555
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:1026
Iocgns::DatabaseIO::m_currentCellCenterSolutionIndex
int m_currentCellCenterSolutionIndex
Definition: Iocgns_DatabaseIO.h:186
Iocgns::DatabaseIO::create_structured_block
void create_structured_block(int base, int zone, size_t &num_node)
Definition: Iocgns_DatabaseIO.C:886
Iocgns::DatabaseIO::begin__
bool begin__(Ioss::State state) override
Definition: Iocgns_DatabaseIO.C:1366
Iocgns::DatabaseIO::m_blockLocalNodeMap
std::vector< std::vector< cgsize_t > > m_blockLocalNodeMap
Definition: Iocgns_DatabaseIO.h:192
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:194
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:562
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::~DatabaseIO
~DatabaseIO() override
Definition: Iocgns_DatabaseIO.C:409
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:80
Iocgns::DatabaseIO::read_meta_data__
void read_meta_data__() override
Definition: Iocgns_DatabaseIO.C:1203
Iocgns::DatabaseIO::m_zoneOffset
std::vector< size_t > m_zoneOffset
Definition: Iocgns_DatabaseIO.h:188
Iocgns::DatabaseIO::finalize_database
void finalize_database() override
Definition: Iocgns_DatabaseIO.C:542
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:1990
Iocgns::DatabaseIO::element_global_to_local__
int64_t element_global_to_local__(int64_t global) const override
Definition: Iocgns_DatabaseIO.C:560
Ioss::PropertyManager
A collection of Ioss::Property objects.
Definition: Ioss_PropertyManager.h:49
Ioss::EdgeBlock
A collection of element edges with the same topology.
Definition: Ioss_EdgeBlock.h:53
Iocgns::DatabaseIO::entity_type::NODE