Sierra Toolkit Version of the Day
QuadFixture.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 <algorithm>
00010 
00011 #include <stk_mesh/fixtures/QuadFixture.hpp>
00012 
00013 #include <stk_mesh/base/FieldData.hpp>
00014 #include <stk_mesh/base/Types.hpp>
00015 #include <stk_mesh/base/Entity.hpp>
00016 #include <stk_mesh/base/BulkModification.hpp>
00017 
00018 #include <stk_mesh/fem/Stencils.hpp>
00019 #include <stk_mesh/fem/EntityRanks.hpp>
00020 #include <stk_mesh/fem/TopologyHelpers.hpp>
00021 #include <stk_mesh/fem/BoundaryAnalysis.hpp>
00022 
00023 namespace stk {
00024 namespace mesh {
00025 namespace fixtures {
00026 
00027 QuadFixture::~QuadFixture()
00028 {}
00029 
00030 QuadFixture::QuadFixture( stk::ParallelMachine pm ,
00031                         unsigned nx , unsigned ny )
00032   : spatial_dimension(2),
00033     meta_data( TopologicalMetaData::entity_rank_names(spatial_dimension) ),
00034     bulk_data( meta_data , pm ),
00035     top_data( meta_data, spatial_dimension ),
00036     quad_part( top_data.declare_part<shards::Quadrilateral<4> >("quad_part" ) ),
00037     coord_field( meta_data.declare_field<CoordFieldType>("Coordinates") ),
00038     coord_gather_field( meta_data.declare_field<CoordGatherFieldType>("GatherCoordinates") ),
00039     NX( nx ),
00040     NY( ny )
00041 {
00042   typedef shards::Quadrilateral<4> Quad4 ;
00043   enum { SpatialDim = 2 };
00044   enum { NodesPerElem = Quad4::node_count };
00045 
00046   //put coord-field on all nodes:
00047   put_field(
00048       coord_field,
00049       top_data.node_rank,
00050       meta_data.universal_part(),
00051       SpatialDim
00052       );
00053 
00054   //put coord-gather-field on all elements:
00055   put_field(
00056       coord_gather_field,
00057       top_data.element_rank,
00058       meta_data.universal_part(),
00059       NodesPerElem
00060       );
00061 
00062   // Field relation so coord-gather-field on elements points
00063   // to coord-field of the element's nodes
00064   meta_data.declare_field_relation( coord_gather_field, element_node_stencil<Quad4>, coord_field);
00065 
00066 }
00067 
00068 void QuadFixture::generate_mesh() {
00069   std::vector<EntityId> element_ids_on_this_processor;
00070 
00071   const unsigned p_size = bulk_data.parallel_size();
00072   const unsigned p_rank = bulk_data.parallel_rank();
00073   const unsigned num_elems = NX * NY;
00074 
00075   const EntityId beg_elem = 1 + ( num_elems * p_rank ) / p_size ;
00076   const EntityId end_elem = 1 + ( num_elems * ( p_rank + 1 ) ) / p_size ;
00077 
00078   for ( EntityId i = beg_elem; i != end_elem; ++i) {
00079     element_ids_on_this_processor.push_back(i);
00080   }
00081 
00082   generate_mesh(element_ids_on_this_processor);
00083 }
00084 
00085 void QuadFixture::generate_mesh(std::vector<EntityId> & element_ids_on_this_processor) {
00086 
00087   {
00088     //sort and unique the input elements
00089     std::vector<EntityId>::iterator ib = element_ids_on_this_processor.begin();
00090     std::vector<EntityId>::iterator ie = element_ids_on_this_processor.end();
00091 
00092     std::sort( ib, ie);
00093     ib = std::unique( ib, ie);
00094     element_ids_on_this_processor.erase(ib, ie);
00095   }
00096 
00097   bulk_data.modification_begin();
00098 
00099   {
00100     std::vector<EntityId>::iterator ib = element_ids_on_this_processor.begin();
00101     const std::vector<EntityId>::iterator ie = element_ids_on_this_processor.end();
00102     for (; ib != ie; ++ib) {
00103       EntityId entity_id = *ib;
00104       unsigned ix = 0, iy = 0;
00105       elem_ix_iy(entity_id, ix, iy);
00106 
00107       stk::mesh::EntityId elem_node[4] ;
00108 
00109       elem_node[0] = node_id( ix   , iy );
00110       elem_node[1] = node_id( ix+1 , iy );
00111       elem_node[2] = node_id( ix+1 , iy+1 );
00112       elem_node[3] = node_id( ix   , iy+1 );
00113 
00114       stk::mesh::declare_element( bulk_data, quad_part, elem_id( ix , iy ) , elem_node);
00115       for (unsigned i = 0; i<4; ++i) {
00116         stk::mesh::Entity * const node =
00117           bulk_data.get_entity( top_data.node_rank , elem_node[i] );
00118 
00119         if ( node != NULL) {
00120 
00121           unsigned nx = 0, ny = 0;
00122           node_ix_iy(elem_node[i], nx, ny);
00123 
00124           Scalar * data = stk::mesh::field_data( coord_field , *node );
00125 
00126           data[0] = nx ;
00127           data[1] = ny ;
00128         }
00129       }
00130     }
00131   }
00132 
00133   bulk_data.modification_end();
00134 
00135 }
00136 
00137 
00138 } // fixtures
00139 } // mesh
00140 } // stk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends