Skip to content

Commit 28eadcb

Browse files
Set superclass for all parameters (#126)
* Make all parameters subclass otp.Parameters * Fix typos * Enforce naming conventions * Make all presets use varargin * Fix errors and warnings
1 parent 0701558 commit 28eadcb

93 files changed

Lines changed: 801 additions & 662 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

tests/+problemtests/validateqg.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
fprintf(' Testing Quasi-Geostrophic Equations\n');
44

5-
model = otp.quasigeostrophic.presets.PopovMouIliescuSandu('size', [16, 32]);
5+
model = otp.quasigeostrophic.presets.PopovMouIliescuSandu('Nx', 16, 'Ny', 32);
66
model.TimeSpan = [0, 0.109];
77

88
[~] = otp.utils.Solver.Nonstiff(model.RHSADLES.F, model.TimeSpan, model.Y0);

tests/getpresets.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
presetclass = sprintf('otp.%s.presets.%s', problemname, presetname);
3232

3333
if strcmp(problemname, 'quasigeostrophic')
34-
presetclass = sprintf('%s%s', presetclass, "('size', [16, 32])");
34+
presetclass = sprintf('%s%s', presetclass, "('Nx', 16, 'Ny', 32)");
3535
end
3636

3737
if strcmp(problemname, 'allencahn')
38-
presetclass = sprintf('%s%s', presetclass, "('size', 16)");
38+
presetclass = sprintf('%s%s', presetclass, "('Size', 16)");
3939
end
4040

4141
end

tests/validateallderivatives.m

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
fprintf('\n Validating all model and preset derivatives \n\n');
44

5-
fprintf([' Model | Preset |' ...
6-
' Jacobian | JVP | JAVP \n']);
7-
fprintf([repmat('-', 1, 85) '\n']);
5+
fprintf(' Model | Preset | Jacobian | JVP | JAVP \n');
6+
fprintf([repmat('-', 1, 88) '\n']);
87

98
presets = getpresets();
109

@@ -14,7 +13,7 @@
1413
presetname = preset.name;
1514
presetclass = preset.presetclass;
1615

17-
fprintf(' %-20s | %-20s | ', ...
16+
fprintf(' %-23s | %-20s | ', ...
1817
problemname, ...
1918
presetname);
2019

tests/validateallplots.m

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ function validateallplots(testplots, testmovies)
1010

1111
fprintf('\n Validating all model and preset plots and movies \n\n');
1212

13-
fprintf([' Model | Preset |' ...
14-
' Plot | Phase | Movie\n']);
15-
fprintf([repmat('-', 1, 85) '\n']);
13+
fprintf(' Model | Preset | Plot | Phase | Movie\n');
14+
fprintf([repmat('-', 1, 88) '\n']);
1615

1716
presets = getpresets();
1817

@@ -22,7 +21,7 @@ function validateallplots(testplots, testmovies)
2221
presetname = preset.name;
2322
presetclass = preset.presetclass;
2423

25-
fprintf(' %-20s | %-20s | ', ...
24+
fprintf(' %-23s | %-20s | ', ...
2625
problemname, ...
2726
presetname);
2827

tests/validateallpresets.m

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
function validateallpresets
22

33
fprintf('\n Validating all presets and RHS \n\n');
4-
fprintf([' Model | Preset |' ...
5-
' Build | Solve \n']);
6-
fprintf([repmat('-', 1, 61) '\n']);
4+
fprintf(' Model | Preset | Build | Solve \n');
5+
fprintf([repmat('-', 1, 64) '\n']);
76

87
presets = getpresets();
98

@@ -13,7 +12,7 @@
1312
presetname = preset.name;
1413
presetclass = preset.presetclass;
1514

16-
fprintf(' %-20s | %-20s | ', ...
15+
fprintf(' %-23s | %-20s | ', ...
1716
problemname, ...
1817
presetname);
1918

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

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,13 @@
33

44
methods
55
function obj = Canonical(varargin)
6+
params = otp.allencahn.AllenCahnParameters('Size', 64, 'Alpha', 0.1, 'Beta', 1, 'Forcing', 0, varargin{:});
67

7-
p = inputParser;
8-
p.addParameter('Size', 64);
9-
p.addParameter('alpha', 0.1);
10-
p.addParameter('beta', 1);
11-
12-
p.parse(varargin{:});
13-
14-
s = p.Results;
15-
16-
n = s.Size;
17-
18-
19-
params = otp.allencahn.AllenCahnParameters;
20-
params.Size = n;
21-
params.Alpha = s.alpha;
22-
params.Beta = s.beta;
23-
params.Forcing = 0;
24-
25-
x = linspace(0, 1, n);
8+
x = linspace(0, 1, params.Size);
269
[xs, ys] = meshgrid(x, x);
2710

28-
u0 = reshape(0.4 + 0.1*(xs + ys) + 0.1*sin(10*xs)*sin(20*ys), n^2, 1);
29-
11+
u0 = reshape(0.4 + 0.1*(xs + ys) + 0.1*sin(10*xs)*sin(20*ys), [], 1);
3012
tspan = [0, 0.2];
31-
3213
obj = obj@otp.allencahn.AllenCahnProblem(tspan, u0, params);
3314
end
3415
end
Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
1-
classdef AllenCahnParameters
2-
%ALLENCAHNPARAMETERS User-configurable parameters for the Allen-Cahn Problem
3-
%
4-
% See also otp.allencahn.AllenCahnProblem
1+
classdef AllenCahnParameters < otp.Parameters
2+
% Parameters for the Allen–Cahn problem.
53

64
properties
75
%Size is the dimension of the problem
8-
Size %MATLAB ONLY: (1,1) {mustBeInteger}
6+
Size %MATLAB ONLY: (1,1) {mustBeInteger, mustBePositive} = 1
7+
98
%Alpha is non-negative diffusion constant
10-
Alpha %MATLAB ONLY: (1,1) {mustBeNonnegative}
9+
Alpha %MATLAB ONLY: (1,1) {otp.utils.validation.mustBeNumerical}
10+
1111
%Beta is a non-negative reaction constant
12-
Beta %MATLAB ONLY: (1,1) {mustBeNonnegative}
12+
Beta %MATLAB ONLY: (1,1) {otp.utils.validation.mustBeNumerical}
13+
1314
%Forcing is a forcing function or constant
1415
Forcing %MATLAB ONLY: {mustBeA(Forcing, {'numeric', 'function_handle'})}
1516
end
17+
18+
methods
19+
function obj = AllenCahnParameters(varargin)
20+
% Create an Allen–Cahn parameters object.
21+
%
22+
% Parameters
23+
% ----------
24+
% varargin
25+
% A variable number of name-value pairs. A name can be any property of this class, and the subsequent
26+
% value initializes that property.
27+
28+
obj = obj@otp.Parameters(varargin{:});
29+
end
30+
end
1631
end

toolbox/+otp/+allencahn/AllenCahnProblem.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
methods
55
function obj = AllenCahnProblem(timeSpan, y0, parameters)
6-
obj@otp.Problem('Allen-Cahn', [], timeSpan, y0, parameters);
6+
obj@otp.Problem('AllenCahn', [], timeSpan, y0, parameters);
77
end
88
end
99

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,16 @@
88
% See also otp.arenstorf.ArenstorfProblem
99

1010
methods
11-
function obj = Canonical(mu)
11+
function obj = Canonical(varargin)
1212
%CANONICAL Construct a canonical Arenstorf problem
1313
% OBJ = CANONICAL(MU) Uses a Moon of mass MU. The time span and
1414
% initial conditions use the same data type as MU. Single
1515
% precision, vpa, and other types are supported.
1616
%
1717
% OBJ = CANONICAL() Uses a MU corresponding to the Moon
18-
19-
if nargin < 1
20-
mu = 0.012277471;
21-
end
22-
23-
params = otp.arenstorf.ArenstorfParameters;
24-
params.Mu = mu;
2518

26-
cls = class(mu);
19+
params = otp.arenstorf.ArenstorfParameters('Mu', 0.012277471, varargin{:});
20+
cls = class(params.Mu);
2721

2822
% Decimals converted to rational to support multiple data types
2923
y0 = [cast(497, cls) / cast(500, cls); ...
Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
1-
classdef ArenstorfParameters
2-
%ARENSTORFPARAMETERS User-configurable parameters for the Arenstorf problem
3-
%
4-
% See also otp.arenstorf.ArenstorfProblem
1+
classdef ArenstorfParameters < otp.Parameters
2+
% Parameters for the Arenstorf problem.
53

64
properties
7-
%MU The mass of one body, while the other body has mass MU'=1-Mu
8-
Mu %MATLAB ONLY: (1, 1) {mustBeReal, mustBeFinite}
5+
% The mass of one body, while the other body has mass $\mu' = 1 - \mu$.
6+
Mu %MATLAB ONLY: (1, 1) {otp.utils.validation.mustBeNumerical}
7+
end
8+
9+
methods
10+
function obj = ArenstorfParameters(varargin)
11+
% Create an Arenstorf parameters object.
12+
%
13+
% Parameters
14+
% ----------
15+
% varargin
16+
% A variable number of name-value pairs. A name can be any property of this class, and the subsequent
17+
% value initializes that property.
18+
19+
obj = obj@otp.Parameters(varargin{:});
20+
end
921
end
1022
end

0 commit comments

Comments
 (0)