rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
pmicro2tmacro.m
1 function pmic2tmac = pmicro2tmacro(glob,model)
2 %function pmic2tmac = pmicro2tmacro(glob,model)
3 %
4 % function defining a vector pmic2tmac containing the information
5 % which point of the vector glob lies in which triangle of the
6 % macrogrid.
7 % pmic2tmac(5) = 7 means that the 5th point in glob (glob(5,:)
8 % lies in macro-triangle nr 7
9 %
10 % input:
11 % grid : triagrid
12 % glob : n-by-2 vector with the coordinates of the points
13 %
14 % output:
15 % mic2mac : n-by-1 vector
16 %
17 % see also function micro2macro_map, which does the same fot microtriangles
18 % instead of single points
19 %
20 % Oliver Zeeb, 08.02.11
21 
22 grid=triagrid(model.pmacro',model.tmacro',[]);
23 
24 
25 pmic2tmac = zeros(size(glob,1),1);
26 
27 pmacro_x = grid.X;
28 pmacro_y = grid.Y;
29 tmacro = grid.VI;
30 nr_macro_tri =grid.nelements; %nr of macro-triangles
31 
32 pmic_x = glob(:,1);
33 pmic_y = glob(:,2);
34 
35 %dummy matrices for the affine transfomation from original macro triangle
36 %to reference triangle
37 C=zeros(2,nr_macro_tri);
38 G=zeros(2,2,nr_macro_tri);
39 
40 % get all the transformations of the macrotriangles to the
41 % standard-triangle:
42 for k=1:nr_macro_tri
43  tria_pts_x = pmacro_x(tmacro(k,:),:);
44  tria_pts_y = pmacro_y(tmacro(k,:),:);
45  [C(:,k), G(:,:,k)] = aff_trafo_glob2loc(tria_pts_x, tria_pts_y);
46 end
47 
48 %check which point is in which macrotriangle
49 for macro_element_id = 1:nr_macro_tri
50  pts_in_mac_tri = zeros(size(glob,1),1);
51  C_big = repmat(C(:,macro_element_id),1,size(glob,1));
52  pts_ref_dom = C_big + G(:,:,macro_element_id)*[pmic_x'; pmic_y']; %transform all points
53  %check, which of the transformed points are in the reference triangle:
54  % CAREFUL!!! See the "eps"! The comparison, wheter a value ist bigger 0
55  % or smaller 1 is a bit sloppy...
56  i=(pts_ref_dom(1,:)>=0-10*eps & pts_ref_dom(2,:)>=0-10*eps & pts_ref_dom(1,:)+pts_ref_dom(2,:)<=1+10*eps);
57  %original (mathematically correct, but unfortunatelly not working
58  %correctly...):
59  %i=(pts_ref_dom(1,:)>=0 & pts_ref_dom(2,:)>=0 & pts_ref_dom(1,:)+pts_ref_dom(2,:)<=1);
60  pts_in_mac_tri(i)=1; %index of the points in macro-triangle k
61 
62  % sort out those points, which are already in another triangle,
63  % e.g. those which are on the edge of two triangles
64  pts_in_mac_tri(pmic2tmac > 0) = 0;
65  pmic2tmac = pmic2tmac + macro_element_id.* pts_in_mac_tri;
66 end
67 
68 
69 if length(find(pmic2tmac == 0)) >= 1
70  warning('for some points, no corresponding macrotriangle was found. maybe they are not in the domain')
71 end
X
vector of vertex x-coordinates
Definition: gridbase.m:74
A triangular conforming grid in two dimensions.
Definition: triagrid.m:17