V3FIT
cfode.f
1  SUBROUTINE cfode(meth, elco, tesco)
2  USE stel_kinds
3  IMPLICIT NONE
4 C-----------------------------------------------
5 C D u m m y A r g u m e n t s
6 C-----------------------------------------------
7  INTEGER meth
8  REAL(rprec), DIMENSION(13,12) :: elco
9  REAL(rprec), DIMENSION(3,12) :: tesco
10 C-----------------------------------------------
11 C L o c a l V a r i a b l e s
12 C-----------------------------------------------
13  INTEGER :: i, ib, nq, nqm1, nqp1
14  REAL(rprec) :: agamq, fnq, fnqm1
15  REAL(rprec), DIMENSION(12) :: pc
16  REAL(rprec) :: pint, ragq, rqfac, rq1fac, tsign, xpin
17 C-----------------------------------------------
18 clll. optimize
19 c-----------------------------------------------------------------------
20 c cfode is called by the integrator routine to set coefficients
21 c needed there. the coefficients for the current method, as
22 c given by the value of meth, are set for ALL orders and saved.
23 c the maximum order assumed here is 12 IF meth = 1 and 5 IF meth = 2.
24 c (a smaller value of the maximum order is also allowed.)
25 c cfode is called once at the beginning of the problem,
26 c and is not called again unless and until meth is changed.
27 c
28 c the elco array CONTAINS the basic method coefficients.
29 c the coefficients el(i), 1 .le. i .le. nq+1, for the method of
30 c order nq are stored in elco(i,nq). they are given by a genetrating
31 c polynomial, i.e.,
32 c l(x) = el(1) + el(2)*x + ... + el(nq+1)*x**nq.
33 c for the IMPLICIT adams methods, l(x) is given by
34 c dl/dx = (x+1)*(x+2)*...*(x+nq-1)/factorial(nq-1), l(-1) = 0.
35 c for the bdf methods, l(x) is given by
36 c l(x) = (x+1)*(x+2)* ... *(x+nq)/k,
37 c WHERE k = factorial(nq)*(1 + 1/2 + ... + 1/nq).
38 c
39 c the tesco array CONTAINS test constants used for the
40 c local error test and the selection of step SIZE and/or order.
41 c at order nq, tesco(k,nq) is used for the selection of step
42 c SIZE at order nq - 1 IF k = 1, at order nq IF k = 2, and at order
43 c nq + 1 IF k = 3.
44 c-----------------------------------------------------------------------
45 c
46  SELECT CASE (meth)
47 c
48  CASE DEFAULT
49  elco(1,1) = 1
50  elco(2,1) = 1
51  tesco(1,1) = 0
52  tesco(2,1) = 2
53  tesco(1,2) = 1
54  tesco(3,12) = 0
55  pc(1) = 1
56  rqfac = 1
57  DO nq = 2, 12
58 c-----------------------------------------------------------------------
59 c the pc array will contain the coefficients of the polynomial
60 c p(x) = (x+1)*(x+2)*...*(x+nq-1).
61 c initially, p(x) = 1.
62 c-----------------------------------------------------------------------
63  rq1fac = rqfac
64  rqfac = rqfac/nq
65  nqm1 = nq - 1
66  fnqm1 = nqm1
67  nqp1 = nq + 1
68 c form coefficients of p(x)*(x+nq-1). ----------------------------------
69  pc(nq) = 0.0_dp
70  DO ib = 1, nqm1
71  i = nqp1 - ib
72  pc(i) = pc(i-1) + fnqm1*pc(i)
73  END DO
74  pc(1) = fnqm1*pc(1)
75 c compute integral, -1 to 0, of p(x) and x*p(x). -----------------------
76  pint = pc(1)
77  xpin = pc(1)/2.0_dp
78  tsign = 1.0_dp
79  DO i = 2, nq
80  tsign = -tsign
81  pint = pint + tsign*pc(i)/i
82  xpin = xpin + tsign*pc(i)/(i + 1)
83  END DO
84 c store coefficients in elco and tesco. --------------------------------
85  elco(1,nq) = pint*rq1fac
86  elco(2,nq) = 1.0_dp
87  DO i = 2, nq
88  elco(i+1,nq) = rq1fac*pc(i)/i
89  END DO
90  agamq = rqfac*xpin
91  ragq = 1.0_dp/agamq
92  tesco(2,nq) = ragq
93  IF (nq < 12) tesco(1,nqp1) = ragq*rqfac/nqp1
94  tesco(3,nqm1) = ragq
95  END DO
96  RETURN
97 c
98  CASE (2)
99  pc(1) = 1.0_dp
100  rq1fac = 1.0_dp
101  DO nq = 1, 5
102 c-----------------------------------------------------------------------
103 c the pc array will contain the coefficients of the polynomial
104 c p(x) = (x+1)*(x+2)*...*(x+nq).
105 c initially, p(x) = 1.
106 c-----------------------------------------------------------------------
107  fnq = nq
108  nqp1 = nq + 1
109 c form coefficients of p(x)*(x+nq). ------------------------------------
110  pc(nqp1) = 0.0_dp
111  DO ib = 1, nq
112  i = nq + 2 - ib
113  pc(i) = pc(i-1) + fnq*pc(i)
114  END DO
115  pc(1) = fnq*pc(1)
116 c store coefficients in elco and tesco. --------------------------------
117  elco(:nqp1,nq) = pc(:nqp1)/pc(2)
118  elco(2,nq) = 1.0_dp
119  tesco(1,nq) = rq1fac
120  tesco(2,nq) = nqp1/elco(1,nq)
121  tesco(3,nq) = (nq + 2)/elco(1,nq)
122  rq1fac = rq1fac/fnq
123  END DO
124  RETURN
125  END SELECT
126 
127  END SUBROUTINE cfode