MeshKit  1.0
copymove_parallel.cpp
Go to the documentation of this file.
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 int CoreGen::copymove(const int nrank, const int numprocs)
00013 // ---------------------------------------------------------------------------
00014 // Function: copy/move the assemblies based on the geometrytype and symmetry - Assume 1 meshfile in each instance
00015 // Input:    none
00016 // Output:   none
00017 // ---------------------------------------------------------------------------
00018 {
00019     if (nrank < ((int) core_alias.size() + ((int) files.size() - nassys))){
00020         err = set_copymove_coords();
00021         // ERRORR("Failed to set cm coords.", err);
00022 
00023         // now copy/move
00024         err = copymove_all(nrank, numprocs);
00025         // ERRORR("Failed to cm hexflat.", err);
00026     }
00027     return iBase_SUCCESS;
00028 }
00029 
00030 int CoreGen::set_copymove_coords()
00031 // ---------------------------------------------------------------------------
00032 // Function:
00033 // Input:    none
00034 // Output:   none
00035 // ---------------------------------------------------------------------------
00036 {
00037     x_coord.resize(tot_assys);
00038     y_coord.resize(tot_assys);
00039     int i = 0;
00040     int assm_index;
00041     double dx[3] = {0.0, 0.0, 0.0};
00042     // move the assys based on the geometry type
00043     if (!strcmp(geom_type.c_str(), "hexflat") && symm == 6) {
00044         for (int n1 = 0; n1 < nrings; n1++) {
00045             for (int n2 = 0; n2 < n1 + 1; n2++) {
00046                 err = find_assm(i, assm_index);
00047                 y_coord[i] = n1 * pitch * sin(PII / 3.0) - n2 * pitch * sin(PII / 3.0);
00048                 x_coord[i] = n1 * pitch * cos(PII / 3.0) + n2 * pitch * cos(PII / 3.0);
00049                 i++;
00050             }
00051         }
00052     }
00053     if (!strcmp(geom_type.c_str(), "rectangular") && symm == 1) {
00054         double dx = 0.0, dy = 0.0;
00055         int i = 0;
00056         for (int m = 1; m <= nringsy; m++) {
00057             for (int n = 1; n <= nringsx; n++) {
00058                 if (n==1){
00059                     dx = 0;
00060                     if(m==1)
00061                       dy = 0;
00062                   }
00063                 else{
00064                     dx+= pitchx;
00065                   }
00066                 if (m > 1 && n==1){
00067                     dy+= pitchy;
00068                   }
00069                 y_coord[i] = -dy;
00070                 x_coord[i] = dx;
00071                 i++;
00072               }
00073           }
00074       }
00075     if (!strcmp(geom_type.c_str(), "hexflat") && symm == 1) {
00076         int t, width = 2 * nrings - 1;
00077         for (int n1 = 1; n1 <= width; n1++) {
00078             if(n1 > nrings)
00079                 t = 2 * nrings - n1;
00080             else
00081                 t = n1;
00082 
00083             for (int n2 = 1; n2 <= (nrings + t - 1); n2++) {
00084                 err = find_assm(i,assm_index);
00085 
00086                 if (n1 < nrings){
00087                     x_coord[i] = (nrings - n2 + 1) * pitch / 2.0 + n2 * pitch / 2.0 +
00088                             (n2 - 1) * pitch - (n1 - 1) * pitch / 2.0;
00089                     y_coord[i] = -((n1 - 1) * (0.5 * pitch / sin(PII/3.0) + 0.5 * pitch * sin(PII/6.0) / sin(PII/3.0)));
00090                 }
00091                 else{
00092                     x_coord[i] = (nrings - n2 + 1) * pitch / 2.0 + n2 * pitch / 2.0 + (n2 - 1) * pitch -
00093                             (2 * nrings - n1 -1) * pitch / 2.0;
00094                     y_coord[i] = -((n1 -1) * (0.5 * pitch / sin(PII/3.0) + 0.5 * pitch * sin(PII/6.0) / sin(PII/3.0)));
00095                 }
00096                 i++;
00097             }
00098         }
00099     }
00100 
00101     if (!strcmp(geom_type.c_str(), "hexflat") && symm == 12) {
00102         int flag = 0;
00103         for (int n1 = 0; n1 < nrings; n1++) {
00104             int loc = (n1 + 2)/2;
00105 
00106             if( flag == 0 ){
00107                 dx[0] = (n1 + loc - 1) * pitch / 2.0;
00108                 dx[1] = (n1 - loc + 1) * pitch * sin(PII/3.0);
00109                 flag = 1;
00110             }
00111             else{
00112                 dx[0] = (n1 + loc) * pitch / 2.0;
00113                 dx[1] = (n1 - loc) * pitch * sin(PII/3.0);
00114                 flag = 0;
00115             }
00116 
00117             for (int n2 = 0; n2 < loc; n2++) {
00118                 err = find_assm(i,assm_index);
00119                 y_coord[i] = dx[1] - n2 * pitch * sin(PII/3.0);
00120                 x_coord[i] = dx[0] + n2 * pitch * cos(PII/3.0);
00121                 i++;
00122             }
00123         }
00124     }
00125 
00126     if (!strcmp(geom_type.c_str(), "hexvertex") && symm == 6) {
00127         int bd = 0;
00128         for (int n1 = 0; n1 < nrings; n1++) {
00129             if(n1%2==0){//check if n1 is even
00130                 for (int n2 = 0; n2 < n1+1; n2++) {
00131 
00132                     err = find_assm(i, assm_index);
00133                     if (-1 == assm_index){
00134                         i++;
00135                         if(n2 > (n1+1)/2)
00136                             ++bd; // index for assemblies below diagonal needs updatation
00137                         continue;
00138                     }
00139                     if(n2 <= n1/2){// before or equal to diagonal
00140                         dx[0] = n2 * pitch;
00141                         dx[1] = n1 * pitch * sin(PII/3.0);
00142                     }
00143                     else{//below the diagonal
00144                         dx[0] = (n1 + 1 + bd) * pitch / 2.0;
00145                         dx[1] = (n1 - 1 - bd) * pitch * sin(PII/3.0);
00146                         ++bd;
00147                     }
00148                     x_coord[i] = (dx[0] * cos(PII/6.0) + dx[1] * sin(PII/6.0));
00149                     y_coord[i] = (dx[1] * cos(PII/6.0) - dx[0] * sin(PII/6.0));
00150                     i++;
00151                 }
00152             }
00153             else{//n1 is odd
00154                 for (int n2 = 0; n2 < n1; n2++) {
00155                     err = find_assm(i, assm_index);
00156                     if (-1 == assm_index){
00157                         i++;
00158                         if(n2 > (n1+1)/2)
00159                             ++bd; // index for assemblies below diagonal needs updatation
00160                         continue;
00161 
00162                     }
00163                     if(n2 <= (n1-1)/2){// before or equal to diagonal
00164                         dx[0] = (2 * n2 + 1) * pitch / 2.0;
00165                         dx[1] = n1 * pitch * sin(PII/3.0);
00166 
00167                     }
00168                     else{//below the diagonal
00169                         dx[0] = (n1 + 1 + bd) * pitch / 2.0;
00170                         if (bd == 0) // first n2 = 1 assembly
00171                             dx[1] = pitch * sin(PII/3.0);
00172                         dx[1] = (n1 - 1 - bd) * pitch * sin(PII/3.0);
00173                         ++bd;
00174                     }
00175 
00176 
00177                     // starting from x-axis
00178                     x_coord[i] = (dx[0] * cos(PII/6.0) + dx[1] * sin(PII/6.0));
00179                     y_coord[i] = (dx[1] * cos(PII/6.0) - dx[0] * sin(PII/6.0));
00180                     i++;
00181                 }
00182             }
00183             bd = 0;
00184         }
00185     }
00186     return iBase_SUCCESS;
00187 }
00188 
00189 int CoreGen::copymove_all(const int nrank, const int numprocs)
00190 // ---------------------------------------------------------------------------
00191 // Function:
00192 // Input:    none
00193 // Output:   none
00194 // ---------------------------------------------------------------------------
00195 {
00196     if(prob_type == "mesh"){
00197         // get the copy/expand sets
00198         const char *ctag_names[] = { "GEOM_DIMENSION" };
00199         const char *ctag_vals[] = { (const char*) &set_DIM };
00200 
00201         int flag = 1;
00202         int assm_index = -1;
00203         double dx_orig[3], dx[3];
00204 
00205         if(numprocs <= (int) files.size()){
00206             // no distribution of task for copy/move; each file loaded only once
00207             int *flags = new int[assys.size()];
00208             int move_index = -1;
00209             int *run_count = new int[assys.size()];
00210             double dx[3] = { 0.0, 0.0, 0.0 };
00211             double dx_move[3] = { 0.0, 0.0, 0.0 };
00212             CMatrix<double> dx_orig(assys.size(), 3);
00213             dx_orig.Set(0.0);
00214 
00215             for (unsigned int i = 0; i < assys.size(); i++) {
00216                 flags[i]=0;
00217                 run_count[i]=0;
00218                 cm[i]->expand_sets().add_tag("MATERIAL_SET");
00219                 cm[i]->expand_sets().add_tag("DIRICHLET_SET");
00220                 cm[i]->expand_sets().add_tag("NEUMANN_SET");
00221 
00222                 cm[i]->copy_sets().add_tag("GEOM_DIMENSION");
00223 
00224                 cm[i]->update_sets();
00225               }
00226             for (int k=0; k< tot_assys; k++){
00227                 err = find_assm(k, assm_index);
00228                 if(assm_index >= 0){
00229                     // check if this file is with the proc
00230                     int out = 0;
00231                     for(int c=0; c < (int) assys.size(); c++){
00232                         if(assys_index[c] == assm_index){
00233                             //found assembly
00234                             move_index=c;
00235                             out = 0;
00236                             break;
00237                         }
00238                         else{
00239                             out = 1;
00240                         }
00241                     }
00242                     if(out == 1){
00243                         continue;
00244                     }
00245                     if (-1 == assm_index) {
00246                         continue;
00247                     }
00248 
00249                     if (flags[move_index] == 0) {
00250                         dx_move[0] = x_coord[k];
00251                         dx_move[1] = y_coord[k];
00252                         dx_move[2] = 0;
00253                         dx_orig(move_index + 1, 1) = dx_move[0];
00254                         dx_orig(move_index + 1, 2) = dx_move[1];
00255                         dx_orig(move_index + 1, 3) = dx_move[2];
00256 
00257                         move_verts(assys[move_index], dx_move);
00258                         logfile << "Moved Assembly: " << assm_index  << " dX = " << dx_move[0] << " dY = "
00259                                   << dx_move[1] << " in proc with rank " << nrank << std::endl;
00260                         if(strcmp(info.c_str(),"on") == 0)
00261                             info_file << assm_index << " \t" << k  << " \t" << dx_move[0] << " \t" << dx_move[1]  << " \t" << dx_move[2]  << " \t" << nrank << std::endl;
00262 
00263                         flags[move_index]=1;
00264                     }
00265                     else{
00266 
00267                         dx[0] =  x_coord[k] - dx_orig(move_index+1, 1);
00268                         dx[1] =  y_coord[k] - dx_orig(move_index+1, 2);
00269                         dx[2] =  0.0;
00270                         cm[move_index]->set_transform(Copy::Translate(dx));
00271                         cm[move_index]->execute_this();
00272                         ++run_count[move_index];
00273 
00274                         logfile << "Copy/moved A: " << assm_index
00275                                   <<" dX = " <<dx[0]<< " dY = " << dx[1] << " rank " << nrank << std::endl;
00276                         if(strcmp(info.c_str(),"on") == 0)
00277                             info_file << assm_index << " " << k  << "  " << dx[0] << " \t" << dx[1]  << " \t" << dx[2]  << " \t" << nrank << std::endl;
00278                         cm[move_index]->tag_copied_sets(ctag_names, ctag_vals, 1);
00279                     }
00280 
00281                 }
00282             }
00283             delete[] flags;
00284             delete[] run_count;
00285         }
00286         else{
00287             for(int i =0; i < (int) position_core[nrank].size(); i++){
00288                 assm_index = position_core[nrank][i];
00289                 if(assm_index >= 0){
00290                     // some files are loaded in two or more processors, copy/move task distribution takes place
00291                     int j = 0;
00292                     cm[j]->expand_sets().add_tag("MATERIAL_SET");
00293                     cm[j]->expand_sets().add_tag("DIRICHLET_SET");
00294                     cm[j]->expand_sets().add_tag("NEUMANN_SET");
00295 
00296                     cm[j]->copy_sets().add_tag("GEOM_DIMENSION");
00297 
00298                     cm[j]->update_sets();
00299 
00300                     if(flag == 0){
00301                         dx[0] = x_coord[assm_index] - dx_orig[0];
00302                         dx[1] = y_coord[assm_index] - dx_orig[1];
00303                         dx[2] = 0.0;
00304 
00305                         cm[0]->set_transform(Copy::Translate(dx));
00306                         cm[0]->execute_this();
00307                         logfile << "Copy/moved Assm: " << assm_index << " dX = " << dx[0] << " dY = "
00308                                   << dx[1]  << " rank " << nrank << std::endl;
00309                         if(strcmp(info.c_str(),"on") == 0)
00310                             info_file << assm_index << " \t" << i  << " \t" << dx[0] << " \t" << dx[1]  << " \t" << dx[2]  << " \t" << nrank << std::endl;
00311                       } else {
00312                         flag = 0;
00313                         dx_orig[0] = x_coord[assm_index];
00314                         dx_orig[1] = y_coord[assm_index];
00315                         dx_orig[2] = 0;
00316                         move_verts(assys[0], dx_orig);
00317                         logfile << "Moved Assm: " << assm_index << " dX = " << dx_orig[0] << " dY = "
00318                                   << dx_orig[1] << " rank " << nrank << std::endl;
00319                         if(strcmp(info.c_str(),"on") == 0)
00320                             info_file << assm_index << " \t" << i  << " \t" << dx_orig[0] << " \t" << dx_orig[1]  << " \t" << dx_orig[2]  << " \t" << nrank << std::endl;
00321 
00322                     }
00323                 }
00324             }
00325         }
00326     }
00327     else{ // prob type is geometry
00328         int assm_index = -1;
00329         // no distribution of task for copy/move; each file loaded only once
00330         int *flags = new int[assys.size()];
00331         int move_index = -1;
00332         double dx[3] = { 0.0, 0.0, 0.0 };
00333         double dx_move[3] = { 0.0, 0.0, 0.0 };
00334         CMatrix<double> dx_orig(assys.size(), 3);
00335         dx_orig.Set(0.0);
00336 
00337         for (unsigned int i = 0; i < assys.size(); i++) {
00338             flags[i]=0;
00339         }
00340 
00341         for (int k=0; k< tot_assys; k++){
00342             err = find_assm(k, assm_index);
00343             if(assm_index >= 0){
00344                 // check if this file is with the proc
00345                 int out = 0;
00346                 for(int c=0; c < (int) assys.size(); c++){
00347                     if(assys_index[c] == assm_index){
00348                         //found assembly
00349                         move_index=c;
00350                         out = 0;
00351                         break;
00352                     }
00353                     else{
00354                         out = 1;
00355                     }
00356                 }
00357                 if(out == 1){
00358                     continue;
00359                 }
00360                 if (-1 == assm_index) {
00361                     continue;
00362                 }
00363 
00364                 if (flags[move_index] == 0) {
00365                     dx_move[0] = x_coord[k];
00366                     dx_move[1] = y_coord[k];
00367                     dx_move[2] = 0;
00368                     dx_orig(move_index + 1, 1) = dx_move[0];
00369                     dx_orig(move_index + 1, 2) = dx_move[1];
00370                     dx_orig(move_index + 1, 3) = dx_move[2];
00371 
00372                     move_geoms(assys[move_index], dx_move);
00373                     logfile << "Moved Assembly: " << assm_index  << " dX = " << dx_move[0] << " dY = "
00374                               << dx_move[1] << " in proc with rank " << nrank << std::endl;
00375                     flags[move_index]=1;
00376                 }
00377                 else{
00378 
00379                     dx[0] =  x_coord[k] - dx_orig(move_index+1, 1);
00380                     dx[1] =  y_coord[k] - dx_orig(move_index+1, 2);
00381                     dx[2] =  0.0;
00382 
00383                     cg[move_index]->set_location(dx);
00384                     cg[move_index]->execute_this();
00385                     logfile << "Copy/moved A: " << assm_index
00386                               <<" dX = " <<dx[0]<< " dY = " << dx[1] << " rank " << nrank << std::endl;
00387                 }
00388 
00389             }
00390         }
00391         delete [] flags;
00392 
00393     }
00394     return iBase_SUCCESS;
00395 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines