rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
rb_simulation.m
1 function rbsim = rb_simulation(model, reduced_data)
2 % RB_SIMULATION Perform a reduced simulation
3 %
4 % Andreas Schmidt, 2015
5 tsim = tic;
6 [E,A,B,C,Q,R] = model.assemble(reduced_data);
7 
8 if norm(E - eye(size(E))) < 1e-8
9  PN = care(A,B,C'*Q*C,R);
10 else
11  PN = care(A,B,C'*Q*C,R,0*B,E);
12 end
13 
14 rbsim = ARE.RBSimData;
15 rbsim.PN = PN;
16 rbsim.time_sim = toc(tsim);
17 
18 % Calculate the residual if necessary:
19 if model.calc_residual
20  testim = tic;
21  tResidual = tic;
22  [n,nn,nnn] = model.rb_residual_norm(reduced_data, rbsim);
23  tResidual = toc(tResidual);
24 
25  rbsim.time_residual = tResidual;
26 
27  rbsim.residual = n;
28  rbsim.nresidual = nn;
29  rbsim.nnresidual = nnn;
30 end
31 
32 % If the error estimator is enabled, calculate the stuff:
33 if model.enable_error_estimator
34  if isempty(reduced_data.gamma_function)
35  warning('Cannot perform error estimation as no suitable gamma function was specified')
36  return;
37  end
38 
39  if ~strcmp(reduced_data.gamma_mode, model.gamma_mode)
40  warning('rbmatlab:are:gamma_mode_changed', 'The gamma mode in the ReducedData class is different from the gamma mode in the Model class!');
41  end
42 
43  tGamma = tic;
44  gamma = reduced_data.gamma_function(model, reduced_data, rbsim);
45  tGamma = toc(tGamma);
46 
47  rbsim.gamma = gamma;
48  rbsim.time_gamma = tGamma;
49 
50  normBRinvBt = 1;%norm(full(B))^2*norm(inv(R));
51  L = 2*reduced_data.estim.normE^2*normBRinvBt;
52  rbsim.L = L;
53 
54  rbsim.validity_crit = 4*gamma^2*rbsim.residual*L;
55  rbsim.valid = rbsim.validity_crit <= 1;
56 
57  rbsim.error_estimate = 1/2/gamma/L*(1 - sqrt( 1 - rbsim.validity_crit ));
58  rbsim.stab_crit = rbsim.error_estimate*2*gamma*normBRinvBt*reduced_data.estim.normE/reduced_data.estim.normEinv;
59  rbsim.stable = rbsim.stab_crit < 1;
60 
61  rbsim.time_errorestim = toc(testim);
62 end
MODEL Abstract model class.
Definition: Model.m:18
PN
The reduced solution NxN matrix.
Definition: RBSimData.m:27
Implementation of the parametric algebraic Riccati equation.