(git:34ef472)
pw_env_methods.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 methods of pw_env that have dependence on qs_env
10 !> \par History
11 !> 10.2002 created [fawzi]
12 !> JGH (22-Feb-03) PW grid options added
13 !> 04.2003 added rs grid pools [fawzi]
14 !> 02.2004 added commensurate grids
15 !> \author Fawzi Mohamed
16 ! **************************************************************************************************
18  USE ao_util, ONLY: exp_radius
20  gto_basis_set_type
21  USE cell_types, ONLY: cell_type
22  USE cp_control_types, ONLY: dft_control_type
24  cp_logger_type
25  USE cp_output_handling, ONLY: cp_p_file,&
30  USE cube_utils, ONLY: destroy_cube_info,&
33  USE d3_poly, ONLY: init_d3_poly_module
34  USE dct, ONLY: neumannx,&
35  neumannxy,&
36  neumannxyz,&
37  neumannxz,&
38  neumanny,&
39  neumannyz,&
40  neumannz,&
42  USE dielectric_types, ONLY: derivative_cd3,&
49  USE input_constants, ONLY: do_method_gapw,&
59  section_vals_type,&
61  USE kinds, ONLY: dp
62  USE message_passing, ONLY: mp_para_env_type
63  USE ps_implicit_types, ONLY: mixed_bc,&
65  neumann_bc,&
67  USE ps_wavelet_types, ONLY: wavelet0d,&
68  wavelet2d,&
69  wavelet3d
70  USE pw_env_types, ONLY: pw_env_type
72  USE pw_grid_types, ONLY: fullspace,&
73  halfspace,&
74  pw_grid_type
87  pw_poisson_parameter_type,&
90  USE pw_pool_types, ONLY: pw_pool_create,&
91  pw_pool_p_type,&
94  USE qs_dispersion_types, ONLY: qs_dispersion_type
95  USE qs_environment_types, ONLY: get_qs_env,&
96  qs_environment_type
97  USE qs_kind_types, ONLY: get_qs_kind,&
98  qs_kind_type
99  USE qs_rho0_types, ONLY: get_rho0_mpole,&
100  rho0_mpole_type
101  USE realspace_grid_types, ONLY: &
102  realspace_grid_desc_p_type, realspace_grid_desc_type, realspace_grid_input_type, &
103  realspace_grid_type, rs_grid_create, rs_grid_create_descriptor, rs_grid_print, &
105  USE xc_input_constants, ONLY: &
109 #include "./base/base_uses.f90"
110 
111  IMPLICIT NONE
112  PRIVATE
113 
114  LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .true.
115  CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'pw_env_methods'
116 
117  PUBLIC :: pw_env_create, pw_env_rebuild
118 !***
119 CONTAINS
120 
121 ! **************************************************************************************************
122 !> \brief creates a pw_env, if qs_env is given calls pw_env_rebuild
123 !> \param pw_env the pw_env that gets created
124 !> \par History
125 !> 10.2002 created [fawzi]
126 !> \author Fawzi Mohamed
127 ! **************************************************************************************************
128  SUBROUTINE pw_env_create(pw_env)
129  TYPE(pw_env_type), POINTER :: pw_env
130 
131  CHARACTER(len=*), PARAMETER :: routinen = 'pw_env_create'
132 
133  INTEGER :: handle
134 
135  CALL timeset(routinen, handle)
136 
137  cpassert(.NOT. ASSOCIATED(pw_env))
138  ALLOCATE (pw_env)
139  NULLIFY (pw_env%pw_pools, pw_env%gridlevel_info, pw_env%poisson_env, &
140  pw_env%cube_info, pw_env%rs_descs, pw_env%rs_grids, &
141  pw_env%xc_pw_pool, pw_env%vdw_pw_pool, &
142  pw_env%interp_section)
143  pw_env%auxbas_grid = -1
144  pw_env%ref_count = 1
145 
146  CALL timestop(handle)
147 
148  END SUBROUTINE pw_env_create
149 
150 ! **************************************************************************************************
151 !> \brief rebuilds the pw_env data (necessary if cell or cutoffs change)
152 !> \param pw_env the environment to rebuild
153 !> \param qs_env the qs_env where to get the cell, cutoffs,...
154 !> \param external_para_env ...
155 !> \par History
156 !> 10.2002 created [fawzi]
157 !> \author Fawzi Mohamed
158 ! **************************************************************************************************
159  SUBROUTINE pw_env_rebuild(pw_env, qs_env, external_para_env)
160  TYPE(pw_env_type), POINTER :: pw_env
161  TYPE(qs_environment_type), POINTER :: qs_env
162  TYPE(mp_para_env_type), INTENT(IN), OPTIONAL, &
163  TARGET :: external_para_env
164 
165  CHARACTER(len=*), PARAMETER :: routinen = 'pw_env_rebuild'
166 
167  CHARACTER(LEN=3) :: string
168  INTEGER :: blocked_id, blocked_id_input, boundary_condition, grid_span, handle, i, &
169  igrid_level, iounit, ncommensurate, ngrid_level, xc_deriv_method_id, xc_smooth_method_id
170  INTEGER, DIMENSION(2) :: distribution_layout
171  INTEGER, DIMENSION(3) :: higher_grid_layout
172  LOGICAL :: do_io, efg_present, linres_present, odd, set_vdw_pool, should_output, &
173  smooth_required, spherical, uf_grid, use_ref_cell
174  REAL(kind=dp) :: cutilev, rel_cutoff
175  REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: radius
176  REAL(kind=dp), DIMENSION(:), POINTER :: cutoff
177  TYPE(cell_type), POINTER :: cell, cell_ref, my_cell
178  TYPE(cp_logger_type), POINTER :: logger
179  TYPE(dft_control_type), POINTER :: dft_control
180  TYPE(mp_para_env_type), POINTER :: para_env
181  TYPE(pw_grid_type), POINTER :: dct_pw_grid, mt_super_ref_grid, old_pw_grid, pw_grid, &
182  super_ref_grid, vdw_grid, vdw_ref_grid, xc_super_ref_grid
183  TYPE(pw_poisson_parameter_type) :: poisson_params
184  TYPE(pw_pool_p_type), DIMENSION(:), POINTER :: pw_pools
185  TYPE(qs_dispersion_type), POINTER :: dispersion_env
186  TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
187  TYPE(realspace_grid_desc_p_type), DIMENSION(:), &
188  POINTER :: rs_descs
189  TYPE(realspace_grid_input_type) :: input_settings
190  TYPE(realspace_grid_type), DIMENSION(:), POINTER :: rs_grids
191  TYPE(section_vals_type), POINTER :: efg_section, input, linres_section, &
192  poisson_section, print_section, &
193  rs_grid_section, xc_section
194 
195  ! a very small safety factor might be needed for roundoff issues
196  ! e.g. radius being computed here as 12.998 (13) and 13.002 (14) during the collocation
197  ! the latter can happen due to the lower precision in the computation of the radius in collocate
198  ! parallel cost of rs_pw_transfer goes as safety_factor**3 so it is worthwhile keeping it tight
199  ! Edit: Safety Factor was unused
200 
201  CALL timeset(routinen, handle)
202 
203  !
204  !
205  ! Part one, deallocate old data if needed
206  !
207  !
208  NULLIFY (cutoff, cell, pw_grid, old_pw_grid, dft_control, qs_kind_set, &
209  pw_pools, rs_descs, para_env, cell_ref, vdw_ref_grid, &
210  mt_super_ref_grid, input, poisson_section, xc_super_ref_grid, &
211  dct_pw_grid, vdw_grid, super_ref_grid, my_cell, rs_grids, dispersion_env)
212 
213  CALL get_qs_env(qs_env=qs_env, &
214  dft_control=dft_control, &
215  qs_kind_set=qs_kind_set, &
216  cell_ref=cell_ref, &
217  cell=cell, &
218  para_env=para_env, &
219  input=input, &
220  dispersion_env=dispersion_env)
221 
222  cpassert(ASSOCIATED(pw_env))
223  cpassert(pw_env%ref_count > 0)
224  CALL pw_pool_release(pw_env%vdw_pw_pool)
225  CALL pw_pool_release(pw_env%xc_pw_pool)
226  CALL pw_pools_dealloc(pw_env%pw_pools)
227  IF (ASSOCIATED(pw_env%rs_descs)) THEN
228  DO i = 1, SIZE(pw_env%rs_descs)
229  CALL rs_grid_release_descriptor(pw_env%rs_descs(i)%rs_desc)
230  END DO
231  DEALLOCATE (pw_env%rs_descs)
232  END IF
233  IF (ASSOCIATED(pw_env%rs_grids)) THEN
234  DO i = 1, SIZE(pw_env%rs_grids)
235  CALL rs_grid_release(pw_env%rs_grids(i))
236  END DO
237  DEALLOCATE (pw_env%rs_grids)
238  END IF
239  IF (ASSOCIATED(pw_env%gridlevel_info)) THEN
240  CALL destroy_gaussian_gridlevel(pw_env%gridlevel_info)
241  ELSE
242  ALLOCATE (pw_env%gridlevel_info)
243  END IF
244 
245  IF (ASSOCIATED(pw_env%cube_info)) THEN
246  DO igrid_level = 1, SIZE(pw_env%cube_info)
247  CALL destroy_cube_info(pw_env%cube_info(igrid_level))
248  END DO
249  DEALLOCATE (pw_env%cube_info)
250  END IF
251  NULLIFY (pw_env%pw_pools, pw_env%cube_info)
252 
253  !
254  !
255  ! Part two, setup the pw_grids
256  !
257  !
258 
259  do_io = .true.
260  IF (PRESENT(external_para_env)) THEN
261  para_env => external_para_env
262  cpassert(ASSOCIATED(para_env))
263  do_io = .false. !multiple MPI subgroups mess-up the output file
264  END IF
265  ! interpolation section
266  pw_env%interp_section => section_vals_get_subs_vals(input, "DFT%MGRID%INTERPOLATOR")
267 
268  CALL get_qs_env(qs_env, use_ref_cell=use_ref_cell)
269  IF (use_ref_cell) THEN
270  my_cell => cell_ref
271  ELSE
272  my_cell => cell
273  END IF
274  rel_cutoff = dft_control%qs_control%relative_cutoff
275  cutoff => dft_control%qs_control%e_cutoff
276  CALL section_vals_val_get(input, "DFT%XC%XC_GRID%USE_FINER_GRID", l_val=uf_grid)
277  ngrid_level = SIZE(cutoff)
278 
279  ! init gridlevel_info XXXXXXXXX setup mapping to the effective cutoff ?
280  ! XXXXXXXXX the cutoff array here is more a 'wish-list'
281  ! XXXXXXXXX same holds for radius
282  print_section => section_vals_get_subs_vals(input, &
283  "PRINT%GRID_INFORMATION")
284  CALL init_gaussian_gridlevel(pw_env%gridlevel_info, &
285  ngrid_levels=ngrid_level, cutoff=cutoff, rel_cutoff=rel_cutoff, &
286  print_section=print_section)
287  ! init pw_grids and pools
288  ALLOCATE (pw_pools(ngrid_level))
289 
290  IF (dft_control%qs_control%commensurate_mgrids) THEN
291  ncommensurate = ngrid_level
292  ELSE
293  ncommensurate = 0
294  END IF
295  !
296  ! If Tuckerman is present let's perform the set-up of the super-reference-grid
297  !
298  cutilev = cutoff(1)
299  IF (dft_control%qs_control%pw_grid_opt%spherical) THEN
300  grid_span = halfspace
301  spherical = .true.
302  ELSE IF (dft_control%qs_control%pw_grid_opt%fullspace) THEN
303  grid_span = fullspace
304  spherical = .false.
305  ELSE
306  grid_span = halfspace
307  spherical = .false.
308  END IF
309 
310  CALL setup_super_ref_grid(super_ref_grid, mt_super_ref_grid, &
311  xc_super_ref_grid, cutilev, grid_span, spherical, my_cell, para_env, &
312  qs_env%input, ncommensurate, uf_grid=uf_grid, &
313  print_section=print_section)
314  old_pw_grid => super_ref_grid
315  IF (.NOT. ASSOCIATED(mt_super_ref_grid)) vdw_ref_grid => super_ref_grid
316  !
317  ! Setup of the multi-grid pw_grid and pw_pools
318  !
319 
320  IF (do_io) THEN
321  logger => cp_get_default_logger()
322  iounit = cp_print_key_unit_nr(logger, print_section, '', extension='.Log')
323  ELSE
324  iounit = 0
325  END IF
326 
327  IF (dft_control%qs_control%pw_grid_opt%spherical) THEN
328  grid_span = halfspace
329  spherical = .true.
330  odd = .true.
331  ELSE IF (dft_control%qs_control%pw_grid_opt%fullspace) THEN
332  grid_span = fullspace
333  spherical = .false.
334  odd = .false.
335  ELSE
336  grid_span = halfspace
337  spherical = .false.
338  odd = .true.
339  END IF
340 
341  ! use input suggestion for blocked
342  blocked_id_input = dft_control%qs_control%pw_grid_opt%blocked
343 
344  ! methods that require smoothing or nearest neighbor have to use a plane distributed setup
345  ! find the xc properties (FIXME this could miss other xc sections that operate on the grid ...)
346  xc_section => section_vals_get_subs_vals(input, "DFT%XC")
347  xc_deriv_method_id = section_get_ival(xc_section, "XC_GRID%XC_DERIV")
348  xc_smooth_method_id = section_get_ival(xc_section, "XC_GRID%XC_SMOOTH_RHO")
349  smooth_required = .false.
350  SELECT CASE (xc_deriv_method_id)
352  smooth_required = smooth_required .OR. .false.
353  CASE (xc_deriv_spline2_smooth, &
355  smooth_required = smooth_required .OR. .true.
356  CASE DEFAULT
357  cpabort("")
358  END SELECT
359  SELECT CASE (xc_smooth_method_id)
360  CASE (xc_rho_no_smooth)
361  smooth_required = smooth_required .OR. .false.
363  smooth_required = smooth_required .OR. .true.
364  CASE DEFAULT
365  cpabort("")
366  END SELECT
367  ! EPR, NMR, EFG can require splines. If the linres/EFG section is present we assume
368  ! it could be on and splines might be used (not quite sure if this is due to their use of splines or something else)
369  linres_section => section_vals_get_subs_vals(section_vals=input, &
370  subsection_name="PROPERTIES%LINRES")
371  CALL section_vals_get(linres_section, explicit=linres_present)
372  IF (linres_present) THEN
373  smooth_required = smooth_required .OR. .true.
374  END IF
375 
376  efg_section => section_vals_get_subs_vals(section_vals=input, &
377  subsection_name="DFT%PRINT%ELECTRIC_FIELD_GRADIENT")
378  CALL section_vals_get(efg_section, explicit=efg_present)
379  IF (efg_present) THEN
380  smooth_required = smooth_required .OR. .true.
381  END IF
382 
383  DO igrid_level = 1, ngrid_level
384  CALL pw_grid_create(pw_grid, para_env)
385 
386  cutilev = cutoff(igrid_level)
387 
388  ! the whole of QS seems to work fine with either blocked/non-blocked distribution in g-space
389  ! the default choice should be made free
390  blocked_id = blocked_id_input
391 
392  distribution_layout = dft_control%qs_control%pw_grid_opt%distribution_layout
393 
394  ! qmmm does not support a ray distribution
395  ! FIXME ... check if a plane distributed lower grid is sufficient
396  IF (qs_env%qmmm) THEN
397  distribution_layout = (/para_env%num_pe, 1/)
398  END IF
399 
400  ! If splines are required
401  ! FIXME.... should only be true for the highest grid
402  IF (smooth_required) THEN
403  distribution_layout = (/para_env%num_pe, 1/)
404  END IF
405 
406  IF (igrid_level == 1) THEN
407  IF (ASSOCIATED(old_pw_grid)) THEN
408  CALL pw_grid_setup(my_cell%hmat, pw_grid, grid_span=grid_span, &
409  cutoff=cutilev, &
410  spherical=spherical, odd=odd, fft_usage=.true., &
411  ncommensurate=ncommensurate, icommensurate=igrid_level, &
412  blocked=do_pw_grid_blocked_false, &
413  ref_grid=old_pw_grid, &
414  rs_dims=distribution_layout, &
415  iounit=iounit)
416  old_pw_grid => pw_grid
417  ELSE
418  CALL pw_grid_setup(my_cell%hmat, pw_grid, grid_span=grid_span, &
419  cutoff=cutilev, &
420  spherical=spherical, odd=odd, fft_usage=.true., &
421  ncommensurate=ncommensurate, icommensurate=igrid_level, &
422  blocked=blocked_id, &
423  rs_dims=distribution_layout, &
424  iounit=iounit)
425  old_pw_grid => pw_grid
426  END IF
427  ELSE
428  CALL pw_grid_setup(my_cell%hmat, pw_grid, grid_span=grid_span, &
429  cutoff=cutilev, &
430  spherical=spherical, odd=odd, fft_usage=.true., &
431  ncommensurate=ncommensurate, icommensurate=igrid_level, &
432  blocked=do_pw_grid_blocked_false, &
433  ref_grid=old_pw_grid, &
434  rs_dims=distribution_layout, &
435  iounit=iounit)
436  END IF
437 
438  ! init pw_pools
439  NULLIFY (pw_pools(igrid_level)%pool)
440  CALL pw_pool_create(pw_pools(igrid_level)%pool, pw_grid=pw_grid)
441 
442  CALL pw_grid_release(pw_grid)
443 
444  END DO
445 
446  pw_env%pw_pools => pw_pools
447 
448  ! init auxbas_grid
449  DO i = 1, ngrid_level
450  IF (cutoff(i) == dft_control%qs_control%cutoff) pw_env%auxbas_grid = i
451  END DO
452 
453  ! init xc_pool
454  IF (ASSOCIATED(xc_super_ref_grid)) THEN
455  CALL pw_pool_create(pw_env%xc_pw_pool, &
456  pw_grid=xc_super_ref_grid)
457  CALL pw_grid_release(xc_super_ref_grid)
458  ELSE
459  pw_env%xc_pw_pool => pw_pools(pw_env%auxbas_grid)%pool
460  CALL pw_env%xc_pw_pool%retain()
461  END IF
462 
463  ! init vdw_pool
464  set_vdw_pool = .false.
465  IF (ASSOCIATED(dispersion_env)) THEN
466  IF (dispersion_env%type == xc_vdw_fun_nonloc) THEN
467  IF (dispersion_env%pw_cutoff > 0._dp) set_vdw_pool = .true.
468  END IF
469  END IF
470  IF (set_vdw_pool) THEN
471  cpassert(ASSOCIATED(old_pw_grid))
472  IF (.NOT. ASSOCIATED(vdw_ref_grid)) vdw_ref_grid => old_pw_grid
473  CALL pw_grid_create(vdw_grid, para_env)
474  IF (iounit > 0) WRITE (iounit, "(/,T2,A)") "PW_GRID| Grid for non-local vdW functional"
475  CALL pw_grid_setup(my_cell%hmat, vdw_grid, grid_span=grid_span, &
476  cutoff=dispersion_env%pw_cutoff, &
477  spherical=spherical, odd=odd, fft_usage=.true., &
478  ncommensurate=0, icommensurate=0, &
479  blocked=do_pw_grid_blocked_false, &
480  ref_grid=vdw_ref_grid, &
481  rs_dims=distribution_layout, &
482  iounit=iounit)
483  CALL pw_pool_create(pw_env%vdw_pw_pool, pw_grid=vdw_grid)
484  CALL pw_grid_release(vdw_grid)
485  ELSE
486  pw_env%vdw_pw_pool => pw_pools(pw_env%auxbas_grid)%pool
487  CALL pw_env%vdw_pw_pool%retain()
488  END IF
489 
490  IF (do_io) CALL cp_print_key_finished_output(iounit, logger, print_section, '')
491 
492  ! complete init of the poisson_env
493  IF (.NOT. ASSOCIATED(pw_env%poisson_env)) THEN
494  ALLOCATE (pw_env%poisson_env)
495  CALL pw_env%poisson_env%create()
496  END IF
497  poisson_section => section_vals_get_subs_vals(input, "DFT%POISSON")
498 
499  CALL pw_poisson_read_parameters(poisson_section, poisson_params)
500  CALL pw_poisson_set(pw_env%poisson_env, cell_hmat=my_cell%hmat, pw_pools=pw_env%pw_pools, &
501  parameters=poisson_params, mt_super_ref_pw_grid=mt_super_ref_grid, &
502  dct_pw_grid=dct_pw_grid, use_level=pw_env%auxbas_grid)
503  CALL pw_grid_release(mt_super_ref_grid)
504  CALL pw_grid_release(dct_pw_grid)
505 !
506 ! If reference cell is present, then use pw_grid_change to keep bounds constant...
507 ! do not re-init the Gaussian grid level (fix the gridlevel on which the pgf should go.
508 !
509  IF (use_ref_cell) THEN
510  DO igrid_level = 1, SIZE(pw_pools)
511  CALL pw_grid_change(cell%hmat, pw_pools(igrid_level)%pool%pw_grid)
512  END DO
513  IF (set_vdw_pool) CALL pw_grid_change(cell%hmat, pw_env%vdw_pw_pool%pw_grid)
514  CALL pw_poisson_read_parameters(poisson_section, poisson_params)
515  CALL pw_poisson_set(pw_env%poisson_env, cell_hmat=cell%hmat, pw_pools=pw_env%pw_pools, &
516  parameters=poisson_params, mt_super_ref_pw_grid=mt_super_ref_grid, &
517  dct_pw_grid=dct_pw_grid, use_level=pw_env%auxbas_grid)
518  END IF
519 
520  IF ((poisson_params%ps_implicit_params%boundary_condition .EQ. mixed_periodic_bc) .OR. &
521  (poisson_params%ps_implicit_params%boundary_condition .EQ. mixed_bc)) THEN
522  pw_env%poisson_env%parameters%dbc_params%do_dbc_cube = &
523  btest(cp_print_key_should_output(logger%iter_info, input, &
524  "DFT%PRINT%IMPLICIT_PSOLVER%DIRICHLET_BC_CUBE"), cp_p_file)
525  END IF
526  ! setup dct_pw_grid (an extended pw_grid) for Discrete Cosine Transformation (DCT)
527  IF ((poisson_params%ps_implicit_params%boundary_condition .EQ. neumann_bc) .OR. &
528  (poisson_params%ps_implicit_params%boundary_condition .EQ. mixed_bc)) THEN
529  CALL setup_dct_pw_grids(pw_env%poisson_env%pw_pools(pw_env%poisson_env%pw_level)%pool%pw_grid, &
530  my_cell%hmat, poisson_params%ps_implicit_params%neumann_directions, &
531  pw_env%poisson_env%dct_pw_grid)
532  END IF
533  ! setup real space grid for finite difference derivatives of dielectric constant function
534  IF (poisson_params%has_dielectric .AND. &
535  ((poisson_params%dielectric_params%derivative_method .EQ. derivative_cd3) .OR. &
536  (poisson_params%dielectric_params%derivative_method .EQ. derivative_cd5) .OR. &
537  (poisson_params%dielectric_params%derivative_method .EQ. derivative_cd7))) THEN
538 
539  SELECT CASE (poisson_params%ps_implicit_params%boundary_condition)
540  CASE (neumann_bc, mixed_bc)
541  CALL setup_diel_rs_grid(pw_env%poisson_env%diel_rs_grid, &
542  poisson_params%dielectric_params%derivative_method, input, &
543  pw_env%poisson_env%dct_pw_grid)
545  CALL setup_diel_rs_grid(pw_env%poisson_env%diel_rs_grid, &
546  poisson_params%dielectric_params%derivative_method, input, &
547  pw_env%poisson_env%pw_pools(pw_env%poisson_env%pw_level)%pool%pw_grid)
548  END SELECT
549 
550  END IF
551 
552 !
553 !
554 ! determine the maximum radii for mapped gaussians, needed to
555 ! set up distributed rs grids
556 !
557 !
558 
559  ALLOCATE (radius(ngrid_level))
560 
561  CALL compute_max_radius(radius, pw_env, qs_env)
562 
563 !
564 !
565 ! set up the rs_grids and the cubes, requires 'radius' to be set up correctly
566 !
567 !
568  ALLOCATE (rs_descs(ngrid_level))
569 
570  ALLOCATE (rs_grids(ngrid_level))
571 
572  ALLOCATE (pw_env%cube_info(ngrid_level))
573  higher_grid_layout = (/-1, -1, -1/)
574 
575  DO igrid_level = 1, ngrid_level
576  pw_grid => pw_pools(igrid_level)%pool%pw_grid
577 
578  CALL init_d3_poly_module() ! a fairly arbitrary but sufficient spot to do this
579  CALL init_cube_info(pw_env%cube_info(igrid_level), &
580  pw_grid%dr(:), pw_grid%dh(:, :), pw_grid%dh_inv(:, :), pw_grid%orthorhombic, &
581  radius(igrid_level))
582 
583  rs_grid_section => section_vals_get_subs_vals(input, "DFT%MGRID%RS_GRID")
584 
585  CALL init_input_type(input_settings, nsmax=2*max(1, return_cube_max_iradius(pw_env%cube_info(igrid_level))) + 1, &
586  rs_grid_section=rs_grid_section, ilevel=igrid_level, &
587  higher_grid_layout=higher_grid_layout)
588 
589  NULLIFY (rs_descs(igrid_level)%rs_desc)
590  CALL rs_grid_create_descriptor(rs_descs(igrid_level)%rs_desc, pw_grid, input_settings)
591 
592  IF (rs_descs(igrid_level)%rs_desc%distributed) higher_grid_layout = rs_descs(igrid_level)%rs_desc%group_dim
593 
594  CALL rs_grid_create(rs_grids(igrid_level), rs_descs(igrid_level)%rs_desc)
595  END DO
596  pw_env%rs_descs => rs_descs
597  pw_env%rs_grids => rs_grids
598 
599  DEALLOCATE (radius)
600 
601  ! Print grid information
602 
603  IF (do_io) THEN
604  logger => cp_get_default_logger()
605  iounit = cp_print_key_unit_nr(logger, print_section, '', extension='.Log')
606  END IF
607  IF (iounit > 0) THEN
608  SELECT CASE (poisson_params%solver)
609  CASE (pw_poisson_periodic)
610  WRITE (unit=iounit, fmt="(/,T2,A,T51,A30)") &
611  "POISSON| Solver", "PERIODIC"
612  CASE (pw_poisson_analytic)
613  WRITE (unit=iounit, fmt="(/,T2,A,T51,A30)") &
614  "POISSON| Solver", "ANALYTIC"
615  CASE (pw_poisson_mt)
616  WRITE (unit=iounit, fmt="(/,T2,A,T51,A30)") &
617  "POISSON| Solver", adjustr("Martyna-Tuckerman (MT)")
618  WRITE (unit=iounit, fmt="(T2,A,T71,F10.3,/,T2,A,T71,F10.1)") &
619  "POISSON| MT| Alpha", poisson_params%mt_alpha, &
620  "POISSON| MT| Relative cutoff", poisson_params%mt_rel_cutoff
621  CASE (pw_poisson_multipole)
622  WRITE (unit=iounit, fmt="(/,T2,A,T51,A30)") &
623  "POISSON| Solver", "MULTIPOLE (Bloechl)"
624  CASE (pw_poisson_wavelet)
625  WRITE (unit=iounit, fmt="(/,T2,A,T51,A30)") &
626  "POISSON| Solver", "WAVELET"
627  WRITE (unit=iounit, fmt="(T2,A,T71,I10)") &
628  "POISSON| Wavelet| Scaling function", poisson_params%wavelet_scf_type
629  SELECT CASE (poisson_params%wavelet_method)
630  CASE (wavelet0d)
631  WRITE (unit=iounit, fmt="(T2,A,T51,A30)") &
632  "POISSON| Periodicity", "NONE"
633  CASE (wavelet2d)
634  WRITE (unit=iounit, fmt="(T2,A,T51,A30)") &
635  "POISSON| Periodicity", "XZ"
636  CASE (wavelet3d)
637  WRITE (unit=iounit, fmt="(T2,A,T51,A30)") &
638  "POISSON| Periodicity", "XYZ"
639  CASE DEFAULT
640  cpabort("Invalid periodicity for wavelet solver selected")
641  END SELECT
642  CASE (pw_poisson_implicit)
643  WRITE (unit=iounit, fmt="(/,T2,A,T51,A30)") &
644  "POISSON| Solver", "IMPLICIT (GENERALIZED)"
645  boundary_condition = poisson_params%ps_implicit_params%boundary_condition
646  SELECT CASE (boundary_condition)
647  CASE (periodic_bc)
648  WRITE (unit=iounit, fmt="(T2,A,T51,A30)") &
649  "POISSON| Boundary Condition", "PERIODIC"
650  CASE (neumann_bc, mixed_bc)
651  IF (boundary_condition .EQ. neumann_bc) THEN
652  WRITE (unit=iounit, fmt="(T2,A,T51,A30)") &
653  "POISSON| Boundary Condition", "NEUMANN"
654  ELSE
655  WRITE (unit=iounit, fmt="(T2,A,T51,A30)") &
656  "POISSON| Boundary Condition", "MIXED"
657  END IF
658  SELECT CASE (poisson_params%ps_implicit_params%neumann_directions)
659  CASE (neumannxyz)
660  WRITE (unit=iounit, fmt="(T2,A,T51,A30)") "POISSON| homogeneous Neumann directions", "X, Y, Z"
661  WRITE (unit=iounit, fmt="(T2,A,T51,A30)") "POISSON| periodic directions", "NONE"
662  CASE (neumannxy)
663  WRITE (unit=iounit, fmt="(T2,A,T51,A30)") "POISSON| homogeneous Neumann directions", "X, Y"
664  WRITE (unit=iounit, fmt="(T2,A,T51,A30)") "POISSON| periodic directions", "Z"
665  CASE (neumannxz)
666  WRITE (unit=iounit, fmt="(T2,A,T51,A30)") "POISSON| homogeneous Neumann directions", "X, Z"
667  WRITE (unit=iounit, fmt="(T2,A,T51,A30)") "POISSON| periodic directions", "Y"
668  CASE (neumannyz)
669  WRITE (unit=iounit, fmt="(T2,A,T51,A30)") "POISSON| homogeneous Neumann directions", "Y, Z"
670  WRITE (unit=iounit, fmt="(T2,A,T51,A30)") "POISSON| periodic directions", "X"
671  CASE (neumannx)
672  WRITE (unit=iounit, fmt="(T2,A,T51,A30)") "POISSON| homogeneous Neumann directions", "X"
673  WRITE (unit=iounit, fmt="(T2,A,T51,A30)") "POISSON| periodic directions", "Y, Z"
674  CASE (neumanny)
675  WRITE (unit=iounit, fmt="(T2,A,T51,A30)") "POISSON| homogeneous Neumann directions", "Y"
676  WRITE (unit=iounit, fmt="(T2,A,T51,A30)") "POISSON| periodic directions", "X, Z"
677  CASE (neumannz)
678  WRITE (unit=iounit, fmt="(T2,A,T51,A30)") "POISSON| homogeneous Neumann directions", "Z"
679  WRITE (unit=iounit, fmt="(T2,A,T51,A30)") "POISSON| periodic directions", "X, Y"
680  CASE DEFAULT
681  cpabort("Invalid combination of Neumann and periodic conditions.")
682  END SELECT
683  CASE (mixed_periodic_bc)
684  WRITE (unit=iounit, fmt="(T2,A,T51,A30)") &
685  "POISSON| Boundary Condition", "PERIODIC & DIRICHLET"
686  CASE DEFAULT
687  cpabort("Invalid boundary conditions for the implicit (generalized) poisson solver.")
688  END SELECT
689  WRITE (unit=iounit, fmt="(T2,A,T71,I10)") &
690  "POISSON| Maximum number of iterations", poisson_params%ps_implicit_params%max_iter
691  WRITE (unit=iounit, fmt="(T2,A,T51,ES30.2)") &
692  "POISSON| Convergence threshold", poisson_params%ps_implicit_params%tol
693  IF (poisson_params%dielectric_params%dielec_functiontype .EQ. rho_dependent) THEN
694  WRITE (unit=iounit, fmt="(T2,A,T51,F30.2)") &
695  "POISSON| Dielectric Constant", poisson_params%dielectric_params%eps0
696  ELSE
697  WRITE (unit=iounit, fmt="(T2,A,T31,F9.2)", advance='NO') &
698  "POISSON| Dielectric Constants", poisson_params%dielectric_params%eps0
699  DO i = 1, poisson_params%dielectric_params%n_aa_cuboidal
700  WRITE (unit=iounit, fmt="(F9.2)", advance='NO') &
701  poisson_params%dielectric_params%aa_cuboidal_eps(i)
702  END DO
703  DO i = 1, poisson_params%dielectric_params%n_xaa_annular
704  WRITE (unit=iounit, fmt="(F9.2)", advance='NO') &
705  poisson_params%dielectric_params%xaa_annular_eps(i)
706  END DO
707  WRITE (unit=iounit, fmt='(A1,/)')
708  END IF
709  WRITE (unit=iounit, fmt="(T2,A,T51,ES30.2)") &
710  "POISSON| Relaxation parameter", poisson_params%ps_implicit_params%omega
711  CASE (pw_poisson_none)
712  WRITE (unit=iounit, fmt="(/,T2,A,T51,A30)") &
713  "POISSON| Solver", "NONE"
714  CASE default
715  cpabort("Invalid Poisson solver selected")
716  END SELECT
717  IF ((poisson_params%solver /= pw_poisson_wavelet) .AND. &
718  (poisson_params%solver /= pw_poisson_implicit)) THEN
719  IF (sum(poisson_params%periodic(1:3)) == 0) THEN
720  WRITE (unit=iounit, fmt="(T2,A,T77,A4)") &
721  "POISSON| Periodicity", "NONE"
722  ELSE
723  string = ""
724  IF (poisson_params%periodic(1) == 1) string = trim(string)//"X"
725  IF (poisson_params%periodic(2) == 1) string = trim(string)//"Y"
726  IF (poisson_params%periodic(3) == 1) string = trim(string)//"Z"
727  WRITE (unit=iounit, fmt="(T2,A,T78,A3)") &
728  "POISSON| Periodicity", adjustr(string)
729  END IF
730  END IF
731  END IF
732 
733  IF ((dft_control%qs_control%method_id == do_method_gpw) .OR. &
734  (dft_control%qs_control%method_id == do_method_gapw) .OR. &
735  (dft_control%qs_control%method_id == do_method_gapw_xc) .OR. &
736  (dft_control%qs_control%method_id == do_method_lrigpw) .OR. &
737  (dft_control%qs_control%method_id == do_method_rigpw) .OR. &
738  (dft_control%qs_control%method_id == do_method_ofgpw)) THEN
739  IF ((poisson_params%solver /= pw_poisson_wavelet) .AND. &
740  (poisson_params%solver /= pw_poisson_implicit)) THEN
741  IF (any(my_cell%perd(1:3) /= poisson_params%periodic(1:3))) THEN
742  CALL cp_warn(__location__, &
743  "The selected periodicities in the sections &CELL and &POISSON do not match")
744  END IF
745  END IF
746  END IF
747 
748  IF (do_io) THEN
749  should_output = btest(cp_print_key_should_output(logger%iter_info, &
750  print_section, ''), cp_p_file)
751  IF (should_output) THEN
752  DO igrid_level = 1, ngrid_level
753  CALL rs_grid_print(rs_grids(igrid_level), iounit)
754  END DO
755  END IF
756  CALL cp_print_key_finished_output(iounit, logger, print_section, "")
757  END IF
758 
759  CALL timestop(handle)
760 
761  END SUBROUTINE pw_env_rebuild
762 
763 ! **************************************************************************************************
764 !> \brief computes the maximum radius
765 !> \param radius ...
766 !> \param pw_env ...
767 !> \param qs_env ...
768 !> \par History
769 !> 10.2010 refactored [Joost VandeVondele]
770 !> 01.2020 igrid_zet0_s initialisation code is reused in rho0_s_grid_create() [Sergey Chulkov]
771 !> \author Joost VandeVondele
772 ! **************************************************************************************************
773  SUBROUTINE compute_max_radius(radius, pw_env, qs_env)
774  REAL(kind=dp), DIMENSION(:), INTENT(OUT) :: radius
775  TYPE(pw_env_type), POINTER :: pw_env
776  TYPE(qs_environment_type), POINTER :: qs_env
777 
778  CHARACTER(len=*), PARAMETER :: routinen = 'compute_max_radius'
779  CHARACTER(LEN=8), DIMENSION(4), PARAMETER :: &
780  pbas = (/"ORB ", "AUX_FIT ", "MAO ", "HARRIS "/)
781  CHARACTER(LEN=8), DIMENSION(8), PARAMETER :: sbas = (/"ORB ", "AUX ", "RI_AUX ", &
782  "MAO ", "HARRIS ", "RI_HXC ", "RI_K ", "LRI_AUX "/)
783  REAL(kind=dp), PARAMETER :: safety_factor = 1.015_dp
784 
785  INTEGER :: handle, ibasis_set_type, igrid_level, igrid_zet0_s, ikind, ipgf, iset, ishell, &
786  jkind, jpgf, jset, jshell, la, lb, lgrid_level, ngrid_level, nkind, nseta, nsetb
787  INTEGER, DIMENSION(:), POINTER :: npgfa, npgfb, nshella, nshellb
788  INTEGER, DIMENSION(:, :), POINTER :: lshella, lshellb
789  REAL(kind=dp) :: alpha, core_charge, eps_gvg, eps_rho, &
790  max_rpgf0_s, maxradius, zet0_h, zetp
791  REAL(kind=dp), DIMENSION(:, :), POINTER :: zeta, zetb
792  TYPE(dft_control_type), POINTER :: dft_control
793  TYPE(gto_basis_set_type), POINTER :: orb_basis_set
794  TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
795  TYPE(qs_kind_type), POINTER :: qs_kind
796  TYPE(rho0_mpole_type), POINTER :: rho0_mpole
797 
798  ! a very small safety factor might be needed for roundoff issues
799  ! e.g. radius being computed here as 12.998 (13) and 13.002 (14) during the collocation
800  ! the latter can happen due to the lower precision in the computation of the radius in collocate
801  ! parallel cost of rs_pw_transfer goes as safety_factor**3 so it is worthwhile keeping it tight
802 
803  CALL timeset(routinen, handle)
804  NULLIFY (dft_control, qs_kind_set, rho0_mpole)
805 
806  CALL get_qs_env(qs_env=qs_env, qs_kind_set=qs_kind_set, dft_control=dft_control)
807 
808  eps_rho = dft_control%qs_control%eps_rho_rspace
809  eps_gvg = dft_control%qs_control%eps_gvg_rspace
810 
811  IF (dft_control%qs_control%gapw) THEN
812  CALL get_qs_env(qs_env=qs_env, rho0_mpole=rho0_mpole)
813  cpassert(ASSOCIATED(rho0_mpole))
814 
815  CALL get_rho0_mpole(rho0_mpole=rho0_mpole, max_rpgf0_s=max_rpgf0_s, zet0_h=zet0_h)
816  igrid_zet0_s = gaussian_gridlevel(pw_env%gridlevel_info, 2.0_dp*zet0_h)
817  rho0_mpole%igrid_zet0_s = igrid_zet0_s
818  END IF
819 
820  ngrid_level = SIZE(radius)
821  nkind = SIZE(qs_kind_set)
822 
823  ! try to predict the maximum radius of the gaussians to be mapped on the grid
824  ! up to now, it is not yet very good
825  radius = 0.0_dp
826  DO igrid_level = 1, ngrid_level
827 
828  maxradius = 0.0_dp
829  ! Take into account the radius of the soft compensation charge rho0_soft1
830  IF (dft_control%qs_control%gapw) THEN
831  IF (igrid_zet0_s == igrid_level) maxradius = max(maxradius, max_rpgf0_s)
832  END IF
833 
834  ! this is to be sure that the core charge is mapped ok
835  ! right now, the core is mapped on the auxiliary basis,
836  ! this should, at a give point be changed
837  ! so that also for the core a multigrid is used
838  DO ikind = 1, nkind
839  CALL get_qs_kind(qs_kind_set(ikind), &
840  alpha_core_charge=alpha, ccore_charge=core_charge)
841  IF (alpha > 0.0_dp .AND. core_charge .NE. 0.0_dp) THEN
842  maxradius = max(maxradius, exp_radius(0, alpha, eps_rho, core_charge, rlow=maxradius))
843  ! forces
844  maxradius = max(maxradius, exp_radius(1, alpha, eps_rho, core_charge, rlow=maxradius))
845  END IF
846  END DO
847 
848  ! loop over basis sets that are used in grid collocation directly (no product)
849  ! e.g. for calculating a wavefunction or a RI density
850  DO ibasis_set_type = 1, SIZE(sbas)
851  DO ikind = 1, nkind
852  qs_kind => qs_kind_set(ikind)
853  NULLIFY (orb_basis_set)
854  CALL get_qs_kind(qs_kind=qs_kind, &
855  basis_set=orb_basis_set, basis_type=sbas(ibasis_set_type))
856  IF (.NOT. ASSOCIATED(orb_basis_set)) cycle
857  CALL get_gto_basis_set(gto_basis_set=orb_basis_set, &
858  npgf=npgfa, nset=nseta, zet=zeta, l=lshella, nshell=nshella)
859  DO iset = 1, nseta
860  DO ipgf = 1, npgfa(iset)
861  DO ishell = 1, nshella(iset)
862  zetp = zeta(ipgf, iset)
863  la = lshella(ishell, iset)
864  lgrid_level = gaussian_gridlevel(pw_env%gridlevel_info, zetp)
865  IF (lgrid_level .EQ. igrid_level) THEN
866  maxradius = max(maxradius, exp_radius(la, zetp, eps_rho, 1.0_dp, rlow=maxradius))
867  END IF
868  END DO
869  END DO
870  END DO
871  END DO
872  END DO
873  ! loop over basis sets that are used in product function grid collocation
874  DO ibasis_set_type = 1, SIZE(pbas)
875  DO ikind = 1, nkind
876  qs_kind => qs_kind_set(ikind)
877  NULLIFY (orb_basis_set)
878  CALL get_qs_kind(qs_kind=qs_kind, &
879  basis_set=orb_basis_set, basis_type=pbas(ibasis_set_type))
880  IF (.NOT. ASSOCIATED(orb_basis_set)) cycle
881  CALL get_gto_basis_set(gto_basis_set=orb_basis_set, &
882  npgf=npgfa, nset=nseta, zet=zeta, l=lshella, nshell=nshella)
883 
884  DO jkind = 1, nkind
885  qs_kind => qs_kind_set(jkind)
886  CALL get_qs_kind(qs_kind=qs_kind, &
887  basis_set=orb_basis_set, basis_type=pbas(ibasis_set_type))
888  IF (.NOT. ASSOCIATED(orb_basis_set)) cycle
889  CALL get_gto_basis_set(gto_basis_set=orb_basis_set, &
890  npgf=npgfb, nset=nsetb, zet=zetb, l=lshellb, nshell=nshellb)
891  DO iset = 1, nseta
892  DO ipgf = 1, npgfa(iset)
893  DO ishell = 1, nshella(iset)
894  la = lshella(ishell, iset)
895  DO jset = 1, nsetb
896  DO jpgf = 1, npgfb(jset)
897  DO jshell = 1, nshellb(jset)
898  zetp = zeta(ipgf, iset) + zetb(jpgf, jset)
899  lb = lshellb(jshell, jset) + la
900  lgrid_level = gaussian_gridlevel(pw_env%gridlevel_info, zetp)
901  IF (lgrid_level .EQ. igrid_level) THEN
902  ! density (scale is at most 2)
903  maxradius = max(maxradius, exp_radius(lb, zetp, eps_rho, 2.0_dp, rlow=maxradius))
904  ! tau, properties?
905  maxradius = max(maxradius, exp_radius(lb + 1, zetp, eps_rho, 2.0_dp, rlow=maxradius))
906  ! potential
907  maxradius = max(maxradius, exp_radius(lb, zetp, eps_gvg, 2.0_dp, rlow=maxradius))
908  ! forces
909  maxradius = max(maxradius, exp_radius(lb + 1, zetp, eps_gvg, 2.0_dp, rlow=maxradius))
910  END IF
911  END DO
912  END DO
913  END DO
914  END DO
915  END DO
916  END DO
917  END DO
918  END DO
919  END DO
920 
921  ! this is a bit of hack, but takes into account numerics and rounding
922  maxradius = maxradius*safety_factor
923  radius(igrid_level) = maxradius
924  END DO
925 
926  CALL timestop(handle)
927 
928  END SUBROUTINE compute_max_radius
929 
930 ! **************************************************************************************************
931 !> \brief Initialize the super-reference grid for Tuckerman or xc
932 !> \param super_ref_pw_grid ...
933 !> \param mt_super_ref_pw_grid ...
934 !> \param xc_super_ref_pw_grid ...
935 !> \param cutilev ...
936 !> \param grid_span ...
937 !> \param spherical ...
938 !> \param cell_ref ...
939 !> \param para_env ...
940 !> \param input ...
941 !> \param my_ncommensurate ...
942 !> \param uf_grid ...
943 !> \param print_section ...
944 !> \author 03-2005 Teodoro Laino [teo]
945 !> \note
946 !> move somewere else?
947 ! **************************************************************************************************
948  SUBROUTINE setup_super_ref_grid(super_ref_pw_grid, mt_super_ref_pw_grid, &
949  xc_super_ref_pw_grid, cutilev, grid_span, spherical, &
950  cell_ref, para_env, input, my_ncommensurate, uf_grid, print_section)
951  TYPE(pw_grid_type), POINTER :: super_ref_pw_grid, mt_super_ref_pw_grid, &
952  xc_super_ref_pw_grid
953  REAL(kind=dp), INTENT(IN) :: cutilev
954  INTEGER, INTENT(IN) :: grid_span
955  LOGICAL, INTENT(in) :: spherical
956  TYPE(cell_type), POINTER :: cell_ref
957  TYPE(mp_para_env_type), POINTER :: para_env
958  TYPE(section_vals_type), POINTER :: input
959  INTEGER, INTENT(IN) :: my_ncommensurate
960  LOGICAL, INTENT(in) :: uf_grid
961  TYPE(section_vals_type), POINTER :: print_section
962 
963  INTEGER :: iounit, my_val, nn(3), no(3)
964  LOGICAL :: mt_s_grid
965  REAL(kind=dp) :: mt_rel_cutoff, my_cutilev
966  TYPE(cp_logger_type), POINTER :: logger
967  TYPE(section_vals_type), POINTER :: poisson_section
968 
969  NULLIFY (poisson_section)
970  cpassert(.NOT. ASSOCIATED(mt_super_ref_pw_grid))
971  cpassert(.NOT. ASSOCIATED(xc_super_ref_pw_grid))
972  cpassert(.NOT. ASSOCIATED(super_ref_pw_grid))
973  poisson_section => section_vals_get_subs_vals(input, "DFT%POISSON")
974  CALL section_vals_val_get(poisson_section, "POISSON_SOLVER", i_val=my_val)
975  !
976  ! Check if grids will be the same... In this case we don't use a super-reference grid
977  !
978  mt_s_grid = .false.
979  IF (my_val == pw_poisson_mt) THEN
980  CALL section_vals_val_get(poisson_section, "MT%REL_CUTOFF", &
981  r_val=mt_rel_cutoff)
982  IF (mt_rel_cutoff > 1._dp) mt_s_grid = .true.
983  END IF
984 
985  logger => cp_get_default_logger()
986  iounit = cp_print_key_unit_nr(logger, print_section, "", &
987  extension=".Log")
988 
989  IF (uf_grid) THEN
990  CALL pw_grid_create(xc_super_ref_pw_grid, para_env)
991  CALL pw_grid_setup(cell_ref%hmat, xc_super_ref_pw_grid, grid_span=grid_span, &
992  cutoff=4._dp*cutilev, spherical=spherical, odd=.false., fft_usage=.true., &
993  ncommensurate=my_ncommensurate, icommensurate=1, &
994  blocked=do_pw_grid_blocked_false, rs_dims=(/para_env%num_pe, 1/), &
995  iounit=iounit)
996  super_ref_pw_grid => xc_super_ref_pw_grid
997  END IF
998  IF (mt_s_grid) THEN
999  CALL pw_grid_create(mt_super_ref_pw_grid, para_env)
1000 
1001  IF (ASSOCIATED(xc_super_ref_pw_grid)) THEN
1002  cpabort("special grid for mt and fine xc grid not compatible")
1003  ELSE
1004  my_cutilev = cutilev*mt_rel_cutoff
1005 
1006  no = pw_grid_init_setup(cell_ref%hmat, cutoff=cutilev, spherical=spherical, &
1007  odd=.false., fft_usage=.true., ncommensurate=0, icommensurate=1)
1008  nn = pw_grid_init_setup(cell_ref%hmat, cutoff=my_cutilev, spherical=spherical, &
1009  odd=.false., fft_usage=.true., ncommensurate=0, icommensurate=1)
1010 
1011  ! bug appears for nn==no, also in old versions
1012  cpassert(all(nn > no))
1013  CALL pw_grid_setup(cell_ref%hmat, mt_super_ref_pw_grid, &
1014  cutoff=my_cutilev, spherical=spherical, fft_usage=.true., &
1015  blocked=do_pw_grid_blocked_false, rs_dims=(/para_env%num_pe, 1/), &
1016  iounit=iounit)
1017  super_ref_pw_grid => mt_super_ref_pw_grid
1018  END IF
1019  END IF
1020  CALL cp_print_key_finished_output(iounit, logger, print_section, &
1021  "")
1022  END SUBROUTINE setup_super_ref_grid
1023 
1024 ! **************************************************************************************************
1025 !> \brief sets up a real-space grid for finite difference derivative of dielectric
1026 !> constant function
1027 !> \param diel_rs_grid real space grid to be created
1028 !> \param method preferred finite difference derivative method
1029 !> \param input input file
1030 !> \param pw_grid plane-wave grid
1031 !> \par History
1032 !> 12.2014 created [Hossein Bani-Hashemian]
1033 !> \author Mohammad Hossein Bani-Hashemian
1034 ! **************************************************************************************************
1035  SUBROUTINE setup_diel_rs_grid(diel_rs_grid, method, input, pw_grid)
1036 
1037  TYPE(realspace_grid_type), POINTER :: diel_rs_grid
1038  INTEGER, INTENT(IN) :: method
1039  TYPE(section_vals_type), POINTER :: input
1040  TYPE(pw_grid_type), POINTER :: pw_grid
1041 
1042  CHARACTER(LEN=*), PARAMETER :: routinen = 'setup_diel_rs_grid'
1043 
1044  INTEGER :: border_points, handle
1045  TYPE(realspace_grid_desc_type), POINTER :: rs_desc
1046  TYPE(realspace_grid_input_type) :: input_settings
1047  TYPE(section_vals_type), POINTER :: rs_grid_section
1048 
1049  CALL timeset(routinen, handle)
1050 
1051  NULLIFY (rs_desc)
1052  rs_grid_section => section_vals_get_subs_vals(input, "DFT%MGRID%RS_GRID")
1053  SELECT CASE (method)
1054  CASE (derivative_cd3)
1055  border_points = 1
1056  CASE (derivative_cd5)
1057  border_points = 2
1058  CASE (derivative_cd7)
1059  border_points = 3
1060  END SELECT
1061  CALL init_input_type(input_settings, 2*border_points + 1, rs_grid_section, &
1062  1, (/-1, -1, -1/))
1063  CALL rs_grid_create_descriptor(rs_desc, pw_grid, input_settings, &
1064  border_points=border_points)
1065  ALLOCATE (diel_rs_grid)
1066  CALL rs_grid_create(diel_rs_grid, rs_desc)
1067 ! CALL rs_grid_print(diel_rs_grid,6)
1068  CALL rs_grid_release_descriptor(rs_desc)
1069 
1070  CALL timestop(handle)
1071 
1072  END SUBROUTINE setup_diel_rs_grid
1073 
1074 END MODULE pw_env_methods
1075 
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
subroutine, public get_gto_basis_set(gto_basis_set, name, aliases, norm_type, kind_radius, ncgf, nset, nsgf, cgf_symbol, sgf_symbol, norm_cgf, set_radius, lmax, lmin, lx, ly, lz, m, ncgf_set, npgf, nsgf_set, nshell, cphi, pgf_radius, sphi, scon, zet, first_cgf, first_sgf, l, last_cgf, last_sgf, n, gcc, maxco, maxl, maxpgf, maxsgf_set, maxshell, maxso, nco_sum, npgf_sum, nshell_sum, maxder, short_kind_radius)
...
Handles all functions related to the CELL.
Definition: cell_types.F:15
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
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,...
integer, parameter, public cp_p_file
integer function, public cp_print_key_should_output(iteration_info, basis_section, print_key_path, used_print_key, first_time)
returns what should be done with the given property if btest(res,cp_p_store) then the property should...
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
for a given dr()/dh(r) this will provide the bounds to be used if one wants to go over a sphere-subre...
Definition: cube_utils.F:18
integer function, public return_cube_max_iradius(info)
...
Definition: cube_utils.F:175
subroutine, public destroy_cube_info(info)
...
Definition: cube_utils.F:185
subroutine, public init_cube_info(info, dr, dh, dh_inv, ortho, max_radius)
...
Definition: cube_utils.F:212
Routines to efficiently handle dense polynomial in 3 variables up to a given degree....
Definition: d3_poly.F:23
subroutine, public init_d3_poly_module()
initialization of the cache, is called by functions in this module that use cached values
Definition: d3_poly.F:74
the type I Discrete Cosine Transform (DCT-I)
Definition: dct.F:16
integer, parameter, public neumannx
Definition: dct.F:64
integer, parameter, public neumannxy
Definition: dct.F:64
integer, parameter, public neumannxz
Definition: dct.F:64
integer, parameter, public neumannxyz
Definition: dct.F:64
integer, parameter, public neumannz
Definition: dct.F:64
integer, parameter, public neumannyz
Definition: dct.F:64
subroutine, public setup_dct_pw_grids(pw_grid, cell_hmat, neumann_directions, dct_pw_grid)
sets up an extended pw_grid for Discrete Cosine Transform (DCT) calculations
Definition: dct.F:163
integer, parameter, public neumanny
Definition: dct.F:64
dielectric constant data type
integer, parameter, public derivative_cd5
integer, parameter, public derivative_cd3
integer, parameter, public rho_dependent
integer, parameter, public derivative_cd7
integer function, public gaussian_gridlevel(gridlevel_info, exponent)
...
subroutine, public destroy_gaussian_gridlevel(gridlevel_info, para_env)
...
subroutine, public init_gaussian_gridlevel(gridlevel_info, ngrid_levels, cutoff, rel_cutoff, print_section)
...
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public do_method_ofgpw
integer, parameter, public do_method_rigpw
integer, parameter, public do_method_gpw
integer, parameter, public xc_vdw_fun_nonloc
integer, parameter, public do_method_gapw
integer, parameter, public do_method_lrigpw
integer, parameter, public do_method_gapw_xc
objects that represent the structure of input sections and the data contained in an input section
integer function, public section_get_ival(section_vals, keyword_name)
...
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
subroutine, public section_vals_get(section_vals, ref_count, n_repetition, n_subs_vals_rep, section, explicit)
returns various attributes about the section_vals
subroutine, public section_vals_val_get(section_vals, keyword_name, i_rep_section, i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, c_vals, explicit)
returns the requested value
Defines the basic variable types.
Definition: kinds.F:23
integer, parameter, public dp
Definition: kinds.F:34
Interface to the message passing library MPI.
Types containing essential information for running implicit (iterative) Poisson solver.
integer, parameter, public neumann_bc
integer, parameter, public mixed_bc
integer, parameter, public mixed_periodic_bc
integer, parameter, public periodic_bc
Definition and initialisation of the ps_wavelet data type.
integer, parameter, public wavelet3d
integer, parameter, public wavelet0d
integer, parameter, public wavelet2d
methods of pw_env that have dependence on qs_env
subroutine, public pw_env_rebuild(pw_env, qs_env, external_para_env)
rebuilds the pw_env data (necessary if cell or cutoffs change)
subroutine, public pw_env_create(pw_env)
creates a pw_env, if qs_env is given calls pw_env_rebuild
container for various plainwaves related things
Definition: pw_env_types.F:14
This module returns additional info on PW grids.
Definition: pw_grid_info.F:14
integer function, dimension(3), public pw_grid_init_setup(hmat, cutoff, spherical, odd, fft_usage, ncommensurate, icommensurate, ref_grid, n_orig)
...
Definition: pw_grid_info.F:48
integer, parameter, public halfspace
Definition: pw_grid_types.F:28
integer, parameter, public fullspace
Definition: pw_grid_types.F:28
This module defines the grid data type and some basic operations on it.
Definition: pw_grids.F:36
integer, parameter, public do_pw_grid_blocked_false
Definition: pw_grids.F:78
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_grid_change(cell_hmat, pw_grid)
Recalculate the g-vectors after a change of the box.
Definition: pw_grids.F:2068
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 pw_poisson_wavelet
integer, parameter, public pw_poisson_periodic
integer, parameter, public pw_poisson_none
integer, parameter, public pw_poisson_mt
integer, parameter, public pw_poisson_implicit
integer, parameter, public pw_poisson_analytic
integer, parameter, public pw_poisson_multipole
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_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
Definition of disperson types for DFT calculations.
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_RI_aux_kp, matrix_s, matrix_s_RI_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, ecoul_1c, rho0_s_rs, rho0_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, WannierCentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, rhs)
Get the QUICKSTEP environment.
Define the quickstep kind type and their sub types.
Definition: qs_kind_types.F:23
subroutine, public get_qs_kind(qs_kind, basis_set, basis_type, ncgf, nsgf, all_potential, tnadd_potential, gth_potential, sgp_potential, upf_potential, se_parameter, dftb_parameter, xtb_parameter, dftb3_param, zeff, elec_conf, mao, lmax_dftb, alpha_core_charge, ccore_charge, core_charge, core_charge_radius, paw_proj_set, paw_atom, hard_radius, hard0_radius, max_rad_local, covalent_radius, vdw_radius, gpw_r3d_rs_type_forced, harmonics, max_iso_not0, max_s_harm, grid_atom, ngrid_ang, ngrid_rad, lmax_rho0, dft_plus_u_atom, l_of_dft_plus_u, n_of_dft_plus_u, u_minus_j, U_of_dft_plus_u, J_of_dft_plus_u, alpha_of_dft_plus_u, beta_of_dft_plus_u, J0_of_dft_plus_u, occupation_of_dft_plus_u, dispersion, bs_occupation, magnetization, no_optimize, addel, laddel, naddel, orbitals, max_scf, eps_scf, smear, u_ramping, u_minus_j_target, eps_u_ramping, init_u_ramping_each_scf, reltmat, ghost, floating, name, element_symbol, pao_basis_size, pao_potentials, pao_descriptors, nelec)
Get attributes of an atomic kind.
subroutine, public get_rho0_mpole(rho0_mpole, g0_h, vg0_h, iat, ikind, lmax_0, l0_ikind, mp_gau_ikind, mp_rho, norm_g0l_h, Qlm_gg, Qlm_car, Qlm_tot, zet0_h, igrid_zet0_s, rpgf0_h, rpgf0_s, max_rpgf0_s, rho0_s_rs, rho0_s_gs)
...
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_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)
input constants for xc
integer, parameter, public xc_deriv_spline2_smooth
integer, parameter, public xc_rho_spline2_smooth
integer, parameter, public xc_deriv_collocate
integer, parameter, public xc_rho_spline3_smooth
integer, parameter, public xc_deriv_nn10_smooth
integer, parameter, public xc_deriv_pw
integer, parameter, public xc_deriv_spline2
integer, parameter, public xc_rho_nn10
integer, parameter, public xc_deriv_nn50_smooth
integer, parameter, public xc_deriv_spline3
integer, parameter, public xc_rho_nn50
integer, parameter, public xc_deriv_spline3_smooth
integer, parameter, public xc_rho_no_smooth