IOSS  2.0
Iogs_GeneratedMesh.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_Iogs_GeneratedMesh_h
34 #define IOSS_Iogs_GeneratedMesh_h
35 
36 #include <Ioss_CodeTypes.h>
37 #include <Ioss_EntityType.h> // for EntityType
38 #include <array>
39 #include <cstddef> // for size_t
40 #include <cstdint> // for int64_t
41 #include <map> // for map, etc
42 #include <string> // for string
43 #include <utility> // for pair
44 #include <vector> // for vector
45 
46 namespace Iogs {
47  using MapVector = std::vector<int64_t>;
48 
50  {
51  public:
52  enum ShellLocation { MX = 0, PX = 1, MY = 2, PY = 3, MZ = 4, PZ = 5 };
53 
54  /**
55  Generate a cube mesh of size 'num_x' by 'num_y' by 'num_z' elements.
56  By default, the mesh is gen_struc on a single processor. If 'proc_count' is
57  greater than 1, then the mesh will be distributed over 'proc_count' processors
58  and this process will get the portion of the mesh for 'my_proc'.
59  The mesh will be decomposed along the 'Z' axis so 'num_z' must be greater than
60  or equal to 'proc_count' and for even distribution of the hexes 'num_z' mod 'proc_count'
61  should be zero.
62 
63  The mesh can optionally include sidesets along each
64  face of the cube mesh. These are specified via the
65  'add_sidesets' function.
66 
67  If the 'parameters' string constructor is used, the string
68  is parsed to determine the intervals in each direction and,
69  optionally, additional information. The form of the string
70  is "IxJxK" where I, J, and K are the number of intervals
71  in the X, Y, and Z directions respectively and the "x" are
72  literal 'x' characters. For example, the constructor
73  GeneratedMesh("10x12x14") will create the same mesh as
74  GeneratedMesh(10,12,14)
75 
76  Additional valid options are:
77  - help -- no argument, shows valid options
78  - show -- no argument, prints out a summary of the
79  GeneratedMesh() parameters. The output will look similar
80  to:
81  \code
82  "10x12x8|bbox:-10,-10,-10,10,10,10|sideset:XYZ|show"
83 
84  Mesh Parameters:
85  Intervals: 10 by 12 by 8
86  X = 2 * (0..10) + -10 Range: -10 <= X <= 10
87  Y = 1.66667 * (0..12) + -10 Range: -10 <= Y <= 10
88  Z = 2.5 * (0..8) + -10 Range: -10 <= Z <= 10
89  Node Count (total) = 1287
90  Element Count (total) = 1152
91  Block Count = 3
92  SideSet Count = 3
93  \endcode
94 
95  - sideset -- argument = xXyYzZ which specifies whether there is
96  a sideset at that location. 'x' is minimum x face, 'X' is
97  maximum x face, similarly for y and z. Note that the argument
98  string is a single multicharacter string. You can add multiple
99  sidesets to a face, for example, sideset:xxx would add three
100  sidesets on the minimum x face. An error is output if a non
101  xXyYzZ character is found, but execution continues.
102 
103  - zdecomp -- argument = n0, n1, n2, ..., n#proc-1 which are the number
104  of intervals in the z direction for each processor in a pallel run.
105  If this option is specified, then the total number of intervals in the
106  z direction is the sum of the n0, n1, ... An interval count must be
107  specified for each processor. If this option is not specified, then
108  the number of intervals on each processor in the z direction is
109  numZ/numProc with the extras added to the lower numbered processors.
110 
111  - scale -- argument = xs, ys, zs which are the scale factors in the x,
112  y, and z directions. All three must be specified if this option is
113  present.
114 
115  - offset -- argument = xoff, yoff, zoff which are the offsets in the
116  x, y, and z directions. All three must be specified if this option
117  is present.
118 
119  - bbox -- argument = xmin, ymin, zmin, xmax, ymax, zmax
120  which specify the lower left and upper right corners of
121  the bounding box for the gen_struc mesh. This will
122  calculate the scale and offset which will fit the mesh in
123  the specified box. All calculations are based on the currently
124  active interval settings. If scale or offset or zdecomp
125  specified later in the option list, you may not get the
126  desired bounding box.
127 
128  - rotate -- argument = axis,angle,axis,angle,...
129  where axis is 'x', 'y', or 'z' and angle is the rotation angle in
130  degrees. Multiple rotations are cumulative. The composite rotation
131  matrix is applied at the time the coordinates are retrieved after
132  scaling and offset are applied.
133 
134  The unrotated coordinate of a node at grid location i,j,k is:
135  \code
136  x = x_scale * i + x_off,
137  y = z_scale * j + y_off,
138  z = z_scale * k + z_off,
139  \endcode
140 
141  The extent of the unrotated mesh will be:
142  \code
143  x_off <= x <= x_scale * numX + x_off
144  y_off <= y <= y_scale * numY + y_off
145  z_off <= z <= z_scale * numZ + z_off
146  \endcode
147 
148  If an unrecognized option is specified, an error message will be
149  output and execution will continue.
150 
151  An example of valid input is:
152  \code
153  "10x20x40|scale:1,0.5,0.25|offset:-5,-5,-5"
154  \endcode
155 
156  This would create a mesh with 10 intervals in x, 20 in y, 40 in z
157  The mesh would be centered on 0,0,0 with a range of 10 in each
158  direction.
159 
160  NOTE: All options are processed in the order they appear in
161  the parameters string (except rotate which is applied at the
162  time the coordinates are gen_struc/retrieved)
163  */
164  explicit GeneratedMesh(const std::string &parameters, int proc_count = 1, int my_proc = 0);
165  GeneratedMesh(int64_t num_x, int64_t num_y, int64_t num_z, int proc_count = 1, int my_proc = 0);
166  GeneratedMesh();
167  virtual ~GeneratedMesh();
168 
169  /**
170  * Add a sideset along the specified face of the hex mesh.
171  * The sidesets will maintain the order of definition. The
172  * first sideset defined will be sideset 1.
173  * The loc options are:
174  * - MX = add sideset on the face with minimum X
175  * - PX = add sideset on the face with maximum X
176  * - MY = add sideset on the face with minimum Y
177  * - PY = add sideset on the face with maximum Y
178  * - MZ = add sideset on the face with minimum Z
179  * - PZ = add sideset on the face with maximum Z
180  *
181  */
182  int64_t add_sideset(ShellLocation loc);
183 
184  /**
185  * Specify the coordinate scaling and offset in all three
186  * spatial dimensions.
187  *
188  * node location of node at (i,j,k) is
189  * \code
190  * X = scale X * i + offset X
191  * Y = scale Y * i + offset Y
192  * Z = scale Z * i + offset Z
193  * \endcode
194  *
195  * WARNING: Should be called before retrieving node
196  * coordinates.
197  */
198  void set_scale(double scl_x, double scl_y, double scl_z);
199  void set_offset(double off_x, double off_y, double off_z);
200  void set_bbox(double xmin, double ymin, double zmin, double xmax, double ymax, double zmax);
201 
202  /**
203  * Set rotation. Multiple calls are cumulative.
204  * Rotate 'angle_degrees' degrees about the axis 'axis'
205  * Center of rotation is about the origin and operates
206  * on the scaled/offset coordinates of the mesh.
207  */
208  void set_rotation(const std::string &axis, double angle_degrees);
209 
210  /**
211  * Return number of nodes in the entire model.
212  */
213  virtual int64_t node_count() const;
214 
215  /**
216  * Return number of nodes on this processor.
217  */
218  virtual int64_t node_count_proc() const;
219 
220  /**
221  * Return number of structured blocks in the entire model.
222  */
223  virtual int64_t structured_block_count() const;
224 
225  /**
226  * Return number of sidesets in the entire model.
227  */
228  virtual int64_t sideset_count() const;
229 
230  /**
231  * Return number of sideset 'sides' on sideset 'id'
232  */
233  int64_t sideset_side_count(int64_t id) const;
234 
235  /**
236  * Return number of sideset 'sides' on sideset 'id' on the current
237  * processor.
238  */
239  virtual int64_t sideset_side_count_proc(int64_t id) const;
240 
241  Ioss::IJK_t block_range(int64_t /* id */) const
242  {
243  return Ioss::IJK_t{{(int)numX, (int)numY, (int)numZ}};
244  }
245  Ioss::IJK_t block_range_proc(int64_t id) const;
246  Ioss::IJK_t block_offset_proc(int64_t id) const;
247 
248  /**
249  * Return number of elements in all structured blocks in the model.
250  */
251  virtual int64_t element_count() const;
252 
253  /**
254  * Return number of elements in all structured blocks on this processor.
255  */
256  virtual int64_t element_count_proc() const;
257 
258  int64_t timestep_count() const { return timestepCount; }
259  /**
260  * Return number of elements in the structured block with id
261  * 'block_number'. The 'block_number' ranges from '1' to
262  * 'block_count()'.
263  */
264  virtual int64_t element_count(int64_t block_number) const;
265 
266  /**
267  * Return number of elements on this processor in the structured
268  * block with id 'block_number'. The 'block_number' ranges from
269  * '1' to 'block_count()'.
270  */
271  virtual int64_t element_count_proc(int64_t block_number) const;
272 
273  /**
274  * Returns pair containing "topology type string" and "number of
275  * nodes / element". The topology type string will be "hex8" for
276  * the hex element block
277  */
278  virtual std::pair<std::string, int> topology_type(int64_t block_number) const;
279 
280  void build_node_map(Ioss::Int64Vector &map, std::vector<int> &proc, int64_t slab,
281  size_t slabOffset, size_t adjacentProc, size_t index);
282  virtual int64_t communication_node_count_proc() const;
283  virtual void node_communication_map(MapVector &map, std::vector<int> &proc);
284  virtual void owning_processor(int *owner, int64_t num_node);
285 
286  /**
287  * Fill the passed in 'map' argument with the node map
288  * "map[local_position] = global_id" for the nodes on this
289  * processor.
290  */
291  virtual void node_map(MapVector &map) const;
292  virtual void node_map(Ioss::IntVector &map) const;
293 
294  /**
295  * Fill the passed in 'map' argument with the element map
296  * "map[local_position] = global_id" for the elements on this
297  * processor in block "block_number".
298  */
299  virtual void element_map(int64_t block_number, MapVector &map) const;
300  virtual void element_map(int64_t block_number, Ioss::IntVector &map) const;
301 
302  /**
303  * Fill the passed in 'map' argument with the element map
304  * "map[local_position] = global_id" for all elements on this
305  * processor
306  */
307  virtual void element_map(MapVector &map) const;
308  virtual void element_map(Ioss::IntVector &map) const;
309 
310  /**
311  * Fill the passed in 'map' argument with the element map pair
312  * "map[local_position] = element global_id" and
313  * "map[local_position+1] = element local face id (0-based)" for
314  * all elements on the current processor having a face on the
315  * surface defined by ShellLocation.
316  */
317  void element_surface_map(ShellLocation loc, MapVector &map) const;
318 
319  /**
320  * Return the connectivity for the elements on this processor in
321  * the block with id 'block_number'. If the elements in this block
322  * have 'npe' nodes per element, then the first 'npe' entries in
323  * the 'conn' vector will be the nodal connectivity for the first
324  * element; the next 'npe' entries are the nodal connectivity for
325  * the second element. The 'connect' vector will be resized to the
326  * size required to contain the nodal connectivity for the
327  * specified block; all information in 'connect' will be overwritten.
328  */
329  void connectivity(int64_t block_number, Ioss::Int64Vector &connect) const;
330  void connectivity(int64_t block_number, Ioss::IntVector &connect) const;
331  void connectivity(int64_t block_number, int64_t *connect) const;
332  virtual void connectivity(int64_t block_number, int *connect) const;
333 
334  /**
335  * Return the coordinates for all nodes on this processor. The
336  * first 3 entries in the 'coord' vector are the x, y, and z
337  * coordinates of the first node, etc. The 'coord' vector will be
338  * resized to the size required to contain the nodal coordinates;
339  * all information in 'coord' will be overwritten.
340  */
341  virtual void coordinates(std::vector<double> &coord) const;
342  virtual void coordinates(double *coord) const;
343 
344  /**
345  * Return the coordinates for all nodes on this processor in
346  * separate vectors. The vectors will be resized to the size
347  * required to contain the nodal coordinates; all information in
348  * the vectors will be overwritten.
349  */
350  virtual void coordinates(std::vector<double> &x, std::vector<double> &y,
351  std::vector<double> &z) const;
352 
353  /**
354  * Return the coordinates for componenet 'comp' (1=x, 2=y, 3=z)
355  * for all nodes on this processor. The
356  * vector will be resized to the size required to contain the
357  * nodal coordinates; all information in the vector will be
358  * overwritten.
359  * It is an error to request the coordinates via this function
360  * if a rotation is defined.
361  */
362  virtual void coordinates(int component, std::vector<double> &xyz) const;
363 
364  /**
365  * Return the coordinates for componenet 'comp' (1=x, 2=y, 3=z, 0=all)
366  * for all nodes in zone `zone` on this processor. The
367  * vector will be resized to the size required to contain the
368  * nodal coordinates; all information in the vector will be
369  * overwritten.
370  * It is an error to request the coordinates via this function
371  * if a rotation is defined.
372  */
373  void coordinates(int component, int zone, double *coord) const;
374 
375  /**
376  * Return the list of the face/ordinal pairs
377  * "elem_sides[local_position] = element global_id" and
378  * "elem_sides[local_position+1] = element local face id (0-based)"
379  * for the faces in sideset 'id' on this
380  * processor. The 'elem_sides' vector will be resized to the size
381  * required to contain the list. The element ids are global ids,
382  * the side ordinal is 0-based.
383  */
384  virtual void sideset_elem_sides(int64_t id, Ioss::Int64Vector &elem_sides) const;
385 
386  virtual std::vector<std::string> sideset_touching_blocks(int64_t set_id) const;
387 
388  int64_t get_num_x() const { return numX; }
389  int64_t get_num_y() const { return numY; }
390  int64_t get_num_z() const { return numZ; }
391 
393  {
394  return variableCount.find(type) != variableCount.end() ? variableCount.find(type)->second : 0;
395  }
396 
397  private:
398  template <typename INT> void raw_element_map(int64_t block_number, std::vector<INT> &map) const;
399  template <typename INT> void raw_element_map(std::vector<INT> &map) const;
400  template <typename INT> void raw_connectivity(int64_t block_number, INT *connect) const;
401 
402  GeneratedMesh(const GeneratedMesh &);
404 
405  void set_variable_count(const std::string &type, size_t count);
406  void parse_options(const std::vector<std::string> &groups);
407  void show_parameters() const;
408  void initialize();
409 
410  std::vector<ShellLocation> sidesets;
411  std::array<std::array<double, 3>, 3> rotmat;
412  size_t numX{0}, numY{0}, numZ{0};
413  size_t myNumZ{0}, myStartZ{0};
414 
415  size_t processorCount{1};
416  size_t myProcessor{0};
417 
418  size_t timestepCount{0};
419  std::map<Ioss::EntityType, size_t> variableCount;
420 
421  double offX{0}, offY{0}, offZ{0}; /** Offsets in X, Y, and Z directions */
422  double sclX{1}, sclY{1}, sclZ{1}; /** Scale in X, Y, and Z directions
423  * location of node at (i,j,k)
424  * position is (sclX*i+offX,
425  * sclY*i+offY, sclZ*i+offZ) */
426  bool doRotation{false};
427  };
428 } // namespace Iogs
429 #endif
virtual int64_t node_count_proc() const
Definition: Iogs_GeneratedMesh.C:348
void set_bbox(double xmin, double ymin, double zmin, double xmax, double ymax, double zmax)
Definition: Iogs_GeneratedMesh.C:141
int64_t timestep_count() const
Definition: Iogs_GeneratedMesh.h:258
void set_offset(double off_x, double off_y, double off_z)
Definition: Iogs_GeneratedMesh.C:179
void build_node_map(Ioss::Int64Vector &map, std::vector< int > &proc, int64_t slab, size_t slabOffset, size_t adjacentProc, size_t index)
Definition: Iogs_GeneratedMesh.C:469
void parse_options(const std::vector< std::string > &groups)
Definition: Iogs_GeneratedMesh.C:186
ShellLocation
Definition: Iogs_GeneratedMesh.h:52
double sclZ
Definition: Iogs_GeneratedMesh.h:422
virtual void element_map(int64_t block_number, MapVector &map) const
Definition: Iogs_GeneratedMesh.C:502
void set_variable_count(const std::string &type, size_t count)
Definition: Iogs_GeneratedMesh.C:857
size_t myProcessor
Definition: Iogs_GeneratedMesh.h:416
virtual void node_communication_map(MapVector &map, std::vector< int > &proc)
Definition: Iogs_GeneratedMesh.C:479
void show_parameters() const
Definition: Iogs_GeneratedMesh.C:315
virtual int64_t communication_node_count_proc() const
Definition: Iogs_GeneratedMesh.C:445
virtual int64_t sideset_count() const
Definition: Iogs_GeneratedMesh.C:352
Ioss::IJK_t block_range(int64_t) const
Definition: Iogs_GeneratedMesh.h:241
int64_t sideset_side_count(int64_t id) const
Definition: Iogs_GeneratedMesh.C:381
virtual std::vector< std::string > sideset_touching_blocks(int64_t set_id) const
Definition: Iogs_GeneratedMesh.C:851
double offX
Definition: Iogs_GeneratedMesh.h:421
size_t numY
Definition: Iogs_GeneratedMesh.h:412
std::vector< int > IntVector
Definition: Ioss_CodeTypes.h:43
A namespace for the gen_struc database format.
Definition: Iogs_DatabaseIO.C:129
std::vector< ShellLocation > sidesets
Definition: Iogs_GeneratedMesh.h:410
Definition: Iogs_GeneratedMesh.h:52
int64_t add_sideset(ShellLocation loc)
Definition: Iogs_GeneratedMesh.C:135
virtual void node_map(MapVector &map) const
Definition: Iogs_GeneratedMesh.C:431
Definition: Iogs_GeneratedMesh.h:52
void initialize()
Definition: Iogs_GeneratedMesh.C:80
GeneratedMesh & operator=(const GeneratedMesh &)
virtual int64_t element_count_proc() const
Definition: Iogs_GeneratedMesh.C:360
void set_rotation(const std::string &axis, double angle_degrees)
Definition: Iogs_GeneratedMesh.C:880
virtual void sideset_elem_sides(int64_t id, Ioss::Int64Vector &elem_sides) const
Definition: Iogs_GeneratedMesh.C:843
std::map< Ioss::EntityType, size_t > variableCount
Definition: Iogs_GeneratedMesh.h:419
bool set_id(const Ioss::GroupingEntity *entity, ex_entity_type type, Ioex::EntityIdSet *idset)
Definition: Ioex_Utils.C:277
int64_t get_num_z() const
Definition: Iogs_GeneratedMesh.h:390
virtual int64_t sideset_side_count_proc(int64_t id) const
Definition: Iogs_GeneratedMesh.C:397
int64_t get_num_y() const
Definition: Iogs_GeneratedMesh.h:389
virtual int64_t element_count() const
Definition: Iogs_GeneratedMesh.C:354
std::array< int, 3 > IJK_t
Definition: Ioss_CodeTypes.h:46
virtual void owning_processor(int *owner, int64_t num_node)
Definition: Iogs_GeneratedMesh.C:455
void element_surface_map(ShellLocation loc, MapVector &map) const
Definition: Iogs_GeneratedMesh.C:547
size_t myStartZ
Definition: Iogs_GeneratedMesh.h:413
virtual void coordinates(std::vector< double > &coord) const
Definition: Iogs_GeneratedMesh.C:626
Definition: Iogs_GeneratedMesh.h:52
Definition: Iogs_GeneratedMesh.h:49
std::vector< int64_t > Int64Vector
Definition: Ioss_CodeTypes.h:44
virtual std::pair< std::string, int > topology_type(int64_t block_number) const
Definition: Iogs_GeneratedMesh.C:425
std::array< std::array< double, 3 >, 3 > rotmat
Definition: Iogs_GeneratedMesh.h:411
size_t myNumZ
Definition: Iogs_GeneratedMesh.h:413
virtual int64_t structured_block_count() const
Definition: Iogs_GeneratedMesh.C:350
Definition: Iogs_GeneratedMesh.h:52
size_t timestepCount
Definition: Iogs_GeneratedMesh.h:418
int INT
Definition: Ioss_StructuredBlock.h:53
Ioss::IJK_t block_offset_proc(int64_t id) const
virtual int64_t node_count() const
Definition: Iogs_GeneratedMesh.C:346
void raw_element_map(int64_t block_number, std::vector< INT > &map) const
Definition: Iogs_GeneratedMesh.C:513
GeneratedMesh()
Definition: Iogs_GeneratedMesh.C:76
int64_t get_num_x() const
Definition: Iogs_GeneratedMesh.h:388
size_t get_variable_count(Ioss::EntityType type) const
Definition: Iogs_GeneratedMesh.h:392
size_t numX
Definition: Iogs_GeneratedMesh.h:412
void connectivity(int64_t block_number, Ioss::Int64Vector &connect) const
Definition: Iogs_GeneratedMesh.C:784
Definition: Iogs_GeneratedMesh.h:52
bool doRotation
Definition: Iogs_GeneratedMesh.h:426
EntityType
The particular type of GroupingEntity.
Definition: Ioss_EntityType.h:39
Definition: Iogs_GeneratedMesh.h:52
std::vector< int64_t > MapVector
Definition: Iogs_GeneratedMesh.h:47
size_t processorCount
Definition: Iogs_GeneratedMesh.h:415
double offY
Definition: Iogs_GeneratedMesh.h:421
Ioss::IJK_t block_range_proc(int64_t id) const
double sclX
Definition: Iogs_GeneratedMesh.h:422
virtual ~GeneratedMesh()
void raw_connectivity(int64_t block_number, INT *connect) const
Definition: Iogs_GeneratedMesh.C:811
size_t numZ
Definition: Iogs_GeneratedMesh.h:412
double offZ
Definition: Iogs_GeneratedMesh.h:421
double sclY
Definition: Iogs_GeneratedMesh.h:422
void set_scale(double scl_x, double scl_y, double scl_z)
Definition: Iogs_GeneratedMesh.C:172