VMEC 8.52
3D Equilibrium solver with nested flux surfaces.
Loading...
Searching...
No Matches
tridslv.f90
Go to the documentation of this file.
1
3
15SUBROUTINE tridslv(a, d, b, c, jmin, jmax, mnd1, ns, nrhs)
16
17 USE stel_kinds
18
19 IMPLICIT NONE
20
21 INTEGER, INTENT(in) :: jmax, mnd1, ns, nrhs
22 INTEGER, DIMENSION(0:mnd1), INTENT(in) :: jmin
23 REAL(rprec), DIMENSION(ns,0:mnd1) :: a, d, b
24 REAL(rprec), DIMENSION(ns,0:mnd1, nrhs), INTENT(inout) :: c
25
26 REAL(rprec), PARAMETER :: zero = 0.0_dp, one = 1.0_dp
27
28 INTEGER :: mn, in, i0, in1, jrhs
29 REAL(rprec), ALLOCATABLE, DIMENSION(:,:) :: alf
30 REAL(rprec), DIMENSION(0:mnd1) :: psi0
31
32 ! SOLVES B(I)*X(I-1)+D(I)*X(I)+A(I)*X(I+1)=C(I), I=IN,JMAX
33 ! AND RETURNS ANSWER IN C(I)
34 ! ADDED VECTORIZATION ON FOURIER MODE ARGUMENT (01-2000)
35 ! AND NEW ARGUMENT (NRHS) TO DO MULTIPLE RIGHT SIDES SIMULTANEOUSLY
36
37 IF (jmax .gt. ns) stop 'jmax>ns in tridslv'
38
39 ALLOCATE (alf(ns,0:mnd1), stat = in)
40 IF (in .ne. 0) stop 'Allocation error in tridslv'
41
42 ! globally minimum radial index
43 in = minval(jmin)
44! print *, "in=", in ! 1 for solovev case
45! print *, "mnd1=", mnd1 ! 11 for solovev case
46! print *, "nrhs=", nrhs ! 1 for solovev case
47
48 ! FILL IN MN BELOW MAX(JMIN) WITH DUMMY VALUES
49 ! TO ALLOW VECTORIZATION ON MN INDEX
50 DO mn = 0, mnd1
51 in1 = jmin(mn)-1
52 IF (in1 .ge. in) THEN
53! print *, "in1 >= i", in1, " at ", mn
54 d(in:in1, mn) = 1.0_dp
55 c(in:in1, mn, 1:nrhs) = 0.0_dp
56 b(in:in1, mn) = 0.0_dp
57 a(in:in1, mn) = 0.0_dp
58 END IF
59 END DO
60
61 in1 = in + 1 ! 2 for solovev case
62
63 psi0(:)= d(in,:)
64 IF (any(psi0 .eq. zero)) stop 'psi0 == 0 error in tridslv'
65 psi0 = one/psi0
66 DO jrhs = 1, nrhs
67 c(in,:,jrhs) = c(in,:,jrhs)*psi0(:)
68 END DO
69
70 DO i0 = in1,jmax
71 alf(i0-1,:) = a(i0-1,:)*psi0(:)
72 psi0 = d(i0,:) - b(i0,:)*alf(i0-1,:)
73 IF (any(abs(psi0) .le. 1.e-8_dp*abs(d(i0,:)))) then
74 stop 'psi0/d(i0) < 1.E-8: possible singularity in tridslv'
75 end if
76 psi0 = one/psi0
77 DO jrhs = 1, nrhs
78 c(i0,:,jrhs) = (c(i0,:,jrhs) - b(i0,:)*c(i0-1,:,jrhs)) * psi0
79 END DO
80 END DO
81
82 DO i0 = jmax - 1, in, -1
83 DO jrhs = 1,nrhs
84 c(i0,:,jrhs) = c(i0,:,jrhs) - alf(i0,:)*c(i0+1,:,jrhs)
85 END DO
86 END DO
87
88 DEALLOCATE (alf)
89
90END SUBROUTINE tridslv
subroutine tridslv(a, d, b, c, jmin, jmax, mnd1, ns, nrhs)
Solve a tridiagonal system of equations.
Definition tridslv.f90:16