rbmatlab 0.10.01
|
00001 function micro2macro = micro2macro_map(microgrid, macrogrid) 00002 %function micro2macro = micro2macro_map(model, grid) 00003 % function defining a vector micro2macro containing the information 00004 % which triangle of the microgrid lies in which triangle of the 00005 % macrogrid, defined in the model 00006 % micro2macro(5) = 7 means that micro-triangle nr 5 00007 % lies in macro-triangle nr 7 00008 % 00009 % microgrid and macrogrid must be triagrid 00010 % 00011 % Oliver Zeeb, 01.02.11 00012 00013 micro2macro = zeros(microgrid.nelements,1); 00014 00015 pmacro_x = macrogrid.X; 00016 pmacro_y = macrogrid.Y; 00017 tmacro = macrogrid.VI; 00018 nr_macro_tri =macrogrid.nelements; %nr of macro-triangles 00019 00020 pmicro_x = microgrid.X; 00021 pmicro_y = microgrid.Y; 00022 00023 %dummy matrices for the affine transfomation from original macro triangle 00024 %to reference triangle 00025 C=zeros(2,nr_macro_tri); 00026 G=zeros(2,2,nr_macro_tri); 00027 00028 % get all the transformations of the macrotriangles to the 00029 % reference-triangle: 00030 for k=1:nr_macro_tri 00031 tria_pts_x = pmacro_x(tmacro(k,:),:); 00032 tria_pts_y = pmacro_y(tmacro(k,:),:); 00033 [C(:,k), G(:,:,k)] = aff_trafo_orig2ref(tria_pts_x, tria_pts_y); 00034 end 00035 00036 %check which point is in which macrotriangle 00037 for macro_element_id = 1:nr_macro_tri 00038 pts_in_mac_tri = zeros(1,microgrid.nvertices); 00039 C_big = repmat(C(:,macro_element_id),1,microgrid.nvertices); 00040 pts_ref_dom = C_big + G(:,:,macro_element_id)*[pmicro_x'; pmicro_y']; %transform all points 00041 %check, which of the transformed points are in the reference triangle: 00042 % CAREFUL!!! See the "eps"! The comparison, wheter a value ist bigger 0 00043 % or smaller 1 is a bit sloppy... 00044 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); 00045 %original (mathematically correct, but unfortunatelly not working 00046 %correctly...): 00047 %i=(pts_ref_dom(1,:)>=0 & pts_ref_dom(2,:)>=0 & pts_ref_dom(1,:)+pts_ref_dom(2,:)<=1); 00048 pts_in_mac_tri(i)=1; %index of the points in macro-triangle k 00049 00050 %check, for which microtriangle all the vertices are in the macro-tringle: 00051 % if all 3 vertices of the transformed mirotriangle are in the 00052 % standard-triangle, then this microtriangle lies in the macrotriangle 00053 bool_mat = zeros(size(microgrid.VI)); 00054 bool_mat(:,:) = pts_in_mac_tri(microgrid.VI(:,:)); 00055 %bool_mat is a matrix of triangles with entry = 1 if the corresponding point 00056 %is in the reference triangle, so the original point is in the 00057 %macro-triangle and entry = 0 if the correspondong point is not in 00058 %the macro tiangle 00059 mic_in_mac_triangle=(bool_mat(:,1)==1 & bool_mat(:,2)==1 & bool_mat(:,3)==1); 00060 % entry of mic_in_mac_triangle is 1, if all three vertices are in the standard triangle 00061 % else it is 0 00062 micro2macro = micro2macro + macro_element_id.* mic_in_mac_triangle; 00063 end 00064