rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules 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
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  tmodel = set_mu(tmodel, M_test(:, i));
45  rb_sim_data = rb_simulation(tmodel,reduced_data);
46  sim_data = load_detailed_simulation(i, ...
47  savepath,...
48  tmodel);
49  rb_sim_data = rb_reconstruction(tmodel,detailed_data,rb_sim_data);
50 
51  if isfield(detailed_data,'W')
52  err_par = detailed_data.W;
53  else
54  err_par = [];
55  end;
56 
57  errs = tmodel.error_algorithm(tmodel.get_dofs_from_sim_data(sim_data),...
58  tmodel.get_dofs_from_sim_data(rb_sim_data),...
59  err_par, model);
60  if isfield(tmodel,'relative_error') && tmodel.relative_error
61  errs = errs./tmodel.error_algorithm(tmodel.get_dofs_from_sim_data(sim_data), ...
62  0, err_par, tmodel);
63  end
64  err = max(errs);
65 % err = errs(end);
66 % disp('warning, check monotonicity in errs!!!');
67  test_err(i) = err;
68 % if (i==2) & (mod(size(detailed_data.RB,2),30) == 0)
69 % save(['errs',num2str(size(detailed_data.RB,2))],'errs');
70 % end;
71 end;
72 
73 disp(test_err');
74 
function [ sim_data , tictoc ] = load_detailed_simulation(m, savepath, params)
load single trajectory of previously saved results.
function save_detailed_simulations(model, model_data, M, savepath)
perform loop over detailed simulations and save results or check consistency with existing saved resu...