|
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 00010 #include <sstream> 00011 00012 #include <unit_tests/UnitTestMesh.hpp> 00013 00014 00015 namespace stk { 00016 namespace unit_test { 00017 00018 /****************************************************************/ 00019 00020 std::vector<std::string> get_entity_rank_names ( int rank ) 00021 { 00022 std::vector<std::string> ret_val; 00023 ret_val.push_back ( "Node" ); 00024 if ( rank == 0 ) return ret_val; 00025 ret_val.push_back ( "Edge" ); 00026 if ( rank == 1 ) return ret_val; 00027 ret_val.push_back ( "Face" ); 00028 if ( rank == 2 ) return ret_val; 00029 ret_val.push_back ( "Element" ); 00030 if ( rank == 3 ) return ret_val; 00031 for ( int i = 3 ; i != rank ; i++ ) 00032 { 00033 std::stringstream name; 00034 name << "Entity rank " << i; 00035 ret_val.push_back ( name.str() ); 00036 } 00037 return ret_val; 00038 } 00039 00040 00041 UnitTestMesh::UnitTestMesh ( stk::ParallelMachine comm , unsigned block_size ) 00042 : m_meta_data ( get_entity_rank_names ( MAX_RANK ) ) 00043 , m_bulk_data ( m_meta_data , comm , block_size ) 00044 , m_test_part ( m_meta_data.declare_part ( "Test Part" ) ) 00045 , m_cell_part ( m_meta_data.declare_part ( "Cell list" , MAX_RANK ) ) 00046 , m_part_A_0 ( m_meta_data.declare_part ( "Part A 0", 0 ) ) 00047 , m_part_A_1 ( m_meta_data.declare_part ( "Part A 1", 1 ) ) 00048 , m_part_A_2 ( m_meta_data.declare_part ( "Part A 2", 2 ) ) 00049 , m_part_A_3 ( m_meta_data.declare_part ( "Part A 3", 3 ) ) 00050 , m_part_A_superset ( m_meta_data.declare_part ( "Part A superset" ) ) 00051 , m_part_B_0 ( m_meta_data.declare_part ( "Part B 0", 0 ) ) 00052 , m_part_B_1 ( m_meta_data.declare_part ( "Part B 1", 1 ) ) 00053 , m_part_B_2 ( m_meta_data.declare_part ( "Part B 2", 2 ) ) 00054 , m_part_B_3 ( m_meta_data.declare_part ( "Part B 3", 3 ) ) 00055 , m_part_B_superset ( m_meta_data.declare_part ( "Part B superset" ) ) 00056 , m_comm_rank( stk::parallel_machine_rank( comm ) ) 00057 , m_comm_size( stk::parallel_machine_size( comm ) ) 00058 , m_previous_state ( stk::mesh::BulkData::MODIFIABLE ) 00059 { 00060 m_meta_data.declare_part_subset ( m_part_A_superset , m_part_A_0 ); 00061 m_meta_data.declare_part_subset ( m_part_A_superset , m_part_A_1 ); 00062 m_meta_data.declare_part_subset ( m_part_A_superset , m_part_A_2 ); 00063 m_meta_data.declare_part_subset ( m_part_A_superset , m_part_A_3 ); 00064 00065 m_meta_data.declare_part_subset ( m_part_B_superset , m_part_B_0 ); 00066 m_meta_data.declare_part_subset ( m_part_B_superset , m_part_B_1 ); 00067 m_meta_data.declare_part_subset ( m_part_B_superset , m_part_B_2 ); 00068 m_meta_data.declare_part_subset ( m_part_B_superset , m_part_B_3 ); 00069 00070 m_meta_data.commit (); 00071 } 00072 00073 00074 void UnitTestMesh::generate_boxes ( bool aura ) 00075 { 00076 enter_modification(); 00077 const int root_box[3][2] = { { 0,4 } , { 0,5 } , { 0,6 } }; 00078 int local_box[3][2] = { { 0,0 } , { 0,0 } , { 0,0 } }; 00079 priv_generate_boxes( m_bulk_data , aura , root_box , local_box ); 00080 exit_modification(); 00081 } 00082 00083 00084 00085 namespace { 00086 00087 /* Recursively split a box into ( up - ip ) sub-boxes */ 00088 00089 typedef int BOX[3][2] ; 00090 00091 void box_partition( int ip , int up , int axis , 00092 const BOX box , 00093 BOX p_box[] ) 00094 { 00095 const int np = up - ip ; 00096 if ( 1 == np ) { 00097 p_box[ip][0][0] = box[0][0] ; p_box[ip][0][1] = box[0][1] ; 00098 p_box[ip][1][0] = box[1][0] ; p_box[ip][1][1] = box[1][1] ; 00099 p_box[ip][2][0] = box[2][0] ; p_box[ip][2][1] = box[2][1] ; 00100 } 00101 else { 00102 const int n = box[ axis ][1] - box[ axis ][0] ; 00103 const int np_low = np / 2 ; /* Rounded down */ 00104 const int np_upp = np - np_low ; 00105 00106 const int n_upp = (int) (((double) n) * ( ((double)np_upp) / ((double)np))); 00107 const int n_low = n - n_upp ; 00108 const int next_axis = ( axis + 2 ) % 3 ; 00109 00110 if ( np_low ) { /* P = [ip,ip+np_low) */ 00111 BOX dbox ; 00112 dbox[0][0] = box[0][0] ; dbox[0][1] = box[0][1] ; 00113 dbox[1][0] = box[1][0] ; dbox[1][1] = box[1][1] ; 00114 dbox[2][0] = box[2][0] ; dbox[2][1] = box[2][1] ; 00115 00116 dbox[ axis ][1] = dbox[ axis ][0] + n_low ; 00117 00118 box_partition( ip, ip + np_low, next_axis, 00119 (const int (*)[2]) dbox, p_box ); 00120 } 00121 00122 if ( np_upp ) { /* P = [ip+np_low,ip+np_low+np_upp) */ 00123 BOX dbox ; 00124 dbox[0][0] = box[0][0] ; dbox[0][1] = box[0][1] ; 00125 dbox[1][0] = box[1][0] ; dbox[1][1] = box[1][1] ; 00126 dbox[2][0] = box[2][0] ; dbox[2][1] = box[2][1] ; 00127 00128 ip += np_low ; 00129 dbox[ axis ][0] += n_low ; 00130 dbox[ axis ][1] = dbox[ axis ][0] + n_upp ; 00131 00132 box_partition( ip, ip + np_upp, next_axis, 00133 (const int (*)[2]) dbox, p_box ); 00134 } 00135 } 00136 } 00137 00138 } 00139 00140 void UnitTestMesh::priv_generate_boxes( 00141 stk::mesh::BulkData & mesh , 00142 const bool generate_aura , 00143 const int root_box[][2] , 00144 int local_box[][2] ) 00145 { 00146 const unsigned p_rank = mesh.parallel_rank(); 00147 const unsigned p_size = mesh.parallel_size(); 00148 const unsigned ngx = root_box[0][1] - root_box[0][0] ; 00149 const unsigned ngy = root_box[1][1] - root_box[1][0] ; 00150 // const unsigned ngz = root_box[2][1] - root_box[2][0] ; 00151 /* 00152 const unsigned e_global = ngx * ngy * ngz ; 00153 const unsigned n_global = ( ngx + 1 ) * ( ngy + 1 ) * ( ngz + 1 ); 00154 */ 00155 00156 00157 BOX * const p_box = new BOX[ p_size ]; 00158 00159 box_partition( 0 , p_size , 2 , root_box , & p_box[0] ); 00160 00161 local_box[0][0] = p_box[ p_rank ][0][0] ; 00162 local_box[0][1] = p_box[ p_rank ][0][1] ; 00163 local_box[1][0] = p_box[ p_rank ][1][0] ; 00164 local_box[1][1] = p_box[ p_rank ][1][1] ; 00165 local_box[2][0] = p_box[ p_rank ][2][0] ; 00166 local_box[2][1] = p_box[ p_rank ][2][1] ; 00167 00168 //const unsigned nx = local_box[0][1] - local_box[0][0] ; 00169 //const unsigned ny = local_box[1][1] - local_box[1][0] ; 00170 //const unsigned nz = local_box[2][1] - local_box[2][0] ; 00171 00172 //const unsigned e_local = nx * ny * nz ; 00173 //const unsigned n_local = ( nx + 1 ) * ( ny + 1 ) * ( nz + 1 ); 00174 00175 // Create elements: 00176 00177 std::vector<unsigned> local_count ; 00178 00179 const stk::mesh::PartVector no_parts ; 00180 00181 for ( int k = local_box[2][0] ; k < local_box[2][1] ; ++k ) { 00182 for ( int j = local_box[1][0] ; j < local_box[1][1] ; ++j ) { 00183 for ( int i = local_box[0][0] ; i < local_box[0][1] ; ++i ) { 00184 const stk::mesh::EntityId n0 = 1 + (i+0) + (j+0) * (ngx+1) + (k+0) * (ngx+1) * (ngy+1); 00185 const stk::mesh::EntityId n1 = 1 + (i+1) + (j+0) * (ngx+1) + (k+0) * (ngx+1) * (ngy+1); 00186 const stk::mesh::EntityId n2 = 1 + (i+1) + (j+1) * (ngx+1) + (k+0) * (ngx+1) * (ngy+1); 00187 const stk::mesh::EntityId n3 = 1 + (i+0) + (j+1) * (ngx+1) + (k+0) * (ngx+1) * (ngy+1); 00188 const stk::mesh::EntityId n4 = 1 + (i+0) + (j+0) * (ngx+1) + (k+1) * (ngx+1) * (ngy+1); 00189 const stk::mesh::EntityId n5 = 1 + (i+1) + (j+0) * (ngx+1) + (k+1) * (ngx+1) * (ngy+1); 00190 const stk::mesh::EntityId n6 = 1 + (i+1) + (j+1) * (ngx+1) + (k+1) * (ngx+1) * (ngy+1); 00191 const stk::mesh::EntityId n7 = 1 + (i+0) + (j+1) * (ngx+1) + (k+1) * (ngx+1) * (ngy+1); 00192 00193 const stk::mesh::EntityId elem_id = 1 + i + j * ngx + k * ngx * ngy; 00194 00195 stk::mesh::Entity & node0 = mesh.declare_entity( 0 , n0 , no_parts ); 00196 stk::mesh::Entity & node1 = mesh.declare_entity( 0 , n1 , no_parts ); 00197 stk::mesh::Entity & node2 = mesh.declare_entity( 0 , n2 , no_parts ); 00198 stk::mesh::Entity & node3 = mesh.declare_entity( 0 , n3 , no_parts ); 00199 stk::mesh::Entity & node4 = mesh.declare_entity( 0 , n4 , no_parts ); 00200 stk::mesh::Entity & node5 = mesh.declare_entity( 0 , n5 , no_parts ); 00201 stk::mesh::Entity & node6 = mesh.declare_entity( 0 , n6 , no_parts ); 00202 stk::mesh::Entity & node7 = mesh.declare_entity( 0 , n7 , no_parts ); 00203 stk::mesh::Entity & elem = mesh.declare_entity( 3 , elem_id , no_parts ); 00204 00205 mesh.declare_relation( elem , node0 , 0 ); 00206 mesh.declare_relation( elem , node1 , 1 ); 00207 mesh.declare_relation( elem , node2 , 2 ); 00208 mesh.declare_relation( elem , node3 , 3 ); 00209 mesh.declare_relation( elem , node4 , 4 ); 00210 mesh.declare_relation( elem , node5 , 5 ); 00211 mesh.declare_relation( elem , node6 , 6 ); 00212 mesh.declare_relation( elem , node7 , 7 ); 00213 } 00214 } 00215 } 00216 00217 // Set up sharing: 00218 mesh.modification_end(); 00219 00220 delete[] p_box ; 00221 } 00222 00223 //---------------------------------------------------------------------- 00224 00225 00226 } // namespace unit_test 00227 } // namespace stk 00228 00229 00230