rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
nonlin_evol_reduced_data_subset.m
Go to the documentation of this file.
1 function reduced_data_subset = nonlin_evol_reduced_data_subset(model,reduced_data)
2 %function reduced_data_subset = nonlin_evol_reduced_data_subset(model,reduced_data)
3 % method which modifies reduced_data, which is the data, that will
4 % be passed to the online-simulation algorithm.
5 %
6 % Typically, this routine only does a submatrix extraction of the
7 % 'reduced_data.M', 'reduced_data.N' sized offline-objects to produce
8 % 'model.M', 'model.N' sized objects for the real simulation.
9 %
10 % Required fields of model:
11 % N : number of reduced basis vectors to choose
12 % M : number of collateral reduced basis vectors to choose for the
13 % simulation
14 %
15 % Optional fields of model:
16 % Mstrich : number of collateral reduced basis vectors to choose for the
17 % a posteriori error estimator (default = 0)
18 %
19 % Optional fields of reduced_data:
20 % a0 : a cell array sequence of N-vector components of initial data
21 % projection
22 % LL_E : a cell array sequence of N x N component-Matrices of explicit
23 % operator evaluations.
24 % LL_I : a cell array sequence of N x N component-Matrices of implicit
25 % operator evaluations.
26 % bb : a cell array sequence of N-vector components of the offset
27 % bb_I : a cell array sequence of N-vector components of the implicit offset
28 % K_II : a cell array sequence sequence of N x N matrices
29 % K_IE : a cell array sequence of N x N matrices
30 % K_EE : a cell array sequence of N x N matrices
31 % m_I : a cell array sequence of N-vector components of offset
32 % m_E : a cell array sequence of N-vector components of offset
33 % m : a cell array sequence of scalars (simply copied from 'reduced_data')
34 % CE : N x M interpolation matrix
35 % grid_local_ext : part of the grid containing the cells 'TM' plus their
36 % neighbours to be used for local operator evaluation
37 % TM_local : indices of magic-point-elements in the locally extended
38 % grid
39 % RB_local_ext : reduced basis vector values restricted to the support of
40 % 'grid_local_ext'
41 % s_RB : in case of a given output functional, this is a vector of
42 % output functional values of the reduced basis
43 % s_l2norm : in case of a given output functional, this is the
44 % `L^2`-norm of the output functional
45 % BM : 'M x M' interpolation matrix of empirical interpolation.
46 % DE : 'N x M' cross correlation matrix between 'detailed_data.QM' and
47 % 'detailed_data.RB'
48 % Mmass : 'M x M' mass matrix computed from 'detailed_data.QM' vectors
49 %
50 % generated fields of reduced_data_subset:
51 % a0 : a cell array sequence of N-vector components of initial data
52 % projection
53 % LL_E : a cell array sequence of N x N component-Matrices of explicit
54 % operator evaluations.
55 % LL_I : a cell array sequence of N x N component-Matrices of implicit
56 % operator evaluations.
57 % bb : a cell array sequence of N-vector components of the offset
58 % bb_I : a cell array sequence of N-vector components of the implicit offset
59 % K_II : a cell array sequence sequence of N x N matrices
60 % K_IE : a cell array sequence of N x N matrices
61 % K_EE : a cell array sequence of N x N matrices
62 % m_I : a cell array sequence of N-vector components of offset
63 % m_E : a cell array sequence of N-vector components of offset
64 % m : a cell array sequence of scalars (simply copied from 'reduced_data')
65 % CE : N x M interpolation matrix
66 % grid_local_ext : part of the grid containing the cells TM plus their
67 % neighbours to be used for local operator evaluation
68 % TM_local : indices of magic-point-elements in the locally extended
69 % grid
70 % RB_local_ext : reduced basis vector values restricted to the support of
71 % 'grid_local_ext'
72 % s_RB : in case of a given output functional, this is a vector of
73 % output functional values of the reduced basis
74 % s_l2norm : in case of a given output functional, this is the
75 % `L^2`-norm of the output functional
76 %
77 
78 % Bernard Haasdonk 16.5.2008
79 
80 reduced_data_subset = reduced_data;
81 
82 if ~isfield(model, 'stencil_mode')
83  stencil_mode = 'edge';
84 else
85  stencil_mode = model.stencil_mode;
86 end
87 
88 if ~isfield(model, 'Mstrich')
89  model.Mstrich = 0;
90 end
91 
92 if model.N ~= reduced_data.N || any(model.M ~= reduced_data.M) ...
93  || model.Mstrich ~= reduced_data.Mstrich
94 
95  % extract correct N-sized submatrices and subvectors from reduced_data
96  if model.N > length(reduced_data.a0{1})
97  error('N too large for current size of reduced basis!');
98  end;
99  N = model.N;
100  M = model.M;
101  Mstrich = model.Mstrich;
102  if isfield(reduced_data, 'a0')
103  reduced_data_subset.a0 = subblock_sequence(reduced_data.a0,1:N);
104  end
105  if isfield(reduced_data, 'LL_I')
106  reduced_data_subset.LL_I = subblock_sequence(reduced_data.LL_I,1:N,1:N);
107  end
108  if isfield(reduced_data, 'LL_E')
109  reduced_data_subset.LL_E = subblock_sequence(reduced_data.LL_E,1:N,1:N);
110  end
111  if isfield(reduced_data, 'bb')
112  reduced_data_subset.bb = subblock_sequence(reduced_data.bb,1:N);
113  end
114  if isfield(reduced_data, 'bb_I')
115  reduced_data_subset.bb_I = subblock_sequence(reduced_data.bb_I,1:N);
116  end
117  if isfield(reduced_data, 'K_EE')
118  reduced_data_subset.K_EE = subblock_sequence(reduced_data.K_EE,1:N,1:N);
119  end
120  if isfield(reduced_data, 'K_IE')
121  reduced_data_subset.K_IE = subblock_sequence(reduced_data.K_IE,1:N,1:N);
122  end
123  if isfield(reduced_data, 'K_II')
124  reduced_data_subset.K_II = subblock_sequence(reduced_data.K_II,1:N,1:N);
125  end
126  if isfield(reduced_data, 'm_I')
127  reduced_data_subset.m_I = subblock_sequence(reduced_data.m_I,1:N);
128  end
129  if isfield(reduced_data, 'm_E')
130  reduced_data_subset.m_E = subblock_sequence(reduced_data.m_E,1:N);
131  end
132  if isfield(reduced_data, 'm')
133  reduced_data_subset.m = reduced_data.m;
134  end
135  if isfield(reduced_data, 'Nmass')
136  reduced_data_subset.Nmass = reduced_data.Nmass(1:N,1:N);
137  end
138 
139  if isfield(reduced_data, 'BM')
140 
141  reduced_data_subset.factor = cell(size(reduced_data.BM));
142 
143  for oi = 1:length(reduced_data.BM(:))
144  Mmax = length(reduced_data.TM_local{oi});
145  MM = M(oi) + Mstrich;
146  if MM > Mmax
147  error('M + Mstrich > Mmax');
148  end
149  reduced_data_subset.DE{oi} = reduced_data.DE{oi}(1:N,1:MM);
150  grid = reduced_data.grid_local_ext{oi};
151 
152  if strcmp(stencil_mode, 'vertex') == 1
153  mask = zeros(1,grid.nelements);
154  nbi = grid.NBI(reduced_data.TM_local{oi}(1:MM),:);
155  i = find(nbi>0);
156  mask(nbi(i)) = 2;
157  % get indices of TM's neighbour-neighbours
158  nnbi = grid.NBI(unique(nbi(i)),:);
159  ni = find(nnbi > 0);
160  [nnbuniq,tally] = unique(sort(nnbi(ni)),'first');
161  tally = [tally(2:end);length(nnbi(ni))+1] - tally;
162  mask(nnbuniq) = tally;
163  mask(nbi(i)) = 5;
164  mask(reduced_data.TM_local{oi}(1:MM)) = 6;
165  mask(mask < 2) = 0;
166 % disp('workaround for Frederikes model')
167 % mask(mask < 1) = 0; % here second neighbours are generated!
168 
169  eind = find(mask);
170  else
171  % new version with external routine index_ext:
172  eind = index_ext(...
173  grid,...
174  reduced_data.TM_local{oi}(1:MM),...
175  model.local_stencil_size);
176 
177  end
178 
179 
180  reduced_data_subset.grid_local_ext{oi} = gridpart(grid,eind);
181 
182  reduced_data_subset.RB_local_ext{oi} = reduced_data.RB_local_ext{oi}(eind,1:N);
183 
184  % the following messes up the order of the ei-functions!!
185  %reduced_data.TM_local = find(mask(eind)==2);
186 
187  %goal TM_local(1) is the local element number, which corresponds to
188  %the original one, i.e. eind(TM_local(i)) = TM(i)
189 
190  % create kind of 'inversion' map
191 
192  % eind : 1:M_local_ext => 1:H
193 
194  glob2loc = zeros(grid.nelements,1);
195  glob2loc(eind) = 1:length(eind);
196  reduced_data_subset.TM_local{oi} = glob2loc(reduced_data.TM_local{oi}(1:MM));
197  reduced_data_subset.BM{oi} = reduced_data.BM{oi}(1:MM,1:MM);
198  reduced_data_subset.Mmass{oi} = reduced_data.Mmass{oi}(1:MM,1:MM);
199 
200 
201  % get Q^t W Q for M to M+M'
202  if Mstrich > 0
203  QWQ = reduced_data_subset.Mmass{oi}(M(oi)+1,MM);
204  reduced_data_subset.factor{oi} = norm(QWQ);
205  else
206  reduced_data_subset.factor{oi} = NaN;
207  end
208  % if the velocity file is based on a file, the corresponding
209  % subsets must be extracted here:
210  % in case of file access, the correct filename must be set here
211  % the following is only relevant in case of use of a
212  % model.use_velocitymatrix_file and filecaching mode 2
213  if isfield(model,'filecache_velocity_matrixfile_extract') && ...
214  (model.filecache_velocity_matrixfile_extract == 2);
215  % change global velocity file to MMax velocity file generated in
216  % offline
217  if Mmax ~= model.Mmax
218  error('Mmax in model and reduced_data does not correspond!!');
219  end;
220  model.velocity_matrixfile = ...
221  ['gridpart_Mmax',num2str(Mmax),'_',model.velocity_matrixfile];
222  % generate M velocity file if not existing
223  cache_velocity_matrixfile_extract(model, ...
224  reduced_data_subset.grid_local_ext{1}.ECX(:,:),...
225  reduced_data_subset.grid_local_ext{1}.ECY(:,:),...
226  ['M',num2str(model.M(oi))]);
227  end;
228  end
229  end
230 
231  if isfield(model,'name_output_functional')
232  reduced_data_subset.s_RB = reduced_data.s_RB(1:N);
233  reduced_data_subset.s_l2norm = reduced_data.s_l2norm;
234  end;
235 
236 
237  reduced_data_subset.N = N;
238  reduced_data_subset.M = M;
239  reduced_data_subset.Mstrich = Mstrich;
240  if isfield(reduced_data, 'time_split_map')
241  reduced_data_subset.time_split_map = reduced_data.time_split_map;
242  end
243 
244 end
245 
function reduced_data_subset = nonlin_evol_reduced_data_subset(model, reduced_data)
method which modifies reduced_data, which is the data, that will be passed to the online-simulation a...