|
Sierra Toolkit
Version of the Day
|
00001 /*------------------------------------------------------------------------*/ 00002 /* Copyright 2010, 2011 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/FEMMetaData.hpp> 00021 #include <stk_mesh/fem/FEMHelpers.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_classic { 00040 namespace mesh { 00041 namespace fixtures { 00042 00043 00044 GridFixture::GridFixture(stk_classic::ParallelMachine pm) 00045 : m_spatial_dimension(2) 00046 , m_fem_meta( m_spatial_dimension, fem::entity_rank_names(m_spatial_dimension) ) 00047 , m_bulk_data( stk_classic::mesh::fem::FEMMetaData::get_meta_data(m_fem_meta) , pm ) 00048 , m_quad_part( fem::declare_part<shards::Quadrilateral<4> >(m_fem_meta, "quad_part") ) 00049 , m_dead_part( m_fem_meta.declare_part("dead_part")) 00050 {} 00051 00052 GridFixture::~GridFixture() 00053 { } 00054 00055 void GridFixture::generate_grid() 00056 { 00057 const unsigned num_nodes = 25; 00058 const unsigned num_quad_faces = 16; 00059 const unsigned p_rank = m_bulk_data.parallel_rank(); 00060 const unsigned p_size = m_bulk_data.parallel_size(); 00061 const EntityRank element_rank = m_fem_meta.element_rank(); 00062 std::vector<Entity*> all_entities; 00063 00064 // assign ids, quads, nodes, then shells 00065 // (we need this order to be this way in order for our connectivity setup to work) 00066 std::vector<unsigned> quad_face_ids(num_quad_faces); 00067 std::vector<unsigned> node_ids(num_nodes); 00068 { 00069 unsigned curr_id = 1; 00070 for (unsigned i = 0 ; i < num_quad_faces; ++i, ++curr_id) { 00071 quad_face_ids[i] = curr_id; 00072 } 00073 for (unsigned i = 0 ; i < num_nodes; ++i, ++curr_id) { 00074 node_ids[i] = curr_id; 00075 } 00076 } 00077 00078 // Note: This block of code would normally be replaced with a call to stk_io 00079 // to generate the mesh. 00080 00081 // declare entities such that entity_id - 1 is the index of the 00082 // entity in the all_entities vector 00083 { 00084 const PartVector no_parts; 00085 const unsigned first_quad = (p_rank * num_quad_faces) / p_size; 00086 const unsigned end_quad = ((p_rank + 1) * num_quad_faces) / p_size; 00087 00088 // declare faces 00089 PartVector face_parts; 00090 face_parts.push_back(&m_quad_part); 00091 const unsigned num_nodes_per_quad = 4; 00092 // (right-hand rule) counterclockwise: 00093 const int stencil_for_4x4_quad_mesh[num_nodes_per_quad] = {0, 5, 1, -5}; 00094 for (unsigned i = first_quad; i < end_quad; ++i) { 00095 00096 unsigned face_id = quad_face_ids[i]; 00097 unsigned row = (face_id - 1) / num_nodes_per_quad; 00098 00099 Entity& face = m_bulk_data.declare_entity(element_rank, face_id, face_parts); 00100 00101 unsigned node_id = num_quad_faces + face_id + row; 00102 00103 for (unsigned chg_itr = 0; chg_itr < num_nodes_per_quad; ++chg_itr) { 00104 node_id += stencil_for_4x4_quad_mesh[chg_itr]; 00105 Entity& node = m_bulk_data.declare_entity(fem::FEMMetaData::NODE_RANK, node_id, no_parts); 00106 m_bulk_data.declare_relation( face , node , chg_itr); 00107 } 00108 } 00109 } 00110 } 00111 00112 } // fixtures 00113 } // mesh 00114 } // stk 00115