-
Notifications
You must be signed in to change notification settings - Fork 0
/
m_pawcprj.F90
2949 lines (2580 loc) · 85.7 KB
/
m_pawcprj.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
!!****m* abinit/m_pawcprj
!! NAME
!! m_pawcprj
!!
!! FUNCTION
!! This module contains functions used to manipulate variables of
!! structured datatype pawcprj_type.
!! pawcprj_type variables are <p_lmn|Cnk> projected quantities,
!! where |p_lmn> are non-local projectors
!! |Cnk> are wave functions
!!
!! COPYRIGHT
!! Copyright (C) 2012-2022 ABINIT group (MT,JWZ)
!! This file is distributed under the terms of the
!! GNU General Public License, see ~abinit/COPYING
!! or http://www.gnu.org/copyleft/gpl.txt .
!!
!! NOTES
!! FOR DEVELOPPERS: in order to preserve the portability of libPAW library,
!! please consult ~abinit/src/??_libpaw/libpaw-coding-rules.txt
!!
!! SOURCE
#include "libpaw.h"
module m_pawcprj
USE_DEFS
USE_MSG_HANDLING
USE_MPI_WRAPPERS
USE_MEMORY_PROFILING
use m_pawtab, only : pawtab_type
implicit none
private
!!***
!!****t* m_pawcprj/pawcprj_type
!! NAME
!! pawcprj_type
!!
!! FUNCTION
!! This structured datatype contains <p_lmn|Cnk> projected scalars and derivatives
!! where |p_lmn> are non-local projectors for a given atom
!! |Cnk> is a wave function
!! Used only for PAW calculations.
!!
!! SOURCE
type,public :: pawcprj_type
!Integer scalars
integer :: ncpgr=0
! Number of gradients of cp=<p_lmn|Cnk>
integer :: nlmn=0
! Number of (l,m,n) non-local projectors
!Real (real(dp)) arrays
real(dp), allocatable :: cp (:,:)
! cp(2,nlmn)
! <p_lmn|Cnk> projected scalars for a given atom and wave function
real(dp), allocatable :: dcp (:,:,:)
! dcp(2,ncpgr,nlmn)
! derivatives of <p_lmn|Cnk> projected scalars for a given atom and wave function
end type pawcprj_type
!public procedures.
public :: pawcprj_alloc ! Allocation
public :: pawcprj_free ! Deallocation
public :: pawcprj_set_zero ! Set to zero all arrays in a cprj datastructure
public :: pawcprj_copy ! Copy a cprj datastructure into another
public :: pawcprj_axpby ! cprjy(:,:) <- alpha.cprjx(:,:)+beta.cprjy(:,:)
public :: pawcprj_zaxpby ! cprjy(:,:) <- alpha.cprjx(:,:)+beta.cprjy(:,:), alpha and beta are COMPLEX scalars
public :: pawcprj_projbd ! cprjy(:,:) <- alpha.cprjx(:,:)+beta.cprjy(:,:), alpha and beta are COMPLEX scalars
public :: pawcprj_conjg ! cprj(:,:) <- conjugate(cprj(:,:))
public :: pawcprj_symkn ! construct cprj from that at a symmetry related k point
public :: pawcprj_lincom ! Compute a LINear COMbination of cprj datastructure:
public :: pawcprj_output ! Output a cprj. Useful for debugging.
public :: pawcprj_get ! Read the cprj for a given k-point from memory or from a temporary file
public :: pawcprj_put ! Write the cprj for a given set of (n,k) into memory or into a temporary file
public :: pawcprj_reorder ! Change the order of a cprj datastructure
public :: pawcprj_mpi_allgather ! Perform MPI_ALLGATHER on a pawcprj_type inside a MPI communicator.
public :: pawcprj_bcast ! Broadcast a pawcprj_type from master to all nodes inside a MPI communicator.
public :: pawcprj_transpose ! Transpose a cprj datastructure FOR A GIVEN (K,SPIN)
public :: pawcprj_gather_spin ! Collect spin distributed cprjs.
public :: pawcprj_mpi_exch ! Exchange a pawcprj_type between two processors inside a MPI communicator.
public :: pawcprj_mpi_send ! Send a pawcprj_type inside a MPI communicator.
public :: pawcprj_mpi_recv ! Receive a pawcprj_type inside a MPI communicator.
public :: pawcprj_mpi_sum ! Perform MPI_SUM on a pawcprj_type inside a MPI communicator.
public :: pawcprj_getdim ! Returns the number of lmn components in the <p_{lmn}^i|\psi> for the i-th atom.
public :: paw_overlap ! Compute the onsite contribution to the overlap between two states.
public :: pawcprj_pack ! Copy data from a cprj to a simple real buffer
public :: pawcprj_unpack ! Copy data from a simple real buffer to a cprj
!!***
CONTAINS
!===========================================================
!!***
!!****f* m_pawcprj/pawcprj_alloc
!! NAME
!! pawcprj_alloc
!!
!! FUNCTION
!! Allocation of a cprj datastructure
!!
!! INPUTS
!! ncpgr=number of gradients to be allocated
!! nlmn(:)=sizes of cprj%cp
!!
!! SIDE EFFECTS
!! cprj(:,:) <type(pawcprj_type)>= cprj datastructure
!!
!! SOURCE
subroutine pawcprj_alloc(cprj,ncpgr,nlmn)
!Arguments ------------------------------------
!scalars
integer,intent(in) :: ncpgr
!arrays
integer,intent(in) :: nlmn(:)
type(pawcprj_type),intent(inout) :: cprj(:,:)
!Local variables-------------------------------
!scalars
integer :: ii,jj,n1dim,n2dim,nn
character(len=500) :: msg
! *************************************************************************
n1dim=size(cprj,dim=1);n2dim=size(cprj,dim=2);nn=size(nlmn,dim=1)
if (nn/=n1dim) then
write(msg,*) 'wrong sizes (pawcprj_alloc)! :',nn,n1dim
LIBPAW_ERROR(msg)
end if
do jj=1,n2dim
do ii=1,n1dim
if (allocated(cprj(ii,jj)%cp)) then
LIBPAW_DEALLOCATE(cprj(ii,jj)%cp)
end if
if (allocated(cprj(ii,jj)%dcp)) then
LIBPAW_DEALLOCATE(cprj(ii,jj)%dcp)
end if
nn=nlmn(ii)
cprj(ii,jj)%nlmn=nn
LIBPAW_ALLOCATE(cprj(ii,jj)%cp,(2,nn))
cprj(ii,jj)%cp=zero
cprj(ii,jj)%ncpgr=ncpgr
if (ncpgr>0) then
LIBPAW_ALLOCATE(cprj(ii,jj)%dcp,(2,ncpgr,nn))
cprj(ii,jj)%dcp=zero
end if
end do
end do
end subroutine pawcprj_alloc
!!***
!----------------------------------------------------------------------
!!****f* m_pawcprj/pawcprj_free
!! NAME
!! pawcprj_free
!!
!! FUNCTION
!! Deallocation of a cprj datastructure
!!
!! SIDE EFFECTS
!! cprj(:,:) <type(pawcprj_type)>= cprj datastructure
!!
!! SOURCE
subroutine pawcprj_free(cprj)
!Arguments ------------------------------------
!scalars
!arrays
type(pawcprj_type),intent(inout) :: cprj(:,:)
!Local variables-------------------------------
!scalars
integer :: ii,jj,n1dim,n2dim
! *************************************************************************
n1dim=size(cprj,dim=1);n2dim=size(cprj,dim=2)
do jj=1,n2dim
do ii=1,n1dim
if (allocated(cprj(ii,jj)%cp)) then
LIBPAW_DEALLOCATE(cprj(ii,jj)%cp)
end if
if (allocated(cprj(ii,jj)%dcp)) then
LIBPAW_DEALLOCATE(cprj(ii,jj)%dcp)
end if
end do
end do
end subroutine pawcprj_free
!!***
!----------------------------------------------------------------------
!! m_scf_history,suscep_stat
!!****f* m_pawcprj/pawcprj_set_zero
!! NAME
!! pawcprj_set_zero
!!
!! FUNCTION
!! Set to zero all arrays in a cprj datastructure
!!
!! SIDE EFFECTS
!! cprj(:,:) <type(pawcprj_type)>= cprj datastructure
!!
!! SOURCE
subroutine pawcprj_set_zero(cprj)
!Arguments ------------------------------------
!scalars
!arrays
type(pawcprj_type),intent(inout) :: cprj(:,:)
!Local variables-------------------------------
!scalars
integer :: ii,jj,n1dim,n2dim
! *************************************************************************
n1dim=size(cprj,dim=1);n2dim=size(cprj,dim=2)
do jj=1,n2dim
do ii=1,n1dim
if (cprj(ii,jj)%nlmn>0) cprj(ii,jj)%cp(:,:)=zero
if (cprj(ii,jj)%ncpgr>0) cprj(ii,jj)%dcp(:,:,:)=zero
end do
end do
end subroutine pawcprj_set_zero
!!***
!----------------------------------------------------------------------
!!****f* m_pawcprj/pawcprj_copy
!! NAME
!! pawcprj_copy
!!
!! FUNCTION
!! Copy a cprj datastructure into another
!!
!! INPUTS
!! icpgr= (optional argument) if present, only component icpgr of
!! input cprj gradient is copied into output cprj
!! Not used if cprj(:,:)%ncpgr<icpgr
!! -1 only copy cp
!! cprj_in(:,:) <type(pawcprj_type)>= input cprj datastructure
!!
!! OUTPUT
!! cprj_out(:,:) <type(pawcprj_type)>= output cprj datastructure
!!
!! NOTES
!! MG: What about an option to report a pointer to cprj_in?
!!
!! SOURCE
subroutine pawcprj_copy(cprj_in,cprj_out,&
& icpgr) ! optional argument
!Arguments ------------------------------------
!scalars
integer,intent(in),optional :: icpgr
!arrays
type(pawcprj_type),intent(in) :: cprj_in(:,:)
type(pawcprj_type),intent(inout) :: cprj_out(:,:)
!Local variables-------------------------------
!scalars
integer :: ii,jj,kk,n1dim_in,n1dim_out,n2dim_in,n2dim_out,ncpgr_in,ncpgr_out,nlmn
logical :: has_icpgr,copy_dcp
character(len=500) :: msg
! *************************************************************************
n1dim_in=size(cprj_in,dim=1); n1dim_out=size(cprj_out,dim=1)
n2dim_in=size(cprj_in,dim=2); n2dim_out=size(cprj_out,dim=2)
ncpgr_in=cprj_in(1,1)%ncpgr; ncpgr_out=cprj_out(1,1)%ncpgr
if (n1dim_in/=n1dim_out) then
write(msg,'(a,2(1x,i0))')" Error in pawcprj_copy: n1 wrong sizes ",n1dim_in,n1dim_out
LIBPAW_ERROR(msg)
end if
if (n2dim_in/=n2dim_out) then
write(msg,'(a,2(1x,i0))')" Error in pawcprj_copy: n2 wrong sizes ",n2dim_in,n2dim_out
LIBPAW_ERROR(msg)
end if
if (ncpgr_in<ncpgr_out) then
write(msg,'(a,2(1x,i0))')" Error in pawcprj_copy: ncpgr wrong sizes ",ncpgr_in,ncpgr_out
LIBPAW_ERROR(msg)
end if
!Check if icgr is present and if dcp have to be copy
has_icpgr=present(icpgr)
copy_dcp = .TRUE.
if(has_icpgr)then
copy_dcp = icpgr>=0
end if
do jj=1,n2dim_in
do ii=1,n1dim_in
nlmn=cprj_in(ii,jj)%nlmn
cprj_out(ii,jj)%nlmn =nlmn
do kk=1,nlmn
cprj_out(ii,jj)%cp(1:2,kk)=cprj_in(ii,jj)%cp(1:2,kk)
end do
end do
end do
if (ncpgr_in>0.and.copy_dcp) then
if (has_icpgr) has_icpgr=(ncpgr_out>0.and.icpgr>0.or.icpgr<=ncpgr_in)
if (has_icpgr) then
do jj=1,n2dim_in
do ii=1,n1dim_in
nlmn=cprj_in(ii,jj)%nlmn
do kk=1,nlmn
cprj_out(ii,jj)%dcp(1:2,1,kk)=cprj_in(ii,jj)%dcp(1:2,icpgr,kk)
end do
end do
end do
else
if (ncpgr_out>=ncpgr_in) then
do jj=1,n2dim_in
do ii=1,n1dim_in
nlmn=cprj_in(ii,jj)%nlmn
do kk=1,nlmn
cprj_out(ii,jj)%dcp(1:2,1:ncpgr_in,kk)=cprj_in(ii,jj)%dcp(1:2,1:ncpgr_in,kk)
end do
end do
end do
end if
end if
end if
end subroutine pawcprj_copy
!!***
!----------------------------------------------------------------------
!!****f* m_pawcprj/pawcprj_axpby
!! NAME
!! pawcprj_axpby
!!
!! FUNCTION
!! Apply AXPBY (blas-like) operation with 2 cprj datastructures:
!! cprjy(:,:) <- alpha.cprjx(:,:)+beta.cprjy(:,:)
!! alpha and beta are REAL scalars
!!
!! INPUTS
!! alpha,beta= alpha,beta REAL factors
!! cprjx(:,:) <type(pawcprj_type)>= input cprjx datastructure
!!
!! SIDE EFFECTS
!! cprjy(:,:) <type(pawcprj_type)>= input/output cprjy datastructure
!!
!! SOURCE
subroutine pawcprj_axpby(alpha,beta,cprjx,cprjy)
!Arguments ------------------------------------
!scalars
real(dp),intent(in) :: alpha,beta
!arrays
type(pawcprj_type),intent(in) :: cprjx(:,:)
type(pawcprj_type),intent(inout) :: cprjy(:,:)
!Local variables-------------------------------
!scalars
integer :: ii,jj,kk,n1dimx,n1dimy,n2dimx,n2dimy,ncpgrx,ncpgry,nlmn
character(len=500) :: msg
! *************************************************************************
n1dimy=size(cprjy,dim=1);n2dimy=size(cprjy,dim=2);ncpgry=cprjy(1,1)%ncpgr
if (abs(alpha)>tol16) then
n1dimx=size(cprjx,dim=1);n2dimx=size(cprjx,dim=2);ncpgrx=cprjx(1,1)%ncpgr
msg = ""
if (n1dimx/=n1dimy) msg = TRIM(msg)//"Error in pawcprj_axpby: n1 wrong sizes !"//ch10
if (n2dimx/=n2dimy) msg = TRIM(msg)//"Error in pawcprj_axpby: n2 wrong sizes !"//ch10
if (ncpgrx/=ncpgry) msg = TRIM(msg)//"Error in pawcprj_axpby: ncpgr wrong sizes !"//ch10
if (LEN_TRIM(msg) > 0) then
LIBPAW_ERROR(msg)
end if
else
n1dimx=0;n2dimx=0;ncpgrx=0
end if
if (abs(alpha)<=tol16) then
do jj=1,n2dimy
do ii=1,n1dimy
nlmn=cprjy(ii,jj)%nlmn
do kk=1,nlmn
cprjy(ii,jj)%cp(1:2,kk)=beta*cprjy(ii,jj)%cp(1:2,kk)
end do
end do
end do
if (ncpgry>0) then
do jj=1,n2dimy
do ii=1,n1dimy
nlmn=cprjy(ii,jj)%nlmn
do kk=1,nlmn
cprjy(ii,jj)%dcp(1:2,1:ncpgry,kk)=beta*cprjy(ii,jj)%dcp(1:2,1:ncpgry,kk)
end do
end do
end do
end if
else if (abs(beta)<=tol16) then
do jj=1,n2dimx
do ii=1,n1dimx
nlmn=cprjx(ii,jj)%nlmn
cprjy(ii,jj)%nlmn=nlmn
do kk=1,nlmn
cprjy(ii,jj)%cp(1:2,kk)=alpha*cprjx(ii,jj)%cp(1:2,kk)
end do
end do
end do
if (ncpgrx>0) then
do jj=1,n2dimx
do ii=1,n1dimx
nlmn=cprjx(ii,jj)%nlmn
do kk=1,nlmn
cprjy(ii,jj)%dcp(1:2,1:ncpgrx,kk)=alpha*cprjx(ii,jj)%dcp(1:2,1:ncpgrx,kk)
end do
end do
end do
end if
else ! alpha/=0 and beta/=0
do jj=1,n2dimx
do ii=1,n1dimx
nlmn=cprjx(ii,jj)%nlmn
cprjy(ii,jj)%nlmn=nlmn
do kk=1,nlmn
cprjy(ii,jj)%cp(1:2,kk)=alpha*cprjx(ii,jj)%cp(1:2,kk) &
& +beta *cprjy(ii,jj)%cp(1:2,kk)
end do
end do
end do
if (ncpgrx>0) then
do jj=1,n2dimx
do ii=1,n1dimx
nlmn=cprjx(ii,jj)%nlmn
do kk=1,nlmn
cprjy(ii,jj)%dcp(1:2,1:ncpgrx,kk)=alpha*cprjx(ii,jj)%dcp(1:2,1:ncpgrx,kk) &
& +beta *cprjy(ii,jj)%dcp(1:2,1:ncpgrx,kk)
end do
end do
end do
end if
end if
end subroutine pawcprj_axpby
!!***
!----------------------------------------------------------------------
!!****f* m_pawcprj/pawcprj_zaxpby
!! NAME
!! pawcprj_zaxpby
!!
!! FUNCTION
!! Apply ZAXPBY (blas-like) operation with 2 cprj datastructures:
!! cprjy(:,:) <- alpha.cprjx(:,:)+beta.cprjy(:,:)
!! alpha and beta are COMPLEX scalars
!!
!! INPUTS
!! alpha(2),beta(2)= alpha,beta COMPLEX factors
!! cprjx(:,:) <type(pawcprj_type)>= input cprjx datastructure
!!
!! SIDE EFFECTS
!! cprjy(:,:) <type(pawcprj_type)>= input/output cprjy datastructure
!!
!! SOURCE
subroutine pawcprj_zaxpby(alpha,beta,cprjx,cprjy)
!Arguments ------------------------------------
!scalars
real(dp),intent(in) :: alpha(2),beta(2)
!arrays
type(pawcprj_type),intent(in) :: cprjx(:,:)
type(pawcprj_type),intent(inout) :: cprjy(:,:)
!Local variables-------------------------------
!scalars
integer :: ii,jj,kk,ll,n1dimx,n1dimy,n2dimx,n2dimy,ncpgrx,ncpgry,nlmn
real(dp) :: cp1,cp2,norma,normb
character(len=500) :: msg
! *************************************************************************
norma=alpha(1)**2+alpha(2)**2
normb=beta(1) **2+beta(2) **2
n1dimy=size(cprjy,dim=1);n2dimy=size(cprjy,dim=2);ncpgry=cprjy(1,1)%ncpgr
if (norma>tol16*tol16) then
n1dimx=size(cprjx,dim=1);n2dimx=size(cprjx,dim=2);ncpgrx=cprjx(1,1)%ncpgr
msg = ""
if (n1dimx/=n1dimy) msg = TRIM(msg)//"Error in pawcprj_zaxpby: n1 wrong sizes !"//ch10
if (n2dimx/=n2dimy) msg = TRIM(msg)//"Error in pawcprj_zaxpby: n2 wrong sizes !"//ch10
if (ncpgrx/=ncpgry) msg = TRIM(msg)//"Error in pawcprj_zaxpby: ncpgr wrong sizes !"//ch10
if (LEN_TRIM(msg) > 0) then
LIBPAW_ERROR(msg)
end if
end if
if (norma<=tol16*tol16) then
do jj=1,n2dimy
do ii=1,n1dimy
nlmn=cprjy(ii,jj)%nlmn
do kk=1,nlmn
cp1=beta(1)*cprjy(ii,jj)%cp(1,kk)-beta(2)*cprjy(ii,jj)%cp(2,kk)
cp2=beta(1)*cprjy(ii,jj)%cp(2,kk)+beta(2)*cprjy(ii,jj)%cp(1,kk)
cprjy(ii,jj)%cp(1,kk)=cp1
cprjy(ii,jj)%cp(2,kk)=cp2
end do
end do
end do
if (ncpgry>0) then
do jj=1,n2dimy
do ii=1,n1dimy
nlmn=cprjy(ii,jj)%nlmn
do kk=1,nlmn
do ll=1,ncpgry
cp1=beta(1)*cprjy(ii,jj)%dcp(1,ll,kk)-beta(2)*cprjy(ii,jj)%dcp(2,ll,kk)
cp2=beta(1)*cprjy(ii,jj)%dcp(2,ll,kk)+beta(2)*cprjy(ii,jj)%dcp(1,ll,kk)
cprjy(ii,jj)%dcp(1,ll,kk)=cp1
cprjy(ii,jj)%dcp(2,ll,kk)=cp2
end do
end do
end do
end do
end if
else if (normb<=tol16*tol16) then
do jj=1,n2dimx
do ii=1,n1dimx
nlmn=cprjx(ii,jj)%nlmn
cprjy(ii,jj)%nlmn=nlmn
do kk=1,nlmn
cprjy(ii,jj)%cp(1,kk)=alpha(1)*cprjx(ii,jj)%cp(1,kk)-alpha(2)*cprjx(ii,jj)%cp(2,kk)
cprjy(ii,jj)%cp(2,kk)=alpha(1)*cprjx(ii,jj)%cp(2,kk)+alpha(2)*cprjx(ii,jj)%cp(1,kk)
end do
end do
end do
if (ncpgrx>0) then
do jj=1,n2dimx
do ii=1,n1dimx
nlmn=cprjx(ii,jj)%nlmn
do kk=1,nlmn
cprjy(ii,jj)%dcp(1,1:ncpgrx,kk)=alpha(1)*cprjx(ii,jj)%dcp(1,1:ncpgrx,kk) &
& -alpha(2)*cprjx(ii,jj)%dcp(2,1:ncpgrx,kk)
cprjy(ii,jj)%dcp(2,1:ncpgrx,kk)=alpha(1)*cprjx(ii,jj)%dcp(2,1:ncpgrx,kk) &
& +alpha(2)*cprjx(ii,jj)%dcp(1,1:ncpgrx,kk)
end do
end do
end do
end if
! else if (abs(beta(1)-one)<tol16.and.abs(beta(2))<tol16) then
! do jj=1,n2dimx
! do ii=1,n1dimx
! nlmn=cprjx(ii,jj)%nlmn
! cprjy(ii,jj)%nlmn =nlmn
! do kk=1,nlmn
! cp1=cprjy(ii,jj)%cp(1,kk)
! cp2=cprjy(ii,jj)%cp(2,kk)
! cp1=cp1+alpha(1)*cprjx(ii,jj)%cp(1,kk)-alpha(2)*cprjx(ii,jj)%cp(2,kk)
! cp2=cp2+alpha(1)*cprjx(ii,jj)%cp(2,kk)+alpha(2)*cprjx(ii,jj)%cp(1,kk)
! cprjy(ii,jj)%cp(1,kk)=cp1
! cprjy(ii,jj)%cp(2,kk)=cp2
! end do
! end do
! end do
! if (ncpgrx>0) then
! do jj=1,n2dimx
! do ii=1,n1dimx
! nlmn=cprjx(ii,jj)%nlmn
! do kk=1,nlmn
! do ll=1,ncpgrx
! cp1=cprjy(ii,jj)%dcp(1,ll,kk)
! cp2=cprjy(ii,jj)%dcp(2,ll,kk)
! cp1=cp1+alpha(1)*cprjx(ii,jj)%dcp(1,ll,kk)-alpha(2)*cprjx(ii,jj)%dcp(2,ll,kk)
! cp2=cp2+alpha(1)*cprjx(ii,jj)%dcp(2,ll,kk)+alpha(2)*cprjx(ii,jj)%dcp(1,ll,kk)
! cprjy(ii,jj)%dcp(1,ll,kk)=cp1
! cprjy(ii,jj)%dcp(2,ll,kk)=cp2
! end do
! end do
! end do
! end do
! end if
else
do jj=1,n2dimx
do ii=1,n1dimx
nlmn=cprjx(ii,jj)%nlmn
cprjy(ii,jj)%nlmn =nlmn
do kk=1,nlmn
cp1=alpha(1)*cprjx(ii,jj)%cp(1,kk)-alpha(2)*cprjx(ii,jj)%cp(2,kk) &
& +beta(1) *cprjy(ii,jj)%cp(1,kk)-beta(2) *cprjy(ii,jj)%cp(2,kk)
cp2=alpha(1)*cprjx(ii,jj)%cp(2,kk)+alpha(2)*cprjx(ii,jj)%cp(1,kk) &
& +beta(1) *cprjy(ii,jj)%cp(2,kk)+beta(2) *cprjy(ii,jj)%cp(1,kk)
! cp1=beta(1) *cprjy(ii,jj)%cp(1,kk)-beta(2) *cprjy(ii,jj)%cp(2,kk)
! cp1=cp1+alpha(1)*cprjx(ii,jj)%cp(1,kk)-alpha(2)*cprjx(ii,jj)%cp(2,kk)
! cp2=beta(1) *cprjy(ii,jj)%cp(2,kk)+beta(2) *cprjy(ii,jj)%cp(1,kk)
! cp2=cp2+alpha(1)*cprjx(ii,jj)%cp(2,kk)+alpha(2)*cprjx(ii,jj)%cp(1,kk)
cprjy(ii,jj)%cp(1,kk)=cp1
cprjy(ii,jj)%cp(2,kk)=cp2
end do
end do
end do
if (ncpgrx>0) then
do jj=1,n2dimx
do ii=1,n1dimx
nlmn=cprjx(ii,jj)%nlmn
do kk=1,nlmn
do ll=1,ncpgrx
cp1=alpha(1)*cprjx(ii,jj)%dcp(1,ll,kk)-alpha(2)*cprjx(ii,jj)%dcp(2,ll,kk) &
& +beta(1) *cprjy(ii,jj)%dcp(1,ll,kk)-beta(2) *cprjy(ii,jj)%dcp(2,ll,kk)
cp2=alpha(1)*cprjx(ii,jj)%dcp(2,ll,kk)+alpha(2)*cprjx(ii,jj)%dcp(1,ll,kk) &
& +beta(1) *cprjy(ii,jj)%dcp(2,ll,kk)+beta(2) *cprjy(ii,jj)%dcp(1,ll,kk)
! cp1=beta(1) *cprjy(ii,jj)%dcp(1,ll,kk)-beta(2) *cprjy(ii,jj)%dcp(2,ll,kk)
! cp1=cp1+alpha(1)*cprjx(ii,jj)%dcp(1,ll,kk)-alpha(2)*cprjx(ii,jj)%dcp(2,ll,kk)
! cp2=beta(1) *cprjy(ii,jj)%dcp(2,ll,kk)+beta(2) *cprjy(ii,jj)%dcp(1,ll,kk)
! cp2=cp2+alpha(1)*cprjx(ii,jj)%dcp(2,ll,kk)+alpha(2)*cprjx(ii,jj)%dcp(1,ll,kk)
cprjy(ii,jj)%dcp(1,ll,kk)=cp1
cprjy(ii,jj)%dcp(2,ll,kk)=cp2
end do
end do
end do
end do
end if
end if
end subroutine pawcprj_zaxpby
!!***
!----------------------------------------------------------------------
!!****f* m_pawcprj/pawcprj_projbd
!! NAME
!! pawcprj_projbd
!!
!! FUNCTION
!! Apply ZAXPBY (blas-like) operation with 2 cprj datastructures:
!! cprjy(:,:) <- alpha.cprjx(:,:)+beta.cprjy(:,:)
!! alpha and beta are COMPLEX scalars
!!
!! INPUTS
!! alpha(2),beta(2)= alpha,beta COMPLEX factors
!! cprjx(:,:) <type(pawcprj_type)>= input cprjx datastructure
!!
!! SIDE EFFECTS
!! cprjy(:,:) <type(pawcprj_type)>= input/output cprjy datastructure
!!
!! SOURCE
subroutine pawcprj_projbd(alpha,cprjx,cprjy)
!Arguments ------------------------------------
!scalars
real(dp),intent(in) :: alpha(:,:)
!arrays
type(pawcprj_type),intent(in) :: cprjx(:,:)
type(pawcprj_type),intent(inout) :: cprjy(:,:)
!Local variables-------------------------------
!scalars
integer :: ia,ii,jj,kk,ll,n1dima,n1dimx,n1dimy,n2dimx,n2dimy,n2dima,ncpgrx,ncpgry,nlmn
real(dp) :: cp1,cp2,norma
character(len=500) :: msg
! *************************************************************************
n1dimy=size(cprjy,dim=1);n2dimy=size(cprjy,dim=2);ncpgry=cprjy(1,1)%ncpgr
n1dimx=size(cprjx,dim=1);n2dimx=size(cprjx,dim=2);ncpgrx=cprjx(1,1)%ncpgr
n1dima=size(alpha,dim=1);n2dima=size(alpha,dim=2)
msg = ""
if (n1dima/=2) msg = TRIM(msg)//"Error in pawcprj_projbd: alpha n1 wrong sizes !"//ch10
if (n1dimx/=n1dimy) msg = TRIM(msg)//"Error in pawcprj_projbd: n1 wrong sizes !"//ch10
if (n2dimx/=n2dimy*n2dima) msg = TRIM(msg)//"Error in pawcprj_projbd: n2 wrong sizes !"//ch10
if (ncpgrx/=ncpgry) msg = TRIM(msg)//"Error in pawcprj_projbd: ncpgr wrong sizes !"//ch10
if (LEN_TRIM(msg) > 0) then
LIBPAW_ERROR(msg)
end if
do ia=1,n2dima
norma=alpha(1,ia)**2+alpha(2,ia)**2
if (norma>tol16*tol16) then
do jj=1,n2dimy
do ii=1,n1dimx
nlmn=cprjy(ii,jj)%nlmn
cprjy(ii,jj)%nlmn =nlmn
do kk=1,nlmn
cp1=alpha(1,ia)*cprjx(ii,jj+(ia-1)*n2dimy)%cp(1,kk)-alpha(2,ia)*cprjx(ii,jj+(ia-1)*n2dimy)%cp(2,kk)
cp2=alpha(1,ia)*cprjx(ii,jj+(ia-1)*n2dimy)%cp(2,kk)+alpha(2,ia)*cprjx(ii,jj+(ia-1)*n2dimy)%cp(1,kk)
cprjy(ii,jj)%cp(1,kk)=cprjy(ii,jj)%cp(1,kk)+cp1
cprjy(ii,jj)%cp(2,kk)=cprjy(ii,jj)%cp(2,kk)+cp2
end do
end do
end do
if (ncpgrx>0) then
do jj=1,n2dimy
do ii=1,n1dimx
nlmn=cprjy(ii,jj)%nlmn
do kk=1,nlmn
do ll=1,ncpgrx
cp1=alpha(1,ia)*cprjx(ii,jj+(ia-1)*n2dimy)%dcp(1,ll,kk)-alpha(2,ia)*cprjx(ii,jj+(ia-1)*n2dimy)%dcp(2,ll,kk)
cp2=alpha(1,ia)*cprjx(ii,jj+(ia-1)*n2dimy)%dcp(2,ll,kk)+alpha(2,ia)*cprjx(ii,jj+(ia-1)*n2dimy)%dcp(1,ll,kk)
cprjy(ii,jj)%dcp(1,ll,kk)=cprjy(ii,jj)%dcp(1,ll,kk)+cp1
cprjy(ii,jj)%dcp(2,ll,kk)=cprjy(ii,jj)%dcp(2,ll,kk)+cp2
end do
end do
end do
end do
end if
end if
end do
end subroutine pawcprj_projbd
!!***
!----------------------------------------------------------------------
!!****f* m_pawcprj/pawcprj_symkn
!! NAME
!! pawcprj_symkn
!!
!! FUNCTION
!! compute cprj for a given band and k point based on cprj at a symmetry-related
!! k point.
!!
!! INPUTS
!! cprj_ikn (pawcprj_type) :: cprj for a single band and k point, typically a k point in the IBZ
!! cprj_sym(4,nsym,natom) :: 1:3 shift, and 4 final atom, of symmetry isym operating on iatom
!! (S^{-1}(R - t) = r0 + L, see symatm.F90
!! dimlmn(natom) :: ln dimension of each atom
!! iband :: number of bands to treat, use -1 to treat all nband bands
!! indlmn(6,lmnmax,ntypat) :: n,l,m dimensions for each atom type (see psps type)
!! isym :: symmetry element used in current application
!! itim :: 1 if time reversal also used, 0 else
!! kpt(3) :: kpt vector used
!! lmax :: max l value
!! lmnmax :: max lmn value
!! mband :: maximum number of bands
!! natom :: number of atoms in cell
!! nband :: number of bands in cprj_ikn
!! nspinor :: number of spinors
!! nsym :: total number of symmetry elements
!! ntypat :: number of types of atoms
!! typat(natom) :: type of each atom
!! zarot(2*lmax+1,2*lmax+1,lmax+1,nsym) :: elements of rotation matrix for angular momentum states
!! and symmetry operations. See m_paw_sphharm/setsym_ylm.
!!
!! OUTPUT
!! cprj_fkn (pawcprj_type) :: cprj for a single band and k point where the k point is related to
!! the input k point by a symmetry operation
!!
!! SIDE EFFECTS
!!
!! NOTES
!! This routine is based on M. Giantomassi's doctoral dissertation, formula 7.77. It is not clear
!! whether it is implemented correctly for nonsymmorphic symmetries.
!!
!! SOURCE
subroutine pawcprj_symkn(cprj_fkn,cprj_ikn,cprj_sym,dimlmn,iband,indlmn,&
& isym,itim,kpt,lmax,lmnmax,mband,natom,nband,nspinor,nsym,ntypat,&
& typat,zarot)
!Arguments---------------------------
!scalars
integer,intent(in) :: iband,isym,itim,lmax,lmnmax,mband
integer,intent(in) :: natom,nband,nspinor,nsym,ntypat
!arrays
integer,intent(in) :: cprj_sym(4,nsym,natom),dimlmn(natom)
integer,intent(in) :: indlmn(6,lmnmax,ntypat),typat(natom)
real(dp),intent(in) :: kpt(3)
real(dp),intent(in) :: zarot(2*lmax+1,2*lmax+1,lmax+1,nsym)
type(pawcprj_type),intent(in) :: cprj_ikn(natom,mband*nspinor)
type(pawcprj_type),intent(inout) :: cprj_fkn(natom,mband*nspinor) !vz_i
!Local variables---------------------------
!scalars
integer :: iatm,iatom, ibct, ibnd, ibsp, ibst, icpgr, iin, il, il0, im
integer :: ilmn, iln, iln0, ilpm, indexi, ispinor, itypat, jatm,jatom, mm, nlmn
real(dp) :: kdotL, phr, phi
!arrays
real(dp) :: rl(3), t1(2), t2(2)
! *************************************************************************
if (iband == -1) then
ibst = 1
ibnd = nband
else
ibst = iband
ibnd = iband
end if
do iatom = 1, natom
iatm=iatom
itypat = typat(iatom)
nlmn = dimlmn(iatm)
jatom = cprj_sym(4,isym,iatom)
jatm=jatom
rl(:) = cprj_sym(1:3,isym,iatom)
kdotL = dot_product(rl,kpt)
phr = cos(two_pi*kdotL)
phi = sin(two_pi*kdotL)
il0 = -1; iln0 = -1; indexi = 1
do ilmn = 1, nlmn
il = indlmn(1,ilmn,itypat)
im = indlmn(2,ilmn,itypat)
iin = indlmn(3,ilmn,itypat)
iln = indlmn(5,ilmn,itypat)
ilpm = 1 + il + im
if (iln /= iln0) indexi = indexi + 2*il0 + 1
do ibct = ibst, ibnd
do ispinor = 1, nspinor
ibsp = nspinor*(ibct-1) + ispinor
t1(:) = zero
do mm = 1, 2*il+1
t1(1) = t1(1) + zarot(mm,ilpm,il+1,isym)*cprj_ikn(jatm,ibsp)%cp(1,indexi+mm)
t1(2) = t1(2) + zarot(mm,ilpm,il+1,isym)*cprj_ikn(jatm,ibsp)%cp(2,indexi+mm)
end do
t2(1) = t1(1)*phr - t1(2)*phi
t2(2) = t1(2)*phr + t1(1)*phi
if (itim == 1) t2(2) = -t2(2)
cprj_fkn(iatm,ibsp)%cp(1,ilmn) = t2(1)
cprj_fkn(iatm,ibsp)%cp(2,ilmn) = t2(2)
! do same transformations for gradients of cprj_ikn
! note that ncpgr = 0 if no gradients present so this loop will not be executed
! in this case
do icpgr = 1, cprj_ikn(jatom,ibsp)%ncpgr
t1(:) = zero
do mm = 1, 2*il+1
t1(1) = t1(1) + zarot(mm,ilpm,il+1,isym)*cprj_ikn(jatm,ibsp)%dcp(1,icpgr,indexi+mm)
t1(2) = t1(2) + zarot(mm,ilpm,il+1,isym)*cprj_ikn(jatm,ibsp)%dcp(2,icpgr,indexi+mm)
end do
t2(1) = t1(1)*phr - t1(2)*phi
t2(2) = t1(2)*phr + t1(1)*phi
if (itim == 1) t2(2) = -t2(2)
cprj_fkn(iatm,ibsp)%dcp(1,icpgr,ilmn) = t2(1)
cprj_fkn(iatm,ibsp)%dcp(2,icpgr,ilmn) = t2(2)
end do ! end loop over ncpgr
end do ! end loop over nspinor
end do ! end loop over bands
il0 = il; iln0 = iln
end do ! end loop over ilmn
end do ! end loop over atoms
end subroutine pawcprj_symkn
!!***
!----------------------------------------------------------------------
!!****f* m_pawcprj/pawcprj_conjg
!! NAME
!! pawcprj_conjg
!!
!! FUNCTION
!! conjugate a cprj datastructures:
!! cprj(:,:) <- conjugate(cprj(:,:))
!!
!! INPUTS
!!
!! SIDE EFFECTS
!! cprj(:,:) <type(pawcprj_type)>= input/output cprj datastructure
!!
!! SOURCE
subroutine pawcprj_conjg(cprj)
!Arguments ------------------------------------
!scalars
!arrays
type(pawcprj_type),intent(inout) :: cprj(:,:)
!Local variables-------------------------------
!scalars
integer :: ii,jj,kk,n1dim,n2dim,ncpgr,nlmn
!arrays
! *************************************************************************
n1dim=size(cprj,dim=1);n2dim=size(cprj,dim=2);ncpgr=cprj(1,1)%ncpgr
do jj=1,n2dim
do ii=1,n1dim
nlmn=cprj(ii,jj)%nlmn
do kk=1,nlmn
cprj(ii,jj)%cp(2,kk)=-cprj(ii,jj)%cp(2,kk)
end do
end do
end do
if (ncpgr>0) then
do jj=1,n2dim
do ii=1,n1dim
nlmn=cprj(ii,jj)%nlmn
do kk=1,nlmn
cprj(ii,jj)%dcp(2,1:ncpgr,kk)=-cprj(ii,jj)%dcp(2,1:ncpgr,kk)
end do
end do
end do
end if
end subroutine pawcprj_conjg
!!***
!----------------------------------------------------------------------
!!****f* m_pawcprj/pawcprj_lincom
!! NAME
!! pawcprj_lincom
!!
!! FUNCTION
!! Compute a LINear COMbination of cprj datastructure:
!! cprj_out(:,:) <--- Sum_i [ alpha_i . cprj_i(:,:) ]
!! alpha_i are COMPLEX scalars
!!
!! INPUTS
!! alpha(2,nn)= alpha COMPLEX factors
!! cprj_in(:,:) <type(pawcprj_type)>= input cprj_in datastructure
!! nn= number of cprj involved in the linear combination
!!
!! OUTPUT
!! cprj_out(:,:) <type(pawcprj_type)>= output cprj_out datastructure
!!
!! NOTES
!! cprj_in and cprj_out must be dimensionned as cprj_in(n1,n2*nn) and cprj_in(n1,n2)
!!
!! SOURCE
subroutine pawcprj_lincom(alpha,cprj_in,cprj_out,nn)
!Arguments ------------------------------------
!scalars
integer,intent(in) :: nn
real(dp),intent(in) :: alpha(2,nn)
!arrays
type(pawcprj_type),intent(in) :: cprj_in(:,:)
type(pawcprj_type),intent(inout) :: cprj_out(:,:)
!Local variables-------------------------------
!scalars
integer :: ii,in,jj,jn,kk,ll,n1in,n1out,n2in,n2out,ncpgrin,ncpgrout,nlmn
real(dp) :: cp1,cp2
character(len=500) :: msg
! *************************************************************************
n1in=size(cprj_in,dim=1);n1out=size(cprj_out,dim=1)
n2in=size(cprj_in,dim=2);n2out=size(cprj_out,dim=2)
ncpgrin=cprj_in(1,1)%ncpgr;ncpgrout=cprj_out(1,1)%ncpgr
msg = ""
if (n1in/=n1out) msg = TRIM(msg)//"Bug in pawcprj_lincom: n1 wrong sizes!"//ch10
if (n2in/=n2out*nn) msg = TRIM(msg)//"Bug in pawcprj_lincom: n2 wrong sizes!"//ch10
if (ncpgrin/=ncpgrout) msg = TRIM(msg)//"Bug in pawcprj_lincom: ncpgr wrong sizes!"//ch10
if (LEN_TRIM(msg) > 0) then
LIBPAW_ERROR(msg)
end if
do jj=1,n2out
do ii=1,n1out