Sierra Toolkit Version of the Day
GridFixture.cpp
00001 /*------------------------------------------------------------------------*/
00002 /*                 Copyright 2010 Sandia Corporation.                     */
00003 /*  Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive   */
00004 /*  license for use of this work by or on behalf of the U.S. Government.  */
00005 /*  Export of this program may require a license from the                 */
00006 /*  United States Government.                                             */
00007 /*------------------------------------------------------------------------*/
00008 
00009 #include <stk_mesh/fixtures/GridFixture.hpp>
00010 
00011 #include <Shards_BasicTopologies.hpp>
00012 
00013 #include <stk_util/parallel/Parallel.hpp>
00014 
00015 #include <stk_mesh/base/MetaData.hpp>
00016 #include <stk_mesh/base/BulkData.hpp>
00017 #include <stk_mesh/base/Entity.hpp>
00018 #include <stk_mesh/base/GetEntities.hpp>
00019 
00020 #include <stk_mesh/fem/EntityRanks.hpp>
00021 #include <stk_mesh/fem/TopologyHelpers.hpp>
00022 
00023 /*
00024 The following fixture creates the mesh below
00025 1-16 Quadrilateral<4>
00026 17-41 Nodes
00027 
00028 17---18---19---20---21
00029 |  1 |  2 |  3 |  4 |
00030 22---23---24---25---26
00031 |  5 |  6 |  7 |  8 |
00032 27---28---29---30---31
00033 |  9 | 10 | 11 | 12 |
00034 32---33---34---35---36
00035 | 13 | 14 | 15 | 16 |
00036 37---38---39---40---41
00037 */
00038 
00039 namespace stk {
00040 namespace mesh {
00041 namespace fixtures {
00042 
00043 
00044 GridFixture::GridFixture(stk::ParallelMachine pm)
00045   : m_spatial_dimension(2)
00046   , m_meta_data( TopologicalMetaData::entity_rank_names(m_spatial_dimension) )
00047   , m_bulk_data( m_meta_data , pm )
00048   , m_top_data( m_meta_data, m_spatial_dimension )
00049   , m_quad_part( m_top_data.declare_part<shards::Quadrilateral<4> >("quad_part" ) )
00050   , m_dead_part( m_meta_data.declare_part("dead_part"))
00051 {
00052 }
00053 
00054 GridFixture::~GridFixture()
00055 { }
00056 
00057 void GridFixture::generate_grid()
00058 {
00059   const unsigned num_nodes = 25;
00060   const unsigned num_quad_faces = 16;
00061   const unsigned p_rank = m_bulk_data.parallel_rank();
00062   const unsigned p_size = m_bulk_data.parallel_size();
00063   std::vector<Entity*> all_entities;
00064 
00065   // assign ids, quads, nodes, then shells
00066   // (we need this order to be this way in order for our connectivity setup to  work)
00067   std::vector<unsigned> quad_face_ids(num_quad_faces);
00068   std::vector<unsigned> node_ids(num_nodes);
00069   {
00070     unsigned curr_id = 1;
00071     for (unsigned  i = 0 ; i < num_quad_faces; ++i, ++curr_id) {
00072       quad_face_ids[i] = curr_id;
00073     }
00074     for (unsigned  i = 0 ; i < num_nodes; ++i, ++curr_id) {
00075       node_ids[i] = curr_id;
00076     }
00077   }
00078 
00079   // Note:  This block of code would normally be replaced with a call to stk_io
00080   // to generate the mesh.
00081 
00082   // declare entities such that entity_id - 1 is the index of the
00083   // entity in the all_entities vector
00084   {
00085     const PartVector no_parts;
00086     const unsigned first_quad = (p_rank * num_quad_faces) / p_size;
00087     const unsigned end_quad = ((p_rank + 1) * num_quad_faces) / p_size;
00088 
00089     // declare faces
00090     PartVector face_parts;
00091     face_parts.push_back(&m_quad_part);
00092     const unsigned num_nodes_per_quad = 4;
00093     // (right-hand rule) counterclockwise:
00094     const int stencil_for_4x4_quad_mesh[num_nodes_per_quad] = {0, 5, 1, -5};
00095     for (unsigned i = first_quad; i < end_quad; ++i) {
00096 
00097       unsigned face_id = quad_face_ids[i];
00098       unsigned row = (face_id - 1) / num_nodes_per_quad;
00099 
00100       Entity& face = m_bulk_data.declare_entity(m_top_data.element_rank, face_id, face_parts);
00101 
00102       unsigned node_id = num_quad_faces + face_id + row;
00103 
00104       for (unsigned chg_itr = 0; chg_itr < num_nodes_per_quad; ++chg_itr) {
00105         node_id += stencil_for_4x4_quad_mesh[chg_itr];
00106         Entity& node = m_bulk_data.declare_entity(m_top_data.node_rank, node_id, no_parts);
00107         m_bulk_data.declare_relation( face , node , chg_itr);
00108       }
00109     }
00110   }
00111 }
00112 
00113 } // fixtures
00114 } // mesh
00115 } // stk
00116 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends