Spaces:
Sleeping

headless_scilab / data /help /4-ImplicitRK.xml
notsn's picture
Deploy headless Scilab space implementation
3d893c2 verified
Raw History Blame Contribute Delete
13.7 kB
<?xml version="1.0" encoding="UTF-8"?>
<!--
* Scilab ( https://www.scilab.org/ ) - This file is part of Scilab
* Copyright (C) Scilab Enterprises - 2012 - Paul Bignier
*
* Copyright (C) 2012 - 2016 - Scilab Enterprises
*
* This file is hereby licensed under the terms of the GNU GPL v2.0,
* pursuant to article 5.3.4 of the CeCILL v.2.1.
* This file was originally licensed under the terms of the CeCILL v2.1,
* and continues to be available under such terms.
* For more information, see the COPYING file which you should have received
* along with this program.
-->
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:lang="en_US" xml:id="ImpRK">
<refnamediv>
<refname>Implicit Runge-Kutta 4(5)</refname>
<refpurpose>
Numerical solver providing an efficient and stable implicit method to solve Ordinary Differential Equations (ODEs) Initial Value Problems.
</refpurpose>
</refnamediv>
<refsection>
<title>Description</title>
<para>
<emphasis>Runge-Kutta</emphasis> is a numerical solver providing an efficient and stable fixed-size step method to solve Initial Value Problems of the form:
</para>
<para>
<latex>
\begin{eqnarray}
\dot{y} = f(t,y), \hspace{3 mm} y(t_0) = y_0, \hspace{3 mm} y \in R^N
\end{eqnarray}
</latex>
</para>
<para>
<emphasis>CVode</emphasis> and <emphasis>IDA</emphasis> use variable-size steps for the integration.
</para>
<para>
A drawback of that is the unpredictable computation time. With <emphasis>Runge-Kutta</emphasis>, we do not adapt to the complexity of the problem, but we guarantee a stable computation time.
</para>
<para>
This method being implicit, it can be used on stiff problems.
</para>
<para>
It is an enhancement of the backward Euler method, which approximates
<emphasis>
y<subscript>n+1</subscript>
</emphasis>
by computing
<emphasis>
f(t<subscript>n</subscript>+h, y<subscript>n+1</subscript>)
</emphasis>
and truncating the Taylor expansion.
</para>
<para>
The implemented scheme is inspired from the "Low-Dispersion Low-Dissipation Implicit Runge-Kutta Scheme" (see bottom for link).
</para>
<para>
By convention, to use fixed-size steps, the program first computes a fitting <emphasis>h</emphasis> that approaches the simulation parameter <link linkend="Simulatemenu_Menu_entries">max step size</link>.
</para>
<para>
An important difference of <emphasis>implicit Runge-Kutta</emphasis> with the previous methods is that it computes up to the fourth derivative of <emphasis>y</emphasis>, while the others only use linear combinations of <emphasis>y</emphasis> and <emphasis>y'</emphasis>.
</para>
<para>
Here, the next value is determined by the present value
<emphasis>
y<subscript>n</subscript>
</emphasis>
plus the weighted average of three increments, where each increment is the product of the size of the interval, <emphasis>h</emphasis>, and an estimated slope specified by the function <emphasis>f(t,y)</emphasis>. They are distributed approximately equally on the interval.
<itemizedlist>
<listitem>
<emphasis>k1</emphasis> is the increment based on the slope near the quarter of the interval, using
<emphasis>
y<subscript>n</subscript>+ a11*h*k1
</emphasis>
,
</listitem>
<listitem>
<emphasis>k2</emphasis> is the increment based on the slope near the midpoint of the interval, using
<emphasis>
y<subscript>n</subscript> + a21*h*k1 + a22*h*k2
</emphasis>
,
</listitem>
<listitem>
<emphasis>k3</emphasis> is the increment based on the slope near the third quarter of the interval, using
<emphasis>
y<subscript>n</subscript> + a31*h*k1 + a32*h*k2 + a33*h*k3
</emphasis>
.
</listitem>
</itemizedlist>
</para>
<para>
We see that the computation of <emphasis>ki</emphasis> requires <emphasis>ki</emphasis>, thus necessitating the use of a nonlinear solver (here, fixed-point iterations).
</para>
<para>
First, we set
<emphasis>
k0 = h * f(t<subscript>n</subscript>, y<subscript>n</subscript>)
</emphasis>
as first guess for all the <emphasis>ki</emphasis>, to get updated <emphasis>ki</emphasis> and a first value for
<emphasis>
y<subscript>n+1</subscript>
</emphasis>
.
</para>
<para>
Next, we save and recompute
<emphasis>
y<subscript>n+1</subscript>
</emphasis>
with those new <emphasis>ki</emphasis>.
</para>
<para>
Then, we compare the two
<emphasis>
y<subscript>n+1</subscript>
</emphasis>
and recompute it until its difference with the last computed one is inferior to the simulation parameter <emphasis>reltol</emphasis>.
</para>
<para>
This process adds a significant computation time to the method, but greatly improves stability.
</para>
<para>
We can see that with the <emphasis>ki</emphasis>, we progress in the derivatives of
<emphasis>
y<subscript>n</subscript>
</emphasis>
. So in <emphasis>k3</emphasis>, we are approximating
<emphasis>
y<superscript>(3)</superscript><subscript>n</subscript>
</emphasis>
, thus making an error in
<emphasis>
O(h<superscript>4</superscript>)
</emphasis>
. But choosing the right coefficients in the computation of the <emphasis>ki</emphasis> (notably the
<emphasis>
a<subscript>ij</subscript>
</emphasis>
) makes us gain an order, thus making a per-step total error in
<emphasis>
O(h<superscript>5</superscript>)
</emphasis>
.
</para>
<para>
So the total error is
<emphasis>
number of steps * O(h<superscript>5</superscript>)
</emphasis>
. And since <emphasis>number of steps = interval size / h</emphasis> by definition, the total error is in
<emphasis>
O(h<superscript>4</superscript>)
</emphasis>
.
</para>
<para>
That error analysis baptized the method <emphasis>implicit Runge-Kutta 4(5)</emphasis>:
<emphasis>
O(h<superscript>5</superscript>)
</emphasis>
per step,
<emphasis>
O(h<superscript>4</superscript>)
</emphasis>
in total.
</para>
<para>
Although the solver works fine for <link linkend="Simulatemenu_Menu_entries">max step size</link> up to
<emphasis>
10<superscript>-3</superscript>
</emphasis>
, rounding errors sometimes come into play as we approach
<emphasis>
4*10<superscript>-4</superscript>
</emphasis>
. Indeed, the interval splitting cannot be done properly and we get capricious results.
</para>
</refsection>
<refsection>
<title>Examples</title>
<para>
<link type="scilab" linkend="scilab.xcos/xcos/examples/solvers/ODE_Example.zcos">
<inlinemediaobject>
<imageobject>
<imagedata align="center" fileref="../../../examples/solvers/ODE_Example.zcos" valign="middle"/>
</imageobject>
</inlinemediaobject>
</link>
<scilab:image><![CDATA[
loadScicos();
loadXcosLibs();
importXcosDiagram(SCI + "/modules/xcos/examples/solvers/ODE_Example.zcos");
scs_m.props.tol(2) = 10^-5;
scs_m.props.tol(6) = 7;
scs_m.props.tol(7) = 10^-2;
try xcos_simulate(scs_m, 4); catch disp(lasterror()); end
]]></scilab:image>
</para>
<para>
The integral block returns its continuous state, we can evaluate it with <emphasis>implicit RK</emphasis> by running the example:
</para>
<para>
<programlisting language="example"><![CDATA[
// Import the diagram and set the ending time
loadScicos();
loadXcosLibs();
importXcosDiagram("SCI/modules/xcos/examples/solvers/ODE_Example.zcos");
scs_m.props.tf = 5000;
// Select the solver implicit RK and set the precision
scs_m.props.tol(2) = 10^-10;
scs_m.props.tol(6) = 7;
scs_m.props.tol(7) = 10^-2;
// Start the timer, launch the simulation and display time
tic();
try xcos_simulate(scs_m, 4); catch disp(lasterror()); end
t = toc();
disp("Time for implicit Runge-Kutta:", t);
]]></programlisting>
</para>
<para>
The Scilab console displays:
<screen><![CDATA[
Time for implicit Runge-Kutta:
8.911
]]></screen>
</para>
<para>
Now, in the following script, we compare the time difference between <emphasis>implicit RK</emphasis> and <emphasis>CVode</emphasis> by running the example with the five solvers in turn:
<link type="scilab" linkend ="scilab.scinotes/xcos/examples/solvers/integImpRK.sce">
Open the script
</link>
</para>
<para>
<screen><![CDATA[
Time for BDF / Newton:
18.894
Time for BDF / Functional:
18.382
Time for Adams / Newton:
10.368
Time for Adams / Functional:
9.815
Time for implicit Runge-Kutta:
6.652
]]></screen>
</para>
<para>
These results show that on a nonstiff problem, for relatively same precision required and forcing the same step size, <emphasis>implicit Runge-Kutta</emphasis> competes with <emphasis>Adams / Functional</emphasis>.
</para>
<para>
Variable-size step ODE solvers are not appropriate for deterministic real-time applications because the computational overhead of taking a time step varies over the course of an application.
</para>
</refsection>
<refsection role="see also">
<title>See also</title>
<simplelist type="inline">
<member>
<link linkend="LSodar">LSodar</link>
</member>
<member>
<link linkend="CVode">CVode</link>
</member>
<member>
<link linkend="IDA">IDA</link>
</member>
<member>
<link linkend="RK">Runge-Kutta 4(5)</link>
</member>
<member>
<link linkend="DoPri">Dormand-Prince 4(5)</link>
</member>
<member>
<link linkend="CRANI">Crank-Nicolson 2(3)</link>
</member>
<member>
<link linkend="DDaskr">DDaskr</link>
</member>
<member>
<link linkend="Comparisons">Comparisons</link>
</member>
<member>
<link linkend="ode_discrete">ode_discrete</link>
</member>
<member>
<link linkend="ode_root">ode_root</link>
</member>
<member>
<link linkend="odedc">odedc</link>
</member>
<member>
<link linkend="dae">dae</link>
</member>
</simplelist>
</refsection>
<refsection>
<title>Bibliography</title>
<para>
Journal of Computational Physics, Volume 233, January 2013, Pages 315-323 <ulink url="http://dl.acm.org/citation.cfm?id=2397727.2397975&amp;coll=DL&amp;dl=GUIDE&amp;CFID=295003167&amp;CFTOKEN=37159263">A low-dispersion and low-dissipation implicit Runge-Kutta scheme</ulink>
</para>
<para>
<ulink url="https://computation.llnl.gov/casc/sundials/documentation/documentation.html">Sundials Documentation</ulink>
</para>
</refsection>
<refsection>
<title>History</title>
<revhistory>
<revision>
<revnumber>5.4.1</revnumber>
<revdescription>Implicit Runge-Kutta 4(5) solver added</revdescription>
</revision>
</revhistory>
</refsection>
</refentry>