Commit 925b9f1d authored by Jakob Gabriel's avatar Jakob Gabriel
Browse files

quantity.Discrete: replaced gridIndex and gridSize with similar Domain methods

parent b2bac17d
......@@ -158,7 +158,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi
function itIs = isConstant(obj)
% the quantity is interpreted as constant if it has no grid or
% it has a grid that is only one point.
itIs = isempty(obj.gridSize) || prod(obj.gridSize) == 1;
itIs = isempty(obj(1).domain);
end
function doNotCopy = get.doNotCopy(obj)
doNotCopy = obj.doNotCopyPropertiesName();
......@@ -495,7 +495,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi
assert(numel(referenceGridName) == numel(varargin{it}(1).gridName), ...
['For getFinestGrid, the gridName of all objects must be equal', ...
'. Maybe gridJoin() does what you want?']);
comparisonGridSize = varargin{it}.gridSize(referenceGridName);
comparisonGridSize = varargin{it}(1).gridSize(referenceGridName);
for jt = 1 : numel(referenceGridName)
comparisonGrid = varargin{it}.gridOf(referenceGridName{jt});
assert(referenceGrid{jt}(1) == comparisonGrid(1), 'Grids must have same domain for combining them')
......@@ -649,12 +649,12 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi
else
value = objCell{k};
for l = 1:numel(value)
M(:,l) = repmat(value(l), prod(obj(1).gridSize), 1);
M(:,l) = repmat(value(l), prod(obj(1).domain.gridLength), 1);
end
if isempty(value)
M = zeros([prod(obj(1).gridSize), size(value(l))]);
M = zeros([prod(obj(1).domain.gridLength), size(value(l))]);
end
M = reshape(M, [obj(1).gridSize, size(value)]);
M = reshape(M, [obj(1).domain.gridLength, size(value)]);
o = quantity.Discrete( M, ...
'size', size(value), ...
'gridName', obj(1).gridName, ...
......@@ -772,7 +772,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi
assert(numel(obj(1).gridName) == 1);
assert(isequal(size(obj), [1, 1]));
inverse = quantity.Discrete(repmat(obj(1).grid{obj.gridIndex(gridName)}(:), [1, size(obj)]), ...
inverse = quantity.Discrete(repmat(obj(1).grid{obj(1).domain.gridIndex(gridName)}(:), [1, size(obj)]), ...
'size', size(obj), 'grid', obj.on(), 'gridName', {[obj(1).name]}, ...
'name', gridName);
......@@ -965,14 +965,14 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi
% the grid of gridName2Replace is set to values{1} for
% evaluation of obj.on().
newGridForOn = obj(1).grid;
newGridForOn{obj.gridIndex(gridName2Replace{1})} = values{1};
newGridForOn{obj(1).domain.gridIndex(gridName2Replace{1})} = values{1};
newValue = reshape(obj.on(newGridForOn), [newGridSize, size(obj)]);
elseif isnumeric(values{1}) && numel(values{1}) > 1
% if values{1} is a double vector, then the grid is
% replaced.
newGrid = obj(1).grid;
newGrid{obj.gridIndex(gridName2Replace{1})} = values{1};
newGrid{obj(1).domain.gridIndex(gridName2Replace{1})} = values{1};
newGridName = obj(1).gridName;
newValue = obj.on(newGrid);
else
......@@ -992,6 +992,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi
end
function [idx, logicalIdx] = gridIndex(obj, varargin)
warning('DEPRICATED: use quantity.Domain.gridIndex method instead')
[idx, logicalIdx] = obj(1).domain.gridIndex(varargin{:});
end
......@@ -1017,10 +1018,10 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi
% than the grid dimensions are neglected.
if nargin == 1
if numel(obj.gridSize) == 1
value = zeros(obj.gridSize, 1);
if numel(obj(1).domain.gridLength) == 1
value = zeros(obj(1).domain.gridLength, 1);
else
value = zeros(obj.gridSize, 1);
value = zeros(obj(1).domain.gridLength, 1);
end
if isempty(value)
value = 0;
......@@ -1068,6 +1069,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi
function s = gridSize(obj, myGridName)
% GRIDSIZE returns the size of all grid entries.
% todo: this should be called gridLength
warning('DEPRICATED: use quantity.Domain.gridLength method instead')
if isempty(obj(1).domain)
s = [];
else
......@@ -1095,7 +1097,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi
'extraAxisOptions', 'every axis title/.append style={yshift=-1.5ex}, every axis x label/.append style={yshift=2mm}'});
p.parse(varargin{:});
additionalPlotOptions = misc.struct2namevaluepair(p.Unmatched);
if prod(obj.gridSize) == 1
if prod(obj(1).domain.gridLength) == 1
additionalPlotOptions = [additionalPlotOptions(:)', ...
{'x'}];
end
......@@ -1332,7 +1334,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi
% [lowerBounds, upperBounds] = getBoundaryValues(obj) returns
% the boudary values of all grids defined for the object.
grids = obj(1).grid(obj.gridIndex(varargin{:}));
grids = obj(1).grid(obj(1).domain.gridIndex(varargin{:}));
lowerBounds = zeros(1, numel(grids));
upperBounds = zeros(1, numel(grids));
......@@ -1620,8 +1622,8 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi
% reshape and permute objDiscrete such that only on for
% loop is needed.
objDiscreteReshaped = permute(reshape(objDiscreteOriginal, ...
[prod(obj(1).gridSize), size(obj)]), [2, 3, 1]);
invDiscrete = zeros([prod(obj(1).gridSize), size(obj)]);
[prod(obj(1).domain.gridLength), size(obj)]), [2, 3, 1]);
invDiscrete = zeros([prod(obj(1).domain.gridLength), size(obj)]);
parfor it = 1 : size(invDiscrete, 1)
invDiscrete(it, :, :) = inv(objDiscreteReshaped(:, :, it));
......@@ -1917,7 +1919,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi
I = obj.int(intGridName{2:end}, a(2:end), b(2:end));
return
end
[idxGrid, isGrid] = obj.gridIndex(intGridName);
[idxGrid, isGrid] = obj(1).domain.gridIndex(intGridName);
if nargin == 4
I = cumInt( obj, varargin{:});
return;
......@@ -2187,7 +2189,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi
v(:,k) = obj(k).valueDiscrete(:);
end
value = reshape(v, [obj(1).gridSize(), size(obj)]);
value = reshape(v, [obj(1).domain.gridLength(), size(obj)]);
if nargin == 2 && ~isequal( myDomain, obj(1).domain )
% if a new domain is specified for the evaluation of
......@@ -2296,7 +2298,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi
s.size = size(A);
s.nargin = A.nargin();
parameters = struct(A);
gridSize = A.gridSize();
gridSize = A.domain.gridLength();
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