1 function micro2macro = micro2macro_map(microgrid, macrogrid)
2 %
function micro2macro = micro2macro_map(model, grid)
3 %
function defining a vector micro2macro containing the information
4 % which triangle of the microgrid lies in which triangle of the
5 % macrogrid, defined in the model
6 % micro2macro(5) = 7 means that micro-triangle nr 5
7 % lies in macro-triangle nr 7
9 % microgrid and macrogrid must be
triagrid
11 % Oliver Zeeb, 01.02.11
13 micro2macro = zeros(microgrid.nelements,1);
15 pmacro_x = macrogrid.X;
16 pmacro_y = macrogrid.Y;
17 tmacro = macrogrid.VI;
18 nr_macro_tri =macrogrid.nelements; %nr of macro-triangles
20 pmicro_x = microgrid.X;
21 pmicro_y = microgrid.Y;
23 %dummy matrices
for the affine transfomation from original macro triangle
24 %to reference triangle
25 C=zeros(2,nr_macro_tri);
26 G=zeros(2,2,nr_macro_tri);
28 %
get all the transformations of the macrotriangles to the
31 tria_pts_x = pmacro_x(tmacro(k,:),:);
32 tria_pts_y = pmacro_y(tmacro(k,:),:);
33 [C(:,k), G(:,:,k)] = aff_trafo_orig2ref(tria_pts_x, tria_pts_y);
36 %check which point is in which macrotriangle
37 for macro_element_id = 1:nr_macro_tri
38 pts_in_mac_tri = zeros(1,microgrid.nvertices);
39 C_big = repmat(C(:,macro_element_id),1,microgrid.nvertices);
40 pts_ref_dom = C_big + G(:,:,macro_element_id)*[pmicro_x
'; pmicro_y']; %transform all points
41 %check, which of the transformed points are in the reference triangle:
42 % CAREFUL!!! See the
"eps"! The comparison, wheter a value ist bigger 0
43 % or smaller 1 is a bit sloppy...
44 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);
45 %original (mathematically correct, but unfortunatelly not working
47 %i=(pts_ref_dom(1,:)>=0 & pts_ref_dom(2,:)>=0 & pts_ref_dom(1,:)+pts_ref_dom(2,:)<=1);
48 pts_in_mac_tri(i)=1; %index of the points in macro-triangle k
50 %check,
for which microtriangle all the vertices are in the macro-tringle:
51 %
if all 3 vertices of the transformed mirotriangle are in the
52 % standard-triangle, then
this microtriangle lies in the macrotriangle
53 bool_mat = zeros(size(microgrid.VI));
54 bool_mat(:,:) = pts_in_mac_tri(microgrid.VI(:,:));
55 %bool_mat is a matrix of triangles with entry = 1
if the corresponding point
56 %is in the reference triangle, so the original point is in the
57 %macro-triangle and entry = 0
if the correspondong point is not in
59 mic_in_mac_triangle=(bool_mat(:,1)==1 & bool_mat(:,2)==1 & bool_mat(:,3)==1);
60 % entry of mic_in_mac_triangle is 1,
if all three vertices are in the standard triangle
62 micro2macro = micro2macro + macro_element_id.* mic_in_mac_triangle;
A triangular conforming grid in two dimensions.