172 use,
intrinsic :: iso_fortran_env
211 real(real64) :: x_limit(2)
212 type(c_ptr) :: spl, acc
213 real(real64),
public :: x_threshold
256 type(c_ptr),
intent(inout) :: spl, acc
261 use,
intrinsic :: iso_fortran_env
263 integer,
intent(in) :: nrc
264 real(real64),
intent(in) :: x
265 real(real64),
intent(in) :: y
266 type(c_ptr),
intent(inout) :: spl
267 type(c_ptr),
intent(inout) :: acc
273 type(c_ptr),
intent(out) :: acc
279 type(c_ptr),
intent(inout) :: acc
282 real(real64) function oct_spline_eval(x, spl, acc)
284 use,
intrinsic :: iso_fortran_env
286 real(real64),
intent(in) :: x
287 type(c_ptr),
intent(in) :: spl
288 type(c_ptr),
intent(in) :: acc
293 use,
intrinsic :: iso_fortran_env
295 integer,
intent(in) :: nn
296 real(real64),
intent(inout) :: xf
297 type(c_ptr),
intent(in) :: spl
298 type(c_ptr),
intent(in) :: acc
303 use,
intrinsic :: iso_fortran_env
305 integer,
intent(in) :: nn
306 complex(real64),
intent(inout) :: xf
307 type(c_ptr),
intent(in) :: spl
308 type(c_ptr),
intent(in) :: acc
311 real(real64) function oct_spline_eval_der(x, spl, acc)
313 use,
intrinsic :: iso_fortran_env
315 real(real64),
intent(in) :: x
316 type(c_ptr),
intent(in) :: spl
317 type(c_ptr),
intent(in) :: acc
320 real(real64) function oct_spline_eval_der2(x, spl, acc)
322 use,
intrinsic :: iso_fortran_env
324 real(real64),
intent(in) :: x
325 type(c_ptr),
intent(in) :: spl
326 type(c_ptr),
intent(in) :: acc
329 integer pure function oct_spline_npoints(spl, acc)
332 type(c_ptr),
intent(in) :: spl
333 type(c_ptr),
intent(in) :: acc
338 use,
intrinsic :: iso_fortran_env
340 type(c_ptr),
intent(in) :: spl
341 real(real64),
intent(out) :: x
346 use,
intrinsic :: iso_fortran_env
348 type(c_ptr),
intent(in) :: spl
349 real(real64),
intent(out) :: y
352 real(real64)
pure function oct_spline_eval_integ(spl, a, b, acc)
354 use,
intrinsic :: iso_fortran_env
356 type(c_ptr),
intent(in) :: spl
357 real(real64),
intent(in) :: a
358 real(real64),
intent(in) :: b
359 type(c_ptr),
intent(in) :: acc
364 use,
intrinsic :: iso_fortran_env
366 type(c_ptr),
intent(in) :: spl
367 type(c_ptr),
intent(in) :: acc
371 real(real64),
parameter :: tol_x = 1e-14_real64
385 spl%x_limit(1) = -1_real64
386 spl%x_limit(2) = -2_real64
388 spl%x_threshold = m_zero
395 type(
spline_t),
intent(out) :: spl(:)
411 type(
spline_t),
intent(out) :: spl(:, :)
417 do i = 1,
size(spl, 1)
418 do j = 1,
size(spl, 2)
429 type(
spline_t),
intent(inout) :: spl
433 if (c_associated(spl%spl) .and. c_associated(spl%acc))
then
444 type(
spline_t),
intent(inout) :: spl(:)
460 type(
spline_t),
intent(inout) :: spl(:, :)
466 do i = 1,
size(spl, 1)
467 do j = 1,
size(spl, 2)
477 subroutine spline_fit(nrc, rofi, ffit, spl, threshold)
478 integer,
intent(in) :: nrc
479 real(real64),
contiguous,
intent(in) :: rofi(:)
480 real(real64),
contiguous,
intent(in) :: ffit(:)
481 type(
spline_t),
intent(inout) :: spl
482 real(real64),
optional,
intent(in) :: threshold
488 spl%x_limit(1) = rofi(1)
489 spl%x_limit(2) = rofi(nrc)
492 if (
present(threshold))
then
493 if (threshold > m_zero)
then
496 spl%x_threshold = spl%x_limit(2)
499 spl%x_threshold = m_zero
505 real(real64) function spline_eval(spl, x)
507 real(real64),
intent(in) :: x
517 type(c_ptr),
intent(out) :: acc
524 type(c_ptr),
intent(inout) :: acc
532 real(real64) function spline_eval_accel(spl, x, acc)
534 real(real64),
intent(in) :: x
535 type(c_ptr),
intent(in) :: acc
543 type(
spline_t),
intent(in) :: spl1, spl2
552 integer,
intent(in) :: nn
553 real(real64),
contiguous,
intent(inout) :: xf(:)
564 integer,
intent(in) :: nn
565 complex(real64),
contiguous,
intent(inout) :: xf(:)
574 real(real64),
intent(in) :: a
575 type(
spline_t),
intent(inout) :: spl
576 real(real64),
intent(in) :: threshold
578 integer :: npoints, i
579 real(real64),
allocatable :: x(:), y(:)
586 safe_allocate(x(1:npoints))
587 safe_allocate(y(1:npoints))
596 call spline_fit(npoints, x, y, spl, threshold)
620 real(real64),
intent(in) :: a
621 real(real64),
intent(in) :: b
629 type(
spline_t),
intent(inout) :: splw
630 real(real64),
intent(in) :: threshold
631 real(real64),
optional,
intent(in) :: gmax
634 real(real64) :: g, dg
636 integer :: npoints, i, j
637 real(real64),
allocatable :: x(:), y(:), y2(:), xw(:), yw(:)
644 safe_allocate( x(1:npoints))
645 safe_allocate( y(1:npoints))
646 safe_allocate(y2(1:npoints))
652 if (c_associated(splw%spl))
then
654 safe_allocate(xw(1:np))
655 safe_allocate(yw(1:np))
660 assert(
present(gmax))
663 safe_allocate(xw(1:np))
664 safe_allocate(yw(1:np))
674 y2(j) = m_four*m_pi*y(j)*x(j)**2
684 y2(j) = (m_four*m_pi/xw(i))*y(j)*x(j)*
sin(xw(i)*x(j))
697 safe_deallocate_a(y2)
698 safe_deallocate_a(xw)
699 safe_deallocate_a(yw)
708 type(
spline_t),
intent(inout) :: splw
709 integer,
intent(in) :: l
710 real(real64),
optional,
intent(in) :: threshold
711 real(real64),
optional,
intent(in) :: gmax
716 integer :: npoints, i, j
717 real(real64),
allocatable :: x(:), y(:), y2(:), xw(:), yw(:)
724 safe_allocate( x(1:npoints))
725 safe_allocate( y(1:npoints))
726 safe_allocate(y2(1:npoints))
732 if (c_associated(splw%spl))
then
734 safe_allocate(xw(1:np))
735 safe_allocate(yw(1:np))
740 assert(
present(gmax))
743 safe_allocate(xw(1:np))
744 safe_allocate(yw(1:np))
754 y2(j) = y(j) * x(j)**2 * loct_sph_bessel(l, x(j)*xw(i))
768 safe_deallocate_a(y2)
769 safe_deallocate_a(xw)
770 safe_deallocate_a(yw)
777 subroutine spline_cut(spl, cutoff, beta, threshold)
779 real(real64),
intent(in) :: cutoff
780 real(real64),
intent(in) :: beta
781 real(real64),
optional,
intent(in) :: threshold
783 integer :: npoints, i
784 real(real64),
allocatable :: x(:), y(:)
785 real(real64) :: exp_arg
792 safe_allocate(x(1:npoints))
793 safe_allocate(y(1:npoints))
799 do i = npoints, 1, -1
800 if (x(i)<cutoff)
then
804 exp_arg = -beta*(x(i)/cutoff - m_one)**2
806 if (exp_arg > m_min_exp_arg)
then
807 y(i) = y(i) *
exp(exp_arg)
812 call spline_fit(npoints, x, y, spl, threshold)
827 type(
spline_t),
intent(inout) :: spla
829 real(real64),
optional,
intent(in) :: threshold
831 integer :: npoints, i, new_npoints
832 real(real64),
allocatable :: x(:), y(:)
840 safe_allocate(x(1:npoints))
841 safe_allocate(y(1:npoints))
847 assert(splb%x_limit(2) >= splb%x_limit(1))
852 do i = npoints, 1, -1
853 if (x(i) > splb%x_limit(2)-
tol_x) cycle
856 new_npoints = new_npoints + 1
858 assert(new_npoints > 0)
860 call spline_fit(new_npoints, x, y, spla, threshold)
872 type(
spline_t),
intent(inout) :: spl
873 real(real64),
intent(in) :: threshold
875 integer :: npoints, i
876 real(real64),
allocatable :: x(:), y(:)
883 safe_allocate(x(1:npoints))
884 safe_allocate(y(1:npoints))
891 do i = npoints, 1, -1
892 y(i) = max(y(i),m_zero)
895 call spline_fit(npoints, x, y, spl, threshold)
906 type(
spline_t),
intent(inout) :: spla
908 real(real64),
intent(in) :: threshold
910 integer :: npoints, i, new_npoints
911 real(real64),
allocatable :: x(:), y(:)
917 if(npoints <= 0)
then
922 safe_allocate(x(1:npoints))
923 safe_allocate(y(1:npoints))
929 assert(splb%x_limit(2) >= splb%x_limit(1))
934 do i = npoints, 1, -1
935 if (x(i) > splb%x_limit(2) -
tol_x) cycle
938 new_npoints = new_npoints + 1
941 call spline_fit(new_npoints, x, y, spla, threshold)
953 type(
spline_t),
intent(inout) :: dspl
954 real(real64),
intent(in) :: threshold
956 integer :: npoints, i
957 real(real64),
allocatable :: x(:), y(:)
962 if (.not. c_associated(dspl%spl))
then
965 safe_allocate(x(1:npoints))
966 safe_allocate(y(1:npoints))
971 safe_allocate(x(1:npoints))
972 safe_allocate(y(1:npoints))
978 call spline_fit(npoints, x, y, dspl, threshold)
991 type(
spline_t),
intent(inout) :: dspl
992 real(real64),
intent(in) :: threshold
993 real(real64),
contiguous,
optional,
intent(in) :: grid(:)
995 integer :: npoints, i
996 real(real64),
allocatable :: x(:), y(:)
1001 if (.not. c_associated(dspl%spl))
then
1004 safe_allocate(x(1:npoints))
1005 safe_allocate(y(1:npoints))
1006 if (
present(grid))
then
1014 safe_allocate(x(1:npoints))
1015 safe_allocate(y(1:npoints))
1021 call spline_fit(npoints, x, y, dspl, threshold)
1023 safe_deallocate_a(x)
1024 safe_deallocate_a(y)
1033 integer,
intent(in) :: iunit
1036 real(real64),
allocatable :: x(:), y(:)
1042 safe_allocate(x(1:np))
1043 safe_allocate(y(1:np))
1048 write(iunit,
'(2es18.8E3)') x(i), y(i)
1051 safe_deallocate_a(x)
1052 safe_deallocate_a(y)
1062 integer,
intent(in) :: iunit
1064 integer :: np, i, n, j
1065 real(real64),
allocatable :: x(:)
1066 real(real64) :: x_limit
1067 integer :: max_x_index
1077 x_limit = spl(1)%x_limit(2)
1082 if (x_limit < spl(i)%x_limit(2))
then
1083 x_limit = spl(i)%x_limit(2)
1089 safe_allocate(x(1:np))
1093 write(iunit,
'(es18.8E3)', advance=
'no') x(i)
1095 if (x(i) <= spl(j)%x_limit(2))
then
1096 write(iunit,
'(es18.8E3)', advance=
'no')
spline_eval(spl(j), x(i))
1098 write(iunit,
'(es18.8E3)', advance=
'no') m_zero
1101 write(iunit,
'(a)', advance=
'yes')
''
1104 safe_deallocate_a(x)
1113 type(
spline_t),
intent(in) :: spl(:, :)
1114 integer,
intent(in) :: iunit
1116 integer :: np, i, n1, n2, j, k
1117 real(real64),
allocatable :: x(:)
1118 real(real64) :: x_limit
1119 integer :: max_x_index(2)
1125 if (n1 * n2 <= 0)
then
1132 x_limit = spl(1,1)%x_limit(2)
1135 if (x_limit < spl(i,j)%x_limit(2))
then
1136 x_limit = spl(i,j)%x_limit(2)
1137 max_x_index = (/i,j/)
1142 np =
oct_spline_npoints(spl(max_x_index(1), max_x_index(2))%spl, spl(max_x_index(1), max_x_index(2))%acc)
1143 safe_allocate(x(1:np))
1145 call oct_spline_x(spl(max_x_index(1), max_x_index(2))%spl, x(1))
1148 write(iunit,
'(es18.8E3)', advance=
'no') x(i)
1151 if (x(i) <= spl(j,k)%x_limit(2))
then
1152 write(iunit,
'(es18.8E3)', advance=
'no')
spline_eval(spl(j, k), x(i))
1154 write(iunit,
'(es18.8E3)', advance=
'no') m_zero
1158 write(iunit,
'(a)', advance=
'yes')
''
1161 safe_deallocate_a(x)
1170 real(real64) function spline_x_threshold(spl, threshold) result(r)
1172 real(real64),
intent(in) :: threshold
1175 real(real64),
parameter :: dx = 0.01_real64
1178 assert(spl%x_limit(2) >= spl%x_limit(1))
1180 call profiling_in(
'SPLINE_CUTOFF_RADIUS')
1182 jj =
floor(spl%x_limit(2)/dx) + 1
1185 do while(dx*(jj-1) > spl%x_limit(2) - m_half * dx)
1194 call profiling_out(
'SPLINE_CUTOFF_RADIUS')
1200 real(real64)
pure function spline_range_min(this) result(range)
1203 range = this%x_limit(1)
1209 real(real64)
pure function spline_range_max(this) result(range)
1212 range = this%x_limit(2)
1219 real(real64),
allocatable,
intent(inout) :: x_shifted(:)
1221 real(real64),
allocatable :: x(:)
1222 integer :: npoints, i
1229 safe_allocate(x(1:npoints))
1230 safe_allocate(x_shifted(1:npoints))
1232 do i = 1, npoints -1
1233 x_shifted(i) = m_half*(x(i) + x(i+1))
1235 x_shifted(npoints) = x(npoints)
1236 safe_deallocate_a(x)
Both the filling of the function, and the retrieval of the values may be done using single- or double...
Some operations may be done for one spline-function, or for an array of them.
The integral may be done with or without integration limits, but we want the interface to be common.
double exp(double __x) __attribute__((__nothrow__
double sin(double __x) __attribute__((__nothrow__
double sqrt(double __x) __attribute__((__nothrow__
double floor(double __x) __attribute__((__nothrow__
/* To use the profiling module, call profiling_in and profiling_out with the label of the region as a...
subroutine, public spline_der(spl, dspl, threshold)
subroutine, public spline_accel_init(acc)
Allocate a GSL accelerator owned by the caller. Used with spline_eval_accel (one accelerator per thre...
subroutine spline_end_0(spl)
subroutine, public spline_force_pos(spl, threshold)
real(real64) pure function spline_integral_limits(spl, a, b)
subroutine, public spline_fit(nrc, rofi, ffit, spl, threshold)
real(real64) function, public spline_x_threshold(spl, threshold)
Determines the largest value of x for which the spline values are above the threshold.
subroutine, public spline_3dft(spl, splw, threshold, gmax)
subroutine, public spline_der2(spl, dspl, threshold, grid)
Returns a spline that contains the second derivative of the original spline.
subroutine spline_end_2(spl)
real(real64), parameter tol_x
Tolerance for checking if x is inside or outside the limits of the splines.
subroutine, public spline_besselft(spl, splw, l, threshold, gmax)
logical function, public spline_same(spl1, spl2)
True if both splines refer to the same underlying GSL spline.
real(real64) pure function, public spline_range_min(this)
subroutine spline_end_1(spl)
subroutine spline_print_1(spl, iunit)
Print debug information for a 1D array of splines.
real(real64) function spline_integral_full(spl)
real(real64) function, public spline_eval(spl, x)
subroutine spline_init_0(spl)
subroutine spline_print_0(spl, iunit)
subroutine spline_print_2(spl, iunit)
Print debug information for a 2D array of splines.
subroutine spline_eval8_array(spl, nn, xf)
subroutine spline_init_1(spl)
subroutine, public spline_cut(spl, cutoff, beta, threshold)
subroutine, public spline_div(spla, splb, threshold)
Returns the values of spla divided by the values of splb.
real(real64) pure function, public spline_range_max(this)
real(real64) function, public spline_eval_accel(spl, x, acc)
Same as spline_eval, with a caller-owned accelerator (see spline_accel_init).
subroutine, public spline_times(a, spl, threshold)
subroutine spline_init_2(spl)
subroutine, public spline_accel_end(acc)
subroutine, public spline_mult(spla, splb, threshold)
subroutine spline_evalz_array(spl, nn, xf)
subroutine, public spline_generate_shifted_grid(this, x_shifted)
the basic spline datatype