24 use,
intrinsic :: iso_fortran_env
42 integer,
parameter,
public :: &
43 LOGRID_PSF = 1, & !< log grid used in Troullier-Martins code
53 real(real64),
allocatable :: rofi(:)
54 real(real64),
allocatable :: r2ofi(:)
55 real(real64),
allocatable :: drdi(:)
56 real(real64),
allocatable :: s(:)
63 type(logrid_t),
intent(out) :: grid
64 integer,
intent(in) :: flavor
65 real(real64),
intent(in) :: aa, bb
66 integer,
intent(in) :: nrval
68 real(real64) :: rpb, ea
73 assert(flavor == logrid_psf .or. flavor ==
logrid_cpi)
80 safe_allocate(grid%rofi(1:nrval))
81 safe_allocate(grid%r2ofi(1:nrval))
82 safe_allocate(grid%drdi(1:nrval))
83 safe_allocate(grid%s(1:nrval))
85 select case (grid%flavor)
90 grid%drdi(ir) = aa*rpb
92 grid%rofi(ir) = bb*(
exp(aa*(ir-1)) -
m_one)
101 grid%drdi(2) = bb*rpb
102 do ir = 3, grid%nrval
103 grid%rofi(ir) = grid%rofi(ir-1)*aa
104 grid%drdi(ir) = grid%rofi(ir)*rpb
109 do ir = 1, grid%nrval
110 grid%s(ir) =
sqrt(grid%drdi(ir))
111 grid%r2ofi(ir) = grid%rofi(ir)**2
120 type(logrid_t),
intent(inout) :: grid
124 safe_deallocate_a(grid%rofi)
125 safe_deallocate_a(grid%r2ofi)
126 safe_deallocate_a(grid%drdi)
127 safe_deallocate_a(grid%s)
136 type(
logrid_t),
intent(inout) :: grid_out
142 grid_out%flavor = grid_in%flavor
143 grid_out%a = grid_in%a
144 grid_out%b = grid_in%b
145 grid_out%nrval = grid_in%nrval
147 safe_allocate(grid_out%rofi (1:grid_out%nrval))
148 safe_allocate(grid_out%r2ofi(1:grid_out%nrval))
149 safe_allocate(grid_out%drdi (1:grid_out%nrval))
150 safe_allocate(grid_out%s (1:grid_out%nrval))
152 grid_out%rofi(:) = grid_in%rofi(:)
153 grid_out%r2ofi(:) = grid_in%r2ofi(:)
154 grid_out%drdi(:) = grid_in%drdi(:)
155 grid_out%s(:) = grid_in%s(:)
164 real(real64),
intent(in) :: rofi
171 do ir = 1, grid%nrval-1
173 if (rofi >= grid%rofi(ir).and.rofi < grid%rofi(ir+1))
then
174 if (abs(rofi-grid%rofi(ir)) < abs(rofi-grid%rofi(ir+1)))
then
191 real(real64),
intent(in) :: ff(:)
192 real(real64),
intent(out) :: dfdr(:)
198 dfdr(1) = (ff(2) - ff(1))/(grid%rofi(2) - grid%rofi(1))
199 do ii = 2, grid%nrval-1
200 dfdr(ii) = (ff(ii+1) - ff(ii-1))/(grid%rofi(ii+1) - grid%rofi(ii-1))
202 dfdr(grid%nrval) = (ff(grid%nrval) - ff(grid%nrval-1))/(grid%rofi(grid%nrval) - grid%rofi(grid%nrval-1))
208 real(real64)
pure function
logrid_radius(grid) result(radius)
211 radius = grid%rofi(grid%nrval)
216 type(namespace_t),
intent(in) :: namespace
217 integer,
intent(in) :: zz
218 real(real64),
intent(out) :: aa, bb
219 integer,
intent(out) :: np
221 real(real64) :: xmin, xmax, a1, a2, f1, fm
230 xmin =
sqrt(real(zz, real64) )*1e-5_real64
231 xmax =
sqrt(real(zz, real64) )*30.0_real64
232 np =
floor(
sqrt(real(zz, real64) )*200_real64)
234 np =
floor(np/m_two)*2+1
237 f1 =
func(xmin, xmax, real(np, real64) , a1)
240 aa = (a2 + a1)*m_half
241 fm =
func(xmin, xmax, real(np, real64) , aa)
242 if (m_half*abs(a1 - a2) < 1.0e-16_real64)
exit
243 if (fm*f1 > m_zero)
then
251 bb = xmin/(
exp(aa)-m_one)
253 write(message(1),
'(a,es13.6,a,es13.6,a,i4)')
'Debug: Log grid parameters: a = ', aa, &
254 ' b = ', bb,
' np = ', np
255 call messages_info(1, namespace=namespace, debug_only=.
true.)
259 real(real64) function
func(r1, rn, n, a)
260 real(real64),
intent(in) :: r1, rn, a, n
261 if((n-m_one)*a < m_max_exp_arg)
then
262 func =
exp((n-m_one)*a)*r1 - m_one*r1 - rn*
exp(a) + rn*m_one
264 func = m_huge*r1 - m_one*r1 - rn*
exp(a) + rn*m_one
double log(double __x) __attribute__((__nothrow__
double exp(double __x) __attribute__((__nothrow__
double sqrt(double __x) __attribute__((__nothrow__
double floor(double __x) __attribute__((__nothrow__
real(real64) function func(r1, rn, n, a)
real(real64), parameter, public m_zero
real(real64), parameter, public m_one
subroutine, public logrid_find_parameters(namespace, zz, aa, bb, np)
real(real64) pure function, public logrid_radius(grid)
subroutine, public logrid_copy(grid_in, grid_out)
integer, parameter, public logrid_cpi
log grid used in FHI code
integer function, public logrid_index(grid, rofi)
subroutine, public logrid_end(grid)
subroutine, public derivative_in_log_grid(grid, ff, dfdr)
subroutine, public logrid_init(grid, flavor, aa, bb, nrval)