rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
RB_extension_max_error_snapshot.m
1 function [RBext,info] = RB_extension_max_error_snapshot(model,detailed_data)
2 %function [RBext,par] = RB_extension_max_error_snapshot(model,detailed_data)
3 %
4 % function computing the snapshot for parameter mu which is set in
5 % params, which causes the largest increase of the posterior error estimator
6 % in time. This snapshot is orthonormalized with respect to detailed_data.RB and
7 % returned in RBext.
8 %
9 % Occasionally, the selected snapshot is already within the span
10 % of the reduced basis RB, then the second max-error snapshot is taken,
11 % and so on.
12 %
13 % The values returned in info are:
14 % snapshot: the snapshot before orthonormalization
15 % ti: the absolute simulation time of the snapshot
16 % rank: rank of the snapshot in the list of
17 % error-prediction.increases
18 %
19 % required fields of params
20 % detailed_simulation_algorithm: name of the function to be called
21 % with parameters (grid,params) and resulting in DOF-vectors
22 % e.g. fv_conv_diff_operators
23 % or detailed_simulation with additional fields
24 % mu_names: cell array of names of the parameter-vector entries
25 % inner_product_matrix_algorithm : function computing the correct inner
26 % product matrix between function DOF-vectors
27 
28 % Bernard Haasdonk 13.10.2005
29 
30  info = [];
31 
32  % perform full and RB simulation
33  %U = fv_conv_diff(params);
34  %if isempty(grid)
35  % grid = grid_geometry(params);
36  %end;
37 
38  % take care to remove some changed fields from model and detailed
39  % data, such that filecaching works!!! in RB_extension_algorithm
40  % !!!
41  tmp_model = model;
42  ifm = model.filecache_ignore_fields_in_model;
43  for i = 1:length(model.filecache_ignore_fields_in_model);
44  if isfield(model,ifm{i})
45  tmp_model = rmfield(tmp_model,ifm{i});
46  end;
47  end;
48  ifm = model.filecache_ignore_fields_in_detailed_data;
49  dim_RB = size(model.get_rb_from_detailed_data(detailed_data));
50  tmp_detailed_data = ...
51  model.set_rb_in_detailed_data(detailed_data, zeros(dim_RB(1),0));
52  for i = 1:length(model.filecache_ignore_fields_in_detailed_data);
53  if isfield(detailed_data,ifm{i})
54  tmp_detailed_data = rmfield(tmp_detailed_data,ifm{i});
55  end;
56  end;
57  % U = fv_conv_diff_operators(grid,params);
58  sim_data = filecache_function(@detailed_simulation,tmp_model, ...
59  tmp_detailed_data);
60 
61  % perform RB-simulation
62  reduced_data = gen_reduced_data(model,detailed_data);
63  simulation_data = rb_simulation(model,reduced_data);
64  Urec = rb_reconstruction(model,detailed_data,simulation_data);
65  %[A,pe] = fv_conv_diff_galerkin(RB,params);
66  %Uappr = RB*A;
67  simulation_data.Delta = fv_error(Urec,U,detailed_data.W,model);
68 
69  % rank timesteps according to error increase
70  post_est_diff = simulation_data.Delta' - ...
71  [0; simulation_data.Delta(1:end-1)'];
72  [m,ti] = sort(-post_est_diff); % -> post_est_diff(ti) ist sortiert
73 
74  % select snapshot by following rank-list
75  ra = 0;
76  found_update = 0;
77 
78  W = model.get_inner_product_matrix(detailed_data);
79 
80  while ~found_update
81  ra = ra+1;
82  % orthonormalize snapshot at rank ra
83  Uproj = U(:,ti(ra)) - detailed_data.RB * (detailed_data.RB' * W * U(:,ti(ra)));
84  if norm(Uproj)> 1e-10
85  % if nonzero projection error -> end with new snapshot
86  % Uproj = Uproj/norm(Uproj).*params.vec_to_func;
87  % due to scaling, no precise orthonormalization is obtained. So perform
88  % explicit orthonormalization
89  RBtmp = orthonormalize([detailed_data.RB,Uproj],W);
90  if size(RBtemp,2)> size(detailed_data.RB,2)
91  Uproj = RBtmp(:,end); %.*grid.Ainv(:).^(0.5);
92  found_update = 1;
93  else
94  error('accuracy problem, should not reach this point!!');
95  end;
96  end;
97  end;
98 
99  % return values
100  RBext = Uproj;
101  info.rank = ra;
102  info.snapshot = U(:,ra);
103  info.ti = (ti(ra)-1)*params.T/params.nt;
104 
105 %| \docupdate
function varargout = filecache_function(funcptr, varargin)
function used for file-caching other function calls.