rbmatlab  1.13.10
 All Classes Namespaces Files Functions Variables Groups Pages
rb_test_error.m
1 function test_err = rb_test_error(model,detailed_data,reduced_data,M_test,...
2  savepath)
3 %function test_err = rb_test_error(model,detailed_data,reduced_data,M_test,...
4 % savepath)
5 %
6 % function determining the test-errors, i.e. energy norm or l2-error given ty
7 % 'model.error_algorithm' at end time for the given set of vectors `\mu`
8 % (columns in 'M_test') of the RB simulation with corresponding RB set.
9 %
10 % parameters:
11 % M_test: matrix with column vectors of parameter tuples `\mu` for which the
12 % error between reduced and detailed simulation shall be computed.
13 % savepath: directory path where the detailed simulations shall be saved to
14 % with save_detailed_simulations().
15 %
16 % required fields of model:
17 % error_algorithm: function handle to function that computes the error
18 % `\|u_h - u_{red}\|` in some norm.
19 %
20 % optional fields of model:
21 % relative_error: boolean indicating wether relative or absolute errors shall
22 % be computed. (Default = absolut errors)
23 %
24 % return values:
25 % test_err: vector of errors at end time
26 
27 % Bernard Haasdonk 6.6.2007
28 
29 % import model specific methods
30 
31 nmus = size(M_test,2);
32 test_err = zeros(nmus,1);
33 
34 if isempty(savepath)
35  error('savepath must be provided in case of error as target value!');
36 end;
37 save_detailed_simulations(model, detailed_data, M_test, savepath);
38 
39 parfor i = 1:nmus
40  fprintf('.');
41  tmodel = model;
42 
43  tmodel = tmodel.set_mu(model, M_test(:,i));
44  rb_sim_data = rb_simulation(tmodel,reduced_data);
45  sim_data = load_detailed_simulation(i, ...
46  savepath,...
47  tmodel);
48  rb_sim_data = rb_reconstruction(tmodel,detailed_data,rb_sim_data);
49 
50  if isfield(detailed_data,'W')
51  err_par = detailed_data.W;
52  else
53  err_par = [];
54  end;
55 
56  errs = tmodel.error_algorithm(tmodel.get_dofs_from_sim_data(sim_data),...
57  tmodel.get_dofs_from_sim_data(rb_sim_data),...
58  err_par, model);
59  if isfield(tmodel,'relative_error') && tmodel.relative_error
60  errs = errs./tmodel.error_algorithm(tmodel.get_dofs_from_sim_data(sim_data), ...
61  0, err_par, tmodel);
62  end
63  err = max(errs);
64 % err = errs(end);
65 % disp('warning, check monotonicity in errs!!!');
66  test_err(i) = err;
67 % if (i==2) & (mod(size(detailed_data.RB,2),30) == 0)
68 % save(['errs',num2str(size(detailed_data.RB,2))],'errs');
69 % end;
70 end;
71 
72 disp(test_err');
73