MeshKit
1.0
|
00001 /********************************************* 00002 June,10 00003 Reactor Assembly Mesh Assembler 00004 Argonne National Laboratory 00005 00006 CCrgen class functions for cop/moving meshes 00007 based on symmetry and geometry type 00008 *********************************************/ 00009 00010 #include "meshkit/CoreGen.hpp" 00011 using namespace MeshKit; 00012 #include <string.h> 00013 int CoreGen::copymove(const int nrank, const int numprocs) 00014 // --------------------------------------------------------------------------- 00015 // Function: copy/move the assemblies based on the geometrytype and symmetry - Assume 1 meshfile in each instance 00016 // Input: none 00017 // Output: none 00018 // --------------------------------------------------------------------------- 00019 { 00020 if (nrank < ((int) core_alias.size() + ((int) files.size() - nassys))){ 00021 err = set_copymove_coords(); 00022 // ERRORR("Failed to set cm coords.", err); 00023 00024 // now copy/move 00025 err = copymove_all(nrank, numprocs); 00026 // ERRORR("Failed to cm hexflat.", err); 00027 } 00028 return iBase_SUCCESS; 00029 } 00030 00031 int CoreGen::set_copymove_coords() 00032 // --------------------------------------------------------------------------- 00033 // Function: 00034 // Input: none 00035 // Output: none 00036 // --------------------------------------------------------------------------- 00037 { 00038 x_coord.resize(tot_assys); 00039 y_coord.resize(tot_assys); 00040 int i = 0; 00041 int assm_index; 00042 double dx[3] = {0.0, 0.0, 0.0}; 00043 // move the assys based on the geometry type 00044 if (!strcmp(geom_type.c_str(), "hexflat") && symm == 6) { 00045 for (int n1 = 0; n1 < nrings; n1++) { 00046 for (int n2 = 0; n2 < n1 + 1; n2++) { 00047 err = find_assm(i, assm_index); 00048 y_coord[i] = n1 * pitch * sin(PII / 3.0) - n2 * pitch * sin(PII / 3.0); 00049 x_coord[i] = n1 * pitch * cos(PII / 3.0) + n2 * pitch * cos(PII / 3.0); 00050 i++; 00051 } 00052 } 00053 } 00054 if (!strcmp(geom_type.c_str(), "rectangular") && symm == 1) { 00055 for (int n1 = 0; n1 < nringsx; n1++) { 00056 for (int n2 = 0; n2 < nringsy; n2++) { 00057 err = find_assm(i, assm_index); 00058 y_coord[i] = -n1 * pitchy; 00059 x_coord[i] = n2 * pitchx; 00060 i++; 00061 } 00062 } 00063 } 00064 if (!strcmp(geom_type.c_str(), "hexflat") && symm == 1) { 00065 int t, width = 2 * nrings - 1; 00066 for (int n1 = 1; n1 <= width; n1++) { 00067 if(n1 > nrings) 00068 t = 2 * nrings - n1; 00069 else 00070 t = n1; 00071 00072 for (int n2 = 1; n2 <= (nrings + t - 1); n2++) { 00073 err = find_assm(i,assm_index); 00074 00075 if (n1 < nrings){ 00076 x_coord[i] = (nrings - n2 + 1) * pitch / 2.0 + n2 * pitch / 2.0 + 00077 (n2 - 1) * pitch - (n1 - 1) * pitch / 2.0; 00078 y_coord[i] = -((n1 - 1) * (0.5 * pitch / sin(PII/3.0) + 0.5 * pitch * sin(PII/6.0) / sin(PII/3.0))); 00079 } 00080 else{ 00081 x_coord[i] = (nrings - n2 + 1) * pitch / 2.0 + n2 * pitch / 2.0 + (n2 - 1) * pitch - 00082 (2 * nrings - n1 -1) * pitch / 2.0; 00083 y_coord[i] = -((n1 -1) * (0.5 * pitch / sin(PII/3.0) + 0.5 * pitch * sin(PII/6.0) / sin(PII/3.0))); 00084 } 00085 i++; 00086 } 00087 } 00088 } 00089 00090 if (!strcmp(geom_type.c_str(), "hexflat") && symm == 12) { 00091 int flag = 0; 00092 for (int n1 = 0; n1 < nrings; n1++) { 00093 int loc = (n1 + 2)/2; 00094 00095 if( flag == 0 ){ 00096 dx[0] = (n1 + loc - 1) * pitch / 2.0; 00097 dx[1] = (n1 - loc + 1) * pitch * sin(PII/3.0); 00098 flag = 1; 00099 } 00100 else{ 00101 dx[0] = (n1 + loc) * pitch / 2.0; 00102 dx[1] = (n1 - loc) * pitch * sin(PII/3.0); 00103 flag = 0; 00104 } 00105 00106 for (int n2 = 0; n2 < loc; n2++) { 00107 err = find_assm(i,assm_index); 00108 y_coord[i] = dx[1] - n2 * pitch * sin(PII/3.0); 00109 x_coord[i] = dx[0] + n2 * pitch * cos(PII/3.0); 00110 i++; 00111 } 00112 } 00113 } 00114 00115 if (!strcmp(geom_type.c_str(), "hexvertex") && symm == 6) { 00116 int bd = 0; 00117 for (int n1 = 0; n1 < nrings; n1++) { 00118 if(n1%2==0){//check if n1 is even 00119 for (int n2 = 0; n2 < n1+1; n2++) { 00120 00121 err = find_assm(i, assm_index); 00122 if (-1 == assm_index){ 00123 i++; 00124 if(n2 > (n1+1)/2) 00125 ++bd; // index for assemblies below diagonal needs updatation 00126 continue; 00127 } 00128 if(n2 <= n1/2){// before or equal to diagonal 00129 dx[0] = n2 * pitch; 00130 dx[1] = n1 * pitch * sin(PII/3.0); 00131 } 00132 else{//below the diagonal 00133 dx[0] = (n1 + 1 + bd) * pitch / 2.0; 00134 dx[1] = (n1 - 1 - bd) * pitch * sin(PII/3.0); 00135 ++bd; 00136 } 00137 x_coord[i] = (dx[0] * cos(PII/6.0) + dx[1] * sin(PII/6.0)); 00138 y_coord[i] = (dx[1] * cos(PII/6.0) - dx[0] * sin(PII/6.0)); 00139 i++; 00140 } 00141 } 00142 else{//n1 is odd 00143 for (int n2 = 0; n2 < n1; n2++) { 00144 err = find_assm(i, assm_index); 00145 if (-1 == assm_index){ 00146 i++; 00147 if(n2 > (n1+1)/2) 00148 ++bd; // index for assemblies below diagonal needs updatation 00149 continue; 00150 00151 } 00152 if(n2 <= (n1-1)/2){// before or equal to diagonal 00153 dx[0] = (2 * n2 + 1) * pitch / 2.0; 00154 dx[1] = n1 * pitch * sin(PII/3.0); 00155 00156 } 00157 else{//below the diagonal 00158 dx[0] = (n1 + 1 + bd) * pitch / 2.0; 00159 if (bd == 0) // first n2 = 1 assembly 00160 dx[1] = pitch * sin(PII/3.0); 00161 dx[1] = (n1 - 1 - bd) * pitch * sin(PII/3.0); 00162 ++bd; 00163 } 00164 00165 00166 // starting from x-axis 00167 x_coord[i] = (dx[0] * cos(PII/6.0) + dx[1] * sin(PII/6.0)); 00168 y_coord[i] = (dx[1] * cos(PII/6.0) - dx[0] * sin(PII/6.0)); 00169 i++; 00170 } 00171 } 00172 bd = 0; 00173 } 00174 } 00175 return iBase_SUCCESS; 00176 } 00177 00178 int CoreGen::copymove_all(const int nrank, const int numprocs) 00179 // --------------------------------------------------------------------------- 00180 // Function: 00181 // Input: none 00182 // Output: none 00183 // --------------------------------------------------------------------------- 00184 { 00185 if(prob_type == "mesh"){ 00186 // get the copy/expand sets 00187 // int num_etags = 3, num_ctags = 1; 00188 // const char *etag_names[] = { "MATERIAL_SET", "DIRICHLET_SET", "NEUMANN_SET" }; 00189 // const char *etag_vals[] = { NULL, NULL, NULL }; 00190 const char *ctag_names[] = { "GEOM_DIMENSION" }; 00191 const char *ctag_vals[] = { (const char*) &set_DIM }; 00192 00193 int flag = 1; 00194 int assm_index = -1; 00195 double dx_orig[3], dx[3]; 00196 // iBase_EntityHandle *new_ents; 00197 // int new_ents_alloc, new_ents_size; 00198 00199 if(numprocs <= (int) files.size()){ 00200 // no distribution of task for copy/move; each file loaded only once 00201 int flags[assys.size()], move_index = -1, run_count[assys.size()]; 00202 double dx[3] = { 0.0, 0.0, 0.0 }; 00203 double dx_move[3] = { 0.0, 0.0, 0.0 }; 00204 CMatrix<double> dx_orig(assys.size(), 3); 00205 dx_orig.Set(0.0); 00206 00207 for (unsigned int i = 0; i < assys.size(); i++) { 00208 flags[i]=0; 00209 run_count[i]=0; 00210 cm[i]->expand_sets().add_tag("MATERIAL_SET"); 00211 cm[i]->expand_sets().add_tag("DIRICHLET_SET"); 00212 cm[i]->expand_sets().add_tag("NEUMANN_SET"); 00213 00214 cm[i]->copy_sets().add_tag("GEOM_DIMENSION"); 00215 00216 cm[i]->update_sets(); 00217 // err = get_expand_sets(cm[i], assys[i], etag_names, etag_vals, num_etags); 00218 // // ERRORR("Failed to add expand lists.", iBase_FAILURE); 00219 // err = get_copy_sets(cm[i], assys[i], ctag_names, ctag_vals, num_ctags); 00220 // //ERRORR("Failed to add expand lists.", iBase_FAILURE); 00221 // err = extend_expand_sets(cm[i]); 00222 // // ERRORR("Failed to extend expand lists.", iBase_FAILURE); 00223 } 00224 for (int k=0; k< tot_assys; k++){ 00225 err = find_assm(k, assm_index); 00226 if(assm_index >= 0){ 00227 // check if this file is with the proc 00228 int out = 0; 00229 for(int c=0; c < (int) assys.size(); c++){ 00230 if(assys_index[c] == assm_index){ 00231 //found assembly 00232 move_index=c; 00233 out = 0; 00234 break; 00235 } 00236 else{ 00237 out = 1; 00238 } 00239 } 00240 if(out == 1){ 00241 continue; 00242 } 00243 if (-1 == assm_index) { 00244 continue; 00245 } 00246 00247 if (flags[move_index] == 0) { 00248 dx_move[0] = x_coord[k]; 00249 dx_move[1] = y_coord[k]; 00250 dx_move[2] = 0; 00251 dx_orig(move_index + 1, 1) = dx_move[0]; 00252 dx_orig(move_index + 1, 2) = dx_move[1]; 00253 dx_orig(move_index + 1, 3) = dx_move[2]; 00254 00255 move_verts(assys[move_index], dx_move); 00256 std::cout << "Moved Assembly: " << assm_index << " dX = " << dx_move[0] << " dY = " 00257 << dx_move[1] << " in proc with rank " << nrank << std::endl; 00258 if(strcmp(info.c_str(),"on") == 0) 00259 info_file << assm_index << " \t" << k << " \t" << dx_move[0] << " \t" << dx_move[1] << " \t" << dx_move[2] << " \t" << nrank << std::endl; 00260 00261 flags[move_index]=1; 00262 } 00263 else{ 00264 00265 dx[0] = x_coord[k] - dx_orig(move_index+1, 1); 00266 dx[1] = y_coord[k] - dx_orig(move_index+1, 2); 00267 dx[2] = 0.0; 00268 00269 // int orig_ents_alloc = 0, orig_ents_size; 00270 // iBase_EntityHandle *orig_ents = NULL; 00271 // new_ents = NULL; 00272 // new_ents_alloc = 0; 00273 cm[move_index]->set_transform(Copy::Translate(dx)); 00274 // mk_core()->insert_node(cm[move_index], (MeshOp*) this); 00275 //cm[move_index]->execute_this(); 00276 00277 // if(run_count[move_index] == 0){ 00278 // ModelEnt me(mk_core(), iBase_EntitySetHandle(0), /*igeom instance*/0, (moab::EntityHandle)assys[move_index]); 00279 // MEntVector assm_set; 00280 // assm_set.clear(); 00281 // assm_set.push_back(&me); 00282 // assm_set[0]->add_meshop(cm[move_index]); 00283 // cm[move_index]->add_modelent(&me); 00284 // // } 00285 // cm[move_index]->execute_this(); 00286 // assm_set[0]->remove_meshop(cm[move_index]); 00287 // mk_core()->insert_node(cm[move_index], (MeshOp*) this); 00288 00289 00290 cm[move_index]->execute_this(); 00291 // if (run_count[move_index] < 1) { 00292 // cm[move_index]->execute_this(); 00293 // } 00294 // else { 00295 // mk_core()->insert_node(cm[move_index], (MeshOp*) this); 00296 // } 00297 ++run_count[move_index]; 00298 00299 // cm[move_index]-> 00300 // iMesh_getEntities(impl, assys[move_index], iBase_ALL_TYPES,iMesh_ALL_TOPOLOGIES, 00301 // &orig_ents, &orig_ents_alloc, &orig_ents_size, &err); 00302 // ERRORR("Failed to get any entities from original set.", iBase_FAILURE); 00303 00304 // cm[move_index]->copy(orig_ents,orig_ents_size, copy::Translate(dx), 00305 // &new_ents, &new_ents_alloc, &new_ents_size, false); 00306 00307 std::cout << "Copy/moved A: " << assm_index 00308 <<" dX = " <<dx[0]<< " dY = " << dx[1] << " rank " << nrank << std::endl; 00309 if(strcmp(info.c_str(),"on") == 0) 00310 info_file << assm_index << " " << k << " " << dx[0] << " \t" << dx[1] << " \t" << dx[2] << " \t" << nrank << std::endl; 00311 // free(new_ents); 00312 // free(orig_ents); 00313 cm[move_index]->tag_copied_sets(ctag_names, ctag_vals, 1); 00314 // cm[move_index]->tag_copied_sets(ctag_names, ctag_vals, 1); 00315 } 00316 00317 } 00318 } 00319 } 00320 else{ 00321 for(int i =0; i < (int) position_core[nrank].size(); i++){ 00322 assm_index = position_core[nrank][i]; 00323 if(assm_index >= 0){ 00324 // some files are loaded in two or more processors, copy/move task distribution takes place 00325 int j = 0; 00326 cm[j]->expand_sets().add_tag("MATERIAL_SET"); 00327 cm[j]->expand_sets().add_tag("DIRICHLET_SET"); 00328 cm[j]->expand_sets().add_tag("NEUMANN_SET"); 00329 00330 cm[j]->copy_sets().add_tag("GEOM_DIMENSION"); 00331 00332 cm[j]->update_sets(); 00333 00334 // err = get_expand_sets(cm[j], assys[j], etag_names, etag_vals, num_etags); 00335 // ERRORR("Failed to add expand lists.", iBase_FAILURE); 00336 // err = get_copy_sets(cm[j], assys[j], ctag_names, ctag_vals, num_ctags); 00337 // ERRORR("Failed to add expand lists.", iBase_FAILURE); 00338 // err = extend_expand_sets(cm[j]); 00339 // ERRORR("Failed to extend expand lists.", iBase_FAILURE); 00340 00341 if(flag == 0){ 00342 dx[0] = x_coord[assm_index] - dx_orig[0]; 00343 dx[1] = y_coord[assm_index] - dx_orig[1]; 00344 dx[2] = 0.0; 00345 00346 // new_ents = NULL; 00347 // new_ents_alloc = 0; 00348 // new_ents_size = 0; 00349 00350 // int orig_ents_alloc = 0, orig_ents_size; 00351 // iBase_EntityHandle *orig_ents = NULL; 00352 00353 00354 /* iMesh_getEntities(impl, assys[0], iBase_ALL_TYPES, 00355 iMesh_ALL_TOPOLOGIES, &orig_ents, &orig_ents_alloc, 00356 &orig_ents_size, &err); 00357 /*/// ERRORR("Failed to get any entities from original set.", iBase_FAILURE); 00358 00359 // cm[0]->copy(orig_ents, orig_ents_size, copy::Translate(dx), 00360 // &new_ents, &new_ents_alloc, &new_ents_size, false); 00361 cm[0]->set_transform(Copy::Translate(dx)); 00362 std::cout << "Copy/moved Assm: " << assm_index << " dX = " << dx[0] << " dY = " 00363 << dx[1] << " rank " << nrank << std::endl; 00364 if(strcmp(info.c_str(),"on") == 0) 00365 info_file << assm_index << " \t" << i << " \t" << dx[0] << " \t" << dx[1] << " \t" << dx[2] << " \t" << nrank << std::endl; 00366 00367 // cm[0]->tag_copied_sets(ctag_names, ctag_vals, 1); 00368 00369 // free(new_ents); 00370 // free(orig_ents); 00371 } else { 00372 flag = 0; 00373 dx_orig[0] = x_coord[assm_index]; 00374 dx_orig[1] = y_coord[assm_index]; 00375 dx_orig[2] = 0; 00376 move_verts(assys[0], dx_orig); 00377 std::cout << "Moved Assm: " << assm_index << " dX = " << dx_orig[0] << " dY = " 00378 << dx_orig[1] << " rank " << nrank << std::endl; 00379 if(strcmp(info.c_str(),"on") == 0) 00380 info_file << assm_index << " \t" << i << " \t" << dx_orig[0] << " \t" << dx_orig[1] << " \t" << dx_orig[2] << " \t" << nrank << std::endl; 00381 00382 } 00383 } 00384 } 00385 } 00386 } 00387 else{ // prob type is geometry 00388 int assm_index = -1; 00389 // iBase_EntityHandle *new_ents; 00390 // int new_ents_alloc, new_ents_size; 00391 00392 // no distribution of task for copy/move; each file loaded only once 00393 int flags[assys.size()], move_index = -1; 00394 double dx[3] = { 0.0, 0.0, 0.0 }; 00395 double dx_move[3] = { 0.0, 0.0, 0.0 }; 00396 CMatrix<double> dx_orig(assys.size(), 3); 00397 dx_orig.Set(0.0); 00398 00399 for (unsigned int i = 0; i < assys.size(); i++) { 00400 flags[i]=0; 00401 } 00402 00403 for (int k=0; k< tot_assys; k++){ 00404 err = find_assm(k, assm_index); 00405 if(assm_index >= 0){ 00406 // check if this file is with the proc 00407 int out = 0; 00408 for(int c=0; c < (int) assys.size(); c++){ 00409 if(assys_index[c] == assm_index){ 00410 //found assembly 00411 move_index=c; 00412 out = 0; 00413 break; 00414 } 00415 else{ 00416 out = 1; 00417 } 00418 } 00419 if(out == 1){ 00420 continue; 00421 } 00422 if (-1 == assm_index) { 00423 continue; 00424 } 00425 00426 if (flags[move_index] == 0) { 00427 dx_move[0] = x_coord[k]; 00428 dx_move[1] = y_coord[k]; 00429 dx_move[2] = 0; 00430 dx_orig(move_index + 1, 1) = dx_move[0]; 00431 dx_orig(move_index + 1, 2) = dx_move[1]; 00432 dx_orig(move_index + 1, 3) = dx_move[2]; 00433 00434 move_geoms(assys[move_index], dx_move); 00435 std::cout << "Moved Assembly: " << assm_index << " dX = " << dx_move[0] << " dY = " 00436 << dx_move[1] << " in proc with rank " << nrank << std::endl; 00437 flags[move_index]=1; 00438 } 00439 else{ 00440 00441 dx[0] = x_coord[k] - dx_orig(move_index+1, 1); 00442 dx[1] = y_coord[k] - dx_orig(move_index+1, 2); 00443 dx[2] = 0.0; 00444 00445 // int orig_ents_alloc = 0, orig_ents_size; 00446 // iBase_EntityHandle *orig_ents = NULL; 00447 // new_ents = NULL; 00448 // new_ents_alloc = 0; 00449 00450 // iGeom_getEntities(geom, assys[move_index], iBase_ALL_TYPES, 00451 // &orig_ents, &orig_ents_alloc, &orig_ents_size, &err); 00452 // ERRORR("Failed to get any entities from original set.", iBase_FAILURE); 00453 00454 // cg[move_index]->copy(orig_ents,orig_ents_size, dx, 00455 // &new_ents, &new_ents_alloc, &new_ents_size, false); 00456 cg[move_index]->set_location(dx); 00457 cg[move_index]->execute_this(); 00458 std::cout << "Copy/moved A: " << assm_index 00459 <<" dX = " <<dx[0]<< " dY = " << dx[1] << " rank " << nrank << std::endl; 00460 // free(new_ents); 00461 // free(orig_ents); 00462 00463 } 00464 00465 } 00466 } 00467 00468 } 00469 return iBase_SUCCESS; 00470 }