Skip to content

Commit 427216d

Browse files
committed
up Ascher docs, added presets
1 parent 3d932af commit 427216d

File tree

6 files changed

+92
-37
lines changed

6 files changed

+92
-37
lines changed

docs/references.bib

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,15 @@ @article{Asc89
120120
doi = {10.1137/0910054}
121121
}
122122

123+
@article{Pet86,
124+
author = {L. R. Petzold},
125+
journal = {SIAM Journal on Numerical Analysis},
126+
number = {4},
127+
pages = {837--852},
128+
publisher = {Society for Industrial and Applied Mathematics},
129+
title = {Order Results for Implicit Runge-Kutta Methods Applied to Differential/ Algebraic Systems},
130+
volume = {23},
131+
year = {1986},
132+
url = {https://www.jstor.org/stable/2157625}
133+
}
123134

toolbox/+otp/+ascherlineardae/+presets/Canonical.m

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
classdef Canonical < otp.ascherlineardae.AscherLinearDAEProblem
2-
% The original problem defined by Uri Ascher in :cite:p:`Asc89` with
3-
% $\beta = 0.5$
2+
% The problem defined by Uri Ascher in :cite:p:`Asc89` (sec. 2)
3+
% which uses timespan $t \in [0, 1]$ and $\beta = 1 $.
44
%
55
methods
6-
function obj = Canonical(beta)
7-
tspan = [0.0; 1];
6+
function obj = Canonical(varargin)
7+
% Create the Canonical CUSP problem object.
8+
%
9+
% Parameters
10+
% ----------
11+
% varargin
12+
% A variable number of name-value pairs. The accepted names are
13+
%
14+
% - ``Beta`` – The parameter of the Ascher linear DAE problem.
815

9-
if nargin < 1
10-
beta = 0.5;
11-
end
16+
p = inputParser;
17+
p.addParameter('beta', 1);
18+
p.parse(varargin{:});
19+
opts = p.Results;
1220

13-
params = otp.ascherlineardae.AscherLinearDAEParameters;
14-
params.Beta = beta;
21+
params = otp.ascherlineardae.AscherLinearDAEParameters;
22+
params.Beta = opts.beta;
1523

16-
y0 = [1; beta];
24+
y0 = [1; params.Beta];
25+
tspan = [0.0; 1.0];
1726

1827
obj = obj@otp.ascherlineardae.AscherLinearDAEProblem(tspan, y0, params);
1928
end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
classdef Petzold < otp.ascherlineardae.AscherLinearDAEProblem
2+
% The Petzold DAE example :cite:p:`Pet86` as a variant of the
3+
% Ascher linear DAE problem
4+
% which uses timespan $t \in [0, 1]$ and $\beta = 0 $.
5+
%
6+
methods
7+
function obj = Petzold
8+
% Create the Petzold example of the Ascher linear DAE problem object.
9+
10+
params = otp.ascherlineardae.AscherLinearDAEParameters;
11+
params.Beta = 0;
12+
13+
y0 = [1; params.Beta];
14+
tspan = [0.0; 1.0];
15+
16+
obj = obj@otp.ascherlineardae.AscherLinearDAEProblem(tspan, y0, params);
17+
end
18+
end
19+
end
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
classdef Stiff < otp.ascherlineardae.AscherLinearDAEProblem
2+
% The Stiff example from :cite:p:`Asc89` (sec. 2. A variant of the
3+
% Ascher linear DAE problem
4+
% which uses timespan $t \in [0, 1]$ and $\beta = 100 $.
5+
%
6+
methods
7+
function obj = Stiff
8+
% Create the stiff example of the Ascher linear DAE problem object.
9+
10+
params = otp.ascherlineardae.AscherLinearDAEParameters;
11+
params.Beta = 100;
12+
13+
y0 = [1; params.Beta];
14+
tspan = [0.0; 1.0];
15+
16+
obj = obj@otp.ascherlineardae.AscherLinearDAEProblem(tspan, y0, params);
17+
end
18+
end
19+
end
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
classdef AscherLinearDAEParameters
22
% Parameters for Ascher Linear DAE problem
33
properties
4-
% Beta is a scalar parameter in the linear model. It also affects the initial condition
5-
% of the algebraic variable.
6-
Beta %MATLAB ONLY: (1,1) {mustBeNumeric} = 0.5
4+
% Beta is a scalar parameter in the linear model. It affects the stifness
5+
% of the problem.
6+
Beta %MATLAB ONLY: (1,1) {mustBeNumeric} = 1
77
end
88
end

toolbox/+otp/+ascherlineardae/AscherLinearDAEProblem.m

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,33 @@
22
% A simple linear differential algebraic problem.
33
%
44
% The Ascher linear DAE Problem :cite:p:`Asc89` is an index-1 differential agebraic
5-
% equation given by $M(t) y' = A(t) y + q(t) $ where
5+
% equation given by
66
%
77
% $$
8-
% M=\left(\begin{array}{cc}
8+
% \begin{bmatrix}
99
% 1 & -t \\
1010
% 0 & 0
11-
% \end{array}\right), \quad A=\left(\begin{array}{cc}
11+
% \end{bmatrix} \begin{bmatrix} y'(t) \\ z'(t) \end{bmatrix} = \left[ \begin{array}{cc}
1212
% -1 & 1+t \\
1313
% \beta & -1-\beta t
14-
% \end{array}\right), \quad {q}=\left(\begin{array}{c}
14+
% \end{array}\right] \begin{bmatrix} y(t) \\ z(t) \end{bmatrix} + \begin{bmatrix}
1515
% 0 \\
1616
% \sin t
17-
% \end{array}\right),
17+
% \end{bmatrix}.
1818
% $$
1919
%
20-
% defined on timespan $t \in [0,1]$, and initial condition $y_0 = [1, \beta]^T$. The exact solution
21-
% is given by
20+
% The problem has the following closed-form solution when the initial condition $y(0) = 1 , z(0) = \beta$ is used:
2221
%
2322
% $$
24-
% y = \begin{pmatrix}
23+
% \begin{bmatrix} y(t)\\ z(t) \end{bmatrix} = \begin{bmatrix}
2524
% t \sin(t) + (1 + \beta t) e^{-t}\\
2625
% \beta e^{-t} + \sin(t)
27-
% \end{pmatrix}.
26+
% \end{bmatrix}.
2827
% $$
29-
%
30-
% Due to its stiffness and time-dependant mass
31-
% matrix, this simple DAE problem can
32-
% become challenging to solve. This problem is introduced in :cite:p:`Asc89`
33-
% to study the convergence of implcit solvers applied to DAEs.
28+
% This DAE problem
29+
% can be used to investigate
30+
% the convergence of implcit time-stepping methods due to its stiffness and time-dependant mass
31+
% matrix.
3432
%
3533
% Notes
3634
% -----
@@ -39,14 +37,15 @@
3937
% +---------------------+-----------------------------------------+
4038
% | Number of Variables | 2 |
4139
% +---------------------+-----------------------------------------+
42-
% | Stiff | typically, depending on $\beta$ |
40+
% | Stiff | possibly, depending on $\beta$ |
4341
% +---------------------+-----------------------------------------+
4442
%
4543
% Example
4644
% -------
47-
% >>> problem = otp.ascherlineardae.presets.Canonical(0.1);
48-
% >>> sol = problem.solve('MaxStep',1e-5);
49-
% >>> problem.plotPhaseSpace(sol);
45+
% >>> problem = otp.ascherlineardae.presets.Canonical('Beta', 50);
46+
% >>> t = linspace(0,1,100);
47+
% >>> sol = problem.solveExcatly(t);
48+
% >>> problem.plot(sol);
5049

5150
properties (Access = private, Constant)
5251
NumComps = 2
@@ -65,11 +64,6 @@
6564
% The initial conditions.
6665
% parameters : AscherLinearDAEParameters
6766
% The parameters.
68-
%
69-
% Returns
70-
% -------
71-
% obj : AscherLinearDAEProblem
72-
% The constructed problem.
7367
obj@otp.Problem('Ascher Linear DAE', 2, timeSpan, y0, parameters);
7468
end
7569
end
@@ -85,7 +79,8 @@ function onSettingsChanged(obj)
8579
'MassSingular', 'yes');
8680
end
8781

88-
function y = internalSolveExactly(obj, t)
82+
function sol = internalSolveExactly(obj, t)
83+
sol = [];
8984
beta = obj.Parameters.Beta;
9085
if ~isequal(obj.Y0, [1; beta])
9186
error('OTP:noExactSolution', ...
@@ -94,6 +89,8 @@ function onSettingsChanged(obj)
9489

9590
y = [t .* sin(t) + (1 + beta * t) .* exp(-t); ...
9691
beta * exp(-t) + sin(t)];
92+
sol.x = t;
93+
sol.y = y;
9794
end
9895

9996
function sol = internalSolve(obj, varargin)

0 commit comments

Comments
 (0)