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