rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
lin_ds_gen_reduced_data.m
1 function reduced_data = lin_ds_gen_reduced_data(model,detailed_data)
2 %function reduced_data = lin_ds_gen_reduced_data(model,detailed_data)
3 %
4 % function computing reduced data for rb ds simulation
5 
6 % Bernard Haasdonk 2.4.2009
7 
8 %model.affine_decomp_mode = 'components';
9 
10 %W = detailed_data.W;
11 V = detailed_data.V;
12 Wtrans = detailed_data.W';
13 Vtrans = detailed_data.V';
14 
15 %keyboard;
16 
17 % reduced system matrices:
18 %model.t = 0;
19 x0comp = detailed_data.x0_components;
20 Q_x0 = length(x0comp);
21 x0r = cell(1,Q_x0);
22 for i=1:Q_x0
23  x0r{i} = Wtrans * x0comp{i};
24 end;
25 
26 %Acomp = model.A_function_ptr(model);
27 Acomp = detailed_data.A_components;
28 Q_A = length(Acomp);
29 Ar = cell(1,Q_A);
30 for i=1:Q_A
31  Ar{i} = Wtrans * Acomp{i} * detailed_data.V;
32 end;
33 
34 %Bcomp = model.B_function_ptr(model);
35 Bcomp = detailed_data.B_components;
36 Q_B = length(Bcomp);
37 Br = cell(1,Q_B);
38 for i=1:Q_B
39  Br{i} = Wtrans * Bcomp{i};
40 end;
41 
42 %Ccomp = model.C_function_ptr(model);
43 Ccomp = detailed_data.C_components;
44 Q_C = length(Ccomp);
45 Cr = cell(1,Q_C);
46 for i=1:Q_C
47  Cr{i} = Ccomp{i}*detailed_data.V;
48 end;
49 
50 if model.enable_error_estimator
51 
52  % error estimator matrices:
53  M1 = cell(Q_A,Q_A);
54  for q1=1:Q_A
55  for q2=1:Q_A
56  M1{q1,q2} = Vtrans*(Acomp{q1}')*detailed_data.G*Acomp{q2}*detailed_data.V;
57  end;
58  end;
59 
60  M2 = cell(Q_B,Q_B);
61  for q1=1:Q_B
62  for q2=1:Q_B
63  M2{q1,q2} = (Bcomp{q1}')*detailed_data.G*Bcomp{q2};
64  end;
65  end;
66 
67  % M3 is single matrix
68  M3 = Vtrans * detailed_data.G * detailed_data.V;
69 
70  M4 = cell(Q_B,Q_A);
71  for q1=1:Q_B
72  for q2=1:Q_A
73  M4{q1,q2} = (Bcomp{q1}')*detailed_data.G*Acomp{q2}*detailed_data.V;
74  end;
75  end;
76 
77  M5 = cell(1,Q_A);
78  for q=1:Q_A
79  M5{q} = Vtrans * detailed_data.G * Acomp{q}*detailed_data.V;
80  end;
81 
82  M6= cell(1,Q_B);
83  for q=1:Q_B
84  M6{q} = Vtrans * detailed_data.G * Bcomp{q};
85  end;
86 
87  %m = cell(Q_x0,Q_x0);
88  %I_minVW = speye(size(detailed_data.V,1))- detailed_data.V*Wtrans;
89  %Mtemp = I_minVW' * detailed_data.G * I_minVW;
90  %for q1=1:Q_x0
91  % for q2=1:Q_x0
92  % m{q1,q2} = x0comp{q1}'*Mtemp*x0comp{q2};
93  % end;
94  %end;
95 
96  % instead of large dense matrix allocation equivalent:
97  % a' Mtemp b =
98  % a' G b - (a' W) (V' G b) - (a' G V) (W' b) + (a' W) (V' G V) (W' b)
99  %
100  % these components can not be summed up here,
101  % as we must be able to extract online data for other reduced dimensions!!!
102  % hence no longer computation of m here
103  % but decomposition as follows:
104  %
105  % m00: 2d cell array of values x0{q}'G x0{q'}
106  % VtGx0: 1d cell array of of vectors (V' G x0{q})
107  % Wtx0: 1d cell array of of vectors (W' x0{q})
108  % VtGV : matrix V' G V
109  %
110  % then in rb_simulation the above sum can be easily performed
111 
112  G = detailed_data.G;
113 
114  m00 = cell(Q_x0,Q_x0);
115  VtGx0 = cell(1,Q_x0);
116  Wtx0 = cell(1,Q_x0);
117  for q1=1:Q_x0
118  v1 = x0comp{q1};
119  for q2=1:Q_x0
120  v2 = x0comp{q2};
121  % m{q1,q2} = x0comp{q1}'*Mtemp*x0comp{q2};
122  % m{q1,q2} = v1t * G * v2 - (v1t * W) * (Vtrans * G * v2) ...
123  % - (v1t * G * V) * (Wtrans * v2) ...
124  % + (v1t * W) * (Vtrans * G * V) * (Wtrans * v2);
125  m00{q1,q2}= v1'*G*v2;
126  end;
127  VtGx0{q1} = Vtrans * G * v1;
128  Wtx0{q1} = Wtrans * v1;
129  end;
130  VtGV = Vtrans * G * V;
131 end;
132 
133 reduced_data.x0r = x0r;
134 reduced_data.Ar = Ar;
135 reduced_data.Br = Br;
136 reduced_data.Cr = Cr;
137 reduced_data.N = size(V,2);
138 
139 if model.enable_error_estimator
140  reduced_data.M1 = M1;
141  reduced_data.M2 = M2;
142  reduced_data.M3 = M3;
143  reduced_data.M4 = M4;
144  reduced_data.M5 = M5;
145  reduced_data.M6 = M6;
146  %reduced_data.m = m;
147  reduced_data.m00 = m00; %: 2d cell array of values x0{q}'G x0{q'}
148  reduced_data.VtGx0 = VtGx0; %: 1d cell array of of vectors (V' G x0{q})
149  reduced_data.Wtx0 = Wtx0; %: 1d cell array of of vectors (W' x0{q})
150  reduced_data.VtGV = VtGV; %: matrix V' G V
151 end;
152