Advertisement
Guest User

Untitled

a guest
Jul 12th, 2014
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.31 KB | None | 0 0
  1.     int SIMULATION_core::transient(){
  2.         PetscPrintf(PETSC_COMM_WORLD,"\n\nStart simulation:\n-----------------------------------------------\n");
  3. #ifndef NOADAPTATION
  4.  
  5. //      set<pVertex> PathWayPoints;
  6. //      bool tr = true;
  7. //      if (tr){
  8.        
  9.            
  10. //          system("rm PathWayPoints");
  11.  
  12. //          ofstream PWP("./PathWayPoints", ios::app);
  13.  
  14. //          if (!PWP) {
  15. //              PWP.open("./PathWayPoints");
  16. //          }
  17.  
  18. //      }
  19.  
  20.         double adaptStep = 0;   // performs mesh adaptation every 20 timeSteps
  21.         bool adapt;
  22.         double tolSat1 = pSimPar->getSatToleranceForAllElements();
  23.         double tolSat2 = pSimPar->getSatToleranceForAllElements_excludingSingularities();
  24.         double tolPres1 = pSimPar->getPresToleranceForAllElements();
  25.         double tolPres2 = pSimPar->getPresToleranceForAllElements_excludingSingularities();
  26.         int numFields = 2;
  27.         pIData->m1 = theMesh;
  28.         PADMEC_mesh *pm = new PADMEC_mesh;
  29. #endif
  30.         LogFiles(OPENLG,0,0,0,0,pSimPar->getOutputPathName(),pSimPar->useRestart(),pSimPar->getTStepNumber(),pSimPar->getCPU_time());
  31.         double timeStep;
  32.         double time_step_summation = .0;
  33.  
  34.         int numAdapts = 0;
  35.  
  36.         while ( !pSimPar->finishSimulation() ){
  37.             double time2 = pSimPar->getAccumulatedSimulationTime();
  38.             pElliptic_eq->solver(theMesh);
  39.  
  40.             pHyperbolic_eq->solver(theMesh,timeStep);
  41.            
  42. #ifndef NOADAPTATION
  43.             if ( pSimPar->userRequiresAdaptation() ){
  44.                 adapt = calculate_ErrorAnalysis(pErrorAnalysis,theMesh,pSimPar,pPPData,tolSat1,tolSat2,tolPres1,tolPres2,pPPData->get_getPFuncArray(),numFields);
  45.  
  46.                 pSimPar->printOutVTK(theMesh,pPPData,pErrorAnalysis,pSimPar,exportSolutionToVTK);
  47.                
  48.                 static int iteration = 30;
  49.                 srand (time(NULL));
  50.                 int add = rand()%4;
  51.                 iteration += add;
  52.  
  53.                 if (iteration >= 30 && !adapt) {
  54.                     iteration = 0;
  55.                     adapt = true;
  56.                 } else if(adapt) {
  57.                     //adapt = false;
  58.                     iteration = 0;
  59.                 }
  60.  
  61.         //      if (tr){
  62.         //          adapt = false;
  63.         //      }
  64.  
  65.                 if (adapt){
  66.                     numAdapts++;
  67.                     if(numAdapts >= 3) {
  68.                         if(numAdapts == 5) {
  69.                             throw Exception(__LINE__,__FILE__,"Exiting after 5 adaptations without any advance on the solution!");
  70.                         }
  71.                         tolSat1 = tolSat1*1.02;
  72.                         tolSat2 = tolSat2*1.02;
  73.                         tolPres1 = tolPres1*1.05;
  74.                         tolPres2 = tolPres2*1.05;
  75.                         if(pSimPar->getRefStrategy() == RH_REFINEMENT) {
  76.                             //((RH_Refinement*)pMeshAdapt)->mult(0.99);
  77.                         }
  78.                         //numAdapts = 0;
  79.                     }
  80.                     pSimPar->setSimulationTime(time2);
  81.                     switch( pSimPar->getRefStrategy() ){
  82.                         case H_REFINEMENT:
  83.                             throw Exception(__LINE__,__FILE__,"h-refinement is not yet supported.");
  84.                             break;
  85.  
  86.                         case ADAPTIVE_REMESHING:
  87.                             makeMeshCopy2(pIData->m1,pm,pPPData->getPressure,pPPData->getSaturation_Old);
  88.  
  89.                             pMeshAdapt->rodar(pErrorAnalysis,pIData->m1);
  90.  
  91.                             deleteMesh(pIData->m1);pIData->m1 = 0;
  92.                             deleteMesh(theMesh); theMesh = 0;
  93.                             pIData->m1 = MS_newMesh(0);
  94.  
  95.                             readmesh(pIData->m1,"Final_01.msh");
  96.  
  97.                             theMesh = pIData->m1;
  98.                             makeMeshCopy2(pm,pIData->m2,pPPData->setPressure,pPPData->setSaturation);
  99.                             //PADMEC_GAMBIARRA(pIData->m1);
  100.  
  101.                             interpolation(pIData,pSimPar->getInterpolationMethod());
  102.  
  103.                             EBFV1_preprocessor(pIData->m1,pGCData);
  104.  
  105.                             #ifdef __ADAPTATION_DEBUG__
  106.                                 validate_EBFV1(pGCData,pIData->m1,pSimPar->setOfDomains);
  107.                                 if (!pSimPar->setOfDomains.size()){
  108.                                     throw Exception(__LINE__,__FILE__,"Num domains NULL!\n");
  109.                                 }
  110.                             #endif
  111.  
  112.                             updatePointersData(theMesh);
  113.                             deleteMesh(pm);
  114.                             deleteMesh(pIData->m2); pIData->m2 = 0;
  115.                             pIData->m2 = MS_newMesh(0);
  116.  
  117.                             break;
  118.  
  119.                         case RH_REFINEMENT:
  120.                             cout << "refinamento" << endl;
  121.                             makeMeshCopy2(pIData->m1,pm,pPPData->getPressure,pPPData->getSaturation_Old);
  122.  
  123.                             pMeshAdapt->rodar(pErrorAnalysis,pIData->m1);
  124.                            
  125.                             AOMD_Util::Instance()->ex_port("FMDB2.msh", pIData->m1, true);
  126.                             //pSimPar->printOutVTK(pIData->m1,pPPData,pErrorAnalysis,pSimPar,exportSolutionToVTK);
  127.                            
  128.                             //STOP();
  129.                             if(pSimPar->getInterpolationMethod() == h_REFINEMENT) {
  130.                                 deleteMesh(theMesh); theMesh = 0;
  131.  
  132.                                 theMesh = pIData->m1;
  133.                             }
  134.                             else {
  135.                                 deleteMesh(pIData->m1);pIData->m1 = 0;
  136.                                 deleteMesh(theMesh); theMesh = 0;
  137.                                 pIData->m1 = MS_newMesh(0);
  138.  
  139.                                 readmesh(pIData->m1,"MAD2.msh");
  140.                                 theMesh = pIData->m1;
  141.                                 makeMeshCopy2(pm,pIData->m2,pPPData->setPressure,pPPData->setSaturation);
  142.  
  143.                                 interpolation(pIData,pSimPar->getInterpolationMethod());
  144.                             }
  145.                             cout << "preprocessamento" << endl;
  146.                             EBFV1_preprocessor(pIData->m1,pGCData);
  147.  
  148.                             #ifdef __ADAPTATION_DEBUG__
  149.                                 validate_EBFV1(pGCData,pIData->m1,pSimPar->setOfDomains);
  150.                                 if (!pSimPar->setOfDomains.size()){
  151.                                     throw Exception(__LINE__,__FILE__,"Num domains NULL!\n");
  152.                                 }
  153.                             #endif
  154.                             cout << "update" << endl;
  155.                             updatePointersData(theMesh);
  156.                             cout << "fimupd" << endl;
  157.                             deleteMesh(pm);
  158.                             deleteMesh(pIData->m2); pIData->m2 = 0;
  159.                             pIData->m2 = MS_newMesh(0);
  160.                             cout << "fim" << endl;
  161.                             break;
  162.  
  163.                         default:
  164.                             throw Exception(__LINE__,__FILE__,"Unknown adaptation strategy.");
  165.                     }
  166.  
  167.                 } else { numAdapts = 0; }
  168.  
  169.             } else { pSimPar->printOutVTK(theMesh,pPPData,pErrorAnalysis,pSimPar,exportSolutionToVTK); }
  170. #endif
  171.         }
  172.         return 0;
  173.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement