Commit 6da3dcdf authored by Ferdinand Fischer's avatar Ferdinand Fischer
Browse files

Temp state for the implementation of the domain object.

parent 50afa926
This diff is collapsed.
classdef Domain classdef Domain
%DOMAIN class to describes a range of values on which a function can be defined. %DOMAIN class to describes a range of values on which a function can be defined.
% todo: % todo:
% * EquidistantDomain % * EquidistantDomain
% * multi dimensional % * multi dimensional
...@@ -9,16 +9,18 @@ classdef Domain ...@@ -9,16 +9,18 @@ classdef Domain
% 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};
% 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.
name char; name char;
isConstant = false ;
end end
properties (Dependent) properties (Dependent)
n; % number of discretization points n; % number of discretization points
lower; % lower bound of the domain lower; % lower bound of the domain
upper; % upper bound of the domain upper; % upper bound of the domain
end end
...@@ -29,13 +31,13 @@ classdef Domain ...@@ -29,13 +31,13 @@ classdef Domain
% %
if nargin >= 1 if nargin >= 1
parser = misc.Parser(); parser = misc.Parser();
parser.addParameter('grid', [], @isvector); parser.addParameter('grid', [], @(g) isvector(g) || isempty(g));
parser.addParameter('name', '', @ischar); parser.addParameter('name', '', @ischar);
parser.parse(varargin{:}); parser.parse(varargin{:});
% todo: assertions % todo: assertions
% * ascending ? % * ascending ?
obj.grid = parser.Results.grid(:); obj.grid = parser.Results.grid(:);
obj.name = parser.Results.name; obj.name = parser.Results.name;
else else
...@@ -72,6 +74,124 @@ classdef Domain ...@@ -72,6 +74,124 @@ classdef Domain
s = [obj.n]; s = [obj.n];
end end
function s = eq(obj, obj2)
s = all(obj.gridLength == obj2.gridLength);
for k = 1:numel(obj)
s = s && all(obj(k).grid == obj2(k).grid);
s = s && strcmp(obj(k).name, obj2(k).name);
end
end
function l = ne(obj, obj2)
l = ~(obj == obj2);
end
function [joinedDomain] = gridJoin(obj1, obj2)
%% gridJoin combines the grid and gridName of two objects (obj1,
% obj2), such that every gridName only occurs once and that the
% finer grid of both is used.
[joinedGrid] = union({obj1.name}, {obj2.name}, 'sorted');
joinedDomain = quantity.Domain.empty;
% check for each grid if it is in the domain of obj1 or obj2 or
% both
for i = 1 : numel(joinedGrid)
currentGridName = joinedGrid{i};
[index1, logicalIndex1] = obj1.gridIndex(currentGridName);
[index2, logicalIndex2] = obj2.gridIndex(currentGridName);
%
% if ~any(logicalIndex1)
% joinedDomain(i) = obj2(index2);
% elseif ~any(logicalIndex2)
% joinedDomain(i) = obj1(index1);
% else
%
% Check if a domain is in both domains:
% -> then take the finer one of both
if any(logicalIndex1) && any(logicalIndex2)
tempDomain1 = obj1(index1);
tempDomain2 = obj2(index2);
if ~tempDomain1.isConstant && ~tempDomain2.isConstant
assert(tempDomain1.lower == tempDomain2.lower, 'Grids must have same domain for gridJoin')
assert(tempDomain1.upper == tempDomain2.upper, 'Grids must have same domain for gridJoin')
end
if tempDomain1.gridLength > tempDomain2.gridLength
joinedDomain(i) = tempDomain1;
else
joinedDomain(i) = tempDomain2;
end
% If it is not in both, -> just take the normal grid
elseif any(logicalIndex1)
joinedDomain(i) = obj1(index1);
elseif any(logicalIndex2)
joinedDomain(i) = obj2(index2);
end
end
end % gridJoin()
function [idx, logicalIdx] = gridIndex(obj, names)
%% GRIDINDEX returns the index of the grid
% [idx, log] = gridIndex(obj, names) searches in the gridName
% properties of obj for the "names" and returns its index as
% "idx" and its logical index as "log"
if nargin == 1
names = {obj.name};
end
names = misc.ensureIsCell(names);
idx = zeros(1, length(names));
nArgIdx = 1:obj.ndims();
logicalIdx = false(1, obj.ndims());
for k = 1:length(names)
log = strcmp({obj.name}, names{k});
logicalIdx = logicalIdx | log;
if any(log)
idx(k) = nArgIdx(log);
else
idx(k) = 0;
end
end
end % gridIndex
function matGrid = ndgrid(obj)
% ndgrid calles ndgrid for the default grid, if no other grid
% is specified. Empty grid as input returns empty cell as
% result.
if isempty(obj)
matGrid = {};
else
grids = {obj.grid};
[matGrid{1:obj.ndims}] = ndgrid(grids{:});
end
end % ndgrid()
function [newDomain, idx] = permute(obj, order)
if isa(order, 'quantity.Domain')
names = {order.name};
elseif ischar([order{:}])
names = order;
else
error('the input parameter order must be a array of quantity.Domain objects or a cell-array with string')
end
idx = cellfun(@(v) obj.gridIndex(v), names);
if isa(order, 'quantity.Domain')
newDomain = order;
else
newDomain = obj(idx);
end
end
end end
methods (Static) methods (Static)
...@@ -97,7 +217,7 @@ classdef Domain ...@@ -97,7 +217,7 @@ classdef Domain
g(k) = quantity.Domain('grid', O, 'name', name{k}); g(k) = quantity.Domain('grid', O, 'name', name{k});
end end
end end
end end
end end
...@@ -74,57 +74,25 @@ classdef Function < quantity.Discrete ...@@ -74,57 +74,25 @@ classdef Function < quantity.Discrete
%----------------------------- %-----------------------------
% --- overloaded functions --- % --- overloaded functions ---
%----------------------------- %-----------------------------
function value = on(obj, myGrid, myGridName) function value = obj2value(obj, myDomain, recalculate)
% evaluates obj.valueContinuous function and returns an array
% with the dimensions (n, m, ..., z_disc). n, m, ... are the
% array dimensions of obj.valueContinuous and z_disc is the
% dimensions of the grid.
if nargin == 1
gridSize = obj(1).gridSize;
if gridSize > 2
value = cat(length(gridSize),obj.valueDiscrete);
else % important to include this case for empty grids!
value = [obj.valueDiscrete]; % = cat(2,obj.valueDiscrete)
end
value = reshape(value, [gridSize, size(obj)]);
return
elseif nargin >= 2 && ~iscell(myGrid)
myGrid = {myGrid};
end
gridPermuteIdx = 1:obj(1).nargin;
if isempty(gridPermuteIdx)
gridPermuteIdx = 1;
end
if nargin == 3
if ~iscell(myGridName)
myGridName = {myGridName};
end
assert(numel(myGrid) == numel(myGridName), ...
['If on() is called by using gridNames as third input', ...
', then the cell-array of grid and gridName must have ', ...
'equal number of elements.']);
assert(numel(myGridName) == obj(1).nargin, ...
'All (or none) gridName must be specified');
gridPermuteIdx = cellfun(@(v) obj(1).gridIndex(v), myGridName);
myGrid = myGrid(gridPermuteIdx);
end
% at first the value has to be initialized by different
% dimensions, to simplify the evaluation of each entry:
gridSize = cellfun('length', myGrid); % check if the domain for the evaluation has changed. If not
if isempty(gridSize), gridSize = 1; end % we can use the stored values in valueDiscrete:
if nargin < 3
value = nan([numel(obj), gridSize]); recalculate = false;
for k = 1:numel(obj) end
ndGrd = obj.ndgrid( myGrid ); if ~recalculate && (myDomain == obj(1).domain)
tmp = obj(k).evaluateFunction( ndGrd{:} ); value = obj2value@quantity.Discrete(obj, myDomain);
% Replaced else
% double(subs(obj(k).valueSymbolic, obj.variable, grid)); % otherwise the function has to be evaluated on the new
% because this is very slow! % domain
value(k,:) = tmp(:); value = nan([numel(obj), myDomain.gridLength]);
for k = 1:numel(obj)
ndGrd = myDomain.ndgrid;
tmp = obj(k).evaluateFunction( ndGrd{:} );
value(k,:) = tmp(:);
end
end end
value = reshape(permute(value, [1+(gridPermuteIdx), 1]), ...
[gridSize(gridPermuteIdx), size(obj)]);
end end
function n = nargin(obj) function n = nargin(obj)
......
...@@ -472,23 +472,28 @@ testCase.verifyEqual(myQuantityDZzeta(3).on(), zeros(11, 21), 'AbsTol', 10*eps); ...@@ -472,23 +472,28 @@ testCase.verifyEqual(myQuantityDZzeta(3).on(), zeros(11, 21), 'AbsTol', 10*eps);
end end
function testOn(testCase) function testOn(testCase)
%% init data % init data
gridVecA = linspace(0, 1, 27); domainVecA = quantity.Domain('grid', linspace(0, 1, 27), 'name', 'z');
gridVecB = linspace(0, 1, 41); domainVecB = quantity.Domain('grid', linspace(0, 1, 41), 'name', 'zeta');
[value] = createTestData(gridVecA, gridVecB); [value] = createTestData(domainVecA.grid, domainVecB.grid);
a = quantity.Discrete(value, 'size', [2, 3], ... a = quantity.Discrete(value, 'size', [2, 3], ...
'grid', {gridVecA, gridVecB}, 'gridName', {'z', 'zeta'}, 'name', 'A'); 'domain', [domainVecA, domainVecB], 'name', 'A');
%% %
testCase.verifyEqual(value, a.on()); testCase.verifyEqual(value, a.on());
testCase.verifyEqual(permute(value, [2, 1, 3, 4]), ... testCase.verifyEqual(permute(value, [2, 1, 3, 4]), ...
a.on({gridVecB, gridVecA}, {'zeta', 'z'})); a.on([domainVecB, domainVecA]));
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');
d21zeta = quantity.Domain('grid', linspace(0, 1, 21), 'name', 'zeta');
testCase.verifyEqual(createTestData(linspace(0, 1, 24), linspace(0, 1, 21)), ... testCase.verifyEqual(createTestData(linspace(0, 1, 24), linspace(0, 1, 21)), ...
a.on({linspace(0, 1, 24), linspace(0, 1, 21)}, {'z', 'zeta'}), 'AbsTol', 24*eps); a.on( [d24z, d21zeta] ), 'AbsTol', 24*eps);
testCase.verifyEqual(permute(createTestData(linspace(0, 1, 21), linspace(0, 1, 24)), [2, 1, 3, 4]), ... testCase.verifyEqual(permute(createTestData(linspace(0, 1, 21), linspace(0, 1, 24)), [2, 1, 3, 4]), ...
a.on({linspace(0, 1, 24), linspace(0, 1, 21)}, {'zeta', 'z'}), 'AbsTol', 2e-4); a.on( {linspace(0, 1, 24), linspace(0, 1, 21)}, {'zeta', 'z'}), 'AbsTol', 2e-4);
function [value] = createTestData(gridVecA, gridVecB) function [value] = createTestData(gridVecA, gridVecB)
[zGridA , zetaGridA] = ndgrid(gridVecA, gridVecB); [zGridA , zetaGridA] = ndgrid(gridVecA, gridVecB);
...@@ -531,7 +536,7 @@ b = quantity.Symbolic((eye(2, 2)), 'variable', zeta, ... ...@@ -531,7 +536,7 @@ b = quantity.Symbolic((eye(2, 2)), 'variable', zeta, ...
'grid', gridVecB); 'grid', gridVecB);
c = a*b; c = a*b;
%% %
testCase.verifyEqual(c.on(), a.on()); testCase.verifyEqual(c.on(), a.on());
end end
...@@ -575,7 +580,10 @@ KLdKR = KL \ KR; ...@@ -575,7 +580,10 @@ KLdKR = KL \ KR;
%% %%
testCase.verifyEqual(vLdVR.on(), 2 .\ (linspace(1, 2, 21).').^2); testCase.verifyEqual(vLdVR.on(), 2 .\ (linspace(1, 2, 21).').^2);
testCase.verifyEqual(KLdKR.on(), permute(repmat(2*eye(2), [1, 1, size(T)]), [4, 3, 1, 2]));
% TODO #discussion: for the following case the operation KL \ KR seems to change the order of the grid in the old version. As this is very unexpected. I would like to change them to not change the order!
testCase.verifyEqual(KLdKR.on(), permute(repmat(2*eye(2), [1, 1, size(T)]), [3, 4, 1, 2]));
end end
function testMrdivide(testCase) function testMrdivide(testCase)
...@@ -601,7 +609,9 @@ KLdKR = KL / KR; ...@@ -601,7 +609,9 @@ KLdKR = KL / KR;
%% %%
testCase.verifyEqual(vLdVR.on(), 2 ./ (linspace(1, 2, 21).').^2); testCase.verifyEqual(vLdVR.on(), 2 ./ (linspace(1, 2, 21).').^2);
testCase.verifyEqual(KLdKR.on(), permute(repmat(0.5*eye(2), [1, 1, size(T)]), [4, 3, 1, 2]));
% TODO #discussion: for the following case the operation KL \ KR seems to change the order of the grid in the old version. As this is very unexpected. I would like to change them to not change the order!
testCase.verifyEqual(KLdKR.on(), permute(repmat(0.5*eye(2), [1, 1, size(T)]), [3, 4, 1, 2]));
end end
function testInv(testCase) function testInv(testCase)
...@@ -753,61 +763,6 @@ testCase.verifyTrue(all(B_z_1(:,:,2) == 1)); ...@@ -753,61 +763,6 @@ testCase.verifyTrue(all(B_z_1(:,:,2) == 1));
end end
function testGridJoin(testCase)
s = linspace(0, 1);
z = linspace(0, 1, 71)';
t = linspace(0, 1, 51);
[Z, T, S] = ndgrid(z, t, s);
a = quantity.Discrete(cat(4, sin(Z.*Z.*S), cos(Z.*T.*S)), ...
'size', [2 1], 'grid', {z, t, s}, 'gridName', {'z', 't', 's'});
b = quantity.Discrete(ones(numel(s), numel(t)), ...
'size', [1 1], 'grid', {s, t}, 'gridName', {'p', 's'});
c = quantity.Discrete(ones(numel(t), 2, 2), ...
'size', [2 2], 'grid', {t}, 'gridName', {'p'});
[gridJoinedAB, gridNameJoinedAB] = gridJoin(a, b);
[gridJoinedCC, gridNameJoinedCC] = gridJoin(c, c);
[gridJoinedBC, gridNameJoinedBC] = gridJoin(b, c);
testCase.verifyEqual(gridNameJoinedAB, {'p', 's', 't', 'z'});
testCase.verifyEqual(gridJoinedAB, {s, s, t, z});
testCase.verifyEqual(gridNameJoinedCC, {'p'});
testCase.verifyEqual(gridJoinedCC, {t});
testCase.verifyEqual(gridNameJoinedBC, {'p', 's'});
testCase.verifyEqual(gridJoinedBC, {s, t});
end
function testGridIndex(testCase)
z = linspace(0, 2*pi, 71)';
t = linspace(0, 3*pi, 51);
s = linspace(0, 1);
[Z, T, S] = ndgrid(z, t, s);
a = quantity.Discrete(cat(4, sin(Z.*Z.*S), cos(Z.*T.*S)), ...
'size', [2 1], 'grid', {z, t, s}, 'gridName', {'z', 't', 's'});
idx = a.gridIndex('z');
testCase.verifyEqual(idx, 1);
idx = a.gridIndex({'z', 't'});
testCase.verifyEqual(idx, [1 2]);
idx = a.gridIndex({'z', 's'});
testCase.verifyEqual(idx, [1 3]);
idx = a.gridIndex('t');
testCase.verifyEqual(idx, 2);
end
function testMTimes(testCase) function testMTimes(testCase)
% multiplication of a(z) * a(z)' % multiplication of a(z) * a(z)'
% a(z) \in (3, 2), z \in (100) % a(z) \in (3, 2), z \in (100)
...@@ -836,7 +791,7 @@ testCase.verifyTrue(numeric.near(b1b1', B1B1.on())); ...@@ -836,7 +791,7 @@ testCase.verifyTrue(numeric.near(b1b1', B1B1.on()));
% vector multiplication of b(z, t) * b(v, t) % vector multiplication of b(z, t) * b(v, t)
b2 = cat(3, z .* t, z*0 +1); b2 = cat(3, z .* t, z*0 +1);
b2b2 = misc.multArray(b2, permute(b2, [1 2 4 3]), 4, 3, [1, 2]); b2b2 = misc.multArray(b2, permute(b2, [1 2 4 3]), 4, 3, [1, 2]);
b2b2 = permute(b2b2, [2 1 3 4]); b2b2 = permute(b2b2, [1 2 3 4]);
B2 = quantity.Discrete(b2, 'size', [ 2, 1 ], 'gridName', {'z', 't'}, 'grid', {z(:,1), t(1,:)}); B2 = quantity.Discrete(b2, 'size', [ 2, 1 ], 'gridName', {'z', 't'}, 'grid', {z(:,1), t(1,:)});
B2B2 = B2*B2'; B2B2 = B2*B2';
testCase.verifyTrue(numeric.near(b2b2, B2B2.on())); testCase.verifyTrue(numeric.near(b2b2, B2B2.on()));
...@@ -845,12 +800,12 @@ c2 = cat(4, sin(z), sin(t), cos(z)); ...@@ -845,12 +800,12 @@ c2 = cat(4, sin(z), sin(t), cos(z));
b2c2 = misc.multArray(b2, c2, 4, 3, [1 2]); b2c2 = misc.multArray(b2, c2, 4, 3, [1 2]);
C2 = quantity.Discrete(c2, 'size', [1 3], 'gridName', {'z', 't'}, 'grid', {z(:,1), t(1,:)}); C2 = quantity.Discrete(c2, 'size', [1 3], 'gridName', {'z', 't'}, 'grid', {z(:,1), t(1,:)});
B2C2 = B2 * C2; B2C2 = B2 * C2;
testCase.verifyTrue(numeric.near(permute(b2c2, [2 1 3 4]), B2C2.on())); testCase.verifyTrue(numeric.near(permute(b2c2, [1 2 3 4]), B2C2.on()));
% matrix b(z,t) * b(z,t) % matrix b(z,t) * b(z,t)
b = cat(4, cat(3, z .* t, z*0 +1), cat(3, sin( z ), cos( z .* t ))); b = cat(4, cat(3, z .* t, z*0 +1), cat(3, sin( z ), cos( z .* t )));
bb = misc.multArray(b, b, 4, 3, [1, 2]); bb = misc.multArray(b, b, 4, 3, [1, 2]);
bb = permute(bb, [2 1 3 4]); bb = permute(bb, [1 2 3 4]);
B = quantity.Discrete(b, 'size', [ 2, 2 ], 'gridName', {'z', 't'}, 'grid', {z(:,1), t(1,:)}); B = quantity.Discrete(b, 'size', [ 2, 2 ], 'gridName', {'z', 't'}, 'grid', {z(:,1), t(1,:)});
BB = B*B; BB = B*B;
testCase.verifyTrue(numeric.near(bb, BB.on)); testCase.verifyTrue(numeric.near(bb, BB.on));
...@@ -859,8 +814,8 @@ testCase.verifyTrue(numeric.near(bb, BB.on)); ...@@ -859,8 +814,8 @@ testCase.verifyTrue(numeric.near(bb, BB.on));
c = cat(4, cat(3, v .* t2, v*0 +1), cat(3, sin( v ), cos( v .* t2 )), cat(3, cos( t2 ), tan( v .* t2 ))); c = cat(4, cat(3, v .* t2, v*0 +1), cat(3, sin( v ), cos( v .* t2 )), cat(3, cos( t2 ), tan( v .* t2 )));
bc = misc.multArray(b, c, 4, 3, 2); bc = misc.multArray(b, c, 4, 3, 2);
bc = permute(bc, [ 1 2 4 3 5 ]); bc = permute(bc, [ 1 2 4 3 5 ]);
B = quantity.Discrete(b, 'size', [ 2, 2 ], 'gridName', {'z', 't'}, 'grid', {z(:,1), t(1,:)}); B = quantity.Discrete(b, 'size', [2, 2], 'gridName', {'z', 't'}, 'grid', {z(:,1), t(1,:)});
C = quantity.Discrete(c, 'size', [2, 3], 'gridName', {'v', 't'}, 'grid',{v(:,1), t2(1,:)}); C = quantity.Discrete(c, 'size', [2, 3], 'gridName', {'v', 't'}, 'grid', {v(:,1), t2(1,:)});
BC = B*C; BC = B*C;
testCase.verifyTrue(numeric.near(bc, BC.on)); testCase.verifyTrue(numeric.near(bc, BC.on));
...@@ -876,7 +831,7 @@ testCase.verifyTrue( numeric.near( aa(2,2).on() , cos(z * pi) .* cos(z * pi))); ...@@ -876,7 +831,7 @@ testCase.verifyTrue( numeric.near( aa(2,2).on() , cos(z * pi) .* cos(z * pi)));
%% test multiplicatin with constants: %% test multiplicatin with constants:
C = [3 0; 0 5]; C = [3 0; 0 5];
c = quantity.Discrete(C, 'gridName', {}, 'grid', {}, 'name', 'c'); c = quantity.Discrete(C, 'domain', quantity.Domain.empty(), 'name', 'c');
testCase.verifyTrue( numeric.near( squeeze(double(a*c)), [sin(z * pi) * 3, cos(z * pi) * 5])); testCase.verifyTrue( numeric.near( squeeze(double(a*c)), [sin(z * pi) * 3, cos(z * pi) * 5]));
testCase.verifyTrue( numeric.near( squeeze(double(a*[3 0; 0 5])), [sin(z * pi) * 3, cos(z * pi) * 5])); testCase.verifyTrue( numeric.near( squeeze(double(a*[3 0; 0 5])), [sin(z * pi) * 3, cos(z * pi) * 5]));
testCase.verifyTrue( numeric.near( double(c*c), C*C)); testCase.verifyTrue( numeric.near( double(c*c), C*C));
...@@ -897,7 +852,7 @@ end ...@@ -897,7 +852,7 @@ end
function testIsConstant(testCase) function testIsConstant(testCase)
C = quantity.Discrete(rand(3,7), 'gridName', {}); C = quantity.Discrete(rand(3,7), 'domain', quantity.Domain.empty());
testCase.verifyTrue(C.isConstant()); testCase.verifyTrue(C.isConstant());
z = linspace(0, pi)'; z = linspace(0, pi)';
...@@ -913,7 +868,7 @@ a = cat(3, [myGrid*0, myGrid, sin(myGrid)], [myGrid.^2, myGrid.^3, cos(myGrid)]) ...@@ -913,7 +868,7 @@ a = cat(3, [myGrid*0, myGrid, sin(myGrid)], [myGrid.^2, myGrid.^3, cos(myGrid)])
c = rand(2, 3); % dim = (2, 3) c = rand(2, 3); % dim = (2, 3)
A = quantity.Discrete(a, 'size', [3, 2], 'grid', myGrid, 'gridName', {'z'}); A = quantity.Discrete(a, 'size', [3, 2], 'grid', myGrid, 'gridName', {'z'});
C = quantity.Discrete(c, 'gridName', {}); C = quantity.Discrete(c, 'domain', quantity.Domain.empty());
ac = misc.multArray(a, c, 3, 1); % dim = (100, 3, 3) ac = misc.multArray(a, c, 3, 1); % dim = (100, 3, 3)
AC = A*C; AC = A*C;
...@@ -1019,7 +974,11 @@ v = {sin(z * t * pi); cos(z * t * pi)}; ...@@ -1019,7 +974,11 @@ v = {sin(z * t * pi); cos(z * t * pi)};
V = cat(3, v{:}); 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'});
d = quantity.Discrete(V, 'gridName', {'z', 't'});
Z = quantity.Domain('grid', z, 'name', 'z');
T = quantity.Domain('grid', t, 'name', 't');
d = quantity.Discrete(V, 'domain', [Z, T]);
%% %%
verifyTrue(testCase, misc.alln(b.on() == c.on())); verifyTrue(testCase, misc.alln(b.on() == c.on()));
...@@ -1071,23 +1030,12 @@ verifyTrue(testCase, numeric.near(A, Anum, 1e-2)); ...@@ -1071,23 +1030,12 @@ verifyTrue(testCase, numeric.near(A, Anum, 1e-2));
end end
% function testNDGrid(testCase)
% %%
% z = linspace(0,1).';
% t = linspace(0,1,101);
% b = quantity.Discrete({sin(z * t * pi); cos(z * t * pi)}, 'grid', {z, t}, 'gridName', {'z', 't'});
% % #TODO
% end
function testDefaultGrid(testCase)
g = quantity.Discrete.defaultGrid([100, 42]);
testCase.verifyEqual(g{1}, linspace(0, 1, 100).');
testCase.verifyEqual(g{2}, linspace(0, 1, 42));
end
function testValue2Cell(testCase) function testValue2Cell(testCase)
v = rand([100, 42, 2, 3]); v = rand([100, 42, 2, 3]);
V = quantity.Discrete( quantity.Discrete.value2cell(v, [100, 42], [2, 3]), 'gridName', {'z', 't'} ); Z = quantity.Domain('grid', linspace(0,1,100), 'name', 'z');
T = quantity.Domain('grid', linspace(0,1,42), 'name', 't');