(git:d18deda)
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-2025 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,&
44 USE pw_pool_types, ONLY: pw_pool_create,&
48 USE realspace_grid_types, ONLY: &
52#include "./base/base_uses.f90"
53
54 IMPLICIT NONE
55
56 PRIVATE
57 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'ewald_pw_types'
61
62! **************************************************************************************************
64 PRIVATE
65 TYPE(pw_pool_type), POINTER :: pw_small_pool => null()
66 TYPE(pw_pool_type), POINTER :: pw_big_pool => null()
67 TYPE(realspace_grid_desc_type), POINTER :: rs_desc => null()
68 TYPE(pw_poisson_type), POINTER :: poisson_env => null()
69 TYPE(dg_type), POINTER :: dg => null()
70 END TYPE ewald_pw_type
71
72CONTAINS
73
74! **************************************************************************************************
75!> \brief creates the structure ewald_pw_type
76!> \param ewald_pw ...
77!> \param ewald_env ...
78!> \param cell ...
79!> \param cell_ref ...
80!> \param print_section ...
81! **************************************************************************************************
82 SUBROUTINE ewald_pw_create(ewald_pw, ewald_env, cell, cell_ref, print_section)
83 TYPE(ewald_pw_type), INTENT(OUT) :: ewald_pw
84 TYPE(ewald_environment_type), POINTER :: ewald_env
85 TYPE(cell_type), POINTER :: cell, cell_ref
86 TYPE(section_vals_type), POINTER :: print_section
87
88 NULLIFY (ewald_pw%pw_big_pool)
89 NULLIFY (ewald_pw%pw_small_pool)
90 NULLIFY (ewald_pw%rs_desc)
91 NULLIFY (ewald_pw%poisson_env)
92 ALLOCATE (ewald_pw%dg)
93 CALL dg_create(ewald_pw%dg)
94 CALL ewald_pw_init(ewald_pw, ewald_env, cell, cell_ref, print_section)
95 END SUBROUTINE ewald_pw_create
96
97! **************************************************************************************************
98!> \brief releases the memory used by the ewald_pw
99!> \param ewald_pw ...
100! **************************************************************************************************
101 SUBROUTINE ewald_pw_release(ewald_pw)
102 TYPE(ewald_pw_type), INTENT(INOUT) :: ewald_pw
103
104 CALL pw_pool_release(ewald_pw%pw_small_pool)
105 CALL pw_pool_release(ewald_pw%pw_big_pool)
106 CALL rs_grid_release_descriptor(ewald_pw%rs_desc)
107 IF (ASSOCIATED(ewald_pw%poisson_env)) THEN
108 CALL ewald_pw%poisson_env%release()
109 DEALLOCATE (ewald_pw%poisson_env)
110 END IF
111 CALL dg_release(ewald_pw%dg)
112 DEALLOCATE (ewald_pw%dg)
113
114 END SUBROUTINE ewald_pw_release
115
116! **************************************************************************************************
117!> \brief ...
118!> \param ewald_pw ...
119!> \param ewald_env ...
120!> \param cell ...
121!> \param cell_ref ...
122!> \param print_section ...
123!> \par History
124!> JGH (12-Jan-2001): Added SPME part
125!> JGH (15-Mar-2001): Work newly distributed between initialize, setup,
126!> and force routine
127!> \author CJM
128! **************************************************************************************************
129 SUBROUTINE ewald_pw_init(ewald_pw, ewald_env, cell, cell_ref, print_section)
130 TYPE(ewald_pw_type), INTENT(INOUT) :: ewald_pw
131 TYPE(ewald_environment_type), POINTER :: ewald_env
132 TYPE(cell_type), POINTER :: cell, cell_ref
133 TYPE(section_vals_type), POINTER :: print_section
134
135 CHARACTER(len=*), PARAMETER :: routinen = 'ewald_pw_init'
136
137 INTEGER :: bo(2, 3), ewald_type, gmax(3), handle, &
138 npts_s(3), ns_max, o_spline, &
139 output_unit
140 REAL(kind=dp) :: alpha, alphasq, cutoff_radius, epsilon, &
141 norm
142 TYPE(cp_logger_type), POINTER :: logger
143 TYPE(mp_para_env_type), POINTER :: para_env
144 TYPE(pw_grid_type), POINTER :: pw_big_grid, pw_small_grid
145 TYPE(pw_poisson_parameter_type) :: poisson_params
146 TYPE(pw_pool_p_type), DIMENSION(:), POINTER :: pw_pools
147 TYPE(pw_pool_type), POINTER :: pw_pool
148 TYPE(realspace_grid_desc_type), POINTER :: rs_desc
149 TYPE(realspace_grid_input_type) :: input_settings
150 TYPE(section_vals_type), POINTER :: poisson_section, rs_grid_section
151
152 CALL timeset(routinen, handle)
153
154 NULLIFY (pw_big_grid)
155 NULLIFY (pw_small_grid, poisson_section)
156
157 cpassert(ASSOCIATED(ewald_env))
158 cpassert(ASSOCIATED(cell))
159 CALL ewald_env_get(ewald_env=ewald_env, &
160 para_env=para_env, &
161 gmax=gmax, alpha=alpha, &
162 ns_max=ns_max, &
163 ewald_type=ewald_type, &
164 o_spline=o_spline, &
165 poisson_section=poisson_section, &
166 epsilon=epsilon)
167
168 rs_grid_section => section_vals_get_subs_vals(poisson_section, "EWALD%RS_GRID")
169
170 SELECT CASE (ewald_type)
171 CASE (do_ewald_ewald)
172 ! set up Classic EWALD sum
173 logger => cp_get_default_logger()
174 output_unit = cp_print_key_unit_nr(logger, print_section, "", extension=".Log")
175
176 IF (any(gmax == 2*(gmax/2))) THEN
177 cpabort("gmax has to be odd.")
178 END IF
179 bo(1, :) = -gmax/2
180 bo(2, :) = +gmax/2
181 CALL pw_grid_create(pw_big_grid, mp_comm_self, cell_ref%hmat, grid_span=halfspace, bounds=bo, spherical=.true., &
182 fft_usage=.false., iounit=output_unit)
183 NULLIFY (pw_pool)
184 CALL pw_pool_create(pw_pool, pw_grid=pw_big_grid)
185 ewald_pw%pw_big_pool => pw_pool
186 CALL pw_grid_release(pw_big_grid)
187 CALL cp_print_key_finished_output(output_unit, logger, print_section, "")
188
189 CASE (do_ewald_pme)
190 ! set up Particle-Mesh EWALD sum
191 logger => cp_get_default_logger()
192 output_unit = cp_print_key_unit_nr(logger, print_section, "", extension=".Log")
193 IF (.NOT. ASSOCIATED(ewald_pw%poisson_env)) THEN
194 ALLOCATE (ewald_pw%poisson_env)
195 CALL ewald_pw%poisson_env%create()
196 END IF
197 IF (ns_max == 2*(ns_max/2)) THEN
198 cpabort("ns_max has to be odd.")
199 END IF
200 npts_s(:) = ns_max
201 ! compute cut-off radius
202 alphasq = alpha**2
203 norm = (2.0_dp*alphasq/pi)**(1.5_dp)
204 cutoff_radius = exp_radius(0, 2.0_dp*alphasq, epsilon, norm)
205
206 CALL dg_pme_grid_setup(cell_ref%hmat, npts_s, cutoff_radius, &
207 pw_small_grid, pw_big_grid, para_env, rs_dims=(/para_env%num_pe, 1/), &
208 iounit=output_unit, fft_usage=.true.)
209 ! Write some useful info
210 IF (output_unit > 0) THEN
211 WRITE (output_unit, '( A,T71,E10.4 )') &
212 ' EWALD| Gaussian tolerance (effective) ', epsilon
213 WRITE (output_unit, '( A,T63,3I6 )') &
214 ' EWALD| Small box grid ', pw_small_grid%npts
215 WRITE (output_unit, '( A,T63,3I6 )') &
216 ' EWALD| Full box grid ', pw_big_grid%npts
217 END IF
218
219 ! pw pools initialized
220 NULLIFY (pw_pool)
221 CALL pw_pool_create(pw_pool, pw_grid=pw_big_grid)
222 ewald_pw%pw_big_pool => pw_pool
223
224 NULLIFY (pw_pool)
225 CALL pw_pool_create(pw_pool, pw_grid=pw_small_grid)
226 ewald_pw%pw_small_pool => pw_pool
227
228 NULLIFY (rs_desc)
229 CALL init_input_type(input_settings, nsmax=maxval(pw_small_grid%npts(1:3)), &
230 rs_grid_section=rs_grid_section, ilevel=1, &
231 higher_grid_layout=(/-1, -1, -1/))
232 CALL rs_grid_create_descriptor(rs_desc, pw_big_grid, input_settings)
233
234 block
235 TYPE(realspace_grid_type) :: rs
236 CALL rs_grid_create(rs, rs_desc)
237 CALL rs_grid_print(rs, output_unit)
238 CALL rs_grid_release(rs)
239 END block
240
241 CALL cp_print_key_finished_output(output_unit, logger, print_section, "")
242
243 ewald_pw%rs_desc => rs_desc
244
245 CALL rs_grid_retain_descriptor(ewald_pw%rs_desc)
246 CALL rs_grid_release_descriptor(rs_desc)
247
248 CALL pw_grid_release(pw_small_grid)
249 CALL pw_grid_release(pw_big_grid)
250
251 CASE (do_ewald_spme)
252 ! set up the Smooth-Particle-Mesh EWALD sum
253 logger => cp_get_default_logger()
254 output_unit = cp_print_key_unit_nr(logger, print_section, "", extension=".Log")
255 IF (.NOT. ASSOCIATED(ewald_pw%poisson_env)) THEN
256 ALLOCATE (ewald_pw%poisson_env)
257 CALL ewald_pw%poisson_env%create()
258 END IF
259 npts_s = gmax
260 CALL pw_grid_create(pw_big_grid, para_env, cell_ref%hmat, grid_span=halfspace, npts=npts_s, spherical=.true., &
261 rs_dims=(/para_env%num_pe, 1/), iounit=output_unit, fft_usage=.true.)
262
263 ! pw pools initialized
264 NULLIFY (pw_pool)
265 CALL pw_pool_create(pw_pool, pw_grid=pw_big_grid)
266 ewald_pw%pw_big_pool => pw_pool
267
268 NULLIFY (rs_desc)
269 CALL init_input_type(input_settings, nsmax=o_spline, &
270 rs_grid_section=rs_grid_section, ilevel=1, &
271 higher_grid_layout=(/-1, -1, -1/))
272 CALL rs_grid_create_descriptor(rs_desc, pw_big_grid, input_settings)
273
274 block
275 TYPE(realspace_grid_type) :: rs
276
277 CALL rs_grid_create(rs, rs_desc)
278 CALL rs_grid_print(rs, output_unit)
279 CALL rs_grid_release(rs)
280 END block
281 CALL cp_print_key_finished_output(output_unit, logger, print_section, "")
282
283 ewald_pw%rs_desc => rs_desc
284
285 CALL rs_grid_retain_descriptor(ewald_pw%rs_desc)
286 CALL rs_grid_release_descriptor(rs_desc)
287
288 CALL pw_grid_release(pw_big_grid)
289 CASE (do_ewald_none)
290 ! No EWALD sums..
291 CASE default
292 cpabort("")
293 END SELECT
294 ! Poisson Environment
295 IF (ASSOCIATED(ewald_pw%poisson_env)) THEN
296 ALLOCATE (pw_pools(1))
297 pw_pools(1)%pool => ewald_pw%pw_big_pool
298 CALL pw_poisson_read_parameters(poisson_section, poisson_params)
299 poisson_params%ewald_type = ewald_type
300 poisson_params%ewald_o_spline = o_spline
301 poisson_params%ewald_alpha = alpha
302 CALL pw_poisson_set(ewald_pw%poisson_env, cell_hmat=cell%hmat, parameters=poisson_params, &
303 use_level=1, pw_pools=pw_pools)
304 DEALLOCATE (pw_pools)
305 END IF
306 CALL timestop(handle)
307 END SUBROUTINE ewald_pw_init
308
309! **************************************************************************************************
310!> \brief get the ewald_pw environment to the correct program.
311!> \param ewald_pw ...
312!> \param pw_big_pool ...
313!> \param pw_small_pool ...
314!> \param rs_desc ...
315!> \param poisson_env ...
316!> \param dg ...
317!> \author CJM
318! **************************************************************************************************
319 SUBROUTINE ewald_pw_get(ewald_pw, pw_big_pool, pw_small_pool, rs_desc, poisson_env, dg)
320
321 TYPE(ewald_pw_type), INTENT(IN) :: ewald_pw
322 TYPE(pw_pool_type), OPTIONAL, POINTER :: pw_big_pool, pw_small_pool
323 TYPE(realspace_grid_desc_type), OPTIONAL, POINTER :: rs_desc
324 TYPE(pw_poisson_type), OPTIONAL, POINTER :: poisson_env
325 TYPE(dg_type), OPTIONAL, POINTER :: dg
326
327 IF (PRESENT(poisson_env)) poisson_env => ewald_pw%poisson_env
328 IF (PRESENT(pw_big_pool)) pw_big_pool => ewald_pw%pw_big_pool
329 IF (PRESENT(pw_small_pool)) pw_small_pool => ewald_pw%pw_small_pool
330 IF (PRESENT(rs_desc)) rs_desc => ewald_pw%rs_desc
331 IF (PRESENT(dg)) dg => ewald_pw%dg
332
333 END SUBROUTINE ewald_pw_get
334
335! **************************************************************************************************
336!> \brief set the ewald_pw environment to the correct program.
337!> \param ewald_pw ...
338!> \param pw_big_pool ...
339!> \param pw_small_pool ...
340!> \param rs_desc ...
341!> \param dg ...
342!> \param poisson_env ...
343!> \author CJM
344! **************************************************************************************************
345 SUBROUTINE ewald_pw_set(ewald_pw, pw_big_pool, pw_small_pool, rs_desc, dg, &
346 poisson_env)
347
348 TYPE(ewald_pw_type), INTENT(INOUT) :: ewald_pw
349 TYPE(pw_pool_type), OPTIONAL, POINTER :: pw_big_pool, pw_small_pool
350 TYPE(realspace_grid_desc_type), OPTIONAL, POINTER :: rs_desc
351 TYPE(dg_type), OPTIONAL, POINTER :: dg
352 TYPE(pw_poisson_type), OPTIONAL, POINTER :: poisson_env
353
354 IF (PRESENT(pw_big_pool)) THEN
355 CALL pw_big_pool%retain()
356 CALL pw_pool_release(ewald_pw%pw_big_pool)
357 ewald_pw%pw_big_pool => pw_big_pool
358 END IF
359 IF (PRESENT(pw_small_pool)) THEN
360 CALL pw_small_pool%retain()
361 CALL pw_pool_release(ewald_pw%pw_small_pool)
362 ewald_pw%pw_small_pool => pw_small_pool
363 END IF
364 IF (PRESENT(rs_desc)) THEN
365 CALL rs_grid_retain_descriptor(rs_desc)
366 CALL rs_grid_release_descriptor(ewald_pw%rs_desc)
367 ewald_pw%rs_desc => rs_desc
368 END IF
369 IF (PRESENT(dg)) THEN
370 CALL dg_release(ewald_pw%dg)
371 ewald_pw%dg => dg
372 END IF
373 IF (PRESENT(poisson_env)) THEN
374 IF (ASSOCIATED(ewald_pw%poisson_env)) THEN
375 IF (.NOT. ASSOCIATED(ewald_pw%poisson_env, poisson_env)) THEN
376 CALL ewald_pw%poisson_env%release()
377 DEALLOCATE (ewald_pw%poisson_env)
378 END IF
379 END IF
380 ewald_pw%poisson_env => poisson_env
381 END IF
382
383 END SUBROUTINE ewald_pw_set
384
385END 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, mp_comm, grid_ref, rs_dims, iounit, fft_usage)
...
Definition dgs.F:97
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:2163
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 ...