rbmatlab  1.13.10
 All Classes Namespaces Files Functions Variables Groups Pages
lin_stat_rb_simulation.m
1 function rb_sim_data = lin_stat_rb_simulation(model,reduced_data)
2 %function rb_sim_data = lin_stat_rb_simulation(model,reduced_data)
3 %
4 % function performing a reduced simulation
5 
6 % B. Haasdonk 22.2.2011
7 
8 rb_sim_data =[];
9 
10 old_mode = model.decomp_mode;
11 model.decomp_mode = 2; % coefficients
12 
13 [A_coeff,f_coeff] = ...
14  model.operators(model,[]);
15 
16 AN = lincomb_sequence(reduced_data.AN_comp, A_coeff);
17 fN = lincomb_sequence(reduced_data.fN_comp, f_coeff);
18 
19 % solution variable:
20 %uh = femdiscfunc([],model_data.df_info);
21 %uh.dofs = A\r;
22 uN = AN\fN;
23 
24 % return results:
25 rb_sim_data.uN = uN;
26 
27 % plus error estimator
28 % res_norm = ... % residual norm
29 
30 % for elliptic compliant case, X-norm (=H10-norm) error estimator:
31 Q_r = size(reduced_data.G,1);
32 neg_auN_coeff = -A_coeff * uN';
33 res_coeff = [f_coeff; neg_auN_coeff(:)];
34 res_norm_sqr = res_coeff' * reduced_data.G * res_coeff;
35 
36 % direct computation (expensive):
37 if 0
38  % for debugging:
39  neg_auN_coeff = neg_auN_coeff(:);
40  Q_f = length(f_coeff);
41  res_norm_sqr_ff = f_coeff' * reduced_data.G(1:Q_f,1:Q_f) * f_coeff;
42  res_norm_sqr_fAu = f_coeff' * reduced_data.G(1:Q_f,(Q_f+1):end) * neg_auN_coeff;
43  res_norm_sqr_Auf = neg_auN_coeff' * reduced_data.G((Q_f+1):end,1:Q_f) * f_coeff;
44  res_norm_sqr_AuAu = neg_auN_coeff' * reduced_data.G((Q_f+1):end,(Q_f+1):end) * neg_auN_coeff;
45 
46  model_data = gen_model_data(model);
47  detailed_data = gen_detailed_data(model,model_data);
48  model.decomp_mode = 0;
49  [A,f] = model.operators(model,model_data);
50  model.decomp_mode = 2;
51  resAu = A * (detailed_data.RB(:,1:model.N) * uN);
52  resf = -f;
53  res = resAu + resf;
54  % residuum functional is res * v
55  % riesz representant: v_r' K v = (v_r,v) = res*v
56  % so res = K * v_r;
57  K = model.get_inner_product_matrix(detailed_data);
58  v_r = K \ res;
59  v_rAu = K \ resAu;
60  v_rf= K \ resf;
61  % res_norm_sqr = (v_r,v_r) = v_r' K v_r = v_r' * res;
62  res_norm_sqr2 = v_r' * res;
63  res_norm_sqr2_ff = v_rf' * resf;
64  res_norm_sqr2_fAu = v_rf' * resAu;
65  res_norm_sqr2_Auf = v_rAu' * resf;
66  res_norm_sqr2_AuAu = v_rAu' * resAu;
67  keyboard;
68 end;
69 
70 % prevent possibly negative numerical disturbances:
71 res_norm_sqr = max(res_norm_sqr,0);
72 res_norm = sqrt(res_norm_sqr);
73 % if the SCM is being used perform an online-phase and use the resulting
74 % lower bound. Otherwise use the old code.
75 if model.use_scm == 0
76  rb_sim_data.Delta = ...
77  res_norm/model.coercivity_alpha(model);
78  rb_sim_data.Delta_s = ...
79  res_norm_sqr/model.coercivity_alpha(model);
80 elseif model.use_scm == 1
81  if ~isfield(reduced_data, 'scm_offline_data')
82  error('There are no scm_offline_data to work with. They must be included in the reduced_data!')
83  end
84  constant_LB = scm_lower_bound(model, reduced_data);
85  rb_sim_data.Delta = ...
86  res_norm/constant_LB;
87  rb_sim_data.Delta_s = ...
88  res_norm_sqr/constant_LB;
89 end
90 
91 if model.compute_output_functional
92  % get operators
93  l_coeff = ...
94  model.operators_output(model,reduced_data);
95  lN = ...
96  lincomb_sequence(reduced_data.lN_comp,l_coeff);
97  rb_sim_data.s = lN(:)' * rb_sim_data.uN;
98  % rb_sim_data.Delta_s = ...;
99 end;
100 
101 model.decomp_mode = old_mode;