1 function grid_reshaped = grid_reshape(model,grid)
2 %
function grid_reshaped = grid_reshape(model,grid)
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
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.
23 % Oliver Zeeb, 09.02.11
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;
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);
40 error(
'unknown entry in model.mu_names');
42 mu_k = getfield(model, model.mu_names{k});
43 pmacro_reshaped(position_in_pmacro,x_or_y) = mu_k;
46 %
get the affine transformation
for every macrogrid
47 C = zeros(2,nr_macro_tri);
48 G = zeros(2,2,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);
55 %which point of the microgrid belongs to which macrotriangle?
56 pmic2tmac = pmicro2tmacro([grid.
X,grid.
Y], model);
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);
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
70 %%% BUT STILL SUFFICIENT FOR ONLY PLOTTING A GRID!!!
71 %%%%%%%%%%%%%%%%%%%%%%%
73 grid_reshaped.X = pts_micro_reshaped(1,:)
';
74 grid_reshaped.Y = pts_micro_reshaped(2,:)';
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
Y
vector of vertex y-coordinates
A triangular conforming grid in two dimensions.