IOSS  2.0
Ioss_StructuredBlock.h
Go to the documentation of this file.
1 // Copyright(C) 1999-2020 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 #ifndef IOSS_Ioss_StructuredBlock_h
8 #define IOSS_Ioss_StructuredBlock_h
9 
10 #include <Ioss_BoundingBox.h>
11 #include <Ioss_CodeTypes.h>
12 #include <Ioss_EntityBlock.h>
13 #include <Ioss_NodeBlock.h>
14 #include <Ioss_Property.h>
15 #include <Ioss_ZoneConnectivity.h>
16 #include <array>
17 #include <cassert>
18 #include <string>
19 
20 #if defined(SEACAS_HAVE_CGNS) && !defined(BUILT_IN_SIERRA)
21 #include <cgnstypes.h>
22 using INT = cgsize_t;
23 #else
24 // If this is not being built with CGNS, then default to using 32-bit integers.
25 // Currently there is no way to input/output a structured mesh without CGNS,
26 // so this block is simply to get things to compile and probably has no use.
27 using INT = int;
28 #endif
29 
30 namespace Ioss {
31  class Region;
32 
34  {
35  BoundaryCondition(const std::string name, const std::string fam_name,
36  const Ioss::IJK_t range_beg, const Ioss::IJK_t range_end)
37  : m_bcName(std::move(name)), m_famName(std::move(fam_name)),
38  m_rangeBeg(std::move(range_beg)), m_rangeEnd(std::move(range_end))
39  {
40  }
41 
42  // Deprecated... Use the constructor above with both name and fam_name
43  BoundaryCondition(const std::string name, const Ioss::IJK_t range_beg,
44  const Ioss::IJK_t range_end)
45  : m_bcName(name), m_famName(std::move(name)), m_rangeBeg(std::move(range_beg)),
46  m_rangeEnd(std::move(range_end))
47  {
48  }
49 
50  BoundaryCondition(const BoundaryCondition &copy_from) = default;
51 
52  // Determine which "face" of the parent block this BC is applied to.
53  int which_face() const;
54 
55  // Does range specify a valid face
56  bool is_valid() const;
57 
58  // Return number of cell faces in the BC
59  size_t get_face_count() const;
60 
61  std::string m_bcName{};
62  std::string m_famName{};
63 
64  // These are potentially subsetted due to parallel decompositions...
67 
68  mutable int m_face{-1};
69 
70  friend std::ostream &operator<<(std::ostream &os, const BoundaryCondition &bc);
71  };
72 
73  class DatabaseIO;
74 
75  /** \brief A structured zone -- i,j,k
76  */
78  {
79  public:
80  StructuredBlock(DatabaseIO *io_database, const std::string &my_name, int index_dim, int ni,
81  int nj, int nk, int off_i, int off_j, int off_k, int glo_ni, int glo_nj,
82  int glo_nk);
83  StructuredBlock(DatabaseIO *io_database, const std::string &my_name, int index_dim,
84  Ioss::IJK_t &ordinal, Ioss::IJK_t &offset, Ioss::IJK_t &global_ordinal);
85 
86  // Useful for serial
87  StructuredBlock(DatabaseIO *io_database, const std::string &my_name, int index_dim, int ni,
88  int nj, int nk);
89  StructuredBlock(DatabaseIO *io_database, const std::string &my_name, int index_dim,
90  Ioss::IJK_t &ordinal);
91 
92  StructuredBlock *clone(DatabaseIO *database) const;
93 
94  ~StructuredBlock() override;
95 
96  std::string type_string() const override { return "StructuredBlock"; }
97  std::string short_type_string() const override { return "structuredblock"; }
98  std::string contains_string() const override { return "Cell"; }
99  EntityType type() const override { return STRUCTUREDBLOCK; }
100 
101  const Ioss::NodeBlock &get_node_block() const { return m_nodeBlock; }
103 
104  /** \brief Does block contain any cells
105  */
106  bool is_active() const { return m_ni * m_nj * m_nk > 0; }
107 
108  // Handle implicit properties -- These are calcuated from data stored
109  // in the grouping entity instead of having an explicit value assigned.
110  // An example would be 'element_block_count' for a region.
111  Property get_implicit_property(const std::string &my_name) const override;
112 
114 
115  /** \brief Set the 'offset' for the block.
116  *
117  * The 'offset' is used to map a cell or node location within a
118  * structured block to the model implicit cell or node location
119  * on a single processor. zero-based.
120  *
121  * The 'global' offsets do the same except for they apply over
122  * the entire model on all processors. zero-based.
123  *
124  * For example, the file descriptor (1-based) of
125  * the 37th cell in the 4th block is calculated by:
126  *
127  * file_descriptor = offset of block 4 + 37
128  *
129  * This can also be used to determine which structured block
130  * a cell with a file_descriptor maps into. An particular
131  * structured block contains all cells in the range:
132  *
133  * offset < file_descriptor <= offset+number_cells_per_block
134  *
135  * Note that for nodes, the nodeOffset does not take into account
136  * the nodes that are shared between blocks.
137  */
138  void set_node_offset(size_t offset) { m_nodeOffset = offset; }
139  void set_cell_offset(size_t offset) { m_cellOffset = offset; }
140  void set_node_global_offset(size_t offset) { m_nodeGlobalOffset = offset; }
141  void set_cell_global_offset(size_t offset) { m_cellGlobalOffset = offset; }
142 
143  size_t get_node_offset() const { return m_nodeOffset; }
144  size_t get_cell_offset() const { return m_cellOffset; }
145  size_t get_node_global_offset() const { return m_nodeGlobalOffset; }
146  size_t get_cell_global_offset() const { return m_cellGlobalOffset; }
147 
148  // Get the global (over all processors) cell
149  // id at the specified i,j,k location (1 <= i,j,k <= ni,nj,nk). 1-based.
150  size_t get_global_cell_id(int i, int j, int k) const
151  {
152  return m_cellGlobalOffset + static_cast<size_t>(k - 1) * m_niGlobal * m_njGlobal +
153  static_cast<size_t>(j - 1) * m_niGlobal + i;
154  }
155 
156  size_t get_global_cell_id(IJK_t index) const
157  {
158  return get_global_cell_id(index[0], index[1], index[2]);
159  }
160 
161  // Get the global (over all processors) node
162  // offset at the specified i,j,k location (1 <= i,j,k <= ni,nj,nk). 0-based, does not account
163  // for shared nodes.
164  size_t get_global_node_offset(int i, int j, int k) const
165  {
166  return m_nodeGlobalOffset + static_cast<size_t>(k - 1) * (m_niGlobal + 1) * (m_njGlobal + 1) +
167  static_cast<size_t>(j - 1) * (m_niGlobal + 1) + i - 1;
168  }
169 
170  size_t get_global_node_offset(IJK_t index) const
171  {
172  return get_global_node_offset(index[0], index[1], index[2]);
173  }
174 
175  // Get the local (relative to this block on this processor) node id at the specified
176  // i,j,k location (1 <= i,j,k <= ni+1,nj+1,nk+1). 0-based.
177  size_t get_block_local_node_offset(int ii, int jj, int kk) const
178  {
179  auto i = ii - m_offsetI;
180  auto j = jj - m_offsetJ;
181  auto k = kk - m_offsetK;
182  assert(i > 0 && i <= m_ni + 1 && j > 0 && j <= m_nj + 1 && k > 0 && k <= m_nk + 1);
183  return static_cast<size_t>(k - 1) * (m_ni + 1) * (m_nj + 1) +
184  static_cast<size_t>(j - 1) * (m_ni + 1) + i - 1;
185  }
186 
187  size_t get_block_local_node_offset(IJK_t index) const
188  {
189  return get_block_local_node_offset(index[0], index[1], index[2]);
190  }
191 
192  // Get the local (on this processor) cell-node offset at the specified
193  // i,j,k location (1 <= i,j,k <= ni+1,nj+1,nk+1). 0-based.
194  size_t get_local_node_offset(int i, int j, int k) const
195  {
196  return get_block_local_node_offset(i, j, k) + m_nodeOffset;
197  }
198 
199  size_t get_local_node_offset(IJK_t index) const
200  {
201  return get_local_node_offset(index[0], index[1], index[2]);
202  }
203 
204  std::vector<INT> get_cell_node_ids(bool add_offset) const
205  {
206  size_t node_count = get_property("node_count").get_int();
207  std::vector<INT> ids(node_count);
208  get_cell_node_ids(ids.data(), add_offset);
209  return ids;
210  }
211 
212  template <typename INT_t> size_t get_cell_node_ids(INT_t *idata, bool add_offset) const
213  {
214  // Fill 'idata' with the cell node ids which are the
215  // 1-based location of each node in this zone
216  // The location is based on the "model" (all processors) zone.
217  // If this is a parallel decomposed model, then
218  // this block may be a subset of the "model" zone
219  //
220  // if 'add_offset' is true, then add the m_cellGlobalOffset
221  // which changes the location to be the location in the
222  // entire "mesh" instead of within a "zone" (all processors)
223 
224  size_t index = 0;
225  size_t offset = add_offset ? m_nodeGlobalOffset : 0;
226 
227  if (m_nk == 0 && m_nj == 0 && m_ni == 0) {
228  return index;
229  }
230 
231  for (int kk = 0; kk < m_nk + 1; kk++) {
232  size_t k = m_offsetK + kk;
233  for (int jj = 0; jj < m_nj + 1; jj++) {
234  size_t j = m_offsetJ + jj;
235  for (int ii = 0; ii < m_ni + 1; ii++) {
236  size_t i = m_offsetI + ii;
237 
238  size_t ind = k * (m_niGlobal + 1) * (m_njGlobal + 1) + j * (m_niGlobal + 1) + i;
239 
240  idata[index++] = ind + offset + 1;
241  }
242  }
243  }
244 
245  for (auto idx_id : m_globalIdMap) {
246  idata[idx_id.first] = idx_id.second;
247  }
248 
249  return index;
250  }
251 
252  template <typename INT_t> size_t get_cell_ids(INT_t *idata, bool add_offset) const
253  {
254  // Fill 'idata' with the cell ids which are the
255  // 1-based location of each cell in this zone
256  // The location is based on the "model" zone.
257  // If this is a parallel decomposed model, then
258  // this block may be a subset of the "model" zone
259  //
260  // if 'add_offset' is true, then add the m_cellGlobalOffset
261  // which changes the location to be the location in the
262  // entire "mesh" instead of within a "zone"
263 
264  size_t index = 0;
265  size_t offset = add_offset ? m_cellGlobalOffset : 0;
266 
267  if (m_nk == 0 && m_nj == 0 && m_ni == 0) {
268  return index;
269  }
270 
271  for (int kk = 0; kk < m_nk; kk++) {
272  size_t k = m_offsetK + kk;
273  for (int jj = 0; jj < m_nj; jj++) {
274  size_t j = m_offsetJ + jj;
275  for (int ii = 0; ii < m_ni; ii++) {
276  size_t i = m_offsetI + ii;
277 
278  size_t ind = k * m_niGlobal * m_njGlobal + j * m_niGlobal + i;
279 
280  idata[index++] = ind + offset + 1;
281  }
282  }
283  }
284  return index;
285  }
286 
287  bool contains(size_t global_offset) const
288  {
289  return (global_offset >= m_nodeOffset &&
290  global_offset < m_nodeOffset + get_property("node_count").get_int());
291  }
292 
293  protected:
294  int64_t internal_get_field_data(const Field &field, void *data,
295  size_t data_size) const override;
296 
297  int64_t internal_put_field_data(const Field &field, void *data,
298  size_t data_size) const override;
299 
300  private:
301  int m_ni{};
302  int m_nj{};
303  int m_nk{};
304 
305  int m_offsetI{}; // Valid 'i' ordinal runs from m_offsetI+1 to m_offsetI+m_ni
306  int m_offsetJ{};
307  int m_offsetK{};
308 
309  int m_niGlobal{}; // The ni,nj,nk of the master block this is a subset of.
310  int m_njGlobal{};
311  int m_nkGlobal{};
312 
313  size_t m_nodeOffset{};
314  size_t m_cellOffset{};
315 
318 
320 
321  public:
322  std::vector<ZoneConnectivity> m_zoneConnectivity;
323  std::vector<BoundaryCondition> m_boundaryConditions;
324  std::vector<size_t> m_blockLocalNodeIndex;
325  std::vector<std::pair<size_t, size_t>> m_globalIdMap;
326  };
327 } // namespace Ioss
328 #endif
Ioss::StructuredBlock::get_cell_offset
size_t get_cell_offset() const
Definition: Ioss_StructuredBlock.h:144
Ioss::StructuredBlock::m_offsetJ
int m_offsetJ
Definition: Ioss_StructuredBlock.h:306
Ioss::BoundaryCondition::which_face
int which_face() const
Definition: Ioss_StructuredBlock.C:248
Ioss::StructuredBlock::~StructuredBlock
~StructuredBlock() override
Ioss::StructuredBlock::m_globalIdMap
std::vector< std::pair< size_t, size_t > > m_globalIdMap
Definition: Ioss_StructuredBlock.h:325
Ioss::Field
Holds metadata for bulk data associated with a GroupingEntity.
Definition: Ioss_Field.h:22
Ioss_Property.h
Ioss::StructuredBlock::m_cellGlobalOffset
size_t m_cellGlobalOffset
Definition: Ioss_StructuredBlock.h:317
Ioss::StructuredBlock::m_offsetI
int m_offsetI
Definition: Ioss_StructuredBlock.h:305
Ioss::StructuredBlock::m_niGlobal
int m_niGlobal
Definition: Ioss_StructuredBlock.h:309
Ioss::StructuredBlock::set_node_offset
void set_node_offset(size_t offset)
Set the 'offset' for the block.
Definition: Ioss_StructuredBlock.h:138
Ioss::StructuredBlock::get_local_node_offset
size_t get_local_node_offset(int i, int j, int k) const
Definition: Ioss_StructuredBlock.h:194
Ioss::StructuredBlock::contains
bool contains(size_t global_offset) const
Definition: Ioss_StructuredBlock.h:287
Ioss::StructuredBlock::get_cell_node_ids
size_t get_cell_node_ids(INT_t *idata, bool add_offset) const
Definition: Ioss_StructuredBlock.h:212
Ioss::StructuredBlock::m_blockLocalNodeIndex
std::vector< size_t > m_blockLocalNodeIndex
Definition: Ioss_StructuredBlock.h:324
Ioss::BoundaryCondition::BoundaryCondition
BoundaryCondition(const std::string name, const std::string fam_name, const Ioss::IJK_t range_beg, const Ioss::IJK_t range_end)
Definition: Ioss_StructuredBlock.h:35
Ioss::StructuredBlock::get_global_cell_id
size_t get_global_cell_id(int i, int j, int k) const
Definition: Ioss_StructuredBlock.h:150
Ioss::StructuredBlock::m_nk
int m_nk
Definition: Ioss_StructuredBlock.h:303
Ioss
The main namespace for the Ioss library.
Definition: Ioad_DatabaseIO.C:40
Ioss::STRUCTUREDBLOCK
@ STRUCTUREDBLOCK
Definition: Ioss_EntityType.h:28
Ioss::StructuredBlock::get_bounding_box
AxisAlignedBoundingBox get_bounding_box() const
Definition: Ioss_StructuredBlock.C:210
Ioss::StructuredBlock::m_nj
int m_nj
Definition: Ioss_StructuredBlock.h:302
Ioss::StructuredBlock
A structured zone – i,j,k.
Definition: Ioss_StructuredBlock.h:78
Ioss::StructuredBlock::get_cell_node_ids
std::vector< INT > get_cell_node_ids(bool add_offset) const
Definition: Ioss_StructuredBlock.h:204
Ioss::StructuredBlock::get_local_node_offset
size_t get_local_node_offset(IJK_t index) const
Definition: Ioss_StructuredBlock.h:199
Ioss::BoundaryCondition::m_bcName
std::string m_bcName
Definition: Ioss_StructuredBlock.h:61
INT
int INT
Definition: Ioss_StructuredBlock.h:27
Ioss::BoundaryCondition::get_face_count
size_t get_face_count() const
Definition: Ioss_StructuredBlock.C:215
Ioss::StructuredBlock::get_block_local_node_offset
size_t get_block_local_node_offset(IJK_t index) const
Definition: Ioss_StructuredBlock.h:187
Ioss::StructuredBlock::internal_get_field_data
int64_t internal_get_field_data(const Field &field, void *data, size_t data_size) const override
Definition: Ioss_StructuredBlock.C:198
Ioss::EntityType
EntityType
The particular type of GroupingEntity.
Definition: Ioss_EntityType.h:13
Ioss::StructuredBlock::m_nodeBlock
Ioss::NodeBlock m_nodeBlock
Definition: Ioss_StructuredBlock.h:319
Ioss::DatabaseIO
An input or output Database.
Definition: Ioss_DatabaseIO.h:59
Ioss::AxisAlignedBoundingBox
Definition: Ioss_BoundingBox.h:12
Ioss::BoundaryCondition::m_rangeEnd
Ioss::IJK_t m_rangeEnd
Definition: Ioss_StructuredBlock.h:66
Ioss::StructuredBlock::m_cellOffset
size_t m_cellOffset
Definition: Ioss_StructuredBlock.h:314
Ioss::StructuredBlock::get_implicit_property
Property get_implicit_property(const std::string &my_name) const override
Calculate and get an implicit property.
Definition: Ioss_StructuredBlock.C:193
Ioss::StructuredBlock::m_offsetK
int m_offsetK
Definition: Ioss_StructuredBlock.h:307
Ioss::StructuredBlock::clone
StructuredBlock * clone(DatabaseIO *database) const
Definition: Ioss_StructuredBlock.C:177
Ioss::StructuredBlock::m_zoneConnectivity
std::vector< ZoneConnectivity > m_zoneConnectivity
Definition: Ioss_StructuredBlock.h:322
Ioss::StructuredBlock::StructuredBlock
StructuredBlock(DatabaseIO *io_database, const std::string &my_name, int index_dim, int ni, int nj, int nk, int off_i, int off_j, int off_k, int glo_ni, int glo_nj, int glo_nk)
Definition: Ioss_StructuredBlock.C:97
Ioss::StructuredBlock::get_node_block
const Ioss::NodeBlock & get_node_block() const
Definition: Ioss_StructuredBlock.h:101
Ioss::BoundaryCondition::m_famName
std::string m_famName
Definition: Ioss_StructuredBlock.h:62
Ioss::StructuredBlock::set_cell_offset
void set_cell_offset(size_t offset)
Definition: Ioss_StructuredBlock.h:139
Ioss::BoundaryCondition::m_rangeBeg
Ioss::IJK_t m_rangeBeg
Definition: Ioss_StructuredBlock.h:65
Ioss::StructuredBlock::contains_string
std::string contains_string() const override
What does this entity contain.
Definition: Ioss_StructuredBlock.h:98
Ioss::StructuredBlock::m_njGlobal
int m_njGlobal
Definition: Ioss_StructuredBlock.h:310
Ioss::EntityBlock
Base class for all 'block'-type grouping entities, which means all members of the block are similar o...
Definition: Ioss_EntityBlock.h:36
Ioss::StructuredBlock::type
EntityType type() const override
Get the EntityType, which indicates the particular type of GroupingEntity this is.
Definition: Ioss_StructuredBlock.h:99
Ioss::StructuredBlock::get_node_block
Ioss::NodeBlock & get_node_block()
Definition: Ioss_StructuredBlock.h:102
Ioss::StructuredBlock::m_nkGlobal
int m_nkGlobal
Definition: Ioss_StructuredBlock.h:311
Ioss::Property::get_int
int64_t get_int() const
Get the property value if it is of type INTEGER.
Definition: Ioss_Property.C:235
Ioss::IJK_t
std::array< int, 3 > IJK_t
Definition: Ioss_CodeTypes.h:28
Ioss::StructuredBlock::type_string
std::string type_string() const override
Get the name of the particular type of entity.
Definition: Ioss_StructuredBlock.h:96
Ioss::BoundaryCondition::is_valid
bool is_valid() const
Definition: Ioss_StructuredBlock.C:238
Ioss::StructuredBlock::is_active
bool is_active() const
Does block contain any cells.
Definition: Ioss_StructuredBlock.h:106
Ioss::StructuredBlock::get_global_node_offset
size_t get_global_node_offset(int i, int j, int k) const
Definition: Ioss_StructuredBlock.h:164
Ioss::GroupingEntity::get_property
Property get_property(const std::string &property_name) const
Get the Property from the property manager associated with the entity.
Definition: Ioss_GroupingEntity.h:332
Ioss::StructuredBlock::get_cell_global_offset
size_t get_cell_global_offset() const
Definition: Ioss_StructuredBlock.h:146
Ioss::StructuredBlock::get_block_local_node_offset
size_t get_block_local_node_offset(int ii, int jj, int kk) const
Definition: Ioss_StructuredBlock.h:177
anonymous_namespace{cth_pressure_map.C}::data
std::vector< char > data
Definition: cth_pressure_map.C:48
Ioss::StructuredBlock::internal_put_field_data
int64_t internal_put_field_data(const Field &field, void *data, size_t data_size) const override
Definition: Ioss_StructuredBlock.C:204
Ioss::BoundaryCondition::BoundaryCondition
BoundaryCondition(const std::string name, const Ioss::IJK_t range_beg, const Ioss::IJK_t range_end)
Definition: Ioss_StructuredBlock.h:43
Ioss::StructuredBlock::set_node_global_offset
void set_node_global_offset(size_t offset)
Definition: Ioss_StructuredBlock.h:140
Ioss::StructuredBlock::get_cell_ids
size_t get_cell_ids(INT_t *idata, bool add_offset) const
Definition: Ioss_StructuredBlock.h:252
Ioss::StructuredBlock::m_boundaryConditions
std::vector< BoundaryCondition > m_boundaryConditions
Definition: Ioss_StructuredBlock.h:323
Ioss::StructuredBlock::set_cell_global_offset
void set_cell_global_offset(size_t offset)
Definition: Ioss_StructuredBlock.h:141
Ioss::BoundaryCondition::operator<<
friend std::ostream & operator<<(std::ostream &os, const BoundaryCondition &bc)
Definition: Ioss_StructuredBlock.C:270
Ioss::BoundaryCondition::m_face
int m_face
Definition: Ioss_StructuredBlock.h:68
Ioss::NodeBlock
A collection of all nodes in the region.
Definition: Ioss_NodeBlock.h:28
Ioss_NodeBlock.h
Ioss::StructuredBlock::m_nodeOffset
size_t m_nodeOffset
Definition: Ioss_StructuredBlock.h:313
Ioss::StructuredBlock::get_node_offset
size_t get_node_offset() const
Definition: Ioss_StructuredBlock.h:143
Ioss_BoundingBox.h
anonymous_namespace{io_info.C}::name
std::string name(const Ioss::GroupingEntity *entity)
Definition: io_info.C:65
Ioss::BoundaryCondition
Definition: Ioss_StructuredBlock.h:34
Ioss::Property
A named value that has a known type.
Definition: Ioss_Property.h:24
Ioss::StructuredBlock::get_node_global_offset
size_t get_node_global_offset() const
Definition: Ioss_StructuredBlock.h:145
Ioss::StructuredBlock::short_type_string
std::string short_type_string() const override
Get a short name of the particular type of entity.
Definition: Ioss_StructuredBlock.h:97
Ioss::StructuredBlock::m_nodeGlobalOffset
size_t m_nodeGlobalOffset
Definition: Ioss_StructuredBlock.h:316
Ioss::StructuredBlock::get_global_cell_id
size_t get_global_cell_id(IJK_t index) const
Definition: Ioss_StructuredBlock.h:156
Ioss::StructuredBlock::m_ni
int m_ni
Definition: Ioss_StructuredBlock.h:301
Ioss_CodeTypes.h
Ioss::StructuredBlock::get_global_node_offset
size_t get_global_node_offset(IJK_t index) const
Definition: Ioss_StructuredBlock.h:170
Ioss::BoundaryCondition::BoundaryCondition
BoundaryCondition(const BoundaryCondition &copy_from)=default
Ioss_EntityBlock.h
Ioss_ZoneConnectivity.h