206 use,
intrinsic :: iso_fortran_env
243 real(real64) :: x_limit(2)
244 type(c_ptr) :: spl, acc
245 real(real64),
public :: x_threshold
288 type(c_ptr),
intent(inout) :: spl, acc
293 use,
intrinsic :: iso_fortran_env
295 integer,
intent(in) :: nrc
296 real(real64),
intent(in) :: x
297 real(real64),
intent(in) :: y
298 type(c_ptr),
intent(inout) :: spl
299 type(c_ptr),
intent(inout) :: acc
304 use,
intrinsic :: iso_fortran_env
306 real(real64),
intent(in) :: x
307 type(c_ptr),
intent(in) :: spl
308 type(c_ptr),
intent(in) :: acc
313 use,
intrinsic :: iso_fortran_env
315 integer,
intent(in) :: nn
316 real(real64),
intent(inout) :: xf
317 type(c_ptr),
intent(in) :: spl
318 type(c_ptr),
intent(in) :: acc
323 use,
intrinsic :: iso_fortran_env
325 integer,
intent(in) :: nn
326 complex(real64),
intent(inout) :: xf
327 type(c_ptr),
intent(in) :: spl
328 type(c_ptr),
intent(in) :: acc
331 real(real64) function oct_spline_eval_der(x, spl, acc)
333 use,
intrinsic :: iso_fortran_env
335 real(real64),
intent(in) :: x
336 type(c_ptr),
intent(in) :: spl
337 type(c_ptr),
intent(in) :: acc
340 real(real64) function oct_spline_eval_der2(x, spl, acc)
342 use,
intrinsic :: iso_fortran_env
344 real(real64),
intent(in) :: x
345 type(c_ptr),
intent(in) :: spl
346 type(c_ptr),
intent(in) :: acc
349 integer pure function oct_spline_npoints(spl, acc)
352 type(c_ptr),
intent(in) :: spl
353 type(c_ptr),
intent(in) :: acc
358 use,
intrinsic :: iso_fortran_env
360 type(c_ptr),
intent(in) :: spl
361 real(real64),
intent(out) :: x
366 use,
intrinsic :: iso_fortran_env
368 type(c_ptr),
intent(in) :: spl
369 real(real64),
intent(out) :: y
372 real(real64)
pure function oct_spline_eval_integ(spl, a, b, acc)
374 use,
intrinsic :: iso_fortran_env
376 type(c_ptr),
intent(in) :: spl
377 real(real64),
intent(in) :: a
378 real(real64),
intent(in) :: b
379 type(c_ptr),
intent(in) :: acc
382 real(real64)
pure function oct_spline_eval_integ_full(spl, acc)
384 use,
intrinsic :: iso_fortran_env
386 type(c_ptr),
intent(in) :: spl
387 type(c_ptr),
intent(in) :: acc
391 real(real64),
parameter :: tol_x = 1e-14_real64
405 spl%x_limit(1) = -1_real64
406 spl%x_limit(2) = -2_real64
408 spl%x_threshold = m_zero
415 type(
spline_t),
intent(out) :: spl(:)
431 type(
spline_t),
intent(out) :: spl(:, :)
437 do i = 1,
size(spl, 1)
438 do j = 1,
size(spl, 2)
453 if (c_associated(spl%spl) .and. c_associated(spl%acc))
then
464 type(
spline_t),
intent(inout) :: spl(:)
480 type(
spline_t),
intent(inout) :: spl(:, :)
486 do i = 1,
size(spl, 1)
487 do j = 1,
size(spl, 2)
497 subroutine spline_fit(nrc, rofi, ffit, spl, threshold)
498 integer,
intent(in) :: nrc
499 real(real64),
intent(in) :: rofi(:)
500 real(real64),
intent(in) :: ffit(:)
501 type(
spline_t),
intent(inout) :: spl
502 real(real64),
optional,
intent(in) :: threshold
508 spl%x_limit(1) = rofi(1)
509 spl%x_limit(2) = rofi(nrc)
512 if (
present(threshold))
then
513 if (threshold > m_zero)
then
516 spl%x_threshold = spl%x_limit(2)
519 spl%x_threshold = m_zero
527 real(real64),
intent(in) :: x
536 integer,
intent(in) :: nn
537 real(real64),
intent(inout) :: xf(:)
548 integer,
intent(in) :: nn
549 complex(real64),
intent(inout) :: xf(:)
557 subroutine spline_sum(spl1, spl2, splsum, threshold)
560 type(
spline_t),
intent(out) :: splsum
561 real(real64),
intent(in) :: threshold
563 integer :: npoints, i
564 real(real64),
allocatable :: x(:), y(:), y2(:)
571 safe_allocate( x(1:npoints))
572 safe_allocate( y(1:npoints))
573 safe_allocate(y2(1:npoints))
583 call spline_fit(npoints, x, y2, splsum, threshold)
587 safe_deallocate_a(y2)
595 real(real64),
intent(in) :: a
596 type(
spline_t),
intent(inout) :: spl
597 real(real64),
intent(in) :: threshold
599 integer :: npoints, i
600 real(real64),
allocatable :: x(:), y(:)
607 safe_allocate(x(1:npoints))
608 safe_allocate(y(1:npoints))
617 call spline_fit(npoints, x, y, spl, threshold)
641 real(real64),
intent(in) :: a
642 real(real64),
intent(in) :: b
649 real(real64) function
spline_dotp(spl1, spl2) result (res)
654 integer :: npoints, i
655 real(real64),
allocatable :: x(:), y(:)
662 safe_allocate(x(1:npoints))
663 safe_allocate(y(1:npoints))
685 type(
spline_t),
intent(inout) :: splw
686 real(real64),
intent(in) :: threshold
687 real(real64),
optional,
intent(in) :: gmax
690 real(real64) :: g, dg
692 integer :: npoints, i, j
693 real(real64),
allocatable :: x(:), y(:), y2(:), xw(:), yw(:)
700 safe_allocate( x(1:npoints))
701 safe_allocate( y(1:npoints))
702 safe_allocate(y2(1:npoints))
708 if (c_associated(splw%spl))
then
710 safe_allocate(xw(1:np))
711 safe_allocate(yw(1:np))
716 assert(
present(gmax))
719 safe_allocate(xw(1:np))
720 safe_allocate(yw(1:np))
730 y2(j) = m_four*m_pi*y(j)*x(j)**2
740 y2(j) = (m_four*m_pi/xw(i))*y(j)*x(j)*
sin(xw(i)*x(j))
753 safe_deallocate_a(y2)
754 safe_deallocate_a(xw)
755 safe_deallocate_a(yw)
764 type(
spline_t),
intent(inout) :: splw
765 integer,
intent(in) :: l
766 real(real64),
optional,
intent(in) :: threshold
767 real(real64),
optional,
intent(in) :: gmax
772 integer :: npoints, i, j
773 real(real64),
allocatable :: x(:), y(:), y2(:), xw(:), yw(:)
780 safe_allocate( x(1:npoints))
781 safe_allocate( y(1:npoints))
782 safe_allocate(y2(1:npoints))
788 if (c_associated(splw%spl))
then
790 safe_allocate(xw(1:np))
791 safe_allocate(yw(1:np))
796 assert(
present(gmax))
799 safe_allocate(xw(1:np))
800 safe_allocate(yw(1:np))
810 y2(j) = y(j) * x(j)**2 * loct_sph_bessel(l, x(j)*xw(i))
824 safe_deallocate_a(y2)
825 safe_deallocate_a(xw)
826 safe_deallocate_a(yw)
833 subroutine spline_cut(spl, cutoff, beta, threshold)
834 type(
spline_t),
intent(inout) :: spl
835 real(real64),
intent(in) :: cutoff
836 real(real64),
intent(in) :: beta
837 real(real64),
optional,
intent(in) :: threshold
839 integer :: npoints, i
840 real(real64),
allocatable :: x(:), y(:)
841 real(real64) :: exp_arg
848 safe_allocate(x(1:npoints))
849 safe_allocate(y(1:npoints))
855 do i = npoints, 1, -1
856 if (x(i)<cutoff)
then
860 exp_arg = -beta*(x(i)/cutoff - m_one)**2
862 if (exp_arg > m_min_exp_arg)
then
863 y(i) = y(i) *
exp(exp_arg)
868 call spline_fit(npoints, x, y, spl, threshold)
883 type(
spline_t),
intent(inout) :: spla
885 real(real64),
optional,
intent(in) :: threshold
887 integer :: npoints, i, new_npoints
888 real(real64),
allocatable :: x(:), y(:)
896 safe_allocate(x(1:npoints))
897 safe_allocate(y(1:npoints))
903 assert(splb%x_limit(2) >= splb%x_limit(1))
908 do i = npoints, 1, -1
909 if (x(i) > splb%x_limit(2)-
tol_x) cycle
912 new_npoints = new_npoints + 1
914 assert(new_npoints > 0)
916 call spline_fit(new_npoints, x, y, spla, threshold)
928 type(
spline_t),
intent(inout) :: spl
929 real(real64),
intent(in) :: threshold
931 integer :: npoints, i
932 real(real64),
allocatable :: x(:), y(:)
939 safe_allocate(x(1:npoints))
940 safe_allocate(y(1:npoints))
947 do i = npoints, 1, -1
948 y(i) = max(y(i),m_zero)
951 call spline_fit(npoints, x, y, spl, threshold)
962 type(
spline_t),
intent(inout) :: spla
964 real(real64),
intent(in) :: threshold
966 integer :: npoints, i
967 real(real64),
allocatable :: x(:), y(:)
973 if(npoints <= 0)
then
978 safe_allocate(x(1:npoints))
979 safe_allocate(y(1:npoints))
985 assert(splb%x_limit(2) >= splb%x_limit(1))
988 do i = npoints, 1, -1
989 if (x(i) > splb%x_limit(2) -
tol_x)
then
997 call spline_fit(npoints, x, y, spla, threshold)
1000 safe_deallocate_a(y)
1009 type(
spline_t),
intent(inout) :: dspl
1010 real(real64),
intent(in) :: threshold
1012 integer :: npoints, i
1013 real(real64),
allocatable :: x(:), y(:)
1018 if (.not. c_associated(dspl%spl))
then
1021 safe_allocate(x(1:npoints))
1022 safe_allocate(y(1:npoints))
1027 safe_allocate(x(1:npoints))
1028 safe_allocate(y(1:npoints))
1034 call spline_fit(npoints, x, y, dspl, threshold)
1036 safe_deallocate_a(x)
1037 safe_deallocate_a(y)
1045 subroutine spline_der2(spl, dspl, threshold, grid)
1047 type(
spline_t),
intent(inout) :: dspl
1048 real(real64),
intent(in) :: threshold
1049 real(real64),
optional,
intent(in) :: grid(:)
1051 integer :: npoints, i
1052 real(real64),
allocatable :: x(:), y(:)
1057 if (.not. c_associated(dspl%spl))
then
1060 safe_allocate(x(1:npoints))
1061 safe_allocate(y(1:npoints))
1062 if (
present(grid))
then
1070 safe_allocate(x(1:npoints))
1071 safe_allocate(y(1:npoints))
1077 call spline_fit(npoints, x, y, dspl, threshold)
1079 safe_deallocate_a(x)
1080 safe_deallocate_a(y)
1089 integer,
intent(in) :: iunit
1092 real(real64),
allocatable :: x(:), y(:)
1098 safe_allocate(x(1:np))
1099 safe_allocate(y(1:np))
1104 write(iunit,
'(2es18.8E3)') x(i), y(i)
1107 safe_deallocate_a(x)
1108 safe_deallocate_a(y)
1117 type(
spline_t),
intent(in) :: spl(:)
1118 integer,
intent(in) :: iunit
1120 character(len=4) :: fm
1121 integer :: np, i, n, j
1122 real(real64),
allocatable :: x(:)
1123 real(real64) :: x_limit
1133 write(fm,
'(i4)') n + 1
1136 x_limit = spl(1)%x_limit(2)
1137 safe_allocate(x(1:np))
1144 x_limit = min(x_limit, spl(i)%x_limit(2))
1148 if (x(i) > x_limit -
tol_x) cycle
1149 write(iunit,
'('//trim(fm)//
'es18.8E3)') x(i), (
spline_eval(spl(j), x(i)), j = 1,
size(spl))
1152 safe_deallocate_a(x)
1161 type(
spline_t),
intent(in) :: spl(:, :)
1162 integer,
intent(in) :: iunit
1164 character(len=4) :: fm
1165 integer :: np, i, n1, n2, j, k
1166 real(real64),
allocatable :: x(:)
1167 real(real64) :: x_limit
1173 if (n1 * n2 <= 0)
then
1178 write(fm,
'(i4)') n1*n2 + 1
1182 safe_allocate(x(1:np))
1185 x_limit = spl(1,1)%x_limit(2)
1191 x_limit = min(x_limit, spl(i,j)%x_limit(2))
1196 if (x(i) > x_limit -
tol_x) cycle
1197 write(iunit,
'('//trim(fm)//
'es18.8E3)') x(i), &
1198 ((
spline_eval(spl(j, k), x(i)), j = 1, n1), k = 1, n2)
1201 safe_deallocate_a(x)
1212 real(real64),
intent(in) :: threshold
1215 real(real64),
parameter :: dx = 0.01_real64
1218 assert(spl%x_limit(2) >= spl%x_limit(1))
1220 call profiling_in(
'SPLINE_CUTOFF_RADIUS')
1222 jj =
floor(spl%x_limit(2)/dx) + 1
1225 do while(dx*(jj-1) > spl%x_limit(2) - m_half * dx)
1234 call profiling_out(
'SPLINE_CUTOFF_RADIUS')
1243 range = this%x_limit(1)
1252 range = this%x_limit(2)
1259 real(real64),
allocatable,
intent(inout) :: x_shifted(:)
1261 real(real64),
allocatable :: x(:)
1262 integer :: npoints, i
1269 safe_allocate(x(1:npoints))
1270 safe_allocate(x_shifted(1:npoints))
1272 do i = 1, npoints -1
1273 x_shifted(i) = m_half*(x(i) + x(i+1))
1275 x_shifted(npoints) = x(npoints)
1276 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__
subroutine, public spline_der(spl, dspl, threshold)
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_sum(spl1, spl2, splsum, 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) function, public spline_dotp(spl1, spl2)
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)
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)
subroutine, public spline_times(a, spl, threshold)
subroutine spline_init_2(spl)
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