5 % Online rb simulation by online greedy minimizing redidual norm
6 % over dictionary, or normal RB simulation:
8 % model.rb_online_mode: 0 standard rb, no adaptivity
9 % model.rb_online_mode: 1 Delta-extended indicator
for online extension
11 % B. Haasdonk 5.3.2015
13 % prepare mu-dependent quantities
17 old_mode = model.decomp_mode;
18 model.decomp_mode = 2; % coefficients
20 tic; % measure linear combination time
22 [a_coeff,f_coeff] = ...
23 model.operators(model,[]);
25 AN = lincomb_sequence(reduced_data.AN_comp, a_coeff);
26 fN = lincomb_sequence(reduced_data.fN_comp, f_coeff);
31 % transform G matrix, such that later simple mult:
32 % G_mu matrix has <vf,vf>, <vf,va_phi_1(mu)> , <vf,va_phi_N>
33 % as first row and column, and <va_phi_i,va_phi_j(mu)> as
35 % the following is the correct code,
if lin_stat_reduced_data is
37 %
if ~isfield(reduced_data,
'used_dictionary_gen_reduced_data');
38 % Saa = kron(speye(N),sparse(1:Qa,1,a_coeff(:),Qa,1));
39 % S = [f_coeff(:), sparse([],[],[],Qf, N); ...
40 % sparse([],[],[], Qa * N, 1), Saa];
41 % G = S
' * reduced_data.G * S;
43 Hff = f_coeff' * reduced_data.bar_Hff * f_coeff;
44 af_coeff = a_coeff * f_coeff
';
45 Haf = reduced_data.bar_Haf * af_coeff(:);
46 aa_coeff = a_coeff * a_coeff';
47 Haa_vec = reduced_data.bar_Haa * aa_coeff(:);
48 Haa = reshape(Haa_vec,[N,N]);
49 G = [Hff,Haf
'; Haf,Haa];
51 G = 0.5*(G+G'); % G is positive definite.
57 % disp(
'check, whether G has correct entries');
58 % %
get full operators
59 % model.decomp_mode = 0; % complete
61 % model.operators(model,reduced_data);
62 % K = model.get_inner_product_matrix(reduced_data);
66 % va_phi1 = K\(A*reduced_data.RB(:,1));
76 if model.rb_online_mode == 0
77 % standard rb simulation, no online enrichment
79 % the following works with standard lin_stat_gen_reduced_data:
80 % Q_r = size(reduced_data.G,1);
81 % neg_auN_coeff = -A_coeff * uN';
82 % res_coeff = [f_coeff; neg_auN_coeff(:)];
83 % res_norm_sqr = res_coeff
' * reduced_data.G * res_coeff;
84 % this is required for dictionary_gen_reduced_data:
86 res_norm_sqr = res_coeff' * G * res_coeff;
87 res_norm_sqr = max(res_norm_sqr,0);
88 res_norm = sqrt(res_norm_sqr);
89 rb_sim_data.Delta = ...
90 res_norm/model.coercivity_alpha(model);
92 elseif model.rb_online_mode == 1
93 % online enrichment by eta(v) = - Delta_N(v; Phi \cup v)
96 %uN = ones(size(AN,1),1);
98 % run iterative loop of online_greedy by minimum residual
101 current_eps = 1e10; %
do at least one extension
103 non_basis_indices = 1:N;
109 %
if model.RB_online_stop_Nmax == 2
113 if N<model.RB_online_stop_Nmax
114 model.RB_online_stop_Nmax = N;
115 disp([
'warning: dictionary too small, Now decreasing RB_online_stop_Nmax']);
118 while (current_eps > model.RB_stop_epsilon) && (iter < model.RB_online_stop_Nmax)
119 % compute all
new uN vectors at once:
120 a = diag_AN(non_basis_indices)
';
121 bar_a = AN(basis_indices,non_basis_indices);
122 bar_bar_a = AN(non_basis_indices,basis_indices)';
123 % tilde_f = fN(non_basis_indices)
' - sum(bar_bar_a.*UN,1);
124 tilde_f = fN(non_basis_indices)' - uN
' * bar_bar_a;
125 ANinv_bar_a = (ANinv*bar_a);
126 tilde_a = a - sum(bar_bar_a .* ANinv_bar_a,1);
128 UN = uN * ones(1,length(non_basis_indices));
131 UN = [UN; zeros(1,length(non_basis_indices))] ...
132 + [-ANinv_bar_a;ones(1,length(non_basis_indices))] * ...
133 sparse(1:n,1:n,tilde_f./tilde_a,n,n);
134 % spdiag((tilde_f./tilde_a),length(tilde_f));
136 % compute all residualnormssquare at once:
137 G11 = G([1,1+basis_indices],[1,1+basis_indices]);
138 UN1 = [ones(1,length(non_basis_indices)); - UN(1:end-1,:)];
140 G12 = G([1,1+basis_indices],1+non_basis_indices);
142 % g = [G11 * UN1 + G12*spdiag(UN2(:),length(UN2)); ...
143 g = [G11 * UN1 + G12*sparse(1:n,1:n,UN2,n,n); ...
144 sum(G12 .* UN1,1) + diag_G(1+non_basis_indices)'.*UN2];
145 resnormsqr = sum([ones(1,length(non_basis_indices)); - UN] .* g,1);
146 if min(resnormsqr<-1e-2)
147 disp('error: negative residual, inspect workspace!');
148 % test for first vector:
151 % if resnormsqr(3)>1e-10
152 % disp('error: residual for func 3 should be 0!!!');
154 % title('residual norms');
155 % % the following test was successful
156 % % G1 = [G11, G12(:,1); G12(:,1)', diag_G(1+1)];
157 % % g1 = G1 * [1; -UN(:,1)]
159 % % resnormsqr1 = [1; -UN(:,1)]' * G1 * [1; -UN(:,1)]
161 % % G3 = [G11, G12(:,3); G12(:,3)', diag_G(1+3)];
162 % % resnormsqr3 = [1; -UN(:,3)]' * G3 * [1; -UN(:,3)]
167 % set NaN values to very high, in order not set to 0 by clipping:
168 p = find(isnan(resnormsqr));
169 resnormsqr(p) = 1e10;
170 % take positive part to avoid numerical instabilities
171 resnormsqr = max(resnormsqr,0);
173 [minresnormsqr, new_index] = min(resnormsqr);
174 % select one if multiple minima
175 current_eps = sqrt(minresnormsqr(1));
176 eps_sequence = [eps_sequence, current_eps];
177 new_index = new_index(1);
178 % remove new basis vector from search set
179 basis_indices = [basis_indices, non_basis_indices(new_index)];
180 non_basis_indices = [non_basis_indices(1:new_index-1),...
181 non_basis_indices(new_index+1:end)];
182 ANinv = inv(AN(basis_indices,basis_indices));
183 uN = UN(:,new_index);
184 UN = [UN(:,1:new_index-1),UN(:,new_index+1:end)];
187 disp('investigate iteration')
188 % true reduced solution with selected basis vectors of previous
190 detailed_data = reduced_data;
191 detailed_data.RB = detailed_data.RB(:,basis_indices(1:end-1));
192 reduced_data_tmp = gen_reduced_data(model,detailed_data);
193 rb_sim_data_tmp = rb_simulation(model,reduced_data_tmp);
194 disp('correct UN old:')
196 disp('current UN_old:')
198 % UN_new(:,new_index)
200 % true reduced solution with selected basis vectors:
201 detailed_data = reduced_data;
202 detailed_data.RB = detailed_data.RB(:,basis_indices);
203 reduced_data_tmp = gen_reduced_data(model,detailed_data);
204 rb_sim_data_tmp = rb_simulation(model,reduced_data_tmp);
209 % UN_new(:,new_index)
212 %disp('recomputed current uN')
213 %uN_new = [uN_old; 0] + tilde_f(new_index)/tilde_a(new_index)*[-ANinv_bar_a(:,new_index);1]
222 rb_sim_data.eps_sequence = eps_sequence;
223 rb_sim_data.basis_indices = basis_indices;
224 rb_sim_data.iter = iter;
225 rb_sim_data.current_eps = current_eps;
226 rb_sim_data.Delta = ...
227 current_eps/model.coercivity_alpha(model);
228 end; % rb_online_mode
233 rb_sim_data.t_lincomb = t_lincomb;
234 rb_sim_data.t_solution = t_solution;
236 model.decomp_mode = old_mode;
function rb_sim_data = dictionary_rb_simulation(model, reduced_data)
Online rb simulation by online greedy minimizing redidual norm over dictionary, or normal RB simulati...