rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
get.m
1 function ret = get(grid,propertyname, varargin)
2 %function ret = get(grid,propertyname, varargin)
3 % get-method for cubegrids
4 %
5 % Parameters:
6 % propertyname: A property name of the grid which can be one of the following
7 % - 'level' : get vector of levels of all elements
8 % - 'dimension' : get dimension of grid
9 % - 'nvertices' : get number of vertices of grid
10 % - 'nelements' : get number of elements of grid
11 % - 'isleaf' : get vector of isleaf-indices of all elements
12 % - 'vertexindex' returns a matrix '(i,j)' index of 'j'-th vertex of element 'i'
13 % a further optional argument with element indices can be passed,
14 % then only the vertices of these elements are returned,
15 % @code get(grid,'vertexindex',[2,3]) @endcode returns a
16 % '2 x nvertices_per_element' matrix with indices
17 % - 'vertex' : returns a matrix of all vertex coordinates, i.e.
18 % ret(i,j) => j-th coordinate of i-th vertex point
19 % optionally, a subset of vertex-indices can be determined as
20 % further parameter, i.e.
21 % @code get(grid,'vertex',[2 3 4]) @endcode produces a '3 x dim'
22 % matrix with the coordinates of the points
23 % .
24 % or property can be equal to one of the following strings returning
25 % quantities which are derived from the above grid properties
26 % - 'nleafelements' : get number of leaf elements of grid
27 % - 'leafelements' : get vector of indices of elements that are leaf elements
28 % - 'leafcogs' : returns a matrix of all centers of gravity of the leaf
29 % elements. 'ret(i,j)' is the 'j'-th coordinate of the 'i'-th leaf
30 % element
31 % varargin: An optional list of arguments as described above.
32 
33 % Bernard Haasdonk 1.3.2007
34 
35  if nargin <2
36  help('cubegrid/get');
37  return;
38  end;
39 
40  switch lower(propertyname)
41  case 'level'
42  ret = grid.level;
43  case 'dimension'
44  ret = grid.dimension;
45  case 'nvertices'
46  ret = grid.nvertices;
47  case 'nelements'
48  ret = grid.nelements;
49  case 'nleafelements'
50  ret = sum(grid.isleaf);
51  case 'isleaf'
52  ret = grid.isleaf;
53  case 'range'
54  ret = grid.range;
55  case 'numintervals'
56  ret = grid.numintervals;
57  case 'vertexindex'
58  if nargin <= 2
59  ids = 1:grid.nelements;
60  else
61  ids = varargin{1};
62  end;
63  ret = grid.vertexindex(ids,:);
64  case 'vertex'
65  if nargin <= 2
66  ids = 1:grid.nvertices;
67  else
68  ids = varargin{1};
69  end;
70  ret = grid.vertex(ids,:);
71  case 'leafelements'
72  ret = find(grid.isleaf);
73  case 'leafcogs'
74  nleafelements = sum(grid.isleaf);
75  ids = 1:nleafelements;
76  ret = zeros(nleafelements,grid.dimension);
77  leafvind = grid.vertexindex(find(grid.isleaf),:);
78  leafv = leafvind(:);
79  % fill all components of ret:
80  for i = 1:size(ret,2)
81  C = grid.vertex(leafv,i);
82  CC = reshape(C,size(leafvind));
83  ret(:,i) = mean(CC,2);
84  end;
85  otherwise
86  error('Propertyname not supported!');
87  end;
88 
89 end
90 
Definition: leaf.m:17