Sierra Toolkit  Version of the Day
GridFixture.cpp
1 /*------------------------------------------------------------------------*/
2 /* Copyright 2010, 2011 Sandia Corporation. */
3 /* Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive */
4 /* license for use of this work by or on behalf of the U.S. Government. */
5 /* Export of this program may require a license from the */
6 /* United States Government. */
7 /*------------------------------------------------------------------------*/
8 
9 #include <stk_mesh/fixtures/GridFixture.hpp>
10 
11 #include <Shards_BasicTopologies.hpp>
12 
13 #include <stk_util/parallel/Parallel.hpp>
14 
15 #include <stk_mesh/base/MetaData.hpp>
16 #include <stk_mesh/base/BulkData.hpp>
17 #include <stk_mesh/base/Entity.hpp>
18 #include <stk_mesh/base/GetEntities.hpp>
19 
20 #include <stk_mesh/fem/FEMMetaData.hpp>
21 #include <stk_mesh/fem/FEMHelpers.hpp>
22 
23 /*
24 The following fixture creates the mesh below
25 1-16 Quadrilateral<4>
26 17-41 Nodes
27 
28 17---18---19---20---21
29 | 1 | 2 | 3 | 4 |
30 22---23---24---25---26
31 | 5 | 6 | 7 | 8 |
32 27---28---29---30---31
33 | 9 | 10 | 11 | 12 |
34 32---33---34---35---36
35 | 13 | 14 | 15 | 16 |
36 37---38---39---40---41
37 */
38 
39 namespace stk_classic {
40 namespace mesh {
41 namespace fixtures {
42 
43 
44 GridFixture::GridFixture(stk_classic::ParallelMachine pm)
45  : m_spatial_dimension(2)
46  , m_fem_meta( m_spatial_dimension, fem::entity_rank_names(m_spatial_dimension) )
47  , m_bulk_data( stk_classic::mesh::fem::FEMMetaData::get_meta_data(m_fem_meta) , pm )
48  , m_quad_part( fem::declare_part<shards::Quadrilateral<4> >(m_fem_meta, "quad_part") )
49  , m_dead_part( m_fem_meta.declare_part("dead_part"))
50 {}
51 
52 GridFixture::~GridFixture()
53 { }
54 
55 void GridFixture::generate_grid()
56 {
57  const unsigned num_nodes = 25;
58  const unsigned num_quad_faces = 16;
59  const unsigned p_rank = m_bulk_data.parallel_rank();
60  const unsigned p_size = m_bulk_data.parallel_size();
61  const EntityRank element_rank = m_fem_meta.element_rank();
62  std::vector<Entity*> all_entities;
63 
64  // assign ids, quads, nodes, then shells
65  // (we need this order to be this way in order for our connectivity setup to work)
66  std::vector<unsigned> quad_face_ids(num_quad_faces);
67  std::vector<unsigned> node_ids(num_nodes);
68  {
69  unsigned curr_id = 1;
70  for (unsigned i = 0 ; i < num_quad_faces; ++i, ++curr_id) {
71  quad_face_ids[i] = curr_id;
72  }
73  for (unsigned i = 0 ; i < num_nodes; ++i, ++curr_id) {
74  node_ids[i] = curr_id;
75  }
76  }
77 
78  // Note: This block of code would normally be replaced with a call to stk_io
79  // to generate the mesh.
80 
81  // declare entities such that entity_id - 1 is the index of the
82  // entity in the all_entities vector
83  {
84  const PartVector no_parts;
85  const unsigned first_quad = (p_rank * num_quad_faces) / p_size;
86  const unsigned end_quad = ((p_rank + 1) * num_quad_faces) / p_size;
87 
88  // declare faces
89  PartVector face_parts;
90  face_parts.push_back(&m_quad_part);
91  const unsigned num_nodes_per_quad = 4;
92  // (right-hand rule) counterclockwise:
93  const int stencil_for_4x4_quad_mesh[num_nodes_per_quad] = {0, 5, 1, -5};
94  for (unsigned i = first_quad; i < end_quad; ++i) {
95 
96  unsigned face_id = quad_face_ids[i];
97  unsigned row = (face_id - 1) / num_nodes_per_quad;
98 
99  Entity& face = m_bulk_data.declare_entity(element_rank, face_id, face_parts);
100 
101  unsigned node_id = num_quad_faces + face_id + row;
102 
103  for (unsigned chg_itr = 0; chg_itr < num_nodes_per_quad; ++chg_itr) {
104  node_id += stencil_for_4x4_quad_mesh[chg_itr];
105  Entity& node = m_bulk_data.declare_entity(fem::FEMMetaData::NODE_RANK, node_id, no_parts);
106  m_bulk_data.declare_relation( face , node , chg_itr);
107  }
108  }
109  }
110 }
111 
112 } // fixtures
113 } // mesh
114 } // stk
115 
Part & declare_part(FEMMetaData &meta_data, const std::string &name)
Declare a part with a given cell topology. This is just a convenient function that wraps FEMMetaData&#39;...
Definition: FEMHelpers.hpp:93
Sierra Toolkit.
MPI_Comm ParallelMachine
Definition: Parallel.hpp:32
std::vector< Part *> PartVector
Collections of parts are frequently maintained as a vector of Part pointers.
Definition: Types.hpp:31