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'
59 SUBROUTINE greenx_refine_pade(e_min, e_max, x_eval, number_of_simulation_steps, number_of_pade_points, &
60 logger, ft_section, bse_unit, omega_series, ft_full_series)
61 REAL(kind=
dp),
INTENT(IN) :: e_min, e_max
62 COMPLEX(KIND=dp),
DIMENSION(:),
POINTER :: x_eval
63 INTEGER,
INTENT(IN) :: number_of_simulation_steps, number_of_pade_points
66 INTEGER,
INTENT(IN) :: bse_unit
67 REAL(kind=
dp),
DIMENSION(number_of_simulation_steps + 2),
INTENT(INOUT) :: omega_series
68 REAL(kind=
dp),
DIMENSION(6, number_of_simulation_steps + 2),
INTENT(INOUT) :: ft_full_series
71 COMPLEX(kind=dp),
DIMENSION(:),
ALLOCATABLE :: omega_complex, &
73 COMPLEX(kind=dp),
DIMENSION(:, :),
ALLOCATABLE :: moments_eval_complex
76 IF (bse_unit > 0)
WRITE (bse_unit,
'(A10,A27,E23.8E3,E20.8E3)') &
77 " PADE_FT| ",
"Evaluation grid bounds [eV]", e_min, e_max
78 ALLOCATE (omega_complex(number_of_simulation_steps + 2))
79 ALLOCATE (moments_ft_complex(number_of_simulation_steps + 2))
80 ALLOCATE (moments_eval_complex(3, number_of_pade_points))
81 omega_complex(:) = cmplx(omega_series(:), 0.0, kind=
dp)
83 moments_ft_complex(:) = cmplx(ft_full_series(2*i - 1, :), &
84 ft_full_series(2*i, :), &
88 CALL greenx_refine_ft(e_min, e_max, omega_complex, moments_ft_complex, x_eval, moments_eval_complex(i, :))
92 file_form=
"FORMATTED", file_position=
"REWIND")
94 DO i = 1, number_of_pade_points
95 WRITE (ft_unit,
'(E20.8E3,E20.8E3,E20.8E3,E20.8E3,E20.8E3,E20.8E3,E20.8E3)') &
96 REAL(x_eval(i)),
REAL(moments_eval_complex(1, i)), aimag(moments_eval_complex(1, i)), &
97 REAL(moments_eval_complex(2, i)), aimag(moments_eval_complex(2, i)), &
98 REAL(moments_eval_complex(3, i)), aimag(moments_eval_complex(3, i))
102 DEALLOCATE (omega_complex)
103 DEALLOCATE (moments_ft_complex)
104 DEALLOCATE (moments_eval_complex)
106 IF (bse_unit > 0)
WRITE (bse_unit,
'(A10,A70)') &
107 " PADE_FT| ",
"GreenX library is not available. Refinement is skipped"
111 mark_used(number_of_simulation_steps)
112 mark_used(number_of_pade_points)
114 mark_used(ft_section)
115 mark_used(omega_series)
116 mark_used(ft_full_series)
133 INTEGER,
INTENT(IN) :: bse_unit
134 INTEGER,
DIMENSION(:, :),
POINTER :: pol_elements
135 COMPLEX(KIND=dp),
DIMENSION(:),
POINTER :: x_eval
136 COMPLEX(kind=dp),
DIMENSION(:, :),
INTENT(IN) :: polarizability_refined
138 INTEGER :: pol_unit, &
141 n_elems =
SIZE(pol_elements, 1)
144 file_form=
"FORMATTED", file_position=
"REWIND")
146 IF (pol_unit > 0)
THEN
147 IF (pol_unit == bse_unit)
THEN
149 WRITE (pol_unit,
'(A21)', advance=
"no")
" POLARIZABILITY_PADE|"
152 WRITE (pol_unit,
'(A1,A19)', advance=
"no")
"#",
"omega [a.u.]"
155 WRITE (pol_unit,
'(A20)', advance=
"no")
"Energy [eV]"
157 DO k = 1, n_elems - 1
158 WRITE (pol_unit,
'(A16,I2,I2,A16,I2,I2)', advance=
"no") &
159 "Real pol.", pol_elements(k, 1), pol_elements(k, 2), &
160 "Imag pol.", pol_elements(k, 1), pol_elements(k, 2)
162 WRITE (pol_unit,
'(A16,I2,I2,A16,I2,I2)') &
163 "Real pol.", pol_elements(n_elems, 1), pol_elements(n_elems, 2), &
164 "Imag pol.", pol_elements(n_elems, 1), pol_elements(n_elems, 2)
165 DO i = 1,
SIZE(x_eval)
166 IF (pol_unit == bse_unit)
THEN
168 WRITE (pol_unit,
'(A21)', advance=
"no")
" POLARIZABILITY_PADE|"
171 WRITE (pol_unit,
'(E20.8E3)', advance=
"no") real(x_eval(i), kind=
dp)
174 WRITE (pol_unit,
'(E20.8E3)', advance=
"no") real(x_eval(i), kind=
dp)*
evolt
175 DO k = 1, n_elems - 1
176 WRITE (pol_unit,
'(E20.8E3,E20.8E3)', advance=
"no") &
177 REAL(polarizability_refined(k, i)), aimag(polarizability_refined(k, i))
180 WRITE (pol_unit,
'(E20.8E3,E20.8E3)') &
181 REAL(polarizability_refined(n_elems, i)), aimag(polarizability_refined(n_elems, i))
187 mark_used(pol_section)
189 mark_used(pol_elements)
191 mark_used(polarizability_refined)
204 SUBROUTINE greenx_refine_ft(fit_e_min, fit_e_max, x_fit, y_fit, x_eval, y_eval, n_pade_opt)
205 REAL(kind=
dp) :: fit_e_min, &
207 COMPLEX(kind=dp),
DIMENSION(:) :: x_fit, &
211 INTEGER,
OPTIONAL :: n_pade_opt
212#if defined (__GREENX)
213 CHARACTER(len=*),
PARAMETER :: routinen =
'greenx_refine_ft'
215 INTEGER :: fit_start, &
225 TYPE(params) :: pade_params
227 CALL timeset(routinen, handle)
230 max_fit =
SIZE(x_fit)
231 n_eval =
SIZE(x_eval)
239 IF (fit_e_max < 0) fit_end = max_fit
241 IF (fit_start == -1 .AND. real(x_fit(i)) >= fit_e_min) fit_start = i
242 IF (fit_end == -1 .AND. real(x_fit(i)) > fit_e_max) fit_end = i - 1
243 IF (fit_start > 0 .AND. fit_end > 0)
EXIT
245 IF (fit_start == -1) fit_start = 1
246 IF (fit_end == -1) fit_end = max_fit
247 n_fit = fit_end - fit_start + 1
250 IF (
PRESENT(n_pade_opt)) n_pade = n_pade_opt
255 cpwarn(é
"FT deck too short for Pad; raise STEPS or disable &FT.")
256 y_eval(1:n_eval) = cmplx(0.0, 0.0, kind=
dp)
257 CALL timestop(handle)
262 IF (n_pade > 1000)
THEN
263 cpwarn(é
"More then 1000 Pad parameters requested - may reduce with FIT_E_MIN/FIT_E_MAX.")
270 IF (unit_nr > 0)
THEN
271 WRITE (unit=unit_nr, fmt=
"(T3,A,T45,I6,I8,2F11.4)") &
272 "GREENX FT_PADE| n_pade, n_fit, window [eV]", n_pade, n_fit, &
273 REAL(x_fit(fit_start), kind=
dp)*
evolt, real(x_fit(fit_end), kind=
dp)*
evolt
278 pade_params = create_thiele_pade(n_pade, x_fit(fit_start:fit_end), y_fit(fit_start:fit_end), &
279 enforce_symmetry=
"conjugate")
282 y_eval(1:n_eval) = evaluate_thiele_pade_at(pade_params, x_eval)
284 CALL free_params(pade_params)
285 CALL timestop(handle)
294 mark_used(n_pade_opt)
295 cpabort(
"Calls to GreenX require CP2K to be compiled with support for GreenX.")
316 tau_tj, tau_wj, regularization_minimax, &
317 tj, wj, weights_cos_tf_t_to_w, &
318 weights_cos_tf_w_to_t, weights_sin_tf_t_to_w, ierr)
320 INTEGER,
INTENT(IN) :: unit_nr, num_integ_points
321 REAL(kind=
dp),
INTENT(IN) :: emin, emax
322 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:), &
323 INTENT(OUT) :: tau_tj, tau_wj
324 REAL(kind=
dp),
INTENT(IN) :: regularization_minimax
325 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:), &
326 INTENT(INOUT) :: tj, wj
327 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :), &
328 INTENT(OUT) :: weights_cos_tf_t_to_w, &
329 weights_cos_tf_w_to_t, &
330 weights_sin_tf_t_to_w
331 INTEGER,
INTENT(OUT) :: ierr
332#if defined (__GREENX)
334 REAL(kind=
dp) :: cosft_duality_error_greenx, &
337 CALL gx_minimax_grid(num_integ_points, emin, emax, tau_tj, tau_wj, tj, wj, &
338 weights_cos_tf_t_to_w, weights_cos_tf_w_to_t, weights_sin_tf_t_to_w, &
339 max_errors_greenx, cosft_duality_error_greenx, ierr, &
340 bare_cos_sin_weights=.true., &
341 regularization=regularization_minimax)
345 IF (unit_nr > 0)
THEN
346 WRITE (unit=unit_nr, fmt=
"(T3,A,T75,i6)") &
347 "GREENX MINIMAX_INFO| Number of integration points:", num_integ_points
348 WRITE (unit=unit_nr, fmt=
"(T3,A,T61,3F20.7)") &
349 "GREENX MINIMAX_INFO| Gap (Emin):", emin
350 WRITE (unit=unit_nr, fmt=
"(T3,A,T61,3F20.7)") &
351 "GREENX MINIMAX_INFO| Maximum eigenvalue difference (Emax):", emax
352 WRITE (unit=unit_nr, fmt=
"(T3,A,T61,3F20.4)") &
353 "GREENX MINIMAX_INFO| Energy range (Emax/Emin):", emax/emin
354 WRITE (unit=unit_nr, fmt=
"(T3,A,T54,A,T72,A)") &
355 "GREENX MINIMAX_INFO| Frequency grid (scaled):",
"Weights",
"Abscissas"
356 DO gi = 1, num_integ_points
357 WRITE (unit=unit_nr, fmt=
"(T41,F20.10,F20.10)") wj(gi), tj(gi)
359 WRITE (unit=unit_nr, fmt=
"(T3,A,T54,A,T72,A)") &
360 "GREENX MINIMAX_INFO| Time grid (scaled):",
"Weights",
"Abscissas"
361 DO gi = 1, num_integ_points
362 WRITE (unit=unit_nr, fmt=
"(T41,F20.10,F20.10)") tau_wj(gi), tau_tj(gi)
367 IF (unit_nr > 0)
THEN
368 WRITE (unit=unit_nr, fmt=
"(T3,A,T75)") &
369 "GREENX MINIMAX_INFO| Grid not available, use internal CP2K grids"
372 IF (
ALLOCATED(tau_tj))
THEN
375 IF (
ALLOCATED(tau_wj))
THEN
378 IF (
ALLOCATED(tj))
THEN
381 IF (
ALLOCATED(wj))
THEN
384 IF (
ALLOCATED(weights_cos_tf_t_to_w))
THEN
385 DEALLOCATE (weights_cos_tf_t_to_w)
387 IF (
ALLOCATED(weights_cos_tf_w_to_t))
THEN
388 DEALLOCATE (weights_cos_tf_w_to_t)
390 IF (
ALLOCATED(weights_sin_tf_t_to_w))
THEN
391 DEALLOCATE (weights_sin_tf_t_to_w)
397 mark_used(num_integ_points)
402 mark_used(regularization_minimax)
405 mark_used(weights_cos_tf_t_to_w)
406 mark_used(weights_cos_tf_w_to_t)
407 mark_used(weights_sin_tf_t_to_w)
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, tau_tj, tau_wj, regularization_minimax, tj, wj, weights_cos_tf_t_to_w, weights_cos_tf_w_to_t, weights_sin_tf_t_to_w, ierr)
...
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...