|
Sierra Toolkit Version of the Day
|
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/HexFixture.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 HexFixture::~HexFixture() 00028 {} 00029 00030 00031 HexFixture::HexFixture(stk::ParallelMachine pm, unsigned nx, unsigned ny, unsigned nz) 00032 : 00033 spatial_dimension(3) 00034 , NX(nx) 00035 , NY(ny) 00036 , NZ(nz) 00037 , meta_data( TopologicalMetaData::entity_rank_names(spatial_dimension) ) 00038 , bulk_data( meta_data , pm ) 00039 , top_data( meta_data, spatial_dimension ) 00040 , hex_part( top_data.declare_part<shards::Hexahedron<8> >("hex_part" ) ) 00041 , coord_field( meta_data.declare_field<CoordFieldType>("Coordinates") ) 00042 , coord_gather_field( 00043 meta_data.declare_field<CoordGatherFieldType>("GatherCoordinates") 00044 ) 00045 { 00046 typedef shards::Hexahedron<8> Hex8 ; 00047 enum { SpatialDim = 3 }; 00048 enum { NodesPerElem = Hex8::node_count }; 00049 00050 //put coord-field on all nodes: 00051 put_field( 00052 coord_field, 00053 top_data.node_rank, 00054 meta_data.universal_part(), 00055 SpatialDim 00056 ); 00057 00058 //put coord-gather-field on all elements: 00059 put_field( 00060 coord_gather_field, 00061 top_data.element_rank, 00062 meta_data.universal_part(), 00063 NodesPerElem 00064 ); 00065 00066 // Field relation so coord-gather-field on elements points 00067 // to coord-field of the element's nodes 00068 meta_data.declare_field_relation( coord_gather_field, element_node_stencil<Hex8>, coord_field); 00069 00070 } 00071 00072 void HexFixture::generate_mesh() { 00073 std::vector<EntityId> element_ids_on_this_processor; 00074 00075 const unsigned p_size = bulk_data.parallel_size(); 00076 const unsigned p_rank = bulk_data.parallel_rank(); 00077 const unsigned num_elems = NX * NY * NZ ; 00078 00079 const EntityId beg_elem = 1 + ( num_elems * p_rank ) / p_size ; 00080 const EntityId end_elem = 1 + ( num_elems * ( p_rank + 1 ) ) / p_size ; 00081 00082 for ( EntityId i = beg_elem; i != end_elem; ++i) { 00083 element_ids_on_this_processor.push_back(i); 00084 } 00085 00086 generate_mesh(element_ids_on_this_processor); 00087 } 00088 00089 void HexFixture::generate_mesh(std::vector<EntityId> & element_ids_on_this_processor) { 00090 00091 { 00092 //sort and unique the input elements 00093 std::vector<EntityId>::iterator ib = element_ids_on_this_processor.begin(); 00094 std::vector<EntityId>::iterator ie = element_ids_on_this_processor.end(); 00095 00096 std::sort( ib, ie); 00097 ib = std::unique( ib, ie); 00098 element_ids_on_this_processor.erase(ib, ie); 00099 } 00100 00101 bulk_data.modification_begin(); 00102 00103 { 00104 std::vector<EntityId>::iterator ib = element_ids_on_this_processor.begin(); 00105 const std::vector<EntityId>::iterator ie = element_ids_on_this_processor.end(); 00106 for (; ib != ie; ++ib) { 00107 EntityId entity_id = *ib; 00108 unsigned ix = 0, iy = 0, iz = 0; 00109 elem_ix_iy_iz(entity_id, ix, iy, iz); 00110 00111 stk::mesh::EntityId elem_node[8] ; 00112 00113 elem_node[0] = node_id( ix , iy , iz ); 00114 elem_node[1] = node_id( ix+1 , iy , iz ); 00115 elem_node[2] = node_id( ix+1 , iy , iz+1 ); 00116 elem_node[3] = node_id( ix , iy , iz+1 ); 00117 elem_node[4] = node_id( ix , iy+1 , iz ); 00118 elem_node[5] = node_id( ix+1 , iy+1 , iz ); 00119 elem_node[6] = node_id( ix+1 , iy+1 , iz+1 ); 00120 elem_node[7] = node_id( ix , iy+1 , iz+1 ); 00121 00122 stk::mesh::declare_element( bulk_data, hex_part, elem_id( ix , iy , iz ) , elem_node); 00123 00124 for (unsigned i = 0; i<8; ++i) { 00125 stk::mesh::Entity * const node = 00126 bulk_data.get_entity( top_data.node_rank , elem_node[i] ); 00127 00128 if ( node != NULL) { 00129 00130 unsigned nx = 0, ny = 0, nz = 0; 00131 node_ix_iy_iz(elem_node[i], nx, ny, nz); 00132 00133 Scalar * data = stk::mesh::field_data( coord_field , *node ); 00134 00135 data[0] = nx ; 00136 data[1] = ny ; 00137 data[2] = -nz ; 00138 } 00139 } 00140 } 00141 } 00142 00143 bulk_data.modification_end(); 00144 00145 00146 } 00147 00148 } // fixtures 00149 } // mesh 00150 } // stk