Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int SIMULATION_core::transient(){
- PetscPrintf(PETSC_COMM_WORLD,"\n\nStart simulation:\n-----------------------------------------------\n");
- #ifndef NOADAPTATION
- // set<pVertex> PathWayPoints;
- // bool tr = true;
- // if (tr){
- // system("rm PathWayPoints");
- // ofstream PWP("./PathWayPoints", ios::app);
- // if (!PWP) {
- // PWP.open("./PathWayPoints");
- // }
- // }
- double adaptStep = 0; // performs mesh adaptation every 20 timeSteps
- bool adapt;
- double tolSat1 = pSimPar->getSatToleranceForAllElements();
- double tolSat2 = pSimPar->getSatToleranceForAllElements_excludingSingularities();
- double tolPres1 = pSimPar->getPresToleranceForAllElements();
- double tolPres2 = pSimPar->getPresToleranceForAllElements_excludingSingularities();
- int numFields = 2;
- pIData->m1 = theMesh;
- PADMEC_mesh *pm = new PADMEC_mesh;
- #endif
- LogFiles(OPENLG,0,0,0,0,pSimPar->getOutputPathName(),pSimPar->useRestart(),pSimPar->getTStepNumber(),pSimPar->getCPU_time());
- double timeStep;
- double time_step_summation = .0;
- int numAdapts = 0;
- while ( !pSimPar->finishSimulation() ){
- double time2 = pSimPar->getAccumulatedSimulationTime();
- pElliptic_eq->solver(theMesh);
- pHyperbolic_eq->solver(theMesh,timeStep);
- #ifndef NOADAPTATION
- if ( pSimPar->userRequiresAdaptation() ){
- adapt = calculate_ErrorAnalysis(pErrorAnalysis,theMesh,pSimPar,pPPData,tolSat1,tolSat2,tolPres1,tolPres2,pPPData->get_getPFuncArray(),numFields);
- pSimPar->printOutVTK(theMesh,pPPData,pErrorAnalysis,pSimPar,exportSolutionToVTK);
- static int iteration = 30;
- srand (time(NULL));
- int add = rand()%4;
- iteration += add;
- if (iteration >= 30 && !adapt) {
- iteration = 0;
- adapt = true;
- } else if(adapt) {
- //adapt = false;
- iteration = 0;
- }
- // if (tr){
- // adapt = false;
- // }
- if (adapt){
- numAdapts++;
- if(numAdapts >= 3) {
- if(numAdapts == 5) {
- throw Exception(__LINE__,__FILE__,"Exiting after 5 adaptations without any advance on the solution!");
- }
- tolSat1 = tolSat1*1.02;
- tolSat2 = tolSat2*1.02;
- tolPres1 = tolPres1*1.05;
- tolPres2 = tolPres2*1.05;
- if(pSimPar->getRefStrategy() == RH_REFINEMENT) {
- //((RH_Refinement*)pMeshAdapt)->mult(0.99);
- }
- //numAdapts = 0;
- }
- pSimPar->setSimulationTime(time2);
- switch( pSimPar->getRefStrategy() ){
- case H_REFINEMENT:
- throw Exception(__LINE__,__FILE__,"h-refinement is not yet supported.");
- break;
- case ADAPTIVE_REMESHING:
- makeMeshCopy2(pIData->m1,pm,pPPData->getPressure,pPPData->getSaturation_Old);
- pMeshAdapt->rodar(pErrorAnalysis,pIData->m1);
- deleteMesh(pIData->m1);pIData->m1 = 0;
- deleteMesh(theMesh); theMesh = 0;
- pIData->m1 = MS_newMesh(0);
- readmesh(pIData->m1,"Final_01.msh");
- theMesh = pIData->m1;
- makeMeshCopy2(pm,pIData->m2,pPPData->setPressure,pPPData->setSaturation);
- //PADMEC_GAMBIARRA(pIData->m1);
- interpolation(pIData,pSimPar->getInterpolationMethod());
- EBFV1_preprocessor(pIData->m1,pGCData);
- #ifdef __ADAPTATION_DEBUG__
- validate_EBFV1(pGCData,pIData->m1,pSimPar->setOfDomains);
- if (!pSimPar->setOfDomains.size()){
- throw Exception(__LINE__,__FILE__,"Num domains NULL!\n");
- }
- #endif
- updatePointersData(theMesh);
- deleteMesh(pm);
- deleteMesh(pIData->m2); pIData->m2 = 0;
- pIData->m2 = MS_newMesh(0);
- break;
- case RH_REFINEMENT:
- cout << "refinamento" << endl;
- makeMeshCopy2(pIData->m1,pm,pPPData->getPressure,pPPData->getSaturation_Old);
- pMeshAdapt->rodar(pErrorAnalysis,pIData->m1);
- AOMD_Util::Instance()->ex_port("FMDB2.msh", pIData->m1, true);
- //pSimPar->printOutVTK(pIData->m1,pPPData,pErrorAnalysis,pSimPar,exportSolutionToVTK);
- //STOP();
- if(pSimPar->getInterpolationMethod() == h_REFINEMENT) {
- deleteMesh(theMesh); theMesh = 0;
- theMesh = pIData->m1;
- }
- else {
- deleteMesh(pIData->m1);pIData->m1 = 0;
- deleteMesh(theMesh); theMesh = 0;
- pIData->m1 = MS_newMesh(0);
- readmesh(pIData->m1,"MAD2.msh");
- theMesh = pIData->m1;
- makeMeshCopy2(pm,pIData->m2,pPPData->setPressure,pPPData->setSaturation);
- interpolation(pIData,pSimPar->getInterpolationMethod());
- }
- cout << "preprocessamento" << endl;
- EBFV1_preprocessor(pIData->m1,pGCData);
- #ifdef __ADAPTATION_DEBUG__
- validate_EBFV1(pGCData,pIData->m1,pSimPar->setOfDomains);
- if (!pSimPar->setOfDomains.size()){
- throw Exception(__LINE__,__FILE__,"Num domains NULL!\n");
- }
- #endif
- cout << "update" << endl;
- updatePointersData(theMesh);
- cout << "fimupd" << endl;
- deleteMesh(pm);
- deleteMesh(pIData->m2); pIData->m2 = 0;
- pIData->m2 = MS_newMesh(0);
- cout << "fim" << endl;
- break;
- default:
- throw Exception(__LINE__,__FILE__,"Unknown adaptation strategy.");
- }
- } else { numAdapts = 0; }
- } else { pSimPar->printOutVTK(theMesh,pPPData,pErrorAnalysis,pSimPar,exportSolutionToVTK); }
- #endif
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement