(git:bb35279)
Loading...
Searching...
No Matches
pw_copy_all.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2025 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \note
10!> Copy of pw types using an optimal match strategy
11!> \par History
12!> JGH (06-May-2021) : pw_copy routine for complex match
13!> \author JGH
14! **************************************************************************************************
16 USE kinds, ONLY: dp
17 USE mathconstants, ONLY: z_zero
20 USE pw_types, ONLY: pw_c1d_gs_type
21#include "../base/base_uses.f90"
22
23 IMPLICIT NONE
24
25 PRIVATE
26
27 PUBLIC :: pw_copy_match
28
29 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'pw_copy_all'
30 LOGICAL, PARAMETER, PRIVATE :: debug_this_module = .false.
31
32! **************************************************************************************************
33
34CONTAINS
35
36! **************************************************************************************************
37!> \brief copy a pw type variable
38!> \param pw1 ...
39!> \param pw2 ...
40!> \author JGH
41! **************************************************************************************************
42 SUBROUTINE pw_copy_match(pw1, pw2)
43 TYPE(pw_c1d_gs_type), INTENT(IN) :: pw1
44 TYPE(pw_c1d_gs_type), INTENT(INOUT) :: pw2
45
46 COMPLEX(KIND=dp), ALLOCATABLE, DIMENSION(:) :: cc
47 INTEGER :: group_size, ig1, ig2, ip, jg2, me, ng1, &
48 ng2, ngm, penow
49 INTEGER, ALLOCATABLE, DIMENSION(:) :: ngr
50 INTEGER, ALLOCATABLE, DIMENSION(:, :) :: g_hat
51 INTEGER, DIMENSION(3) :: k1, k2
52 TYPE(mp_comm_type) :: group
53 TYPE(pw_grid_type), POINTER :: pg1, pg2
54
55 ng1 = SIZE(pw1%array)
56 ng2 = SIZE(pw2%array)
57
58 pg1 => pw1%pw_grid
59 pg2 => pw2%pw_grid
60
61 group = pg1%para%group
62 group_size = pg1%para%group%num_pe
63 me = pg1%para%group%mepos
64 ALLOCATE (ngr(group_size))
65 ngr = 0
66 ngr(me + 1) = pg1%ngpts_cut_local
67 CALL group%sum(ngr)
68 ngm = maxval(ngr)
69 ALLOCATE (cc(ngm))
70 cc(1:ng1) = pw1%array(1:ng1)
71 cc(ng1 + 1:ngm) = z_zero
72
73 ALLOCATE (g_hat(3, ngm))
74 g_hat = 0
75 g_hat(1:3, 1:ng1) = pg1%g_hat(1:3, 1:ng1)
76
77 DO ip = 1, group_size
78 penow = me - ip + 1
79 IF (penow < 0) penow = penow + group_size
80
81 DO ig1 = 1, ngr(penow + 1)
82 k1(1:3) = g_hat(1:3, ig1)
83 jg2 = 0
84 DO ig2 = 1, ng2
85 k2(1:3) = pg2%g_hat(1:3, ig2)
86 IF (sum(abs(k1 - k2)) == 0) THEN
87 jg2 = ig2
88 EXIT
89 END IF
90 END DO
91 IF (jg2 /= 0) pw2%array(jg2) = cc(ig1)
92 END DO
93 IF (ip /= group_size) THEN
94 CALL group%shift(cc)
95 CALL group%shift(g_hat)
96 END IF
97
98 END DO
99
100 DEALLOCATE (ngr, cc, g_hat)
101
102 END SUBROUTINE pw_copy_match
103
104END MODULE pw_copy_all
105
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Definition of mathematical constants and functions.
complex(kind=dp), parameter, public z_zero
Interface to the message passing library MPI.
subroutine, public pw_copy_match(pw1, pw2)
copy a pw type variable
Definition pw_copy_all.F:43