davidson_diago.f90 48.6 KB
Newer Older
 Marco Govoni committed Apr 30, 2017 1 ``````! `````` Victor Yu committed May 20, 2021 2 ``````! Copyright (C) 2015-2017 M. Govoni `````` Marco Govoni committed Apr 30, 2017 3 4 5 6 7 8 9 ``````! This file is distributed under the terms of the ! GNU General Public License. See the file `License' ! in the root directory of the present distribution, ! or http://www.gnu.org/copyleft/gpl.txt . ! ! This file is part of WEST. ! `````` Victor Yu committed May 20, 2021 10 ``````! Contributors to this file: `````` Marco Govoni committed Apr 30, 2017 11 12 13 14 15 16 17 18 19 ``````! Marco Govoni ! #define ZERO ( 0.D0, 0.D0 ) #define ONE ( 1.D0, 0.D0 ) ! !---------------------------------------------------------------------------- SUBROUTINE davidson_diago ( ) !---------------------------------------------------------------------------- ! `````` Victor Yu committed May 20, 2021 20 `````` USE control_flags, ONLY : gamma_only `````` Marco Govoni committed Apr 30, 2017 21 22 23 `````` ! IMPLICIT NONE ! `````` Victor Yu committed May 20, 2021 24 25 `````` IF( gamma_only ) THEN CALL davidson_diago_gamma( ) `````` Marco Govoni committed Apr 30, 2017 26 27 `````` ELSE CALL davidson_diago_k( ) `````` Victor Yu committed May 20, 2021 28 `````` ENDIF `````` Marco Govoni committed Apr 30, 2017 29 `````` ! `````` Victor Yu committed May 20, 2021 30 ``````END SUBROUTINE `````` Marco Govoni committed Apr 30, 2017 31 32 33 34 35 36 37 38 39 40 41 42 43 ``````! !---------------------------------------------------------------------------- SUBROUTINE davidson_diago_gamma ( ) !---------------------------------------------------------------------------- ! ! ... iterative solution of the eigenvalue problem: ! ... ( chi - ev ) * dvg = 0 ! USE kinds, ONLY : DP USE io_global, ONLY : stdout USE distribution_center, ONLY : pert USE class_idistribute, ONLY : idistribute USE io_push, ONLY : io_push_title,io_push_bar `````` Matteo Gerosa committed Dec 18, 2017 44 `````` USE westcom, ONLY : dvg,dng,n_pdep_eigen,trev_pdep,n_pdep_maxiter,n_pdep_basis,wstat_calculation,ev,conv,& `````` Marco Govoni committed Nov 28, 2017 45 `````` & n_pdep_restart_from_itr,n_pdep_read_from_file,n_steps_write_restart,n_pdep_times,npwqx,npwq,& `````` Matteo Gerosa committed Feb 14, 2018 46 `````` & npwqx,npwq,trev_pdep_rel,tr2_dfpt,l_is_wstat_converged,fftdriver `````` Marco Govoni committed Apr 30, 2017 47 48 49 50 51 52 53 `````` USE pdep_db, ONLY : pdep_db_write,pdep_db_read USE wstat_restart, ONLY : wstat_restart_write, wstat_restart_clear, wstat_restart_read USE mp_world, ONLY : mpime USE mp_global, ONLY : inter_image_comm USE mp, ONLY : mp_sum USE gvect, ONLY : gstart USE wstat_tools, ONLY : diagox,serial_diagox,build_hr,symm_hr_distr,redistribute_vr_distr,& `````` Victor Yu committed May 20, 2021 54 `````` & update_with_vr_distr,refresh_with_vr_distr `````` Matteo Gerosa committed Dec 18, 2017 55 `````` USE types_coulomb, ONLY : pot3D `````` Marco Govoni committed Apr 30, 2017 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 `````` ! IMPLICIT NONE ! ! ... LOCAL variables ! INTEGER :: nvec, nvecx ! dimension of the matrix to be diagonalized ! leading dimension of matrix evc, as declared in the calling pgm unit INTEGER :: dav_iter, notcnv ! integer number of iterations performed ! number of unconverged roots INTEGER :: kter, nbase, np, n, m ! counter on iterations ! dimension of the reduced basis ! counter on the reduced basis vectors ! do-loop counters ! counter on the bands INTEGER :: ierr,mloc,mstart,mend INTEGER,ALLOCATABLE :: ishift(:) REAL(DP), ALLOCATABLE :: ew(:) REAL(DP), ALLOCATABLE :: hr_distr(:,:), vr_distr(:,:) ! INTEGER :: il1,il2,ig1,ig2,i REAL(DP) :: time_spent(2) `````` Marco Govoni committed May 23, 2017 80 `````` INTEGER :: sternop_ncalls(2) `````` Marco Govoni committed Apr 30, 2017 81 `````` CHARACTER(LEN=8) :: iter_label `````` Marco Govoni committed May 23, 2017 82 83 `````` REAL(DP) :: pccg_res_tr2 INTEGER :: dfpt_dim, diago_dim `````` Marco Govoni committed Apr 30, 2017 84 85 86 87 88 89 90 91 92 93 94 `````` ! REAL(DP), EXTERNAL :: GET_CLOCK ! ! ... INITIALIZATION ! l_is_wstat_converged = .FALSE. nvec = n_pdep_eigen nvecx = n_pdep_basis ! CALL start_clock( 'chidiago' ) time_spent(1)=get_clock( 'chidiago' ) `````` Marco Govoni committed May 23, 2017 95 `````` CALL get_clock_called( 'stern' , sternop_ncalls(1) ) `````` Marco Govoni committed Apr 30, 2017 96 97 98 99 100 `````` ! ! ... DISTRIBUTE nvecx ! pert = idistribute() CALL pert%init(nvecx,'i','nvecx',.TRUE.) `````` Victor Yu committed May 20, 2021 101 102 `````` !CALL index_distr_init(pert,nvecx,'i','nvecx',.TRUE.) CALL wstat_memory_report() ! Before allocating I report the memory required. `````` Marco Govoni committed Apr 30, 2017 103 104 105 106 107 `````` ! ! ... MEMORY ALLOCATION ! IF ( nvec > nvecx / 2 ) CALL errore( 'chidiago', 'nvecx is too small', 1 ) ! `````` Marco Govoni committed Nov 28, 2017 108 `````` ALLOCATE( dvg( npwqx, pert%nlocx ), STAT=ierr ) `````` Marco Govoni committed Apr 30, 2017 109 110 111 `````` IF( ierr /= 0 ) & CALL errore( 'chidiago',' cannot allocate dvg ', ABS(ierr) ) ! `````` Marco Govoni committed Nov 28, 2017 112 `````` ALLOCATE( dng( npwqx, pert%nlocx ), STAT=ierr ) `````` Marco Govoni committed Apr 30, 2017 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 `````` IF( ierr /= 0 ) & CALL errore( 'chidiago',' cannot allocate dng ', ABS(ierr) ) ! ALLOCATE( hr_distr( nvecx, pert%nlocx ), STAT=ierr ) IF( ierr /= 0 ) & CALL errore( 'chidiago',' cannot allocate hr_distr ', ABS(ierr) ) ! ALLOCATE( vr_distr( nvecx, pert%nlocx ), STAT=ierr ) IF( ierr /= 0 ) & CALL errore( 'chidiago',' cannot allocate vr_distr ', ABS(ierr) ) ! ALLOCATE( ew( nvecx ), STAT=ierr ) IF( ierr /= 0 ) & CALL errore( 'chidiago',' cannot allocate ew ', ABS(ierr) ) ! ALLOCATE( ev( nvec ), STAT=ierr ) IF( ierr /= 0 ) & CALL errore( 'chidiago',' cannot allocate ev ', ABS(ierr) ) ! ALLOCATE( conv( nvec ), STAT=ierr ) IF( ierr /= 0 ) & CALL errore( 'chidiago',' cannot allocate conv ', ABS(ierr) ) ! nbase = nvec conv = .FALSE. ev = 0._DP ew = 0._DP dng = 0._DP dvg = 0._DP hr_distr(:,:) = 0._DP vr_distr(:,:) = 0._DP `````` Victor Yu committed May 20, 2021 144 `````` notcnv = nvec `````` Marco Govoni committed Apr 30, 2017 145 146 `````` dav_iter = -2 ! `````` Matteo Gerosa committed Feb 14, 2018 147 `````` CALL pot3D%init(fftdriver,.FALSE.,'default') `````` Matteo Gerosa committed Dec 18, 2017 148 `````` CALL pot3d%print_divergence() `````` Marco Govoni committed Nov 28, 2017 149 `````` ! `````` Marco Govoni committed Apr 30, 2017 150 151 `````` ! KIND OF CALCULATION ! `````` Marco Govoni committed Sep 29, 2019 152 `````` IF( wstat_calculation(1:1)=="R" .OR. wstat_calculation(2:2)=="R" ) THEN `````` Marco Govoni committed Apr 30, 2017 153 154 155 156 157 `````` ! ! RESTART ! CALL wstat_restart_read( dav_iter, notcnv, nbase, ew, hr_distr, vr_distr ) ! `````` Marco Govoni committed Sep 29, 2019 158 159 `````` ENDIF IF( wstat_calculation(1:1)=="S" .OR. wstat_calculation(2:2)=="S" ) THEN `````` Marco Govoni committed Apr 30, 2017 160 161 162 163 164 165 166 167 168 `````` ! ! FROM SCRATCH ! ! ... Eventually read from file ! IF(n_pdep_read_from_file>0) CALL pdep_db_read( n_pdep_read_from_file ) ! ! ... Eventually randomize ! `````` Matteo Gerosa committed Feb 22, 2018 169 `````` IF(n_pdep_read_from_file nvec ) CYCLE IF( mloc==0 ) mstart = il1 mloc = mloc + 1 ENDDO ! `````` Marco Govoni committed May 23, 2017 194 `````` pccg_res_tr2 = -1._DP `````` Victor Yu committed May 20, 2021 195 `````` CALL apply_operator ( mloc, dvg(1,mstart), dng(1,mstart), pccg_res_tr2, 1 ) `````` Marco Govoni committed Apr 30, 2017 196 `````` dav_iter = -1 `````` Victor Yu committed May 20, 2021 197 `````` IF(n_steps_write_restart == 1) CALL wstat_restart_write( dav_iter, notcnv, nbase, ew, hr_distr, vr_distr ) `````` Marco Govoni committed Apr 30, 2017 198 `````` ! `````` Marco Govoni committed Sep 29, 2019 199 `````` ENDIF `````` Marco Govoni committed Apr 30, 2017 200 `````` ! `````` Victor Yu committed May 20, 2021 201 `````` IF( dav_iter == -2 ) CALL errore( 'chidiago','Cannot find the 1st starting loop',1) `````` Marco Govoni committed Apr 30, 2017 202 203 204 `````` ! IF( dav_iter == -1 ) THEN ! `````` Victor Yu committed May 20, 2021 205 `````` ! < EXTRA STEP > `````` Marco Govoni committed Apr 30, 2017 206 207 208 209 `````` ! dvg = dng CALL do_mgs( dvg, 1, nvec) ! `````` Marco Govoni committed May 23, 2017 210 211 `````` dfpt_dim = nbase diago_dim = nbase `````` Marco Govoni committed Apr 30, 2017 212 213 214 `````` WRITE(stdout, "( /,5x,' *----------* *----------* *----------*') ") WRITE(stdout, & & "( 5x,'# Iteration = | ', a8,' |',' ','DFPT_dim = | ', i8,' |', ' ','Diago_dim = | ', i8,' | x 2/2')")& `````` Marco Govoni committed May 23, 2017 215 `````` & 'starting', dfpt_dim, diago_dim `````` Marco Govoni committed Apr 30, 2017 216 217 218 219 220 `````` WRITE(stdout, "( 5x,' *----------* *----------* *----------*') ") ! ! Apply operator with DFPT ! mloc = 0 `````` Victor Yu committed May 20, 2021 221 `````` mstart = 1 `````` Marco Govoni committed Apr 30, 2017 222 223 224 225 226 227 228 `````` DO il1 = 1, pert%nloc ig1 = pert%l2g(il1) IF( ig1 < 1 .OR. ig1 > nvec ) CYCLE IF( mloc==0 ) mstart = il1 mloc = mloc + 1 ENDDO ! `````` Marco Govoni committed May 23, 2017 229 `````` pccg_res_tr2 = MIN(0.01_DP,1000000._DP*tr2_dfpt) `````` Victor Yu committed May 19, 2021 230 `````` CALL apply_operator ( mloc, dvg(1,mstart), dng(1,mstart), pccg_res_tr2, 1 ) `````` Victor Yu committed May 20, 2021 231 `````` ! `````` Marco Govoni committed Apr 30, 2017 232 233 234 235 `````` ! ! ! hr = ! `````` Victor Yu committed May 20, 2021 236 `````` CALL build_hr( dvg, dng, mstart, mstart+mloc-1, hr_distr, 1, nvec ) `````` Marco Govoni committed Apr 30, 2017 237 238 239 240 241 `````` ! ! ... diagonalize the reduced hamiltonian ! CALL diagox( nbase, nvec, hr_distr, nvecx, ew, vr_distr ) time_spent(2)=get_clock( 'chidiago' ) `````` Marco Govoni committed May 23, 2017 242 `````` CALL get_clock_called( 'stern' , sternop_ncalls(2) ) `````` Marco Govoni committed Apr 30, 2017 243 244 245 246 `````` ev(1:nvec) = ew(1:nvec) ! ! Write the eigenvalues & time spent ! `````` Marco Govoni committed May 23, 2017 247 `````` CALL output_ev_and_time(nvec,ev,conv,time_spent,sternop_ncalls,pccg_res_tr2,dfpt_dim,diago_dim,dav_iter,notcnv) `````` Marco Govoni committed Apr 30, 2017 248 `````` dav_iter = 0 `````` Victor Yu committed May 20, 2021 249 `````` IF(n_steps_write_restart == 1) CALL wstat_restart_write( dav_iter, notcnv, nbase, ew, hr_distr, vr_distr ) `````` Marco Govoni committed Apr 30, 2017 250 251 252 253 254 255 256 257 258 259 260 261 `````` ! ENDIF ! ! -------------------- ! ! ... iterate ! ! -------------------- ! iterate: DO kter = 1, n_pdep_maxiter ! time_spent(1) = get_clock( 'chidiago' ) `````` Marco Govoni committed May 23, 2017 262 `````` CALL get_clock_called( 'stern' , sternop_ncalls(1) ) `````` Marco Govoni committed Apr 30, 2017 263 264 265 `````` ! dav_iter = dav_iter + 1 ! `````` Marco Govoni committed May 23, 2017 266 267 `````` dfpt_dim = notcnv diago_dim = nbase+notcnv `````` Marco Govoni committed Apr 30, 2017 268 269 `````` WRITE(stdout, "( /,5x,' *----------* *----------* *----------*') ") WRITE(stdout, "( 5x,'# Iteration = | ', i8,' |',' ','DFPT_dim = | ', i8,' |', ' ','Diago_dim = | ', i8,' |')") & `````` Marco Govoni committed May 23, 2017 270 `````` &dav_iter, dfpt_dim, diago_dim `````` Marco Govoni committed Apr 30, 2017 271 272 273 274 275 276 277 278 279 280 281 `````` WRITE(stdout, "( 5x,' *----------* *----------* *----------*') ") ! ALLOCATE( ishift( nvecx ), STAT=ierr ) IF( ierr /= 0 ) CALL errore( 'chidiago',' cannot allocate ishift ', ABS(ierr) ) ishift=0 np = 0 ! DO n = 1, nvec ! IF ( .NOT. conv(n) ) THEN ! `````` Victor Yu committed May 20, 2021 282 `````` ! ... this root not yet converged ... `````` Marco Govoni committed Apr 30, 2017 283 284 285 286 `````` ! np = np + 1 ! ! ... reorder eigenvectors so that coefficients for unconverged `````` Victor Yu committed May 20, 2021 287 `````` ! ... roots come first. This allows to use quick matrix-matrix `````` Marco Govoni committed Apr 30, 2017 288 289 290 291 292 293 `````` ! ... multiplications to set a new basis vector (see below) ! !IF ( np /= n ) vr(:,np) = vr(:,n) ishift(nbase+np) = n ! ew(nbase+np) = ev(n) `````` Victor Yu committed May 20, 2021 294 `````` ! `````` Marco Govoni committed Apr 30, 2017 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 `````` END IF ! END DO ! ! ... expand the basis set with new basis vectors ( H - e*S )|psi> ... ! CALL redistribute_vr_distr( notcnv, nbase, nvecx, vr_distr, ishift ) DEALLOCATE(ishift) CALL update_with_vr_distr( dvg, dng, notcnv, nbase, nvecx, vr_distr, ew ) ! ! ... MGS ! CALL do_mgs(dvg,nbase+1,nbase+notcnv) ! ! apply the response function to new vectors ! ! determine image that actually compute dng first ! `````` Victor Yu committed May 20, 2021 313 `````` mloc = 0 `````` Marco Govoni committed Apr 30, 2017 314 315 316 317 318 319 320 321 322 323 `````` mstart = 1 DO il1 = 1, pert%nloc ig1 = pert%l2g(il1) IF( ig1 < nbase+1 .OR. ig1 > nbase+notcnv ) CYCLE IF( mloc==0 ) mstart = il1 mloc = mloc + 1 ENDDO ! ! Apply operator with DFPT ! `````` Marco Govoni committed May 23, 2017 324 `````` pccg_res_tr2 = tr2_dfpt `````` Victor Yu committed May 20, 2021 325 `````` CALL apply_operator ( mloc, dvg(1,mstart), dng(1,mstart), pccg_res_tr2, 1) `````` Marco Govoni committed Apr 30, 2017 326 327 328 329 330 331 `````` ! ! ... update the reduced hamiltonian ! ! ! hr = ! `````` Victor Yu committed May 20, 2021 332 `````` CALL build_hr( dvg, dng, mstart, mstart+mloc-1, hr_distr, nbase+1, nbase+notcnv ) `````` Marco Govoni committed Apr 30, 2017 333 334 335 336 337 338 339 340 341 `````` ! nbase = nbase + notcnv ! CALL symm_hr_distr(hr_distr,nbase,nvecx) ! ! ... diagonalize the reduced hamiltonian ! CALL diagox( nbase, nvec, hr_distr, nvecx, ew, vr_distr ) time_spent(2)=get_clock( 'chidiago' ) `````` Marco Govoni committed May 23, 2017 342 `````` CALL get_clock_called( 'stern' , sternop_ncalls(2) ) `````` Marco Govoni committed Apr 30, 2017 343 344 345 346 347 348 349 350 351 352 353 354 355 `````` ! ! ... test for convergence ! conv(1:nvec) = ( ( ABS( (ew(1:nvec) - ev(1:nvec))/ev(1:nvec) ) < trev_pdep_rel ) & .AND. ( ABS( ew(1:nvec) - ev(1:nvec) ) < trev_pdep ) ) !conv(1:nvec) = ( ( ABS( ew(1:nvec) - ev(1:nvec) ) < trev_pdep ) ) ! notcnv = COUNT( .NOT. conv(:) ) ! ev(1:nvec) = ew(1:nvec) ! ! Write the eigenvalues & time spent ! `````` Marco Govoni committed May 23, 2017 356 `````` CALL output_ev_and_time(nvec,ev,conv,time_spent,sternop_ncalls,pccg_res_tr2,dfpt_dim,diago_dim,dav_iter,notcnv) `````` Marco Govoni committed Apr 30, 2017 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 `````` ! ! ... if overall convergence has been achieved, or the dimension of ! ... the reduced basis set is becoming too large, or in any case if ! ... we are at the last iteration refresh the basis set. i.e. replace ! ... the first nvec elements with the current estimate of the ! ... eigenvectors; set the basis dimension to nvec. ! IF ( notcnv == 0 .OR. nbase+notcnv > nvecx .OR. kter == n_pdep_maxiter ) THEN ! CALL start_clock( 'chidiago:last' ) ! IF ( notcnv == 0 ) THEN ! ! ... all roots converged: return ! CALL stop_clock( 'chidiago:last' ) ! CALL refresh_with_vr_distr( dvg, nvec, nbase, nvecx, vr_distr ) ! CALL pdep_db_write( ) CALL wstat_restart_clear() `````` Marco Govoni committed May 23, 2017 378 `````` !CALL output_a_report(-1) `````` Marco Govoni committed Apr 30, 2017 379 380 `````` ! WRITE(iter_label,'(i8)') kter `````` Victor Yu committed May 20, 2021 381 `````` CALL io_push_title("Convergence achieved !!! in "//TRIM(iter_label)//" steps") `````` Marco Govoni committed Apr 30, 2017 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 `````` l_is_wstat_converged = .TRUE. ! EXIT iterate ! ELSE IF ( kter == n_pdep_maxiter ) THEN ! ! ... last iteration, some roots not converged: return ! WRITE( stdout, '(5X,"WARNING: ",I5, & & " eigenvalues not converged in chidiago")' ) notcnv ! CALL stop_clock( 'chidiago:last' ) ! EXIT iterate ! END IF ! ! ... refresh psi, H*psi and S*psi ! WRITE(stdout,'(/,7x,"Refresh the basis set")') ! CALL refresh_with_vr_distr( dvg, nvec, nbase, nvecx, vr_distr ) CALL refresh_with_vr_distr( dng, nvec, nbase, nvecx, vr_distr ) ! ! ... refresh the reduced hamiltonian ! nbase = nvec ! hr_distr = 0._DP vr_distr = 0._DP ! DO il1 = 1, pert%nloc ig1 = pert%l2g(il1) `````` Victor Yu committed May 20, 2021 415 `````` IF( ig1 > nbase ) CYCLE `````` Marco Govoni committed Apr 30, 2017 416 417 418 419 420 421 422 423 `````` hr_distr(ig1,il1) = ev(ig1) vr_distr(ig1,il1) = 1._DP ENDDO ! CALL stop_clock( 'chidiago:last' ) ! END IF ! `````` Victor Yu committed May 20, 2021 424 425 `````` IF(n_steps_write_restart > 0 .AND. MOD(dav_iter,n_steps_write_restart) == 0) & CALL wstat_restart_write( dav_iter, notcnv, nbase, ew, hr_distr, vr_distr ) `````` Marco Govoni committed May 23, 2017 426 `````` !CALL output_a_report(dav_iter) `````` Marco Govoni committed Apr 30, 2017 427 428 429 430 431 432 433 434 435 436 437 438 `````` ! END DO iterate ! ! DEALLOCATE( conv ) DEALLOCATE( ew ) DEALLOCATE( ev ) DEALLOCATE( hr_distr ) DEALLOCATE( vr_distr ) ! ! DEALLOCATE( dng ) `````` Victor Yu committed May 20, 2021 439 `````` DEALLOCATE( dvg ) `````` Marco Govoni committed Apr 30, 2017 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 `````` ! CALL stop_clock( 'chidiago' ) ! RETURN ! END SUBROUTINE ! !---------------------------------------------------------------------------- SUBROUTINE davidson_diago_k ( ) !---------------------------------------------------------------------------- ! ! ... iterative solution of the eigenvalue problem: ! ... ( chi - ev ) * dvg = 0 ! USE kinds, ONLY : DP USE io_global, ONLY : stdout USE distribution_center, ONLY : pert USE class_idistribute, ONLY : idistribute USE io_push, ONLY : io_push_title,io_push_bar USE westcom, ONLY : dvg,dng,n_pdep_eigen,trev_pdep,n_pdep_maxiter,n_pdep_basis,wstat_calculation,ev,conv,& `````` Marco Govoni committed Nov 28, 2017 460 461 `````` & n_pdep_restart_from_itr,n_pdep_read_from_file,n_steps_write_restart,n_pdep_times,& & trev_pdep_rel,tr2_dfpt,l_is_wstat_converged, & `````` Matteo Gerosa committed Dec 18, 2017 462 `````` & ngq,npwq,igq_q,npwqx `````` Marco Govoni committed Apr 30, 2017 463 464 465 466 467 `````` USE pdep_db, ONLY : pdep_db_write,pdep_db_read USE wstat_restart, ONLY : wstat_restart_write, wstat_restart_clear, wstat_restart_read USE mp_world, ONLY : mpime USE mp_global, ONLY : inter_image_comm USE mp, ONLY : mp_sum `````` Marco Govoni committed Nov 28, 2017 468 469 `````` USE gvect, ONLY : gstart, g, ngm USE gvecw, ONLY : gcutw `````` Marco Govoni committed Apr 30, 2017 470 `````` USE wstat_tools, ONLY : diagox,serial_diagox,build_hr,symm_hr_distr,redistribute_vr_distr,& `````` Victor Yu committed May 20, 2021 471 `````` & update_with_vr_distr,refresh_with_vr_distr `````` Marco Govoni committed Nov 28, 2017 472 `````` USE types_bz_grid, ONLY : q_grid `````` Matteo Gerosa committed Dec 18, 2017 473 `````` USE types_coulomb, ONLY : pot3D `````` Marco Govoni committed Apr 30, 2017 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 `````` ! IMPLICIT NONE ! ! ... LOCAL variables ! INTEGER :: nvec, nvecx ! dimension of the matrix to be diagonalized ! leading dimension of matrix evc, as declared in the calling pgm unit INTEGER :: dav_iter, notcnv ! integer number of iterations performed ! number of unconverged roots INTEGER :: kter, nbase, np, n, m ! counter on iterations ! dimension of the reduced basis ! counter on the reduced basis vectors ! do-loop counters ! counter on the bands INTEGER :: ierr,mloc,mstart,mend INTEGER,ALLOCATABLE :: ishift(:) REAL(DP), ALLOCATABLE :: ew(:) COMPLEX(DP), ALLOCATABLE :: hr_distr(:,:), vr_distr(:,:) ! INTEGER :: il1,il2,ig1,ig2,i REAL(DP) :: time_spent(2) `````` Marco Govoni committed May 23, 2017 498 `````` INTEGER :: sternop_ncalls(2) `````` Marco Govoni committed Apr 30, 2017 499 `````` CHARACTER(LEN=8) :: iter_label `````` Marco Govoni committed May 23, 2017 500 501 `````` REAL(DP) :: pccg_res_tr2 INTEGER :: dfpt_dim, diago_dim `````` Marco Govoni committed Apr 30, 2017 502 `````` ! `````` Marco Govoni committed Nov 28, 2017 503 504 `````` INTEGER :: iq, lastdone_iq LOGICAL :: l_restart_q_done `````` Matteo Gerosa committed Feb 22, 2018 505 `````` LOGICAL :: l_print_pdep_read `````` Marco Govoni committed Nov 28, 2017 506 507 `````` REAL(DP) :: q(3) ! `````` Marco Govoni committed Apr 30, 2017 508 509 510 511 512 513 514 `````` REAL(DP), EXTERNAL :: GET_CLOCK ! ! ... INITIALIZATION ! l_is_wstat_converged = .FALSE. nvec = n_pdep_eigen nvecx = n_pdep_basis `````` Marco Govoni committed Nov 28, 2017 515 516 `````` lastdone_iq = 0 l_restart_q_done = .FALSE. `````` Marco Govoni committed Apr 30, 2017 517 518 519 520 521 `````` ! ! ... DISTRIBUTE nvecx ! pert=idistribute() CALL pert%init(nvecx,'i','nvecx',.TRUE.) `````` Victor Yu committed May 20, 2021 522 523 `````` !CALL index_distr_init(pert,nvecx,'i','nvecx',.TRUE.) CALL wstat_memory_report() ! Before allocating I report the memory required. `````` Marco Govoni committed Apr 30, 2017 524 525 526 527 528 `````` ! ! ... MEMORY ALLOCATION ! IF ( nvec > nvecx / 2 ) CALL errore( 'chidiago', 'nvecx is too small', 1 ) ! `````` Marco Govoni committed Nov 28, 2017 529 `````` ALLOCATE( dvg( npwqx, pert%nlocx ), STAT=ierr ) `````` Marco Govoni committed Apr 30, 2017 530 531 532 `````` IF( ierr /= 0 ) & CALL errore( 'chidiago',' cannot allocate dvg ', ABS(ierr) ) ! `````` Marco Govoni committed Nov 28, 2017 533 `````` ALLOCATE( dng( npwqx, pert%nlocx ), STAT=ierr ) `````` Marco Govoni committed Apr 30, 2017 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 `````` IF( ierr /= 0 ) & CALL errore( 'chidiago',' cannot allocate dng ', ABS(ierr) ) ! ALLOCATE( hr_distr( nvecx, pert%nlocx ), STAT=ierr ) IF( ierr /= 0 ) & CALL errore( 'chidiago',' cannot allocate hr_distr ', ABS(ierr) ) ! ALLOCATE( vr_distr( nvecx, pert%nlocx ), STAT=ierr ) IF( ierr /= 0 ) & CALL errore( 'chidiago',' cannot allocate vr_distr ', ABS(ierr) ) ! ALLOCATE( ew( nvecx ), STAT=ierr ) IF( ierr /= 0 ) & CALL errore( 'chidiago',' cannot allocate ew ', ABS(ierr) ) ! ALLOCATE( ev( nvec ), STAT=ierr ) IF( ierr /= 0 ) & CALL errore( 'chidiago',' cannot allocate ev ', ABS(ierr) ) ! ALLOCATE( conv( nvec ), STAT=ierr ) IF( ierr /= 0 ) & CALL errore( 'chidiago',' cannot allocate conv ', ABS(ierr) ) ! `````` Marco Govoni committed Nov 28, 2017 557 `````` QPOINTS_LOOP: & `````` 558 `````` DO iq = 1, q_grid%np `````` 559 560 561 562 `````` ! CALL start_clock( 'chidiago' ) time_spent(1)=get_clock( 'chidiago' ) CALL get_clock_called( 'stern' , sternop_ncalls(1) ) `````` Marco Govoni committed Apr 30, 2017 563 `````` ! `````` Marco Govoni committed Nov 28, 2017 564 565 566 567 568 569 570 571 `````` nbase = nvec conv = .FALSE. ev = 0._DP ew = 0._DP dng = 0._DP dvg = 0._DP hr_distr(:,:) = 0._DP vr_distr(:,:) = 0._DP `````` Victor Yu committed May 20, 2021 572 `````` notcnv = nvec `````` Marco Govoni committed Nov 28, 2017 573 `````` dav_iter = -2 `````` Marco Govoni committed Apr 30, 2017 574 `````` ! `````` Marco Govoni committed Nov 28, 2017 575 `````` ! set local number of G vectors for perturbation at q `````` Marco Govoni committed Apr 30, 2017 576 `````` ! `````` Marco Govoni committed Nov 28, 2017 577 `````` npwq = ngq(iq) `````` Marco Govoni committed Apr 30, 2017 578 `````` ! `````` Marco Govoni committed Nov 28, 2017 579 `````` ! compute Coulomb potential `````` Marco Govoni committed Apr 30, 2017 580 `````` ! `````` 581 `````` CALL pot3D%init('Wave',.TRUE.,'default',iq) `````` Matteo Gerosa committed Dec 18, 2017 582 `````` CALL pot3d%print_divergence() `````` Marco Govoni committed Apr 30, 2017 583 `````` ! `````` 584 `````` IF ( q_grid%np > 1 ) THEN `````` Marco Govoni committed Apr 30, 2017 585 `````` ! `````` Marco Govoni committed Sep 29, 2019 586 `````` IF ( wstat_calculation(1:1) == 'S' .OR. wstat_calculation(2:2) == 'S' ) THEN `````` Marco Govoni committed Apr 30, 2017 587 `````` ! `````` Marco Govoni committed Nov 28, 2017 588 589 `````` WRITE( stdout, '(/,5x,64a)' ) ('=',i=1,64) WRITE( stdout, '(5x,a,i5.5,a,3f10.4,a)')& `````` 590 `````` 'PDEP calculation at q(',iq,') = (',q_grid%p_cart(:,iq),' )' `````` Marco Govoni committed Nov 28, 2017 591 `````` WRITE( stdout, '(5x,64a)' ) ('-',i=1,64) `````` Marco Govoni committed Apr 30, 2017 592 `````` ! `````` Marco Govoni committed Sep 29, 2019 593 `````` ELSEIF ( (wstat_calculation(1:1) == 'R' .OR. wstat_calculation(2:2) == 'R') .AND. l_restart_q_done ) THEN `````` Marco Govoni committed Apr 30, 2017 594 `````` ! `````` Marco Govoni committed Nov 28, 2017 595 596 `````` WRITE( stdout, '(/,5x,64a)' ) ('=',i=1,64) WRITE( stdout, '(5x,a,i5.5,a,3f10.4,a)')& `````` 597 `````` 'PDEP calculation at q(',iq,') = (',q_grid%p_cart(:,iq),' )' `````` Marco Govoni committed Nov 28, 2017 598 `````` WRITE( stdout, '(5x,64a)' ) ('-',i=1,64) `````` Marco Govoni committed Apr 30, 2017 599 `````` ! `````` Marco Govoni committed Nov 28, 2017 600 `````` ENDIF `````` Marco Govoni committed Apr 30, 2017 601 `````` ! `````` Marco Govoni committed Nov 28, 2017 602 `````` ENDIF `````` Marco Govoni committed Apr 30, 2017 603 `````` ! `````` Marco Govoni committed Nov 28, 2017 604 `````` ! KIND OF CALCULATION `````` Marco Govoni committed Apr 30, 2017 605 `````` ! `````` Victor Yu committed May 20, 2021 606 `````` IF( wstat_calculation(1:1) == "R" .OR. wstat_calculation(2:2) == "R" ) THEN `````` Marco Govoni committed Nov 28, 2017 607 `````` ! `````` Matteo Gerosa committed Jan 05, 2018 608 609 610 611 612 613 614 615 616 617 618 619 620 `````` IF ( .NOT. l_restart_q_done ) THEN ! CALL wstat_restart_read( dav_iter, notcnv, nbase, ew, hr_distr, vr_distr, lastdone_iq, iq ) ! IF ( iq < lastdone_iq ) THEN CYCLE QPOINTS_LOOP ELSEIF ( iq == lastdone_iq .AND. notcnv == 0 ) THEN CYCLE QPOINTS_LOOP ENDIF ! l_restart_q_done = .TRUE. wstat_calculation = 'S' ! Start from scratch for the next q (after restart has been done) ! `````` Marco Govoni committed Nov 28, 2017 621 622 `````` ENDIF ! `````` Marco Govoni committed Sep 29, 2019 623 624 `````` ENDIF IF( wstat_calculation(1:1) == "S" .OR. wstat_calculation(2:2) == "S" ) THEN `````` Marco Govoni committed Nov 28, 2017 625 626 627 628 629 `````` ! ! FROM SCRATCH ! ! ... Eventually read from file ! `````` Victor Yu committed May 20, 2021 630 `````` IF (iq==1) THEN `````` Matteo Gerosa committed Feb 22, 2018 631 `````` l_print_pdep_read = .TRUE. `````` Victor Yu committed May 20, 2021 632 `````` ELSE `````` Matteo Gerosa committed Feb 22, 2018 633 634 635 `````` l_print_pdep_read = .FALSE. ENDIF IF(n_pdep_read_from_file>0) CALL pdep_db_read( n_pdep_read_from_file, iq, l_print_pdep_read) `````` Marco Govoni committed Nov 28, 2017 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 `````` ! ! ... Eventually randomize ! IF(n_pdep_read_from_file nvec ) CYCLE IF( mloc==0 ) mstart = il1 mloc = mloc + 1 ENDDO ! pccg_res_tr2 = -1._DP `````` 665 `````` ! `````` Victor Yu committed May 20, 2021 666 `````` CALL apply_operator ( mloc, dvg(1,mstart), dng(1,mstart), pccg_res_tr2, iq ) `````` Marco Govoni committed Nov 28, 2017 667 `````` dav_iter = -1 `````` Victor Yu committed May 20, 2021 668 `````` IF(n_steps_write_restart == 1) CALL wstat_restart_write( dav_iter, notcnv, nbase, ew, hr_distr, vr_distr, iq ) `````` Marco Govoni committed Nov 28, 2017 669 `````` ! `````` Marco Govoni committed Sep 29, 2019 670 `````` ENDIF `````` Marco Govoni committed Apr 30, 2017 671 `````` ! `````` Victor Yu committed May 20, 2021 672 `````` IF( dav_iter == -2 ) CALL errore( 'chidiago','Cannot find the 1st starting loop',1) `````` Marco Govoni committed Apr 30, 2017 673 `````` ! `````` Marco Govoni committed Nov 28, 2017 674 675 `````` IF( dav_iter == -1 ) THEN ! `````` Victor Yu committed May 20, 2021 676 `````` ! < EXTRA STEP > `````` Marco Govoni committed Nov 28, 2017 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 `````` ! dvg = dng CALL do_mgs( dvg, 1, nvec) ! dfpt_dim = nbase diago_dim = nbase WRITE(stdout, "( /,5x,' *----------* *----------* *----------*') ") WRITE(stdout, & & "( 5x,'# Iteration = | ', a8,' |',' ','DFPT_dim = | ', i8,' |', ' ','Diago_dim = | ', i8,' | x 2/2')")& & 'starting', dfpt_dim, diago_dim WRITE(stdout, "( 5x,' *----------* *----------* *----------*') ") ! ! Apply operator with DFPT ! mloc = 0 `````` Victor Yu committed May 20, 2021 692 `````` mstart = 1 `````` Marco Govoni committed Nov 28, 2017 693 694 695 696 697 698 699 700 `````` DO il1 = 1, pert%nloc ig1 = pert%l2g(il1) IF( ig1 < 1 .OR. ig1 > nvec ) CYCLE IF( mloc==0 ) mstart = il1 mloc = mloc + 1 ENDDO ! pccg_res_tr2 = MIN(0.01_DP,1000000._DP*tr2_dfpt) `````` 701 `````` ! `````` Victor Yu committed May 20, 2021 702 703 `````` CALL apply_operator ( mloc, dvg(1,mstart), dng(1,mstart), pccg_res_tr2, iq ) ! `````` Marco Govoni committed Nov 28, 2017 704 705 706 707 `````` ! ! ! hr = ! `````` Victor Yu committed May 20, 2021 708 `````` CALL build_hr( dvg, dng, mstart, mstart+mloc-1, hr_distr, 1, nvec ) `````` Marco Govoni committed Nov 28, 2017 709 710 711 712 713 714 715 716 717 718 719 720 `````` ! ! ... diagonalize the reduced hamiltonian ! CALL diagox( nbase, nvec, hr_distr, nvecx, ew, vr_distr ) time_spent(2)=get_clock( 'chidiago' ) CALL get_clock_called( 'stern' , sternop_ncalls(2) ) ev(1:nvec) = ew(1:nvec) ! ! Write the eigenvalues & time spent ! CALL output_ev_and_time_q( nvec,ev,conv,time_spent,sternop_ncalls,pccg_res_tr2,dfpt_dim,diago_dim,dav_iter,notcnv,iq ) dav_iter = 0 `````` Victor Yu committed May 20, 2021 721 `````` IF(n_steps_write_restart == 1) CALL wstat_restart_write( dav_iter, notcnv, nbase, ew, hr_distr, vr_distr, iq ) `````` Marco Govoni committed Nov 28, 2017 722 723 `````` ! ENDIF `````` Marco Govoni committed Apr 30, 2017 724 `````` ! `````` Marco Govoni committed Nov 28, 2017 725 `````` ! -------------------- `````` Marco Govoni committed Apr 30, 2017 726 `````` ! `````` Marco Govoni committed Nov 28, 2017 727 `````` ! ... iterate `````` Marco Govoni committed Apr 30, 2017 728 `````` ! `````` Marco Govoni committed Nov 28, 2017 729 `````` ! -------------------- `````` Marco Govoni committed Apr 30, 2017 730 `````` ! `````` Marco Govoni committed Nov 28, 2017 731 `````` iterate: DO kter = 1, n_pdep_maxiter `````` Marco Govoni committed Apr 30, 2017 732 `````` ! `````` Marco Govoni committed Nov 28, 2017 733 734 `````` time_spent(1) = get_clock( 'chidiago' ) CALL get_clock_called( 'stern' , sternop_ncalls(1) ) `````` Marco Govoni committed Apr 30, 2017 735 `````` ! `````` Marco Govoni committed Nov 28, 2017 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 `````` dav_iter = dav_iter + 1 ! dfpt_dim = notcnv diago_dim = nbase+notcnv WRITE(stdout, "( /,5x,' *----------* *----------* *----------*') ") WRITE(stdout, "( 5x,'# Iteration = | ', i8,' |',' ','DFPT_dim = | ', i8,' |', ' ','Diago_dim = | ', i8,' |')") & &dav_iter, dfpt_dim, diago_dim WRITE(stdout, "( 5x,' *----------* *----------* *----------*') ") ! ALLOCATE( ishift( nvecx ), STAT=ierr ) IF( ierr /= 0 ) CALL errore( 'chidiago',' cannot allocate ishift ', ABS(ierr) ) ishift=0 np = 0 ! DO n = 1, nvec `````` Marco Govoni committed Apr 30, 2017 751 `````` ! `````` Marco Govoni committed Nov 28, 2017 752 753 `````` IF ( .NOT. conv(n) ) THEN ! `````` Victor Yu committed May 20, 2021 754 `````` ! ... this root not yet converged ... `````` Marco Govoni committed Nov 28, 2017 755 756 757 758 `````` ! np = np + 1 ! ! ... reorder eigenvectors so that coefficients for unconverged `````` Victor Yu committed May 20, 2021 759 `````` ! ... roots come first. This allows to use quick matrix-matrix `````` Marco Govoni committed Nov 28, 2017 760 761 762 763 764 765 `````` ! ... multiplications to set a new basis vector (see below) ! !IF ( np /= n ) vr(:,np) = vr(:,n) ishift(nbase+np) = n ! ew(nbase+np) = ev(n) `````` Victor Yu committed May 20, 2021 766 `````` ! `````` Marco Govoni committed Nov 28, 2017 767 `````` END IF `````` Marco Govoni committed Apr 30, 2017 768 `````` ! `````` Marco Govoni committed Nov 28, 2017 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 `````` END DO ! ! ... expand the basis set with new basis vectors ( H - e*S )|psi> ... ! CALL redistribute_vr_distr( notcnv, nbase, nvecx, vr_distr, ishift ) DEALLOCATE(ishift) CALL update_with_vr_distr( dvg, dng, notcnv, nbase, nvecx, vr_distr, ew ) ! ! ... MGS ! CALL do_mgs(dvg,nbase+1,nbase+notcnv) ! ! apply the response function to new vectors ! ! determine image that actually compute dng first ! `````` Victor Yu committed May 20, 2021 785 `````` mloc = 0 `````` Marco Govoni committed Nov 28, 2017 786 787 788 789 790 791 792 793 794 795 796 `````` mstart = 1 DO il1 = 1, pert%nloc ig1 = pert%l2g(il1) IF( ig1 < nbase+1 .OR. ig1 > nbase+notcnv ) CYCLE IF( mloc==0 ) mstart = il1 mloc = mloc + 1 ENDDO ! ! Apply operator with DFPT ! pccg_res_tr2 = tr2_dfpt `````` 797 `````` ! `````` Victor Yu committed May 20, 2021 798 `````` CALL apply_operator ( mloc, dvg(1,mstart), dng(1,mstart), pccg_res_tr2, iq ) `````` Marco Govoni committed Nov 28, 2017 799 800 801 802 803 804 `````` ! ! ... update the reduced hamiltonian ! ! ! hr = ! `````` Victor Yu committed May 20, 2021 805 `````` CALL build_hr( dvg, dng, mstart, mstart+mloc-1, hr_distr, nbase+1, nbase+notcnv ) `````` Marco Govoni committed Nov 28, 2017 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 `````` ! nbase = nbase + notcnv ! CALL symm_hr_distr(hr_distr,nbase,nvecx) ! ! ... diagonalize the reduced hamiltonian ! CALL diagox( nbase, nvec, hr_distr, nvecx, ew, vr_distr ) time_spent(2)=get_clock( 'chidiago' ) CALL get_clock_called( 'stern' , sternop_ncalls(2) ) ! ! ... test for convergence ! conv(1:nvec) = ( ( ABS( (ew(1:nvec) - ev(1:nvec))/ev(1:nvec) ) < trev_pdep_rel ) & .AND. ( ABS( ew(1:nvec) - ev(1:nvec) ) < trev_pdep ) ) !conv(1:nvec) = ( ( ABS( ew(1:nvec) - ev(1:nvec) ) < trev_pdep ) ) ! notcnv = COUNT( .NOT. conv(:) ) ! ev(1:nvec) = ew(1:nvec) ! ! Write the eigenvalues & time spent ! CALL output_ev_and_time_q(nvec,ev,conv,time_spent,sternop_ncalls,pccg_res_tr2,dfpt_dim,diago_dim,dav_iter,notcnv,iq) ! ! ... if overall convergence has been achieved, or the dimension of ! ... the reduced basis set is becoming too large, or in any case if ! ... we are at the last iteration refresh the basis set. i.e. replace ! ... the first nvec elements with the current estimate of the ! ... eigenvectors; set the basis dimension to nvec. ! IF ( notcnv == 0 .OR. nbase+notcnv > nvecx .OR. kter == n_pdep_maxiter ) THEN `````` Marco Govoni committed Apr 30, 2017 838 `````` ! `````` Marco Govoni committed Nov 28, 2017 839 `````` CALL start_clock( 'chidiago:last' ) `````` Marco Govoni committed Apr 30, 2017 840 `````` ! `````` Marco Govoni committed Nov 28, 2017 841 842 843 844 845 846 847 848 849 850 851 852 853 `````` IF ( notcnv == 0 ) THEN ! ! ... all roots converged: return ! CALL stop_clock( 'chidiago:last' ) ! CALL refresh_with_vr_distr( dvg, nvec, nbase, nvecx, vr_distr ) ! CALL pdep_db_write( iq ) CALL wstat_restart_clear() !CALL output_a_report(-1) ! WRITE(iter_label,'(i8)') kter `````` Victor Yu committed May 20, 2021 854 `````` CALL io_push_title("Convergence achieved !!! in "//TRIM(iter_label)//" steps") `````` Marco Govoni committed Nov 28, 2017 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 `````` l_is_wstat_converged = .TRUE. ! EXIT iterate ! ELSE IF ( kter == n_pdep_maxiter ) THEN ! ! ... last iteration, some roots not converged: return ! WRITE( stdout, '(5X,"WARNING: ",I5, & & " eigenvalues not converged in chidiago")' ) notcnv ! CALL stop_clock( 'chidiago:last' ) ! EXIT iterate ! END IF `````` Marco Govoni committed Apr 30, 2017 871 `````` ! `````` Marco Govoni committed Nov 28, 2017 872 `````` ! ... refresh psi, H*psi and S*psi `````` Marco Govoni committed Apr 30, 2017 873 `````` ! `````` Marco Govoni committed Nov 28, 2017 874 `````` WRITE(stdout,'(/,7x,"Refresh the basis set")') `````` Marco Govoni committed Apr 30, 2017 875 `````` ! `````` Marco Govoni committed Nov 28, 2017 876 877 `````` CALL refresh_with_vr_distr( dvg, nvec, nbase, nvecx, vr_distr ) CALL refresh_with_vr_distr( dng, nvec, nbase, nvecx, vr_distr ) `````` Marco Govoni committed Apr 30, 2017 878 `````` ! `````` Marco Govoni committed Nov 28, 2017 879 `````` ! ... refresh the reduced hamiltonian `````` Marco Govoni committed Apr 30, 2017 880 `````` ! `````` Marco Govoni committed Nov 28, 2017 881 `````` nbase = nvec `````` Marco Govoni committed Apr 30, 2017 882 `````` ! `````` Marco Govoni committed Nov 28, 2017 883 884 `````` hr_distr = 0._DP vr_distr = 0._DP `````` Marco Govoni committed Apr 30, 2017 885 `````` ! `````` Marco Govoni committed Nov 28, 2017 886 887 888 889 890 891 892 893 `````` DO il1 = 1, pert%nloc ig1 = pert%l2g(il1) IF ( ig1 < 1 .OR. ig1 > nbase ) CYCLE hr_distr(ig1,il1) = ev(ig1) vr_distr(ig1,il1) = 1._DP ENDDO ! CALL stop_clock( 'chidiago:last' ) `````` Marco Govoni committed Apr 30, 2017 894 895 896 `````` ! END IF ! `````` Victor Yu committed May 20, 2021 897 898 899 `````` IF(n_steps_write_restart > 0 .AND. MOD(dav_iter,n_steps_write_restart) == 0) & CALL wstat_restart_write( dav_iter, notcnv, nbase, ew, hr_distr, vr_distr, iq ) !CALL output_a_report(dav_iter) `````` Marco Govoni committed Apr 30, 2017 900 `````` ! `````` Marco Govoni committed Nov 28, 2017 901 `````` END DO iterate `````` Victor Yu committed May 20, 2021 902 903 904 `````` ! CALL stop_clock( 'chidiago' ) ! `````` Marco Govoni committed Nov 28, 2017 905 `````` ENDDO QPOINTS_LOOP ! iq `````` Marco Govoni committed Apr 30, 2017 906 907 908 909 910 911 912 913 914 `````` ! DEALLOCATE( conv ) DEALLOCATE( ew ) DEALLOCATE( ev ) DEALLOCATE( hr_distr ) DEALLOCATE( vr_distr ) ! ! DEALLOCATE( dng ) `````` Marco Govoni committed Nov 28, 2017 915 `````` DEALLOCATE( dvg ) `````` Marco Govoni committed Apr 30, 2017 916 917 918 919 920 921 922 923 924 `````` ! RETURN ! END SUBROUTINE ! ! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ! `````` Victor Yu committed May 20, 2021 925 ``````SUBROUTINE do_mgs(amat,m_global_start,m_global_end) `````` Marco Govoni committed Apr 30, 2017 926 927 928 929 930 931 `````` ! ! MGS of the vectors beloging to the interval [ m_global_start, m_global_end ] ! also with respect to the vectors belonging to the interval [ 1, m_global_start -1 ] ! USE kinds, ONLY : DP USE io_global, ONLY : stdout `````` Victor Yu committed May 20, 2021 932 `````` USE mp_global, ONLY : intra_bgrp_comm,inter_image_comm,my_image_id,nimage,world_comm `````` Marco Govoni committed Apr 30, 2017 933 934 `````` USE gvect, ONLY : gstart USE mp, ONLY : mp_sum,mp_barrier,mp_bcast `````` Marco Govoni committed Nov 28, 2017 935 `````` USE westcom, ONLY : npwq,npwqx `````` Marco Govoni committed Apr 30, 2017 936 `````` USE control_flags, ONLY : gamma_only `````` Victor Yu committed May 20, 2021 937 `````` USE io_push, ONLY : io_push_title `````` Marco Govoni committed Apr 30, 2017 938 939 940 941 942 943 944 `````` USE distribution_center, ONLY : pert ! IMPLICIT NONE ! ! I/O ! INTEGER, INTENT(IN) :: m_global_start,m_global_end `````` Marco Govoni committed Nov 28, 2017 945 `````` COMPLEX(DP) :: amat(npwqx,pert%nlocx) `````` Marco Govoni committed Apr 30, 2017 946 `````` ! `````` Victor Yu committed May 20, 2021 947 `````` ! Workspace `````` Marco Govoni committed Apr 30, 2017 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 `````` ! INTEGER :: ig, ip, j, ncol INTEGER :: k_global, k_local, j_local, k_id REAL(DP) :: anorm REAL(DP),ALLOCATABLE :: braket(:) REAL(DP) :: time_spent(2) COMPLEX(DP),ALLOCATABLE :: vec(:),zbraket(:) LOGICAL :: unfinished COMPLEX(DP) :: za INTEGER :: m_local_start,m_local_end ! REAL(DP),EXTERNAL :: DDOT COMPLEX(DP),EXTERNAL :: ZDOTC ! CALL mp_barrier(world_comm) ! CALL start_clock ('paramgs') ! `````` Marco Govoni committed Nov 28, 2017 966 `````` ALLOCATE( vec(npwqx), zbraket(pert%nloc), braket(pert%nloc) ) `````` Marco Govoni committed Apr 30, 2017 967 968 969 970 971 972 973 974 `````` ! ! 1) Run some checks ! IF( m_global_start < 1 .OR. m_global_start > m_global_end .OR. m_global_end > pert%nglob ) & & CALL errore( 'mgs', 'do_mgs problem', 1 ) ! ! 2) Localize m_global_start ! `````` Victor Yu committed May 20, 2021 975 `````` m_local_start = 1 `````` Marco Govoni committed Apr 30, 2017 976 977 978 `````` DO ip = 1, pert%nloc ig = pert%l2g(ip) IF( ig < m_global_start ) CYCLE `````` Victor Yu committed May 20, 2021 979 `````` m_local_start = ip `````` Marco Govoni committed Apr 30, 2017 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 `````` EXIT ENDDO ! ! 3) Localize m_global_end ! m_local_end = pert%nloc DO ip = pert%nloc, 1, -1 ig = pert%l2g(ip) IF( ig > m_global_end ) CYCLE m_local_end = ip EXIT ENDDO ! j_local=1 unfinished=.true. ! !DO k_global=m_global_start,m_global_end DO k_global=1,m_global_end ! CALL pert%g2l(k_global,k_local,k_id) !CALL distr_g2l(k_global,k_local,k_id,nimage) ! IF(my_image_id==k_id) THEN ! ! 4) Eventually, normalize the current vector ! IF( k_global >= m_global_start ) THEN ! ! anorm = < k_l | k_l > ! IF(gamma_only) THEN `````` Marco Govoni committed Nov 28, 2017 1011 `````` anorm = 2.0_DP * DDOT(2*npwq,amat(1,k_local),1,amat(1,k_local),1) `````` Marco Govoni committed Apr 30, 2017 1012 1013 `````` IF(gstart==2) anorm = anorm - REAL(amat(1,k_local),KIND=DP) * REAL(amat(1,k_local),KIND=DP) ELSE `````` Marco Govoni committed Nov 28, 2017 1014 `````` anorm = DDOT(2*npwq,amat(1,k_local),1,amat(1,k_local),1) `````` Marco Govoni committed Apr 30, 2017 1015 1016 1017 1018 1019 1020 1021 `````` ENDIF ! CALL mp_sum(anorm,intra_bgrp_comm) ! ! normalize | k_l > ! za = CMPLX( 1._DP/SQRT(anorm), 0._DP,KIND=DP) `````` Marco Govoni committed Nov 28, 2017 1022 `````` CALL ZSCAL(npwq,za,amat(1,k_local),1) `````` Marco Govoni committed Apr 30, 2017 1023 1024 1025 1026 1027 `````` ! ENDIF ! ! 5) Copy the current vector into V ! `````` Marco Govoni committed Nov 28, 2017 1028 `````` CALL ZCOPY(npwqx,amat(1,k_local),1,vec(1),1) `````` Marco Govoni committed Apr 30, 2017 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 `````` ! j_local=MAX(k_local+1,m_local_start) ! !IF(j_local>pert%nloc) unfinished=.false. IF(j_local>m_local_end) unfinished=.false. ! ENDIF ! ! BCAST | vec > ! CALL mp_bcast(vec,k_id,inter_image_comm) ! ! Update when needed ! IF(unfinished) THEN ! ! IN the range ip=j_local:pert%nloc = > | ip > = | ip > - | vec > * < vec | ip > ! IF(gamma_only) THEN DO ip = j_local,m_local_end !pert%nloc `````` Marco Govoni committed Nov 28, 2017 1049 `````` braket(ip) = 2._DP * DDOT(2*npwq,vec(1),1,amat(1,ip),1) `````` Marco Govoni committed Apr 30, 2017 1050 `````` ENDDO `````` Victor Yu committed May 20, 2021 1051 1052 `````` !IF (gstart==2) FORALL( ip=j_local:pert%nloc ) braket(ip) = braket(ip) - REAL(vec(1),KIND=DP)*REAL(amat(1,ip),KIND=DP) IF (gstart==2) FORALL( ip=j_local:m_local_end ) braket(ip) = braket(ip) - REAL(vec(1),KIND=DP)*REAL(amat(1,ip),KIND=DP) `````` Marco Govoni committed Apr 30, 2017 1053 1054 1055 1056 1057 1058 `````` !CALL mp_sum(braket(j_local:pert%nloc),intra_bgrp_comm) CALL mp_sum(braket(j_local:m_local_end),intra_bgrp_comm) !FORALL(ip=j_local:pert%nloc) zbraket(ip) = CMPLX( braket(ip), 0._DP, KIND=DP) FORALL(ip=j_local:m_local_end) zbraket(ip) = CMPLX( braket(ip), 0._DP, KIND=DP) ELSE DO ip = j_local,m_local_end !pert%nloc `````` Marco Govoni committed Nov 28, 2017 1059 `````` zbraket(ip) = ZDOTC(npwq,vec(1),1,amat(1,ip),1) `````` Marco Govoni committed Apr 30, 2017 1060 1061 1062 1063 1064 1065 1066 `````` ENDDO !CALL mp_sum(zbraket(j_local:pert%nloc),intra_bgrp_comm) CALL mp_sum(zbraket(j_local:m_local_end),intra_bgrp_comm) ENDIF ! ncol=m_local_end-j_local+1 !ncol=m_global_end-j_local+1 `````` Marco Govoni committed Nov 28, 2017 1067 `````` CALL ZGERU(npwqx,ncol,(-1._DP,0._DP),vec(1),1,zbraket(j_local),1,amat(1,j_local),npwqx) `````` Marco Govoni committed Apr 30, 2017 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 `````` ! ENDIF ! ENDDO ! DEALLOCATE( vec,zbraket,braket ) ! CALL mp_barrier(world_comm) ! CALL stop_clock ('paramgs') ! END SUBROUTINE ! ! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ! `````` Victor Yu committed May 20, 2021 1085 ``````SUBROUTINE do_randomize ( amat, mglobalstart, mglobalend ) `````` Marco Govoni committed Apr 30, 2017 1086 1087 1088 1089 1090 1091 `````` ! ! Randomize in dvg the vectors belonging to [ mglobalstart, mglobalend ] ! USE kinds, ONLY : DP USE random_numbers, ONLY : randy USE gvect, ONLY : g,gstart,ngm_g,ig_l2g `````` Marco Govoni committed Nov 28, 2017 1092 `````` USE westcom, ONLY : npwq,dvg,npwqx `````` Marco Govoni committed Apr 30, 2017 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 `````` USE constants, ONLY : tpi USE mp, ONLY : mp_barrier USE mp_global, ONLY : world_comm USE distribution_center, ONLY : pert ! IMPLICIT NONE ! ! I/O ! INTEGER,INTENT(IN) :: mglobalstart, mglobalend `````` Marco Govoni committed Nov 28, 2017 1103 `````` COMPLEX(DP) :: amat(npwqx,pert%nlocx) `````` Marco Govoni committed Apr 30, 2017 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 `````` ! ! Workspace ! REAL(DP),ALLOCATABLE :: random_num_debug(:,:) INTEGER :: il1,ig1,ig REAL(DP) :: aux_real REAL(DP) :: rr, arg ! CALL mp_barrier(world_comm) ! CALL start_clock ('randomize') ! ! Random numbers are generated according to G-global ! ALLOCATE(random_num_debug(2,ngm_g)) ! DO il1=1,pert%nloc ! ig1=pert%l2g(il1) IF( ig1 < mglobalstart .OR. ig1 > mglobalend ) CYCLE ! ! Initialize the sequence ! aux_real=randy(ig1) ! DO ig=1,ngm_g random_num_debug(1:2,ig) = (/ randy(), randy() /) ENDDO ! amat(:,il1) = 0._DP !\$OMP PARALLEL private(ig,rr,arg) !\$OMP DO `````` Marco Govoni committed Nov 28, 2017 1136 `````` DO ig=gstart,npwq `````` Marco Govoni committed Apr 30, 2017 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 `````` rr = random_num_debug(1,ig_l2g(ig)) arg = tpi * random_num_debug(2,ig_l2g(ig)) amat(ig,il1) = CMPLX( rr*COS( arg ), rr*SIN( arg ), KIND=DP) / & ( g(1,ig)*g(1,ig) + & g(2,ig)*g(2,ig) + & g(3,ig)*g(3,ig) + 1.0_DP ) ENDDO !\$OMP ENDDO !\$OMP END PARALLEL ! ENDDO ! DEALLOCATE(random_num_debug) ! CALL stop_clock ('randomize') ! END SUBROUTINE ! ! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ! `````` Victor Yu committed May 20, 2021 1159 ``````SUBROUTINE do_randomize_q (amat, mglobalstart, mglobalend, iq) `````` Marco Govoni committed Nov 28, 2017 1160 1161 1162 1163 1164 1165 `````` ! ! Randomize in dvg the vectors belonging to [ mglobalstart, mglobalend ] ! USE kinds, ONLY : DP USE random_numbers, ONLY : randy USE gvect, ONLY : g,gstart,ngm_g,ig_l2g `````` Matteo Gerosa committed Dec 13, 2017 1166 1167 `````` USE westcom, ONLY : dvg,npwqx,ngq,igq_q USE constants, ONLY : tpi,eps8 `````` Marco Govoni committed Nov 28, 2017 1168 1169 1170 1171 `````` USE cell_base, ONLY : tpiba2 USE mp, ONLY : mp_barrier USE mp_global, ONLY : world_comm USE distribution_center, ONLY : pert `````` Matteo Gerosa committed Dec 13, 2017 1172 `````` USE types_bz_grid, ONLY : q_grid `````` Marco Govoni committed Nov 28, 2017 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 `````` ! IMPLICIT NONE ! ! I/O ! INTEGER,INTENT(IN) :: mglobalstart, mglobalend COMPLEX(DP) :: amat(npwqx,pert%nlocx) INTEGER,INTENT(IN) :: iq ! ! Workspace ! REAL(DP),ALLOCATABLE :: random_num_debug(:,:) INTEGER :: il1,ig1,ig REAL(DP) :: aux_real `````` Matteo Gerosa committed Dec 13, 2017 1187 `````` REAL(DP) :: rr, arg, qg(3), qgnorm2 `````` Marco Govoni committed Nov 28, 2017 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 `````` ! CALL mp_barrier(world_comm) ! CALL start_clock ('randomize') ! ! Random numbers are generated according to G-global ! ALLOCATE(random_num_debug(2,ngm_g)) ! DO il1=1,pert%nloc ! ig1=pert%l2g(il1) IF( ig1 < mglobalstart .OR. ig1 > mglobalend ) CYCLE ! ! Initialize the sequence ! aux_real=randy(ig1) ! DO ig=1,ngm_g random_num_debug(1:2,ig) = (/ randy(), randy() /) ENDDO ! amat(:,il1) = 0._DP !\$OMP PARALLEL private(ig,rr,arg) !\$OMP DO `````` Matteo Gerosa committed Dec 13, 2017 1213 `````` DO ig=1,ngq(iq) `````` Matteo Gerosa committed Dec 15, 2017 1214 `````` qg(:) = q_grid%p_cart(:,iq) + g(:,igq_q(ig,iq)) `````` Matteo Gerosa committed Dec 13, 2017 1215 1216 `````` qgnorm2 = SUM( qg(:)**2 ) * tpiba2 IF ( qgnorm2 < eps8 ) CYCLE `````` Marco Govoni committed Nov 28, 2017 1217 1218 `````` rr = random_num_debug(1,ig_l2g(igq_q(ig,iq))) arg = tpi * random_num_debug(2,ig_l2g(igq_q(ig,iq))) `````` Victor Yu committed May 20, 2021 1219 `````` amat(ig,il1) = CMPLX( rr*COS( arg ), rr*SIN( arg ), KIND=DP) / ( qgnorm2 + 1.0_DP ) `````` Marco Govoni committed Nov 28, 2017 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 `````` ENDDO !\$OMP ENDDO !\$OMP END PARALLEL ! ENDDO ! DEALLOCATE(random_num_debug) ! CALL stop_clock ('randomize') ! END SUBROUTINE ! ! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ! `````` Marco Govoni committed May 23, 2017 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 ``````!SUBROUTINE output_a_report(iteration) ! ! ! USE json_module, ONLY : json_file ! USE kinds, ONLY : DP ! USE westcom, ONLY : n_pdep_eigen,ev,conv,wstat_output_dir,logfile ! USE west_io , ONLY : serial_table_output ! USE mp_world, ONLY : mpime,root ! ! ! IMPLICIT NONE ! ! ! TYPE(json_file) :: json ! INTEGER,INTENT(IN) :: iteration ! CHARACTER(LEN=9) :: pref ! INTEGER :: ip, ierr, iunit ! !REAL(DP) :: out_tab(n_pdep_eigen,3) ! ! ! INTEGER,ALLOCATABLE :: converged(:) ! ! ! ALLOCATE( converged(n_pdep_eigen) ) ! ! ! converged = 0 ! DO ip=1,n_pdep_eigen ! !out_tab(ip,1) = REAL(ip,DP) `````` Victor Yu committed May 20, 2021 1259 ``````! !ipert(ip) = ip `````` Marco Govoni committed May 23, 2017 1260 1261 1262 1263 1264 ``````! !out_tab(ip,2) = ev(ip) ! !out_tab(ip,3) = 0._DP ! !IF(conv(ip)) out_tab(ip,3) = 1._DP ! IF(conv(ip)) converged(ip) = 1 ! ENDDO `````` Victor Yu committed May 20, 2021 1265 ``````! IF(iteration>=0) THEN `````` Marco Govoni committed May 23, 2017 1266 1267 1268 1269 1270 1271 ``````! WRITE(pref,"('itr_',i5.5)") iteration ! ELSE ! pref='converged' ! ENDIF ! !CALL serial_table_output(mpime==root,4000,'wstat.'//TRIM(ADJUSTL(pref)),out_tab,n_pdep_eigen,3,(/' iprt','eigenv.',' conv.'/)) ! ! `````` Victor Yu committed May 20, 2021 1272 ``````! IF( mpime == root ) THEN `````` Marco Govoni committed May 23, 2017 1273 1274 1275 1276 1277 1278 1279 1280 ``````! ! ! CALL json%initialize() ! ! ! CALL json%load_file(filename=TRIM(logfile)) ! ! ! CALL json%add('output.davitr'//TRIM(pref)//.'egvl', ev ( 1:n_pdep_eigen ) ) ! CALL json%add('output.davitr'//TRIM(pref)//.'conv', converged ( 1:n_pdep_eigen ) ) ! ! `````` Victor Yu committed May 20, 2021 1281 ``````! !OPEN(UNIT=4000,FILE=TRIM(ADJUSTL(wstat_output_dir))//"/o-wstat."//TRIM(ADJUSTL(pref))//".json",IOSTAT=ierr) `````` Marco Govoni committed May 23, 2017 1282 1283 1284 1285 1286 1287 1288 1289 1290 ``````! !CALL json%print_file( 4000 ) ! !CLOSE( 4000, IOSTAT=ierr ) ! ! ! OPEN( NEWUNIT=iunit,FILE=TRIM(logfile) ) ! CALL json%print_file( iunit ) ! CLOSE( iunit ) ! ! ! CALL json%destroy() ! ! `````` Victor Yu committed May 20, 2021 1291 ``````! ENDIF `````` Marco Govoni committed May 23, 2017 1292 ``````! ! `````` Victor Yu committed May 20, 2021 1293 1294 ``````! !DEALLOCATE( iprt ) ! DEALLOCATE( converged ) `````` Marco Govoni committed May 23, 2017 1295 1296 ``````! ! !END SUBROUTINE `````` Marco Govoni committed Apr 30, 2017 1297 1298 1299 1300 1301 ``````! ! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ! %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ! ``````