Commit 6632aaa9 authored by Ferdinand Fischer's avatar Ferdinand Fischer
Browse files

Fixed subs to work with quantity.EquidistantDomain

parent 6ef08d4d
......@@ -483,6 +483,8 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
% compute the permutation index, in order to bring the
% new domain in the same order as the original one.
gridPermuteIdx = obj(1).domain.getPermutationIdx(myDomain);
assert( any(gridPermuteIdx ~= 0), "grid could not be found.")
end
% get the valueDiscrete data for this object. Apply the
% permuted myDomain. Then the obj2value will be evaluated
......@@ -972,6 +974,13 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
assert(numel(values) == numel(gridName2Replace), ...
'gridName2Replace and values must be of same size');
% set the newDomain once. If obj(1).domain is a quantity.Equidistant domain, it can
% not be mixed with other quantity.Domains in an array. Hence, it must be casted to
% a quantity.Domain. The following strange form of concatenation an empty Domain
% with the required domain, ensures that the result is an array of quantity.Domain
% objects.
newDomain = [quantity.Domain.empty, obj(1).domain];
% here substitution starts:
% The first (gridName2Replace{1}, values{1})-pair is
% replaced. If there are more cell-elements in those inputs
......@@ -1000,7 +1009,6 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
% Do not use "return", since, later subs might need to be
% called recursively!
newValue = obj.on();
newDomain = obj(1).domain;
elseif any(strcmp(values{1}, obj(1).gridName))
% if for a quantity f(z, zeta) this method is
% called with subs(f, zeta, z), then g(z) = f(z, z)
......@@ -1023,7 +1031,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
newDomainForOn(all(1:1:numel(newDomainForOn) ~= domainIndices(:)))];
else
% this is the default case. just grid name is changed.
newDomain = obj(1).domain;
%newDomain = obj(1).domain;
newDomain(obj(1).domain.gridIndex(gridName2Replace{1})) = ...
quantity.Domain(values{1}, ...
obj(1).domain(obj(1).domain.gridIndex(gridName2Replace{1})).grid);
......@@ -1034,7 +1042,6 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
% if values{1} is a scalar, then obj is evaluated and
% the resulting quantity looses that spatial grid and
% gridName
newDomain = obj(1).domain;
newDomain = newDomain(~strcmp(gridName2Replace{1}, [newDomain.name]));
% newGrid is the similar to the original grid, but the
% grid of gridName2Replace is removed.
......@@ -1049,14 +1056,16 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
elseif isnumeric(values{1}) && numel(values{1}) > 1
% if values{1} is a double vector, then the grid is
% replaced.
newDomain = obj(1).domain;
newDomain(obj(1).domain.gridIndex(gridName2Replace{1})) = ...
quantity.Domain(gridName2Replace{1}, values{1});
newValue = obj.on(newDomain);
else
error('value must specify a gridName or a gridPoint');
end
end % if ischar(values{1}) || isstring(values{1})
if isempty(newDomain)
% TODO@Jakob: Is it possible that this case occurrs?
% If I see it right, the only case where the newDomain is not set is the case
% where a error is thrown.
solution = newValue;
else
solution = quantity.Discrete(newValue, newDomain, ...
......
......@@ -1546,6 +1546,13 @@ quan4dArbitrary = quan4d.subs({'z', 'zeta', 'eta', 'beta'}, {'zeta', 'beta', 'z'
testCase.verifyEqual(reshape(quan4d.on({1, 1, 1, 1}), size(quan4d)), ...
reshape(quan4dArbitrary.on({1, 1, 1}), size(quan4dAllEta)));
% test a substution where a quantity.EquidistantDomain is used:
e = quantity.EquidistantDomain("t", 0, 1, "stepSize", 0.1);
q = Discrete(e);
p = q.subs(e, "z");
testCase.verifyEqual( p.domain.name, "z")
testCase.verifyEqual( on( q.subs(e, z.grid) ), q.on(z.grid) )
end
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment