UnitTestBoxMeshFixture.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 
00010 #include <stk_mesh/base/FieldData.hpp>
00011 #include <unit_tests/UnitTestBoxMeshFixture.hpp>
00012 #include <unit_tests/stk_utest_macros.hpp>
00013 
00014 BoxMeshFixture::~BoxMeshFixture()
00015 {}
00016 
00017 BoxMeshFixture::BoxMeshFixture( stk::ParallelMachine pm )
00018   : m_meta_data( stk::mesh::fem_entity_type_names() ),
00019     m_bulk_data( m_meta_data , pm ),
00020     m_elem_block( m_meta_data.declare_part("block1", stk::mesh::Element) ),
00021     m_coord_field( m_meta_data.declare_field<CoordFieldType>("Coordinates") ),
00022     m_coord_gather_field(
00023       m_meta_data.declare_field<CoordGatherFieldType>("GatherCoordinates") ),
00024     m_quad_field( m_meta_data.declare_field<QuadFieldType>("Quad") ),
00025     m_basis_field( m_meta_data.declare_field<BasisFieldType>("Basis") )
00026 {
00027   typedef shards::Hexahedron<8> Hex8 ;
00028   enum { SpatialDim = 3 };
00029   enum { NodesPerElem = Hex8::node_count };
00030 
00031   // Set topology of the element block part
00032   stk::mesh::set_cell_topology<shards::Hexahedron<8> >(m_elem_block);
00033 
00034   //put coord-field on all nodes:
00035   stk::mesh::put_field( m_coord_field, stk::mesh::Node, m_meta_data.universal_part(), SpatialDim );
00036 
00037   //put coord-gather-field on all elements:
00038   stk::mesh::put_field( m_coord_gather_field, stk::mesh::Element, m_meta_data.universal_part(), NodesPerElem);
00039 
00040   // Field relation so coord-gather-field on elements points 
00041   // to coord-field of the element's nodes
00042   m_meta_data.declare_field_relation( m_coord_gather_field, stk::mesh::element_node_stencil<shards::Hexahedron<8> >, m_coord_field);
00043 
00044   // Meta data is complete
00045   m_meta_data.commit();
00046 
00047   STKUNIT_EXPECT_TRUE( NULL != stk::mesh::ElementNode::tag().name() );
00048   STKUNIT_EXPECT_TRUE( NULL != stk::mesh::QuadratureTag::tag().name() );
00049   STKUNIT_EXPECT_TRUE( NULL != stk::mesh::BasisTag::tag().name() );
00050 }
00051 
00052 void BoxMeshFixture::fill_mesh()
00053 {
00054   const unsigned p_size = m_bulk_data.parallel_size();
00055   const unsigned p_rank = m_bulk_data.parallel_rank();
00056   const unsigned num_elems = 8 ;
00057 
00058   for ( int iz = 0 ; iz < 3 ; ++iz ) {
00059   for ( int iy = 0 ; iy < 3 ; ++iy ) {
00060   for ( int ix = 0 ; ix < 3 ; ++ix ) {
00061     m_node_id[iz][iy][ix] = 1 + ix + 3 * ( iy + 3 * iz );
00062     m_node_coord[iz][iy][ix][0] = ix ;
00063     m_node_coord[iz][iy][ix][1] = iy ;
00064     m_node_coord[iz][iy][ix][2] = - iz ;
00065   }
00066   }
00067   }
00068 
00069   const unsigned beg_elem = ( num_elems * p_rank ) / p_size ;
00070   const unsigned end_elem = ( num_elems * ( p_rank + 1 ) ) / p_size ;
00071 
00072   m_bulk_data.modification_begin();
00073 
00074   unsigned elem = 0 ;
00075   for ( int iz = 0 ; iz < 2 ; ++iz ) {
00076   for ( int iy = 0 ; iy < 2 ; ++iy ) {
00077   for ( int ix = 0 ; ix < 2 ; ++ix , ++elem ) {
00078     if ( beg_elem <= elem && elem < end_elem ) {
00079       stk::mesh::EntityId elem_id = 1 + ix + 3 * ( iy + 3 * iz );
00080       stk::mesh::EntityId elem_node[8] ;
00081       Scalar * node_coord[8] ;
00082 
00083       elem_node[0] = m_node_id[iz  ][iy  ][ix  ] ;
00084       elem_node[1] = m_node_id[iz  ][iy  ][ix+1] ;
00085       elem_node[2] = m_node_id[iz+1][iy  ][ix+1] ;
00086       elem_node[3] = m_node_id[iz+1][iy  ][ix  ] ;
00087       elem_node[4] = m_node_id[iz  ][iy+1][ix  ] ;
00088       elem_node[5] = m_node_id[iz  ][iy+1][ix+1] ;
00089       elem_node[6] = m_node_id[iz+1][iy+1][ix+1] ;
00090       elem_node[7] = m_node_id[iz+1][iy+1][ix  ] ;
00091 
00092       node_coord[0] = m_node_coord[iz  ][iy  ][ix  ] ;
00093       node_coord[1] = m_node_coord[iz  ][iy  ][ix+1] ;
00094       node_coord[2] = m_node_coord[iz+1][iy  ][ix+1] ;
00095       node_coord[3] = m_node_coord[iz+1][iy  ][ix  ] ;
00096       node_coord[4] = m_node_coord[iz  ][iy+1][ix  ] ;
00097       node_coord[5] = m_node_coord[iz  ][iy+1][ix+1] ;
00098       node_coord[6] = m_node_coord[iz+1][iy+1][ix+1] ;
00099       node_coord[7] = m_node_coord[iz+1][iy+1][ix  ] ;
00100 
00101       stk::mesh::Entity& element = stk::mesh::declare_element( m_bulk_data, m_elem_block, elem_id, elem_node);
00102 
00103       stk::mesh::PairIterRelation rel = element.relations(stk::mesh::Node);
00104 
00105       for(int i=0; i< 8 ; ++i ) {
00106         stk::mesh::Entity& node = *rel[i].entity();
00107         Scalar* data = stk::mesh::field_data( m_coord_field, node);
00108         data[0] = node_coord[i][0];
00109         data[1] = node_coord[i][1];
00110         data[2] = node_coord[i][2];
00111       }
00112     }
00113   }
00114   }
00115   }
00116 
00117   m_bulk_data.modification_end();
00118 
00119   for ( int iz = 0 ; iz < 3 ; ++iz ) {
00120   for ( int iy = 0 ; iy < 3 ; ++iy ) {
00121   for ( int ix = 0 ; ix < 3 ; ++ix ) {
00122     // Find node
00123     stk::mesh::EntityId node_id = 1 + ix + 3 * ( iy + 3 * iz );
00124     m_nodes[iz][iy][ix] = m_bulk_data.get_entity( stk::mesh::Node , node_id );
00125   }
00126   }
00127   }
00128 
00129   for ( int iz = 0 ; iz < 2 ; ++iz ) {
00130   for ( int iy = 0 ; iy < 2 ; ++iy ) {
00131   for ( int ix = 0 ; ix < 2 ; ++ix , ++elem ) {
00132     stk::mesh::EntityId elem_id = 1 + ix + 3 * ( iy + 3 * iz );
00133     // Find element
00134     m_elems[iz][iy][ix] = m_bulk_data.get_entity( stk::mesh::Element , elem_id );
00135   }
00136   }
00137   }
00138 }
00139 

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