| 1 |
// Copyright(C) 1999-2024 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 |
// See packages/seacas/LICENSE for details |
| 6 |
|
| 7 |
#pragma once |
| 8 |
|
| 9 |
#include "Ioss_BoundingBox.h" |
| 10 |
#include "Ioss_CodeTypes.h" |
| 11 |
#include "Ioss_EntityBlock.h" |
| 12 |
#include "Ioss_NodeBlock.h" |
| 13 |
#include "Ioss_Property.h" |
| 14 |
#include "Ioss_ZoneConnectivity.h" |
| 15 |
#include <array> |
| 16 |
#include <cassert> |
| 17 |
#include <iosfwd> |
| 18 |
#include <stddef.h> |
| 19 |
#include <stdint.h> |
| 20 |
#include <string> |
| 21 |
#include <vector> |
| 22 |
|
| 23 |
#include "Ioss_EntityType.h" |
| 24 |
#include "ioss_export.h" |
| 25 |
|
| 26 |
namespace Ioss { |
| 27 |
class Region; |
| 28 |
class Field; |
| 29 |
|
| 30 |
struct IOSS_EXPORT BoundaryCondition |
| 31 |
{ |
| 32 |
BoundaryCondition(std::string name, std::string fam_name, Ioss::IJK_t range_beg, |
| 33 |
Ioss::IJK_t range_end) |
| 34 |
: m_bcName(std::move(name)), m_famName(std::move(fam_name)), m_rangeBeg(range_beg), |
| 35 |
m_rangeEnd(range_end) |
| 36 |
{ |
| 37 |
} |
| 38 |
|
| 39 |
// Deprecated... Use the constructor above with both name and fam_name |
| 40 |
BoundaryCondition(std::string name, Ioss::IJK_t range_beg, Ioss::IJK_t range_end) |
| 41 |
: m_bcName(name), m_famName(std::move(name)), m_rangeBeg(range_beg), m_rangeEnd(range_end) |
| 42 |
{ |
| 43 |
} |
| 44 |
|
| 45 |
// cereal requires a default constructor when de-serializing vectors of objects. Because |
| 46 |
// StructuredBlock contains a vector of BoundaryCondition objects, this default constructor is |
| 47 |
// necessary. |
| 48 |
BoundaryCondition() = default; |
| 49 |
|
| 50 |
BoundaryCondition(const BoundaryCondition ©_from) = default; |
| 51 |
BoundaryCondition &operator=(const BoundaryCondition ©_from) = default; |
| 52 |
|
| 53 |
// Determine which "face" of the parent block this BC is applied to. |
| 54 |
IOSS_NODISCARD int which_face() const; |
| 55 |
|
| 56 |
// Does range specify a valid face |
| 57 |
IOSS_NODISCARD bool is_valid() const; |
| 58 |
|
| 59 |
// Return number of cell faces in the BC |
| 60 |
IOSS_NODISCARD size_t get_face_count() const; |
| 61 |
|
| 62 |
IOSS_NODISCARD bool operator==(const Ioss::BoundaryCondition &rhs) const; |
| 63 |
IOSS_NODISCARD bool operator!=(const Ioss::BoundaryCondition &rhs) const; |
| 64 |
IOSS_NODISCARD bool equal(const Ioss::BoundaryCondition &rhs) const; |
| 65 |
|
| 66 |
std::string m_bcName{}; |
| 67 |
std::string m_famName{}; |
| 68 |
|
| 69 |
// These are potentially subsetted due to parallel decompositions... |
| 70 |
Ioss::IJK_t m_rangeBeg{}; |
| 71 |
Ioss::IJK_t m_rangeEnd{}; |
| 72 |
|
| 73 |
mutable int m_face{-1}; |
| 74 |
|
| 75 |
template <class Archive> void serialize(Archive &archive) |
| 76 |
{ |
| 77 |
archive(m_bcName, m_famName, m_rangeBeg, m_rangeEnd, m_face); |
| 78 |
} |
| 79 |
|
| 80 |
private: |
| 81 |
bool equal_(const Ioss::BoundaryCondition &rhs, bool quiet) const; |
| 82 |
}; |
| 83 |
|
| 84 |
IOSS_EXPORT std::ostream &operator<<(std::ostream &os, const BoundaryCondition &bc); |
| 85 |
|
| 86 |
class DatabaseIO; |
| 87 |
|
| 88 |
/** \brief A structured zone -- i,j,k |
| 89 |
*/ |
| 90 |
class IOSS_EXPORT StructuredBlock : public EntityBlock |
| 91 |
{ |
| 92 |
public: |
| 93 |
StructuredBlock(DatabaseIO *io_database, const std::string &my_name, int index_dim, int ni, |
| 94 |
int nj, int nk, int off_i, int off_j, int off_k, int glo_ni, int glo_nj, |
| 95 |
int glo_nk); |
| 96 |
StructuredBlock(DatabaseIO *io_database, const std::string &my_name, int index_dim, |
| 97 |
const Ioss::IJK_t &ordinal, const Ioss::IJK_t &offset, |
| 98 |
const Ioss::IJK_t &global_ordinal); |
| 99 |
|
| 100 |
// Useful for serial |
| 101 |
StructuredBlock(DatabaseIO *io_database, const std::string &my_name, int index_dim, int ni, |
| 102 |
int nj, int nk); |
| 103 |
StructuredBlock(DatabaseIO *io_database, const std::string &my_name, int index_dim, |
| 104 |
Ioss::IJK_t &ordinal); |
| 105 |
|
| 106 |
StructuredBlock *clone(DatabaseIO *database) const; |
| 107 |
|
| 108 |
IOSS_NODISCARD std::string type_string() const override { return "StructuredBlock"; } |
| 109 |
IOSS_NODISCARD std::string short_type_string() const override { return "structuredblock"; } |
| 110 |
IOSS_NODISCARD std::string contains_string() const override { return "Cell"; } |
| 111 |
IOSS_NODISCARD EntityType type() const override { return STRUCTUREDBLOCK; } |
| 112 |
|
| 113 |
IOSS_NODISCARD const Ioss::NodeBlock &get_node_block() const { return m_nodeBlock; } |
| 114 |
IOSS_NODISCARD Ioss::NodeBlock &get_node_block() { return m_nodeBlock; } |
| 115 |
|
| 116 |
/** \brief Does block contain any cells |
| 117 |
*/ |
| 118 |
IOSS_NODISCARD bool is_active() const { return m_ijk[0] * m_ijk[1] * m_ijk[2] > 0; } |
| 119 |
|
| 120 |
// Handle implicit properties -- These are calculated from data stored |
| 121 |
// in the grouping entity instead of having an explicit value assigned. |
| 122 |
// An example would be 'element_block_count' for a region. |
| 123 |
IOSS_NODISCARD Property get_implicit_property(const std::string &my_name) const override; |
| 124 |
|
| 125 |
IOSS_NODISCARD AxisAlignedBoundingBox get_bounding_box() const; |
| 126 |
|
| 127 |
/** \brief Set the 'offset' for the block. |
| 128 |
* |
| 129 |
* The 'offset' is used to map a cell or node location within a |
| 130 |
* structured block to the model implicit cell or node location |
| 131 |
* on a single processor. zero-based. |
| 132 |
* |
| 133 |
* The 'global' offsets do the same except for they apply over |
| 134 |
* the entire model on all processors. zero-based. |
| 135 |
* |
| 136 |
* For example, the file descriptor (1-based) of |
| 137 |
* the 37th cell in the 4th block is calculated by: |
| 138 |
* |
| 139 |
* file_descriptor = offset of block 4 + 37 |
| 140 |
* |
| 141 |
* This can also be used to determine which structured block |
| 142 |
* a cell with a file_descriptor maps into. An particular |
| 143 |
* structured block contains all cells in the range: |
| 144 |
* |
| 145 |
* offset < file_descriptor <= offset+number_cells_per_block |
| 146 |
* |
| 147 |
* Note that for nodes, the nodeOffset does not take into account |
| 148 |
* the nodes that are shared between blocks. |
| 149 |
*/ |
| 150 |
void set_node_offset(size_t offset) { m_nodeOffset = offset; } |
| 151 |
void set_cell_offset(size_t offset) { m_cellOffset = offset; } |
| 152 |
void set_node_global_offset(size_t offset) { m_nodeGlobalOffset = offset; } |
| 153 |
void set_cell_global_offset(size_t offset) { m_cellGlobalOffset = offset; } |
| 154 |
|
| 155 |
IOSS_NODISCARD size_t get_node_offset() const { return m_nodeOffset; } |
| 156 |
IOSS_NODISCARD size_t get_cell_offset() const { return m_cellOffset; } |
| 157 |
IOSS_NODISCARD size_t get_node_global_offset() const { return m_nodeGlobalOffset; } |
| 158 |
IOSS_NODISCARD size_t get_cell_global_offset() const { return m_cellGlobalOffset; } |
| 159 |
|
| 160 |
void set_ijk_offset(int axis, size_t offset); |
| 161 |
void set_ijk_global(int axis, size_t global); |
| 162 |
|
| 163 |
void set_ijk_offset(const IJK_t &offset); |
| 164 |
void set_ijk_global(const IJK_t &global); |
| 165 |
|
| 166 |
IOSS_NODISCARD IJK_t get_ijk_offset() const { return m_offset; } |
| 167 |
IOSS_NODISCARD IJK_t get_ijk_local() const { return m_ijk; } |
| 168 |
IOSS_NODISCARD IJK_t get_ijk_global() const { return m_ijkGlobal; } |
| 169 |
|
| 170 |
// Get the global (over all processors) cell |
| 171 |
// id at the specified i,j,k location (1 <= i,j,k <= ni,nj,nk). 1-based. |
| 172 |
IOSS_NODISCARD size_t get_global_cell_id(int i, int j, int k) const |
| 173 |
{ |
| 174 |
return m_cellGlobalOffset + static_cast<size_t>(k - 1) * m_ijkGlobal[0] * m_ijkGlobal[1] + |
| 175 |
static_cast<size_t>(j - 1) * m_ijkGlobal[0] + i; |
| 176 |
} |
| 177 |
|
| 178 |
IOSS_NODISCARD size_t get_global_cell_id(IJK_t index) const |
| 179 |
{ |
| 180 |
return get_global_cell_id(index[0], index[1], index[2]); |
| 181 |
} |
| 182 |
|
| 183 |
// Get the global (over all processors) node |
| 184 |
// offset at the specified i,j,k location (1 <= i,j,k <= ni,nj,nk). 0-based, does not account |
| 185 |
// for shared nodes. |
| 186 |
IOSS_NODISCARD size_t get_global_node_offset(int i, int j, int k) const |
| 187 |
{ |
| 188 |
return m_nodeGlobalOffset + |
| 189 |
static_cast<size_t>(k - 1) * (m_ijkGlobal[0] + 1) * (m_ijkGlobal[1] + 1) + |
| 190 |
static_cast<size_t>(j - 1) * (m_ijkGlobal[0] + 1) + i - 1; |
| 191 |
} |
| 192 |
|
| 193 |
IOSS_NODISCARD size_t get_global_node_offset(IJK_t index) const |
| 194 |
{ |
| 195 |
return get_global_node_offset(index[0], index[1], index[2]); |
| 196 |
} |
| 197 |
|
| 198 |
// Get the local (relative to this block on this processor) node id at the specified |
| 199 |
// i,j,k location (1 <= i,j,k <= ni+1,nj+1,nk+1). 0-based. |
| 200 |
IOSS_NODISCARD size_t get_block_local_node_offset(int ii, int jj, int kk) const |
| 201 |
{ |
| 202 |
auto i = ii - m_offset[0]; |
| 203 |
auto j = jj - m_offset[1]; |
| 204 |
auto k = kk - m_offset[2]; |
| 205 |
assert(i > 0 && i <= m_ijk[0] + 1 && j > 0 && j <= m_ijk[1] + 1 && k > 0 && |
| 206 |
k <= m_ijk[2] + 1); |
| 207 |
return static_cast<size_t>(k - 1) * (m_ijk[0] + 1) * (m_ijk[1] + 1) + |
| 208 |
static_cast<size_t>(j - 1) * (m_ijk[0] + 1) + i - 1; |
| 209 |
} |
| 210 |
|
| 211 |
IOSS_NODISCARD size_t get_block_local_node_offset(IJK_t index) const |
| 212 |
{ |
| 213 |
return get_block_local_node_offset(index[0], index[1], index[2]); |
| 214 |
} |
| 215 |
|
| 216 |
// Get the local (on this processor) cell-node offset at the specified |
| 217 |
// i,j,k location (1 <= i,j,k <= ni+1,nj+1,nk+1). 0-based. |
| 218 |
IOSS_NODISCARD size_t get_local_node_offset(int i, int j, int k) const |
| 219 |
{ |
| 220 |
return get_block_local_node_offset(i, j, k) + m_nodeOffset; |
| 221 |
} |
| 222 |
|
| 223 |
IOSS_NODISCARD size_t get_local_node_offset(IJK_t index) const |
| 224 |
{ |
| 225 |
return get_local_node_offset(index[0], index[1], index[2]); |
| 226 |
} |
| 227 |
|
| 228 |
template <typename INT_t> size_t get_cell_node_ids(INT_t *idata, bool add_offset) const |
| 229 |
{ |
| 230 |
// Fill 'idata' with the cell node ids which are the |
| 231 |
// 1-based location of each node in this zone |
| 232 |
// The location is based on the "model" (all processors) zone. |
| 233 |
// If this is a parallel decomposed model, then |
| 234 |
// this block may be a subset of the "model" zone |
| 235 |
// |
| 236 |
// if 'add_offset' is true, then add the m_cellGlobalOffset |
| 237 |
// which changes the location to be the location in the |
| 238 |
// entire "mesh" instead of within a "zone" (all processors) |
| 239 |
|
| 240 |
size_t index = 0; |
| 241 |
size_t offset = add_offset ? m_nodeGlobalOffset : 0; |
| 242 |
|
| 243 |
if (m_ijk[2] == 0 && m_ijk[1] == 0 && m_ijk[0] == 0) { |
| 244 |
return index; |
| 245 |
} |
| 246 |
|
| 247 |
for (int kk = 0; kk < m_ijk[2] + 1; kk++) { |
| 248 |
size_t k = m_offset[2] + kk; |
| 249 |
for (int jj = 0; jj < m_ijk[1] + 1; jj++) { |
| 250 |
size_t j = m_offset[1] + jj; |
| 251 |
for (int ii = 0; ii < m_ijk[0] + 1; ii++) { |
| 252 |
size_t i = m_offset[0] + ii; |
| 253 |
|
| 254 |
size_t ind = |
| 255 |
k * (m_ijkGlobal[0] + 1) * (m_ijkGlobal[1] + 1) + j * (m_ijkGlobal[0] + 1) + i; |
| 256 |
|
| 257 |
idata[index++] = ind + offset + 1; |
| 258 |
} |
| 259 |
} |
| 260 |
} |
| 261 |
|
| 262 |
for (const auto &idx_id : m_globalIdMap) { |
| 263 |
idata[idx_id.first] = idx_id.second; |
| 264 |
} |
| 265 |
|
| 266 |
return index; |
| 267 |
} |
| 268 |
|
| 269 |
template <typename INT_t> size_t get_cell_ids(INT_t *idata, bool add_offset) const |
| 270 |
{ |
| 271 |
// Fill 'idata' with the cell ids which are the |
| 272 |
// 1-based location of each cell in this zone |
| 273 |
// The location is based on the "model" zone. |
| 274 |
// If this is a parallel decomposed model, then |
| 275 |
// this block may be a subset of the "model" zone |
| 276 |
// |
| 277 |
// if 'add_offset' is true, then add the m_cellGlobalOffset |
| 278 |
// which changes the location to be the location in the |
| 279 |
// entire "mesh" instead of within a "zone" |
| 280 |
|
| 281 |
size_t index = 0; |
| 282 |
size_t offset = add_offset ? m_cellGlobalOffset : 0; |
| 283 |
|
| 284 |
if (m_ijk[2] == 0 && m_ijk[1] == 0 && m_ijk[0] == 0) { |
| 285 |
return index; |
| 286 |
} |
| 287 |
|
| 288 |
for (int kk = 0; kk < m_ijk[2]; kk++) { |
| 289 |
size_t k = m_offset[2] + kk; |
| 290 |
for (int jj = 0; jj < m_ijk[1]; jj++) { |
| 291 |
size_t j = m_offset[1] + jj; |
| 292 |
for (int ii = 0; ii < m_ijk[0]; ii++) { |
| 293 |
size_t i = m_offset[0] + ii; |
| 294 |
|
| 295 |
size_t ind = k * m_ijkGlobal[0] * m_ijkGlobal[1] + j * m_ijkGlobal[0] + i; |
| 296 |
|
| 297 |
idata[index++] = ind + offset + 1; |
| 298 |
} |
| 299 |
} |
| 300 |
} |
| 301 |
return index; |
| 302 |
} |
| 303 |
|
| 304 |
IOSS_NODISCARD bool contains_node(size_t global_offset) const |
| 305 |
{ |
| 306 |
return (global_offset >= m_nodeOffset && |
| 307 |
global_offset < m_nodeOffset + get_property("node_count").get_int()); |
| 308 |
} |
| 309 |
|
| 310 |
/* COMPARE two StructuredBlocks */ |
| 311 |
IOSS_NODISCARD bool operator==(const Ioss::StructuredBlock &rhs) const; |
| 312 |
IOSS_NODISCARD bool operator!=(const Ioss::StructuredBlock &rhs) const; |
| 313 |
IOSS_NODISCARD bool equal(const Ioss::StructuredBlock &rhs) const; |
| 314 |
|
| 315 |
protected: |
| 316 |
int64_t internal_get_field_data(const Field &field, void *data, |
| 317 |
size_t data_size) const override; |
| 318 |
|
| 319 |
int64_t internal_put_field_data(const Field &field, void *data, |
| 320 |
size_t data_size) const override; |
| 321 |
|
| 322 |
int64_t internal_get_zc_field_data(const Field &field, void **data, |
| 323 |
size_t *data_size) const override; |
| 324 |
|
| 325 |
private: |
| 326 |
bool equal_(const Ioss::StructuredBlock &rhs, bool quiet) const; |
| 327 |
IJK_t m_ijk; |
| 328 |
IJK_t m_offset; // Valid 'i' ordinal runs from m_offset[i]+1 to m_offset[i]+m_ijk[i] |
| 329 |
IJK_t m_ijkGlobal; // The ni,nj,nk of the master block this is a subset of. |
| 330 |
|
| 331 |
size_t m_nodeOffset{}; |
| 332 |
size_t m_cellOffset{}; |
| 333 |
|
| 334 |
size_t m_nodeGlobalOffset{}; |
| 335 |
size_t m_cellGlobalOffset{}; |
| 336 |
|
| 337 |
Ioss::NodeBlock m_nodeBlock; |
| 338 |
|
| 339 |
public: |
| 340 |
std::vector<ZoneConnectivity> m_zoneConnectivity; |
| 341 |
std::vector<BoundaryCondition> m_boundaryConditions; |
| 342 |
std::vector<size_t> m_blockLocalNodeIndex; |
| 343 |
std::vector<std::pair<size_t, size_t>> m_globalIdMap; |
| 344 |
|
| 345 |
template <class Archive> void serialize(Archive &archive) |
| 346 |
{ |
| 347 |
archive(m_zoneConnectivity, m_boundaryConditions, m_blockLocalNodeIndex, m_globalIdMap); |
| 348 |
} |
| 349 |
}; |
| 350 |
} // namespace Ioss |