1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
| function [T] = Tree(varargin)
% TREE Tree class constructor
%
% T = Tree(Lmax, d) creates a single 2^d tree with Lmax levels.
%
% T = Tree(tag, var, d, Xset) creates a single 2^d tree with
% source/target points given in Xset automatically parsed with
% respect to each box and level to build non-empty child, neighbor
% and E4 sets. If tag = 'Lmax', var is interpreted to be the maximum
% level in the tree; if tag = 's', then var is taken as the grouping
% parameter and used to determine Lmax.
% Check if initializing with another Tree object...
if (isa(varargin{1}, 'Box'))
T = varargin{1};
return
end
% Set up tree structure...
T = struct('level', [], ...
'ij', [], ...
'jF', [], ...
'jL', []);
switch nargin
case 2
Lmax = varargin{1};
d = varargin{2};
for l = 1:Lmax
nboxes = 2^(d*l);
for n = 1:nboxes
T.level(l).box(n) = initBox(n-1,l,d);
end
end
case 4
% Interleave and sort points...
tag = varargin{1};
var = varargin{2};
d = varargin{3};
Xset = varargin{4};
Lavail = floor(30/d);
N = size(Xset,1);
Xi = zeros(1,N);
for i=1:N
Xi(i) = boxIndex(Xset(i,:), Lavail);
end
[Xi,T.ij] = sort(Xi);
switch tag
case 'Lmax'
Lmax = var;
case 's'
Lmax = maxLevel(var,Xi,Lavail,d);
otherwise
error('Incorrect tag value');
end
if Lmax > Lavail
warning('Lmax exceeds Lavail - setting Lmax = Lavail')
Lmax = Lavail;
end
% Construct levels...
for l = 1:Lmax
nboxes = 2^(d*l);
for n = 1:nboxes
T.level(l).box(n) = initBox(n-1,l,d,Xi,Lavail);
end
end
% Initialize 'bookmark' arrays ...
% NOTE: 'bookmarks' are only set for Lmax - this is
% because non-adaptive MLFMM only accesses source
% and reciever points during initial S-expansion
% and evaluation of R-expansion at Lmax.
% 'shift' Xi to Lmax level for parsing with respect
% to boxes at Lmax.
Xi = bitshift(Xi,d*(Lmax-Lavail));
nboxes = 2^(d*Lmax);
T.jF = ones(1,nboxes);
T.jL = zeros(1,nboxes);
imax = size(Xi,2);
i = 1;
while(i < imax + 1)
n = Xi(i);
T.jF(n+1) = i;
while( n == Xi(i) )
T.jL(n+1) = i;
i = i + 1;
if(i > imax)
break
end
end
end
% Clean up memory...
Xi = [];
otherwise
error('Wrong number of inputs received')
end
% Construct Tree class...
T = class(T, 'Tree'); |
Partager