1 function ENBI = get_enbi(grid, edge, tstep)
2 %
function ENBI = get_enbi(grid, edge)
3 %
function assembling a matrix with the 5 neighbour
's cell indices that
4 % are needed in order to compute the gradient over the edge given by
5 % 'edge
' in each row. see also the sketch below.
7 % arrangement of cell indices:
8 % edges' indices of the main cell by which one gets the
"right"
12 % N | NE ENBI(:,2) = N | ENBI(:,5) = NE
13 % ------|------- <-- nb_ind(0) ----------------|-----------------
14 % main | E ENBI(:,1) | ENBI(:,4)
15 % ------|------- <-- nb_ind(1) ----------------|-----------------
16 % S | SE ENBI(:,3) | ENBI(:,6)
21 % Martin Drohmann 05.03.2008
23 persistent Ecache hashes cache_filled;
24 warning(
'off',
'enbi:cache:redundance');
32 %ishashed = @(x)(min (cellfun(@(y)(all(y==x)), hashes)) == 1);
33 hasharray = [size(grid.X), grid.X(1), grid.Y(1), edge];
37 % disp(
'erase cache values');
42 num_cells = size(grid.CX,1);
44 % TODO:
this is a stupid hack: I don
't like it
49 nb_ind = mod([ 2 0 ] + temp, 4) + 1;
52 ENBI = zeros(num_cells, 6);
53 ENBI(:,1) = 1:num_cells;
54 ENBI(:,[2,3]) = grid.NBI(1:num_cells, nb_ind);
56 %neg_ind = find(ENBI < -1);
57 %[ind,col] = ind2sub(size(ENBI), neg_ind);
61 non_bnd_ind = ENBI(:,i) > 0;
62 dir_bnd_ind = ENBI(:,i) == -1;
63 ENBI(non_bnd_ind,i+3) = grid.NBI(ENBI(non_bnd_ind,i),edge);
64 % TODO: Also assign to -1 if _one_ neighbour already is -1. It should be
65 % enough to check for index 4
66 ENBI(dir_bnd_ind,i+3) = -1;
69 temp = logical(ENBI(:,4) == -1);
70 corner_bnd_ind = temp & ENBI(:,5) == 0;
71 ENBI(corner_bnd_ind, 5) = -1;
72 corner_bnd_ind = temp & ENBI(:,6) == 0;
73 ENBI(corner_bnd_ind, 6) = -1;
74 %neg_ind = find(ENBI < -1);
75 %[ind,col] = ind2sub(size(ENBI), neg_ind);
76 %ENBI(neg_ind) = ENBI(sub2ind(size(ENBI), ind, col - 3));
78 %ENBI(find(ENBI == 0)) = -1;
81 hashind = gethash(hasharray, hashes);
85 if(~( isempty(hashind)))
86 warning('enbi:cache:redundance
','two identical hashvalues
');
87 % if(max(max([P1cache.(hashvalue){:}] ~= [P1res{:}]))==1 || ...
88 % max(max([P2cache.(hashvalue){:}] ~= [P2res{:}]))==1)
89 if(max(max(Ecache{hashind} ~= ENBI)) == 1)
90 error('WARNING: hashfunction is not good enough!!!
');
93 hashind = length(Ecache)+1;
94 hashes{hashind} = hasharray;
95 Ecache{hashind} = ENBI;
101 hashind = gethash(hasharray, hashes);
102 ENBI = Ecache{hashind};
106 function [ind]=gethash(X,hashes)
107 ind = find(cellfun(@(y)(all(y==X)), hashes));