| 1 |
/* |
| 2 |
* Copyright(C) 1999-2022, 2024 National Technology & Engineering Solutions |
| 3 |
* of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with |
| 4 |
* NTESS, the U.S. Government retains certain rights in this software. |
| 5 |
* |
| 6 |
* See packages/seacas/LICENSE for details |
| 7 |
*/ |
| 8 |
#pragma once |
| 9 |
|
| 10 |
#include "iocgns_export.h" |
| 11 |
|
| 12 |
#include <cgnsconfig.h> |
| 13 |
#if CG_BUILD_PARALLEL |
| 14 |
|
| 15 |
#include <string> |
| 16 |
#include <vector> |
| 17 |
|
| 18 |
#define CG_USE_ROBIN |
| 19 |
#if defined CG_USE_STD |
| 20 |
#include <unordered_map> |
| 21 |
#elif defined CG_USE_HOPSCOTCH |
| 22 |
#include <bhopscotch_map.h> |
| 23 |
#elif defined CG_USE_ROBIN |
| 24 |
#include <robin_map.h> |
| 25 |
#endif |
| 26 |
|
| 27 |
#include <cstddef> |
| 28 |
#include <cstdint> |
| 29 |
|
| 30 |
#include "Ioss_CodeTypes.h" |
| 31 |
#include "Ioss_Decomposition.h" |
| 32 |
#include "Ioss_FaceGenerator.h" |
| 33 |
#include "Ioss_Field.h" |
| 34 |
#include "Ioss_MeshType.h" |
| 35 |
#include "Ioss_PropertyManager.h" |
| 36 |
#include "Ioss_StructuredBlock.h" |
| 37 |
#include "cgns/Iocgns_StructuredZoneData.h" |
| 38 |
|
| 39 |
#include <cgnslib.h> |
| 40 |
|
| 41 |
#if 0 |
| 42 |
#if !defined(NO_PARMETIS_SUPPORT) |
| 43 |
#include <parmetis.h> |
| 44 |
#endif |
| 45 |
#endif |
| 46 |
|
| 47 |
#undef MPICPP |
| 48 |
#if !defined(NO_ZOLTAN_SUPPORT) |
| 49 |
#include <zoltan_cpp.h> |
| 50 |
#endif |
| 51 |
namespace Ioss { |
| 52 |
class Field; |
| 53 |
template <typename INT> class Decomposition; |
| 54 |
} // namespace Ioss |
| 55 |
|
| 56 |
namespace Iocgns { |
| 57 |
|
| 58 |
class IOCGNS_EXPORT ZoneData |
| 59 |
{ |
| 60 |
public: |
| 61 |
std::string m_name; |
| 62 |
size_t m_nodeOffset; |
| 63 |
size_t m_nodeCount; |
| 64 |
size_t m_elementOffset; |
| 65 |
}; |
| 66 |
|
| 67 |
class IOCGNS_EXPORT DecompositionDataBase |
| 68 |
{ |
| 69 |
public: |
| 70 |
DecompositionDataBase() = default; |
| 71 |
|
| 72 |
virtual ~DecompositionDataBase(); |
| 73 |
virtual void decompose_model(int filePtr, Ioss::MeshType mesh_type) = 0; |
| 74 |
IOSS_NODISCARD virtual size_t ioss_node_count() const = 0; |
| 75 |
IOSS_NODISCARD virtual size_t ioss_elem_count() const = 0; |
| 76 |
IOSS_NODISCARD virtual int int_size() const = 0; |
| 77 |
|
| 78 |
IOSS_NODISCARD virtual int spatial_dimension() const = 0; |
| 79 |
IOSS_NODISCARD virtual size_t global_node_count() const = 0; |
| 80 |
IOSS_NODISCARD virtual size_t global_elem_count() const = 0; |
| 81 |
|
| 82 |
IOSS_NODISCARD virtual size_t decomp_node_offset() const = 0; |
| 83 |
IOSS_NODISCARD virtual size_t decomp_node_count() const = 0; |
| 84 |
IOSS_NODISCARD virtual size_t decomp_elem_offset() const = 0; |
| 85 |
IOSS_NODISCARD virtual size_t decomp_elem_count() const = 0; |
| 86 |
|
| 87 |
IOSS_NODISCARD virtual std::vector<double> ¢roids() = 0; |
| 88 |
|
| 89 |
IOSS_NODISCARD virtual size_t get_commset_node_size() const = 0; |
| 90 |
|
| 91 |
virtual void get_node_coordinates(int filePtr, double *ioss_data, |
| 92 |
const Ioss::Field &field) const = 0; |
| 93 |
|
| 94 |
void get_block_connectivity(int filePtr, void *data, int blk_seq, bool raw_ids = false) const; |
| 95 |
|
| 96 |
void get_element_field(int filePtr, int solution_index, int blk_seq, int field_index, |
| 97 |
double *data) const; |
| 98 |
|
| 99 |
void get_node_field(int filePtr, int step, int field_index, double *data) const; |
| 100 |
|
| 101 |
void get_node_entity_proc_data(void *entity_proc, const Ioss::MapContainer &node_map, |
| 102 |
bool do_map) const; |
| 103 |
|
| 104 |
template <typename T> |
| 105 |
void communicate_element_data(T *file_data, T *ioss_data, size_t comp_count) const; |
| 106 |
|
| 107 |
template <typename T> |
| 108 |
void communicate_node_data(T *file_data, T *ioss_data, size_t comp_count) const; |
| 109 |
|
| 110 |
void get_sideset_element_side(int filePtr, const Ioss::SetDecompositionData &sset, |
| 111 |
void *data) const; |
| 112 |
|
| 113 |
std::vector<ZoneData> m_zones; |
| 114 |
std::vector<Ioss::BlockDecompositionData> m_elementBlocks; |
| 115 |
std::vector<Ioss::SetDecompositionData> m_sideSets; |
| 116 |
std::vector<Iocgns::StructuredZoneData *> m_structuredZones; |
| 117 |
|
| 118 |
// Maps nodes shared between zones. |
| 119 |
// TODO: Currently each processor has same map; need to figure out how to reduce size |
| 120 |
#if defined CG_USE_STD |
| 121 |
using ZoneSharedMap = std::unordered_map<cgsize_t, cgsize_t>; |
| 122 |
#elif defined CG_USE_HOPSCOTCH |
| 123 |
// using ZoneSharedMap = tsl::hopscotch_map<cgsize_t, cgsize_t>; |
| 124 |
using ZoneSharedMap = tsl::bhopscotch_map<cgsize_t, cgsize_t>; |
| 125 |
#elif defined CG_USE_ROBIN |
| 126 |
using ZoneSharedMap = tsl::robin_map<cgsize_t, cgsize_t>; |
| 127 |
#endif |
| 128 |
ZoneSharedMap m_zoneSharedMap; |
| 129 |
}; |
| 130 |
|
| 131 |
template <typename INT> class DecompositionData : public DecompositionDataBase |
| 132 |
{ |
| 133 |
public: |
| 134 |
DecompositionData(const Ioss::PropertyManager &props, Ioss_MPI_Comm communicator); |
| 135 |
~DecompositionData() override = default; |
| 136 |
|
| 137 |
IOSS_NODISCARD int int_size() const override { return sizeof(INT); } |
| 138 |
|
| 139 |
void decompose_model(int filePtr, Ioss::MeshType mesh_type) override; |
| 140 |
|
| 141 |
IOSS_NODISCARD int spatial_dimension() const override |
| 142 |
{ |
| 143 |
return m_decomposition.m_spatialDimension; |
| 144 |
} |
| 145 |
|
| 146 |
IOSS_NODISCARD size_t global_node_count() const override |
| 147 |
{ |
| 148 |
return m_decomposition.global_node_count(); |
| 149 |
} |
| 150 |
IOSS_NODISCARD size_t global_elem_count() const override |
| 151 |
{ |
| 152 |
return m_decomposition.global_elem_count(); |
| 153 |
} |
| 154 |
|
| 155 |
IOSS_NODISCARD size_t ioss_node_count() const override |
| 156 |
{ |
| 157 |
return m_decomposition.ioss_node_count(); |
| 158 |
} |
| 159 |
IOSS_NODISCARD size_t ioss_elem_count() const override |
| 160 |
{ |
| 161 |
return m_decomposition.ioss_elem_count(); |
| 162 |
} |
| 163 |
|
| 164 |
IOSS_NODISCARD size_t decomp_node_offset() const override |
| 165 |
{ |
| 166 |
return m_decomposition.file_node_offset(); |
| 167 |
} |
| 168 |
IOSS_NODISCARD size_t decomp_node_count() const override |
| 169 |
{ |
| 170 |
return m_decomposition.file_node_count(); |
| 171 |
} |
| 172 |
IOSS_NODISCARD size_t decomp_elem_offset() const override |
| 173 |
{ |
| 174 |
return m_decomposition.file_elem_offset(); |
| 175 |
} |
| 176 |
IOSS_NODISCARD size_t decomp_elem_count() const override |
| 177 |
{ |
| 178 |
return m_decomposition.file_elem_count(); |
| 179 |
} |
| 180 |
|
| 181 |
IOSS_NODISCARD std::vector<double> ¢roids() override { return m_decomposition.m_centroids; } |
| 182 |
|
| 183 |
template <typename T> |
| 184 |
void communicate_element_data(T *file_data, T *ioss_data, size_t comp_count) const |
| 185 |
{ |
| 186 |
m_decomposition.communicate_element_data(file_data, ioss_data, comp_count); |
| 187 |
} |
| 188 |
|
| 189 |
template <typename T> |
| 190 |
void communicate_set_data(T *file_data, T *ioss_data, const Ioss::SetDecompositionData &set, |
| 191 |
size_t comp_count) const |
| 192 |
{ |
| 193 |
m_decomposition.communicate_set_data(file_data, ioss_data, set, comp_count); |
| 194 |
} |
| 195 |
|
| 196 |
template <typename T> |
| 197 |
void communicate_node_data(T *file_data, T *ioss_data, size_t comp_count) const |
| 198 |
{ |
| 199 |
m_decomposition.communicate_node_data(file_data, ioss_data, comp_count); |
| 200 |
} |
| 201 |
|
| 202 |
template <typename U, typename T> |
| 203 |
void communicate_block_data(U *file_data, T *ioss_data, |
| 204 |
const Ioss::BlockDecompositionData &block, size_t comp_count) const |
| 205 |
{ |
| 206 |
m_decomposition.communicate_block_data(file_data, ioss_data, block, comp_count); |
| 207 |
} |
| 208 |
|
| 209 |
void get_block_connectivity(int filePtr, INT *data, int blk_seq, bool raw_ids) const; |
| 210 |
|
| 211 |
void get_element_field(int filePtr, int solution_index, int blk_seq, int field_index, |
| 212 |
double *data) const; |
| 213 |
|
| 214 |
void get_node_field(int filePtr, int step, int field_offset, double *data) const; |
| 215 |
|
| 216 |
IOSS_NODISCARD size_t get_commset_node_size() const override |
| 217 |
{ |
| 218 |
return m_decomposition.m_nodeCommMap.size() / 2; |
| 219 |
} |
| 220 |
|
| 221 |
void get_sideset_element_side(int filePtr, const Ioss::SetDecompositionData &sset, |
| 222 |
INT *data) const; |
| 223 |
|
| 224 |
private: |
| 225 |
void decompose_structured(int filePtr); |
| 226 |
void decompose_unstructured(int filePtr); |
| 227 |
|
| 228 |
void get_sideset_data(int filePtr); |
| 229 |
void generate_zone_shared_nodes(int filePtr, INT min_node, INT max_node); |
| 230 |
|
| 231 |
IOSS_NODISCARD bool i_own_node(size_t node) |
| 232 |
const // T/F if node with global index node owned by this processors ioss-decomp. |
| 233 |
{ |
| 234 |
return m_decomposition.i_own_node(node); |
| 235 |
} |
| 236 |
|
| 237 |
IOSS_NODISCARD bool i_own_elem(size_t elem) |
| 238 |
const // T/F if node with global index elem owned by this processors ioss-decomp. |
| 239 |
{ |
| 240 |
return m_decomposition.i_own_elem(elem); |
| 241 |
} |
| 242 |
|
| 243 |
// global_index is 1-based index into global list of nodes [1..global_node_count] |
| 244 |
// return value is 1-based index into local list of nodes on this |
| 245 |
// processor (ioss-decomposition) |
| 246 |
IOSS_NODISCARD size_t node_global_to_local(size_t global_index) const |
| 247 |
{ |
| 248 |
return m_decomposition.node_global_to_local(global_index); |
| 249 |
} |
| 250 |
|
| 251 |
IOSS_NODISCARD size_t elem_global_to_local(size_t global_index) const |
| 252 |
{ |
| 253 |
return m_decomposition.elem_global_to_local(global_index); |
| 254 |
} |
| 255 |
|
| 256 |
void build_global_to_local_elem_map() |
| 257 |
{ |
| 258 |
return m_decomposition.build_global_to_local_elem_map(); |
| 259 |
} |
| 260 |
|
| 261 |
void get_element_block_communication() |
| 262 |
{ |
| 263 |
m_decomposition.get_element_block_communication(m_elementBlocks); |
| 264 |
} |
| 265 |
|
| 266 |
void generate_adjacency_list(int filePtr, Ioss::Decomposition<INT> &decomposition); |
| 267 |
|
| 268 |
void calculate_element_centroids(int filePtr, std::vector<double> ¢roids); |
| 269 |
|
| 270 |
void get_shared_node_list() { m_decomposition.get_shared_node_list(); } |
| 271 |
|
| 272 |
void get_local_node_list() { m_decomposition.get_local_node_list(); } |
| 273 |
|
| 274 |
void get_file_node_coordinates(int filePtr, int direction, double *ioss_data) const; |
| 275 |
void get_node_coordinates(int filePtr, double *ioss_data, |
| 276 |
const Ioss::Field &field) const override; |
| 277 |
|
| 278 |
double m_loadBalanceThreshold{1.4}; |
| 279 |
std::string m_lineDecomposition{}; |
| 280 |
|
| 281 |
mutable std::map<int, Ioss::FaceUnorderedSet> m_boundaryFaces; |
| 282 |
|
| 283 |
public: |
| 284 |
Ioss::Decomposition<INT> m_decomposition; |
| 285 |
}; |
| 286 |
|
| 287 |
} // namespace Iocgns |
| 288 |
#endif |