Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/structure/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ TODO
:maxdepth: 1
:glob:

*
problem
rhs
parameters
6 changes: 6 additions & 0 deletions docs/structure/parameters.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Parameters
================================================================================

.. automodule:: +otp
.. autoclass:: Parameters
:members:
11 changes: 2 additions & 9 deletions toolbox/+otp/+ascherlineardae/+presets/Canonical.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,8 @@
%
% - ``Beta`` – Value of $β$.

p = inputParser;
p.addParameter('beta', 1);
p.parse(varargin{:});
opts = p.Results;

params = otp.ascherlineardae.AscherLinearDAEParameters;
params.Beta = opts.beta;

y0 = [1; params.Beta];
params = otp.ascherlineardae.AscherLinearDAEParameters('Beta', 1, varargin{:});
y0 = [1; params.Beta];
tspan = [0.0; 1.0];

obj = obj@otp.ascherlineardae.AscherLinearDAEProblem(tspan, y0, params);
Expand Down
6 changes: 2 additions & 4 deletions toolbox/+otp/+ascherlineardae/+presets/Petzold.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
function obj = Petzold
% Create the Petzold example of the Ascher linear DAE problem object.

params = otp.ascherlineardae.AscherLinearDAEParameters;
params.Beta = 0;

y0 = [1; params.Beta];
params = otp.ascherlineardae.AscherLinearDAEParameters('Beta', 0);
y0 = [1; params.Beta];
tspan = [0.0; 1.0];

obj = obj@otp.ascherlineardae.AscherLinearDAEProblem(tspan, y0, params);
Expand Down
7 changes: 3 additions & 4 deletions toolbox/+otp/+ascherlineardae/+presets/Stiff.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
methods
function obj = Stiff
% Create the stiff example of the Ascher linear DAE problem object.
params = otp.ascherlineardae.AscherLinearDAEParameters;
params.Beta = 100;

y0 = [1; params.Beta];

params = otp.ascherlineardae.AscherLinearDAEParameters('Beta', 100);
y0 = [1; params.Beta];
tspan = [0.0; 1.0];

obj = obj@otp.ascherlineardae.AscherLinearDAEProblem(tspan, y0, params);
Expand Down
16 changes: 15 additions & 1 deletion toolbox/+otp/+ascherlineardae/AscherLinearDAEParameters.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
classdef AscherLinearDAEParameters
classdef AscherLinearDAEParameters < otp.Parameters
% Parameters for Ascher Linear DAE problem
properties
% A scalar parameter $β$ in the linear model. It affects the stifness of the problem.
Beta %MATLAB ONLY: (1,1) {mustBeNumeric} = 1
end

methods
function obj = AscherLinearDAEParameters(varargin)
% Create a Ascher Linear DAE parameters object.
%
% Parameters
% ----------
% varargin
% A variable number of name-value pairs. A name can be any property of this class, and the subsequent
% value initializes that property.

obj = obj@otp.Parameters(varargin{:});
end
end
end
25 changes: 11 additions & 14 deletions toolbox/+otp/+cusp/+presets/Canonical.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
% b_i(0) &= 2 \sin\left( \frac{2 i \pi}{N} \right), \\
% $$
%
% for $i = 1, \dots, N$. The parameters are $\varepsilon = 10^{-4}$ and $\sigma = \frac{1}{144}$.
% for $i = 1, \dots, N$. The parameters are $ε = 10^{-4}$ and $σ = \frac{1}{144}$.

methods
function obj = Canonical(varargin)
Expand All @@ -20,8 +20,8 @@
% A variable number of name-value pairs. The accepted names are
%
% - ``N`` – The number of cells in the spatial discretization.
% - ``epsilon`` – Value of $\varepsilon$.
% - ``sigma`` – Value of $\sigma$.
% - ``epsilon`` – Value of $ε$.
% - ``sigma`` – Value of $σ$.
%
% Returns
% -------
Expand All @@ -30,22 +30,19 @@

p = inputParser;
p.addParameter('N', 32);
p.addParameter('epsilon', 1e-4);
p.addParameter('sigma', 1/144);
p.parse(varargin{:});
opts = p.Results;
n = p.Results.N;

params = otp.cusp.CUSPParameters;
params.Epsilon = opts.epsilon;
params.Sigma = opts.sigma;

ang = 2 * pi / opts.N * (1:opts.N).';
y0 = zeros(opts.N, 1);
a0 = -2*cos(ang);
b0 = 2*sin(ang);
ang = 2 * pi * (1:n).' / n;
y0 = zeros(n, 1);
a0 = -2 * cos(ang);
b0 = 2 * sin(ang);

u0 = [y0; a0; b0];
tspan = [0; 1.1];

unmatched = namedargs2cell(p.Unmatched);
params = otp.cusp.CUSPParameters('Epsilon', 1e-4, 'Sigma', 1/144, unmatched{:});

obj = obj@otp.cusp.CUSPProblem(tspan, u0, params);
end
Expand Down
20 changes: 17 additions & 3 deletions toolbox/+otp/+cusp/CUSPParameters.m
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
classdef CUSPParameters
classdef CUSPParameters < otp.Parameters
% Parameters for the CUSP problem.
properties
% The stiffness parameter $\varepsilon$ for the "cusp catastrophe" model.
% The stiffness parameter $ε$ for the "cusp catastrophe" model.
Epsilon %MATLAB ONLY: (1,1) {mustBeNumeric}

% The diffusion coefficient $\sigma$ for all three variables.
% The diffusion coefficient $σ$ for all three variables.
Sigma %MATLAB ONLY: (1,1) {mustBeNumeric}
end

methods
function obj = CUSPParameters(varargin)
% Create a CUSP parameters object.
%
% Parameters
% ----------
% varargin
% A variable number of name-value pairs. A name can be any property of this class, and the subsequent
% value initializes that property.

obj = obj@otp.Parameters(varargin{:});
end
end
end

31 changes: 15 additions & 16 deletions toolbox/+otp/+cusp/CUSPProblem.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,32 @@
% The CUSP problem :cite:p:`HW96` (pp. 147-148) is the PDE
%
% $$
% \frac{\partial y}{\partial t} &= -\frac{1}{\varepsilon} (y^3 + a y + b)
% + \sigma \frac{\partial^2 y}{\partial x^2}, \\
% \frac{\partial a}{\partial t} &= b + 0.07 v + \sigma \frac{\partial^2 a}{\partial x^2}, \\
% \frac{\partial b}{\partial t} &= (1 - a^2) b - a - 0.4 y + 0.035 v + \sigma \frac{\partial^2 b}{\partial x^2},
% \frac{\partial y}{\partial t} &= -\frac{1}{ε} (y^3 + a y + b) + σ \frac{\partial^2 y}{\partial x^2}, \\
% \frac{\partial a}{\partial t} &= b + 0.07 v + σ \frac{\partial^2 a}{\partial x^2}, \\
% \frac{\partial b}{\partial t} &= (1 - a^2) b - a - 0.4 y + 0.035 v + σ \frac{\partial^2 b}{\partial x^2},
% $$
%
%
% where $v = u / (u + 0.1)$ and $u = (y - 0.7)(y - 1.3)$. The spatial domain $x \in [0, 1]$ has period boundary
% conditions. Discretization with second order finite difference on a grid with $N$ cells gives
%
% $$
% y'_i &= -\frac{1}{\varepsilon} (y_i^3 + a_i y_i + b_i) + \sigma N^2 (y_{i-1} - 2 y_i + y_{i+1}) \\
% a'_i &= b_i + 0.07 v_i + \sigma N^2 (a_{i-1} - 2 a_i + a_{i+1}) \\
% b'_i &= (1 - a_i^2) b_i - a_i - 0.4 y_i + 0.035 v_i + \sigma N^2 (b_{i-1} - 2 b_i + b_{i+1}),
% y'_i &= -\frac{1}{ε} (y_i^3 + a_i y_i + b_i) + σ N^2 (y_{i-1} - 2 y_i + y_{i+1}) \\
% a'_i &= b_i + 0.07 v_i + σ N^2 (a_{i-1} - 2 a_i + a_{i+1}) \\
% b'_i &= (1 - a_i^2) b_i - a_i - 0.4 y_i + 0.035 v_i + σ N^2 (b_{i-1} - 2 b_i + b_{i+1}),
% $$
%
% where $i = 1, \dots, N$. Values at cell indices $i=0, N+1$ are specificied by the periodic boundary conditions.
%
% Notes
% -----
% +---------------------+----------------------------------------------------------------------------+
% | Type | PDE |
% +---------------------+----------------------------------------------------------------------------+
% | Number of Variables | arbitrary multiple of 3 |
% +---------------------+----------------------------------------------------------------------------+
% | Stiff | typically, depending on $\varepsilon$, $\sigma$, and number of grid points |
% +---------------------+----------------------------------------------------------------------------+
% +---------------------+-------------------------------------------------------------+
% | Type | PDE |
% +---------------------+-------------------------------------------------------------+
% | Number of Variables | arbitrary multiple of 3 |
% +---------------------+-------------------------------------------------------------+
% | Stiff | typically, depending on $ε$, $σ$, and number of grid points |
% +---------------------+-------------------------------------------------------------+
%
% Example
% -------
Expand All @@ -44,7 +43,7 @@
end

properties (SetAccess = private)
% Right-hand side containing the diffusion terms and the reaction terms multiplied by $\varepsilon^{-1}$.
% Right-hand side containing the diffusion terms and the reaction terms multiplied by $ε^{-1}$.
%
% This partition of the RHS is used in :cite:p:`JM17`.
%
Expand All @@ -53,7 +52,7 @@
% RHSNonstiff
RHSStiff

% Right-hand side containing the reaction terms not scaled by $\varepsilon^{-1}$.
% Right-hand side containing the reaction terms not scaled by $ε^{-1}$.
%
% This partition of the RHS is used in :cite:p:`JM17`.
%
Expand Down
15 changes: 1 addition & 14 deletions toolbox/+otp/+lorenz63/+presets/Canonical.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,10 @@
% - ``sigma`` – Value of $σ$.
% - ``rho`` – Value of $ρ$.
% - ``beta`` – Value of $β$.
%

p = inputParser;
p.addParameter('sigma', 10);
p.addParameter('rho', 28);
p.addParameter('beta', 8/3);
p.parse(varargin{:});
opts = p.Results;

params = otp.lorenz63.Lorenz63Parameters;

params.Sigma = opts.sigma;
params.Rho = opts.rho;
params.Beta = opts.beta;

y0 = [0; 1; 0];
tspan = [0 60];
params = otp.lorenz63.Lorenz63Parameters('Sigma', 10, 'Rho', 28, 'Beta', 8/3, varargin{:});

obj = obj@otp.lorenz63.Lorenz63Problem(tspan, y0, params);
end
Expand Down
11 changes: 1 addition & 10 deletions toolbox/+otp/+lorenz63/+presets/LimitCycle.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,13 @@
methods
function obj = LimitCycle
% Create the LimitCycle Lorenz '63 problem object.
%

sigma = 10;
rho = 350;
beta = 8/3;

params = otp.lorenz63.Lorenz63Parameters;
params.Sigma = sigma;
params.Rho = rho;
params.Beta = beta;

% We use Lorenz's initial conditions and timespan as Strogatz
% does not specify those in his book.

y0 = [0; 1; 0];
tspan = [0 60];
params = otp.lorenz63.Lorenz63Parameters('Sigma', 10, 'Rho', 350, 'Beta', 8/3);

obj = obj@otp.lorenz63.Lorenz63Problem(tspan, y0, params);
end
Expand Down
12 changes: 1 addition & 11 deletions toolbox/+otp/+lorenz63/+presets/Surprise.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,11 @@
methods
function obj = Surprise
% Create the Surprise Lorenz '63 problem object.
%

sigma = 10;
rho = 100;
beta = 8/3;

params = otp.lorenz63.Lorenz63Parameters;
params.Sigma = sigma;
params.Rho = rho;
params.Beta = beta;

% Hand-picked initial conditions with the canonical timespan

y0 = [2; 1; 1];
tspan = [0 60];
params = otp.lorenz63.Lorenz63Parameters('Sigma', 10, 'Rho', 100, 'Beta', 8/3);

obj = obj@otp.lorenz63.Lorenz63Problem(tspan, y0, params);
end
Expand Down
16 changes: 15 additions & 1 deletion toolbox/+otp/+lorenz63/Lorenz63Parameters.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
classdef Lorenz63Parameters
classdef Lorenz63Parameters < otp.Parameters
% Parameters for the Lorenz '63 problem.

properties
Expand All @@ -11,4 +11,18 @@
% A geometric factor.
Beta %MATLAB ONLY: (1, 1) {mustBeReal, mustBeFinite}
end

methods
function obj = Lorenz63Parameters(varargin)
% Create a Lorenz '63 parameters object.
%
% Parameters
% ----------
% varargin
% A variable number of name-value pairs. A name can be any property of this class, and the subsequent
% value initializes that property.

obj = obj@otp.Parameters(varargin{:});
end
end
end
19 changes: 6 additions & 13 deletions toolbox/+otp/+lorenz96/+presets/Canonical.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,24 @@
% varargin
% A variable number of name-value pairs. The accepted names are
%
% - ``Size`` – The size of the problem as a positive integer.
% - ``N`` – The size of the problem as a positive integer.
% - ``Forcing`` – The forcing as a scalar, vector of N constants, or as a function.
%

p = inputParser;
p.addParameter('Size', 40, @isscalar);
p.addParameter('Forcing', 8);

p.addParameter('N', 40);
p.parse(varargin{:});

s = p.Results;

n = s.Size;

params = otp.lorenz96.Lorenz96Parameters;
params.F = s.Forcing;
n = p.Results.N;

% We initialise the Lorenz96 model as in (Lorenz & Emanuel 1998)

y0 = 8*ones(n, 1);

y0(floor(n/2)) = 8.008;

% roughly ten years in system time
tspan = [0, 720];

unmatched = namedargs2cell(p.Unmatched);
params = otp.lorenz96.Lorenz96Parameters('F', 8, unmatched{:});

obj = obj@otp.lorenz96.Lorenz96Problem(tspan, y0, params);

Expand Down
16 changes: 15 additions & 1 deletion toolbox/+otp/+lorenz96/Lorenz96Parameters.m
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
classdef Lorenz96Parameters
classdef Lorenz96Parameters < otp.Parameters
% Parameters for the Lorenz '96 problem.

properties
% A forcing function, scalar, or vector.
F %MATLAB ONLY: {mustBeA(F, {'numeric','function_handle'})}
end

methods
function obj = Lorenz96Parameters(varargin)
% Create a Lorenz '96 parameters object.
%
% Parameters
% ----------
% varargin
% A variable number of name-value pairs. A name can be any property of this class, and the subsequent
% value initializes that property.

obj = obj@otp.Parameters(varargin{:});
end
end
end
Loading