void LinearImplicitSystem::solve() { clock_t start_mg_time = clock(); bool isThisFullCycle; unsigned grid0; if(_mg_type == F_CYCLE) { isThisFullCycle = 1; grid0 = 1; } else if(_mg_type == V_CYCLE){ isThisFullCycle = 0; grid0 = _gridn; } else if(_mg_type == M_CYCLE){ isThisFullCycle = 0; grid0 = _gridr; } else{ std::cout << "wrong mg_type for this solver "<<std::endl; abort(); } unsigned AMR_counter=0; for ( unsigned igridn = grid0; igridn <= _gridn; igridn++) { //_igridn std::cout << std::endl << " ************* Level : " << igridn -1 << " *************\n" << std::endl; bool ThisIsAMR = (_mg_type == F_CYCLE && _AMRtest && AMR_counter<_maxAMRlevels && igridn==_gridn)?1:0; if(ThisIsAMR) _solution[igridn-1]->InitAMREps(); Vcycle(igridn, isThisFullCycle ); // ============== AMR ============== if(ThisIsAMR){ bool conv_test=0; if(_AMRnorm==0){ conv_test=_solution[_gridn-1]->FlagAMRRegionBasedOnl2(_SolSystemPdeIndex,_AMRthreshold); } else if (_AMRnorm==1){ conv_test=_solution[_gridn-1]->FlagAMRRegionBasedOnSemiNorm(_SolSystemPdeIndex,_AMRthreshold); } if(conv_test==0){ _ml_msh->AddAMRMeshLevel(); _ml_sol->AddSolutionLevel(); AddSystemLevel(); AMR_counter++; } else{ _maxAMRlevels=AMR_counter; std::cout<<"The AMR solver has converged after "<<AMR_counter<<" refinements.\n"; } } // ============== Solution Prolongation ============== if (igridn < _gridn) { ProlongatorSol(igridn); } } std::cout << "\t SOLVER TIME:\t " << std::setw(11) << std::setprecision(6) << std::fixed <<static_cast<double>((clock()-start_mg_time))/CLOCKS_PER_SEC << std::endl; }
void NonLinearImplicitSystem::solve() { clock_t start_mg_time = clock(); bool full_cycle; unsigned igrid0; if(_mg_type == F_CYCLE) { std::cout<< std::endl<<" *** Start MultiLevel Full-Cycle ***" << std::endl; full_cycle=1; igrid0=1; } else if(_mg_type == V_CYCLE){ std::cout<< std::endl<<" *** Start MultiLevel V-Cycle ***" << std::endl; full_cycle=0; igrid0=_gridn; } else { std::cout<< std::endl<<" *** Start MultiLevel AMR-Cycle ***" << std::endl; full_cycle=0; igrid0=_gridr; } unsigned AMR_counter=0; for ( unsigned igridn=igrid0; igridn <= _gridn; igridn++) { //_igridn std::cout << std::endl << " ****** Start Level Max " << igridn << " ******" << std::endl; clock_t start_nl_time = clock(); bool ThisIsAMR = (_mg_type == F_CYCLE && _AMRtest && AMR_counter<_maxAMRlevels && igridn==_gridn)?1:0; if(ThisIsAMR) _solution[igridn-1]->InitAMREps(); for ( unsigned nonLinearIterator = 0; nonLinearIterator < _n_max_nonlinear_iterations; nonLinearIterator++ ) { //non linear cycle std::cout << std::endl << " ********* Nonlinear iteration " << nonLinearIterator + 1 << " *********" << std::endl; Vcycle(igridn, full_cycle, nonLinearIterator ); // ============== Test for non-linear Convergence ============== bool isnonlinearconverged = IsNonLinearConverged(igridn-1); if (isnonlinearconverged) nonLinearIterator = _n_max_nonlinear_iterations+1; } if(ThisIsAMR){ bool conv_test=0; if(_AMRnorm==0){ conv_test=_solution[_gridn-1]->FlagAMRRegionBasedOnl2(_SolSystemPdeIndex,_AMRthreshold); } else if (_AMRnorm==1){ conv_test=_solution[_gridn-1]->FlagAMRRegionBasedOnSemiNorm(_SolSystemPdeIndex,_AMRthreshold); } if(conv_test==0){ _ml_msh->AddAMRMeshLevel(); _ml_sol->AddSolutionLevel(); AddSystemLevel(); AMR_counter++; } else{ _maxAMRlevels=AMR_counter; std::cout<<"The AMR solver has converged after "<<AMR_counter<<" refinements.\n"; } } if (igridn < _gridn) { ProlongatorSol(igridn); } std::cout << std::endl << " ****** Nonlinear-Cycle TIME: " << std::setw(11) << std::setprecision(6) << std::fixed <<static_cast<double>((clock()-start_nl_time))/CLOCKS_PER_SEC << std::endl; std::cout << std::endl << " ****** End Level Max "<< igridn << " ******" << std::endl; } std::cout << std::endl << " *** MultiGrid TIME: " << std::setw(11) << std::setprecision(6) << std::fixed <<static_cast<double>((clock()-start_mg_time))/CLOCKS_PER_SEC << std::endl; }