27 USE gx_ac,
ONLY: create_thiele_pade, &
28 evaluate_thiele_pade_at, &
31 USE gx_minimax,
ONLY: gx_minimax_grid
34#include "./base/base_uses.f90"
40 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'greenx_interface'
63 imaginary_time, time_weights_at_zero_frequency, frequency, &
64 frequency_weights, cosine_time_to_frequency_weights, &
65 cosine_frequency_to_time_weights, sine_time_to_frequency_weights, ierr)
67 INTEGER,
INTENT(IN) :: unit_nr, num_integ_points
68 REAL(kind=
dp),
INTENT(IN) :: emin, emax, regularization_minimax
69 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:),
INTENT(OUT) :: imaginary_time, &
70 time_weights_at_zero_frequency, &
71 frequency, frequency_weights
72 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :),
INTENT(OUT) :: cosine_time_to_frequency_weights, &
73 cosine_frequency_to_time_weights, &
74 sine_time_to_frequency_weights
75 INTEGER,
INTENT(OUT) :: ierr
79 REAL(kind=
dp) :: cosft_duality_error_greenx, &
82 CALL gx_minimax_grid(num_integ_points, emin, emax, imaginary_time, &
83 time_weights_at_zero_frequency, frequency, frequency_weights, &
84 cosine_time_to_frequency_weights, cosine_frequency_to_time_weights, &
85 sine_time_to_frequency_weights, max_errors_greenx, cosft_duality_error_greenx, ierr, &
86 bare_cos_sin_weights=.true., regularization=regularization_minimax)
89 frequency_weights(:) = frequency_weights(:)*4.0_dp
91 WRITE (unit=unit_nr, fmt=
"(T3,A,T75,i6)") &
92 "GREENX MINIMAX_INFO| Number of integration points:", num_integ_points
93 WRITE (unit=unit_nr, fmt=
"(T3,A,T61,3F20.7)") &
94 "GREENX MINIMAX_INFO| Gap (Emin):", emin
95 WRITE (unit=unit_nr, fmt=
"(T3,A,T61,3F20.7)") &
96 "GREENX MINIMAX_INFO| Maximum eigenvalue difference (Emax):", emax
97 WRITE (unit=unit_nr, fmt=
"(T3,A,T61,3F20.4)") &
98 "GREENX MINIMAX_INFO| Energy range (Emax/Emin):", emax/emin
99 WRITE (unit=unit_nr, fmt=
"(T3,A,T54,A,T72,A)") &
100 "GREENX MINIMAX_INFO| Frequency grid (scaled):",
"Weights",
"Abscissas"
101 DO gi = 1, num_integ_points
102 WRITE (unit=unit_nr, fmt=
"(T41,F20.10,F20.10)") frequency_weights(gi), frequency(gi)
104 WRITE (unit=unit_nr, fmt=
"(T3,A,T54,A,T72,A)") &
105 "GREENX MINIMAX_INFO| Time grid (scaled):",
"Weights",
"Abscissas"
106 DO gi = 1, num_integ_points
107 WRITE (unit=unit_nr, fmt=
"(T41,F20.10,F20.10)") &
108 time_weights_at_zero_frequency(gi), imaginary_time(gi)
113 IF (unit_nr > 0)
THEN
114 WRITE (unit=unit_nr, fmt=
"(T3,A,T75)") &
115 "GREENX MINIMAX_INFO| Grid not available, use internal CP2K grids"
122 mark_used(num_integ_points)
125 mark_used(regularization_minimax)
126 mark_used(imaginary_time)
127 mark_used(time_weights_at_zero_frequency)
129 mark_used(frequency_weights)
130 mark_used(cosine_time_to_frequency_weights)
131 mark_used(cosine_frequency_to_time_weights)
132 mark_used(sine_time_to_frequency_weights)
150 SUBROUTINE greenx_refine_pade(e_min, e_max, x_eval, number_of_simulation_steps, number_of_pade_points, &
151 logger, ft_section, bse_unit, omega_series, ft_full_series)
152 REAL(kind=
dp),
INTENT(IN) :: e_min, e_max
153 COMPLEX(KIND=dp),
DIMENSION(:),
POINTER :: x_eval
154 INTEGER,
INTENT(IN) :: number_of_simulation_steps, number_of_pade_points
157 INTEGER,
INTENT(IN) :: bse_unit
158 REAL(kind=
dp),
DIMENSION(number_of_simulation_steps + 2),
INTENT(INOUT) :: omega_series
159 REAL(kind=
dp),
DIMENSION(6, number_of_simulation_steps + 2),
INTENT(INOUT) :: ft_full_series
160#if defined (__GREENX)
161 INTEGER :: i, ft_unit
162 COMPLEX(kind=dp),
DIMENSION(:),
ALLOCATABLE :: omega_complex, &
164 COMPLEX(kind=dp),
DIMENSION(:, :),
ALLOCATABLE :: moments_eval_complex
167 IF (bse_unit > 0)
WRITE (bse_unit,
'(A10,A27,E23.8E3,E20.8E3)') &
168 " PADE_FT| ",
"Evaluation grid bounds [eV]", e_min, e_max
169 ALLOCATE (omega_complex(number_of_simulation_steps + 2))
170 ALLOCATE (moments_ft_complex(number_of_simulation_steps + 2))
171 ALLOCATE (moments_eval_complex(3, number_of_pade_points))
172 omega_complex(:) = cmplx(omega_series(:), 0.0, kind=
dp)
174 moments_ft_complex(:) = cmplx(ft_full_series(2*i - 1, :), &
175 ft_full_series(2*i, :), &
179 CALL greenx_refine_ft(e_min, e_max, omega_complex, moments_ft_complex, x_eval, moments_eval_complex(i, :))
183 file_form=
"FORMATTED", file_position=
"REWIND")
184 IF (ft_unit > 0)
THEN
185 DO i = 1, number_of_pade_points
186 WRITE (ft_unit,
'(E20.8E3,E20.8E3,E20.8E3,E20.8E3,E20.8E3,E20.8E3,E20.8E3)') &
187 REAL(x_eval(i)),
REAL(moments_eval_complex(1, i)), aimag(moments_eval_complex(1, i)), &
188 REAL(moments_eval_complex(2, i)), aimag(moments_eval_complex(2, i)), &
189 REAL(moments_eval_complex(3, i)), aimag(moments_eval_complex(3, i))
193 DEALLOCATE (omega_complex)
194 DEALLOCATE (moments_ft_complex)
195 DEALLOCATE (moments_eval_complex)
197 IF (bse_unit > 0)
WRITE (bse_unit,
'(A10,A70)') &
198 " PADE_FT| ",
"GreenX library is not available. Refinement is skipped"
202 mark_used(number_of_simulation_steps)
203 mark_used(number_of_pade_points)
205 mark_used(ft_section)
206 mark_used(omega_series)
207 mark_used(ft_full_series)
224 INTEGER,
INTENT(IN) :: bse_unit
225 INTEGER,
DIMENSION(:, :),
POINTER :: pol_elements
226 COMPLEX(KIND=dp),
DIMENSION(:),
POINTER :: x_eval
227 COMPLEX(kind=dp),
DIMENSION(:, :),
INTENT(IN) :: polarizability_refined
229 INTEGER :: pol_unit, &
232 n_elems =
SIZE(pol_elements, 1)
235 file_form=
"FORMATTED", file_position=
"REWIND")
237 IF (pol_unit > 0)
THEN
238 IF (pol_unit == bse_unit)
THEN
240 WRITE (pol_unit,
'(A21)', advance=
"no")
" POLARIZABILITY_PADE|"
243 WRITE (pol_unit,
'(A1,A19)', advance=
"no")
"#",
"omega [a.u.]"
246 WRITE (pol_unit,
'(A20)', advance=
"no")
"Energy [eV]"
248 DO k = 1, n_elems - 1
249 WRITE (pol_unit,
'(A16,I2,I2,A16,I2,I2)', advance=
"no") &
250 "Real pol.", pol_elements(k, 1), pol_elements(k, 2), &
251 "Imag pol.", pol_elements(k, 1), pol_elements(k, 2)
253 WRITE (pol_unit,
'(A16,I2,I2,A16,I2,I2)') &
254 "Real pol.", pol_elements(n_elems, 1), pol_elements(n_elems, 2), &
255 "Imag pol.", pol_elements(n_elems, 1), pol_elements(n_elems, 2)
256 DO i = 1,
SIZE(x_eval)
257 IF (pol_unit == bse_unit)
THEN
259 WRITE (pol_unit,
'(A21)', advance=
"no")
" POLARIZABILITY_PADE|"
262 WRITE (pol_unit,
'(E20.8E3)', advance=
"no") real(x_eval(i), kind=
dp)
265 WRITE (pol_unit,
'(E20.8E3)', advance=
"no") real(x_eval(i), kind=
dp)*
evolt
266 DO k = 1, n_elems - 1
267 WRITE (pol_unit,
'(E20.8E3,E20.8E3)', advance=
"no") &
268 REAL(polarizability_refined(k, i)), aimag(polarizability_refined(k, i))
271 WRITE (pol_unit,
'(E20.8E3,E20.8E3)') &
272 REAL(polarizability_refined(n_elems, i)), aimag(polarizability_refined(n_elems, i))
278 mark_used(pol_section)
280 mark_used(pol_elements)
282 mark_used(polarizability_refined)
295 SUBROUTINE greenx_refine_ft(fit_e_min, fit_e_max, x_fit, y_fit, x_eval, y_eval, n_pade_opt)
296 REAL(kind=
dp) :: fit_e_min, &
298 COMPLEX(kind=dp),
DIMENSION(:) :: x_fit, &
302 INTEGER,
OPTIONAL :: n_pade_opt
303#if defined (__GREENX)
304 CHARACTER(len=*),
PARAMETER :: routinen =
'greenx_refine_ft'
306 INTEGER :: fit_start, &
316 TYPE(params) :: pade_params
318 CALL timeset(routinen, handle)
321 max_fit =
SIZE(x_fit)
322 n_eval =
SIZE(x_eval)
330 IF (fit_e_max < 0) fit_end = max_fit
332 IF (fit_start == -1 .AND. real(x_fit(i)) >= fit_e_min) fit_start = i
333 IF (fit_end == -1 .AND. real(x_fit(i)) > fit_e_max) fit_end = i - 1
334 IF (fit_start > 0 .AND. fit_end > 0)
EXIT
336 IF (fit_start == -1) fit_start = 1
337 IF (fit_end == -1) fit_end = max_fit
338 n_fit = fit_end - fit_start + 1
341 IF (
PRESENT(n_pade_opt)) n_pade = n_pade_opt
346 cpwarn(
"FT deck too short for Padé; raise STEPS or disable &FT.")
347 y_eval(1:n_eval) = cmplx(0.0, 0.0, kind=
dp)
348 CALL timestop(handle)
353 IF (n_pade > 1000)
THEN
354 cpwarn(
"More then 1000 Padé parameters requested - may reduce with FIT_E_MIN/FIT_E_MAX.")
361 IF (unit_nr > 0)
THEN
362 WRITE (unit=unit_nr, fmt=
"(T3,A,T45,I6,I8,2F11.4)") &
363 "GREENX FT_PADE| n_pade, n_fit, window [eV]", n_pade, n_fit, &
364 REAL(x_fit(fit_start), kind=
dp)*
evolt, real(x_fit(fit_end), kind=
dp)*
evolt
369 pade_params = create_thiele_pade(n_pade, x_fit(fit_start:fit_end), y_fit(fit_start:fit_end), &
370 enforce_symmetry=
"conjugate")
373 y_eval(1:n_eval) = evaluate_thiele_pade_at(pade_params, x_eval)
375 CALL free_params(pade_params)
376 CALL timestop(handle)
385 mark_used(n_pade_opt)
386 cpabort(
"Calls to GreenX require CP2K to be compiled with support for GreenX.")
various routines to log and control the output. The idea is that decisions about where to log should ...
integer function, public cp_logger_get_default_io_unit(logger)
returns the unit nr for the ionode (-1 on all other processors) skips as well checks if the procs cal...
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)
...
integer, parameter, public low_print_level
integer, parameter, public medium_print_level
character(len=default_path_length) function, public cp_print_key_generate_filename(logger, print_key, middle_name, extension, my_local)
Utility function that returns a unit number to write the print key. Might open a file with a unique f...
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,...
Interface to the Greenx library.
subroutine, public greenx_refine_ft(fit_e_min, fit_e_max, x_fit, y_fit, x_eval, y_eval, n_pade_opt)
Refines the FT grid using Padé approximants.
subroutine, public greenx_refine_pade(e_min, e_max, x_eval, number_of_simulation_steps, number_of_pade_points, logger, ft_section, bse_unit, omega_series, ft_full_series)
Refines Pade approximants using GreenX, skips this step if GreenX is not available.
subroutine, public greenx_output_polarizability(logger, pol_section, bse_unit, pol_elements, x_eval, polarizability_refined)
Outputs the isotropic polarizability tensor element alpha _ ij = mu_i(omega)/E_j(omega),...
subroutine, public greenx_get_minimax_grid(unit_nr, num_integ_points, emin, emax, regularization_minimax, imaginary_time, time_weights_at_zero_frequency, frequency, frequency_weights, cosine_time_to_frequency_weights, cosine_frequency_to_time_weights, sine_time_to_frequency_weights, ierr)
Get a minimax grid from GreenX when it is available.
Defines the basic variable types.
integer, parameter, public dp
Machine interface based on Fortran 2003 and POSIX.
subroutine, public m_flush(lunit)
flushes units if the &GLOBAL flag is set accordingly
Definition of physical constants:
real(kind=dp), parameter, public evolt
type of a logger, at the moment it contains just a print level starting at which level it should be l...