Changeset 5aaa704
- Timestamp:
- 08/01/06 17:52:40 (7 years ago)
- Branches:
- master, external, fix-prolong, refactor, refactor-ext, refactor-subsolvers
- Children:
- 821f89d
- Parents:
- 98817b2
- git-author:
- eero <eero@…> (08/01/06 17:52:40)
- git-committer:
- eero <eero@…> (08/01/06 17:52:40)
- File:
-
- 1 edited
-
src/solvers/pcg.f90 (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/solvers/pcg.f90
r792ba1b r5aaa704 217 217 end subroutine pcg 218 218 219 220 !-------------------------------221 ! Setup preconditioner222 !-------------------------------223 subroutine setup_preconditioner(sol,A,rhs,CoarseMtx_, Restrict)224 use subsolvers225 use CoarseMtx_mod226 implicit none227 real(kind=rk),dimension(:),pointer :: sol228 type(SpMtx), intent(in) :: A229 real(kind=rk),dimension(:),pointer :: rhs230 type(SpMtx),optional :: CoarseMtx_ ! Coarse matrix231 type(SpMtx),optional :: Restrict ! Restriction matrix232 233 ! ----- local: ------234 real(kind=rk),dimension(:),pointer :: csol,crhs,tmpsol235 ! ----------------------------236 sol=0.0_rk237 if (present(CoarseMtx_)) then238 call sparse_multisolve(sol,A,rhs,CoarseMtx_) !fine solves239 !call sparse_multisolve(sol,A,rhs) !fine solves240 if (sctls%levels>1) then241 if (coarseid==0) then ! setup coarse solve:242 allocate(crhs(CoarseMtx_%ncols))243 allocate(csol(CoarseMtx_%nrows))244 allocate(tmpsol(A%nrows))245 call SpMtx_Ax(crhs,Restrict,rhs,dozero=.true.) ! restriction246 !csol=0.0_rk247 write (stream,*) &248 'factorising coarse matrix of size',CoarseMtx_%nrows, &249 ' and nnz:',CoarseMtx_%nnz250 call sparse_singlesolve(coarseid,csol,crhs, &251 nfreds=CoarseMtx_%nrows, &252 nnz=CoarseMtx_%nnz, &253 indi=CoarseMtx_%indi, &254 indj=CoarseMtx_%indj, &255 val=CoarseMtx_%val)256 write (stream,*) 'coarse factorisation done!'257 !tmpsol=0.0_rk258 call SpMtx_Ax(tmpsol,Restrict,csol,dozero=.true.,transp=.true.) ! interpolation259 !call SpMtx_Ax(tmpsol,Interp,csol,dozero=.true.,transp=.false.) ! interpolation260 else ! apply coarse solve:261 call SpMtx_Ax(crhs,Restrict,rhs,dozero=.true.) ! restriction262 !csol=0.0_rk263 call sparse_singlesolve(coarseid,csol,crhs, &264 nfreds=CoarseMtx_%nrows)265 !tmpsol=0.0_rk266 call SpMtx_Ax(tmpsol,Restrict,csol,dozero=.true.,transp=.true.) ! interpolation267 !call SpMtx_Ax(tmpsol,Interp,csol,dozero=.true.,transp=.false.) ! interpolation268 endif269 !sol=sol+tmpsol270 sol(1:A%nrows)=sol(1:A%nrows)+tmpsol(1:A%nrows)271 endif272 else273 call sparse_multisolve(sol,A,rhs)274 endif275 end subroutine setup_preconditioner276 277 219 !------------------------------- 278 220 ! Make preconditioner 279 221 !------------------------------- 280 subroutine preconditioner(sol,A,rhs, A_interf_,CoarseMtx_,Restrict,refactor_,cdat)222 subroutine preconditioner(sol,A,rhs,M,A_interf_,CoarseMtx_,Restrict,refactor_,cdat) 281 223 use subsolvers 282 224 use CoarseMtx_mod … … 287 229 type(SpMtx) :: A 288 230 real(kind=rk),dimension(:),pointer :: rhs 231 type(Mesh),intent(in) :: M ! Mesh 232 real(kind=rk),dimension(:),pointer :: res ! -- residual vector, allocated 233 ! here for multiplicative Schwarz 289 234 type(SpMtx),optional :: A_interf_ ! matr@interf. 290 235 type(SpMtx),optional :: CoarseMtx_ ! Coarse matrix 291 236 type(SpMtx),optional :: Restrict ! Restriction matrix 292 logical,intent(in ),optional :: refactor_237 logical,intent(inout),optional :: refactor_ 293 238 type(CoarseData),intent(inout),optional :: cdat 294 239 ! ----- local: ------ … … 307 252 if (present(CoarseMtx_)) then !{ 308 253 309 if (.not.present(Restrict)) call DOUG_abort("Restriction matrix needs to be passed along with the coarse matrix!")254 if (.not.present(Restrict)) call DOUG_abort("Restriction matrix needs to be passed along with the coarse matrix!") 310 255 311 if (present(cdat)) then 312 313 !do i=1,MG%nlf 314 ! if (MG%inner_interf_fmask(i)/=0) & 315 ! write(stream,*) MG%lg_fmap(i), rhs(i) 316 !enddo 317 318 256 if (present(cdat)) then 319 257 ! Not the first iteration, so send the coarse vector here 320 258 if (.not.(present(refactor_).and.refactor_)) then 321 call SpMtx_Ax(clrhs,Restrict,rhs,dozero=.true.) ! restrict <RA>259 call SpMtx_Ax(clrhs,Restrict,rhs,dozero=.true.) ! restrict <RA> 322 260 ! call Vect_print(rhs,"RHS") 323 261 324 262 ! And send 325 call AllSendCoarseVector(clrhs,cdat%nprocs,cdat%cdisps,cdat%send, &263 call AllSendCoarseVector(clrhs,cdat%nprocs,cdat%cdisps,cdat%send, & 326 264 useprev=.true.) 327 265 else ! First iteration - send matrix 328 call AllSendCoarseMtx(cdat%LAC,CoarseMtx_,cdat%lg_cfmap,&266 call AllSendCoarseMtx(cdat%LAC,CoarseMtx_,cdat%lg_cfmap,& 329 267 cdat%ngfc,cdat%nprocs,cdat%send) 330 allocate(ctmp(cdat%ngfc))331 268 allocate(ctmp(cdat%ngfc)) 269 332 270 endif 333 271 endif 334 272 273 if (sctls%method>1) then ! For multiplicative Schwarz method...: 274 allocate(res(size(rhs))) 275 endif 335 276 if (sctls%input_type==DCTL_INPUT_TYPE_ELEMENTAL) then 336 call sparse_multisolve(sol=sol,A= a,rhs=rhs, &277 call sparse_multisolve(sol=sol,A=A,M=M,rhs=rhs,res=res, & 337 278 A_interf_=A_interf_, & 338 279 refactor=refactor_) !fine solves 339 280 else 340 call sparse_multisolve(sol=sol,A= a,rhs=rhs, &281 call sparse_multisolve(sol=sol,A=A,M=M,rhs=rhs,res=res, & 341 282 A_interf_=A_interf_,AC=CoarseMtx_, & 342 283 refactor=refactor_,Restrict=Restrict) !fine solves 284 !call Print_Glob_Vect(sol,M,'global sol===') 343 285 endif 344 286 … … 377 319 378 320 if (.not.present(cdat)) then 379 if (sctls%smoothers==-1) then 380 allocate(tmpsol2(A%nrows)) 381 tmpsol2=0.0_rk 382 call exact_sparse_multismoother(tmpsol2,A,rhs) 383 call SpMtx_Ax(crhs,Restrict,tmpsol2,dozero=.true.) ! restriction 384 else 385 call SpMtx_Ax(crhs,Restrict,rhs,dozero=.true.) ! restriction 386 endif 321 if (sctls%smoothers==-1) then 322 allocate(tmpsol2(A%nrows)) 323 tmpsol2=0.0_rk 324 call exact_sparse_multismoother(tmpsol2,A,rhs) 325 call SpMtx_Ax(crhs,Restrict,tmpsol2,dozero=.true.) ! restriction 326 else 327 if (sctls%method>1.and.sctls%method/=5) then ! multiplicative Schwarz 328 call SpMtx_Ax(crhs,Restrict,res,dozero=.true.) ! restriction 329 else 330 call SpMtx_Ax(crhs,Restrict,rhs,dozero=.true.) ! restriction 331 endif 332 endif 387 333 endif 388 334 !csol=0.0_rk … … 412 358 endif 413 359 414 !call sparse_singlesolve(coarseid,csol,crhs, &415 360 call sparse_singlesolve(CoarseMtx_%subsolve_ids(1),csol,crhs, & 416 361 nfreds=CoarseMtx_%nrows, & … … 433 378 call SpMtx_Ax(tmpsol,Restrict,clrhs,dozero=.true.,transp=.true.) ! RB 434 379 else 435 if (sctls%smoothers==-1) then436 call SpMtx_Ax(tmpsol2,Restrict,csol,dozero=.true.,transp=.true.) ! interpolation437 tmpsol=0.0_rk438 call exact_sparse_multismoother(tmpsol,A,tmpsol2)439 else440 call SpMtx_Ax(tmpsol,Restrict,csol,dozero=.true.,transp=.true.) ! interpolation441 endif380 if (sctls%smoothers==-1) then 381 call SpMtx_Ax(tmpsol2,Restrict,csol,dozero=.true.,transp=.true.) ! interpolation 382 tmpsol=0.0_rk 383 call exact_sparse_multismoother(tmpsol,A,tmpsol2) 384 else 385 call SpMtx_Ax(tmpsol,Restrict,csol,dozero=.true.,transp=.true.) ! interpolation 386 endif 442 387 endif 443 388 else ! apply coarse solve: … … 450 395 451 396 else 452 if (sctls%smoothers==-1) then453 tmpsol2=0.0_rk454 call exact_sparse_multismoother(tmpsol2,A,rhs)455 call SpMtx_Ax(crhs,Restrict,tmpsol2,dozero=.true.) ! restriction456 else457 call SpMtx_Ax(crhs,Restrict,rhs,dozero=.true.) ! restriction458 endif397 if (sctls%smoothers==-1) then 398 tmpsol2=0.0_rk 399 call exact_sparse_multismoother(tmpsol2,A,rhs) 400 call SpMtx_Ax(crhs,Restrict,tmpsol2,dozero=.true.) ! restriction 401 else 402 call SpMtx_Ax(crhs,Restrict,rhs,dozero=.true.) ! restriction 403 endif 459 404 endif 460 405 call sparse_singlesolve(CoarseMtx_%subsolve_ids(1),csol,crhs, & … … 470 415 call SpMtx_Ax(tmpsol,Restrict,clrhs,dozero=.true.,transp=.true.) ! RB 471 416 else 472 if (sctls%smoothers==-1) then473 call SpMtx_Ax(tmpsol2,Restrict,csol,dozero=.true.,transp=.true.) ! interpolation474 tmpsol=0.0_rk475 call exact_sparse_multismoother(tmpsol,A,tmpsol2)476 else477 call SpMtx_Ax(tmpsol,Restrict,csol,dozero=.true.,transp=.true.) ! interpolation478 ! call Vect_print(tmpsol,"csol")479 endif417 if (sctls%smoothers==-1) then 418 call SpMtx_Ax(tmpsol2,Restrict,csol,dozero=.true.,transp=.true.) ! interpolation 419 tmpsol=0.0_rk 420 call exact_sparse_multismoother(tmpsol,A,tmpsol2) 421 else 422 call SpMtx_Ax(tmpsol,Restrict,csol,dozero=.true.,transp=.true.) ! interpolation 423 ! call Vect_print(tmpsol,"csol") 424 endif 480 425 endif 481 426 endif 427 if (sctls%method==1) then 428 sol(1:A%nrows)=sol(1:A%nrows)+tmpsol(1:A%nrows) 429 elseif (sctls%method==3) then ! fully multiplicative Schwarz 430 sol(1:A%nrows)=sol(1:A%nrows)+tmpsol(1:A%nrows) 431 ! calculate the residual: 432 call SpMtx_Ax(res,A,sol,dozero=.true.) ! 433 res=rhs-res 434 elseif (sctls%method==4) then ! fully multiplicative Schwarz 435 sol(1:A%nrows)=tmpsol(1:A%nrows) 436 ! calculate the residual: 437 call SpMtx_Ax(res,A,sol,dozero=.true.) ! 438 res=rhs-res 439 endif 440 endif 441 if (sctls%method>1) then ! For multiplicative Schwarz method...: 442 refactor_=.false. 443 if (sctls%input_type==DCTL_INPUT_TYPE_ELEMENTAL) then 444 call sparse_multisolve(sol=sol,A=A,M=M,rhs=rhs,res=res, & 445 A_interf_=A_interf_, & 446 refactor=refactor_) !fine solves 447 else 448 call sparse_multisolve(sol=sol,A=A,M=M,rhs=rhs,res=res, & 449 A_interf_=A_interf_,AC=CoarseMtx_, & 450 refactor=refactor_,Restrict=Restrict) !fine solves 451 endif 452 endif 453 if ((sctls%method==2.or.sctls%method==5).and.sctls%levels>1) then 454 ! multiplicative on fine level, additive with coarse level: 482 455 sol(1:A%nrows)=sol(1:A%nrows)+tmpsol(1:A%nrows) 483 456 endif 484 457 else !}{ 485 if (refactor_.and.present(A_interf_)) then 458 if (refactor_.and.present(A_interf_)) then!{ 486 459 if (sctls%verbose>9) then 487 call SpMtx_printMat(A)460 !call SpMtx_printMat(A) 488 461 call SpMtx_printRaw(A) 489 call SpMtx_printMat(A_interf_)462 !call SpMtx_printMat(A_interf_) 490 463 call SpMtx_printRaw(A_interf_) 491 464 !stop … … 505 478 !endif 506 479 call SpMtx_arrange(A,D_SpMtx_ARRNG_ROWS,sort=.true.) 507 write(stream,*)'AAAAAAAAAAAAAAAA is:' 508 call SpMtx_printRaw(A) 509 call SpMtx_printRaw(A_interf_) 510 write(stream,*)'AAAAAAAAAAAAAAAA :' 511 call flush(stream) 512 call sparse_multisolve(sol=sol,A=A,rhs=rhs, & 480 call sparse_multisolve(sol=sol,A=A,M=M,rhs=rhs,res=res, & 513 481 A_interf_=A_interf_, & 514 482 refactor=refactor_) !fine solves 483 if (sctls%method>1) then ! For multiplicative Schwarz method...: 484 refactor_=.false. 485 call sparse_multisolve(sol=sol,A=A,M=M,rhs=rhs,res=res, & 486 A_interf_=A_interf_, & 487 refactor=refactor_) !fine solves 488 endif 515 489 ! put the original structure and orders back: 516 490 A%indi=A_tmp%indi … … 523 497 call SpMtx_Destroy(A_tmp) 524 498 else 525 call sparse_multisolve(sol=sol,A=a,rhs=rhs, & 499 call sparse_multisolve(sol=sol,A=A,M=M,rhs=rhs,res=res, & 500 A_interf_=A_interf_, & 501 refactor=refactor_) !fine solves 502 if (sctls%method>1) then ! For multiplicative Schwarz method...: 503 refactor_=.false. 504 call sparse_multisolve(sol=sol,A=A,M=M,rhs=rhs,res=res, & 505 A_interf_=A_interf_, & 506 refactor=refactor_) !fine solves 507 endif 508 endif 509 elseif (refactor_.and.sctls%input_type==DCTL_INPUT_TYPE_ASSEMBLED) then!}{ 510 A_tmp=SpMtx_newInit(nnz=A%nnz,nblocks=A%nblocks,nrows=A%nrows,& 511 ncols=A%ncols,& 512 indi=A%indi,indj=A%indj,val=A%val,& 513 arrange_type=A%arrange_type,M_bound=A%M_bound) 514 A%arrange_type=D_SpMtx_ARRNG_NO 515 call SpMtx_arrange(A,D_SpMtx_ARRNG_ROWS,sort=.true.) 516 call sparse_multisolve(sol=sol,A=A,M=M,rhs=rhs,res=res, & 517 refactor=refactor_) !fine solves 518 if (sctls%method>1) then ! For multiplicative Schwarz method...: 519 refactor_=.false. 520 call sparse_multisolve(sol=sol,A=A,M=M,rhs=rhs,res=res, & 521 refactor=refactor_) !fine solves 522 endif 523 ! put the original structure and orders back: 524 A%indi=A_tmp%indi 525 A%indj=A_tmp%indj 526 A%val=A_tmp%val 527 A%M_bound=A_tmp%M_bound 528 A%nrows=A_tmp%nrows 529 A%ncols=A_tmp%ncols 530 A%arrange_type=A_tmp%arrange_type 531 call SpMtx_Destroy(A_tmp) 532 else!}{ 533 call sparse_multisolve(sol=sol,A=A,M=M,rhs=rhs,res=res, & 534 A_interf_=A_interf_, & 535 refactor=refactor_) !fine solves 536 if (sctls%method>1) then ! For multiplicative Schwarz method...: 537 refactor_=.false. 538 call sparse_multisolve(sol=sol,A=A,M=M,rhs=rhs,res=res, & 526 539 A_interf_=A_interf_, & 527 540 refactor=refactor_) !fine solves 528 541 endif 529 elseif (refactor_.and.sctls%input_type==DCTL_INPUT_TYPE_ASSEMBLED) then 530 A_tmp=SpMtx_newInit(nnz=A%nnz,nblocks=A%nblocks,nrows=A%nrows,& 531 ncols=A%ncols,& 532 indi=A%indi,indj=A%indj,val=A%val,& 533 arrange_type=A%arrange_type,M_bound=A%M_bound) 534 A%arrange_type=D_SpMtx_ARRNG_NO 535 call SpMtx_arrange(A,D_SpMtx_ARRNG_ROWS,sort=.true.) 536 write(stream,*)'BBBBBBBBBBBBAAAA is:' 537 write(stream,*)'A%nrows=',A%nrows 538 call SpMtx_printRaw(A,startnz=1,endnz=A%mtx_bbe(2,2)) 539 write(stream,*)'BBBBBBBBBBBBAAAA :' 540 call flush(stream) 541 call sparse_multisolve(sol=sol,A=A,rhs=rhs, & 542 refactor=refactor_) !fine solves 543 ! put the original structure and orders back: 544 A%indi=A_tmp%indi 545 A%indj=A_tmp%indj 546 A%val=A_tmp%val 547 A%M_bound=A_tmp%M_bound 548 A%nrows=A_tmp%nrows 549 A%ncols=A_tmp%ncols 550 A%arrange_type=A_tmp%arrange_type 551 call SpMtx_Destroy(A_tmp) 552 else 553 call sparse_multisolve(sol=sol,A=a,rhs=rhs, & 554 A_interf_=A_interf_, & 555 refactor=refactor_) !fine solves 556 endif 542 endif!} 557 543 endif !} 544 if (sctls%method>1) then ! For multiplicative Schwarz method...: 545 if (associated(res)) deallocate(res) 546 endif 558 547 end subroutine preconditioner 559 548 … … 690 679 691 680 !call Print_Glob_Vect(r,Msh,'global r===') 681 !write(stream,*)'present(CoarseMtx_):',present(CoarseMtx_) 692 682 call preconditioner(sol=z, & 693 683 A=A, & 694 684 rhs=r, & 685 M=Msh, & 695 686 A_interf_=A_interf_, & 696 687 CoarseMtx_=CoarseMtx_, & … … 702 693 call Add_common_interf(z,A,Msh) 703 694 endif 704 ! write(stream,*)'localz==:',z695 !call Print_Glob_Vect(z,Msh,'global z===') 705 696 !call Print_Glob_Vect(z,Msh,'global z===') 706 697 ! compute current rho … … 724 715 ! check 725 716 res_norm = Vect_dot_product(r,r) 726 write (stream,*) "Norm is", res_norm717 !write (stream,*) "Norm is", res_norm 727 718 ratio_norm = res_norm / init_norm 728 719 if (ismaster()) & … … 764 755 if (alpha(i)==0.or.beta(i)<0) then 765 756 print *,'Unable to compute eigenvalue number',i,' and ' 766 do j=1,i t757 do j=1,i 767 758 print *,j,' alpha:',alpha(j),' beta:',beta 768 759 enddo
Note: See TracChangeset
for help on using the changeset viewer.
