1 function pmic2tmac = pmicro2tmacro(glob,model)
2 %
function pmic2tmac = pmicro2tmacro(glob,model)
4 %
function defining a vector pmic2tmac containing the information
5 % which point of the vector glob lies in which triangle of the
7 % pmic2tmac(5) = 7 means that the 5th point in glob (glob(5,:)
8 % lies in macro-triangle nr 7
12 % glob : n-by-2 vector with the coordinates of the points
15 % mic2mac : n-by-1 vector
17 % see also
function micro2macro_map, which does the same fot microtriangles
18 % instead of single points
20 % Oliver Zeeb, 08.02.11
22 grid=
triagrid(model.pmacro
',model.tmacro',[]);
25 pmic2tmac = zeros(size(glob,1),1);
30 nr_macro_tri =grid.nelements; %nr of macro-triangles
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);
40 %
get all the transformations of the macrotriangles to the
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);
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
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
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;
69 if length(find(pmic2tmac == 0)) >= 1
70 warning(
'for some points, no corresponding macrotriangle was found. maybe they are not in the domain')
X
vector of vertex x-coordinates
A triangular conforming grid in two dimensions.