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