Commit 1d3f5e37 authored by Ferdinand Fischer's avatar Ferdinand Fischer
Browse files

Changed constructor of quantity.Domain to use obligatory arguments

parent 97d997c1
...@@ -250,7 +250,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi ...@@ -250,7 +250,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi
deltaCOD = diff(d); deltaCOD = diff(d);
assert(misc.alln(deltaCOD >= 0), 'The domain for the composition f(g(.)) must be monotonically increasing'); assert(misc.alln(deltaCOD >= 0), 'The domain for the composition f(g(.)) must be monotonically increasing');
d = quantity.Domain('grid', d, 'name', domainName); d = quantity.Domain(domainName, d);
end end
function obj_hat = compose(obj, g, optionalArgs) function obj_hat = compose(obj, g, optionalArgs)
...@@ -373,7 +373,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi ...@@ -373,7 +373,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi
end end
for k = 1:length(newGrid) for k = 1:length(newGrid)
myDomain(k) = quantity.Domain('grid', newGrid{k}, 'name', gridNames{k}); myDomain(k) = quantity.Domain(gridNames{k}, newGrid{k});
end end
end end
elseif nargin == 3 elseif nargin == 3
...@@ -391,7 +391,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi ...@@ -391,7 +391,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi
newGrid = myDomain; newGrid = myDomain;
myDomain = quantity.Domain.empty(); myDomain = quantity.Domain.empty();
for k = 1:length(newGrid) for k = 1:length(newGrid)
myDomain(k) = quantity.Domain('grid', newGrid{k}, 'name', gridNames{k}); myDomain(k) = quantity.Domain(gridNames{k}, newGrid{k});
end end
else else
myDomain = obj(1).domain; myDomain = obj(1).domain;
...@@ -1297,19 +1297,22 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi ...@@ -1297,19 +1297,22 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi
end end
if obj(1).isConstant if obj(1).isConstant
newDomain(1:length( gridNew )) = quantity.Domain();
for i = 1 : length(gridNew) for i = 1 : length(gridNew)
newDomain(i) = quantity.Domain(... newDomain(i) = ...
'grid', gridNew{i}, 'name', gridNameNew{i}); quantity.Domain(gridNameNew{i}, gridNew{i});
end end
else else
[gridIndexNew, logIdx] = obj(1).domain.gridIndex(gridNameNew); gridIndexNew = obj(1).domain.gridIndex(gridNameNew);
newDomain = obj(1).domain; newDomain = obj(1).domain;
for i = 1 : length(gridIndexNew) for i = 1 : length(gridIndexNew)
newDomain(gridIndexNew(i)) = quantity.Domain(... newDomain(gridIndexNew(i)) = ...
'grid', gridNew{i}, 'name', gridNameNew{i}); quantity.Domain(gridNameNew{i}, gridNew{i});
end end
assert(isequal({newDomain.name}, obj(1).gridName), 'rearranging grids failed'); assert(isequal({newDomain.name}, obj(1).gridName), ...
'rearranging grids failed');
end end
...@@ -1394,8 +1397,8 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi ...@@ -1394,8 +1397,8 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi
assert(numel(myGrid) > 1, 'If the state transition matrix is computed for constant values, a spatial domain has to be defined!') assert(numel(myGrid) > 1, 'If the state transition matrix is computed for constant values, a spatial domain has to be defined!')
myDomain = [quantity.Domain('grid', myGrid, 'name', gridName1), ... myDomain = [quantity.Domain(gridName1, myGrid), ...
quantity.Domain('grid', myGrid, 'name', gridName2)]; quantity.Domain(gridName2, myGrid)];
if obj.isConstant if obj.isConstant
% for a constant system matrix, the matrix exponential % for a constant system matrix, the matrix exponential
...@@ -1952,8 +1955,8 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi ...@@ -1952,8 +1955,8 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi
if all(isGrid) if all(isGrid)
newDomain = quantity.Domain(); newDomain = quantity.Domain();
else else
newDomain = quantity.Domain('grid', obj(kObj).grid{~isGrid}, ... newDomain = quantity.Domain(obj(kObj).gridName{~isGrid}, ...
'name', obj(kObj).gridName{~isGrid}); obj(kObj).grid{~isGrid});
end end
[I.domain] = deal(newDomain); [I.domain] = deal(newDomain);
......
...@@ -5,12 +5,13 @@ classdef Domain < handle & matlab.mixin.CustomDisplay ...@@ -5,12 +5,13 @@ classdef Domain < handle & matlab.mixin.CustomDisplay
% * EquidistantDomain % * EquidistantDomain
% * multi dimensional % * multi dimensional
properties properties (SetAccess = protected)
% The discrete points of the grid for the evaluation of a % The discrete points of the grid for the evaluation of a
% continuous quantity. For an example, the function f(x) should be % continuous quantity. For an example, the function f(x) should be
% considered on the domain x \in X = [0, 1]. Then, a grid can be % considered on the domain x \in X = [0, 1]. Then, a grid can be
% generated by X_grid = linspace(0, 1). % generated by X_grid = linspace(0, 1).
grid double {mustBeReal}; grid double {mustBeReal, mustBeFinite, mustBe.ascending};
% TODO add mustBeVector
% a speaking name for this domain; Should be unique, so that the % a speaking name for this domain; Should be unique, so that the
% domain can be identified by the name. % domain can be identified by the name.
...@@ -28,21 +29,12 @@ classdef Domain < handle & matlab.mixin.CustomDisplay ...@@ -28,21 +29,12 @@ classdef Domain < handle & matlab.mixin.CustomDisplay
end end
methods methods
function obj = Domain(varargin) function obj = Domain(name, grid)
%DOMAIN initialize the domain %DOMAIN initialize the domain
% %
if nargin >= 1 if nargin >= 1
myParser = misc.Parser(); obj.grid = grid(:);
myParser.addParameter('grid', [], @(g) isvector(g) || isempty(g)); obj.name = name;
myParser.addParameter('name', '', @ischar);
myParser.parse(varargin{:});
% todo: assertions
% * ascending ?
obj.grid = myParser.Results.grid(:);
obj.name = myParser.Results.name;
myParser.unmatchedWarning();
end end
end end
...@@ -284,10 +276,10 @@ classdef Domain < handle & matlab.mixin.CustomDisplay ...@@ -284,10 +276,10 @@ classdef Domain < handle & matlab.mixin.CustomDisplay
% sort the grid entries % sort the grid entries
myGrids = {obj.grid}; myGrids = {obj.grid};
myGrids = myGrids(I); myGrids = myGrids(I);
newObj(1:length(myGrids)) = quantity.Domain();
for k = 1:length(myGrids) for k = 1:length(myGrids)
newObj(k) = quantity.Domain('grid', myGrids{k}, ... newObj(k) = quantity.Domain(sortedNames{k}, myGrids{k});
'name', sortedNames{k}); %#ok<AGROW>
end end
else else
newObj = obj; newObj = obj;
...@@ -339,7 +331,7 @@ classdef Domain < handle & matlab.mixin.CustomDisplay ...@@ -339,7 +331,7 @@ classdef Domain < handle & matlab.mixin.CustomDisplay
d = quantity.Domain.empty(); d = quantity.Domain.empty();
for k = 1:length(grids) for k = 1:length(grids)
d = [d quantity.Domain('grid', grids{k}, 'name', gridNames{k})]; d = [d quantity.Domain(gridNames{k}, grids{k})];
end end
end end
...@@ -363,11 +355,11 @@ classdef Domain < handle & matlab.mixin.CustomDisplay ...@@ -363,11 +355,11 @@ classdef Domain < handle & matlab.mixin.CustomDisplay
O = ones(o); O = ones(o);
O(:) = linspace(0, 1, gridSize(k)); O(:) = linspace(0, 1, gridSize(k));
g(k) = quantity.Domain('grid', O, 'name', name{k}); g(k) = quantity.Domain(name{k}, O);
end end
end end
function [myDomain, unmatched]= parser(varargin) function [myDomain, unmatched] = parser(varargin)
%% domain parser %% domain parser
domainParser = misc.Parser(); domainParser = misc.Parser();
domainParser.addParameter('domain', {}, @(g) isa(g, 'quantity.Domain')); domainParser.addParameter('domain', {}, @(g) isa(g, 'quantity.Domain'));
...@@ -394,8 +386,7 @@ classdef Domain < handle & matlab.mixin.CustomDisplay ...@@ -394,8 +386,7 @@ classdef Domain < handle & matlab.mixin.CustomDisplay
% initialize the domain objects % initialize the domain objects
myDomain = quantity.Domain.empty(); myDomain = quantity.Domain.empty();
for k = 1:numel(myGrid) for k = 1:numel(myGrid)
myDomain(k) = quantity.Domain('grid', myGrid{k}, ... myDomain(k) = quantity.Domain(myGridName{k}, myGrid{k});
'name', myGridName{k});
end end
else else
% else case: the domains are specified as domain % else case: the domains are specified as domain
......
...@@ -6,7 +6,7 @@ end ...@@ -6,7 +6,7 @@ end
function testCompose(testCase) function testCompose(testCase)
t = quantity.Domain('grid', linspace(0, 2), 'name', 't'); t = quantity.Domain('t', linspace(0, 2));
f = quantity.Discrete(sin(t.grid * 2 * pi) , 'domain', t, 'name', 'f' ); f = quantity.Discrete(sin(t.grid * 2 * pi) , 'domain', t, 'name', 'f' );
g = quantity.Discrete( 0.5 * t.grid, 'domain', t, 'name', 'g'); g = quantity.Discrete( 0.5 * t.grid, 'domain', t, 'name', 'g');
h = quantity.Discrete( 2 * t.grid, 'domain', t, 'name', 'h'); h = quantity.Discrete( 2 * t.grid, 'domain', t, 'name', 'h');
...@@ -19,8 +19,8 @@ testCase.verifyWarning(@()f.compose(h), 'quantity:Discrete:compose') ...@@ -19,8 +19,8 @@ testCase.verifyWarning(@()f.compose(h), 'quantity:Discrete:compose')
% verify f(tau) = sin( tau * 2pi ); g(z, t) = t + z^2 % verify f(tau) = sin( tau * 2pi ); g(z, t) = t + z^2
% f( g(z, t ) ) = sin( (t + z^2 ) * 2pi ) % f( g(z, t ) ) = sin( (t + z^2 ) * 2pi )
tau = quantity.Domain('grid', linspace(-1, 3), 'name', 'tau' ); tau = quantity.Domain('tau', linspace(-1, 3));
z = quantity.Domain('grid', linspace(0, 1, 51), 'name', 'z'); z = quantity.Domain('z', linspace(0, 1, 51));
f = quantity.Discrete( sin( tau.grid * 2 * pi ), 'domain', tau ); f = quantity.Discrete( sin( tau.grid * 2 * pi ), 'domain', tau );
g = quantity.Discrete( ( z.grid.^2 ) + t.grid', 'domain', [z, t] ); g = quantity.Discrete( ( z.grid.^2 ) + t.grid', 'domain', [z, t] );
...@@ -35,9 +35,9 @@ testCase.verifyEqual(fg.on, F.on, 'AbsTol', 1e-2) ...@@ -35,9 +35,9 @@ testCase.verifyEqual(fg.on, F.on, 'AbsTol', 1e-2)
% g(z, t) = z + t % g(z, t) = z + t
% f(z, g(z,t) ) = 2*z + t % f(z, g(z,t) ) = 2*z + t
z = quantity.Domain('grid', linspace(0, 1, 11), 'name', 'z'); z = quantity.Domain('z', linspace(0, 1, 11));
t = quantity.Domain('grid', linspace(0, 1, 21), 'name', 't'); t = quantity.Domain('t', linspace(0, 1, 21));
tau = quantity.Domain('grid', linspace(0, 2, 31), 'name', 'tau'); tau = quantity.Domain('tau', linspace(0, 2, 31));
f = quantity.Discrete( z.grid + tau.grid', 'domain', [z, tau]); f = quantity.Discrete( z.grid + tau.grid', 'domain', [z, tau]);
g = quantity.Discrete( z.grid + t.grid', 'domain', [z, t]); g = quantity.Discrete( z.grid + t.grid', 'domain', [z, t]);
...@@ -71,8 +71,8 @@ end % testQuadraticNorm() ...@@ -71,8 +71,8 @@ end % testQuadraticNorm()
function testSort(tc) function testSort(tc)
t = linspace(0, pi, 7)'; t = linspace(0, pi, 7)';
domA = quantity.Domain('grid', t, 'name', 'a'); domA = quantity.Domain('a', t);
domB = quantity.Domain('grid', t, 'name', 'b'); domB = quantity.Domain('b', t);
q = quantity.Discrete(sin(t) .* cos(t'), ... q = quantity.Discrete(sin(t) .* cos(t'), ...
'domain', [domA, domB]); 'domain', [domA, domB]);
...@@ -91,8 +91,8 @@ function testBlkdiag(tc) ...@@ -91,8 +91,8 @@ function testBlkdiag(tc)
% init some data % init some data
syms z zeta syms z zeta
z = quantity.Domain('grid', linspace(0, 1, 21), 'name', 'z'); z = quantity.Domain('z', linspace(0, 1, 21));
zeta = quantity.Domain('grid', linspace(0, 1, 41), 'name', 'zeta'); zeta = quantity.Domain('zeta', linspace(0, 1, 41));
A = quantity.Discrete(cat(4, ... A = quantity.Discrete(cat(4, ...
cat(3, 1 + z.grid .* zeta.grid', - z.ones .* zeta.grid'), ... cat(3, 1 + z.grid .* zeta.grid', - z.ones .* zeta.grid'), ...
...@@ -187,7 +187,7 @@ end % testFlipGrid(); ...@@ -187,7 +187,7 @@ end % testFlipGrid();
function testScalarPlusMinusQuantity(testCase) function testScalarPlusMinusQuantity(testCase)
z = quantity.Domain('grid', linspace(0, 1, 7), 'name', 'z'); z = quantity.Domain('z', linspace(0, 1, 7));
f = quantity.Discrete( ( [2; 1] + zeros(2, 1) .* z.grid' )', ... f = quantity.Discrete( ( [2; 1] + zeros(2, 1) .* z.grid' )', ...
'domain', z); 'domain', z);
...@@ -198,7 +198,7 @@ end % testScalarPlusMinusQuantity ...@@ -198,7 +198,7 @@ end % testScalarPlusMinusQuantity
function testNumericVectorPlusMinusQuantity(testCase) function testNumericVectorPlusMinusQuantity(testCase)
z = quantity.Domain('grid', linspace(0, 1, 7), 'name', 'z'); z = quantity.Domain('z', linspace(0, 1, 7));
f = quantity.Discrete( [1+z.grid, 2+sin(z.grid)] , ... f = quantity.Discrete( [1+z.grid, 2+sin(z.grid)] , ...
'domain', z); 'domain', z);
...@@ -210,8 +210,8 @@ testCase.verifyEqual(on(f+a), f.on()+1); ...@@ -210,8 +210,8 @@ testCase.verifyEqual(on(f+a), f.on()+1);
end % testNumericVectorPlusMinusQuantity end % testNumericVectorPlusMinusQuantity
function testUnitaryPluasAndMinus(testCase) function testUnitaryPluasAndMinus(testCase)
z = quantity.Domain('grid', linspace(0, 1, 7), 'name', 'z'); z = quantity.Domain('z', linspace(0, 1, 7));
zeta = quantity.Domain('grid', linspace(0, 1, 7), 'name', 'zeta'); zeta = quantity.Domain('zeta', linspace(0, 1, 7));
q = quantity.Discrete(cat(4, ... q = quantity.Discrete(cat(4, ...
cat(3, 1 + z.grid .* zeta.grid', - z.grid .* zeta.ones'), ... cat(3, 1 + z.grid .* zeta.grid', - z.grid .* zeta.ones'), ...
...@@ -285,12 +285,12 @@ end ...@@ -285,12 +285,12 @@ end
function testExp(testCase) function testExp(testCase)
% 1 spatial variable % 1 spatial variable
z = quantity.Domain('grid', linspace(0, 1, 3), 'name', 'z'); z = quantity.Domain('z', linspace(0, 1, 3));
s1d = quantity.Discrete(1 + z.grid .* z.grid.', 'domain', z); s1d = quantity.Discrete(1 + z.grid .* z.grid.', 'domain', z);
testCase.verifyEqual(s1d.exp.on(), exp(s1d.on())); testCase.verifyEqual(s1d.exp.on(), exp(s1d.on()));
% diagonal matrix % diagonal matrix
zeta = quantity.Domain('grid', linspace(0, 1, 4), 'name', 'zeta'); zeta = quantity.Domain('zeta', linspace(0, 1, 4));
s2dDiag = quantity.Discrete(cat(4, ... s2dDiag = quantity.Discrete(cat(4, ...
cat(3, 1 + z.grid .* zeta.grid', zeros(z.n, zeta.n)), .... cat(3, 1 + z.grid .* zeta.grid', zeros(z.n, zeta.n)), ....
cat(3, zeros(z.n, zeta.n), z.grid.^2 .* zeta.ones')), 'domain', [z, zeta]); cat(3, zeros(z.n, zeta.n), z.grid.^2 .* zeta.ones')), 'domain', [z, zeta]);
...@@ -300,8 +300,8 @@ end ...@@ -300,8 +300,8 @@ end
function testExpm(testCase) function testExpm(testCase)
z = quantity.Domain('grid', linspace(0, 1, 3), 'name', 'z'); z = quantity.Domain('z', linspace(0, 1, 3));
zeta = quantity.Domain('grid', linspace(0, 1, 4), 'name', 'zeta'); zeta = quantity.Domain('zeta', linspace(0, 1, 4));
mat2d = quantity.Discrete(... mat2d = quantity.Discrete(...
{1 + z.grid .* zeta.grid', 3 * z.ones .* zeta.grid'; ... {1 + z.grid .* zeta.grid', 3 * z.ones .* zeta.grid'; ...
...@@ -382,7 +382,7 @@ end ...@@ -382,7 +382,7 @@ end
function testDiag2Vec(testCase) function testDiag2Vec(testCase)
% quantity.Symbolic % quantity.Symbolic
syms z syms z
do = quantity.Domain('grid', linspace(0,1,3), 'name', 'z'); do = quantity.Domain('z', linspace(0,1,3));
myMatrixSymbolic = quantity.Symbolic([sin(0.5*z*pi)+1, 0; 0, 0.9-z/2], 'domain', do); myMatrixSymbolic = quantity.Symbolic([sin(0.5*z*pi)+1, 0; 0, 0.9-z/2], 'domain', do);
myVectorSymbolic = diag2vec(myMatrixSymbolic); myVectorSymbolic = diag2vec(myMatrixSymbolic);
testCase.verifyEqual(myMatrixSymbolic(1,1).valueContinuous, myVectorSymbolic(1,1).valueContinuous); testCase.verifyEqual(myMatrixSymbolic(1,1).valueContinuous, myVectorSymbolic(1,1).valueContinuous);
...@@ -568,8 +568,8 @@ end ...@@ -568,8 +568,8 @@ end
function testOn(testCase) function testOn(testCase)
% init data % init data
domainVecA = quantity.Domain('grid', linspace(0, 1, 27), 'name', 'z'); domainVecA = quantity.Domain('z', linspace(0, 1, 27));
domainVecB = quantity.Domain('grid', linspace(0, 1, 41), 'name', 'zeta'); domainVecB = quantity.Domain('zeta', linspace(0, 1, 41));
[value] = createTestData(domainVecA.grid, domainVecB.grid); [value] = createTestData(domainVecA.grid, domainVecB.grid);
a = quantity.Discrete(value, 'size', [2, 3], ... a = quantity.Discrete(value, 'size', [2, 3], ...
'domain', [domainVecA, domainVecB], 'name', 'A'); 'domain', [domainVecA, domainVecB], 'name', 'A');
...@@ -581,8 +581,8 @@ testCase.verifyEqual(permute(value, [2, 1, 3, 4]), ... ...@@ -581,8 +581,8 @@ testCase.verifyEqual(permute(value, [2, 1, 3, 4]), ...
testCase.verifyEqual(createTestData(linspace(0, 1, 100), linspace(0, 1, 21)), ... testCase.verifyEqual(createTestData(linspace(0, 1, 100), linspace(0, 1, 21)), ...
a.on({linspace(0, 1, 100), linspace(0, 1, 21)}), 'AbsTol', 100*eps); a.on({linspace(0, 1, 100), linspace(0, 1, 21)}), 'AbsTol', 100*eps);
d24z = quantity.Domain('grid', linspace(0, 1, 24), 'name', 'z'); d24z = quantity.Domain('z', linspace(0, 1, 24));
d21zeta = quantity.Domain('grid', linspace(0, 1, 21), 'name', 'zeta'); d21zeta = quantity.Domain('zeta', linspace(0, 1, 21));
testCase.verifyEqual(createTestData(linspace(0, 1, 24), linspace(0, 1, 21)), ... testCase.verifyEqual(createTestData(linspace(0, 1, 24), linspace(0, 1, 21)), ...
a.on( [d24z, d21zeta] ), 'AbsTol', 24*eps); a.on( [d24z, d21zeta] ), 'AbsTol', 24*eps);
...@@ -601,9 +601,9 @@ testCase.verifyEqual(permute(createTestData(linspace(0, 1, 21), linspace(0, 1, 2 ...@@ -601,9 +601,9 @@ testCase.verifyEqual(permute(createTestData(linspace(0, 1, 21), linspace(0, 1, 2
end end
%% test on on 3-dim domain %% test on on 3-dim domain
z = quantity.Domain('grid', 0:3, 'name', 'z'); z = quantity.Domain('z', 0:3);
t = quantity.Domain('grid', 0:4, 'name', 't'); t = quantity.Domain('t', 0:4);
x = quantity.Domain('grid', 0:5, 'name', 'x'); x = quantity.Domain('x', 0:5);
Z = quantity.Discrete( z.grid, 'domain', z); Z = quantity.Discrete( z.grid, 'domain', z);
T = quantity.Discrete( t.grid, 'domain', t); T = quantity.Discrete( t.grid, 'domain', t);
...@@ -638,8 +638,8 @@ function testMtimesZZeta2x2(testCase) ...@@ -638,8 +638,8 @@ function testMtimesZZeta2x2(testCase)
%% %%
z11_ = linspace(0, 1, 11); z11_ = linspace(0, 1, 11);
z11 = quantity.Domain('grid', z11_, 'name', 'z'); z11 = quantity.Domain('z', z11_);
zeta11 = quantity.Domain('grid', z11_, 'name', 'zeta'); zeta11 = quantity.Domain('zeta', z11_);
a = quantity.Discrete(ones([z11.n, z11.n, 2, 2]), 'size', [2, 2], ... a = quantity.Discrete(ones([z11.n, z11.n, 2, 2]), 'size', [2, 2], ...
'domain', [z11, zeta11], 'name', 'A'); 'domain', [z11, zeta11], 'name', 'A');
...@@ -1089,9 +1089,9 @@ testCase.verifyEqual(AB2c.on(), tst) ...@@ -1089,9 +1089,9 @@ testCase.verifyEqual(AB2c.on(), tst)
testCase.verifyEqual(cAB2.on(), tst) testCase.verifyEqual(cAB2.on(), tst)
%% test plus on different domains %% test plus on different domains
z = quantity.Domain('grid', 0:3, 'name', 'z'); z = quantity.Domain('z', 0:3);
t = quantity.Domain('grid', 0:4, 'name', 't'); t = quantity.Domain('t', 0:4);
x = quantity.Domain('grid', 0:5, 'name', 'x'); x = quantity.Domain('x', 0:5);
T = quantity.Discrete( t.grid, 'domain', t); T = quantity.Discrete( t.grid, 'domain', t);
Z = quantity.Discrete( z.grid, 'domain', z); Z = quantity.Discrete( z.grid, 'domain', z);
...@@ -1119,8 +1119,8 @@ V = cat(3, v{:}); ...@@ -1119,8 +1119,8 @@ V = cat(3, v{:});
b = quantity.Discrete(v, 'grid', {z, t}, 'gridName', {'z', 't'}); b = quantity.Discrete(v, 'grid', {z, t}, 'gridName', {'z', 't'});
c = quantity.Discrete(V, 'grid', {z, t}, 'gridName', {'z', 't'}); c = quantity.Discrete(V, 'grid', {z, t}, 'gridName', {'z', 't'});
Z = quantity.Domain('grid', z, 'name', 'z'); Z = quantity.Domain('z', z);
T = quantity.Domain('grid', t, 'name', 't'); T = quantity.Domain('t', t);
d = quantity.Discrete(V, 'domain', [Z, T]); d = quantity.Discrete(V, 'domain', [Z, T]);
...@@ -1176,8 +1176,8 @@ end ...@@ -1176,8 +1176,8 @@ end
function testValue2Cell(testCase) function testValue2Cell(testCase)
v = rand([100, 42, 2, 3]); v = rand([100, 42, 2, 3]);
Z = quantity.Domain('grid', linspace(0,1,100), 'name', 'z'); Z = quantity.Domain('z', linspace(0,1,100));
T = quantity.Domain('grid', linspace(0,1,42), 'name', 't'); T = quantity.Domain('t', linspace(0,1,42));
V = quantity.Discrete( quantity.Discrete.value2cell(v, [100, 42], [2, 3]), ... V = quantity.Discrete( quantity.Discrete.value2cell(v, [100, 42], [2, 3]), ...
'domain', [Z, T]); 'domain', [Z, T]);
verifyTrue(testCase, misc.alln(v == V.on())); verifyTrue(testCase, misc.alln(v == V.on()));
...@@ -1245,8 +1245,8 @@ function testSubs(testCase) ...@@ -1245,8 +1245,8 @@ function testSubs(testCase)
myTestArray = ones(21, 41, 2, 3); myTestArray = ones(21, 41, 2, 3);
myTestArray(:,1,1,1) = linspace(0, 1, 21); myTestArray(:,1,1,1) = linspace(0, 1, 21);
myTestArray(:,:,2,:) = 2; myTestArray(:,:,2,:) = 2;
z = quantity.Domain('grid', linspace(0, 1, 21), 'name', 'z'); z = quantity.Domain('z', linspace(0, 1, 21));
zeta = quantity.Domain('grid', linspace(0, 1, 41), 'name', 'zeta'); zeta = quantity.Domain('zeta', linspace(0, 1, 41));
quan = quantity.Discrete(myTestArray, 'domain', [z, zeta]); quan = quantity.Discrete(myTestArray, 'domain', [z, zeta]);
...@@ -1270,15 +1270,15 @@ testCase.verifyEqual(quanZetaZeta.on(), quanZetaZetaReference); ...@@ -1270,15 +1270,15 @@ testCase.verifyEqual(quanZetaZeta.on(), quanZetaZetaReference);
testCase.verifyEqual(quanEta(1).gridName, {'eta', 'zeta'}) testCase.verifyEqual(quanEta(1).gridName, {'eta', 'zeta'})
testCase.verifyEqual(quanPt.on(), shiftdim(quan.on({1, quan(1).grid{2}}))); testCase.verifyEqual(quanPt.on(), shiftdim(quan.on({1, quan(1).grid{2}})));
testCase.verifyEqual( gridSize( quanZetaZeta.subs( quantity.Domain('grid', linspace(0,1,3), 'name', 'zeta')) ), 3); testCase.verifyEqual( gridSize( quanZetaZeta.subs( ...
quantity.Domain('zeta', linspace(0,1,3))) ), 3);
% 4d-case % 4d-case
myTestArray4d = rand(11, 21, 31, 41, 1, 2); myTestArray4d = rand(11, 21, 31, 41, 1, 2);
x1 = quantity.Domain('grid', linspace(0, 1, 11), 'name', 'z'); x1 = quantity.Domain('z', linspace(0, 1, 11));
x2 = quantity.Domain('grid', linspace(0, 1, 21), 'name', 'zeta'); x2 = quantity.Domain('zeta', linspace(0, 1, 21));
x3 = quantity.Domain('grid', linspace(0, 1, 31), 'name', 'eta'); x3 = quantity.Domain('eta', linspace(0, 1, 31));
x4 = quantity.Domain('grid', linspace(0, 1, 41), 'name', 'beta'); x4 = quantity.Domain('beta', linspace(0, 1, 41));
quan4d = quantity.Discrete(myTestArray4d, 'domain', [x1, x2, x3, x4], 'name', 'fun5d'); quan4d = quantity.Discrete(myTestArray4d, 'domain', [x1, x2, x3, x4], 'name', 'fun5d');
quan4dAllEta = quan4d.subs({'z', 'zeta', 'eta', 'beta'}, {'eta', 'eta', 'eta', 'eta'}); quan4dAllEta = quan4d.subs({'z', 'zeta', 'eta', 'beta'}, {'eta', 'eta', 'eta', 'eta'});
......
...@@ -7,7 +7,7 @@ end ...@@ -7,7 +7,7 @@ end
function testEquality(testCase) function testEquality(testCase)
d = quantity.Domain('grid', 0, 'name', 'd'); d = quantity.Domain('d', 0);
e = quantity.Domain.empty(); e = quantity.Domain.empty();
dd = d; dd = d;
...@@ -23,7 +23,7 @@ end ...@@ -23,7 +23,7 @@ end
function testDomainInit(testCase) function testDomainInit(testCase)