(git:e7e05ae)
qmmm_pw_grid.F
Go to the documentation of this file.
1 !--------------------------------------------------------------------------------------------------!
2 ! CP2K: A general program to perform molecular dynamics simulations !
3 ! Copyright 2000-2024 CP2K developers group <https://cp2k.org> !
4 ! !
5 ! SPDX-License-Identifier: GPL-2.0-or-later !
6 !--------------------------------------------------------------------------------------------------!
7 
8 ! **************************************************************************************************
9 !> \brief sets variables for the qmmm pool of pw_types
10 !> \author Teodoro Laino
11 ! **************************************************************************************************
13  USE input_constants, ONLY: do_par_atom,&
16  USE kinds, ONLY: dp,&
17  int_8
18  USE pw_env_types, ONLY: pw_env_get,&
19  pw_env_type
20  USE pw_grid_types, ONLY: fullspace,&
23  pw_grid_type
24  USE pw_grids, ONLY: pw_grid_create,&
26  USE pw_pool_types, ONLY: pw_pool_create,&
27  pw_pool_p_type,&
28  pw_pool_type,&
30  USE qmmm_types_low, ONLY: qmmm_env_qm_type
31 #include "./base/base_uses.f90"
32 
33  IMPLICIT NONE
34 
35  PRIVATE
36  PUBLIC :: qmmm_pw_grid_init
37  CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qmmm_pw_grid'
38  INTEGER :: qmmm_grid_tag = 0
39 
40 CONTAINS
41 
42 ! **************************************************************************************************
43 !> \brief Initialize the qmmm pool of pw_r3d_rs_type.
44 !> Then Main difference w.r.t. QS pw_r3d_rs_type pools is that this pool
45 !> has [0,L] as boundaries.
46 !> \param qmmm_env ...
47 !> \param pw_env ...
48 !> \par History
49 !> 08.2004 created [tlaino]
50 !> \author Teodoro Laino
51 ! **************************************************************************************************
52  SUBROUTINE qmmm_pw_grid_init(qmmm_env, pw_env)
53  TYPE(qmmm_env_qm_type), POINTER :: qmmm_env
54  TYPE(pw_env_type), POINTER :: pw_env
55 
56  INTEGER :: auxbas_grid, ilevel, pw_mode
57  REAL(kind=dp), DIMENSION(3) :: maxdr, mindr
58  TYPE(pw_grid_type), POINTER :: el_struct
59  TYPE(pw_pool_p_type), DIMENSION(:), POINTER :: pw_pools
60  TYPE(pw_pool_type), POINTER :: pool
61 
62  NULLIFY (el_struct)
63  maxdr = tiny(0.0_dp)
64  mindr = huge(0.0_dp)
65  IF ((qmmm_env%qmmm_coupl_type == do_qmmm_gauss) .OR. (qmmm_env%qmmm_coupl_type == do_qmmm_swave)) THEN
66  CALL pw_env_get(pw_env=pw_env, &
67  pw_pools=pw_pools, &
68  auxbas_grid=auxbas_grid)
69  !
70  IF (ASSOCIATED(qmmm_env%aug_pools)) THEN
71  CALL pw_pools_dealloc(qmmm_env%aug_pools)
72  END IF
73  ALLOCATE (qmmm_env%aug_pools(SIZE(pw_pools)))
74  !
75  DO ilevel = 1, SIZE(pw_pools)
76  NULLIFY (pool, qmmm_env%aug_pools(ilevel)%pool)
77  pool => pw_pools(ilevel)%pool
78  NULLIFY (el_struct)
79  pw_mode = pw_mode_distributed
80  ! Parallelization scheme
81  IF (qmmm_env%par_scheme == do_par_atom) THEN
82  pw_mode = pw_mode_local
83  END IF
84 
85  CALL pw_grid_create_copy_no_pbc(pool%pw_grid, el_struct, &
86  pw_mode=pw_mode)
87  CALL pw_pool_create(qmmm_env%aug_pools(ilevel)%pool, &
88  pw_grid=el_struct)
89 
90  maxdr = max(maxdr, el_struct%dr)
91  mindr = min(mindr, el_struct%dr)
92  IF (all(maxdr .EQ. el_struct%dr)) qmmm_env%gridlevel_info%coarser_grid = ilevel
93  IF (all(mindr .EQ. el_struct%dr)) qmmm_env%gridlevel_info%auxbas_grid = ilevel
94 
95  CALL pw_grid_release(el_struct)
96 
97  END DO
98  END IF
99 
100  END SUBROUTINE qmmm_pw_grid_init
101 
102 ! **************************************************************************************************
103 !> \brief creates a copy of pw_grid_in in which the pbc have been removed
104 !> (by adding a point for the upper boundary)
105 !> \param pw_grid_in the pw grid to duplicate
106 !> \param pw_grid_out the output pw_grid_type
107 !> \param pw_mode ...
108 !> \par History
109 !> 08.2004 created [tlaino]
110 !> 04.2005 completely rewritten the duplicate routine, fixed parallel
111 !> behaviour, narrowed scope to copy to non pbc and renamed
112 !> accordingly [fawzi]
113 !> 06.2007 moved to new module [jgh]
114 !> \author Fawzi, Teo
115 ! **************************************************************************************************
116  SUBROUTINE pw_grid_create_copy_no_pbc(pw_grid_in, pw_grid_out, pw_mode)
117  TYPE(pw_grid_type), POINTER :: pw_grid_in, pw_grid_out
118  INTEGER, INTENT(IN), OPTIONAL :: pw_mode
119 
120  INTEGER :: pw_mode_loc
121  INTEGER, ALLOCATABLE, DIMENSION(:) :: pos_of_x
122 
123  cpassert(pw_grid_in%ngpts_cut > 0)
124  cpassert(.NOT. ASSOCIATED(pw_grid_out))
125  pw_mode_loc = pw_grid_in%para%mode
126  IF (PRESENT(pw_mode)) pw_mode_loc = pw_mode
127  CALL pw_grid_create(pw_grid_out, pw_grid_in%para%group)
128  qmmm_grid_tag = qmmm_grid_tag + 1
129  pw_grid_out%id_nr = qmmm_grid_tag
130  pw_grid_out%ref_count = 1
131  pw_grid_out%reference = 0
132  pw_grid_out%bounds = pw_grid_in%bounds
133  pw_grid_out%bounds(2, :) = pw_grid_out%bounds(2, :) + 1
134  IF (pw_mode_loc == pw_mode_distributed) THEN
135  pw_grid_out%bounds_local = pw_grid_in%bounds_local
136  IF (pw_grid_in%bounds_local(2, 1) == pw_grid_in%bounds(2, 1) .AND. &
137  pw_grid_in%bounds_local(1, 1) <= pw_grid_in%bounds(2, 1)) THEN
138  pw_grid_out%bounds_local(2, 1) = pw_grid_out%bounds_local(2, 1) + 1
139  END IF
140  pw_grid_out%bounds_local(2, 2) = pw_grid_out%bounds_local(2, 2) + 1
141  pw_grid_out%bounds_local(2, 3) = pw_grid_out%bounds_local(2, 3) + 1
142  ELSE
143  pw_grid_out%bounds_local = pw_grid_out%bounds
144  END IF
145  pw_grid_out%npts = pw_grid_in%npts + 1
146  pw_grid_out%ngpts = product(int(pw_grid_out%npts, kind=int_8))
147  pw_grid_out%ngpts_cut = 0
148  pw_grid_out%npts_local = pw_grid_out%bounds_local(2, :) - pw_grid_out%bounds_local(1, :) + 1
149  pw_grid_out%ngpts_local = product(pw_grid_out%npts_local)
150  pw_grid_out%ngpts_cut_local = 0
151  pw_grid_out%dr = pw_grid_in%dr
152  pw_grid_out%dh = pw_grid_in%dh
153  pw_grid_out%dh_inv = pw_grid_in%dh_inv
154  pw_grid_out%orthorhombic = pw_grid_in%orthorhombic
155  pw_grid_out%dvol = pw_grid_in%dvol
156  pw_grid_out%vol = pw_grid_in%vol*real(pw_grid_out%ngpts, dp) &
157  /real(pw_grid_in%ngpts, dp) !FM do not modify?
158  pw_grid_out%cutoff = pw_grid_in%cutoff
159 
160  !para
161  pw_grid_out%para%group_size = pw_grid_out%para%group%num_pe
162  pw_grid_out%para%my_pos = pw_grid_out%para%group%mepos
163  pw_grid_out%para%group_head_id = pw_grid_in%para%group_head_id
164  pw_grid_out%para%group_head = &
165  (pw_grid_out%para%group_head_id == pw_grid_out%para%my_pos)
166  pw_grid_out%para%mode = pw_mode_loc
167  ALLOCATE (pos_of_x(pw_grid_out%bounds(1, 1):pw_grid_out%bounds(2, 1)))
168  pos_of_x(:pw_grid_out%bounds(2, 1) - 1) = pw_grid_in%para%pos_of_x
169  pos_of_x(pw_grid_out%bounds(2, 1)) = pos_of_x(pw_grid_out%bounds(2, 1) - 1)
170  CALL move_alloc(pos_of_x, pw_grid_out%para%pos_of_x)
171  pw_grid_out%para%rs_dims = pw_grid_in%para%rs_dims
172  IF (product(pw_grid_in%para%rs_dims) /= 0) THEN
173  CALL pw_grid_out%para%rs_group%from_dup(pw_grid_in%para%rs_group)
174  END IF
175  pw_grid_out%para%rs_pos = pw_grid_in%para%rs_pos
176  pw_grid_out%para%rs_mpo = pw_grid_in%para%rs_mpo
177 
178  NULLIFY (pw_grid_out%g, pw_grid_out%gsq)
179  cpassert(pw_grid_in%grid_span == fullspace)
180  pw_grid_out%grid_span = pw_grid_in%grid_span
181  pw_grid_out%have_g0 = .false.
182  pw_grid_out%first_gne0 = huge(0)
183  NULLIFY (pw_grid_out%gidx)
184  pw_grid_out%spherical = .false.
185  pw_grid_out%para%ray_distribution = .false.
186  pw_grid_out%para%blocked = .false.
187  END SUBROUTINE pw_grid_create_copy_no_pbc
188 END MODULE qmmm_pw_grid
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public do_par_atom
integer, parameter, public do_qmmm_swave
integer, parameter, public do_qmmm_gauss
Defines the basic variable types.
Definition: kinds.F:23
integer, parameter, public int_8
Definition: kinds.F:54
integer, parameter, public dp
Definition: kinds.F:34
container for various plainwaves related things
Definition: pw_env_types.F:14
subroutine, public pw_env_get(pw_env, pw_pools, cube_info, gridlevel_info, auxbas_pw_pool, auxbas_grid, auxbas_rs_desc, auxbas_rs_grid, rs_descs, rs_grids, xc_pw_pool, vdw_pw_pool, poisson_env, interp_section)
returns the various attributes of the pw env
Definition: pw_env_types.F:113
integer, parameter, public pw_mode_local
Definition: pw_grid_types.F:29
integer, parameter, public fullspace
Definition: pw_grid_types.F:28
integer, parameter, public pw_mode_distributed
Definition: pw_grid_types.F:29
This module defines the grid data type and some basic operations on it.
Definition: pw_grids.F:36
subroutine, public pw_grid_release(pw_grid)
releases the given pw grid
Definition: pw_grids.F:2133
subroutine, public pw_grid_create(pw_grid, pe_group, local)
Initialize a PW grid with all defaults.
Definition: pw_grids.F:93
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
Definition: pw_pool_types.F:24
subroutine, public pw_pools_dealloc(pools)
deallocates the given pools (releasing each of the underlying pools)
subroutine, public pw_pool_create(pool, pw_grid, max_cache)
creates a pool for pw
sets variables for the qmmm pool of pw_types
Definition: qmmm_pw_grid.F:12
subroutine, public qmmm_pw_grid_init(qmmm_env, pw_env)
Initialize the qmmm pool of pw_r3d_rs_type. Then Main difference w.r.t. QS pw_r3d_rs_type pools is th...
Definition: qmmm_pw_grid.F:53