rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
ReducedData.m
1 classdef ReducedData < Greedy.User.IReducedDataNode
2  % Reduced data implementation for linear evolution problems with finite
3  % volume discretizations
4  %
5  % See @ref HO08a for details on the implementation of the reduced matrices
6  % and vectors.
7 
8 
9  properties
10  % Dof vectors of projections `\left\{{ \cal P }_{\text{red}}[u_0^q]
11  % \right\}_{q=1}^{Q_{u_0}}`.
12  %
13  % @sa LinEvol.ReducedModel.rb_init_values() for details.
14  a0;
15 
16  % `Q_I` reduced matrix for implicit operator `{\cal L}_{h,I}`
17  %
18  % The matrix entries are:
19  % ``({ \bf L}_I^q)_{ij} = \int \varphi_i {\cal L}^q_{h,I}[\varphi_j]``
20  % for `i,j=1,\ldots,N` and `q=1,\ldots,Q_I`.
21  LL_I;
22 
23  % `Q_E`-sequence of reduced matrices for explicit operator `{\cal L}_{h,E}`
24  %
25  % The matrix entries are:
26  % ``({ \bf L}_E^q)_{ij} = \int \varphi_i {\cal L}^q_{h,E}[\varphi_j]``
27  % for `i,j=1,\ldots,N` and `q=1,\ldots,Q_E`.
28  LL_E;
29 
30  % `Q_b`-sequence of reduced vectors for constant contributions `b_h`
31  %
32  % The matrix entries are:
33  % ``({ \bf b})_{i} = \int \varphi_i b^q_h``
34  % for `i=1,\ldots,N` and `q=1,\ldots,Q_b`.
35  bb;
36 
37  % `Q_I \cdot Q_I`-sequence of gram matrices
38  %
39  % The matrix entries are:
40  % ``({ \bf K}_{II}^{q_1,q_2})_{ij} = \int {\cal L}^{q_1}_{h,I}[\varphi_i] {\cal L}^{q_2}_{h,I}[\varphi_j]``
41  % for `i,j=1,\ldots,N` and `q_1,q_2=1,\ldots,Q_I`.
42  K_II;
43 
44  % `Q_I \cdot Q_E`-sequence of gram matrices
45  %
46  % The matrix entries are:
47  % ``({ \bf K}_{IE}^{q_1,q_2})_{ij} = \int {\cal L}^{q_1}_{h,I}[\varphi_i] {\cal L}^{q_2}_{h,E}[\varphi_j]``
48  % for `i,j=1,\ldots,N` and `q_1=1,\ldots,Q_I, q_2=1,\ldots,Q_E`.
49  K_IE;
50 
51  % `Q_E \cdot Q_E`-sequence of gram matrices
52  %
53  % The matrix entries are:
54  % ``({ \bf K}_{EE}^{q_1,q_2})_{ij} = \int {\cal L}^{q_1}_{h,E}[\varphi_i] {\cal L}^{q_2}_{h,E}[\varphi_j]``
55  % for `i,j=1,\ldots,N` and `q_1,q_2=1,\ldots,Q_E`.
56  K_EE;
57 
58  % `Q_I \cdot Q_b`-sequence of vectors
59  %
60  % The vector entries are:
61  % ``({ \bf m}_I^{q_1,q_2})_i = \int {\cal L}^{q_1}_{h,I}[\varphi_i] b_h^{q_2}``
62  % for `i=1,\ldots,N` and `q_1=1,\ldots,Q_I, q_2=1,\ldots,Q_b`.
63  m_I;
64 
65  % `Q_E \cdot Q_b`-sequence of vectors
66  %
67  % The vector entries are:
68  % ``({ \bf m}_E^{q_1,q_2})_i = \int {\cal L}^{q_1}_{h,E}[\varphi_i] b_h^{q_2}``
69  % for `i=1,\ldots,N` and `q_1=1,\ldots,Q_E, q_2=1,\ldots,Q_b`.
70  m_E;
71 
72  % `Q_b \cdot Q_b`-sequence of scalars
73  %
74  % The scalars are:
75  % ``{ \bf m}^{q_1,q_2} = \int b_h^{q_1} b_h^{q_2}``
76  % and `q_1,q_2=1,\ldots,Q_b`.
77  m;
78 
79  % in case of output functional this is a `Q_s`-sequence of vectors.
80  %
81  % The vector entries are:
82  % ``({ \bf s}^q)_i = s(\varphi_i)``
83  % for `i=1,\ldots,N` and `q_1=1,\ldots,Q_s`
84  s_RB;
85 
86  % in case of output functional this is a `Q_s`-sequence of scalars.
87  %
88  % The scalars are:
89  % ``{ \bf s}_{l^2}^q = \|s(\varphi_1), \ldots, s(\varphi_N)\|_{l^2}``
90  % for `q_1=1,\ldots,Q_s`
91  s_l2norm;
92  end
93 
94  properties (SetAccess = private, Dependent)
95  % number of reduced basis vectors stored in this data node.
96  N;
97  end
98 
99  properties (SetAccess = private)
100  % number of collateral reduced basis vectors stored in this data node.
101  M = 0;
102  % number of collateral reduced basis vectors used for error estimation
103  Mstrich = 0;
104  end
106  methods
107 
108  function rd = ReducedData(rmodel, detailed_data)
109  % Constructor for the generation of the reduced matrices and vectors.
110  %
111  % Parameters:
112  % rmodel: of type LinEvol.ReducedModel
113  % detailed_data: of type IDetailedData
114  %
115  %
116  if nargin == 0
117  error('LinEvol.ReducedData constructor needs an argument');
118  elseif nargin == 2 && isa(rmodel, 'IReducedModel') ...
119  && isa(detailed_data, 'LinEvol.ReducedData')
120  copy = detailed_data;
121  copy_extract(rd, copy, rmodel);
122  elseif nargin == 2 && isa(rmodel, 'IReducedModel') && isa(detailed_data, 'IDetailedData')
123  fill_fields(rd, rmodel, detailed_data);
124  else
125  error('Did not find constructor for your arguments');
126  end
127  end
128 
129  function N = get.N(this)
130  if ~isempty(this.a0)
131  N = size(this.a0{1},2);
132  else
133  N = 0;
134  end
135  end
136 
137  function yesno = needs_subset_copy(this, rmodel)
138  % function yesno = needs_subset_copy(this, rmodel)
139  % @copybrief .Greedy.User.IReducedDataNode.needs_subset_copy()
140  %
141  % @copydetails .Greedy.User.IReducedDataNode.needs_subset_copy()
142  %
143  % Parameters:
144  % rmodel: of type LinEvol.ReducedModel
145 
146  yesno = this.N ~= rmodel.N;
147  end
148 
149 
150  function conds = get_conds(this)
151  disp('get_conds needs to be implemented for LinEvol.ReducedData');
152  conds = [];
153  end
154 
155  end
156 
157  methods (Access=private)
158  function fill_fields(this, rmodel, detailed_data)
159  % function fill_fields(this, rmodel, detailed_data)
160 
161  this.a0 = rmodel.descr.mexptr('rb_init_values', 1);
162  [this.LL_I, this.LL_E, this.bb, ...
163  this.K_II, this.K_IE, this.K_EE, ...
164  this.m_I, this.m_E, this.m ] ...
165  = LinEvolDune.ReducedData.rb_operators(rmodel, detailed_data, 1);
166  end
167 
168  function copy_extract(this, copy, rmodel)
169  % function copy_extract(this, copy, rmodel)
170  % @copybrief IReducedModelextract_reduced_data_subset()
171  %
172  % Parameters:
173  % rmodel: reduced model of type LinEvol.ReducedModel indicating the
174  % number of reduced basis vectors to be used in the
175  % 'reduced_data_subset'
176 
177  % extract correct N-sized submatrices and subvectors from reduced_data
178  if rmodel.N > copy.N
179  error('N too large for current size of reduced basis!');
180  end
181 
182  N = rmodel.N;
183  this.a0 = subblock_sequence(copy.a0,1:N);
184  this.LL_I = subblock_sequence(copy.LL_I,1:N,1:N);
185  this.LL_E = subblock_sequence(copy.LL_E,1:N,1:N);
186  this.bb = subblock_sequence(copy.bb,1:N);
187  this.K_EE = subblock_sequence(copy.K_EE,1:N,1:N);
188  this.K_IE = subblock_sequence(copy.K_IE,1:N,1:N);
189  this.K_II = subblock_sequence(copy.K_II,1:N,1:N);
190  this.m_I = subblock_sequence(copy.m_I,1:N);
191  this.m_E = subblock_sequence(copy.m_E,1:N);
192  this.m = copy.m;
193  % if ~isempty(copy.T)
194  % this.T = copy.T(1:N,1:N);
195  % end
196 
197  model = rmodel.detailed_model;
198  if isfield(model,'name_output_functional')
199  this.s_RB = copy.s_RB(1:N);
200  this.s_l2norm = copy.s_l2norm;
201  end
202 
203  end
204  end
205 
206  methods(Static)
207  %
208  %
209  % Parameters:
210  % rmodel : of type LinEvol.ReducedModel
211  % detailed_data : of type Greedy.DataTree.Detailed.RBLeafNode
212  function [LL_I, LL_E, bb, K_II, K_IE, K_EE, m_I, m_E, m] = rb_operators(rmodel, detailed_data, decomp_mode)
213 
214  descr = rmodel.descr;
215 
216  if decomp_mode == 2
217  mu = get_mu(rmodel);
218  dLL_I = descr.coeff_ops.LL_I_ptr(mu);
219  dLL_E = descr.coeff_ops.LL_E_ptr(mu);
220  dbb = descr.coeff_ops.bb_ptr(mu);
221  % model.mexptr('set_mu', model.mu);
222  % foo = model.mexptr('rb_operators', decomp_mode);
223  % disp('start');
224  % dLL_I == foo{1}
225  % dLL_E == foo{2}
226  % dbb == foo{3}
227  % kron(dLL_I,dLL_E) == foo{6}
228  % kron(dLL_E,dbb) == foo{8}
229  % kron(dbb,dbb) == foo{9}
230  LL_I = [1, dLL_I];
231  LL_E = [1, dLL_E];
232  bb = dbb;
233  K_II = [1, dLL_I, dLL_I, kron(dLL_I,dLL_I) ];
234  K_EE = [1, dLL_E, dLL_E, kron(dLL_E,dLL_E) ];
235  K_IE = [1, dLL_I, dLL_E, kron(dLL_I,dLL_E) ];
236  m_I = [dbb, kron(dLL_I,dbb) ];
237  m_E = [dbb, kron(dLL_E,dbb) ];
238  m = kron(dbb,dbb);
239  else
240  foo = descr.mexptr('rb_operators', decomp_mode);
241  dLL_I = foo{1};
242  dLL_E = foo{2};
243  dbb = foo{3};
244  dK_II = foo{4};
245  dK_EE = foo{5};
246  dK_IE = foo{6};
247  dm_I = foo{7};
248  dm_E = foo{8};
249  dm = foo{9};
250 
251  if decomp_mode == 1
252  func2 = @(X) descr.dt * X;
253  func2t = @(X) descr.dt * X';
254  func3 = @(X) descr.dt.^2 * X;
255 
256  identity = speye(size(dLL_I{1}));
257 
258  LL_I = [{identity}; ...
259  cellfun(func2 , dLL_I, 'UniformOutput', false)];
260 
261  LL_E = [{identity}; ...
262  cellfun(func2 , dLL_E, 'UniformOutput', false)];
263 
264  bb = cellfun(func2 , dbb , 'UniformOutput', false);
265 
266  K_II = [{identity}; ...
267  cellfun(func2t, dLL_I, 'UniformOutput', false); ...
268  cellfun(func2 , dLL_I, 'UniformOutput', false); ...
269  cellfun(func3 , dK_II, 'UniformOutput', false)];
270 
271  K_EE = [{identity}; ...
272  cellfun(func2t, dLL_E, 'UniformOutput', false); ...
273  cellfun(func2 , dLL_E, 'UniformOutput', false); ...
274  cellfun(func3 , dK_EE, 'UniformOutput', false)];
275 
276  K_IE = [{identity}; ...
277  cellfun(func2t, dLL_I, 'UniformOutput', false); ...
278  cellfun(func2 , dLL_E, 'UniformOutput', false); ...
279  cellfun(func3 , dK_IE, 'UniformOutput', false)];
280 
281  m_I = [bb; ...
282  cellfun(func3 , dm_I , 'UniformOutput', false)];
283 
284  m_E = [bb; ...
285  cellfun(func3 , dm_E , 'UniformOutput', false)];
286 
287  m = cellfun(func3 , dm , 'UniformOutput', false);
288 
289  else % decomp_mode == 0
290  assert(all(get_mu(rmodel) == get_mu(rmodel.detailed_model)));
291  LL_I = 1 + model.dt * dLL_I;
292  LL_E = 1 + model.dt * dLL_E;
293  bb = model.dt * dbb;
294  K_II = 1 + model.dt * dLL_I' + model.dt * dLL_I + model.dt^2 * dK_II;
295  K_EE = 1 + model.dt * dLL_E' + model.dt * dLL_E + model.dt^2 * dK_EE;
296  K_IE = 1 + model.dt * dLL_I' + model.dt * dLL_E + model.dt^2 * dK_IE;
297  m_I = model.dt * dbb + model.dt^2 * dm_I;
298  m_E = model.dt * dbb + model.dt^2 * dm_E;
299  m = model.dt^2 * dm;
300  end
301  end
302  end
303  end
304 end
reduced model for linear evolution problems as given by a LinEvol.DetailedModel.
Definition: ReducedModel.m:18
reduced model for linear evolution problems as given by a LinEvol.DetailedModel.
Definition: ReducedModel.m:18
N
control variable for the size of the reduced basis used for reduced simulations. By default this is e...
Interface for leaf nodes of the DataTree in Greedy.User.ReducedData objects.
Reduced basis implementation for linear evolution equations.
Interface classes to be implemented by the Greedy.Algorithm user.
This is the interface for a reduced model providing methods to compute low dimensional reduced simula...
Definition: IReducedModel.m:17
Reduced data implementation for linear evolution problems with finite volume discretizations.
Definition: ReducedData.m:18
function a0 = rb_init_values(Greedy.DataTree.Detailed.RBLeafNode detailed_data, decomp_mode)
function computing initial values for a reduced simulation.
Definition: ReducedModel.m:89
Customizable implementation of an abstract greedy algorithm.
Definition: DuneRBLeafNode.m:1
Interface class for the generation and storage of reduced basis spaces as described in Module (M2)...
Definition: IDetailedData.m:17