forked from wannier-developers/wannier90
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwannierise.F90
3661 lines (3203 loc) · 142 KB
/
wannierise.F90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
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
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
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
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!!-*- mode: F90 -*-!
!------------------------------------------------------------!
! This file is distributed as part of the Wannier90 code and !
! under the terms of the GNU General Public License. See the !
! file `LICENSE' in the root directory of the Wannier90 !
! distribution, or http://www.gnu.org/copyleft/gpl.txt !
! !
! The webpage of the Wannier90 code is www.wannier.org !
! !
! The Wannier90 code is hosted on GitHub: !
! !
! https://github.com/wannier-developers/wannier90 !
!------------------------------------------------------------!
! !
! w90_wannierise: MLFW algorithm !
! !
!------------------------------------------------------------!
module w90_wannierise_mod
!! Main routines for the minimisation of the spread
use w90_constants, only: dp
use w90_error, only: w90_error_type, set_error_alloc, set_error_dealloc, set_error_fatal, &
set_error_input, set_error_fatal, set_error_file
use w90_comms, only: w90_comm_type
implicit none
private
public :: wann_main
public :: wann_main_gamma
type localisation_vars_type
!! Contributions to the spread
real(kind=dp) :: om_i !! Gauge Invarient
real(kind=dp) :: om_d !! Diagonal
real(kind=dp) :: om_od !! Off-diagonal
real(kind=dp) :: om_tot !! Total
real(kind=dp) :: om_iod !! Combined I-OD term for selective localization
real(kind=dp) :: om_nu !! Lagrange multiplier term due to constrained centres
end type localisation_vars_type
contains
!================================================!
subroutine wann_main(ham_logical, kmesh_info, kpt_latt, wann_control, omega, sitesym, &
print_output, wannier_data, ws_region, w90_calculation, ham_k, ham_r, &
m_matrix_loc, u_matrix, real_lattice, wannier_centres_translated, irvec, &
mp_grid, ndegen, nrpts, num_kpts, num_proj, num_wann, optimisation, &
rpt_origin, bands_plot_mode, transport_mode, lsitesymmetry, stdout, &
timer, dist_k, error, comm)
!================================================!
!
!! Calculate the Unitary Rotations to give Maximally Localised Wannier Functions
!
!================================================
use w90_constants, only: dp, cmplx_1, cmplx_0, twopi, cmplx_i
use w90_io, only: io_wallclocktime, io_stopwatch_start, io_stopwatch_stop
use w90_wannier90_types, only: wann_control_type, w90_calculation_type, wann_omega_type, &
sitesym_type, ham_logical_type
use w90_types, only: kmesh_info_type, print_output_type, wannier_data_type, ws_region_type, &
timer_list_type
use w90_utility, only: utility_frac_to_cart, utility_zgemm
use w90_sitesym, only: sitesym_symmetrize_gradient
use w90_comms, only: mpisize, mpirank, comms_allreduce, w90_comm_type
use w90_hamiltonian, only: hamiltonian_setup
implicit none
! arguments
type(ham_logical_type), intent(inout) :: ham_logical
type(kmesh_info_type), intent(in) :: kmesh_info
type(ws_region_type), intent(in) :: ws_region
type(print_output_type), intent(in) :: print_output
type(wann_control_type), intent(inout) :: wann_control
type(wann_omega_type), intent(inout) :: omega
type(sitesym_type), intent(in) :: sitesym
type(w90_calculation_type), intent(in) :: w90_calculation
type(w90_comm_type), intent(in) :: comm
type(wannier_data_type), intent(inout) :: wannier_data
type(timer_list_type), intent(inout) :: timer
type(w90_error_type), allocatable, intent(out) :: error
integer, intent(in) :: mp_grid(3)
integer, intent(in) :: num_kpts
integer, intent(in) :: num_proj
integer, intent(in) :: num_wann
integer, intent(in) :: optimisation
integer, intent(inout), allocatable :: irvec(:, :)
integer, intent(inout), allocatable :: ndegen(:)
integer, intent(inout) :: nrpts
integer, intent(inout) :: rpt_origin
integer, intent(in) :: stdout
integer, intent(in) :: dist_k(:)
real(kind=dp), intent(in) :: kpt_latt(:, :)
real(kind=dp), intent(inout), allocatable :: wannier_centres_translated(:, :)
real(kind=dp), intent(in) :: real_lattice(3, 3)
complex(kind=dp), intent(inout), allocatable :: ham_k(:, :, :)
complex(kind=dp), intent(inout), allocatable :: ham_r(:, :, :)
!complex(kind=dp), intent(inout) :: m_matrix(:, :, :, :)
complex(kind=dp), intent(inout) :: m_matrix_loc(:, :, :, :)
complex(kind=dp), intent(inout) :: u_matrix(:, :, :)
logical, intent(in) :: lsitesymmetry
character(len=*), intent(in) :: bands_plot_mode
character(len=*), intent(in) :: transport_mode
! local variables
type(localisation_vars_type) :: old_spread
type(localisation_vars_type) :: wann_spread
type(localisation_vars_type) :: trial_spread
! Data to avoid large allocation within iteration loop
real(kind=dp), allocatable :: rnkb(:, :, :)
real(kind=dp), allocatable :: rnkb_loc(:, :, :)
real(kind=dp), allocatable :: ln_tmp(:, :, :)
real(kind=dp), allocatable :: ln_tmp_loc(:, :, :)
real(kind=dp), allocatable :: sheet(:, :, :)
real(kind=dp), allocatable :: rave(:, :), r2ave(:), rave2(:)
! guiding centres
real(kind=dp), allocatable :: rguide(:, :)
complex(kind=dp), allocatable :: u_matrix_loc(:, :, :)
complex(kind=dp), allocatable :: cdq_loc(:, :, :) ! the only large array sent from process to process in the main loop
complex(kind=dp), allocatable :: cdodq_loc(:, :, :)
complex(kind=dp), allocatable :: csheet(:, :, :)
complex(kind=dp), allocatable :: cdodq(:, :, :)
complex(kind=dp), allocatable :: cdodq_r(:, :, :)
complex(kind=dp), allocatable :: k_to_r(:, :)
complex(kind=dp), allocatable :: cdodq_precond(:, :, :)
complex(kind=dp), allocatable :: cdodq_precond_loc(:, :, :)
!local arrays not passed into subroutines
complex(kind=dp), allocatable :: cwschur1(:), cwschur2(:)
complex(kind=dp), allocatable :: cwschur3(:), cwschur4(:)
complex(kind=dp), allocatable :: cdq(:, :, :)!,cdqkeep(:,:,:)
! cdqkeep is replaced by cdqkeep_loc
complex(kind=dp), allocatable :: cdqkeep_loc(:, :, :)
complex(kind=dp), allocatable :: cz(:, :)
complex(kind=dp), allocatable :: cmtmp(:, :), tmp_cdq(:, :)
! complex(kind=dp), allocatable :: m0(:,:,:,:),u0(:,:,:)
! m0 and u0 are replaced by m0_loc and u0_loc
complex(kind=dp), allocatable :: m0_loc(:, :, :, :), u0_loc(:, :, :)
complex(kind=dp), allocatable :: cwork(:)
real(kind=dp), allocatable :: evals(:)
real(kind=dp), allocatable :: rwork(:)
real(kind=dp), allocatable :: history(:)
real(kind=dp), allocatable :: rnr0n2(:)
logical :: first_pass
!! Used to trigger the calculation of the invarient spread we only need to do this on entering wann_main (_gamma)
real(kind=dp) :: lambda_loc
integer, allocatable :: global_k(:)
complex(kind=dp) :: rdotk
integer :: conv_count, noise_count, page_unit
integer :: i, n, iter, ind, ierr, iw, ncg, nkp, nkp_loc
integer :: irguide
integer :: irpt, loop_kpt
integer :: nkrank
logical :: lconverged, lrandom, lfirst
logical :: lprint, ldump, lquad
real(kind=dp) :: doda0
real(kind=dp) :: falphamin, alphamin
real(kind=dp) :: gcfac, gcnorm1, gcnorm0
real(kind=dp) :: save_spread
! pllel setup
logical :: on_root = .false.
integer :: num_nodes, my_node_id
num_nodes = mpisize(comm)
my_node_id = mpirank(comm)
if (my_node_id == 0) on_root = .true.
if (print_output%timing_level > 0 .and. print_output%iprint > 0) then
call io_stopwatch_start('wann: main', timer)
endif
first_pass = .true.
nkrank = count(dist_k == my_node_id) ! number k this rank, for dimensioning
! there is no need to round up to 1, but less than zero is nonsense
if (nkrank < 0) then
call set_error_fatal(error, 'kpt decomposition nonsensical in wann_main', comm)
return
endif
allocate (global_k(nkrank), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, 'Error in allocating local kpoint distribution in wann_main', comm)
return
end if
loop_kpt = 1
do i = 1, num_kpts
if (dist_k(i) == my_node_id) then
global_k(loop_kpt) = i
loop_kpt = loop_kpt + 1
endif
enddo
! Allocate stuff
allocate (history(wann_control%conv_window), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, 'Error allocating history in wann_main', comm)
return
endif
allocate (rnkb(num_wann, kmesh_info%nntot, num_kpts), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, 'Error in allocating rnkb in wann_main', comm)
return
endif
rnkb = 0.0_dp
allocate (ln_tmp(num_wann, kmesh_info%nntot, num_kpts), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, 'Error in allocating ln_tmp in wann_main', comm)
return
endif
if (wann_control%constrain%selective_loc) then
allocate (rnr0n2(wann_control%constrain%slwf_num), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, 'Error in allocating rnr0n2 in wann_main', comm)
return
endif
end if
! sub vars passed into other subs
allocate (csheet(num_wann, kmesh_info%nntot, num_kpts), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, 'Error in allocating csheet in wann_main', comm)
return
endif
allocate (cdodq(num_wann, num_wann, num_kpts), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, 'Error in allocating cdodq in wann_main', comm)
return
endif
allocate (sheet(num_wann, kmesh_info%nntot, num_kpts), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, 'Error in allocating sheet in wann_main', comm)
return
endif
allocate (rave(3, num_wann), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, 'Error in allocating rave in wann_main', comm)
return
endif
allocate (r2ave(num_wann), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, 'Error in allocating r2ave in wann_main', comm)
return
endif
allocate (rave2(num_wann), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, 'Error in allocating rave2 in wann_main', comm)
return
endif
allocate (rguide(3, num_wann))
if (ierr /= 0) then
call set_error_alloc(error, 'Error in allocating rguide in wann_main', comm)
return
endif
if (wann_control%precond) then
call hamiltonian_setup(ham_logical, print_output, ws_region, w90_calculation, ham_k, ham_r, &
real_lattice, wannier_centres_translated, irvec, mp_grid, ndegen, &
num_kpts, num_wann, nrpts, rpt_origin, bands_plot_mode, stdout, &
timer, error, transport_mode, comm)
if (allocated(error)) return
allocate (cdodq_r(num_wann, num_wann, nrpts), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, 'Error in allocating cdodq_r in wann_main', comm)
return
endif
allocate (cdodq_precond(num_wann, num_wann, num_kpts), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, 'Error in allocating cdodq_precond in wann_main', comm)
return
endif
! this method of computing the preconditioning is much more efficient, but requires more RAM
if (optimisation >= 3) then
allocate (k_to_r(num_kpts, nrpts), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, 'Error in allocating k_to_r in wann_main', comm)
return
endif
do irpt = 1, nrpts
do loop_kpt = 1, num_kpts
rdotk = twopi*dot_product(kpt_latt(:, loop_kpt), real(irvec(:, irpt), dp))
k_to_r(loop_kpt, irpt) = exp(-cmplx_i*rdotk)
enddo
enddo
end if
end if
csheet = cmplx_1; cdodq = cmplx_0
sheet = 0.0_dp; rave = 0.0_dp; r2ave = 0.0_dp; rave2 = 0.0_dp; rguide = 0.0_dp
! sub vars not passed into other subs
allocate (cwschur1(num_wann), cwschur2(10*num_wann), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, 'Error in allocating cwshur1 in wann_main', comm)
return
endif
allocate (cwschur3(num_wann), cwschur4(num_wann), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, 'Error in allocating cwshur3 in wann_main', comm)
return
endif
allocate (cdq(num_wann, num_wann, num_kpts), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, 'Error in allocating cdq in wann_main', comm)
return
endif
allocate (rnkb_loc(num_wann, kmesh_info%nntot, nkrank), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, 'Error in allocating rnkb_loc in wann_main', comm)
return
endif
allocate (ln_tmp_loc(num_wann, kmesh_info%nntot, nkrank), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, 'Error in allocating ln_tmp_loc in wann_main', comm)
return
endif
allocate (u_matrix_loc(num_wann, num_wann, nkrank), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, 'Error in allocating u_matrix_loc in wann_main', comm)
return
endif
if (wann_control%precond) then
allocate (cdodq_precond_loc(num_wann, num_wann, nkrank), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, 'Error in allocating cdodq_precond_loc in wann_main', comm)
return
endif
end if
! initialize local u matrix with global one
do nkp_loc = 1, nkrank
nkp = global_k(nkp_loc)
u_matrix_loc(:, :, nkp_loc) = u_matrix(:, :, nkp)
end do
allocate (cdq_loc(num_wann, num_wann, nkrank), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, 'Error in allocating cdq_loc in wann_main', comm)
return
endif
allocate (cdodq_loc(num_wann, num_wann, nkrank), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, 'Error in allocating cdodq_loc in wann_main', comm)
return
endif
allocate (cdqkeep_loc(num_wann, num_wann, nkrank), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, 'Error in allocating cdqkeep_loc in wann_main', comm)
return
endif
if (optimisation > 0) then
allocate (m0_loc(num_wann, num_wann, kmesh_info%nntot, nkrank), stat=ierr)
end if
if (ierr /= 0) then
call set_error_alloc(error, 'Error in allocating m0_loc in wann_main', comm)
return
endif
allocate (u0_loc(num_wann, num_wann, nkrank), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, 'Error in allocating u0_loc in wann_main', comm)
return
endif
allocate (cz(num_wann, num_wann), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, 'Error in allocating cz in wann_main', comm)
return
endif
allocate (cmtmp(num_wann, num_wann), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, 'Error in allocating cmtmp in wann_main', comm)
return
endif
allocate (tmp_cdq(num_wann, num_wann), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, 'Error in allocating tmp_cdq in wann_main', comm)
return
endif
allocate (evals(num_wann), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, 'Error in allocating evals in wann_main', comm)
return
endif
allocate (cwork(4*num_wann), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, 'Error in allocating cwork in wann_main', comm)
return
endif
allocate (rwork(3*num_wann - 2), stat=ierr)
if (ierr /= 0) then
call set_error_alloc(error, 'Error in allocating rwork in wann_main', comm)
return
endif
cwschur1 = cmplx_0; cwschur2 = cmplx_0; cwschur3 = cmplx_0; cwschur4 = cmplx_0
cdq = cmplx_0; cz = cmplx_0; cmtmp = cmplx_0; cdqkeep_loc = cmplx_0; cdq_loc = cmplx_0
gcnorm1 = 0.0_dp; gcnorm0 = 0.0_dp
! initialise rguide to projection centres (Cartesians in units of Ang)
if (wann_control%guiding_centres%enable) then
do n = 1, num_proj
call utility_frac_to_cart(wann_control%guiding_centres%centres(:, n), rguide(:, n), &
real_lattice)
enddo
end if
if (print_output%iprint > 0) then
write (stdout, *)
write (stdout, '(1x,a)') '*------------------------------- WANNIERISE ---------------------------------*'
write (stdout, '(1x,a)') '+--------------------------------------------------------------------+<-- CONV'
if (print_output%lenconfac .eq. 1.0_dp) then
write (stdout, '(1x,a)') '| Iter Delta Spread RMS Gradient Spread (Ang^2) Time |<-- CONV'
else
write (stdout, '(1x,a)') '| Iter Delta Spread RMS Gradient Spread (Bohr^2) Time |<-- CONV'
endif
write (stdout, '(1x,a)') '+--------------------------------------------------------------------+<-- CONV'
write (stdout, *)
endif
irguide = 0
if (wann_control%guiding_centres%enable .and. (wann_control%guiding_centres%num_no_guide_iter .le. 0)) then
call wann_phases(csheet, sheet, rguide, irguide, num_wann, kmesh_info, num_kpts, &
wann_control%use_ss_functional, m_matrix_loc, rnkb, print_output%timing_level, &
print_output%iprint, timer, nkrank, global_k, error, comm)
if (allocated(error)) return
irguide = 1
endif
! constrained centres part
lambda_loc = 0.0_dp
if (wann_control%constrain%selective_loc .and. wann_control%constrain%constrain) then
lambda_loc = wann_control%constrain%lambda
end if
! calculate initial centers and spread
call wann_omega(csheet, sheet, rave, r2ave, rave2, wann_spread, num_wann, kmesh_info, &
num_kpts, print_output, wann_control%use_ss_functional, wann_control%constrain, &
omega%invariant, ln_tmp_loc, m_matrix_loc, lambda_loc, first_pass, timer, &
nkrank, global_k, error, comm)
if (allocated(error)) return
! public variables
if (.not. wann_control%constrain%selective_loc) then
omega%total = wann_spread%om_tot
omega%invariant = wann_spread%om_i
omega%tilde = wann_spread%om_d + wann_spread%om_od
else
omega%total = wann_spread%om_tot
! omega_invariant = wann_spread%om_iod
! omega_tilde = wann_spread%om_d + wann_spread%om_nu
end if
! public arrays of Wannier centres and spreads
wannier_data%centres = rave
wannier_data%spreads = r2ave - rave2
if (wann_control%lfixstep) lquad = .false.
ncg = 0
iter = 0
old_spread%om_tot = 0.0_dp
! print initial state
if (print_output%iprint > 0) then
write (stdout, '(1x,a78)') repeat('-', 78)
write (stdout, '(1x,a)') 'Initial State'
do iw = 1, num_wann
write (stdout, 1000) iw, (rave(ind, iw)*print_output%lenconfac, ind=1, 3), &
(r2ave(iw) - rave2(iw))*print_output%lenconfac**2
end do
write (stdout, 1001) (sum(rave(ind, :))*print_output%lenconfac, ind=1, 3), &
(sum(r2ave) - sum(rave2))*print_output%lenconfac**2
write (stdout, *)
if (wann_control%constrain%selective_loc .and. wann_control%constrain%constrain) then
write (stdout, '(1x,i6,2x,E12.3,2x,F15.10,2x,F18.10,3x,F8.2,2x,a)') iter, &
(wann_spread%om_tot - old_spread%om_tot)*print_output%lenconfac**2, &
sqrt(abs(gcnorm1))*print_output%lenconfac, &
wann_spread%om_tot*print_output%lenconfac**2, io_wallclocktime(), '<-- CONV'
write (stdout, '(7x,a,F15.7,a,F15.7,a,F15.7,a,F15.7,a)') &
'O_D=', wann_spread%om_d*print_output%lenconfac**2, &
' O_IOD=', (wann_spread%om_iod + wann_spread%om_nu)*print_output%lenconfac**2, &
' O_TOT=', wann_spread%om_tot*print_output%lenconfac**2, ' <-- SPRD'
write (stdout, '(1x,a78)') repeat('-', 78)
elseif (wann_control%constrain%selective_loc .and. .not. wann_control%constrain%constrain) then
write (stdout, '(1x,i6,2x,E12.3,2x,F15.10,2x,F18.10,3x,F8.2,2x,a)') iter, &
(wann_spread%om_tot - old_spread%om_tot)*print_output%lenconfac**2, &
sqrt(abs(gcnorm1))*print_output%lenconfac, &
wann_spread%om_tot*print_output%lenconfac**2, io_wallclocktime(), '<-- CONV'
write (stdout, '(7x,a,F15.7,a,F15.7,a,F15.7,a)') &
'O_D=', wann_spread%om_d*print_output%lenconfac**2, &
' O_IOD=', wann_spread%om_iod*print_output%lenconfac**2, &
' O_TOT=', wann_spread%om_tot*print_output%lenconfac**2, ' <-- SPRD'
write (stdout, '(1x,a78)') repeat('-', 78)
else
write (stdout, '(1x,i6,2x,E12.3,2x,F15.10,2x,F18.10,3x,F8.2,2x,a)') iter, &
(wann_spread%om_tot - old_spread%om_tot)*print_output%lenconfac**2, &
sqrt(abs(gcnorm1))*print_output%lenconfac, &
wann_spread%om_tot*print_output%lenconfac**2, io_wallclocktime(), '<-- CONV'
write (stdout, '(8x,a,F15.7,a,F15.7,a,F15.7,a)') &
'O_D=', wann_spread%om_d*print_output%lenconfac**2, ' O_OD=', &
wann_spread%om_od*print_output%lenconfac**2, &
' O_TOT=', wann_spread%om_tot*print_output%lenconfac**2, ' <-- SPRD'
write (stdout, '(1x,a78)') repeat('-', 78)
end if
endif
lconverged = .false.
lfirst = .true.
lrandom = .false.
conv_count = 0
noise_count = 0
if (.not. wann_control%lfixstep .and. optimisation <= 0) then
open (newunit=page_unit, status='scratch', form='unformatted')
endif
! main iteration loop
do iter = 1, wann_control%num_iter
lprint = .false.
if ((mod(iter, wann_control%num_print_cycles) .eq. 0) .or. (iter .eq. 1) &
.or. (iter .eq. wann_control%num_iter)) lprint = .true.
ldump = .false.
if ((wann_control%num_dump_cycles .gt. 0) .and. &
(mod(iter, wann_control%num_dump_cycles) .eq. 0)) ldump = .true.
if (lprint .and. print_output%iprint > 0) write (stdout, '(1x,a,i6)') 'Cycle: ', iter
if (wann_control%guiding_centres%enable .and. &
(iter .gt. wann_control%guiding_centres%num_no_guide_iter) &
.and. (mod(iter, wann_control%guiding_centres%num_guide_cycles) .eq. 0)) then
call wann_phases(csheet, sheet, rguide, irguide, num_wann, kmesh_info, num_kpts, &
wann_control%use_ss_functional, m_matrix_loc, rnkb, print_output%timing_level, &
print_output%iprint, timer, nkrank, global_k, error, comm)
if (allocated(error)) return
irguide = 1
endif
! calculate gradient of omega
if (lsitesymmetry .or. wann_control%precond) then
call wann_domega(dist_k, csheet, sheet, rave, num_wann, kmesh_info, num_kpts, &
wann_control%constrain, wann_control%use_ss_functional, lsitesymmetry, &
ln_tmp_loc, m_matrix_loc, &
rnkb_loc, cdodq_loc, lambda_loc, print_output%timing_level, sitesym, &
timer, nkrank, global_k, error, comm, print_output%iprint, cdodq)
if (allocated(error)) return
else
call wann_domega(dist_k, csheet, sheet, rave, num_wann, kmesh_info, num_kpts, &
wann_control%constrain, wann_control%use_ss_functional, lsitesymmetry, &
ln_tmp_loc, m_matrix_loc, &
rnkb_loc, cdodq_loc, lambda_loc, print_output%timing_level, sitesym, &
timer, nkrank, global_k, error, comm, print_output%iprint)
if (allocated(error)) return
endif
if (lprint .and. print_output%iprint > 2) &
write (stdout, *) ' LINE --> Iteration :', iter
! calculate search direction (cdq)
if (wann_control%precond) then
call precond_search_direction(cdodq, cdodq_r, cdodq_precond, cdodq_precond_loc, k_to_r, &
wann_spread, num_wann, num_kpts, kpt_latt, real_lattice, &
nrpts, irvec, ndegen, optimisation, timer)
endif
call internal_search_direction(cdodq_precond_loc, cdqkeep_loc, iter, lprint, lrandom, &
noise_count, ncg, gcfac, gcnorm0, gcnorm1, doda0, &
wann_control, num_wann, kmesh_info%wbtot, cdq_loc, cdodq_loc, &
stdout, timer, error, comm)
if (allocated(error)) return
if (lsitesymmetry) then
call sitesym_symmetrize_gradient(sitesym, cdq, 2, num_kpts, num_wann, error, comm)
endif
! save search direction
cdqkeep_loc(:, :, :) = cdq_loc(:, :, :)
! check whether we're doing fixed step lengths
if (wann_control%lfixstep) then
alphamin = wann_control%fixed_step
! or a parabolic line search
else
! take trial step
cdq_loc(:, :, :) = cdqkeep_loc(:, :, :)*(wann_control%trial_step/(4.0_dp*kmesh_info%wbtot))
! store original U and M before rotating
u0_loc = u_matrix_loc
if (optimisation <= 0) then
write (page_unit) m_matrix_loc
rewind (page_unit)
else
m0_loc = m_matrix_loc
endif
! update U and M
call internal_new_u_and_m(cdq, cmtmp, tmp_cdq, cwork, rwork, evals, cwschur1, cwschur2, &
cwschur3, cwschur4, cz, num_wann, num_kpts, kmesh_info, &
lsitesymmetry, cdq_loc, u_matrix_loc, m_matrix_loc, &
print_output%timing_level, stdout, sitesym, timer, nkrank, &
global_k, error, comm)
if (allocated(error)) return
! calculate spread at trial step
call wann_omega(csheet, sheet, rave, r2ave, rave2, trial_spread, num_wann, kmesh_info, &
num_kpts, print_output, wann_control%use_ss_functional, wann_control%constrain, &
omega%invariant, ln_tmp_loc, m_matrix_loc, lambda_loc, first_pass, timer, &
nkrank, global_k, error, comm)
if (allocated(error)) return
! Calculate optimal step (alphamin)
call internal_optimal_step(wann_spread, trial_spread, doda0, alphamin, falphamin, lquad, &
lprint, wann_control%trial_step, stdout, timer)
endif
! print line search information
if (lprint .and. print_output%iprint > 2) then
write (stdout, *) ' LINE --> Spread at initial point :', &
wann_spread%om_tot*print_output%lenconfac**2
if (.not. wann_control%lfixstep) &
write (stdout, *) ' LINE --> Spread at trial step :', &
trial_spread%om_tot*print_output%lenconfac**2
write (stdout, *) ' LINE --> Slope along search direction :', &
doda0*print_output%lenconfac**2
write (stdout, *) ' LINE --> ||SD gradient||^2 :', &
gcnorm1*print_output%lenconfac**2
if (.not. wann_control%lfixstep) then
write (stdout, *) ' LINE --> Trial step length :', wann_control%trial_step
if (lquad) then
write (stdout, *) ' LINE --> Optimal parabolic step length :', alphamin
write (stdout, *) ' LINE --> Spread at predicted minimum :', &
falphamin*print_output%lenconfac**2
endif
else
write (stdout, *) ' LINE --> Fixed step length :', wann_control%fixed_step
endif
write (stdout, *) ' LINE --> CG coefficient :', gcfac
endif
! if taking a fixed step or if parabolic line search was successful
if (wann_control%lfixstep .or. lquad) then
! take optimal step
cdq_loc(:, :, :) = cdqkeep_loc(:, :, :)*(alphamin/(4.0_dp*kmesh_info%wbtot))
! if doing a line search then restore original U and M before rotating
if (.not. wann_control%lfixstep) then
u_matrix_loc = u0_loc
if (optimisation <= 0) then
read (page_unit) m_matrix_loc
rewind (page_unit)
else
m_matrix_loc = m0_loc
endif
endif
! update U and M
call internal_new_u_and_m(cdq, cmtmp, tmp_cdq, cwork, rwork, evals, cwschur1, cwschur2, &
cwschur3, cwschur4, cz, num_wann, num_kpts, kmesh_info, &
lsitesymmetry, cdq_loc, u_matrix_loc, m_matrix_loc, &
print_output%timing_level, stdout, sitesym, timer, nkrank, &
global_k, error, comm)
if (allocated(error)) return
call wann_spread_copy(wann_spread, old_spread)
! calculate the new centers and spread
call wann_omega(csheet, sheet, rave, r2ave, rave2, wann_spread, num_wann, kmesh_info, &
num_kpts, print_output, wann_control%use_ss_functional, wann_control%constrain, &
omega%invariant, ln_tmp_loc, m_matrix_loc, lambda_loc, first_pass, timer, &
nkrank, global_k, error, comm)
if (allocated(error)) return
! parabolic line search was unsuccessful, use trial step already taken
else
call wann_spread_copy(wann_spread, old_spread)
call wann_spread_copy(trial_spread, wann_spread)
endif
! print the new centers and spreads
if (lprint .and. print_output%iprint > 0) then
do iw = 1, num_wann
write (stdout, 1000) iw, (rave(ind, iw)*print_output%lenconfac, ind=1, 3), &
(r2ave(iw) - rave2(iw))*print_output%lenconfac**2
end do
write (stdout, 1001) (sum(rave(ind, :))*print_output%lenconfac, ind=1, 3), &
(sum(r2ave) - sum(rave2))*print_output%lenconfac**2
write (stdout, *)
if (wann_control%constrain%selective_loc .and. wann_control%constrain%constrain) then
write (stdout, '(1x,i6,2x,E12.3,2x,F15.10,2x,F18.10,3x,F8.2,2x,a)') &
iter, (wann_spread%om_tot - old_spread%om_tot)*print_output%lenconfac**2, &
sqrt(abs(gcnorm1))*print_output%lenconfac, &
wann_spread%om_tot*print_output%lenconfac**2, io_wallclocktime(), '<-- CONV'
write (stdout, '(7x,a,F15.7,a,F15.7,a,F15.7,a)') &
'O_IOD=', (wann_spread%om_iod + wann_spread%om_nu)*print_output%lenconfac**2, &
' O_D=', wann_spread%om_d*print_output%lenconfac**2, &
' O_TOT=', wann_spread%om_tot*print_output%lenconfac**2, ' <-- SPRD'
write (stdout, '(a,E15.7,a,E15.7,a,E15.7,a)') &
'Delta: O_IOD=', ((wann_spread%om_iod + wann_spread%om_nu) - &
(old_spread%om_iod + wann_spread%om_nu))*print_output%lenconfac**2, &
' O_D=', (wann_spread%om_d - old_spread%om_d)*print_output%lenconfac**2, &
' O_TOT=', (wann_spread%om_tot - old_spread%om_tot)*print_output%lenconfac**2, ' <-- DLTA'
write (stdout, '(1x,a78)') repeat('-', 78)
elseif (wann_control%constrain%selective_loc .and. .not. wann_control%constrain%constrain) then
write (stdout, '(1x,i6,2x,E12.3,2x,F15.10,2x,F18.10,3x,F8.2,2x,a)') &
iter, (wann_spread%om_tot - old_spread%om_tot)*print_output%lenconfac**2, &
sqrt(abs(gcnorm1))*print_output%lenconfac, &
wann_spread%om_tot*print_output%lenconfac**2, io_wallclocktime(), '<-- CONV'
write (stdout, '(7x,a,F15.7,a,F15.7,a,F15.7,a)') &
'O_IOD=', wann_spread%om_iod*print_output%lenconfac**2, &
' O_D=', wann_spread%om_d*print_output%lenconfac**2, &
' O_TOT=', wann_spread%om_tot*print_output%lenconfac**2, ' <-- SPRD'
write (stdout, '(a,E15.7,a,E15.7,a,E15.7,a)') &
'Delta: O_IOD=', (wann_spread%om_iod - old_spread%om_iod)*print_output%lenconfac**2, &
' O_D=', (wann_spread%om_d - old_spread%om_d)*print_output%lenconfac**2, &
' O_TOT=', (wann_spread%om_tot - old_spread%om_tot)*print_output%lenconfac**2, ' <-- DLTA'
write (stdout, '(1x,a78)') repeat('-', 78)
else
write (stdout, '(1x,i6,2x,E12.3,2x,F15.10,2x,F18.10,3x,F8.2,2x,a)') &
iter, (wann_spread%om_tot - old_spread%om_tot)*print_output%lenconfac**2, &
sqrt(abs(gcnorm1))*print_output%lenconfac, &
wann_spread%om_tot*print_output%lenconfac**2, io_wallclocktime(), '<-- CONV'
write (stdout, '(8x,a,F15.7,a,F15.7,a,F15.7,a)') &
'O_D=', wann_spread%om_d*print_output%lenconfac**2, &
' O_OD=', wann_spread%om_od*print_output%lenconfac**2, &
' O_TOT=', wann_spread%om_tot*print_output%lenconfac**2, ' <-- SPRD'
write (stdout, '(1x,a,E15.7,a,E15.7,a,E15.7,a)') &
'Delta: O_D=', (wann_spread%om_d - old_spread%om_d)*print_output%lenconfac**2, &
' O_OD=', (wann_spread%om_od - old_spread%om_od)*print_output%lenconfac**2, &
' O_TOT=', (wann_spread%om_tot - old_spread%om_tot)*print_output%lenconfac**2, ' <-- DLTA'
write (stdout, '(1x,a78)') repeat('-', 78)
end if
end if
! Public array of Wannier centres and spreads
wannier_data%centres = rave
wannier_data%spreads = r2ave - rave2
! Public variables
if (.not. wann_control%constrain%selective_loc) then
omega%total = wann_spread%om_tot
omega%tilde = wann_spread%om_d + wann_spread%om_od
else
omega%total = wann_spread%om_tot
!omega_tilde = wann_spread%om_d + wann_spread%om_nu
end if
!JJ if (ldump) then
!JJ ! Before calling w90_wannier90_readwrite_write_chkpt, I need to gather on the root node
!JJ ! the u_matrix from the u_matrix_loc. No need to broadcast it since
!JJ ! it's printed by the root node only
!JJ u_matrix(:, :, :) = 0.0_dp
!JJ m_matrix(:, :, :, :) = 0.0_dp
!JJ do nkp_loc = 1, nkrank
!JJ nkp = displs(my_node_id) + nkp_loc
!JJ u_matrix(:, :, nkp) = u_matrix_loc(:, :, nkp_loc)
!JJ m_matrix(:, :, :, nkp) = m_matrix_loc(:, :, :, nkp_loc)
!JJ enddo
!JJ
!JJ wwk = num_wann*num_wann*num_kpts
!JJ call comms_reduce(u_matrix(1, 1, 1), wwk, 'SUM', error, comm)
!JJ if (allocated(error)) return
!JJ call comms_reduce(m_matrix(1, 1, 1, 1), wwk*kmesh_info%nntot, 'SUM', error, comm)
!JJ if (allocated(error)) return
!JJ
!JJ if (on_root) then
!JJ call w90_wannier90_readwrite_write_chkpt('postdis', exclude_bands, wannier_data, &
!JJ kmesh_info, kpt_latt, num_kpts, dis_manifold, &
!JJ num_bands, num_wann, u_matrix, u_matrix_opt, &
!JJ m_matrix, mp_grid, real_lattice, &
!JJ omega%invariant, have_disentangled, stdout, &
!JJ seedname)
!JJ endif
!JJ endif
if (wann_control%conv_window .gt. 1) then
call internal_test_convergence(old_spread, wann_spread, history, save_spread, iter, &
conv_count, noise_count, lconverged, lrandom, lfirst, &
wann_control, error, comm)
if (allocated(error)) return
endif
if (lconverged) then
if (print_output%iprint > 0) then
write (stdout, '(/13x,a,es10.3,a,i2,a)') '<<< Delta <', wann_control%conv_tol, &
' over ', wann_control%conv_window, ' iterations >>>'
write (stdout, '(13x,a/)') '<<< Wannierisation convergence criteria satisfied >>>'
endif
exit
endif
enddo
! end of the minimization loop
! copy from local u matrix back to full matrix & reduce
u_matrix(:, :, :) = 0.0_dp
do nkp_loc = 1, nkrank
nkp = global_k(nkp_loc)
u_matrix(:, :, nkp) = u_matrix_loc(:, :, nkp_loc)
enddo
call comms_allreduce(u_matrix(1, 1, 1), num_wann*num_wann*num_kpts, 'SUM', error, comm)
if (allocated(error)) return
! Evaluate the penalty functional
if (wann_control%constrain%selective_loc .and. wann_control%constrain%constrain) then
rnr0n2 = 0.0_dp
do iw = 1, wann_control%constrain%slwf_num
rnr0n2(iw) = (wannier_data%centres(1, iw) - wann_control%constrain%centres(iw, 1))**2 &
+ (wannier_data%centres(2, iw) - wann_control%constrain%centres(iw, 2))**2 &
+ (wannier_data%centres(3, iw) - wann_control%constrain%centres(iw, 3))**2
end do
end if
if (print_output%iprint > 0) then
write (stdout, '(1x,a)') 'Final State'
do iw = 1, num_wann
write (stdout, 1000) iw, (rave(ind, iw)*print_output%lenconfac, ind=1, 3), &
(r2ave(iw) - rave2(iw))*print_output%lenconfac**2
end do
write (stdout, 1001) (sum(rave(ind, :))*print_output%lenconfac, ind=1, 3), &
(sum(r2ave) - sum(rave2))*print_output%lenconfac**2
write (stdout, *)
if (wann_control%constrain%selective_loc .and. wann_control%constrain%constrain) then
write (stdout, '(3x,a21,a,f15.9)') ' Spreads ('//trim(print_output%length_unit)//'^2)', &
' Omega IOD_C = ', (wann_spread%om_iod + wann_spread%om_nu)*print_output%lenconfac**2
write (stdout, '(3x,a,f15.9)') ' ================ Omega D = ', &
wann_spread%om_d*print_output%lenconfac**2
write (stdout, '(3x,a,f15.9)') ' Omega Rest = ', &
(sum(r2ave) - sum(rave2) + wann_spread%om_tot)*print_output%lenconfac**2
write (stdout, '(3x,a,f15.9)') ' Penalty func = ', &
sum(rnr0n2(:))
write (stdout, '(3x,a21,a,f15.9)') 'Final Spread ('//trim(print_output%length_unit)//'^2)', &
' Omega Total_C = ', wann_spread%om_tot*print_output%lenconfac**2
write (stdout, '(1x,a78)') repeat('-', 78)
else if (wann_control%constrain%selective_loc .and. .not. wann_control%constrain%constrain) then
write (stdout, '(3x,a21,a,f15.9)') ' Spreads ('//trim(print_output%length_unit)//'^2)', &
' Omega IOD = ', wann_spread%om_iod*print_output%lenconfac**2
write (stdout, '(3x,a,f15.9)') ' ================ Omega D = ', &
wann_spread%om_d*print_output%lenconfac**2
write (stdout, '(3x,a,f15.9)') ' Omega Rest = ', &
(sum(r2ave) - sum(rave2) + wann_spread%om_tot)*print_output%lenconfac**2
write (stdout, '(3x,a21,a,f15.9)') 'Final Spread ('//trim(print_output%length_unit)//'^2)', &
' Omega Total = ', wann_spread%om_tot*print_output%lenconfac**2
write (stdout, '(1x,a78)') repeat('-', 78)
else
write (stdout, '(3x,a21,a,f15.9)') ' Spreads ('//trim(print_output%length_unit)//'^2)', &
' Omega I = ', wann_spread%om_i*print_output%lenconfac**2
write (stdout, '(3x,a,f15.9)') ' ================ Omega D = ', &
wann_spread%om_d*print_output%lenconfac**2
write (stdout, '(3x,a,f15.9)') ' Omega OD = ', &
wann_spread%om_od*print_output%lenconfac**2
write (stdout, '(3x,a21,a,f15.9)') 'Final Spread ('//trim(print_output%length_unit)//'^2)', &
' Omega Total = ', wann_spread%om_tot*print_output%lenconfac**2
write (stdout, '(1x,a78)') repeat('-', 78)
end if
endif
if (wann_control%guiding_centres%enable) then
call wann_phases(csheet, sheet, rguide, irguide, num_wann, kmesh_info, num_kpts, &
wann_control%use_ss_functional, m_matrix_loc, rnkb, print_output%timing_level, &
print_output%iprint, timer, nkrank, global_k, error, comm)
if (allocated(error)) return
endif
! check unitarity of u
call wann_check_unitarity(num_kpts, num_wann, u_matrix, print_output%timing_level, &
print_output%iprint, stdout, timer, error, comm)
if (allocated(error)) return
! deallocate sub vars not passed into other subs
deallocate (rwork, stat=ierr)
if (ierr /= 0) then
call set_error_dealloc(error, 'Error in deallocating rwork in wann_main', comm)
return
endif
deallocate (cwork, stat=ierr)
if (ierr /= 0) then
call set_error_dealloc(error, 'Error in deallocating cwork in wann_main', comm)
return
endif
deallocate (evals, stat=ierr)
if (ierr /= 0) then
call set_error_dealloc(error, 'Error in deallocating evals in wann_main', comm)
return
endif
deallocate (tmp_cdq, stat=ierr)
if (ierr /= 0) then
call set_error_dealloc(error, 'Error in deallocating tmp_cdq in wann_main', comm)
return
endif
deallocate (cmtmp, stat=ierr)
if (ierr /= 0) then
call set_error_dealloc(error, 'Error in deallocating cmtmp in wann_main', comm)
return
endif
deallocate (cz, stat=ierr)
if (ierr /= 0) then
call set_error_dealloc(error, 'Error in deallocating cz in wann_main', comm)
return
endif
deallocate (cdq, stat=ierr)
if (ierr /= 0) then
call set_error_dealloc(error, 'Error in deallocating cdq in wann_main', comm)
return
endif
deallocate (ln_tmp_loc, stat=ierr)
if (ierr /= 0) then
call set_error_dealloc(error, 'Error in deallocating ln_tmp_loc in wann_main', comm)
return
endif
deallocate (rnkb_loc, stat=ierr)
if (ierr /= 0) then
call set_error_dealloc(error, 'Error in deallocating rnkb_loc in wann_main', comm)
return
endif
deallocate (u_matrix_loc, stat=ierr)
if (ierr /= 0) then
call set_error_dealloc(error, 'Error in deallocating u_matrix_loc in wann_main', comm)
return
endif
deallocate (cdq_loc, stat=ierr)
if (ierr /= 0) then
call set_error_dealloc(error, 'Error in deallocating cdq_loc in wann_main', comm)
return
endif
deallocate (cdodq_loc, stat=ierr)
if (ierr /= 0) then
call set_error_dealloc(error, 'Error in deallocating cdodq_loc in wann_main', comm)
return
endif
deallocate (cdqkeep_loc, stat=ierr)
if (ierr /= 0) then
call set_error_dealloc(error, 'Error in deallocating cdqkeep_loc in wann_main', comm)
return
endif
deallocate (cwschur3, stat=ierr)
if (ierr /= 0) then
call set_error_dealloc(error, 'Error in deallocating cwschur3 in wann_main', comm)
return
endif
deallocate (cwschur1, stat=ierr)
if (ierr /= 0) then
call set_error_dealloc(error, 'Error in deallocating cwschur1 in wann_main', comm)
return
endif
if (wann_control%precond) then
if (optimisation >= 3) then
deallocate (k_to_r, stat=ierr)
if (ierr /= 0) then
call set_error_dealloc(error, 'Error in deallocating k_to_r in wann_main', comm)
return
endif
end if
deallocate (cdodq_r, stat=ierr)
if (ierr /= 0) then
call set_error_dealloc(error, 'Error in deallocating cdodq_r in wann_main', comm)
return
endif
deallocate (cdodq_precond, stat=ierr)
if (ierr /= 0) then
call set_error_dealloc(error, 'Error in deallocating cdodq_precond in wann_main', comm)
return
endif
deallocate (cdodq_precond_loc, stat=ierr)
if (ierr /= 0) then
call set_error_dealloc(error, 'Error in deallocating cdodq_precond_loc in wann_main', comm)
return
endif
end if
! deallocate sub vars passed into other subs
deallocate (rguide, stat=ierr)
if (ierr /= 0) then
call set_error_dealloc(error, 'Error in deallocating rguide in wann_main', comm)