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(SIERRA_PARALLEL_MPI)
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  EntityType type() const override { return STRUCTUREDBLOCK; }
125 
126  const Ioss::NodeBlock &get_node_block() const { return m_nodeBlock; }
127 
128  /** \brief Does block contain any cells
129  */
130  bool is_active() const { return m_ni * m_nj * m_nk > 0; }
131 
132  // Handle implicit properties -- These are calcuated from data stored
133  // in the grouping entity instead of having an explicit value assigned.
134  // An example would be 'element_block_count' for a region.
135  Property get_implicit_property(const std::string &my_name) const override;
136 
138 
139  /** \brief Set the 'offset' for the block.
140  *
141  * The 'offset' is used to map a cell or node location within a
142  * structured block to the model implicit cell or node location
143  * on a single processor. zero-based.
144  *
145  * The 'global' offsets do the same except for they apply over
146  * the entire model on all processors. zero-based.
147  *
148  * For example, the file descriptor (1-based) of
149  * the 37th cell in the 4th block is calculated by:
150  *
151  * file_descriptor = offset of block 4 + 37
152  *
153  * This can also be used to determine which structured block
154  * a cell with a file_descriptor maps into. An particular
155  * structured block contains all cells in the range:
156  *
157  * offset < file_descriptor <= offset+number_cells_per_block
158  *
159  * Note that for nodes, the nodeOffset does not take into account
160  * the nodes that are shared between blocks.
161  */
162  void set_node_offset(size_t offset) { m_nodeOffset = offset; }
163  void set_cell_offset(size_t offset) { m_cellOffset = offset; }
164  void set_node_global_offset(size_t offset) { m_nodeGlobalOffset = offset; }
165  void set_cell_global_offset(size_t offset) { m_cellGlobalOffset = offset; }
166 
167  size_t get_node_offset() const { return m_nodeOffset; }
168  size_t get_cell_offset() const { return m_cellOffset; }
169  size_t get_node_global_offset() const { return m_nodeGlobalOffset; }
170  size_t get_cell_global_offset() const { return m_cellGlobalOffset; }
171 
172  // Get the global (over all processors) cell
173  // id at the specified i,j,k location (1 <= i,j,k <= ni,nj,nk). 1-based.
174  size_t get_global_cell_id(int i, int j, int k) const
175  {
176  return m_cellGlobalOffset + static_cast<size_t>(k - 1) * m_niGlobal * m_njGlobal +
177  static_cast<size_t>(j - 1) * m_niGlobal + i;
178  }
179 
180  size_t get_global_cell_id(IJK_t index) const
181  {
182  return get_global_cell_id(index[0], index[1], index[2]);
183  }
184 
185  // Get the global (over all processors) node
186  // offset at the specified i,j,k location (1 <= i,j,k <= ni,nj,nk). 0-based, does not account
187  // for shared nodes.
188  size_t get_global_node_offset(int i, int j, int k) const
189  {
190  return m_nodeGlobalOffset + static_cast<size_t>(k - 1) * (m_niGlobal + 1) * (m_njGlobal + 1) +
191  static_cast<size_t>(j - 1) * (m_niGlobal + 1) + i - 1;
192  }
193 
194  size_t get_global_node_offset(IJK_t index) const
195  {
196  return get_global_node_offset(index[0], index[1], index[2]);
197  }
198 
199  // Get the local (relative to this block on this processor) node id at the specified
200  // i,j,k location (1 <= i,j,k <= ni+1,nj+1,nk+1). 0-based.
201  size_t get_block_local_node_offset(int ii, int jj, int kk) const
202  {
203  auto i = ii - m_offsetI;
204  auto j = jj - m_offsetJ;
205  auto k = kk - m_offsetK;
206  assert(i > 0 && i <= m_ni + 1 && j > 0 && j <= m_nj + 1 && k > 0 && k <= m_nk + 1);
207  return static_cast<size_t>(k - 1) * (m_ni + 1) * (m_nj + 1) +
208  static_cast<size_t>(j - 1) * (m_ni + 1) + i - 1;
209  }
210 
211  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  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  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  std::vector<INT> get_cell_node_ids(bool add_offset) const
229  {
230  size_t node_count = get_property("node_count").get_int();
231  std::vector<INT> ids(node_count);
232  get_cell_node_ids(ids.data(), add_offset);
233  return ids;
234  }
235 
236  template <typename INT_t> size_t get_cell_node_ids(INT_t *idata, bool add_offset) const
237  {
238  // Fill 'idata' with the cell node ids which are the
239  // 1-based location of each node in this zone
240  // The location is based on the "model" (all processors) zone.
241  // If this is a parallel decomposed model, then
242  // this block may be a subset of the "model" zone
243  //
244  // if 'add_offset' is true, then add the m_cellGlobalOffset
245  // which changes the location to be the location in the
246  // entire "mesh" instead of within a "zone" (all processors)
247 
248  size_t index = 0;
249  size_t offset = add_offset ? m_nodeGlobalOffset : 0;
250 
251  if (m_nk == 0 && m_nj == 0 && m_ni == 0) {
252  return index;
253  }
254 
255  for (int kk = 0; kk < m_nk + 1; kk++) {
256  size_t k = m_offsetK + kk;
257  for (int jj = 0; jj < m_nj + 1; jj++) {
258  size_t j = m_offsetJ + jj;
259  for (int ii = 0; ii < m_ni + 1; ii++) {
260  size_t i = m_offsetI + ii;
261 
262  size_t ind = k * (m_niGlobal + 1) * (m_njGlobal + 1) + j * (m_niGlobal + 1) + i;
263 
264  idata[index++] = ind + offset + 1;
265  }
266  }
267  }
268 
269  for (auto idx_id : m_globalIdMap) {
270  idata[idx_id.first] = idx_id.second;
271  }
272 
273  return index;
274  }
275 
276  template <typename INT_t> size_t get_cell_ids(INT_t *idata, bool add_offset) const
277  {
278  // Fill 'idata' with the cell ids which are the
279  // 1-based location of each cell in this zone
280  // The location is based on the "model" zone.
281  // If this is a parallel decomposed model, then
282  // this block may be a subset of the "model" zone
283  //
284  // if 'add_offset' is true, then add the m_cellGlobalOffset
285  // which changes the location to be the location in the
286  // entire "mesh" instead of within a "zone"
287 
288  size_t index = 0;
289  size_t offset = add_offset ? m_cellGlobalOffset : 0;
290 
291  if (m_nk == 0 && m_nj == 0 && m_ni == 0) {
292  return index;
293  }
294 
295  for (int kk = 0; kk < m_nk; kk++) {
296  size_t k = m_offsetK + kk;
297  for (int jj = 0; jj < m_nj; jj++) {
298  size_t j = m_offsetJ + jj;
299  for (int ii = 0; ii < m_ni; ii++) {
300  size_t i = m_offsetI + ii;
301 
302  size_t ind = k * m_niGlobal * m_njGlobal + j * m_niGlobal + i;
303 
304  idata[index++] = ind + offset + 1;
305  }
306  }
307  }
308  return index;
309  }
310 
311  bool contains(size_t global_offset) const
312  {
313  return (global_offset >= m_nodeOffset &&
314  global_offset < m_nodeOffset + get_property("node_count").get_int());
315  }
316 
317  protected:
318  int64_t internal_get_field_data(const Field &field, void *data,
319  size_t data_size) const override;
320 
321  int64_t internal_put_field_data(const Field &field, void *data,
322  size_t data_size) const override;
323 
324  private:
325  int m_ni{};
326  int m_nj{};
327  int m_nk{};
328 
329  int m_offsetI{}; // Valid 'i' ordinal runs from m_offsetI+1 to m_offsetI+m_ni
330  int m_offsetJ{};
331  int m_offsetK{};
332 
333  int m_niGlobal{}; // The ni,nj,nk of the master block this is a subset of.
334  int m_njGlobal{};
335  int m_nkGlobal{};
336 
337  size_t m_nodeOffset{};
338  size_t m_cellOffset{};
339 
342 
344 
345  public:
346  std::vector<ZoneConnectivity> m_zoneConnectivity;
347  std::vector<BoundaryCondition> m_boundaryConditions;
348  std::vector<size_t> m_blockLocalNodeIndex;
349  std::vector<std::pair<size_t, size_t>> m_globalIdMap;
350  };
351 } // namespace Ioss
352 #endif
bool contains(size_t global_offset) const
Definition: Ioss_StructuredBlock.h:311
A named value that has a known type.
Definition: Ioss_Property.h:47
The main namespace for the Ioss library.
Definition: Iocgns_DatabaseIO.h:50
An input or output Database.
Definition: Ioss_DatabaseIO.h:80
size_t m_nodeOffset
Definition: Ioss_StructuredBlock.h:337
friend std::ostream & operator<<(std::ostream &os, const BoundaryCondition &bc)
Definition: Ioss_StructuredBlock.C:282
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:343
size_t m_nodeGlobalOffset
Definition: Ioss_StructuredBlock.h:340
size_t get_local_node_offset(IJK_t index) const
Definition: Ioss_StructuredBlock.h:223
int m_ni
Definition: Ioss_StructuredBlock.h:325
int64_t internal_get_field_data(const Field &field, void *data, size_t data_size) const override
Definition: Ioss_StructuredBlock.C:210
Property get_property(const std::string &property_name) const
Get the Property from the property manager associated with the entity.
Definition: Ioss_GroupingEntity.h:342
const Ioss::NodeBlock & get_node_block() const
Definition: Ioss_StructuredBlock.h:126
size_t get_cell_node_ids(INT_t *idata, bool add_offset) const
Definition: Ioss_StructuredBlock.h:236
std::vector< size_t > m_blockLocalNodeIndex
Definition: Ioss_StructuredBlock.h:348
Property get_implicit_property(const std::string &my_name) const override
Calculate and get an implicit property.
Definition: Ioss_StructuredBlock.C:205
size_t get_global_cell_id(int i, int j, int k) const
Definition: Ioss_StructuredBlock.h:174
StructuredBlock * clone(DatabaseIO *database) const
Definition: Ioss_StructuredBlock.C:189
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:87
size_t get_face_count() const
Definition: Ioss_StructuredBlock.C:227
AxisAlignedBoundingBox get_bounding_box() const
Definition: Ioss_StructuredBlock.C:222
void set_node_offset(size_t offset)
Set the &#39;offset&#39; for the block.
Definition: Ioss_StructuredBlock.h:162
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
Base class for all &#39;block&#39;-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:188
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:170
void set_node_global_offset(size_t offset)
Definition: Ioss_StructuredBlock.h:164
int which_face() const
Definition: Ioss_StructuredBlock.C:260
size_t get_block_local_node_offset(IJK_t index) const
Definition: Ioss_StructuredBlock.h:211
void set_cell_global_offset(size_t offset)
Definition: Ioss_StructuredBlock.h:165
A collection of all nodes in the region.
Definition: Ioss_NodeBlock.h:53
int m_nj
Definition: Ioss_StructuredBlock.h:326
bool is_active() const
Does block contain any cells.
Definition: Ioss_StructuredBlock.h:130
std::vector< INT > get_cell_node_ids(bool add_offset) const
Definition: Ioss_StructuredBlock.h:228
Ioss::IJK_t m_rangeBeg
Definition: Ioss_StructuredBlock.h:91
std::vector< BoundaryCondition > m_boundaryConditions
Definition: Ioss_StructuredBlock.h:347
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:167
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:163
size_t get_cell_offset() const
Definition: Ioss_StructuredBlock.h:168
Definition: Ioss_EntityType.h:54
std::string m_famName
Definition: Ioss_StructuredBlock.h:88
int m_njGlobal
Definition: Ioss_StructuredBlock.h:334
int m_offsetJ
Definition: Ioss_StructuredBlock.h:330
size_t get_node_global_offset() const
Definition: Ioss_StructuredBlock.h:169
size_t get_global_cell_id(IJK_t index) const
Definition: Ioss_StructuredBlock.h:180
std::string name(Ioss::GroupingEntity *entity)
Definition: io_info.C:88
~StructuredBlock() override
size_t m_cellOffset
Definition: Ioss_StructuredBlock.h:338
int m_offsetK
Definition: Ioss_StructuredBlock.h:331
size_t get_global_node_offset(IJK_t index) const
Definition: Ioss_StructuredBlock.h:194
Holds metadata for bulk data associated with a GroupingEntity.
Definition: Ioss_Field.h:47
std::vector< ZoneConnectivity > m_zoneConnectivity
Definition: Ioss_StructuredBlock.h:346
size_t m_cellGlobalOffset
Definition: Ioss_StructuredBlock.h:341
int m_offsetI
Definition: Ioss_StructuredBlock.h:329
EntityType type() const override
Get the EntityType, which indicates the particular type of GroupingEntity this is.
Definition: Ioss_StructuredBlock.h:124
int m_nkGlobal
Definition: Ioss_StructuredBlock.h:335
EntityType
The particular type of GroupingEntity.
Definition: Ioss_EntityType.h:39
bool is_valid() const
Definition: Ioss_StructuredBlock.C:250
std::vector< std::pair< size_t, size_t > > m_globalIdMap
Definition: Ioss_StructuredBlock.h:349
size_t get_local_node_offset(int i, int j, int k) const
Definition: Ioss_StructuredBlock.h:218
size_t get_block_local_node_offset(int ii, int jj, int kk) const
Definition: Ioss_StructuredBlock.h:201
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:216
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:276
int m_niGlobal
Definition: Ioss_StructuredBlock.h:333
int m_nk
Definition: Ioss_StructuredBlock.h:327