Skip to content

Commit 2652c95

Browse files
authored
add a Runge-Kutta-Chebyshev (RKC) integrator (#1191)
This is a port of the integrator from Sommeijer et al. 1997. It is fully explicit, so no Jacobian is needed, but it does need an estimate of the spectral radius, which is computed internally. This seems to work for moderate temperatures (T < 2.e9 K) for example with XRBs.
1 parent f5b7933 commit 2652c95

File tree

9 files changed

+1289
-3
lines changed

9 files changed

+1289
-3
lines changed

integration/RKC/Make.package

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
ifeq ($(USE_SIMPLIFIED_SDC), TRUE)
2+
CEXE_headers += actual_integrator_simplified_sdc.H
3+
else
4+
ifneq ($(USE_TRUE_SDC), TRUE)
5+
CEXE_headers += actual_integrator.H
6+
endif
7+
endif
8+
9+
CEXE_headers += rkc_type.H
10+
CEXE_headers += rkc.H

integration/RKC/README.md

Lines changed: 268 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,268 @@
1+
# Runge-Kutta-Chebyshev Integrator
2+
3+
This is an implementation of the Runge-Kutta-Chebyshev (RKC)
4+
integrator. This is a port of the `rkc.f` routine from Sommeijer et
5+
al. 1997, as downloaded from Netlib.
6+
7+
Here's the original comments:
8+
9+
```
10+
ABSTRACT: RKC integrates initial value problems for systems of first
11+
order ordinary differential equations. It is based on a family of
12+
explicit Runge-Kutta-Chebyshev formulas of order two. The stability
13+
of members of the family increases quadratically in the number of
14+
stages m. An estimate of the spectral radius is used at each step to
15+
select the smallest m resulting in a stable integration. RKC is
16+
appropriate for the solution to modest accuracy of mildly stiff
17+
problems with eigenvalues of Jacobians that are close to the negative
18+
real axis. For such problems it has the advantages of explicit
19+
one-step methods and very low storage. If it should turn out that RKC
20+
is using m far beyond 100, the problem is not mildly stiff and
21+
alternative methods should be considered. Answers can be obtained
22+
cheaply anywhere in the interval of integration by means of a
23+
continuous extension evaluated in the subroutine RKCINT.
24+
25+
The initial value problems arising from semi-discretization of
26+
diffusion-dominated parabolic partial differential equations and of
27+
reaction-diffusion equations, especially in two and three spatial
28+
variables, exemplify the problems for which RKC was designed. Two
29+
example programs, ExA and ExB, are provided that show how to use RKC.
30+
31+
USAGE: RKC integrates a system of NEQN first order ordinary
32+
differential equations specified by a subroutine F from T to TEND.
33+
The initial values at T are input in Y(*). On all returns from RKC,
34+
Y(*) is an approximate solution at T. In the computation of Y(*), the
35+
local error has been controlled at each step to satisfy a relative
36+
error tolerance RTOL and absolute error tolerances ATOL(*). The array
37+
INFO(*) specifies the way the problem is to be solved. WORK(*) is a
38+
work array. IDID reports success or the reason the computation has
39+
been terminated.
40+
41+
FIRST CALL TO RK
42+
43+
You must provide storage in your calling program for the arrays in the
44+
call list -- Y(NEQN), INFO(4), WORK(8+5*NEQN). If INFO(2) = 0, you
45+
can reduce the storage for the work array to WORK(8+4*NEQN). ATOL may
46+
be a scalar or an array. If it is an array, you must provide storage
47+
for ATOL(NEQN). You must declare F in an external statement, supply
48+
the subroutine F and the function SPCRAD, and initialize the following
49+
quantities:
50+
51+
NEQN: The number of differential equations. Integer.
52+
53+
T: The initial point of the integration. Double precision.
54+
Must be a variable.
55+
56+
TEND: The end of the interval of integration. Double precision.
57+
TEND may be less than T.
58+
59+
Y(*): The initial value of the solution. Double precision array
60+
of length NEQN.
61+
62+
F: The name of a subroutine for evaluating the differential
63+
equation. It must have the form
64+
65+
subroutine f(neqn,t,y,dy)
66+
integer neqn
67+
double precision t,y(neqn),dy(neqn)
68+
dy(1) = ...
69+
...
70+
dy(neqn) = ...
71+
return
72+
end
73+
74+
RTOL,
75+
ATOL(*): At each step of the integration the local error is controlled
76+
so that its RMS norm is no larger than tolerances RTOL, ATOL(*).
77+
RTOL is a double precision scalar. ATOL(*) is either a double
78+
precision scalar or a double precision array of length NEQN.
79+
RKC is designed for the solution of problems to modest accuracy.
80+
Because it is based on a method of order 2, it is relatively
81+
expensive to achieve high accuracy.
82+
83+
RTOL is a relative error tolerance. You must ask for some
84+
relative accuracy, but you cannot ask for too much for the
85+
precision available. Accordingly, it is required that
86+
0.1 >= RTOL >= 10*uround. (See below for the machine and
87+
precision dependent quantity uround.)
88+
89+
ATOL is an absolute error tolerance that can be either a
90+
scalar or an array. When it is an array, the tolerances are
91+
applied to corresponding components of the solution and when
92+
it is a scalar, it is applied to all components. A scalar
93+
tolerance is reasonable only when all solution components are
94+
scaled to be of comparable size. A scalar tolerance saves a
95+
useful amount of storage and is convenient. Use INFO(*) to
96+
tell RKC whether ATOL is a scalar or an array.
97+
98+
The absolute error tolerances ATOL(*) must satisfy ATOL(i) >= 0
99+
for i = 1,...,NEQN. ATOL(j)= 0 specifies a pure relative error
100+
test on component j of the solution, so it is an error if this
101+
component vanishes in the course of the integration.
102+
103+
If all is going well, reducing the tolerances by a factor of
104+
0.1 will reduce the error in the computed solution by a factor
105+
of roughly 0.2.
106+
107+
INFO(*) Integer array of length 4 that specifies how the problem
108+
is to be solved.
109+
110+
INFO(1): RKC integrates the initial value problem from T to TEND.
111+
This is done by computing approximate solutions at points
112+
chosen automatically throughout [T, TEND]. Ordinarily RKC
113+
returns at each step with an approximate solution. These
114+
approximations show how y behaves throughout the interval.
115+
The subroutine RKCINT can be used to obtain answers anywhere
116+
in the span of a step very inexpensively. This makes it
117+
possible to obtain answers at specific points in [T, TEND]
118+
and to obtain many answers very cheaply when attempting to
119+
locating where some function of the solution has a zero
120+
(event location). Sometimes you will be interested only in
121+
a solution at TEND, so you can suppress the returns at each
122+
step along the way if you wish.
123+
124+
INFO(1) = 0 Return after each step on the way to TEND with a
125+
solution Y(*) at the output value of T.
126+
127+
= 1 Compute a solution Y(*) at TEND only.
128+
129+
INFO(2): RKC needs an estimate of the spectral radius of the Jacobian.
130+
You must provide a function that must be called SPCRAD and
131+
have the form
132+
133+
double precision function spcrad(neqn,t,y)
134+
integer neqn
135+
double precision t,y(neqn)
136+
137+
spcrad = < expression depending on info(2) >
138+
139+
return
140+
end
141+
142+
You can provide a dummy function and let RKC compute the
143+
estimate. Sometimes it is convenient for you to compute in
144+
SPCRAD a reasonably close upper bound on the spectral radius,
145+
using, e.g., Gershgorin's theorem. This may be faster and/or
146+
more reliable than having RKC compute one.
147+
148+
INFO(2) = 0 RKC is to compute the estimate internally.
149+
Assign any value to SPCRAD.
150+
151+
= 1 SPCRAD returns an upper bound on the spectral
152+
radius of the Jacobian of f at (t,y).
153+
154+
INFO(3): If you know that the Jacobian is constant, you should say so.
155+
156+
INFO(3) = 0 The Jacobian may not be constant.
157+
158+
= 1 The Jacobian is constant.
159+
160+
INFO(4): You must tell RKC whether ATOL is a scalar or an array.
161+
162+
INFO(4) = 0 ATOL is a double precision scalar.
163+
164+
= 1 ATOL is a double precision array of length NEQN.
165+
166+
WORK(*): Work array. Double precision array of length at least
167+
8 + 5*NEQN if INFO(2) = 0 and otherwise, 8 + 4*NEQN.
168+
169+
IDID: Set IDID = 0 to initialize the integration.
170+
171+
172+
173+
RETURNS FROM RKC
174+
175+
T: The integration has advanced to T.
176+
177+
Y(*): The solution at T.
178+
179+
IDID: The value of IDID reports what happened.
180+
181+
SUCCESS
182+
183+
IDID = 1 T = TEND, so the integration is complete.
184+
185+
= 2 Took a step to the output value of T. To continue on
186+
towards TEND, just call RKC again. WARNING: Do not
187+
alter any argument between calls.
188+
189+
The last step, HLAST, is returned as WORK(1). RKCINT
190+
can be used to approximate the solution anywhere in
191+
[T-HLAST, T] very inexpensively using data in WORK(*).
192+
193+
The work can be monitored by inspecting data in RKCDID.
194+
195+
FAILURE
196+
197+
= 3 Improper error control: For some j, ATOL(j) = 0
198+
and Y(j) = 0.
199+
200+
= 4 Unable to achieve the desired accuracy with the
201+
precision available. A severe lack of smoothness in
202+
the solution y(t) or the function f(t,y) is likely.
203+
204+
= 5 Invalid input parameters: NEQN <= 0, RTOL > 0.1,
205+
RTOL < 10*UROUND, or ATOL(i) < 0 for some i.
206+
207+
= 6 The method used by RKC to estimate the spectral
208+
radius of the Jacobian failed to converge.
209+
210+
RKCDID is a labelled common block that communicates statistics
211+
about the integration process:
212+
common /rkcdid/ nfe,nsteps,naccpt,nrejct,nfesig,maxm
213+
214+
The integer counters are:
215+
216+
NFE number of evaluations of F used
217+
to integrate the initial value problem
218+
NSTEPS number of integration steps
219+
NACCPT number of accepted steps
220+
NREJCT number of rejected steps
221+
NFESIG number of evaluations of F used
222+
to estimate the spectral radius
223+
MAXM maximum number of stages used
224+
225+
This data can be used to monitor the work and terminate a run
226+
that proves to be unacceptably expensive. Also, if MAXM should
227+
be far beyond 100, the problem is too expensive for RKC and
228+
alternative methods should be considered.
229+
230+
CAUTION: MACHINE/PRECISION ISSUES
231+
232+
UROUND (the machine precision) is the smallest number such that
233+
1 + UROUND > 1, where 1 is a floating point number in the working
234+
precision. UROUND is set in a parameter statement in RKC. Its
235+
value depends on both the precision and the machine used, so it
236+
must be set appropriately. UROUND is the only constant in RKC
237+
that depends on the precision.
238+
239+
This version of RKC is written in double precision. It can be changed
240+
to single precision by replacing DOUBLE PRECISION in the declarations
241+
by REAL and changing the type of the floating point constants set in
242+
PARAMETER statements from double precision to real.
243+
244+
Authors: B.P. Sommeijer and J.G. Verwer
245+
Centre for Mathematics and Computer Science (CWI)
246+
Kruislaan 413
247+
1098 SJ Amsterdam
248+
The Netherlands
249+
250+
251+
L.F. Shampine
252+
Mathematics Department
253+
Southern Methodist University
254+
Dallas, Texas 75275-0156
255+
USA
256+
257+
258+
Details of the methods used and the performance of RKC can be
259+
found in
260+
261+
B.P. Sommeijer, L.F. Shampine and J.G. Verwer
262+
RKC: an Explicit Solver for Parabolic PDEs.
263+
Technical Report MAS-R9715, CWI, Amsterdam, 1997
264+
265+
This source code for RKC and some examples, as well as the
266+
reference solution to the second example can also be obtained
267+
by anonymous ftp from the address ftp://ftp.cwi.nl/pub/bsom/rkc
268+
```

integration/RKC/_parameters

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@namespace: integrator

0 commit comments

Comments
 (0)