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 // non-Member function -- can't access m_cgnsFilePtr; make sure cgns_file_ptr is passed in...
50 #define CGCHECK(funcall) \
51  if ((funcall) != CG_OK) { \
52  Iocgns::Utils::cgns_error(cgns_file_ptr, __FILE__, __func__, __LINE__, myProcessor); \
53  }
54 
55 // Member function -- can access m_cgnsFilePtr
56 #define CGCHECKM(funcall) \
57  if ((funcall) != CG_OK) { \
58  Iocgns::Utils::cgns_error(m_cgnsFilePtr, __FILE__, __func__, __LINE__, myProcessor); \
59  }
60 
61 #define CGCHECKNP(funcall) \
62  if ((funcall) != CG_OK) { \
63  Iocgns::Utils::cgns_error(cgns_file_ptr, __FILE__, __func__, __LINE__, -1); \
64  }
65 
66 // Used in Iocgns_Decomposition.C
67 #define CGCHECK2(funcall) \
68  if ((funcall) != CG_OK) { \
69  Iocgns::Utils::cgns_error(filePtr, __FILE__, __func__, __LINE__, m_decomposition.m_processor); \
70  }
71 
72 namespace Iocgns {
73  class StructuredZoneData;
74 
75  class Utils
76  {
77  public:
78  Utils() = default;
79  ~Utils() = default;
80 
81  static const size_t CG_CELL_CENTER_FIELD_ID = 1ul << 33;
82  static const size_t CG_VERTEX_FIELD_ID = 1ul << 34;
83 
84  static size_t index(const Ioss::Field &field);
85 
86  static void cgns_error(int cgnsid, const char *file, const char *function, int lineno,
87  int processor);
88 
89  static void update_db_zone_property(int cgns_file_ptr, const Ioss::Region *region,
90  int myProcessor, bool is_parallel, bool is_parallel_io);
91  static int get_db_zone(const Ioss::GroupingEntity *entity);
92  static void set_field_index(const Ioss::Field &field, size_t index, CG_GridLocation_t location);
93  static bool is_cell_field(const Ioss::Field &field);
94 
95  template <typename INT>
96  static void map_cgns_face_to_ioss(const Ioss::ElementTopology *parent_topo, size_t num_to_get,
97  INT *idata)
98  {
99  // The {topo}_map[] arrays map from CGNS face# to IOSS face#.
100  // See http://cgns.github.io/CGNS_docs_current/sids/conv.html#unstructgrid
101  // NOTE: '0' for first entry is to account for 1-based face numbering.
102 
103  switch (parent_topo->shape()) {
105  static int hex_map[] = {0, 5, 1, 2, 3, 4, 6};
106  for (size_t i = 0; i < num_to_get; i++) {
107  idata[2 * i + 1] = hex_map[idata[2 * i + 1]];
108  }
109  break;
110 
112  static int tet_map[] = {0, 4, 1, 2, 3};
113  for (size_t i = 0; i < num_to_get; i++) {
114  idata[2 * i + 1] = tet_map[idata[2 * i + 1]];
115  }
116  break;
117 
119  static int pyr_map[] = {0, 5, 1, 2, 3, 4};
120  for (size_t i = 0; i < num_to_get; i++) {
121  idata[2 * i + 1] = pyr_map[idata[2 * i + 1]];
122  }
123  break;
124 
126 #if 0
127  static int wed_map[] = {0, 1, 2, 3, 4, 5}; // Same
128  // Not needed -- maps 1 to 1
129  for (size_t i=0; i < num_to_get; i++) {
130  idata[2*i+1] = wed_map[idata[2*i+1]];
131  }
132 #endif
133  break;
134  default:;
135  }
136  }
137 
138  static void map_ioss_face_to_cgns(const Ioss::ElementTopology *parent_topo, size_t num_to_get,
139  std::vector<cgsize_t> &data)
140  {
141  // The {topo}_map[] arrays map from CGNS face# to IOSS face#.
142  // See http://cgns.github.io/CGNS_docs_current/sids/conv.html#unstructgrid
143  // NOTE: '0' for first entry is to account for 1-based face numbering.
144 
145  switch (parent_topo->shape()) {
147  static int hex_map[] = {0, 2, 3, 4, 5, 1, 6};
148  for (size_t i = 0; i < num_to_get; i++) {
149  data[num_to_get * 2 + i] = hex_map[data[num_to_get * 2 + i]];
150  }
151  break;
152 
154  static int tet_map[] = {0, 2, 3, 4, 1};
155  for (size_t i = 0; i < num_to_get; i++) {
156  data[num_to_get * 2 + i] = tet_map[data[num_to_get * 2 + i]];
157  }
158  break;
159 
161  static int pyr_map[] = {0, 2, 3, 4, 5, 1};
162  for (size_t i = 0; i < num_to_get; i++) {
163  data[num_to_get * 2 + i] = pyr_map[data[num_to_get * 2 + i]];
164  }
165  break;
166 
168 #if 0
169  static int wed_map[] = {0, 1, 2, 3, 4, 5}; // Same
170  // Not needed -- maps 1 to 1
171  for (size_t i=0; i < num_to_get; i++) {
172  data[num_to_get * 2 + i] = wed_map[data[num_to_get * 2 + i]];
173  }
174 #endif
175  break;
176  default:;
177  }
178  }
179 
180  static void write_flow_solution_metadata(int file_ptr, Ioss::Region *region, int state,
181  int *vertex_solution_index,
182  int *cell_center_solution_index, bool is_parallel_io);
183  static int find_solution_index(int cgns_file_ptr, int base, int zone, int step,
184  CG_GridLocation_t location);
185  static Ioss::MeshType check_mesh_type(int cgns_file_ptr);
186  static size_t common_write_meta_data(int file_ptr, const Ioss::Region &region,
187  std::vector<size_t> &zone_offset, bool is_parallel);
188  static size_t resolve_nodes(Ioss::Region &region, int my_processor, bool is_parallel);
189  static std::vector<std::vector<std::pair<size_t, size_t>>>
190  resolve_processor_shared_nodes(Ioss::Region &region, int my_processor);
191 
192  static CG_ElementType_t map_topology_to_cgns(const std::string &name);
193  static std::string map_cgns_to_topology_type(CG_ElementType_t type);
194  static void add_sidesets(int cgns_file_ptr, Ioss::DatabaseIO *db);
195  static void add_structured_boundary_conditions(int cgns_file_ptr, Ioss::StructuredBlock *block,
196  bool is_parallel_io);
197  static void add_structured_boundary_conditions_fpp(int cgns_file_ptr,
198  Ioss::StructuredBlock *block);
199  static void add_structured_boundary_conditions_pio(int cgns_file_ptr,
200  Ioss::StructuredBlock *block);
201 
202  static void finalize_database(int cgns_file_ptr, const std::vector<double> &timesteps,
203  Ioss::Region *region, int myProcessor, bool is_parallel_io);
204  static int get_step_times(int cgns_file_ptr, std::vector<double> &timesteps,
205  Ioss::Region *region, double timeScaleFactor, int myProcessor);
206  static void add_transient_variables(int cgns_file_ptr, const std::vector<double> &timesteps,
207  Ioss::Region *region, bool enable_field_recognition,
208  char suffix_separator, int myProcessor,
209  bool is_parallel_io);
210 
211  static void set_line_decomposition(int cgns_file_ptr, const std::string &line_decomposition,
212  std::vector<Iocgns::StructuredZoneData *> &zones, int rank,
213  bool verbose);
214  static void decompose_model(std::vector<Iocgns::StructuredZoneData *> &zones, int proc_count,
215  int rank, double load_balance_threshold, bool verbose);
216  static size_t pre_split(std::vector<Iocgns::StructuredZoneData *> &zones, double avg_work,
217  double load_balance, int proc_rank, int proc_count, bool verbose);
218  static void assign_zones_to_procs(std::vector<Iocgns::StructuredZoneData *> &zones,
219  std::vector<size_t> &work_vector, bool verbose);
220  static void show_config();
221  };
222 } // namespace Iocgns
223 
224 #endif
Iocgns::Utils::get_db_zone
static int get_db_zone(const Ioss::GroupingEntity *entity)
Definition: Iocgns_Utils.C:512
Iocgns::Utils::finalize_database
static void finalize_database(int cgns_file_ptr, const std::vector< double > &timesteps, Ioss::Region *region, int myProcessor, bool is_parallel_io)
Definition: Iocgns_Utils.C:1767
Ioss::MeshType
MeshType
The mesh type – structured, unstructured, hybrid (future), or unknown.
Definition: Ioss_MeshType.h:39
Iocgns::Utils::update_db_zone_property
static void update_db_zone_property(int cgns_file_ptr, const Ioss::Region *region, int myProcessor, bool is_parallel, bool is_parallel_io)
Definition: Iocgns_Utils.C:450
Iocgns::Utils::show_config
static void show_config()
Definition: Iocgns_Utils.C:2511
Iocgns::Utils::check_mesh_type
static Ioss::MeshType check_mesh_type(int cgns_file_ptr)
Definition: Iocgns_Utils.C:409
Ioss::Field
Holds metadata for bulk data associated with a GroupingEntity.
Definition: Ioss_Field.h:47
Iocgns::Utils::decompose_model
static void decompose_model(std::vector< Iocgns::StructuredZoneData * > &zones, int proc_count, int rank, double load_balance_threshold, bool verbose)
Definition: Iocgns_Utils.C:2102
Iocgns::Utils::assign_zones_to_procs
static void assign_zones_to_procs(std::vector< Iocgns::StructuredZoneData * > &zones, std::vector< size_t > &work_vector, bool verbose)
Definition: Iocgns_Utils.C:2230
Ioss::ElementShape::PYRAMID
Iocgns::Utils::is_cell_field
static bool is_cell_field(const Ioss::Field &field)
Definition: Iocgns_Utils.C:544
Iocgns::Utils::add_structured_boundary_conditions_fpp
static void add_structured_boundary_conditions_fpp(int cgns_file_ptr, Ioss::StructuredBlock *block)
Definition: Iocgns_Utils.C:1696
Iocgns::Utils::set_line_decomposition
static void set_line_decomposition(int cgns_file_ptr, const std::string &line_decomposition, std::vector< Iocgns::StructuredZoneData * > &zones, int rank, bool verbose)
Definition: Iocgns_Utils.C:1980
Ioss_SideBlock.h
Ioss::Region
A grouping entity that contains other grouping entities.
Definition: Ioss_Region.h:98
Iocgns::Utils::resolve_nodes
static size_t resolve_nodes(Ioss::Region &region, int my_processor, bool is_parallel)
Definition: Iocgns_Utils.C:1436
Ioss::StructuredBlock
A structured zone – i,j,k.
Definition: Ioss_StructuredBlock.h:103
Iocgns::Utils::~Utils
~Utils()=default
INT
int INT
Definition: Ioss_StructuredBlock.h:53
Ioss_StructuredBlock.h
Ioss_SideSet.h
Iocgns::Utils::CG_VERTEX_FIELD_ID
static const size_t CG_VERTEX_FIELD_ID
Definition: Iocgns_Utils.h:82
Iocgns::Utils::Utils
Utils()=default
anonymous_namespace{Iocgns_DecompositionData.C}::rank
int rank
Definition: Iocgns_DecompositionData.C:55
Iocgns::Utils
Definition: Iocgns_Utils.h:75
Iocgns::Utils::get_step_times
static int get_step_times(int cgns_file_ptr, std::vector< double > &timesteps, Ioss::Region *region, double timeScaleFactor, int myProcessor)
Definition: Iocgns_Utils.C:1949
Ioss::DatabaseIO
An input or output Database.
Definition: Ioss_DatabaseIO.h:82
Ioss_Utils.h
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:532
Iocgns::Utils::add_structured_boundary_conditions
static void add_structured_boundary_conditions(int cgns_file_ptr, Ioss::StructuredBlock *block, bool is_parallel_io)
Definition: Iocgns_Utils.C:1617
Iocgns::Utils::map_cgns_to_topology_type
static std::string map_cgns_to_topology_type(CG_ElementType_t type)
Definition: Iocgns_Utils.C:1155
Iocgns::Utils::map_topology_to_cgns
static CG_ElementType_t map_topology_to_cgns(const std::string &name)
Definition: Iocgns_Utils.C:1186
Ioss::ElementShape::WEDGE
Iocgns::Utils::add_transient_variables
static void add_transient_variables(int cgns_file_ptr, 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:1858
Ioss::ElementTopology::shape
virtual ElementShape shape() const =0
Ioss::ElementTopology
Represents an element topology.
Definition: Ioss_ElementTopology.h:72
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:1259
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:826
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:1553
Iocgns::Utils::CG_CELL_CENTER_FIELD_ID
static const size_t CG_CELL_CENTER_FIELD_ID
Definition: Iocgns_Utils.h:81
anonymous_namespace{cth_pressure_map.C}::data
std::vector< char > data
Definition: cth_pressure_map.C:74
Iocgns::Utils::cgns_error
static void cgns_error(int cgnsid, const char *file, const char *function, int lineno, int processor)
Definition: Iocgns_Utils.C:387
Iocgns::Utils::index
static size_t index(const Ioss::Field &field)
Definition: Iocgns_Utils.C:530
Ioss::ElementShape::TET
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:96
Ioss_Region.h
anonymous_namespace{io_info.C}::name
std::string name(const Ioss::GroupingEntity *entity)
Definition: io_info.C:89
Ioss::ElementShape::HEX
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, bool verbose)
Definition: Iocgns_Utils.C:2302
Iocgns
A namespace for the CGNS database format.
Definition: Iocgns_DatabaseIO.C:444
Iocgns::Utils::add_sidesets
static void add_sidesets(int cgns_file_ptr, Ioss::DatabaseIO *db)
Definition: Iocgns_Utils.C:1371
Iocgns::Utils::find_solution_index
static int find_solution_index(int cgns_file_ptr, int base, int zone, int step, CG_GridLocation_t location)
Definition: Iocgns_Utils.C:1309
Ioss::GroupingEntity
Base class for all 'grouping' entities. The following derived classes are typical:
Definition: Ioss_GroupingEntity.h:93
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:138
Iocgns::Utils::add_structured_boundary_conditions_pio
static void add_structured_boundary_conditions_pio(int cgns_file_ptr, Ioss::StructuredBlock *block)
Definition: Iocgns_Utils.C:1631
Ioss_ElementTopology.h
Ioss_DatabaseIO.h