Commit 945d1cb4 authored by Jakob Gabriel's avatar Jakob Gabriel
Browse files

quantity.Piecewise: piecewise defined domain may now also be not on the first...

quantity.Piecewise: piecewise defined domain may now also be not on the first place of the domains + conversion to quantity.Discrete.
parent 7ded3f9a
......@@ -26,6 +26,8 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Piecewise < quantity.Discrete
% If the optional arg has not been set, use the grid of
% the functions
domainToJoin = quantities{1}(1).domain;
else
domainToJoin = optionalArgs.domainToJoin;
end
% ensure all have the same domain
......@@ -33,12 +35,15 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Piecewise < quantity.Discrete
assert( all( cellfun(@(q) all( strcmp( [d.name], [q(1).domain.name] ) ), quantities) ) , ...
'The quantities for the piecewise combination must have the same domain names' );
assert(length(quantities) >= 2, 'Only one quantity is given for the piecewise combination. At least 2 are required.');
assert( quantities{1}(1).domain.index(domainToJoin) == 1, ...
'The domain to join must be the first domain!');
domain2joinIndex = quantities{1}(1).domain.index(domainToJoin);
% assert( quantities{1}(1).domain.index(domainToJoin) == 1, ...
% 'The domain to join must be the first domain!');
joinedGrid = quantities{1}(1).domain.find(domainToJoin.name).grid;
joinedValues = quantities{1}.on();
joinedValues = permute(joinedValues, ...
[domain2joinIndex, setdiff((1:ndims(joinedValues)), domain2joinIndex)]);
% ensure the domains fit to each other and then concatenate
% them
......@@ -46,26 +51,33 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Piecewise < quantity.Discrete
dkm1 = quantities{k-1}(1).domain.find(domainToJoin.name);
dk = quantities{k}(1).domain.find(domainToJoin.name);
assert(dkm1.upper == dk.lower, 'Domains do not connect to each other');
assert(dkm1.upper == dk.lower, "Domains do not connect to each other");
% *) join the domains and the discrete values to a common
tmpGrid = dk.grid;
tmpValues = quantities{k}.on();
joinedGrid = [joinedGrid; tmpGrid(2:end,:)]; %#ok<AGROW>
tmpValues = permute(tmpValues, ...
[domain2joinIndex, setdiff(1:ndims(tmpValues), domain2joinIndex)]);
if optionalArgs.upperBoundaryIncluded(k-1)
% the value for the assembling point should be
% taken from the left values
joinedValues = [joinedValues; tmpValues(2:end,:)]; %#ok<AGROW>
joinedValues = cat(1, joinedValues, ...
reshape(tmpValues(2:end,:), size(tmpValues) - eye(1, ndims(tmpValues))));
else
% the value for the assembling point should be
% taken from the right values
joinedValues = [joinedValues(1:end-1,:); tmpValues];
joinedValues = cat(1, ...
reshape(joinedValues(1:end-1,:), size(joinedValues) - eye(1, ndims(joinedValues))), ...
tmpValues);
end
end
joinedDomain = quantity.Domain(domainToJoin.name, joinedGrid);
joinedValues = ipermute(joinedValues, ...
[domain2joinIndex, setdiff((1:ndims(joinedValues)), domain2joinIndex)]);
joinedDomain = quantities{1}(1).domain.copy.replace(...
quantity.Domain(domainToJoin.name, joinedGrid));
initArgs = {joinedValues, joinedDomain, "name", optionalArgs.name};
end
......@@ -75,8 +87,12 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Piecewise < quantity.Discrete
[obj.quantities] = deal(quantities);
end
end
end % Piecewise
end
end
function thisQuantity = quantity.Discrete(obj)
thisQuantity = reshape(quantity.Discrete( cat(numel(obj(1).domain)+1, obj.valueDiscrete), ...
obj(1).domain, "name", obj(1).name), size(obj));
end % quantity.Discrete()
end % methods
end % classdef
......@@ -68,7 +68,7 @@ classdef TimeDelayOperator < handle & matlab.mixin.Copyable
if ~obj(i, j).isZero
d(i, k) = d(i, k) + ...
h(j, k).compose( obj.t + obj(i, j).coefficient, ...
'domain', optionalArgs.domain );
"domain", optionalArgs.domain );
end
end
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