41#include "./base/base_uses.f90"
46 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'negf_integr_cc'
47 LOGICAL,
PARAMETER,
PRIVATE :: debug_this_module = .true.
74 INTEGER :: interval_id = -1
76 INTEGER :: shape_id = -1
78 REAL(kind=
dp) :: error = -1.0_dp
88 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: tnodes
113 SUBROUTINE ccquad_init(cc_env, xnodes, nnodes, a, b, interval_id, shape_id, weights, tnodes_restart)
115 INTEGER,
INTENT(inout) :: nnodes
116 COMPLEX(kind=dp),
DIMENSION(nnodes),
INTENT(out) :: xnodes
117 COMPLEX(kind=dp),
INTENT(in) :: a, b
118 INTEGER,
INTENT(in) :: interval_id, shape_id
120 REAL(kind=
dp),
DIMENSION(nnodes),
INTENT(in), &
121 OPTIONAL :: tnodes_restart
123 CHARACTER(len=*),
PARAMETER :: routinen =
'ccquad_init'
125 INTEGER :: handle, icol, ipoint, irow, ncols, &
127 REAL(kind=
dp),
CONTIGUOUS,
DIMENSION(:, :), &
128 POINTER :: w_data, w_data_my
131 CALL timeset(routinen, handle)
136 nnodes = 2*((nnodes - 1)/2) + 1
138 cc_env%interval_id = interval_id
139 cc_env%shape_id = shape_id
142 cc_env%error = huge(0.0_dp)
144 NULLIFY (cc_env%integral, cc_env%error_fm, cc_env%weights)
145 ALLOCATE (cc_env%weights)
146 CALL cp_fm_get_info(weights, local_data=w_data, nrow_local=nrows, ncol_local=ncols, matrix_struct=fm_struct)
153 w_data_my(irow, icol) = abs(w_data(irow, icol))
157 SELECT CASE (interval_id)
159 nnodes_half = nnodes/2 + 1
163 cpabort(
"Unimplemented interval type")
166 ALLOCATE (cc_env%tnodes(nnodes))
168 IF (
PRESENT(tnodes_restart))
THEN
169 cc_env%tnodes(1:nnodes) = tnodes_restart(1:nnodes)
176 IF (nnodes_half > 2) &
179 SELECT CASE (interval_id)
182 DO ipoint = nnodes_half - 1, 1, -1
183 cc_env%tnodes(nnodes_half + ipoint) = -cc_env%tnodes(nnodes_half - ipoint)
187 cc_env%tnodes(1:nnodes_half) = 2.0_dp*cc_env%tnodes(1:nnodes_half) + 1.0_dp
193 CALL timestop(handle)
205 CHARACTER(len=*),
PARAMETER :: routinen =
'ccquad_release'
207 INTEGER :: handle, ipoint
209 CALL timeset(routinen, handle)
211 IF (
ASSOCIATED(cc_env%error_fm))
THEN
213 DEALLOCATE (cc_env%error_fm)
214 NULLIFY (cc_env%error_fm)
217 IF (
ASSOCIATED(cc_env%weights))
THEN
219 DEALLOCATE (cc_env%weights)
220 NULLIFY (cc_env%weights)
223 IF (
ASSOCIATED(cc_env%integral))
THEN
225 DEALLOCATE (cc_env%integral)
226 NULLIFY (cc_env%integral)
229 IF (
ALLOCATED(cc_env%zdata_cache))
THEN
230 DO ipoint =
SIZE(cc_env%zdata_cache), 1, -1
234 DEALLOCATE (cc_env%zdata_cache)
237 IF (
ALLOCATED(cc_env%tnodes))
DEALLOCATE (cc_env%tnodes)
239 CALL timestop(handle)
252 COMPLEX(kind=dp),
ALLOCATABLE,
DIMENSION(:), &
253 INTENT(inout) :: xnodes_next
255 CHARACTER(len=*),
PARAMETER :: routinen =
'ccquad_double_number_of_points'
257 INTEGER :: handle, ipoint, nnodes_exist, &
258 nnodes_half, nnodes_next
259 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: tnodes, tnodes_old
261 CALL timeset(routinen, handle)
263 cpassert(.NOT.
ALLOCATED(xnodes_next))
264 cpassert(
ASSOCIATED(cc_env%integral))
265 cpassert(
ASSOCIATED(cc_env%error_fm))
266 cpassert(
ALLOCATED(cc_env%zdata_cache))
269 nnodes_exist =
SIZE(cc_env%zdata_cache)
272 nnodes_half = nnodes_exist - 1
274 SELECT CASE (cc_env%interval_id)
277 nnodes_next = 2*nnodes_half
279 nnodes_next = nnodes_half
281 cpabort(
"Unimplemented interval type")
284 ALLOCATE (xnodes_next(nnodes_next))
285 ALLOCATE (tnodes(nnodes_next))
288 -0.5_dp/real(nnodes_half, kind=
dp), &
293 SELECT CASE (cc_env%interval_id)
296 DO ipoint = 1, nnodes_half
297 tnodes(nnodes_half + ipoint) = -tnodes(nnodes_half - ipoint + 1)
301 tnodes(1:nnodes_half) = 2.0_dp*tnodes(1:nnodes_half) + 1.0_dp
305 CALL move_alloc(cc_env%tnodes, tnodes_old)
306 nnodes_exist =
SIZE(tnodes_old)
308 ALLOCATE (cc_env%tnodes(nnodes_exist + nnodes_next))
309 cc_env%tnodes(1:nnodes_exist) = tnodes_old(1:nnodes_exist)
310 cc_env%tnodes(nnodes_exist + 1:nnodes_exist + nnodes_next) = tnodes(1:nnodes_next)
311 DEALLOCATE (tnodes_old)
317 CALL timestop(handle)
335 TYPE(
cp_cfm_type),
DIMENSION(:),
INTENT(inout) :: zdata_next
337 CHARACTER(len=*),
PARAMETER :: routinen =
'ccquad_reduce_and_append_zdata'
340 COMPLEX(kind=dp),
ALLOCATABLE,
DIMENSION(:) :: zscale
341 INTEGER :: handle, ipoint, nnodes_exist, &
342 nnodes_half, nnodes_next
343 TYPE(
cp_cfm_type),
ALLOCATABLE,
DIMENSION(:) :: zdata_tmp
345 CALL timeset(routinen, handle)
347 nnodes_next =
SIZE(zdata_next)
348 cpassert(nnodes_next > 0)
351 nnodes_exist =
SIZE(cc_env%tnodes)
352 cpassert(nnodes_exist >= nnodes_next)
354 ALLOCATE (zscale(nnodes_next))
356 cc_env%a, cc_env%b, cc_env%shape_id, weights=zscale)
361 DO ipoint = 1, nnodes_next
367 IF (
ALLOCATED(cc_env%zdata_cache))
THEN
368 nnodes_exist =
SIZE(cc_env%zdata_cache)
373 SELECT CASE (cc_env%interval_id)
375 IF (
ALLOCATED(cc_env%zdata_cache))
THEN
376 cpassert(nnodes_exist == nnodes_next/2 + 1)
377 nnodes_half = nnodes_exist - 1
379 cpassert(mod(nnodes_next, 2) == 1)
380 nnodes_half = nnodes_next/2 + 1
383 IF (
ALLOCATED(cc_env%zdata_cache))
THEN
384 cpassert(nnodes_exist == nnodes_next + 1)
387 nnodes_half = nnodes_next
391 DO ipoint = nnodes_next/2, 1, -1
396 IF (
ALLOCATED(cc_env%zdata_cache))
THEN
398 ALLOCATE (zdata_tmp(nnodes_half + nnodes_exist))
400 DO ipoint = 1, nnodes_half
401 zdata_tmp(2*ipoint - 1) = cc_env%zdata_cache(ipoint)
402 zdata_tmp(2*ipoint) = zdata_next(ipoint)
403 zdata_next(ipoint) = cfm_null
405 zdata_tmp(nnodes_half + nnodes_exist) = cc_env%zdata_cache(nnodes_exist)
407 CALL move_alloc(zdata_tmp, cc_env%zdata_cache)
411 ALLOCATE (cc_env%zdata_cache(nnodes_half))
413 DO ipoint = 1, nnodes_half
414 cc_env%zdata_cache(ipoint) = zdata_next(ipoint)
415 zdata_next(ipoint) = cfm_null
419 CALL timestop(handle)
431 CHARACTER(len=*),
PARAMETER :: routinen =
'ccquad_refine_integral'
433 COMPLEX(kind=dp),
CONTIGUOUS,
DIMENSION(:, :, :), &
434 POINTER :: ztmp, ztmp_dct
435 INTEGER :: handle, icol, ipoint, irow, ncols_local, nintervals, nintervals_half, &
436 nintervals_half_plus_1, nintervals_half_plus_2, nintervals_plus_2, nrows_local, stat
438 REAL(kind=
dp) :: rscale
439 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: weights
445 CALL timeset(routinen, handle)
447 cpassert(
ALLOCATED(cc_env%zdata_cache))
449 nintervals_half_plus_1 =
SIZE(cc_env%zdata_cache)
450 nintervals_half = nintervals_half_plus_1 - 1
451 nintervals_half_plus_2 = nintervals_half_plus_1 + 1
452 nintervals = 2*nintervals_half
453 nintervals_plus_2 = nintervals + 2
454 cpassert(nintervals_half > 1)
456 IF (.NOT.
ASSOCIATED(cc_env%integral))
THEN
461 ALLOCATE (cc_env%integral)
463 NULLIFY (cc_env%error_fm)
464 ALLOCATE (cc_env%error_fm)
468 IF (debug_this_module)
THEN
469 DO ipoint = 1, nintervals_half_plus_1
475 CALL cp_cfm_get_info(cc_env%integral, nrow_local=nrows_local, ncol_local=ncols_local)
477 ALLOCATE (weights(nintervals_half))
480 DO ipoint = 2, nintervals_half
481 rscale = real(2*(ipoint - 1), kind=
dp)
482 weights(ipoint) = 1.0_dp/(1.0_dp - rscale*rscale)
485 rscale = real(nintervals, kind=
dp)
486 weights(1) = 1.0_dp/(1.0_dp - rscale*rscale)
489 rscale = 1.0_dp/rscale
491 CALL fft_alloc(ztmp, [nintervals, nrows_local, ncols_local])
492 CALL fft_alloc(ztmp_dct, [nintervals, nrows_local, ncols_local])
496 DO icol = 1, ncols_local
497 DO irow = 1, nrows_local
498 DO ipoint = 1, nintervals_half_plus_1
499 ztmp(ipoint, irow, icol) = cc_env%zdata_cache(ipoint)%local_data(irow, icol)
502 DO ipoint = 2, nintervals_half
503 ztmp(nintervals_half + ipoint, irow, icol) = ztmp(nintervals_half_plus_2 - ipoint, irow, icol)
509 CALL fft_fw1d(nintervals, nrows_local*ncols_local, .false., ztmp, ztmp_dct, 1.0_dp, stat)
511 CALL cp_abort(__location__, &
512 "An FFT library is required for Clenshaw-Curtis quadrature. "// &
513 "You can use an alternative integration method instead.")
519 DO icol = 1, ncols_local
520 DO irow = 1, nrows_local
521 ztmp_dct(1, irow, icol) = 0.5_dp*ztmp_dct(1, irow, icol)
522 DO ipoint = 2, nintervals_half
523 ztmp_dct(ipoint, irow, icol) = 0.5_dp*weights(ipoint)*(ztmp_dct(ipoint, irow, icol) + &
524 ztmp_dct(nintervals_plus_2 - ipoint, irow, icol))
526 ztmp_dct(nintervals_half_plus_1, irow, icol) = weights(1)*ztmp_dct(nintervals_half_plus_1, irow, icol)
528 cc_env%integral%local_data(irow, icol) = rscale*
accurate_sum(ztmp_dct(1:nintervals_half_plus_1, irow, icol))
529 cc_env%error_fm%local_data(irow, icol) = rscale*abs(ztmp_dct(nintervals_half_plus_1, irow, icol))
534 CALL fft_dealloc(ztmp)
535 CALL fft_dealloc(ztmp_dct)
537 CALL cp_fm_trace(cc_env%error_fm, cc_env%weights, cc_env%error)
540 CALL timestop(handle)
Basic linear algebra operations for complex full matrices.
subroutine, public cp_cfm_scale_and_add(alpha, matrix_a, beta, matrix_b)
Scale and add two BLACS matrices (a = alpha*a + beta*b).
Represents a complex full matrix distributed on many processors.
subroutine, public cp_cfm_create(matrix, matrix_struct, name)
Creates a new full matrix with the given structure.
subroutine, public cp_cfm_release(matrix)
Releases a full matrix.
subroutine, public cp_cfm_get_info(matrix, name, nrow_global, ncol_global, nrow_block, ncol_block, nrow_local, ncol_local, row_indices, col_indices, local_data, context, matrix_struct, para_env)
Returns information about a full matrix.
basic linear algebra operations for full matrices
represent the structure of a full matrix
logical function, public cp_fm_struct_equivalent(fmstruct1, fmstruct2)
returns true if the two matrix structures are equivalent, false otherwise.
represent a full matrix distributed on many processors
subroutine, public cp_fm_get_info(matrix, name, nrow_global, ncol_global, nrow_block, ncol_block, nrow_local, ncol_local, row_indices, col_indices, local_data, context, nrow_locals, ncol_locals, matrix_struct, para_env)
returns all kind of information about the full matrix
subroutine, public cp_fm_create(matrix, matrix_struct, name, use_sp)
creates a new full matrix with the given structure
sums arrays of real/complex numbers with much reduced round-off as compared to a naive implementation...
Defines the basic variable types.
integer, parameter, public int_8
integer, parameter, public dp
Definition of mathematical constants and functions.
complex(kind=dp), parameter, public z_one
complex(kind=dp), parameter, public z_zero
Adaptive Clenshaw-Curtis quadrature algorithm to integrate a complex-valued function in a complex pla...
integer, parameter, public cc_shape_linear
subroutine, public ccquad_refine_integral(cc_env)
Refine approximated integral.
integer, parameter, public cc_interval_full
subroutine, public ccquad_double_number_of_points(cc_env, xnodes_next)
Get the next set of points at which the integrand needs to be computed. These points are then can be ...
subroutine, public ccquad_release(cc_env)
Release a Clenshaw-Curtis quadrature environment variable.
integer, parameter, public cc_interval_half
subroutine, public ccquad_init(cc_env, xnodes, nnodes, a, b, interval_id, shape_id, weights, tnodes_restart)
Initialise a Clenshaw-Curtis quadrature environment variable.
integer, parameter, public cc_shape_arc
subroutine, public ccquad_reduce_and_append_zdata(cc_env, zdata_next)
Prepare Clenshaw-Curtis environment for the subsequent refinement of the integral.
Helper functions for integration routines.
subroutine, public rescale_normalised_nodes(nnodes, tnodes, a, b, shape_id, xnodes, weights)
subroutine, public rescale_nodes_cos(nnodes, tnodes)
Rescale nodes tnodes(i) = cos(pi/2 * (1-tnodes(i))); tnodes \in [-1 .. 1] .
integer, parameter, public contour_shape_arc
integer, parameter, public contour_shape_linear
Represent a complex full matrix.
keeps the information about the structure of a full matrix
Adaptive Clenshaw-Curtis environment.