52#include "./base/base_uses.f90"
66 LOGICAL :: do_multipoles = .false.
67 INTEGER :: do_ipol = -1
68 INTEGER :: max_multipole = -1
69 INTEGER :: max_ipol_iter = -1
70 INTEGER :: ewald_type = -1
71 INTEGER :: gmax(3) = -1
72 INTEGER :: ns_max = -1
73 INTEGER :: o_spline = -1
74 REAL(kind=
dp) :: precs = 0.0_dp
75 REAL(kind=
dp) :: alpha = 0.0_dp, rcut = 0.0_dp
76 REAL(kind=
dp) :: epsilon = 0.0_dp
77 REAL(kind=
dp) :: eps_pol = 0.0_dp
83 REAL(kind=
dp),
DIMENSION(:, :, :),
POINTER :: interaction_cutoffs => null()
85 REAL(kind=
dp),
DIMENSION(3, 3) :: cell_hmat = -1.0_dp
99 CHARACTER(len=*),
PARAMETER,
PRIVATE :: modulen =
'ewald_environment_types'
129 gmax, ns_max, o_spline, group, para_env, poisson_section, precs, &
130 rcut, do_multipoles, max_multipole, do_ipol, max_ipol_iter, &
131 interaction_cutoffs, cell_hmat)
133 INTEGER,
OPTIONAL :: ewald_type
134 REAL(kind=
dp),
OPTIONAL :: alpha, eps_pol, epsilon
135 INTEGER,
OPTIONAL :: gmax(3), ns_max, o_spline
139 REAL(kind=
dp),
OPTIONAL :: precs, rcut
140 LOGICAL,
INTENT(OUT),
OPTIONAL :: do_multipoles
141 INTEGER,
INTENT(OUT),
OPTIONAL :: max_multipole, do_ipol, max_ipol_iter
142 REAL(kind=
dp),
DIMENSION(:, :, :),
OPTIONAL, &
143 POINTER :: interaction_cutoffs
144 REAL(kind=
dp),
DIMENSION(3, 3),
OPTIONAL :: cell_hmat
146 IF (
PRESENT(ewald_type)) ewald_type = ewald_env%ewald_type
147 IF (
PRESENT(do_multipoles)) do_multipoles = ewald_env%do_multipoles
148 IF (
PRESENT(do_ipol)) do_ipol = ewald_env%do_ipol
149 IF (
PRESENT(max_multipole)) max_multipole = ewald_env%max_multipole
150 IF (
PRESENT(max_ipol_iter)) max_ipol_iter = ewald_env%max_ipol_iter
151 IF (
PRESENT(alpha)) alpha = ewald_env%alpha
152 IF (
PRESENT(precs)) precs = ewald_env%precs
153 IF (
PRESENT(rcut)) rcut = ewald_env%rcut
154 IF (
PRESENT(epsilon)) epsilon = ewald_env%epsilon
155 IF (
PRESENT(eps_pol)) eps_pol = ewald_env%eps_pol
156 IF (
PRESENT(gmax)) gmax = ewald_env%gmax
157 IF (
PRESENT(ns_max)) ns_max = ewald_env%ns_max
158 IF (
PRESENT(o_spline)) o_spline = ewald_env%o_spline
159 IF (
PRESENT(group)) group = ewald_env%para_env
160 IF (
PRESENT(para_env)) para_env => ewald_env%para_env
161 IF (
PRESENT(poisson_section)) poisson_section => ewald_env%poisson_section
162 IF (
PRESENT(interaction_cutoffs)) interaction_cutoffs => &
163 ewald_env%interaction_cutoffs
164 IF (
PRESENT(cell_hmat)) cell_hmat = ewald_env%cell_hmat
187 gmax, ns_max, precs, o_spline, para_env, poisson_section, &
188 interaction_cutoffs, cell_hmat)
191 INTEGER,
OPTIONAL :: ewald_type
192 REAL(kind=
dp),
OPTIONAL :: alpha, epsilon, eps_pol
193 INTEGER,
OPTIONAL :: gmax(3), ns_max
194 REAL(kind=
dp),
OPTIONAL :: precs
195 INTEGER,
OPTIONAL :: o_spline
198 REAL(kind=
dp),
DIMENSION(:, :, :),
OPTIONAL, &
199 POINTER :: interaction_cutoffs
200 REAL(kind=
dp),
DIMENSION(3, 3),
OPTIONAL :: cell_hmat
202 IF (
PRESENT(ewald_type)) ewald_env%ewald_type = ewald_type
203 IF (
PRESENT(alpha)) ewald_env%alpha = alpha
204 IF (
PRESENT(precs)) ewald_env%precs = precs
205 IF (
PRESENT(epsilon)) ewald_env%epsilon = epsilon
206 IF (
PRESENT(eps_pol)) ewald_env%eps_pol = eps_pol
207 IF (
PRESENT(gmax)) ewald_env%gmax = gmax
208 IF (
PRESENT(ns_max)) ewald_env%ns_max = ns_max
209 IF (
PRESENT(o_spline)) ewald_env%o_spline = o_spline
210 IF (
PRESENT(para_env)) ewald_env%para_env => para_env
211 IF (
PRESENT(poisson_section))
THEN
214 ewald_env%poisson_section => poisson_section
216 IF (
PRESENT(interaction_cutoffs)) ewald_env%interaction_cutoffs => &
218 IF (
PRESENT(cell_hmat)) ewald_env%cell_hmat = cell_hmat
233 NULLIFY (ewald_env%poisson_section)
234 CALL para_env%retain()
235 ewald_env%para_env => para_env
236 NULLIFY (ewald_env%interaction_cutoffs)
251 IF (
ASSOCIATED(ewald_env%interaction_cutoffs))
THEN
252 DEALLOCATE (ewald_env%interaction_cutoffs)
268 INTEGER,
DIMENSION(:),
POINTER :: gmax_read
270 REAL(kind=
dp) :: dummy
277 NULLIFY (enum, keyword, section, multipole_section)
284 ewald_env%rcut = 0.0_dp
290 ewald_env%rcut = find_ewald_optimal_value(ewald_env%precs)/ewald_env%alpha
294 SELECT CASE (ewald_env%ewald_type)
297 SELECT CASE (
SIZE(gmax_read, 1))
299 ewald_env%gmax = gmax_read(1)
301 ewald_env%gmax = gmax_read
313 ewald_env%gmax = huge(0)
314 ewald_env%ns_max = huge(0)
319 CALL section_vals_val_get(multipole_section,
"_SECTION_PARAMETERS_", l_val=ewald_env%do_multipoles)
322 IF (ewald_env%do_multipoles)
THEN
323 SELECT CASE (ewald_env%ewald_type)
326 i_val=ewald_env%max_multipole)
329 cpabort(
"Multipole code works at the moment only with standard EWALD sums.")
336 NULLIFY (keyword, enum)
341 WRITE (iw,
'(/,T2,"EWALD| ",A,T67,A14 )')
'Summation is done by:', &
342 adjustr(trim(
enum_i2c(enum, ewald_env%ewald_type)))
343 IF (ewald_env%do_multipoles)
THEN
344 NULLIFY (keyword, enum)
347 WRITE (iw,
'( T2,"EWALD| ",A )')
'Enabled Multipole Method'
348 WRITE (iw,
'( T2,"EWALD| ",A,T67,A14 )')
'Max Term in Multipole Expansion :', &
349 adjustr(trim(
enum_i2c(enum, ewald_env%max_multipole)))
350 WRITE (iw,
'( T2,"EWALD| ",A,T67,3I10 )')
'Max number Iterations for IPOL :', &
351 ewald_env%max_ipol_iter
354 WRITE (iw,
'( T2,"EWALD| ",A,A18,A,T71,F10.4 )') &
355 'Alpha parameter [',
'ANGSTROM^-1',
']', dummy
357 WRITE (iw,
'( T2,"EWALD| ",A,A18,A,T71,F10.4 )') &
358 'Real Space Cutoff [',
'ANGSTROM',
']', dummy
360 SELECT CASE (ewald_env%ewald_type)
362 WRITE (iw,
'( T2,"EWALD| ",A,T51,3I10 )') &
363 'G-space max. Miller index', ewald_env%gmax
365 WRITE (iw,
'( T2,"EWALD| ",A,T71,I10 )') &
366 'Max small-grid points (input) ', ewald_env%ns_max
367 WRITE (iw,
'( T2,"EWALD| ",A,T71,E10.4 )') &
368 'Gaussian tolerance (input) ', ewald_env%epsilon
370 WRITE (iw,
'( T2,"EWALD| ",A,T51,3I10 )') &
371 'G-space max. Miller index', ewald_env%gmax
372 WRITE (iw,
'( T2,"EWALD| ",A,T71,I10 )') &
373 'Spline interpolation order ', ewald_env%o_spline
378 WRITE (iw,
'( T2,"EWALD| ",T73, A )')
'not used'
383 "PRINT%PROGRAM_RUN_INFO")
400 REAL(kind=
dp),
DIMENSION(3, 3),
INTENT(IN) :: hmat
401 LOGICAL,
INTENT(IN),
OPTIONAL :: silent
402 CHARACTER(LEN=*),
OPTIONAL :: pset
403 INTEGER,
DIMENSION(3),
INTENT(IN),
OPTIONAL :: cell_periodic
405 CHARACTER(LEN=5) :: param
406 INTEGER :: i, iw, n(3), poisson_key
407 INTEGER,
DIMENSION(3) :: poisson_periodic
408 INTEGER,
DIMENSION(:),
POINTER :: gmax_read
409 LOGICAL :: do_print, explicit
410 REAL(kind=
dp) :: alat, cutoff, dummy, omega
416 IF (
PRESENT(silent)) do_print = .NOT. silent
418 IF (
PRESENT(pset)) param = pset
420 IF (
PRESENT(cell_periodic))
THEN
421 poisson_section => ewald_env%poisson_section
422 IF (
ASSOCIATED(poisson_section))
THEN
424 CALL tb_decode_periodicity(poisson_key, poisson_periodic)
425 IF (any(cell_periodic /= poisson_periodic))
THEN
426 CALL cp_warn(__location__, &
427 "The selected periodicities in SUBSYS/CELL and DFT/POISSON do not match. "// &
428 "The TB Ewald electrostatics will use DFT/POISSON/PERIODIC="// &
429 trim(tb_periodicity_label(poisson_periodic))// &
430 " while SUBSYS/CELL/PERIODIC="//trim(tb_periodicity_label(cell_periodic))//
".")
435 ewald_env%do_multipoles = .false.
436 ewald_env%do_ipol = 0
437 ewald_env%eps_pol = 1.e-12_dp
438 ewald_env%max_multipole = 0
439 ewald_env%max_ipol_iter = 0
440 ewald_env%epsilon = 1.e-12_dp
441 ewald_env%ns_max = huge(0)
447 cpabort(
"TB needs EWALD_TYPE SPME")
462 ewald_env%alpha = sqrt(
twopi)/omega**(1./3.)
479 ewald_env%o_spline = 6
481 ewald_env%o_spline = 4
489 ewald_env%rcut = find_ewald_optimal_value(ewald_env%precs)/ewald_env%alpha
495 SELECT CASE (
SIZE(gmax_read, 1))
497 ewald_env%gmax = gmax_read(1)
499 ewald_env%gmax = gmax_read
507 cutoff = 45._dp*ewald_env%alpha
510 cutoff = 30._dp*ewald_env%alpha
513 alat = sum(hmat(:, i)**2)
514 cpassert(alat /= 0._dp)
515 ewald_env%gmax(i) = 2*floor(sqrt(2.0_dp*cutoff*alat)/
twopi) + 1
523 IF (iw > 0 .AND. do_print)
THEN
524 WRITE (iw,
'(/,T2,"EWALD| ",A,T67,A14 )')
'Summation is done by:', adjustr(
"SPME")
526 WRITE (iw,
'( T2,"EWALD| ",A,A18,A,T71,F10.4 )') &
527 'Alpha parameter [',
'ANGSTROM^-1',
']', dummy
529 WRITE (iw,
'( T2,"EWALD| ",A,A18,A,T71,F10.4 )') &
530 'Real Space Cutoff [',
'ANGSTROM',
']', dummy
531 WRITE (iw,
'( T2,"EWALD| ",A,T51,3I10 )') &
532 'G-space max. Miller index', ewald_env%gmax
533 WRITE (iw,
'( T2,"EWALD| ",A,T71,I10 )') &
534 'Spline interpolation order ', ewald_env%o_spline
537 "PRINT%PROGRAM_RUN_INFO")
546 SUBROUTINE tb_decode_periodicity(periodic_key, periodic)
547 INTEGER,
INTENT(IN) :: periodic_key
548 INTEGER,
DIMENSION(3),
INTENT(OUT) :: periodic
550 SELECT CASE (periodic_key)
568 cpabort(
"Invalid PERIODIC setting for TB Ewald")
571 END SUBROUTINE tb_decode_periodicity
578 FUNCTION tb_periodicity_label(periodic)
RESULT(label)
579 INTEGER,
DIMENSION(3),
INTENT(IN) :: periodic
580 CHARACTER(LEN=4) :: label
583 IF (all(periodic == 0))
THEN
586 IF (periodic(1) == 1) label = trim(label)//
"X"
587 IF (periodic(2) == 1) label = trim(label)//
"Y"
588 IF (periodic(3) == 1) label = trim(label)//
"Z"
591 END FUNCTION tb_periodicity_label
600 FUNCTION find_ewald_optimal_value(precs)
RESULT(value)
601 REAL(kind=
dp) :: precs,
value
603 REAL(kind=
dp) :: func, func1, func2, s, s1, s2
606 func = exp(-s**2)/s**2 - precs
607 cpassert(func > 0.0_dp)
608 DO WHILE (func > 0.0_dp)
610 func = exp(-s**2)/s**2 - precs
616 func2 = exp(-s2**2)/s2**2 - precs
617 func1 = exp(-s1**2)/s1**2 - precs
621 func = exp(-s**2)/s**2 - precs
622 IF (func > 0.0_dp)
THEN
624 ELSE IF (func < 0.0_dp)
THEN
627 IF (abs(func) < 100.0_dp*epsilon(0.0_dp))
EXIT
630 END FUNCTION find_ewald_optimal_value
Handles all functions related to the CELL.
integer, parameter, public use_perd_xyz
integer, parameter, public use_perd_y
integer, parameter, public use_perd_xz
integer, parameter, public use_perd_x
integer, parameter, public use_perd_z
integer, parameter, public use_perd_yz
integer, parameter, public use_perd_none
integer, parameter, public use_perd_xy
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,...
real(kind=dp) function, public cp_unit_from_cp2k(value, unit_str, defaults, power)
converts from the internal cp2k units to the given unit
subroutine, public ewald_env_set(ewald_env, ewald_type, alpha, epsilon, eps_pol, gmax, ns_max, precs, o_spline, para_env, poisson_section, interaction_cutoffs, cell_hmat)
Purpose: Set the EWALD environment.
subroutine, public ewald_env_create(ewald_env, para_env)
allocates and intitializes a ewald_env
subroutine, public read_ewald_section(ewald_env, ewald_section)
Purpose: read the EWALD section.
subroutine, public read_ewald_section_tb(ewald_env, ewald_section, hmat, silent, pset, cell_periodic)
Purpose: read the EWALD section for TB methods.
subroutine, public ewald_env_release(ewald_env)
releases the given ewald_env (see doc/ReferenceCounting.html)
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.
Defines the basic variable types.
integer, parameter, public dp
Definition of mathematical constants and functions.
real(kind=dp), parameter, public twopi
Collection of simple mathematical functions and subroutines.
Interface to the message passing library MPI.
subroutine, public mp_para_env_release(para_env)
releases the para object (to be called when you don't want anymore the shared copy of this object)
This module returns additional info on PW grids.
integer function, dimension(3), public pw_grid_n_for_fft(n, odd)
returns the closest number of points >= n, on which you can perform ffts
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
type of a logger, at the moment it contains just a print level starting at which level it should be l...
to build arrays of pointers
stores all the informations relevant to an mpi environment