- Timestamp:
- 12/22/21 10:39:44 (3 years ago)
- Location:
- issm/trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk
- Property svn:mergeinfo changed
/issm/trunk-jpl merged: 25837-25866,25868-25993,25995-26330,26332-26733,26736-26739,26741
- Property svn:mergeinfo changed
-
issm/trunk/src
- Property svn:mergeinfo changed
-
issm/trunk/src/c
- Property svn:ignore
-
old new 20 20 issm 21 21 kriging 22 issm_slc 22 23 issm_slr 23 24 issm_ocean
-
- Property svn:ignore
-
issm/trunk/src/c/solutionsequences/solutionsequence_schurcg.cpp
r25836 r26744 33 33 IssmPDouble t1,t2; /* Time measurement for bottleneck analysis */ 34 34 35 36 35 double tmp1,tmp2,tmp3; 37 36 int tmpi; … … 39 38 40 39 int noIt; 41 42 43 40 44 41 int precond = 0; … … 49 46 PetscBool flag,flg; 50 47 #endif 51 52 48 53 49 char ksp_type[50]; … … 71 67 #endif 72 68 73 74 69 if(precond){ 75 70 _printf0_("Running WITH preconditioner\n"); … … 78 73 } 79 74 80 81 75 /*Initialize output*/ 82 76 Vector<IssmDouble>* out_uf=new Vector<IssmDouble>(uf0); 83 77 84 78 /* Extract block matrices from the saddle point matrix */ 85 79 /* [ A B ] = Kff … … 97 91 MatGetSubMatrix(Kff,isp,isv,MAT_INITIAL_MATRIX,&BT); 98 92 #endif 99 93 100 94 /* Extract preconditioner matrix on the pressure space*/ 101 95 #if PETSC_VERSION_GT(3,8,0) … … 105 99 #endif 106 100 107 108 101 /* Get number of velocity / pressure nodes */ 109 102 MatGetSize(B,&nu,&np); … … 117 110 VecGetSubVector(out_uf->pvector->vector,isv,&uold); 118 111 VecGetSubVector(out_uf->pvector->vector,isp,&p); 119 120 112 121 113 /* Set up intermediaries */ … … 133 125 VecDuplicate(p,&wnew);VecSet(wnew,0.0); 134 126 VecDuplicate(uold,&chi);VecSet(chi,0.0); 135 127 136 128 /* Get global RHS (for each block sub-problem respectively)*/ 137 129 VecGetSubVector(pf,isv,&f1); … … 143 135 /* a(u0,v) = f1(v)-b(p0,v) i.e. Au0 = F1-Bp0 */ 144 136 /* u0 = u_DIR on \Gamma_DIR */ 145 137 146 138 /* Create KSP context */ 147 139 KSPCreate(IssmComm::GetComm(),&kspu); … … 174 166 _error_("Suggested KSP method not implemented yet!\n"); 175 167 } 176 168 177 169 KSPSetInitialGuessNonzero(kspu,PETSC_TRUE); 178 170 179 171 /*Strong rel. residual tolerance needed when solving for the velocity update. 180 172 * This is because ISSM uses the dimensional equations, so the initial guess chi = 0 181 173 * results in a very high initial residual (~ 1e19)*/ 182 174 KSPSetTolerances(kspu,ELLTOL,PETSC_DEFAULT,PETSC_DEFAULT,maxiter); //maxiter 183 184 185 175 186 176 KSPGetPC(kspu,&pcu); … … 210 200 KSPSetUp(kspu); 211 201 212 213 202 /* Create RHS */ 214 203 /* RHS = F1-B * pold */ … … 227 216 VecNorm(resu,NORM_2,&tmp5); 228 217 229 230 } 231 218 } 232 219 233 220 /* Go solve Au0 = F1-Bp0*/ … … 235 222 KSPGetIterationNumber(kspu,&noIt); 236 223 237 238 239 224 if (VerboseConvergence()) 240 225 { 241 226 242 227 KSPGetIterationNumber(kspu,&tmpi); 243 228 VecScale(rhsu,-1.);MatMultAdd(A,uold,rhsu,tmpu);VecScale(rhsu,-1.); … … 249 234 } 250 235 251 252 253 236 /* Set up u_new */ 254 237 VecDuplicate(uold,&unew);VecCopy(uold,unew); 255 238 VecAssemblyBegin(unew);VecAssemblyEnd(unew); 256 239 257 258 259 240 /* ------------------------------------------------------------- */ 260 241 261 242 /*Get initial residual*/ 262 243 /*(1/mu(x) * g0, q) = b(q,u0) - (f2,q) i.e. IP * g0 = BT * u0 - F2*/ 263 244 264 245 /* Create KSP context */ 265 246 KSPCreate(IssmComm::GetComm(),&kspip); … … 269 250 KSPSetOperators(kspip,IP,IP,DIFFERENT_NONZERO_PATTERN); 270 251 #endif 271 252 272 253 /* Create RHS */ 273 254 /* RHS = BT * uold - F2 */ 274 255 VecScale(uold,-1.);MatMultAdd(BT,uold,f2,rhsp);VecScale(uold,-1.); 275 256 276 277 257 /* Set KSP & PC options */ 278 258 KSPSetType(kspip,KSPGMRES); 279 259 KSPSetInitialGuessNonzero(kspip,PETSC_TRUE); 280 281 260 282 261 KSPGetPC(kspip,&pcp); 283 262 PCSetType(pcp,PCJACOBI); … … 294 273 } 295 274 296 297 298 275 /* Go solve */ 299 276 KSPSolve(kspip,rhsp,gold); 300 277 301 302 303 278 if (VerboseConvergence()) 304 279 { 305 280 306 281 KSPGetResidualNorm(kspip,&tmp1); 307 282 VecScale(rhsp,-1.);MatMultAdd(IP,gold,rhsp,tmpp);VecScale(rhsp,-1.); … … 311 286 _printf0_("||IP*g00 - rhsp||_euc: " << tmp4 <<"\n||Jac(-1)*(IP*g00-rhsp)||_euc: " << tmp5 << "\n||IP*gn0-rhsp||_euc: " << tmp2<< "\n||Jac(-1)*(IP*gn0-rhsp)||_euc: " << tmp1 << "\nIteration number: "<<tmpi<<"\n"); 312 287 } 313 314 288 315 289 /*Initial residual*/ … … 318 292 _printf0_("inner product norm g0: "<<initRnorm<<"\n"); 319 293 320 321 294 /*Iterate only if inital residual large enough*/ 322 295 if(initRnorm > 1e-5) … … 326 299 VecDuplicate(gold,&gnew);VecCopy(gold,gnew); 327 300 VecAssemblyBegin(gnew);VecAssemblyEnd(gnew); 328 329 301 330 302 /* ------------------------------------------------------------ */ … … 334 306 VecDuplicate(gold,&wold);VecCopy(gold,wold); 335 307 VecAssemblyBegin(wold);VecAssemblyEnd(wold); 336 337 308 338 309 /* Count number of iterations */ … … 351 322 VecScale(wold,1.);MatMult(B,wold,rhsu);VecScale(wold,1.); 352 323 VecSet(chi,0.0); 353 354 324 355 325 if(VerboseConvergence()) 356 326 { 357 327 VecScale(rhsu,-1.);MatMultAdd(A,chi,rhsu,tmpu);VecScale(rhsu,-1.); 358 328 VecNorm(tmpu,NORM_2,&tmp4); 359 329 360 330 KSPInitialResidual(kspu,chi,tmpu,tmpu2,resu,rhsu); 361 331 VecNorm(resu,NORM_2,&tmp5); … … 363 333 } 364 334 365 366 335 KSPSolve(kspu,rhsu,chi); 367 368 369 370 336 371 337 if (VerboseConvergence()) 372 338 { 373 339 VecNorm(chi,NORM_2,&tmp1); 374 340 KSPGetResidualNorm(kspu,&tmp2); 375 341 376 342 VecScale(rhsu,-1.);MatMultAdd(A,chi,rhsu,tmpu);VecScale(rhsu,-1.); 377 343 VecNorm(tmpu,NORM_2,&tmp3); 378 379 344 380 345 KSPGetIterationNumber(kspu,&tmpi); 381 346 _printf0_("||chi_nk||_euc: "<< tmp1 << "\n||A*chi_0k - rhsu||_euc: "<<tmp4<< "\n||P(-1)*(A*chi_0k-rhsu)||_euc: " << tmp5 << "\n||A*chi_nk - rhsu||_euc: "<< tmp3 <<"\n||P(-1)*(A*chi_nk - rhsu)||_euc: " << tmp2 <<"\nIteration Number: " << tmpi <<"\n"); 382 347 } 383 348 384 385 349 /* ---------------------------------------------------------- */ 386 387 350 388 351 /*Set step size*/ … … 390 353 MatMult(IP,gold,tmpp); 391 354 VecDot(tmpp,wold,&rho); 392 355 393 356 MatMult(BT,chi,tmpp); 394 357 VecDot(tmpp,wold,&tmpScalar); 395 358 rho = rho/tmpScalar; 396 359 397 398 360 /* ---------------------------------------------------------- */ 399 400 361 401 362 /*Pressure update*/ 402 363 /*p(m+1) = pm + rhom * wm*/ 403 364 VecAXPY(p,-1.*rho,wold); 404 405 365 406 366 /*Velocity update*/ … … 408 368 VecWAXPY(unew,rho,chi,uold); 409 369 VecNorm(unew,NORM_2,&tmpScalar); 410 411 370 412 371 if (VerboseConvergence()) … … 421 380 _printf0_("Incompressibility norm: " << tmp7 <<"\n"); 422 381 } 423 424 425 382 426 383 /* ---------------------------------------------------------- */ … … 432 389 VecWAXPY(rhsp,-1.*rho,tmpp,tmpp2); 433 390 KSPSolve(kspip,rhsp,gnew); 434 435 436 391 437 392 /* ---------------------------------------------------------- */ 438 393 439 394 MatMult(IP,gnew,tmpp); 440 395 441 396 VecDot(tmpp,gnew,&gamma); 442 397 rnorm = sqrt(gamma); … … 454 409 _printf0_("L2-Norm g: "<< rnorm << "\n"); 455 410 } 456 411 457 412 /*Break prematurely if solver doesn't reach desired tolerance in reasonable time frame*/ 458 413 if(count > 10./TOL) … … 461 416 break; 462 417 } 463 464 418 465 419 /* ---------------------------------------------------------- */ 466 467 420 468 421 /*Directional update*/ … … 475 428 /* Assign new to old iterates */ 476 429 VecCopy(wnew,wold);VecCopy(gnew,gold);VecCopy(unew,uold); 477 430 478 431 count++; 479 432 } … … 487 440 *puf=out_uf; 488 441 489 490 442 /* Cleanup */ 491 443 KSPDestroy(&kspu);KSPDestroy(&kspip); 492 444 493 445 MatDestroy(&A);MatDestroy(&B);MatDestroy(&BT);MatDestroy(&IP); 494 446 495 447 VecDestroy(&p);VecDestroy(&uold);VecDestroy(&unew);VecDestroy(&rhsu);VecDestroy(&rhsp); 496 448 VecDestroy(&gold);VecDestroy(&gnew);VecDestroy(&wold);VecDestroy(&wnew);VecDestroy(&chi); … … 522 474 double rnorm1, rnorm2; 523 475 524 525 476 if(VerboseModule()) _printf0_(" checking convergence\n"); 526 477 … … 548 499 MatGetSubMatrix(Kff->pmatrix->matrix,isp,isv,MAT_INITIAL_MATRIX,&BT); 549 500 #endif 550 501 551 502 /*no. of free nodes in velocity/pressure space*/ 552 503 MatGetSize(B,&n_u,&n_p); … … 560 511 VecGetSubVector(uf->pvector->vector,isv,&u); 561 512 VecGetSubVector(uf->pvector->vector,isp,&p); 562 563 513 564 514 /*Extract values of the RHS corresponding to the first/second block*/ … … 573 523 VecDuplicate(p,&res2);VecSet(res2,1.0); 574 524 575 576 525 /*Display solver caracteristics*/ 577 526 if (VerboseConvergence()){ 578 527 579 528 /*Calculate res1 = A*u + B*p - f1*/ 580 529 VecScale(f1,-1.);MatMultAdd(A,u,f1,tmp);MatMultAdd(B,p,tmp,res1);VecScale(f1,-1.); 581 530 /*Calculate res2 = B^T * u - f2*/ 582 531 VecScale(f2,-1.);MatMultAdd(BT,u,f2,res2);VecScale(f2,-1.); 583 584 532 585 533 /*compute norm(res1), norm(res2), norm(F) and residue*/ … … 597 545 VecRestoreSubVector(uf->pvector->vector,isv,&u); 598 546 VecRestoreSubVector(uf->pvector->vector,isp,&p); 599 547 600 548 /*Extract values corresponding to velocity/pressure on the old solution*/ 601 549 VecGetSubVector(old_uf->pvector->vector,isv,&uold); 602 550 VecGetSubVector(old_uf->pvector->vector,isp,&pold); 603 604 551 605 552 /*Force equilibrium (Mandatory)*/ … … 609 556 /*Calculate res2 = B^T * uold - f2*/ 610 557 VecScale(f2,-1.);MatMultAdd(BT,uold,f2,res2);VecScale(f2,-1.); 611 558 612 559 /*compute norm(res1), norm(res2), norm(F) and residue*/ 613 560 VecNorm(res1,NORM_2,&rnorm1);VecNorm(res2,NORM_2,&rnorm2); … … 626 573 VecRestoreSubVector(old_uf->pvector->vector,isv,&uold); 627 574 VecRestoreSubVector(old_uf->pvector->vector,isp,&pold); 628 629 630 575 631 576 //print … … 721 666 int count=0; 722 667 bool converged=false; 723 668 724 669 /*Start non-linear iteration using input velocity: */ 725 670 GetSolutionFromInputsx(&ug,femmodel); … … 729 674 InputUpdateFromConstantx(femmodel,converged,ConvergedEnum); 730 675 InputUpdateFromSolutionx(femmodel,ug); 731 676 732 677 for(;;){ 733 678 … … 747 692 PetscOptionsGetInt(NULL,PETSC_NULL,"-schur_pc",&precond,NULL); 748 693 #endif 749 694 750 695 StressbalanceAnalysis* analysis = new StressbalanceAnalysis(); 751 696 752 697 /* Construct Schur preconditioner matrix or mass matrix depending on input */ 753 698 if(precond) … … 760 705 } 761 706 }else{ 762 707 763 708 for(Object* & object : femmodel->elements->objects){ 764 709 Element* element2=xDynamicCast<Element*>(object); … … 769 714 } 770 715 771 772 716 delete analysis; 773 717 774 718 /*Obtain index sets for velocity and pressure components */ 775 719 IS isv = NULL; … … 785 729 Kff->Assemble(); 786 730 787 788 731 /*Solve*/ 789 732 femmodel->profiler->Start(SOLVER); 790 733 _assert_(Kff->type==PetscMatType); 791 792 734 793 735 SchurCGSolver(&uf,
Note:
See TracChangeset
for help on using the changeset viewer.