IOSS 2.0

Iocgns_Utils.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_UTILS_H
34 #define IOSS_IOCGNS_UTILS_H
35
36 #include <Ioss_CodeTypes.h>
37 #include <Ioss_DatabaseIO.h>
38 #include <Ioss_ElementTopology.h>
39 #include <Ioss_Region.h>
40 #include <Ioss_SideBlock.h>
41 #include <Ioss_SideSet.h>
42 #include <Ioss_StructuredBlock.h>
43 #include <Ioss_Utils.h>
44 #include <cgnslib.h>
45 #include <ostream>
46 #include <string>
47
48 // Used in Iocgns_DatabaseIO.C and Iocgns_ParallelDatabase.C
49 #define CGCHECK(funcall) \
50 if ((funcall) != CG_OK) { \
51 Iocgns::Utils::cgns_error(cgnsFilePtr, __FILE__, __func__, __LINE__, myProcessor); \
52 }
53
54 #define CGCHECKNP(funcall) \
55 if ((funcall) != CG_OK) { \
56 Iocgns::Utils::cgns_error(cgnsFilePtr, __FILE__, __func__, __LINE__, -1); \
57 }
58
59 // Used in Iocgns_Decomposition.C
60 #define CGCHECK2(funcall) \
61 if ((funcall) != CG_OK) { \
62 Iocgns::Utils::cgns_error(filePtr, __FILE__, __func__, __LINE__, m_decomposition.m_processor); \
63 }
64
65 namespace Iocgns {
66 class StructuredZoneData;
67
68 class Utils
69 {
70 public:
71 Utils() = default;
72 ~Utils() = default;
73
74 static const size_t CG_CELL_CENTER_FIELD_ID = 1ul << 33;
75 static const size_t CG_VERTEX_FIELD_ID = 1ul << 34;
76
77 static size_t index(const Ioss::Field &field);
78
79 static void cgns_error(int cgnsid, const char *file, const char *function, int lineno,
80 int processor);
81
82 static int get_db_zone(const Ioss::EntityBlock *block);
83 static void set_field_index(const Ioss::Field &field, size_t index, CG_GridLocation_t location);
84 static bool is_cell_field(const Ioss::Field &field);
85
86 template <typename INT>
87 static void map_cgns_face_to_ioss(const Ioss::ElementTopology *parent_topo, size_t num_to_get,
88 INT *idata)
89 {
90 // The {topo}_map[] arrays map from CGNS face# to IOSS face#.
91 // See http://cgns.github.io/CGNS_docs_current/sids/conv.html#unstructgrid
92 // NOTE: '0' for first entry is to account for 1-based face numbering.
93
94 switch (parent_topo->shape()) {
95 case Ioss::ElementShape::HEX:
96 static int hex_map[] = {0, 5, 1, 2, 3, 4, 6};
97 for (size_t i = 0; i < num_to_get; i++) {
98 idata[2 * i + 1] = hex_map[idata[2 * i + 1]];
99 }
100 break;
101
102 case Ioss::ElementShape::TET:
103 static int tet_map[] = {0, 4, 1, 2, 3};
104 for (size_t i = 0; i < num_to_get; i++) {
105 idata[2 * i + 1] = tet_map[idata[2 * i + 1]];
106 }
107 break;
108
109 case Ioss::ElementShape::PYRAMID:
110 static int pyr_map[] = {0, 5, 1, 2, 3, 4};
111 for (size_t i = 0; i < num_to_get; i++) {
112 idata[2 * i + 1] = pyr_map[idata[2 * i + 1]];
113 }
114 break;
115
116 case Ioss::ElementShape::WEDGE:
117 #if 0
118 static int wed_map[] = {0, 1, 2, 3, 4, 5}; // Same
119 // Not needed -- maps 1 to 1
120 for (size_t i=0; i < num_to_get; i++) {
121 idata[2*i+1] = wed_map[idata[2*i+1]];
122 }
123 #endif
124 break;
125 default:;
126 }
127 }
128
129 static void map_ioss_face_to_cgns(const Ioss::ElementTopology *parent_topo, size_t num_to_get,
130 std::vector<cgsize_t> &data)
131 {
132 // The {topo}_map[] arrays map from CGNS face# to IOSS face#.
133 // See http://cgns.github.io/CGNS_docs_current/sids/conv.html#unstructgrid
134 // NOTE: '0' for first entry is to account for 1-based face numbering.
135
136 switch (parent_topo->shape()) {
137 case Ioss::ElementShape::HEX:
138 static int hex_map[] = {0, 2, 3, 4, 5, 1, 6};
139 for (size_t i = 0; i < num_to_get; i++) {
140 data[num_to_get * 2 + i] = hex_map[data[num_to_get * 2 + i]];
141 }
142 break;
143
144 case Ioss::ElementShape::TET:
145 static int tet_map[] = {0, 2, 3, 4, 1};
146 for (size_t i = 0; i < num_to_get; i++) {
147 data[num_to_get * 2 + i] = tet_map[data[num_to_get * 2 + i]];
148 }
149 break;
150
151 case Ioss::ElementShape::PYRAMID:
152 static int pyr_map[] = {0, 2, 3, 4, 5, 1};
153 for (size_t i = 0; i < num_to_get; i++) {
154 data[num_to_get * 2 + i] = pyr_map[data[num_to_get * 2 + i]];
155 }
156 break;
157
158 case Ioss::ElementShape::WEDGE:
159 #if 0
160 static int wed_map[] = {0, 1, 2, 3, 4, 5}; // Same
161 // Not needed -- maps 1 to 1
162 for (size_t i=0; i < num_to_get; i++) {
163 data[num_to_get * 2 + i] = wed_map[data[num_to_get * 2 + i]];
164 }
165 #endif
166 break;
167 default:;
168 }
169 }
170
171 static void write_flow_solution_metadata(int file_ptr, Ioss::Region *region, int state,
172 int *vertex_solution_index,
173 int *cell_center_solution_index, bool is_parallel_io);
174 static int find_solution_index(int cgnsFilePtr, int base, int zone, int step,
175 CG_GridLocation_t location);
176 static CG_ZoneType_t check_zone_type(int cgnsFilePtr);
177 static size_t common_write_meta_data(int file_ptr, const Ioss::Region &region,
178 std::vector<size_t> &zone_offset, bool is_parallel);
179 static size_t resolve_nodes(Ioss::Region &region, int my_processor, bool is_parallel);
180 static std::vector<std::vector<std::pair<size_t, size_t>>>
181 resolve_processor_shared_nodes(Ioss::Region &region, int my_processor);
182
183 static CG_ElementType_t map_topology_to_cgns(const std::string &name);
184 static std::string map_cgns_to_topology_type(CG_ElementType_t type);
185 static void add_sidesets(int cgnsFilePtr, Ioss::DatabaseIO *db);
186 static void add_structured_boundary_conditions(int cgnsFilePtr, Ioss::StructuredBlock *block,
187 bool is_parallel_io);
188 static void add_structured_boundary_conditions_fpp(int cgnsFilePtr,
189 Ioss::StructuredBlock *block);
190 static void add_structured_boundary_conditions_pio(int cgnsFilePtr,
191 Ioss::StructuredBlock *block);
192
193 static void finalize_database(int cgnsFilePtr, const std::vector<double> &timesteps,
194 Ioss::Region *region, int myProcessor, bool is_parallel_io);
195 static int get_step_times(int cgnsFilePtr, std::vector<double> &timesteps, Ioss::Region *region,
196 double timeScaleFactor, int myProcessor);
197 static void add_transient_variables(int cgnsFilePtr, const std::vector<double> &timesteps,
198 Ioss::Region *region, bool enable_field_recognition,
199 char suffix_separator, int myProcessor,
200 bool is_parallel_io);
201
202 static size_t pre_split(std::vector<Iocgns::StructuredZoneData *> &zones, double avg_work,
203 double load_balance, int proc_rank, int proc_count);
204 static void assign_zones_to_procs(std::vector<Iocgns::StructuredZoneData *> &zones,
205 std::vector<size_t> & work_vector);
206 };
207 } // namespace Iocgns
208
209 #endif
Ioss_CodeTypes.h
Iocgns::Utils::map_ioss_face_to_cgns
static void map_ioss_face_to_cgns(const Ioss::ElementTopology *parent_topo, size_t num_to_get, std::vector< cgsize_t > &data)
Definition: Iocgns_Utils.h:129
Ioss::ElementTopology
Represents an element topology.
Definition: Ioss_ElementTopology.h:72
Iocgns::Utils::add_transient_variables
static void add_transient_variables(int cgnsFilePtr, const std::vector< double > &timesteps, Ioss::Region *region, bool enable_field_recognition, char suffix_separator, int myProcessor, bool is_parallel_io)
Definition: Iocgns_Utils.C:1723
Iocgns::Utils::map_topology_to_cgns
static CG_ElementType_t map_topology_to_cgns(const std::string &name)
Definition: Iocgns_Utils.C:1019
Ioss::DatabaseIO
An input or output Database.
Definition: Ioss_DatabaseIO.h:80
Iocgns::Utils::resolve_processor_shared_nodes
static std::vector< std::vector< std::pair< size_t, size_t > > > resolve_processor_shared_nodes(Ioss::Region &region, int my_processor)
Definition: Iocgns_Utils.C:1371
Iocgns::Utils::resolve_nodes
static size_t resolve_nodes(Ioss::Region &region, int my_processor, bool is_parallel)
Definition: Iocgns_Utils.C:1254
Ioss::ElementShape::PYRAMID
Iocgns::Utils::get_db_zone
static int get_db_zone(const Ioss::EntityBlock *block)
Definition: Iocgns_Utils.C:448
Iocgns
A namespace for the CGNS database format.
Definition: Iocgns_DatabaseIO.C:392
Iocgns::Utils::get_step_times
static int get_step_times(int cgnsFilePtr, std::vector< double > &timesteps, Ioss::Region *region, double timeScaleFactor, int myProcessor)
Definition: Iocgns_Utils.C:1814
Iocgns::Utils::cgns_error
static void cgns_error(int cgnsid, const char *file, const char *function, int lineno, int processor)
Definition: Iocgns_Utils.C:398
Iocgns::Utils::add_structured_boundary_conditions_pio
static void add_structured_boundary_conditions_pio(int cgnsFilePtr, Ioss::StructuredBlock *block)
Definition: Iocgns_Utils.C:1449
Iocgns::Utils::~Utils
~Utils()=default
Iocgns::Utils::is_cell_field
static bool is_cell_field(const Ioss::Field &field)
Definition: Iocgns_Utils.C:473
Iocgns::Utils::add_structured_boundary_conditions_fpp
static void add_structured_boundary_conditions_fpp(int cgnsFilePtr, Ioss::StructuredBlock *block)
Definition: Iocgns_Utils.C:1573
Ioss::ElementShape::HEX
Ioss_DatabaseIO.h
Iocgns::Utils::finalize_database
static void finalize_database(int cgnsFilePtr, const std::vector< double > &timesteps, Ioss::Region *region, int myProcessor, bool is_parallel_io)
Definition: Iocgns_Utils.C:1643
Ioss_Region.h
Iocgns::Utils::index
static size_t index(const Ioss::Field &field)
Definition: Iocgns_Utils.C:459
Ioss::StructuredBlock
A structured zone – i,j,k.
Definition: Ioss_StructuredBlock.h:103
Iocgns::Utils::CG_CELL_CENTER_FIELD_ID
static const size_t CG_CELL_CENTER_FIELD_ID
Definition: Iocgns_Utils.h:74
Ioss_StructuredBlock.h
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_Utils.h
Ioss::ElementShape::WEDGE
Ioss_SideSet.h
Iocgns::Utils::map_cgns_to_topology_type
static std::string map_cgns_to_topology_type(CG_ElementType_t type)
Definition: Iocgns_Utils.C:988
Iocgns::Utils::Utils
Utils()=default
Iocgns::Utils::common_write_meta_data
static size_t common_write_meta_data(int file_ptr, const Ioss::Region &region, std::vector< size_t > &zone_offset, bool is_parallel)
Definition: Iocgns_Utils.C:729
Ioss::ElementTopology::shape
virtual ElementShape shape() const =0
Iocgns::Utils::add_structured_boundary_conditions
static void add_structured_boundary_conditions(int cgnsFilePtr, Ioss::StructuredBlock *block, bool is_parallel_io)
Definition: Iocgns_Utils.C:1435
Iocgns::Utils::map_cgns_face_to_ioss
static void map_cgns_face_to_ioss(const Ioss::ElementTopology *parent_topo, size_t num_to_get, INT *idata)
Definition: Iocgns_Utils.h:87
Iocgns::Utils::assign_zones_to_procs
static void assign_zones_to_procs(std::vector< Iocgns::StructuredZoneData *> &zones, std::vector< size_t > &work_vector)
Definition: Iocgns_Utils.C:1845
Iocgns::Utils::write_flow_solution_metadata
static void write_flow_solution_metadata(int file_ptr, Ioss::Region *region, int state, int *vertex_solution_index, int *cell_center_solution_index, bool is_parallel_io)
Definition: Iocgns_Utils.C:1086
INT
int INT
Definition: Ioss_StructuredBlock.h:53
anonymous_namespace{cth_pressure_map.C}::data
std::vector< char > data
Definition: cth_pressure_map.C:73
Ioss::ElementShape::TET
Ioss::Region
A grouping entity that contains other grouping entities.
Definition: Ioss_Region.h:98
anonymous_namespace{io_info.C}::name
std::string name(Ioss::GroupingEntity *entity)
Definition: io_info.C:88
Iocgns::Utils::set_field_index
static void set_field_index(const Ioss::Field &field, size_t index, CG_GridLocation_t location)
Definition: Iocgns_Utils.C:461
Iocgns::Utils::CG_VERTEX_FIELD_ID
static const size_t CG_VERTEX_FIELD_ID
Definition: Iocgns_Utils.h:75
Ioss::Field
Holds metadata for bulk data associated with a GroupingEntity.
Definition: Ioss_Field.h:47
Ioss_SideBlock.h
Ioss_ElementTopology.h
Iocgns::Utils::pre_split
static size_t pre_split(std::vector< Iocgns::StructuredZoneData *> &zones, double avg_work, double load_balance, int proc_rank, int proc_count)
Definition: Iocgns_Utils.C:1904
Iocgns::Utils::add_sidesets
static void add_sidesets(int cgnsFilePtr, Ioss::DatabaseIO *db)
Definition: Iocgns_Utils.C:1191
Iocgns::Utils::find_solution_index
static int find_solution_index(int cgnsFilePtr, int base, int zone, int step, CG_GridLocation_t location)
Definition: Iocgns_Utils.C:1136
Iocgns::Utils::check_zone_type
static CG_ZoneType_t check_zone_type(int cgnsFilePtr)
Definition: Iocgns_Utils.C:420
Iocgns::Utils
Definition: Iocgns_Utils.h:68