rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
coord2leaf_element.m
1 function leaf_element = coord2leaf_element(grid,coord)
2 %function coord2leaf_element(grid,coord)
3 %function giving the leaf_element of a grid where the values of the
4 %coord-vector can be found (coord- can for example be a set of mu-values in
5 %a parameter grid. This function utilizes a `O(log(n))`-search algorithm.
6 %
7 % coord : vector of coord-values (must have same dimension as grid)
8 %
9 %
10 % 15.02.2010 Markus Dihlmann
11 %
12 
13 if(get(grid,'dimension')~=length(coord))
14  leaf_element=-1;
15  error('length of coord-vector doesnt match the dimension of the grid')
16 end
17 
18 dim = length(coord);
19 continue_search = 1;
20 element = 1;
21 
22 % find maximal coordinates of vertexes to identify outer-bound coordinates
23 % of the whole cube.
24 V=get(grid,'vertex');
25 max=V(1,:);
26 for i=1:dim
27  for j=1:length(V(:,1))
28  if(max(i)<V(j,i))
29  max(i)=V(j,i);
30  end
31  end
32 end
33 
34 is_leaf = get(grid,'isleaf');
35 
36 while continue_search
37  leaf_element=element;
38  ranges=get_ranges_of_element(grid,leaf_element);
39  sum=0;
40  for i=1:dim
41  if coord(i)<max(i) %if coordinates are not on outer bound of grid
42  if((coord(i)<ranges{i}(2))&&(coord(i)>=ranges{i}(1)))
43  sum = sum+1;
44  end
45  else
46  if((coord(i)<=ranges{i}(2))&&(coord(i)>=ranges{i}(1)))
47  sum=sum+1;
48  end
49  end
50  end
51  if(sum == dim)
52  if is_leaf(element)
53  continue_search=0;
54  else
55  element = grid.firstchild(element);
56  end
57  else
58  element=element+1;
59  end
60 
61  if(element>get(grid,'nelements'))
62  continue_search=0;
63  leaf_element=-1;
64  error('coord- range out of global parameter ranges');
65  end
66 end
67 
68 end
69 
70