(git:ed6f26b)
Loading...
Searching...
No Matches
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-2025 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,&
20 USE pw_grid_types, ONLY: fullspace,&
24 USE pw_grids, ONLY: pw_grid_release
25 USE pw_pool_types, ONLY: pw_pool_create,&
30#include "./base/base_uses.f90"
31
32 IMPLICIT NONE
33
34 PRIVATE
35 PUBLIC :: qmmm_pw_grid_init
36 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qmmm_pw_grid'
37 INTEGER :: qmmm_grid_tag = 0
38
39CONTAINS
40
41! **************************************************************************************************
42!> \brief Initialize the qmmm pool of pw_r3d_rs_type.
43!> Then Main difference w.r.t. QS pw_r3d_rs_type pools is that this pool
44!> has [0,L] as boundaries.
45!> \param qmmm_env ...
46!> \param pw_env ...
47!> \par History
48!> 08.2004 created [tlaino]
49!> \author Teodoro Laino
50! **************************************************************************************************
51 SUBROUTINE qmmm_pw_grid_init(qmmm_env, pw_env)
52 TYPE(qmmm_env_qm_type), POINTER :: qmmm_env
53 TYPE(pw_env_type), POINTER :: pw_env
54
55 INTEGER :: auxbas_grid, ilevel, pw_mode
56 REAL(kind=dp), DIMENSION(3) :: maxdr, mindr
57 TYPE(pw_grid_type), POINTER :: el_struct
58 TYPE(pw_pool_p_type), DIMENSION(:), POINTER :: pw_pools
59 TYPE(pw_pool_type), POINTER :: pool
60
61 NULLIFY (el_struct)
62 maxdr = tiny(0.0_dp)
63 mindr = huge(0.0_dp)
64 IF ((qmmm_env%qmmm_coupl_type == do_qmmm_gauss) .OR. (qmmm_env%qmmm_coupl_type == do_qmmm_swave)) THEN
65 CALL pw_env_get(pw_env=pw_env, &
66 pw_pools=pw_pools, &
67 auxbas_grid=auxbas_grid)
68 !
69 IF (ASSOCIATED(qmmm_env%aug_pools)) THEN
70 CALL pw_pools_dealloc(qmmm_env%aug_pools)
71 END IF
72 ALLOCATE (qmmm_env%aug_pools(SIZE(pw_pools)))
73 !
74 DO ilevel = 1, SIZE(pw_pools)
75 NULLIFY (pool, qmmm_env%aug_pools(ilevel)%pool)
76 pool => pw_pools(ilevel)%pool
77 NULLIFY (el_struct)
78 pw_mode = pw_mode_distributed
79 ! Parallelization scheme
80 IF (qmmm_env%par_scheme == do_par_atom) THEN
81 pw_mode = pw_mode_local
82 END IF
83
84 CALL pw_grid_create_copy_no_pbc(pool%pw_grid, el_struct, &
85 pw_mode=pw_mode)
86 CALL pw_pool_create(qmmm_env%aug_pools(ilevel)%pool, &
87 pw_grid=el_struct)
88
89 maxdr = max(maxdr, el_struct%dr)
90 mindr = min(mindr, el_struct%dr)
91 IF (all(maxdr .EQ. el_struct%dr)) qmmm_env%gridlevel_info%coarser_grid = ilevel
92 IF (all(mindr .EQ. el_struct%dr)) qmmm_env%gridlevel_info%auxbas_grid = ilevel
93
94 CALL pw_grid_release(el_struct)
95
96 END DO
97 END IF
98
99 END SUBROUTINE qmmm_pw_grid_init
100
101! **************************************************************************************************
102!> \brief creates a copy of pw_grid_in in which the pbc have been removed
103!> (by adding a point for the upper boundary)
104!> \param pw_grid_in the pw grid to duplicate
105!> \param pw_grid_out the output pw_grid_type
106!> \param pw_mode ...
107!> \par History
108!> 08.2004 created [tlaino]
109!> 04.2005 completely rewritten the duplicate routine, fixed parallel
110!> behaviour, narrowed scope to copy to non pbc and renamed
111!> accordingly [fawzi]
112!> 06.2007 moved to new module [jgh]
113!> \author Fawzi, Teo
114! **************************************************************************************************
115 SUBROUTINE pw_grid_create_copy_no_pbc(pw_grid_in, pw_grid_out, pw_mode)
116 TYPE(pw_grid_type), POINTER :: pw_grid_in, pw_grid_out
117 INTEGER, INTENT(IN), OPTIONAL :: pw_mode
118
119 INTEGER :: pw_mode_loc
120 INTEGER, ALLOCATABLE, DIMENSION(:) :: pos_of_x
121
122 cpassert(pw_grid_in%ngpts_cut > 0)
123 cpassert(.NOT. ASSOCIATED(pw_grid_out))
124 pw_mode_loc = pw_grid_in%para%mode
125 IF (PRESENT(pw_mode)) pw_mode_loc = pw_mode
126 ! TODO: introduce pw_grid_create_from_grid
127 ALLOCATE (pw_grid_out)
128 CALL pw_grid_out%para%group%from_dup(pw_grid_in%para%group)
129 qmmm_grid_tag = qmmm_grid_tag + 1
130 pw_grid_out%id_nr = qmmm_grid_tag
131 pw_grid_out%ref_count = 1
132 pw_grid_out%reference = 0
133 pw_grid_out%bounds = pw_grid_in%bounds
134 pw_grid_out%bounds(2, :) = pw_grid_out%bounds(2, :) + 1
135 IF (pw_mode_loc == pw_mode_distributed) THEN
136 pw_grid_out%bounds_local = pw_grid_in%bounds_local
137 IF (pw_grid_in%bounds_local(2, 1) == pw_grid_in%bounds(2, 1) .AND. &
138 pw_grid_in%bounds_local(1, 1) <= pw_grid_in%bounds(2, 1)) THEN
139 pw_grid_out%bounds_local(2, 1) = pw_grid_out%bounds_local(2, 1) + 1
140 END IF
141 pw_grid_out%bounds_local(2, 2) = pw_grid_out%bounds_local(2, 2) + 1
142 pw_grid_out%bounds_local(2, 3) = pw_grid_out%bounds_local(2, 3) + 1
143 ELSE
144 pw_grid_out%bounds_local = pw_grid_out%bounds
145 END IF
146 pw_grid_out%npts = pw_grid_in%npts + 1
147 pw_grid_out%ngpts = product(int(pw_grid_out%npts, kind=int_8))
148 pw_grid_out%ngpts_cut = 0
149 pw_grid_out%npts_local = pw_grid_out%bounds_local(2, :) - pw_grid_out%bounds_local(1, :) + 1
150 pw_grid_out%ngpts_local = product(pw_grid_out%npts_local)
151 pw_grid_out%ngpts_cut_local = 0
152 pw_grid_out%dr = pw_grid_in%dr
153 pw_grid_out%dh = pw_grid_in%dh
154 pw_grid_out%dh_inv = pw_grid_in%dh_inv
155 pw_grid_out%orthorhombic = pw_grid_in%orthorhombic
156 pw_grid_out%dvol = pw_grid_in%dvol
157 pw_grid_out%vol = pw_grid_in%vol*real(pw_grid_out%ngpts, dp) &
158 /real(pw_grid_in%ngpts, dp) !FM do not modify?
159 pw_grid_out%cutoff = pw_grid_in%cutoff
160
161 !para
162 pw_grid_out%para%mode = pw_mode_loc
163 ALLOCATE (pos_of_x(pw_grid_out%bounds(1, 1):pw_grid_out%bounds(2, 1)))
164 pos_of_x(:pw_grid_out%bounds(2, 1) - 1) = pw_grid_in%para%pos_of_x
165 pos_of_x(pw_grid_out%bounds(2, 1)) = pos_of_x(pw_grid_out%bounds(2, 1) - 1)
166 CALL move_alloc(pos_of_x, pw_grid_out%para%pos_of_x)
167
168 NULLIFY (pw_grid_out%g, pw_grid_out%gsq)
169 cpassert(pw_grid_in%grid_span == fullspace)
170 pw_grid_out%grid_span = pw_grid_in%grid_span
171 pw_grid_out%have_g0 = .false.
172 pw_grid_out%first_gne0 = huge(0)
173 NULLIFY (pw_grid_out%gidx)
174 pw_grid_out%spherical = .false.
175 pw_grid_out%para%ray_distribution = .false.
176 pw_grid_out%para%blocked = .false.
177 END SUBROUTINE pw_grid_create_copy_no_pbc
178END 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
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
integer, parameter, public pw_mode_local
integer, parameter, public fullspace
integer, parameter, public pw_mode_distributed
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:2163
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
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
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...
contained for different pw related things
to create arrays of pools
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...