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))
718 safe_allocate(xw(1:np))
719 safe_allocate(yw(1:np))
729 y2(j) = m_four*m_pi*y(j)*x(j)**2
739 y2(j) = (m_four*m_pi/xw(i))*y(j)*x(j)*
sin(xw(i)*x(j))
752 safe_deallocate_a(y2)
753 safe_deallocate_a(xw)
754 safe_deallocate_a(yw)
763 type(
spline_t),
intent(inout) :: splw
764 integer,
intent(in) :: l
765 real(real64),
optional,
intent(in) :: threshold
766 real(real64),
optional,
intent(in) :: gmax
771 integer :: npoints, i, j
772 real(real64),
allocatable :: x(:), y(:), y2(:), xw(:), yw(:)
779 safe_allocate( x(1:npoints))
780 safe_allocate( y(1:npoints))
781 safe_allocate(y2(1:npoints))
787 if (c_associated(splw%spl))
then
789 safe_allocate(xw(1:np))
790 safe_allocate(yw(1:np))
795 assert(
present(gmax))
798 safe_allocate(xw(1:np))
799 safe_allocate(yw(1:np))
809 y2(j) = y(j) * x(j)**2 * loct_sph_bessel(l, x(j)*xw(i))
823 safe_deallocate_a(y2)
824 safe_deallocate_a(xw)
825 safe_deallocate_a(yw)
832 subroutine spline_cut(spl, cutoff, beta, threshold)
833 type(
spline_t),
intent(inout) :: spl
834 real(real64),
intent(in) :: cutoff
835 real(real64),
intent(in) :: beta
836 real(real64),
optional,
intent(in) :: threshold
838 integer :: npoints, i
839 real(real64),
allocatable :: x(:), y(:)
840 real(real64) :: exp_arg
847 safe_allocate(x(1:npoints))
848 safe_allocate(y(1:npoints))
854 do i = npoints, 1, -1
855 if (x(i)<cutoff)
then
859 exp_arg = -beta*(x(i)/cutoff - m_one)**2
861 if (exp_arg > m_min_exp_arg)
then
862 y(i) = y(i) *
exp(exp_arg)
867 call spline_fit(npoints, x, y, spl, threshold)
882 type(
spline_t),
intent(inout) :: spla
884 real(real64),
optional,
intent(in) :: threshold
886 integer :: npoints, i, new_npoints
887 real(real64),
allocatable :: x(:), y(:)
895 safe_allocate(x(1:npoints))
896 safe_allocate(y(1:npoints))
902 assert(splb%x_limit(2) >= splb%x_limit(1))
907 do i = npoints, 1, -1
908 if (x(i) > splb%x_limit(2)-
tol_x) cycle
911 new_npoints = new_npoints + 1
914 call spline_fit(new_npoints, x, y, spla, threshold)
926 type(
spline_t),
intent(inout) :: spl
927 real(real64),
intent(in) :: threshold
929 integer :: npoints, i
930 real(real64),
allocatable :: x(:), y(:)
937 safe_allocate(x(1:npoints))
938 safe_allocate(y(1:npoints))
945 do i = npoints, 1, -1
946 y(i) = max(y(i),m_zero)
949 call spline_fit(npoints, x, y, spl, threshold)
960 type(
spline_t),
intent(inout) :: spla
962 real(real64),
intent(in) :: threshold
964 integer :: npoints, i
965 real(real64),
allocatable :: x(:), y(:)
971 if(npoints <= 0)
then
976 safe_allocate(x(1:npoints))
977 safe_allocate(y(1:npoints))
983 assert(splb%x_limit(2) >= splb%x_limit(1))
986 do i = npoints, 1, -1
987 if (x(i) > splb%x_limit(2) -
tol_x)
then
995 call spline_fit(npoints, x, y, spla, threshold)
1007 type(
spline_t),
intent(inout) :: dspl
1008 real(real64),
intent(in) :: threshold
1010 integer :: npoints, i
1011 real(real64),
allocatable :: x(:), y(:)
1016 if (.not. c_associated(dspl%spl))
then
1019 safe_allocate(x(1:npoints))
1020 safe_allocate(y(1:npoints))
1025 safe_allocate(x(1:npoints))
1026 safe_allocate(y(1:npoints))
1032 call spline_fit(npoints, x, y, dspl, threshold)
1034 safe_deallocate_a(x)
1035 safe_deallocate_a(y)
1043 subroutine spline_der2(spl, dspl, threshold, grid)
1045 type(
spline_t),
intent(inout) :: dspl
1046 real(real64),
intent(in) :: threshold
1047 real(real64),
optional,
intent(in) :: grid(:)
1049 integer :: npoints, i
1050 real(real64),
allocatable :: x(:), y(:)
1055 if (.not. c_associated(dspl%spl))
then
1058 safe_allocate(x(1:npoints))
1059 safe_allocate(y(1:npoints))
1060 if (
present(grid))
then
1068 safe_allocate(x(1:npoints))
1069 safe_allocate(y(1:npoints))
1075 call spline_fit(npoints, x, y, dspl, threshold)
1077 safe_deallocate_a(x)
1078 safe_deallocate_a(y)
1087 integer,
intent(in) :: iunit
1090 real(real64),
allocatable :: x(:), y(:)
1096 safe_allocate(x(1:np))
1097 safe_allocate(y(1:np))
1102 write(iunit,
'(2es18.8E3)') x(i), y(i)
1105 safe_deallocate_a(x)
1106 safe_deallocate_a(y)
1115 type(
spline_t),
intent(in) :: spl(:)
1116 integer,
intent(in) :: iunit
1118 character(len=4) :: fm
1119 integer :: np, i, n, j
1120 real(real64),
allocatable :: x(:)
1121 real(real64) :: x_limit
1131 write(fm,
'(i4)') n + 1
1134 x_limit = spl(1)%x_limit(2)
1135 safe_allocate(x(1:np))
1142 x_limit = min(x_limit, spl(i)%x_limit(2))
1146 if (x(i) > x_limit -
tol_x) cycle
1147 write(iunit,
'('//trim(fm)//
'es18.8E3)') x(i), (
spline_eval(spl(j), x(i)), j = 1,
size(spl))
1150 safe_deallocate_a(x)
1159 type(
spline_t),
intent(in) :: spl(:, :)
1160 integer,
intent(in) :: iunit
1162 character(len=4) :: fm
1163 integer :: np, i, n1, n2, j, k
1164 real(real64),
allocatable :: x(:)
1165 real(real64) :: x_limit
1171 if (n1 * n2 <= 0)
then
1176 write(fm,
'(i4)') n1*n2 + 1
1180 safe_allocate(x(1:np))
1183 x_limit = spl(1,1)%x_limit(2)
1189 x_limit = min(x_limit, spl(i,j)%x_limit(2))
1194 if (x(i) > x_limit -
tol_x) cycle
1195 write(iunit,
'('//trim(fm)//
'es18.8E3)') x(i), &
1196 ((
spline_eval(spl(j, k), x(i)), j = 1, n1), k = 1, n2)
1199 safe_deallocate_a(x)
1210 real(real64),
intent(in) :: threshold
1213 real(real64),
parameter :: dx = 0.01_real64
1216 assert(spl%x_limit(2) >= spl%x_limit(1))
1218 call profiling_in(
'SPLINE_CUTOFF_RADIUS')
1220 jj =
floor(spl%x_limit(2)/dx) + 1
1223 do while(dx*(jj-1) > spl%x_limit(2) - m_half * dx)
1232 call profiling_out(
'SPLINE_CUTOFF_RADIUS')
1241 range = this%x_limit(1)
1250 range = this%x_limit(2)
1257 real(real64),
allocatable,
intent(inout) :: x_shifted(:)
1259 real(real64),
allocatable :: x(:)
1260 integer :: npoints, i
1267 safe_allocate(x(1:npoints))
1268 safe_allocate(x_shifted(1:npoints))
1270 do i = 1, npoints -1
1271 x_shifted(i) = m_half*(x(i) + x(i+1))
1273 x_shifted(npoints) = x(npoints)
1274 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