UnitTestGridMeshFixture.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 <unit_tests/UnitTestGridMeshFixture.hpp>
00010 
00011 #include <unit_tests/stk_utest_macros.hpp>
00012 #include <Shards_BasicTopologies.hpp>
00013 
00014 #include <stk_util/parallel/Parallel.hpp>
00015 
00016 #include <stk_mesh/base/MetaData.hpp>
00017 #include <stk_mesh/base/BulkData.hpp>
00018 #include <stk_mesh/base/Entity.hpp>
00019 #include <stk_mesh/base/GetEntities.hpp>
00020 
00021 #include <stk_mesh/fem/EntityTypes.hpp>
00022 #include <stk_mesh/fem/TopologyHelpers.hpp>
00023 
00024 using namespace stk;
00025 using namespace stk::mesh;
00026 
00027 /*
00028 The following fixture creates the mesh below on proc 0
00029 1-16 Quadrilateral<4>
00030 17-41 Nodes
00031 42-45 ShellLine<2>
00032 
00033 17---18---19---20---21
00034 |  1 |  2 |  3 || 4  |
00035 22---23---24---25---26
00036 |  5 |  6 |  7 ||  8 |
00037 27---28---29---30---31
00038 |  9 | 10 | 11 || 12 |
00039 32---33---34---35---36
00040 | 13 | 14 | 15 || 16 |
00041 37---38---39---40---41
00042 */
00043 
00044 GridMeshFixture::GridMeshFixture(ParallelMachine pm)
00045   : m_meta_data( fem_entity_type_names() )
00046   , m_bulk_data( m_meta_data , pm , 100 )
00047   , m_quad_part( m_meta_data.declare_part("quad_part", Face))
00048   , m_shell_part( m_meta_data.declare_part("shell_part", Face))
00049   , m_closure()
00050   , m_node_ids()
00051   , m_quad_face_ids()
00052   , m_shell_face_ids()
00053 {
00054   set_cell_topology<shards::Quadrilateral<4> >(m_quad_part);
00055   set_cell_topology<shards::ShellLine<2> >(m_shell_part);
00056 
00057   m_meta_data.commit();
00058 
00059   // Add shells from nodes 20 to 40
00060   // shells are considered to be a Face
00061 
00062   m_bulk_data.modification_begin();
00063   generate_grid();
00064   m_bulk_data.modification_end();
00065 }
00066 
00067 GridMeshFixture::~GridMeshFixture()
00068 { }
00069 
00070 void GridMeshFixture::generate_grid()
00071 {
00072   const unsigned num_nodes = 25;
00073   const unsigned num_quad_faces = 16;
00074   const unsigned num_shell_faces = 4;
00075   const unsigned p_rank = m_bulk_data.parallel_rank();
00076   std::vector<Entity*> all_entities;
00077 
00078   // we don't want anything on any of the processes expect rank 0
00079   if (p_rank != 0) {
00080     return;
00081   }
00082 
00083   m_node_ids.resize( num_nodes );
00084   m_quad_face_ids.resize( num_quad_faces );
00085   m_shell_face_ids.resize( num_shell_faces );
00086 
00087   // assign ids, quads, nodes, then shells
00088   // (we need this order to be this way in order for our connectivity setup to work)
00089   {
00090     unsigned curr_id = 1;
00091     for (unsigned  i = 0 ; i < num_quad_faces; ++i, ++curr_id) {
00092       m_quad_face_ids[i] = curr_id;
00093     }
00094     for (unsigned  i = 0 ; i < num_nodes; ++i, ++curr_id) {
00095       m_node_ids[i] = curr_id;
00096     }
00097     for (unsigned  i = 0 ; i < num_shell_faces; ++i, ++curr_id) {
00098       m_shell_face_ids[i] = curr_id;
00099     }
00100   }
00101 
00102   // declare entities such that entity_id - 1 is the index of the
00103   // entity in the all_entities vector
00104   std::vector<Entity*> quad_faces;
00105   std::vector<Entity*> nodes;
00106   std::vector<Entity*> shell_faces;
00107   {
00108     const PartVector no_parts;
00109 
00110     // declare faces
00111     PartVector face_parts;
00112     face_parts.push_back(&m_quad_part);
00113     for (unsigned i = 0; i < num_quad_faces; ++i) {
00114       Entity& new_face = m_bulk_data.declare_entity(Face, m_quad_face_ids[i], face_parts);
00115       quad_faces.push_back(&new_face);
00116       all_entities.push_back(&new_face);
00117       switch (m_quad_face_ids[i]) {
00118       case 6:
00119       case 7:
00120       case 10:
00121       case 11:
00122       case 14:
00123       case 15:
00124         m_closure.push_back(&new_face);
00125       default:
00126         break;
00127       }
00128     }
00129 
00130     // declare nodes
00131     for (unsigned i = 0; i < num_nodes; ++i) {
00132       Entity& new_node = m_bulk_data.declare_entity(Node, m_node_ids[i], no_parts);
00133       nodes.push_back(&new_node);
00134       all_entities.push_back(&new_node);
00135       switch (m_node_ids[i]) {
00136       case 23:
00137       case 24:
00138       case 25:
00139       case 28:
00140       case 29:
00141       case 30:
00142       case 33:
00143       case 34:
00144       case 35:
00145       case 38:
00146       case 39:
00147       case 40:
00148         m_closure.push_back(&new_node);
00149       default:
00150         break;
00151       }
00152     }
00153 
00154     // declare shell faces
00155     PartVector shell_parts;
00156     shell_parts.push_back(&m_shell_part);
00157     for (unsigned i = 0; i < num_shell_faces; ++i) {
00158       Entity& new_shell = m_bulk_data.declare_entity(Face, m_shell_face_ids[i], shell_parts);
00159       all_entities.push_back(&new_shell);
00160       shell_faces.push_back(&new_shell);
00161     }
00162   }
00163 
00164   // sort the closure
00165   std::sort(m_closure.begin(), m_closure.end(), stk::mesh::EntityLess());
00166 
00167   // declare relationships
00168   {
00169     // declare quad relationships
00170     for (unsigned i = 0; i < num_quad_faces; ++i) {
00171       Entity& face = *(quad_faces[i]);
00172       unsigned face_id = m_quad_face_ids[i];
00173       unsigned row = (face_id - 1) / 4;
00174 
00175       unsigned node_id = num_quad_faces + face_id + row;
00176       int chg_list[4] = {0, 5, 1, -5}; // (right-hand rule) counterclockwise
00177       for (unsigned chg_itr = 0; chg_itr < 4; ++chg_itr) {
00178         node_id += chg_list[chg_itr];
00179         Entity& node = *(all_entities[node_id - 1]);
00180         m_bulk_data.declare_relation( face , node , chg_itr);
00181       }
00182     }
00183 
00184     // declare shell relationships
00185     unsigned node_list[5] = {20, 25, 30, 35, 40};
00186     for (unsigned i = 0; i < num_shell_faces; ++i) {
00187       Entity& shell = *(shell_faces[i]);
00188       Entity& node1 = *all_entities[node_list[i] - 1];
00189       Entity& node2 = *all_entities[node_list[i+1] - 1];
00190       m_bulk_data.declare_relation(shell, node1, 0);
00191       m_bulk_data.declare_relation(shell, node2, 1);
00192     }
00193   }
00194 }

Generated on Tue Jul 13 09:27:32 2010 for Sierra Toolkit by  doxygen 1.4.7