rbmatlab  1.13.10
 All Classes Namespaces Files Functions Variables Groups Pages
dom_dec_gen_reduced_data.m
1 function reduced_data = dom_dec_gen_reduced_data(model, ...
2  detailed_data)
3 % function reduced_data = dom_dec_reduced_data(model,detailed_data)
4 %
5 % all required offline data for the rb-simulation is computed.
6 % there are two ingredients for the error estimator - the jump
7 % across `\Gamma` and the residuum.
8 %
9 % the computation of residuum-components needs
10 % Q_f+N1*Q_A1+N2*Q_A2 detailed simulations. the number of
11 % iterations is very high there, because the accuracy of the error
12 % estimator is good then. therefore very expensive computations.
13 %
14 % Generated fields of reduced_data:
15 % AN_comp: nested cell containing the components of the system matrizes
16 % for the subproblems
17 % fN_comp: nested cell containing the components of the right hand
18 % side vectors for the subproblems
19 % R_11, R_12, R_22: matrizes for the computation of the jump
20 % across `\Gamma` component of the error estimator
21 % G: cell containing the matrizes for the residuum component
22 % N: cell with the dimensions of the RB spaces
23 % I_0, I_G: cells with index vectors of `0` and `\Gamma` spaces
24 
25 % I.Maier, 19.07.2011
26 
27 dir = model.dirichlet_side;
28 no_dir = mod(dir,2)+1;
29 
30 reduced_data = [];
31 
32 model.decomp_mode = 1;
33 
34 % A_comp and f_comp are nested cells!
35 [A_comp, f_comp, dummy1, dummy2] = ...
36  model.operators(model,detailed_data);
37 
38 % number of matrix/vector components
39 Q_A = cell(1,2);
40 Q_f = cell(1,2);
41 N = cell(1,2);
42 for i = 1:2
43  Q_A{i} = length(A_comp{i});
44  Q_f{i} = length(f_comp{i});
45 
46  N{i} = size(detailed_data.RB{i},2);
47 end;
48 
49 reduced_data.N = N;
50 reduced_data.I_0 = detailed_data.I_0;
51 reduced_data.I_G = detailed_data.I_G;
52 
53 reduced_data.AN_comp = cell(1,2);
54 reduced_data.fN_comp = cell(1,2);
55 
56 for i = 1:2
57  reduced_data.AN_comp{i} = cell(1,Q_A{i});
58  for q = 1:Q_A{i}
59  reduced_data.AN_comp{i}{q} = detailed_data.RB{i}' * ...
60  A_comp{i}{q} * detailed_data.RB{i};
61  end;
62 
63  reduced_data.fN_comp{i} = cell(1,Q_f{i});
64  for q = 1:Q_f{i}
65  reduced_data.fN_comp{i}{q} = detailed_data.RB{i}' * ...
66  f_comp{i}{q};
67  end;
68 end;
69 
70 % error estimation quantities
71 K = model.get_inner_product_matrices(detailed_data);
72 
73 %%%%%%%%%%% computation of extension matrizes
74 
75 RB_ext = cell(1,2);
76 % trivial finite element extension
77 for i = 1:2
78  RB_ext{i} = zeros(size(detailed_data.RB{dir},1), ...
79  size(detailed_data.RB{i},2));
80  RB_ext{i}(detailed_data.gamma_dofs{dir},:) = ...
81  detailed_data.RB{i}(detailed_data.gamma_dofs{i},:);
82 end;
83 reduced_data.R_11 = RB_ext{dir}' * K{dir} * RB_ext{dir};
84 reduced_data.R_12 = RB_ext{dir}' * K{dir} * RB_ext{no_dir};
85 reduced_data.R_22 = RB_ext{no_dir}' * K{dir} * RB_ext{no_dir};
86 
87 %%%%%%%%%%%%% computation of residuum-components
88 % perform a detailed simulation for each component
89 
90 model.verbose = 0;
91 
92 res_mat = cell(1,2);
93 res_rhs = cell(1,2);
94 for i = 1:2
95  res_mat{i} = K{i};
96  dir_gids = detailed_data.df_infos{i}.dirichlet_gids;
97  mat_dir = sparse(dir_gids,dir_gids,ones(size(dir_gids)), ...
98  detailed_data.df_infos{i}.ndofs, ...
99  detailed_data.df_infos{i}.ndofs);
100  res_mat{i}(dir_gids,:) = 0;
101  res_mat{i} = res_mat{i} + mat_dir;
102 end;
103 clear('mat_dir');
104 
105 % assume Q_f{1}=Q_f{2}
106 % v_f has one part on each domain
107 v_f = cell(1,2);
108 for i = 1:2
109  v_f{i} = zeros(size(res_mat{i},1),Q_f{i});
110 end;
111 
112 for q = 1:Q_f{1}
113  if any(f_comp{1}{q}) || any(f_comp{2}{q})
114 
115  % prepare detailed simulation
116  detailed_data.operators = @(j) deal(res_mat{j}, f_comp{j}{q});
117 
118  % detailed simulation
119  sim_data = detailed_simulation(model,detailed_data);
120  if sim_data.reached_maxiter
121  warning('detailed simulation may have diverged!');
122  end;
123  for i = 1:2
124  v_f{i}(:,q) = sim_data.uh{i}.dofs;
125  end;
126 
127  end;
128 end;
129 
130 % two different right hand sides for v_a
131 % (v_a{1}{m},phi) = a_1(phi_N^m,phi)
132 % (v_a{2}{m},phi) = a_2(phi_N^m,phi)
133 v_a = cell(1,2);
134 for i = 1:2
135 
136  v_a{i} = cell(1,N{i});
137  for m = 1:N{i}
138 
139  % v_a{i}{m} has one part on each domain
140  v_a{i}{m} = cell(1,2);
141  for j = 1:2
142  v_a{i}{m}{j} = zeros(size(res_mat{j},1),Q_A{i});
143  end;
144 
145  for q = 1:Q_A{i}
146  if any(any(A_comp{i}{q}))
147 
148  % prepare detailed simulation
149  res_rhs{i} = A_comp{i}{q} * detailed_data.RB{i}(:,m);
150  res_rhs{mod(i,2)+1} = zeros(size(res_mat{mod(i,2)+1},1),1);
151  detailed_data.operators = @(j) deal(res_mat{j}, ...
152  res_rhs{j});
153 
154  % detailed simulation
155  sim_data = detailed_simulation(model,detailed_data);
156  if sim_data.reached_maxiter
157  warning('detailed simulation may have diverged!');
158  end;
159  for j = 1:2
160  v_a{i}{m}{j}(:,q) = sim_data.uh{j}.dofs;
161  end;
162 
163  end;
164  end;
165 
166  end;
167 end;
168 
169 reduced_data.G = cell(1,2);
170 
171 % two matrizes G (same procedure as in lin_stat_gen_reduced_data)
172 for i = 1:2
173 
174  Gff = v_f{i}' * K{i} * v_f{i};
175 
176  Gfa1 = cell(1,N{1});
177  for n = 1:N{1}
178  Gfa1{n} = v_f{i}' * K{i} * v_a{1}{n}{i};
179  end;
180  Gfa2 = cell(1,N{2});
181  for n = 1:N{2}
182  Gfa2{n} = v_f{i}' * K{i} * v_a{2}{n}{i};
183  end;
184 
185  Ga1a1 = cell(N{1},N{1});
186  for n1 = 1:N{1}
187  for n2 = 1:N{1}
188  Ga1a1{n1,n2} = v_a{1}{n1}{i}' * K{i} * v_a{1}{n2}{i};
189  end;
190  end;
191  Ga1a2 = cell(N{1},N{2});
192  for n1 = 1:N{1}
193  for n2 = 1:N{2}
194  Ga1a2{n1,n2} = v_a{1}{n1}{i}' * K{i} * v_a{2}{n2}{i};
195  end;
196  end;
197  Ga2a2 = cell(N{2},N{2});
198  for n1 = 1:N{2}
199  for n2 = 1:N{2}
200  Ga2a2{n1,n2} = v_a{2}{n1}{i}' * K{i} * v_a{2}{n2}{i};
201  end;
202  end;
203 
204  Q_r = Q_f{1}+N{1}*Q_A{1}+N{2}*Q_A{2};
205  G = zeros(Q_r,Q_r);
206  G(1:Q_f{1},1:Q_f{1}) = Gff;
207  for n = 1:N{1}
208  G(1:Q_f{1},Q_f{1}+(n-1)*Q_A{1}+(1:Q_A{1})) = Gfa1{n};
209  G(Q_f{1}+(n-1)*Q_A{1}+(1:Q_A{1}),1:Q_f{1}) = Gfa1{n}';
210  end;
211  for n = 1:N{2}
212  G(1:Q_f{1},Q_f{1}+N{1}*Q_A{1}+(n-1)*Q_A{2}+(1:Q_A{2})) = ...
213  Gfa2{n};
214  G(Q_f{1}+N{1}*Q_A{1}+(n-1)*Q_A{2}+(1:Q_A{2}),1:Q_f{1}) = ...
215  Gfa2{n}';
216  end;
217  for n1 = 1:N{1}
218  for n2 = 1:N{1}
219  G(Q_f{1}+(n1-1)*Q_A{1}+(1:Q_A{1}),Q_f{1}+(n2-1)*Q_A{1}+(1:Q_A{1})) ...
220  = Ga1a1{n1,n2};
221  end;
222  end;
223 
224  for n1 = 1:N{1}
225  for n2 = 1:N{2}
226  G(Q_f{1}+(n1-1)*Q_A{1}+(1:Q_A{1}),Q_f{1}+N{1}*Q_A{1}+ ...
227  (n2-1)*Q_A{2}+(1:Q_A{2})) = Ga1a2{n1,n2};
228  G(Q_f{1}+N{1}*Q_A{1}+(n2-1)*Q_A{2}+(1:Q_A{2}),Q_f{1}+ ...
229  (n1-1)*Q_A{1}+(1:Q_A{1})) = Ga1a2{n1,n2}';
230  end;
231  end;
232 
233  for n1 = 1:N{2}
234  for n2 = 1:N{2}
235  G(Q_f{1}+N{1}*Q_A{1}+(n1-1)*Q_A{2}+(1:Q_A{2}),Q_f{1}+ ...
236  N{1}*Q_A{1}+(n2-1)*Q_A{2}+(1:Q_A{2})) = Ga2a2{n1,n2};
237  end;
238  end;
239 
240  reduced_data.G{i} = G;
241 
242 end;