(git:374b731)
Loading...
Searching...
No Matches
ewald_pw_types.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 pw_types
10!> \author CJM
11! **************************************************************************************************
13 USE ao_util, ONLY: exp_radius
14 USE cell_types, ONLY: cell_type
20 USE dg_types, ONLY: dg_create,&
23 USE dgs, ONLY: dg_pme_grid_setup
28 USE kinds, ONLY: dp
29 USE mathconstants, ONLY: pi
30 USE message_passing, ONLY: mp_comm_self,&
32 USE pw_grid_types, ONLY: halfspace,&
34 USE pw_grids, ONLY: pw_grid_create,&
45 USE pw_pool_types, ONLY: pw_pool_create,&
49 USE realspace_grid_types, ONLY: &
53#include "./base/base_uses.f90"
54
55 IMPLICIT NONE
56
57 PRIVATE
58 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'ewald_pw_types'
62
63! **************************************************************************************************
65 PRIVATE
66 TYPE(pw_pool_type), POINTER :: pw_small_pool => null()
67 TYPE(pw_pool_type), POINTER :: pw_big_pool => null()
68 TYPE(realspace_grid_desc_type), POINTER :: rs_desc => null()
69 TYPE(pw_poisson_type), POINTER :: poisson_env => null()
70 TYPE(dg_type), POINTER :: dg => null()
71 END TYPE ewald_pw_type
72
73CONTAINS
74
75! **************************************************************************************************
76!> \brief creates the structure ewald_pw_type
77!> \param ewald_pw ...
78!> \param ewald_env ...
79!> \param cell ...
80!> \param cell_ref ...
81!> \param print_section ...
82! **************************************************************************************************
83 SUBROUTINE ewald_pw_create(ewald_pw, ewald_env, cell, cell_ref, print_section)
84 TYPE(ewald_pw_type), INTENT(OUT) :: ewald_pw
85 TYPE(ewald_environment_type), POINTER :: ewald_env
86 TYPE(cell_type), POINTER :: cell, cell_ref
87 TYPE(section_vals_type), POINTER :: print_section
88
89 NULLIFY (ewald_pw%pw_big_pool)
90 NULLIFY (ewald_pw%pw_small_pool)
91 NULLIFY (ewald_pw%rs_desc)
92 NULLIFY (ewald_pw%poisson_env)
93 ALLOCATE (ewald_pw%dg)
94 CALL dg_create(ewald_pw%dg)
95 CALL ewald_pw_init(ewald_pw, ewald_env, cell, cell_ref, print_section)
96 END SUBROUTINE ewald_pw_create
97
98! **************************************************************************************************
99!> \brief releases the memory used by the ewald_pw
100!> \param ewald_pw ...
101! **************************************************************************************************
102 SUBROUTINE ewald_pw_release(ewald_pw)
103 TYPE(ewald_pw_type), INTENT(INOUT) :: ewald_pw
104
105 CALL pw_pool_release(ewald_pw%pw_small_pool)
106 CALL pw_pool_release(ewald_pw%pw_big_pool)
107 CALL rs_grid_release_descriptor(ewald_pw%rs_desc)
108 IF (ASSOCIATED(ewald_pw%poisson_env)) THEN
109 CALL ewald_pw%poisson_env%release()
110 DEALLOCATE (ewald_pw%poisson_env)
111 END IF
112 CALL dg_release(ewald_pw%dg)
113 DEALLOCATE (ewald_pw%dg)
114
115 END SUBROUTINE ewald_pw_release
116
117! **************************************************************************************************
118!> \brief ...
119!> \param ewald_pw ...
120!> \param ewald_env ...
121!> \param cell ...
122!> \param cell_ref ...
123!> \param print_section ...
124!> \par History
125!> JGH (12-Jan-2001): Added SPME part
126!> JGH (15-Mar-2001): Work newly distributed between initialize, setup,
127!> and force routine
128!> \author CJM
129! **************************************************************************************************
130 SUBROUTINE ewald_pw_init(ewald_pw, ewald_env, cell, cell_ref, print_section)
131 TYPE(ewald_pw_type), INTENT(INOUT) :: ewald_pw
132 TYPE(ewald_environment_type), POINTER :: ewald_env
133 TYPE(cell_type), POINTER :: cell, cell_ref
134 TYPE(section_vals_type), POINTER :: print_section
135
136 CHARACTER(len=*), PARAMETER :: routinen = 'ewald_pw_init'
137
138 INTEGER :: bo(2, 3), ewald_type, gmax(3), handle, &
139 npts_s(3), ns_max, o_spline, &
140 output_unit
141 REAL(kind=dp) :: alpha, alphasq, cutoff_radius, epsilon, &
142 norm
143 TYPE(cp_logger_type), POINTER :: logger
144 TYPE(mp_para_env_type), POINTER :: para_env
145 TYPE(pw_grid_type), POINTER :: pw_big_grid, pw_small_grid
146 TYPE(pw_poisson_parameter_type) :: poisson_params
147 TYPE(pw_pool_p_type), DIMENSION(:), POINTER :: pw_pools
148 TYPE(pw_pool_type), POINTER :: pw_pool
149 TYPE(realspace_grid_desc_type), POINTER :: rs_desc
150 TYPE(realspace_grid_input_type) :: input_settings
151 TYPE(section_vals_type), POINTER :: poisson_section, rs_grid_section
152
153 CALL timeset(routinen, handle)
154
155 NULLIFY (pw_big_grid)
156 NULLIFY (pw_small_grid, poisson_section)
157
158 cpassert(ASSOCIATED(ewald_env))
159 cpassert(ASSOCIATED(cell))
160 CALL ewald_env_get(ewald_env=ewald_env, &
161 para_env=para_env, &
162 gmax=gmax, alpha=alpha, &
163 ns_max=ns_max, &
164 ewald_type=ewald_type, &
165 o_spline=o_spline, &
166 poisson_section=poisson_section, &
167 epsilon=epsilon)
168
169 rs_grid_section => section_vals_get_subs_vals(poisson_section, "EWALD%RS_GRID")
170
171 SELECT CASE (ewald_type)
172 CASE (do_ewald_ewald)
173 ! set up Classic EWALD sum
174 logger => cp_get_default_logger()
175 output_unit = cp_print_key_unit_nr(logger, print_section, "", extension=".Log")
176 CALL pw_grid_create(pw_big_grid, mp_comm_self)
177
178 IF (any(gmax == 2*(gmax/2))) THEN
179 cpabort("gmax has to be odd.")
180 END IF
181 bo(1, :) = -gmax/2
182 bo(2, :) = +gmax/2
183 CALL pw_grid_setup(cell_ref%hmat, pw_big_grid, grid_span=halfspace, bounds=bo, spherical=.true., &
184 fft_usage=.false., iounit=output_unit)
185 NULLIFY (pw_pool)
186 CALL pw_pool_create(pw_pool, pw_grid=pw_big_grid)
187 ewald_pw%pw_big_pool => pw_pool
188 CALL pw_grid_release(pw_big_grid)
189 CALL cp_print_key_finished_output(output_unit, logger, print_section, "")
190
191 CASE (do_ewald_pme)
192 ! set up Particle-Mesh EWALD sum
193 logger => cp_get_default_logger()
194 output_unit = cp_print_key_unit_nr(logger, print_section, "", extension=".Log")
195 IF (.NOT. ASSOCIATED(ewald_pw%poisson_env)) THEN
196 ALLOCATE (ewald_pw%poisson_env)
197 CALL ewald_pw%poisson_env%create()
198 END IF
199 CALL pw_grid_create(pw_small_grid, mp_comm_self)
200 CALL pw_grid_create(pw_big_grid, para_env)
201 IF (ns_max == 2*(ns_max/2)) THEN
202 cpabort("ns_max has to be odd.")
203 END IF
204 npts_s(:) = ns_max
205 ! compute cut-off radius
206 alphasq = alpha**2
207 norm = (2.0_dp*alphasq/pi)**(1.5_dp)
208 cutoff_radius = exp_radius(0, 2.0_dp*alphasq, epsilon, norm)
209
210 CALL dg_pme_grid_setup(cell_ref%hmat, npts_s, cutoff_radius, &
211 pw_small_grid, pw_big_grid, rs_dims=(/para_env%num_pe, 1/), &
212 iounit=output_unit, fft_usage=.true.)
213 ! Write some useful info
214 IF (output_unit > 0) THEN
215 WRITE (output_unit, '( A,T71,E10.4 )') &
216 ' EWALD| Gaussian tolerance (effective) ', epsilon
217 WRITE (output_unit, '( A,T63,3I6 )') &
218 ' EWALD| Small box grid ', pw_small_grid%npts
219 WRITE (output_unit, '( A,T63,3I6 )') &
220 ' EWALD| Full box grid ', pw_big_grid%npts
221 END IF
222
223 ! pw pools initialized
224 NULLIFY (pw_pool)
225 CALL pw_pool_create(pw_pool, pw_grid=pw_big_grid)
226 ewald_pw%pw_big_pool => pw_pool
227
228 NULLIFY (pw_pool)
229 CALL pw_pool_create(pw_pool, pw_grid=pw_small_grid)
230 ewald_pw%pw_small_pool => pw_pool
231
232 NULLIFY (rs_desc)
233 CALL init_input_type(input_settings, nsmax=maxval(pw_small_grid%npts(1:3)), &
234 rs_grid_section=rs_grid_section, ilevel=1, &
235 higher_grid_layout=(/-1, -1, -1/))
236 CALL rs_grid_create_descriptor(rs_desc, pw_big_grid, input_settings)
237
238 block
239 TYPE(realspace_grid_type) :: rs
240 CALL rs_grid_create(rs, rs_desc)
241 CALL rs_grid_print(rs, output_unit)
242 CALL rs_grid_release(rs)
243 END block
244
245 CALL cp_print_key_finished_output(output_unit, logger, print_section, "")
246
247 ewald_pw%rs_desc => rs_desc
248
249 CALL rs_grid_retain_descriptor(ewald_pw%rs_desc)
250 CALL rs_grid_release_descriptor(rs_desc)
251
252 CALL pw_grid_release(pw_small_grid)
253 CALL pw_grid_release(pw_big_grid)
254
255 CASE (do_ewald_spme)
256 ! set up the Smooth-Particle-Mesh EWALD sum
257 logger => cp_get_default_logger()
258 output_unit = cp_print_key_unit_nr(logger, print_section, "", extension=".Log")
259 IF (.NOT. ASSOCIATED(ewald_pw%poisson_env)) THEN
260 ALLOCATE (ewald_pw%poisson_env)
261 CALL ewald_pw%poisson_env%create()
262 END IF
263 CALL pw_grid_create(pw_big_grid, para_env)
264 npts_s = gmax
265 CALL pw_grid_setup(cell_ref%hmat, pw_big_grid, grid_span=halfspace, npts=npts_s, spherical=.true., &
266 rs_dims=(/para_env%num_pe, 1/), iounit=output_unit, fft_usage=.true.)
267
268 ! pw pools initialized
269 NULLIFY (pw_pool)
270 CALL pw_pool_create(pw_pool, pw_grid=pw_big_grid)
271 ewald_pw%pw_big_pool => pw_pool
272
273 NULLIFY (rs_desc)
274 CALL init_input_type(input_settings, nsmax=o_spline, &
275 rs_grid_section=rs_grid_section, ilevel=1, &
276 higher_grid_layout=(/-1, -1, -1/))
277 CALL rs_grid_create_descriptor(rs_desc, pw_big_grid, input_settings)
278
279 block
280 TYPE(realspace_grid_type) :: rs
281
282 CALL rs_grid_create(rs, rs_desc)
283 CALL rs_grid_print(rs, output_unit)
284 CALL rs_grid_release(rs)
285 END block
286 CALL cp_print_key_finished_output(output_unit, logger, print_section, "")
287
288 ewald_pw%rs_desc => rs_desc
289
290 CALL rs_grid_retain_descriptor(ewald_pw%rs_desc)
291 CALL rs_grid_release_descriptor(rs_desc)
292
293 CALL pw_grid_release(pw_big_grid)
294 CASE (do_ewald_none)
295 ! No EWALD sums..
296 CASE default
297 cpabort("")
298 END SELECT
299 ! Poisson Environment
300 IF (ASSOCIATED(ewald_pw%poisson_env)) THEN
301 ALLOCATE (pw_pools(1))
302 pw_pools(1)%pool => ewald_pw%pw_big_pool
303 CALL pw_poisson_read_parameters(poisson_section, poisson_params)
304 poisson_params%ewald_type = ewald_type
305 poisson_params%ewald_o_spline = o_spline
306 poisson_params%ewald_alpha = alpha
307 CALL pw_poisson_set(ewald_pw%poisson_env, cell_hmat=cell%hmat, parameters=poisson_params, &
308 use_level=1, pw_pools=pw_pools)
309 DEALLOCATE (pw_pools)
310 END IF
311 CALL timestop(handle)
312 END SUBROUTINE ewald_pw_init
313
314! **************************************************************************************************
315!> \brief get the ewald_pw environment to the correct program.
316!> \param ewald_pw ...
317!> \param pw_big_pool ...
318!> \param pw_small_pool ...
319!> \param rs_desc ...
320!> \param poisson_env ...
321!> \param dg ...
322!> \author CJM
323! **************************************************************************************************
324 SUBROUTINE ewald_pw_get(ewald_pw, pw_big_pool, pw_small_pool, rs_desc, poisson_env, dg)
325
326 TYPE(ewald_pw_type), INTENT(IN) :: ewald_pw
327 TYPE(pw_pool_type), OPTIONAL, POINTER :: pw_big_pool, pw_small_pool
328 TYPE(realspace_grid_desc_type), OPTIONAL, POINTER :: rs_desc
329 TYPE(pw_poisson_type), OPTIONAL, POINTER :: poisson_env
330 TYPE(dg_type), OPTIONAL, POINTER :: dg
331
332 IF (PRESENT(poisson_env)) poisson_env => ewald_pw%poisson_env
333 IF (PRESENT(pw_big_pool)) pw_big_pool => ewald_pw%pw_big_pool
334 IF (PRESENT(pw_small_pool)) pw_small_pool => ewald_pw%pw_small_pool
335 IF (PRESENT(rs_desc)) rs_desc => ewald_pw%rs_desc
336 IF (PRESENT(dg)) dg => ewald_pw%dg
337
338 END SUBROUTINE ewald_pw_get
339
340! **************************************************************************************************
341!> \brief set the ewald_pw environment to the correct program.
342!> \param ewald_pw ...
343!> \param pw_big_pool ...
344!> \param pw_small_pool ...
345!> \param rs_desc ...
346!> \param dg ...
347!> \param poisson_env ...
348!> \author CJM
349! **************************************************************************************************
350 SUBROUTINE ewald_pw_set(ewald_pw, pw_big_pool, pw_small_pool, rs_desc, dg, &
351 poisson_env)
352
353 TYPE(ewald_pw_type), INTENT(INOUT) :: ewald_pw
354 TYPE(pw_pool_type), OPTIONAL, POINTER :: pw_big_pool, pw_small_pool
355 TYPE(realspace_grid_desc_type), OPTIONAL, POINTER :: rs_desc
356 TYPE(dg_type), OPTIONAL, POINTER :: dg
357 TYPE(pw_poisson_type), OPTIONAL, POINTER :: poisson_env
358
359 IF (PRESENT(pw_big_pool)) THEN
360 CALL pw_big_pool%retain()
361 CALL pw_pool_release(ewald_pw%pw_big_pool)
362 ewald_pw%pw_big_pool => pw_big_pool
363 END IF
364 IF (PRESENT(pw_small_pool)) THEN
365 CALL pw_small_pool%retain()
366 CALL pw_pool_release(ewald_pw%pw_small_pool)
367 ewald_pw%pw_small_pool => pw_small_pool
368 END IF
369 IF (PRESENT(rs_desc)) THEN
370 CALL rs_grid_retain_descriptor(rs_desc)
371 CALL rs_grid_release_descriptor(ewald_pw%rs_desc)
372 ewald_pw%rs_desc => rs_desc
373 END IF
374 IF (PRESENT(dg)) THEN
375 CALL dg_release(ewald_pw%dg)
376 ewald_pw%dg => dg
377 END IF
378 IF (PRESENT(poisson_env)) THEN
379 IF (ASSOCIATED(ewald_pw%poisson_env)) THEN
380 IF (.NOT. ASSOCIATED(ewald_pw%poisson_env, poisson_env)) THEN
381 CALL ewald_pw%poisson_env%release()
382 DEALLOCATE (ewald_pw%poisson_env)
383 END IF
384 END IF
385 ewald_pw%poisson_env => poisson_env
386 END IF
387
388 END SUBROUTINE ewald_pw_set
389
390END MODULE ewald_pw_types
All kind of helpful little routines.
Definition ao_util.F:14
real(kind=dp) function, public exp_radius(l, alpha, threshold, prefactor, epsabs, epsrel, rlow)
The radius of a primitive Gaussian function for a given threshold is calculated. g(r) = prefactor*r**...
Definition ao_util.F:96
Handles all functions related to the CELL.
Definition cell_types.F:15
various routines to log and control the output. The idea is that decisions about where to log should ...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout)
...
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
subroutine, public init_input_type(input_settings, nsmax, rs_grid_section, ilevel, higher_grid_layout)
parses an input section to assign the proper values to the input type
subroutine, public dg_create(dg)
create the dg structure
Definition dg_types.F:57
subroutine, public dg_release(dg)
releases the given dg_type
Definition dg_types.F:73
Definition dgs.F:13
subroutine, public dg_pme_grid_setup(b_cell_hmat, npts_s, cutoff_radius, grid_s, grid_b, grid_ref, rs_dims, iounit, fft_usage)
...
Definition dgs.F:94
subroutine, public ewald_env_get(ewald_env, ewald_type, alpha, eps_pol, epsilon, gmax, ns_max, o_spline, group, para_env, poisson_section, precs, rcut, do_multipoles, max_multipole, do_ipol, max_ipol_iter, interaction_cutoffs, cell_hmat)
Purpose: Get the EWALD environment.
subroutine, public ewald_pw_set(ewald_pw, pw_big_pool, pw_small_pool, rs_desc, dg, poisson_env)
set the ewald_pw environment to the correct program.
subroutine, public ewald_pw_get(ewald_pw, pw_big_pool, pw_small_pool, rs_desc, poisson_env, dg)
get the ewald_pw environment to the correct program.
subroutine, public ewald_pw_release(ewald_pw)
releases the memory used by the ewald_pw
subroutine, public ewald_pw_create(ewald_pw, ewald_env, cell, cell_ref, print_section)
creates the structure ewald_pw_type
objects that represent the structure of input sections and the data contained in an input section
recursive type(section_vals_type) function, pointer, public section_vals_get_subs_vals(section_vals, subsection_name, i_rep_section, can_return_null)
returns the values of the requested subsection
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Definition of mathematical constants and functions.
real(kind=dp), parameter, public pi
Interface to the message passing library MPI.
type(mp_comm_type), parameter, public mp_comm_self
integer, parameter, public halfspace
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_setup(cell_hmat, pw_grid, grid_span, cutoff, bounds, bounds_local, npts, spherical, odd, fft_usage, ncommensurate, icommensurate, blocked, ref_grid, rs_dims, iounit)
sets up a pw_grid
Definition pw_grids.F:286
subroutine, public pw_grid_create(pw_grid, pe_group, local)
Initialize a PW grid with all defaults.
Definition pw_grids.F:93
subroutine, public pw_poisson_set(poisson_env, cell_hmat, parameters, pw_pools, use_level, mt_super_ref_pw_grid, dct_pw_grid, force_rebuild)
sets cell, grids and parameters used by the poisson solver You should call this at least once (and se...
Reading of input parameters for the pw_poisson-modules.
subroutine, public pw_poisson_read_parameters(poisson_section, params)
Reads the POISSON input-section and into pw_poisson_parameter_type.
functions related to the poisson solver on regular grids
integer, parameter, public do_ewald_pme
integer, parameter, public do_ewald_ewald
integer, parameter, public do_ewald_none
integer, parameter, public do_ewald_spme
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
subroutine, public pw_pool_release(pool)
releases the given pool (see cp2k/doc/ReferenceCounting.html)
subroutine, public pw_pool_create(pool, pw_grid, max_cache)
creates a pool for pw
subroutine, public rs_grid_print(rs, iounit)
Print information on grids to output.
subroutine, public rs_grid_create(rs, desc)
...
subroutine, public rs_grid_create_descriptor(desc, pw_grid, input_settings, border_points)
Determine the setup of real space grids - this is divided up into the creation of a descriptor and th...
subroutine, public rs_grid_retain_descriptor(rs_desc)
retains the given rs grid descriptor (see doc/ReferenceCounting.html)
subroutine, public rs_grid_release_descriptor(rs_desc)
releases the given rs grid descriptor (see doc/ReferenceCounting.html)
subroutine, public rs_grid_release(rs_grid)
releases the given rs grid (see doc/ReferenceCounting.html)
Type defining parameters related to the simulation cell.
Definition cell_types.F:55
type of a logger, at the moment it contains just a print level starting at which level it should be l...
stores all the informations relevant to an mpi environment
parameters for the poisson solver independet of input_section
environment for the poisson solver
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 ...