rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
nonlin_evol_gen_reduced_data.m
Go to the documentation of this file.
1 function reduced_data = nonlin_evol_gen_reduced_data(model, detailed_data, params)
2 %function reduced_data = nonlin_evol_gen_reduced_data(model, detailed_data[, params])
3 % method which produces reduced_data, which is the data, that will be passed to
4 % an online-algorithm.
5 %
6 % Therefore, no quantities dependent on the high-dimension `H` may be included
7 % here. Neither may online-data include parameter-dependent `\mu`-quantities.
8 % So no complete grid or detailed solutions or reduced basis vectors may be
9 % stored here. So online data is produced in the offline stage, but may be used
10 % in online-stages. So the computation time may depend on `H`, but the results
11 % may not depend on this complexity.
12 %
13 % allowed dependency of generated data:
14 % - Nmax,
15 % - Mmax
16 % not allowed dependency of data:
17 % - H
18 % allowed dependency of computation:
19 % - Nmax,
20 % - Mmax,
21 % - H
22 % Unknown at this stage:
23 % - mu,
24 %
25 % Generated fields of reduced_data:
26 % a0 : a cell array sequence of N-vector components of initial data
27 % projection
28 % LL_E : a cell array sequence of N x N component-Matrices of explicit
29 % operator evaluations.
30 % LL_I : a cell array sequence of N x N component-Matrices of implicit
31 % operator evaluations.
32 % bb_I : a cell array sequence of N-vector components of the implicit offset
33 % DE : 'Nmax x Mmax' cross correlation matrix between 'detailed_data.QM'
34 % and 'detailed_data.RB'
35 % BM : 'Mmax x Mmax' interpolation matrix of empirical interpolation.
36 % grid_local_ext : part of the grid containing the cells 'TM' plus their
37 % neighbours to be used for local operator evaluation
38 % TM_local : indices of magic-point-elements in the grid_local_ext
39 % RB_local_ext : reduced basis vector values restricted to the support of
40 % 'grid_local_ext'
41 %
42 
43 % Bernard Haasdonk 16.5.2007
44 
45 if nargin == 2
46  params = [];
47 end
48 
49 if ~isfield(model, 'stencil_mode')
50  stencil_mode = 'edge';
51 else
52  stencil_mode = model.stencil_mode;
53 end
54 
55 if model.verbose > 11
56  disp(['stencil mode: ' , model.stencil_mode]);
57  disp(['stencil size: ' , num2str(model.local_stencil_size)]);
58 end
59 
60 model.decomp_mode = 1;
61 reduced_data.a0 = model.rb_init_values(model, detailed_data);
62 Nmax = size(detailed_data.RB,2);
63 Mmax = size(detailed_data.QM{1},2);
64 
65 % assuming that components do not change in time, so wlg t = 0!!!
66 params.t = 0;
67 [reduced_data.LL_I, reduced_data.bb_I] = ...
68  model.rb_operators(model, detailed_data);
69 
70 A = detailed_data.W;
71 
72 reduced_data.Nmass = detailed_data.RB' * A * detailed_data.RB;
73 
74 reduced_data.DE = cell(size(detailed_data.QM));
75 reduced_data.BM = cell(size(detailed_data.QM));
76 reduced_data.grid_local_ext = cell(size(detailed_data.QM));
77 reduced_data.RB_local_ext = cell(size(detailed_data.QM));
78 reduced_data.TM_local = cell(size(detailed_data.QM));
79 reduced_data.Mmass = cell(size(detailed_data.QM));
80 
81 for oi = 1:length(detailed_data.QM(:))
82  reduced_data.DE{oi} = detailed_data.RB' * A * detailed_data.QM{oi};
83 
84  reduced_data.BM{oi} = detailed_data.BM{oi};
85 
86  % determine indices of TMmax and its neighbours
87  grid = detailed_data.grid;
88  TM = detailed_data.TM{oi};
89  if strcmp(stencil_mode, 'vertex') == 1
90  mask = zeros(1, grid.nelements);
91  nbi = grid.NBI(TM,:);
92  i = find(nbi > 0);
93  % get indices of TM's neighbour-neighbours
94  nnbi = grid.NBI(unique(nbi(i)),:);
95  ni = find(nnbi > 0);
96  [nnbuniq,tally] = unique(sort(nnbi(ni)),'first');
97  tally = [tally(2:end);length(nnbi(ni))+1] - tally;
98  mask(nnbuniq) = tally;
99  mask(nbi(i)) = 5;
100  mask(TM) = 6;
101  mask(mask < 2) = 0; % skip the elements which have no vertex with the
102  % given elements in TM in common
103  eind = find(mask);
104  else
105  eind = index_ext(grid,TM,model.local_stencil_size);
106  end
107 
108  if isa(grid,'rectgrid')|| isa(grid,'triagrid') || isa(grid,'onedgrid')
109  reduced_data.grid_local_ext{oi} = gridpart(grid,eind);
110 % else % e.g. struct, or not required local grid:
111 % disp('please gen nice grid class for 1d grid...')
112 % reduced_data.grid_local_ext{oi} = onedgrid_gridpart(grid,eind);
113 % keyboard;
114  end;
115  reduced_data.RB_local_ext{oi} = detailed_data.RB(eind,:);
116  reduced_data.implicit_crb_index = detailed_data.implicit_crb_index;
117  reduced_data.explicit_crb_index = detailed_data.explicit_crb_index;
118 
119  % the following messes up the order of the ei-functions!!
120  %reduced_data.TM_local = find(mask(eind)==2);
121 
122  %goal TM_local(1) is the local element number, which corresponds to
123  %the original one, i.e. eind(TM_local(i)) = TM(i)
124 
125  % create kind of 'inversion' map
126 
127  % eind : 1:M_local_ext => 1:H
128 
129  glob2loc = zeros(grid.nelements,1);
130  glob2loc(eind) = 1:length(eind);
131  reduced_data.TM_local{oi} = glob2loc(detailed_data.TM{oi});
132 
133  % generate grid_local velocity file, if the flux is based on a file:
134  % in case of file access, the correct filename must be set here
135  % the following is only relevant in case of use of a
136  % params.use_velocitymatrix_file and filecaching mode 2
137  if isfield(model,'filecache_velocity_matrixfile_extract') && ...
138  (model.filecache_velocity_matrixfile_extract == 2);
139  cache_velocity_matrixfile_extract(model, ...
140  reduced_data.grid_local_ext{1}.ECX(:,:),...
141  reduced_data.grid_local_ext{1}.ECY(:,:),...
142  ['M',num2str(model.M),'_','gridpart_Mmax',num2str(Mmax)]);
143  end;
144 
145  % may be needed by a posteriori error estimator: the CRB mass matrix Q^t W Q
146  reduced_data.Mmass{oi} = detailed_data.QM{oi}' * ...
147  model.get_inner_product_matrix(detailed_data) * detailed_data.QM{oi};
148 
149  % add the localext2global mapping:
150  %reduced_data.local_ext_2_global = eind;
151 
152  % check correspondence!
153  %disp('Check TM-local-global correspondence. Remove later...');
154  %for i = 1:length(detailed_data.TM)
155  % if (eind(reduced_data.TM_local(i)) ~= detailed_data.TM(i))
156  % error('local T_M numbers confused!!!');
157  % end;
158  %end;
159 
160  % for debugging: add mass-matrix
161  %disp('temporary mass matrix is added');
162  %reduced_data.M = detailed_data.RB' * A * detailed_data.RB;
163 
164 end
165 if(isfield(detailed_data,'time_split_map'))
166  reduced_data.time_split_map = detailed_data.time_split_map;
167 end
168 reduced_data.N = model.get_rb_size(model, detailed_data);
169 reduced_data.M = cellfun(@(x) size(x,2), detailed_data.QM);
170 reduced_data.Mstrich = 0;
171 
172 %| \docupdate
function r = verbose(level, message, messageId)
This function displays messages depending on a message-id and/or a level. Aditionally you can set/res...
Definition: verbose.m:17
function reduced_data = nonlin_evol_gen_reduced_data(model, detailed_data, params)
method which produces reduced_data, which is the data, that will be passed to an online-algorithm.
A triangular conforming grid in two dimensions.
Definition: triagrid.m:17
A cartesian rectangular grid in two dimensions with axis parallel elements.
Definition: rectgrid.m:17
a one dimensional grid implementation
Definition: onedgrid.m:17