Line data Source code
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 container for various plainwaves related things
10 : !> \par History
11 : !> 10.2002 created [fawzi]
12 : !> \author Fawzi Mohamed
13 : ! **************************************************************************************************
14 : MODULE pw_env_types
15 : USE cube_utils, ONLY: cube_info_type,&
16 : destroy_cube_info
17 : USE gaussian_gridlevels, ONLY: destroy_gaussian_gridlevel,&
18 : gridlevel_info_type
19 : USE input_section_types, ONLY: section_vals_type
20 : USE kinds, ONLY: dp
21 : USE message_passing, ONLY: mp_para_env_type
22 : USE pw_poisson_types, ONLY: pw_poisson_type
23 : USE pw_pool_types, ONLY: pw_pool_p_type,&
24 : pw_pool_release,&
25 : pw_pool_type,&
26 : pw_pools_dealloc
27 : USE realspace_grid_types, ONLY: realspace_grid_desc_p_type,&
28 : realspace_grid_desc_type,&
29 : realspace_grid_type,&
30 : rs_grid_release,&
31 : rs_grid_release_descriptor
32 : #include "../base/base_uses.f90"
33 :
34 : IMPLICIT NONE
35 : PRIVATE
36 :
37 : LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .TRUE.
38 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'pw_env_types'
39 :
40 : PUBLIC :: pw_env_type
41 : PUBLIC :: pw_env_retain, pw_env_release, pw_env_get
42 :
43 : !***
44 :
45 : ! **************************************************************************************************
46 : !> \brief contained for different pw related things
47 : !> \param pw_pools pools for multigrids
48 : !> \param rs_descs descriptors for the realspace grids
49 : !> \param rs_grids the realspace grids
50 : !> \param xc_pw_pool the pool used for xc calculation on grid (might be the
51 : !> same as the finest, or finer still).
52 : !> \param vdw_pw_pool the pool used for vdw-nl calculation on grid (might be the
53 : !> same or a grid with a new cutoff
54 : !> \param gridlevel_info gaussian gridlevel info
55 : !> \param cube_info info on cube and max sphere size for multigrids
56 : !> \param aux_bas which multigrid is the auxiliar basis
57 : !>
58 : !> readonly attributes
59 : !> \param auxbas_pw_pool a pool that allocates grids in the auxiliary basis
60 : !> \param auxbas_rs_desc real space grid in the auxiliary basis, be careful
61 : !> in parallel nsmax is chosen with multigrid in mind!
62 : !> \note
63 : !> be careful in parallel nsmax for the rs_grids is chosen with
64 : !> multigrid in mind! (well not as of this writing but...)
65 : !> \par History
66 : !> 10.2002 created [fawzi]
67 : !> 04.2003 added rs grid pools [fawzi]
68 : !> \author Fawzi Mohamed
69 : ! **************************************************************************************************
70 : TYPE pw_env_type
71 : INTEGER :: ref_count = -1
72 : INTEGER :: auxbas_grid = 0
73 : TYPE(pw_pool_p_type), DIMENSION(:), POINTER :: pw_pools => NULL()
74 : TYPE(pw_pool_type), POINTER :: xc_pw_pool => NULL()
75 : TYPE(pw_pool_type), POINTER :: vdw_pw_pool => NULL()
76 : TYPE(realspace_grid_desc_p_type), &
77 : DIMENSION(:), POINTER :: rs_descs => NULL()
78 : TYPE(realspace_grid_type), &
79 : DIMENSION(:), POINTER :: rs_grids => NULL()
80 : TYPE(gridlevel_info_type), POINTER :: gridlevel_info => NULL()
81 : TYPE(cube_info_type), DIMENSION(:), POINTER :: cube_info => NULL()
82 : TYPE(pw_poisson_type), POINTER :: poisson_env => NULL()
83 : TYPE(section_vals_type), POINTER :: interp_section => NULL()
84 : ! store current cell, used to rebuild lazily.
85 : REAL(KIND=dp), DIMENSION(3, 3) :: cell_hmat = -1.0_dp
86 : END TYPE pw_env_type
87 :
88 : CONTAINS
89 :
90 : ! **************************************************************************************************
91 : !> \brief returns the various attributes of the pw env
92 : !> \param pw_env the einvironment you want info about
93 : !> \param pw_pools ...
94 : !> \param cube_info ...
95 : !> \param gridlevel_info ...
96 : !> \param auxbas_pw_pool ...
97 : !> \param auxbas_grid ...
98 : !> \param auxbas_rs_desc ...
99 : !> \param auxbas_rs_grid ...
100 : !> \param rs_descs ...
101 : !> \param rs_grids ...
102 : !> \param xc_pw_pool ...
103 : !> \param vdw_pw_pool ...
104 : !> \param poisson_env ...
105 : !> \param interp_section ...
106 : !> \par History
107 : !> 10.2002 created [fawzi]
108 : !> \author Fawzi Mohamed
109 : ! **************************************************************************************************
110 1430830 : SUBROUTINE pw_env_get(pw_env, pw_pools, cube_info, gridlevel_info, &
111 : auxbas_pw_pool, auxbas_grid, auxbas_rs_desc, auxbas_rs_grid, rs_descs, rs_grids, &
112 : xc_pw_pool, vdw_pw_pool, poisson_env, interp_section)
113 : TYPE(pw_env_type), INTENT(IN) :: pw_env
114 : TYPE(pw_pool_p_type), DIMENSION(:), OPTIONAL, &
115 : POINTER :: pw_pools
116 : TYPE(cube_info_type), DIMENSION(:), OPTIONAL, &
117 : POINTER :: cube_info
118 : TYPE(gridlevel_info_type), OPTIONAL, POINTER :: gridlevel_info
119 : TYPE(pw_pool_type), OPTIONAL, POINTER :: auxbas_pw_pool
120 : INTEGER, INTENT(out), OPTIONAL :: auxbas_grid
121 : TYPE(realspace_grid_desc_type), OPTIONAL, POINTER :: auxbas_rs_desc
122 : TYPE(realspace_grid_type), OPTIONAL, POINTER :: auxbas_rs_grid
123 : TYPE(realspace_grid_desc_p_type), DIMENSION(:), &
124 : OPTIONAL, POINTER :: rs_descs
125 : TYPE(realspace_grid_type), DIMENSION(:), &
126 : OPTIONAL, POINTER :: rs_grids
127 : TYPE(pw_pool_type), OPTIONAL, POINTER :: xc_pw_pool, vdw_pw_pool
128 : TYPE(pw_poisson_type), OPTIONAL, POINTER :: poisson_env
129 : TYPE(section_vals_type), OPTIONAL, POINTER :: interp_section
130 :
131 1430830 : CPASSERT(pw_env%ref_count > 0)
132 1430830 : IF (PRESENT(pw_pools)) pw_pools => pw_env%pw_pools
133 1430830 : IF (PRESENT(rs_descs)) rs_descs => pw_env%rs_descs
134 1430830 : IF (PRESENT(rs_grids)) rs_grids => pw_env%rs_grids
135 1430830 : IF (PRESENT(cube_info)) cube_info => pw_env%cube_info
136 1430830 : IF (PRESENT(gridlevel_info)) gridlevel_info => pw_env%gridlevel_info
137 1430830 : IF (PRESENT(auxbas_pw_pool)) THEN
138 472034 : auxbas_pw_pool => pw_env%pw_pools(pw_env%auxbas_grid)%pool
139 : END IF
140 1430830 : IF (PRESENT(auxbas_rs_desc)) THEN
141 10744 : auxbas_rs_desc => pw_env%rs_descs(pw_env%auxbas_grid)%rs_desc
142 : END IF
143 1430830 : IF (PRESENT(auxbas_rs_grid)) THEN
144 26681 : auxbas_rs_grid => pw_env%rs_grids(pw_env%auxbas_grid)
145 : END IF
146 1430830 : IF (PRESENT(auxbas_grid)) auxbas_grid = pw_env%auxbas_grid
147 1430830 : IF (PRESENT(xc_pw_pool)) xc_pw_pool => pw_env%xc_pw_pool
148 1430830 : IF (PRESENT(vdw_pw_pool)) vdw_pw_pool => pw_env%vdw_pw_pool
149 1430830 : IF (PRESENT(poisson_env)) poisson_env => pw_env%poisson_env
150 1430830 : IF (PRESENT(interp_section)) interp_section => pw_env%interp_section
151 1430830 : END SUBROUTINE pw_env_get
152 :
153 : ! **************************************************************************************************
154 : !> \brief retains the pw_env (see doc/ReferenceCounting.html)
155 : !> \param pw_env the pw_env to retain
156 : !> \par History
157 : !> 10.2002 created [fawzi]
158 : !> \author Fawzi Mohamed
159 : ! **************************************************************************************************
160 7518 : SUBROUTINE pw_env_retain(pw_env)
161 : TYPE(pw_env_type), INTENT(INOUT) :: pw_env
162 :
163 7518 : CPASSERT(pw_env%ref_count > 0)
164 7518 : pw_env%ref_count = pw_env%ref_count + 1
165 7518 : END SUBROUTINE pw_env_retain
166 :
167 : ! **************************************************************************************************
168 : !> \brief releases the given pw_env (see doc/ReferenceCounting.html)
169 : !> \param pw_env the pw_env to release
170 : !> \param para_env ...
171 : !> \par History
172 : !> 10.2002 created [fawzi]
173 : !> \author Fawzi Mohamed
174 : ! **************************************************************************************************
175 22357 : SUBROUTINE pw_env_release(pw_env, para_env)
176 : TYPE(pw_env_type), POINTER :: pw_env
177 : TYPE(mp_para_env_type), INTENT(IN), OPTIONAL :: para_env
178 :
179 : INTEGER :: i, igrid_level
180 :
181 22357 : IF (ASSOCIATED(pw_env)) THEN
182 15198 : CPASSERT(pw_env%ref_count > 0)
183 15198 : pw_env%ref_count = pw_env%ref_count - 1
184 15198 : IF (pw_env%ref_count < 1) THEN
185 7680 : IF (ASSOCIATED(pw_env%poisson_env)) THEN
186 7658 : CALL pw_env%poisson_env%release()
187 7658 : DEALLOCATE (pw_env%poisson_env)
188 : END IF
189 7680 : CALL pw_pools_dealloc(pw_env%pw_pools)
190 7680 : IF (ASSOCIATED(pw_env%gridlevel_info)) THEN
191 7680 : CALL destroy_gaussian_gridlevel(pw_env%gridlevel_info, para_env)
192 7680 : DEALLOCATE (pw_env%gridlevel_info)
193 : END IF
194 7680 : IF (ASSOCIATED(pw_env%cube_info)) THEN
195 33844 : DO igrid_level = 1, SIZE(pw_env%cube_info)
196 33844 : CALL destroy_cube_info(pw_env%cube_info(igrid_level))
197 : END DO
198 7680 : DEALLOCATE (pw_env%cube_info)
199 : END IF
200 7680 : CALL pw_pool_release(pw_env%xc_pw_pool)
201 7680 : CALL pw_pool_release(pw_env%vdw_pw_pool)
202 7680 : IF (ASSOCIATED(pw_env%rs_descs)) THEN
203 33844 : DO i = 1, SIZE(pw_env%rs_descs)
204 33844 : CALL rs_grid_release_descriptor(pw_env%rs_descs(i)%rs_desc)
205 : END DO
206 7680 : DEALLOCATE (pw_env%rs_descs)
207 : END IF
208 7680 : IF (ASSOCIATED(pw_env%rs_grids)) THEN
209 33844 : DO i = 1, SIZE(pw_env%rs_grids)
210 33844 : CALL rs_grid_release(pw_env%rs_grids(i))
211 : END DO
212 7680 : DEALLOCATE (pw_env%rs_grids)
213 : END IF
214 7680 : DEALLOCATE (pw_env)
215 : END IF
216 : END IF
217 22357 : NULLIFY (pw_env)
218 22357 : END SUBROUTINE pw_env_release
219 :
220 0 : END MODULE pw_env_types
|