14 USE stel_constants,
ONLY : pi
49 REAL (rprec) :: length
52 REAL (rprec),
DIMENSION(:),
POINTER :: weights
54 REAL (rprec),
DIMENSION(:),
POINTER :: absc
63 REAL (rprec),
DIMENSION(3) :: position
65 TYPE (
vertex),
POINTER :: next => null()
121 CHARACTER (len=*),
INTENT(in) :: method
122 INTEGER,
INTENT(in) :: npoints
123 REAL (rprec),
INTENT(in) :: length
172 REAL (rprec),
DIMENSION(3),
INTENT(in) :: position
196 TYPE (path_int_class),
POINTER :: this
199 IF (
ASSOCIATED(this%weights))
THEN
200 DEALLOCATE(this%weights)
201 this%weights => null()
204 IF (
ASSOCIATED(this%absc))
THEN
205 DEALLOCATE(this%absc)
226 TYPE (
vertex),
POINTER :: this
229 IF (
ASSOCIATED(this%next))
THEN
257 TYPE (
vertex),
POINTER :: this
258 REAL (rprec),
DIMENSION(3),
INTENT(in) :: position
261 IF (
ASSOCIATED(this))
THEN
262 IF (
ASSOCIATED(this%next))
THEN
291 & integration_function, context)
297 REAL (rprec) :: total
299 TYPE (
vertex),
INTENT(in) :: path
300 CHARACTER (len=1),
INTENT(in) :: context(:)
302 FUNCTION integration_function(context, xcart, dxcart, &
305 REAL (rprec) :: integration_function
306 CHARACTER (len=1),
INTENT(in) :: context(:)
307 REAL (rprec),
DIMENSION(3),
INTENT(in) :: xcart
308 REAL (rprec),
DIMENSION(3),
INTENT(in) :: dxcart
309 REAL (rprec),
INTENT(in) :: length
310 REAL (rprec),
INTENT(in) :: dx
315 If (
ASSOCIATED(path%next))
THEN
318 total = total +
integrate(this, context, path, path%next,
319 & integration_function)
342 RECURSIVE FUNCTION path_search(path, search_function, context, &
343 & found)
RESULT(xcart)
347 REAL (rprec),
DIMENSION(3) :: xcart
348 TYPE (
vertex),
INTENT(in) :: path
349 CHARACTER (len=1),
INTENT(in) :: context(:)
350 LOGICAL,
INTENT(out) :: found
352 FUNCTION search_function(context, xcart1, xcart2)
354 LOGICAL :: search_function
355 CHARACTER (len=1),
INTENT(in) :: context(:)
356 REAL (rprec),
DIMENSION(3),
INTENT(in) :: xcart1
357 REAL (rprec),
DIMENSION(3),
INTENT(in) :: xcart2
364 IF (
ASSOCIATED(path%next))
THEN
365 found =
search(context, path, path%next, search_function,
368 xcart =
path_search(path%next, search_function, context,
394 FUNCTION integrate(this, context, vertex1, vertex2, &
395 & integration_function)
402 CHARACTER(len=1),
INTENT(in) :: context(:)
403 TYPE (
vertex),
INTENT(in) :: vertex1
404 TYPE (
vertex),
INTENT(in) :: vertex2
406 FUNCTION integration_function(context, xcart, dxcart, &
409 REAL (rprec) :: integration_function
410 CHARACTER (len=1),
INTENT(in) :: context(:)
411 REAL (rprec),
DIMENSION(3),
INTENT(in) :: xcart
412 REAL (rprec),
DIMENSION(3),
INTENT(in) :: dxcart
413 REAL (rprec),
INTENT(in) :: length
414 REAL (rprec),
INTENT(in) :: dx
419 SELECT CASE (this%method)
423 & integration_function)
427 & vertex2, integration_function)
432 & integration_function)
459 & integration_function)
466 CHARACTER(len=1),
INTENT(in) :: context(:)
467 TYPE (
vertex),
INTENT(in) :: vertex1
468 TYPE (
vertex),
INTENT(in) :: vertex2
470 FUNCTION integration_function(context, xcart, dxcart, &
473 REAL (rprec) :: integration_function
474 CHARACTER (len=1),
INTENT(in) :: context(:)
475 REAL (rprec),
DIMENSION(3),
INTENT(in) :: xcart, dxcart
476 REAL (rprec),
INTENT(in) :: length, dx
481 REAL (rprec),
DIMENSION(3) :: xcart
482 REAL (rprec),
DIMENSION(3) :: dxcart
483 REAL (rprec) :: length
490 dxcart = vertex2%position - vertex1%position
491 length = sqrt(dot_product(dxcart, dxcart))
492 nsteps = int(length/this%dx)
494 dxcart = dxcart/nsteps
495 dx = sqrt(dot_product(dxcart, dxcart))
501 xcart = vertex1%position
503 xcart = xcart + dxcart
506 & + integration_function(context, xcart, dxcart,
530 & integration_function)
537 CHARACTER(len=1),
INTENT(in) :: context(:)
538 TYPE (
vertex),
INTENT(in) :: vertex1
539 TYPE (
vertex),
INTENT(in) :: vertex2
541 FUNCTION integration_function(context, xcart, dxcart, &
544 REAL (rprec) :: integration_function
545 CHARACTER (len=1),
INTENT(in) :: context(:)
546 REAL (rprec),
DIMENSION(3),
INTENT(in) :: xcart
547 REAL (rprec),
DIMENSION(3),
INTENT(in) :: dxcart
548 REAL (rprec),
INTENT(in) :: length
549 REAL (rprec),
INTENT(in) :: dx
554 REAL (rprec),
DIMENSION(3) :: xcart
555 REAL (rprec),
DIMENSION(3) :: xcart1
556 REAL (rprec),
DIMENSION(3) :: dxcart
557 REAL (rprec) :: length
558 REAL (rprec) :: temp_length
566 dxcart = vertex2%position - vertex1%position
567 length = sqrt(dot_product(dxcart, dxcart))
568 dxcart(:) = dxcart(:)/length
572 xcart = vertex1%position
573 DO i = 1,
SIZE(this%weights)
574 xcart = vertex1%position + this%absc(i)*dxcart*length
575 temp_length = this%absc(i)*length
578 & this%weights(i)*integration_function(context, xcart,
579 & dxcart, temp_length,
606 & integration_function)
613 CHARACTER(len=1),
INTENT(in) :: context(:)
614 TYPE (
vertex),
INTENT(in) :: vertex1
615 TYPE (
vertex),
INTENT(in) :: vertex2
617 function integration_function(context, xcart, dxcart,
620 REAL (rprec) :: integration_function
621 CHARACTER (len=1),
INTENT(in) :: context(:)
622 REAL (rprec),
DIMENSION(3),
INTENT(in) :: xcart
623 REAL (rprec),
DIMENSION(3),
INTENT(in) :: dxcart
624 REAL (rprec),
INTENT(in) :: length
625 REAL (rprec),
INTENT(in) :: dx
630 REAL (rprec),
DIMENSION(3) :: xcart
631 REAL (rprec),
DIMENSION(3) :: xcart1
632 REAL (rprec),
DIMENSION(3) :: dxcart
633 REAL (rprec) :: length
634 REAL (rprec) :: lengthp
635 REAL (rprec) :: temp_length
639 REAL (rprec) :: int_length
640 REAL (rprec) :: integratej
646 dxcart = vertex2%position - vertex1%position
647 length = sqrt(dot_product(dxcart, dxcart))
648 dxcart(:) = dxcart(:)/length
650 nsteps = int(length/this%length)
651 int_length = length/real(nsteps, rprec)
655 xcart = vertex1%position
659 DO i = 1,
SIZE(this%weights)
660 xcart1 = xcart + this%absc(i)*dxcart*int_length
661 temp_length = lengthp + this%absc(i)*int_length
662 integratej = integratej +
663 & this%weights(i)*integration_function(context, xcart1,
664 & dxcart, temp_length,
669 lengthp = lengthp + int_length
670 xcart = xcart + dxcart*int_length
690 FUNCTION search(context, vertex1, vertex2, search_function, xcart)
696 CHARACTER(len=1),
INTENT(in) :: context(:)
697 TYPE (
vertex),
INTENT(in) :: vertex1
698 TYPE (
vertex),
INTENT(in) :: vertex2
699 REAL (rprec),
DIMENSION(3),
INTENT(out) :: xcart
701 FUNCTION search_function(context, xcart1, xcart2)
703 LOGICAL :: search_function
704 CHARACTER (len=1),
INTENT(in) :: context(:)
705 REAL (rprec),
DIMENSION(3),
INTENT(in) :: xcart1
706 REAL (rprec),
DIMENSION(3),
INTENT(in) :: xcart2
711 REAL (rprec),
DIMENSION(3) :: dxcart
717 REAL (rprec),
PARAMETER :: dxcourse = 0.01
718 REAL (rprec),
PARAMETER :: dxfine = 1.0e-20
723 dxcart = vertex2%position - vertex1%position
724 nsteps = int(sqrt(dot_product(dxcart, dxcart))/dxcourse)
727 dxcart = dxcart/nsteps
730 xcart = vertex1%position
734 search = search_function(context, xcart, xcart + dxcart)
738 DO WHILE (sqrt(dot_product(dxcart, dxcart)) .gt. dxfine)
740 IF (.not.search_function(context, xcart,
741 & xcart + dxcart))
THEN
742 xcart = xcart + dxcart
746 xcart = xcart + dxcart/2.0
751 xcart = xcart + dxcart
774 REAL (rprec),
INTENT(in) :: a
775 REAL (rprec),
INTENT(in) :: b
776 REAL(rprec),
DIMENSION(:),
INTENT(out) :: abscissas
777 REAL(rprec),
DIMENSION(:),
INTENT(out) :: weights
789 REAL (rprec) :: current
793 REAL (rprec),
PARAMETER :: eps = 1.0e-14
796 m = (
SIZE(weights) + 1)/2
804 current = cos(pi*(real(i, rprec) - 0.25_rprec)/
805 & (real(
SIZE(weights), rprec) + 0.5_rprec))
813 DO j = 1,
SIZE(weights)
816 p1 = (real(2.0*j - 1, rprec)*current*p2 -
817 & real(j - 1, rprec)*p3)/real(j, rprec)
821 pp = real(
SIZE(weights), rprec)*(current*p1 - p2)
822 & / (current**2 - 1._rprec)
826 current = last - p1/pp
827 IF (abs(current - last) .le. eps)
EXIT
830 abscissas(i) = xm - xl*current
831 abscissas(
SIZE(weights) + 1 - i) = xm + xl*current
834 weights(i) = 2.0*xl/((1.0 - current*current)*pp*pp)
835 weights(
SIZE(weights) + 1 - i) = weights(i)
858 REAL (rprec) :: result
859 TYPE (
vertex),
POINTER :: test_path => null()
861 CHARACTER(len=1),
ALLOCATABLE :: context(:)
862 REAL(rprec),
DIMENSION(3) :: absc
863 REAL(rprec),
DIMENSION(3) :: wgts
868 path_test =
check(.false.,
ASSOCIATED(test_path), 1,
'ASSOCIATED')
873 & (/ 1.0_rprec, 2.0_rprec, 3.0_rprec /))
875 &
'path_append_vertex')
878 &
'path_append_vertex')
881 &
'path_append_vertex')
884 &
'path_append_vertex')
889 & (/ 4.0_rprec, 5.0_rprec, 6.0_rprec /))
891 &
'path_append_vertex')
894 &
'path_append_vertex')
897 &
'path_append_vertex')
900 &
'path_append_vertex')
903 &
'path_append_vertex')
906 &
'path_append_vertex')
909 &
'path_append_vertex')
914 & (/ 7.0_rprec, 8.0_rprec, 9.0_rprec /))
916 & 12,
'path_append_vertex')
919 &
'path_append_vertex')
922 &
'path_append_vertex')
925 &
'path_append_vertex')
937 &
'path_construct_int')
942 & (/ 2.0_rprec, 0.0_rprec, 0.0_rprec /))
944 & (/ 0.0_rprec, 0.0_rprec, 0.0_rprec /))
952 work = sqrt(0.6_rprec)
956 path_test =
check(5._rprec/9._rprec, wgts(1), 4,
'get_gaussqad_w')
957 path_test =
check(8._rprec/9._rprec, wgts(2), 5,
'get_gaussqad_w')
958 path_test =
check(5._rprec/9._rprec, wgts(3), 6,
'get_gaussqad_w')
974 &
'path_integrate_hp_gleg')
996 FUNCTION check_log(expected, received, testNum, name)
1002 LOGICAL,
INTENT(in) :: expected
1003 LOGICAL,
INTENT(in) :: received
1004 INTEGER,
INTENT(in) :: testnum
1005 CHARACTER (LEN=*),
INTENT(in) :: name
1010 WRITE(*,*)
"integration_path.f: ", name,
" test", testnum,
1012 WRITE(*,*)
"Expected", expected,
"Received", received
1029 FUNCTION check_real(expected, received, testNum, name)
1035 REAL(rprec),
INTENT(in) :: expected
1036 REAL(rprec),
INTENT(in) :: received
1037 INTEGER,
INTENT(in) :: testnum
1038 CHARACTER (LEN=*),
INTENT(in) :: name
1041 REAL(rprec) :: eps = 1.0e-8
1044 check_real = (abs(expected - received) .lt. eps)
1046 WRITE(*,*)
"integration_path.f: ", name,
" test", testnum,
1048 WRITE(*,*)
"Expected", expected,
"Received", received
1065 FUNCTION check_int(expected, received, testNum, name)
1071 INTEGER,
INTENT(in) :: expected
1072 INTEGER,
INTENT(in) :: received
1073 INTEGER,
INTENT(in) :: testnum
1074 CHARACTER (LEN=*),
INTENT(in) :: name
1079 WRITE(*,*)
"integration_path.f: ", name,
" test", testnum,
1081 WRITE(*,*)
"Expected", expected,
"Received", received
1105 CHARACTER (len=1),
INTENT(in) :: context(:)
1106 REAL (rprec),
DIMENSION(3),
INTENT(in) :: xcart
1107 REAL (rprec),
DIMENSION(3),
INTENT(in) :: dxcart
1108 REAL (rprec),
INTENT(in) :: length
1109 REAL (rprec),
INTENT(in) :: dx