rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
ReducedModel.m
1 classdef ReducedModel < Greedy.User.IReducedModel
2  % reduced model for non-linear evolution problems as given by a
4  %
5  % This is compatible with Greedy.User.IReducedModel and can therefore make
6  % use of @ref Greedy.User.IDetailedData "detailed data objects" created by
7  % Greedy algorithms.
8 
9  properties
10  enable_error_estimator = true;
11 
12 % properties (Constant) @code
13 % nl_checks = struct('Mstrich', {{@isscalar, 'minmax', [0, inf]}},...
14 % 'enable_error_estimator', {{@isscalar, 'own', ...
15 % @(model) ~model.enable_error_estimator || model.Mstrich > 0, ...
16 % 'model.Mstrich needs to be positive if error estimator is enabled'}} ...
17 % );
18 % @endcode
19 
21  compute_conditions = false;
22 
23  % defines how the stencil of the local grid is computed
24  %
25  % Two possibilities:
26  % - 'edge' for all neighbours over edges
27  % - 'vertex' for all neighbours of a grid cell's vertices
28  %
29  % See also: #local_stencil_size
30  stencil_mode = 'edge';
31 
32  % defines the number of neighbors that shall be added to the stencil of the
33  % local grid created for efficient empirical interpolation evalutations.
34  %
35  % See also: stencil_mode
36  local_stencil_size = 1;
37  end
38 
39  properties (Dependent)
40  % current time instance
41  t;
42 
43  % current time step
44  tstep;
45  end
46 
47  properties(Constant)
48  % This constant is used for a consistency check of the model descr with
49  % help of IModel.struct_check()
50  ddescr_checks = struct(...
51  'init_values_algorithm', {{@(x) isequal(class(x), 'function_handle')}},...
52  'error_norm', {{@ischar, 'values', {'l2', 'energy'} }},...
53  'stencil_mode', {{@ischar, 'values', {'edge', 'vertex'} }},...
54  'local_stencil_size', {{@isnumeric}}...
55  );
56 
57  end
58 
59  methods
60  function rm = ReducedModel(dmodel, bg_descr)
61  % function rm = ReducedModel(dmodel, bg_descr)
62  % Constructor for the reduced model.
63  %
64  % Parameters:
65  % dmodel: of type NonlinEvol.DetailedModel
66  %
67  if nargin == 1 || isempty(bg_descr)
68  bg_descr = [];
69  end
70  % this implements a copy constructor if necessary...
71  rm = rm@Greedy.User.IReducedModel(dmodel, bg_descr);
72  % are we NOT a copy constructor?
73  if ~(isempty(bg_descr) || isa(dmodel, 'NonlinEvol.ReducedModel'))
74 
75  descr = dmodel.descr;
76 
77  if ~IModel.struct_check(descr, ...
78  NonlinEvol.ReducedModel.ddescr_checks);
79  error('Consistency check for NonlinEvol.ReducedModel failed.');
80  end
81 
82  rm.stencil_mode = descr.stencil_mode;
83  rm.local_stencil_size = descr.local_stencil_size;
84 
85  rm.Mstrich = 1;
86  rm.crb_enabled = true;
87  end
88 
89  end
90 
91  function M = get_current_M(this, id)
92  % function M = get_current_M(this[, id])
93  % returns the collateral reduced basis size for the current parameter and
94  % time instant
95  %
96  % Parameters:
97  % id: an optional id in case there are many collateral reduced basis
98  % spaces for one parameter and time instant combination.
99  %
100  % Return values:
101  % M: the size of the collateral reduced basis space
102 
103  if nargin < 2
104  id = [];
105  end
106 
107  if isa(this.M, 'DataTree.INode')
108  M = get_active_leaf(this.M, this, id);
109  M = M.value;
110  else
111  M = this.M;
112  end
113  end
114 
115  function c = copy(this)
116  % function c = copy(this)
117  % @copybrief IReducedModelcopy()
118  %
119  % Return values:
120  % c: an object of type NonlinEvol.ReducedModel which is a deep copy of this object.
121  c = NonlinEvol.ReducedModel(this);
122  end
123 
124 % function reduced_data = gen_reduced_data(this, detailed_data)
125 % rd_creator = NonlinEvol.ReducedDataCreator;
126 % if isfield(this.descr, 'stencil_mode')
127 % rd_creator.stencil_mode = this.descr.stencil_mode;
128 % rd_creator.local_stencil_size = this.descr.local_stencil_size;
129 % end
131 % reduced_data = gen_reduced_data(detailed_data, this, rd_creator);
132 % end
133 
134 % function reduced_data = extract_reduced_data_subset(this, reduced_data)
135 % rd_creator = NonlinEvol.ReducedDataCreator;
136 % if isfield(this.descr, 'stencil_mode')
137 % rd_creator.stencil_mode = this.descr.stencil_mode;
138 % rd_creator.local_stencil_size = this.descr.local_stencil_size;
139 % end
140 %
141 % reduced_data = extract_reduced_data_subset(reduced_data, this, rd_creator);
142 % end
143 
144  %
145  %
146  % Parameters:
147  % reduced_data: of type NonlinEvol.EiRbReducedDataNode
148  rb_sim_data = rb_simulation_impl(this, reduced_data);
149 
150 % function [LL_I, bb_I] = rb_operators(model, detailed_data)
151 % [LL_I, bb_I] = NonlinEvol.ReducedDataCreator.rb_operators(model, detailed_data);
152 % end
153 
154  function a0 = rb_init_values(this, detailed_data, decomp_mode)
155  % function a0 = rb_init_values(this, detailed_data, decomp_mode)
156  % @copybrief rb_init_values_separable()
157  %
158  % This calls rb_init_values_separable().
159  %
160  % Parameters:
161  % detailed_data: detailed data tree leaf object of type GreedyDataTreeDetailed.PODEILeafNode.
162  %
163  % Return values:
164  % a0: coefficient vector of size 'N x 1' for the initial values.
165  a0 = rb_init_values_separable(this, detailed_data, decomp_mode);
166  end
167 
168  function rb_sim_data = rb_reconstruction(this, detailed_data, rb_sim_data)
169  % function rb_sim_data = rb_reconstruction(this, detailed_data, rb_sim_data)
170  % @copybrief rb_reconstruction_default()
171  %
172  % This calls rb_reconstruction_default().
173  %
174  % Parameters:
175  % detailed_data: of type NonlinEvol.DetailedData
176  % rb_sim_data: struct holding reduced simulation data returned by
177  % ReducedModel.rb_simulation().
178  %
179  % Return values:
180  % rb_sim_data: struct holding the reduced simulation results and their
181  % reconstructions.
182 
183  dd=get_active_leaf(detailed_data, this, 'rb');
184  rb_sim_data = rb_reconstruction_default(this, dd, rb_sim_data);
185  end
186 
187  function enable_error_estimator = get.enable_error_estimator(this)
188  if this.enable_error_estimator && this.Mstrich == 0
189  error('Mstrich needs to be positive if error estimator is enabled!')
190  elseif ~this.enable_error_estimator && this.Mstrich > 0
191  warning('RBMatlab:error_estimator', 'Mstrich is larger than zero, but error_estimator is disabled!');
192  end
193  enable_error_estimator = this.enable_error_estimator;
194  end
195 
196  end
197 
198  methods(Static)
199  function Delta = get_estimators_from_sim_data(rb_sim_data)
200  % function Delta = get_estimators_from_sim_data(rb_sim_data)
201  % @copybrief IReducedModelget_estimators_from_sim_data()
202  %
203  % @copydetails IReducedModelget_estimators_from_sim_data()
204  Delta = rb_sim_data.Delta;
205  end
206 
207  function Delta = get_estimator_from_sim_data(rb_sim_data)
208  % function Delta = get_estimator_from_sim_data(rb_sim_data)
209  % @copybrief IReducedModelget_estimator_from_sim_data()
210  %
211  % @copydetails IReducedModelget_estimator_from_sim_data()
212  Delta = rb_sim_data.Delta(end);
213  end
214 
215 % function U = get_dofs_from_sim_data(sim_data)
216 % if isfield(sim_data, 'U')
217 % U = sim_data.U;
218 % else
219 % U = [];
220 % warning('RBMatlab:NonlinEvolReducedModel:ReconstructionMissing', 'No reconstructed data found in sim_data, execute rb_reconstruct() first');
221 % end
222 % end
223  end
224 
225  methods
226  function t = get.t(this)
227  t = this.descr.t;
228  end
229 
230  function set.t(this, t)
231  this.detailed_model.t = t;
232  end
233 
234  function tstep = get.tstep(this)
235  tstep = this.descr.tstep;
236  end
238  function set.tstep(this, tstep)
239  this.detailed_model.tstep = tstep;
240  end
241  end
242 end
IDetailedModel implementation for a non linear evolution problem.
Definition: DetailedModel.m:18
reduced model for non-linear evolution problems as given by a NonlinEvol.DetailedModel.
Definition: ReducedModel.m:18
function rb_sim_data = rb_reconstruction_default(model, detailed_data, rb_sim_data)
(trivial) function computing a detailed reconstruction by linear combination of the coefficients in t...
class generating the reduced basis space for the LinEvol problem with a Greedy algorithm.
Definition: DetailedData.m:18
This is the common interface for all models, detailed and reduced ones.
Definition: IModel.m:17
compute_conditions
boolean flag indicating whether conditions of system matrices shall be computed.
function a0 = rb_init_values_separable(IReducedModel rmodel,Greedy.DataTree.Detailed.RBLeafNode detailed_data, decomp_mode)
function computing initial values for a reduced simulation.
static function ok = struct_check(descr, checks)
executes checks on the fields of a structure object
Definition: IModel.m:210
Reduced basis implementation for non-linear evolution equations.
Definition: leaf.m:17
an interface specialization for detailed data objects used with the Greedy algorithm.
Definition: IDetailedData.m:19
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 non-linear evolution problems with finite volume discretizations.
decomp_mode
Decomposition operation mode.
Definition: IModel.m:66
Customizable implementation of an abstract greedy algorithm.
Definition: DuneRBLeafNode.m:1
interface specialization for a reduced model that can be used with the Greedy algorithm for basis gen...
Definition: IReducedModel.m:19