rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
grid_reshape.m
1 function grid_reshaped = grid_reshape(model,grid)
2 % function grid_reshaped = grid_reshape(model,grid)
3 %
4 %
5 % input:
6 % grid: triagrid
7 % model
8 %
9 % required fields of model:
10 % pmacro: list of the points of the macro-triangulation
11 % tmacro: vertex-list of the macro-triangles
12 % mu_names: array with the names of the parameters (should be even numbers
13 % of parameters)
14 %
15 % output:
16 % grid: reshaped triagrid
17 %
18 % function is reshaping a grid, according to the mus set in the model.
19 % that means the macrogrid is transformed, and all the points of the grid
20 % are transformed acoording to the corresponding corresponding
21 % transformation of the macrogrid they belong to.
22 %
23 % Oliver Zeeb, 09.02.11
24 
25 %disp('in grid_reshape.m: be careful! grid is corrupted afterwards!!! only use for plotting!')
26 nr_macro_tri = size(model.tmacro,1);
27 nr_mus = length(model.mu_names);
28 pmacro_ref = model.pmacro; % points of the reference macrogrid
29 pmacro_reshaped = model.pmacro; % coordinates of the reshaped macrogrid
30 tmacro = model.tmacro;
31 
32 for k=1:length(model.mu_names)
33  position_in_pmacro = str2double(model.mu_names{k}(2));
34  x_or_y = model.mu_names{k}(1);
35  if x_or_y == 'x'
36  x_or_y = 1;
37  elseif x_or_y == 'y'
38  x_or_y = 2;
39  else
40  error('unknown entry in model.mu_names');
41  end
42  mu_k = getfield(model, model.mu_names{k});
43  pmacro_reshaped(position_in_pmacro,x_or_y) = mu_k;
44 end
45 
46 %get the affine transformation for every macrogrid
47 C = zeros(2,nr_macro_tri);
48 G = zeros(2,2,nr_macro_tri);
49 for k=1:nr_macro_tri
50  tria_pts_ref = pmacro_ref(tmacro(k,:),:);
51  tria_pts_reshaped = pmacro_reshaped(tmacro(k,:),:);
52  [C(:,k), G(:,:,k)] = aff_trafo_coef(tria_pts_ref, tria_pts_reshaped);
53 end
54 
55 %which point of the microgrid belongs to which macrotriangle?
56 pmic2tmac = pmicro2tmacro([grid.X,grid.Y], model);
57 
58 % transform every point of the microgrid with the corresponding affine trafo
59 pts_micro_reshaped = [grid.X'; grid.Y'];
60 for k = 1:nr_macro_tri
61  pts_micro_reshaped(:,pmic2tmac==k) = repmat(C(:,k),1,length(pts_micro_reshaped(pmic2tmac==k)))...
62  + G(:,:,k)*pts_micro_reshaped(:,pmic2tmac==k);
63 end
64 
65 
66 %%%%%%%%%%%%%%%%%%%%%%%
67 %%% LIKE THIS, NOT A REAL NEW GRID IS GENERATED!
68 %%% e.g. A and A_inv are not touched and therefore are wrong for the ne
69 %%% grid
70 %%% BUT STILL SUFFICIENT FOR ONLY PLOTTING A GRID!!!
71 %%%%%%%%%%%%%%%%%%%%%%%
72 grid_reshaped = triagrid(grid);
73 grid_reshaped.X = pts_micro_reshaped(1,:)';
74 grid_reshaped.Y = pts_micro_reshaped(2,:)';
75 
76 % coordinates of vertices: XX(elnum, vnum)
77 XX = reshape(grid_reshaped.X(grid_reshaped.VI(:)),size(grid_reshaped.VI));
78 YY = reshape(grid_reshaped.Y(grid_reshaped.VI(:)),size(grid_reshaped.VI));
79 grid_reshaped.CX = mean(XX,2);
80 grid_reshaped.CY = mean(YY,2);
X
vector of vertex x-coordinates
Definition: gridbase.m:74
Y
vector of vertex y-coordinates
Definition: gridbase.m:81
A triangular conforming grid in two dimensions.
Definition: triagrid.m:17