rbmatlab 0.10.01
|
00001 function ret = get(grid,propertyname, varargin) 00002 %function ret = get(grid,propertyname, varargin) 00003 % get-method for cubegrids 00004 % 00005 % Parameters: 00006 % propertyname: A property name of the grid which can be one of the following 00007 % - 'level' : get vector of levels of all elements 00008 % - 'dimension' : get dimension of grid 00009 % - 'nvertices' : get number of vertices of grid 00010 % - 'nelements' : get number of elements of grid 00011 % - 'isleaf' : get vector of isleaf-indices of all elements 00012 % - 'vertexindex' returns a matrix '(i,j)' index of 'j'-th vertex of element 'i' 00013 % a further optional argument with element indices can be passed, 00014 % then only the vertices of these elements are returned, 00015 % @code get(grid,'vertexindex',[2,3]) @endcode returns a 00016 % '2 x nvertices_per_element' matrix with indices 00017 % - 'vertex' : returns a matrix of all vertex coordinates, i.e. 00018 % ret(i,j) => j-th coordinate of i-th vertex point 00019 % optionally, a subset of vertex-indices can be determined as 00020 % further parameter, i.e. 00021 % @code get(grid,'vertex',[2 3 4]) @endcode produces a '3 x dim' 00022 % matrix with the coordinates of the points 00023 % . 00024 % or property can be equal to one of the following strings returning 00025 % quantities which are derived from the above grid properties 00026 % - 'nleafelements' : get number of leaf elements of grid 00027 % - 'leafelements' : get vector of indices of elements that are leaf elements 00028 % - 'leafcogs' : returns a matrix of all centers of gravity of the leaf 00029 % elements. 'ret(i,j)' is the 'j'-th coordinate of the 'i'-th leaf 00030 % element 00031 % varargin: An optional list of arguments as described above. 00032 00033 % Bernard Haasdonk 1.3.2007 00034 00035 if nargin <2 00036 help('cubegrid/get'); 00037 return; 00038 end; 00039 00040 switch lower(propertyname) 00041 case 'level' 00042 ret = grid.level; 00043 case 'dimension' 00044 ret = grid.dimension; 00045 case 'nvertices' 00046 ret = grid.nvertices; 00047 case 'nelements' 00048 ret = grid.nelements; 00049 case 'nleafelements' 00050 ret = sum(grid.isleaf); 00051 case 'isleaf' 00052 ret = grid.isleaf; 00053 case 'range' 00054 ret = grid.range; 00055 case 'numintervals' 00056 ret = grid.numintervals; 00057 case 'vertexindex' 00058 if nargin <= 2 00059 ids = 1:grid.nelements; 00060 else 00061 ids = varargin{1}; 00062 end; 00063 ret = grid.vertexindex(ids,:); 00064 case 'vertex' 00065 if nargin <= 2 00066 ids = 1:grid.nvertices; 00067 else 00068 ids = varargin{1}; 00069 end; 00070 ret = grid.vertex(ids,:); 00071 case 'leafelements' 00072 ret = find(grid.isleaf); 00073 case 'leafcogs' 00074 nleafelements = sum(grid.isleaf); 00075 ids = 1:nleafelements; 00076 ret = zeros(nleafelements,grid.dimension); 00077 leafvind = grid.vertexindex(find(grid.isleaf),:); 00078 leafv = leafvind(:); 00079 % fill all components of ret: 00080 for i = 1:size(ret,2) 00081 C = grid.vertex(leafv,i); 00082 CC = reshape(C,size(leafvind)); 00083 ret(:,i) = mean(CC,2); 00084 end; 00085 otherwise 00086 error('Propertyname not supported!'); 00087 end; 00088 00089 end 00090