KerMor  0.9
Model order reduction for nonlinear dynamical systems and nonlinear approximation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BaseEstimator.m
Go to the documentation of this file.
1 namespace error{
2 
3 
4 /* (Autoinserted by mtoc++)
5  * This source code has been filtered by the mtoc++ executable,
6  * which generates code that can be processed by the doxygen documentation tool.
7  *
8  * On the other hand, it can neither be interpreted by MATLAB, nor can it be compiled with a C++ compiler.
9  * Except for the comments, the function bodies of your M-file functions are untouched.
10  * Consequently, the FILTER_SOURCE_FILES doxygen switch (default in our Doxyfile.template) will produce
11  * attached source files that are highly readable by humans.
12  *
13  * Additionally, links in the doxygen generated documentation to the source code of functions and class members refer to
14  * the correct locations in the source code browser.
15  * However, the line numbers most likely do not correspond to the line numbers in the original MATLAB source files.
16  */
17 
19  :public KerMorObject,
20  public ICloneable {
65  public: /* ( Dependent ) */
66 
80  public:
81 
82  StateError = "[]";
113  public:
114 
115  OutputError = "[]";
144  public: /* ( Transient ) */
145 
146  mu;
147 
148 
149  private:
150 
151  fEnabled = true;
152 
153  e0Comp;
154 
155 
156  public:
157 
158 
160 
161  if isa(model.System.x0," dscomponents.AffineInitialValue ")
162  this.e0Comp= error.initial.AffineParametric;
163  else
164  this.e0Comp= error.initial.Constant;
165  end
166  }
181  function doublect = postProcess(unused1,rowvec t,unused2) {
182 
183  if all(this.StateError == 0)
184  warning(" BaseEstimator:postProcess "," State error is all zero. Attention! ");
185  end
186 
187  st = tic;
188  /* Tranform to output error estimation (if used) */
189  fs = this.ReducedModel.FullModel.System;
190  C = fs.C;
191  if ~isequal(fs.StateScaling,1)
192  fd = size(this.ReducedModel.V,1);
193  C = C*spdiags(fs.StateScaling,0,fd,fd);
194  end
195  if ~isempty(C)
196  /* Get error */
197  if C.TimeDependent
198  e = this.StateError;
199  for idx=1:length(t)
200  e(idx) = norm(m.System.C.evaluate(t(idx),this.mu))*e(idx);
201  end
202  else
203  Ce = C.evaluate([],this.mu);
204  if issparse(Ce)
205  Cn = normest(Ce);
206  else
207  Cn = norm(Ce);
208  end
209  this.OutputError= Cn*this.StateError;
210  end
211  else
212  this.OutputError= this.StateError;
213  end
214  ct = toc(st);
215  }
234  function clear() {
235  this.StateError= [];
236  this.OutputError= [];
237  }
244  function copy = clone(copy) {
245  if nargin < 2
246  error(" Clone to this method can only be called from subclasses. ");
247  end
248  copy.ExtraODEDims= this.ExtraODEDims;
249  copy.StateError= this.StateError;
250  copy.OutputError= this.OutputError;
251  copy.Enabled= this.Enabled;
252  /* no cloning; components are only used in reduced models. */
253  copy.e0Comp= this.e0Comp;
254  /* No cloning of the associated reduced model. */
255  copy.ReducedModel= this.ReducedModel;
256  copy.mu= this.mu;
257  }
270  function e0 = getE0(colvec<double> mu) {
271  e0 = this.e0Comp.getE0(mu);
272  }
282  function ct = prepareConstants(colvec<double> mu,unused1) {
283  this.mu= mu;
284  ct = 0;
285  }
286 
287 
288  function prepared = prepareForReducedModel(models.ReducedModel rmodel) {
289  prepared = this.clone;
290  if ~isa(rmodel," models.ReducedModel ")
291  error(" The given value has to be a models.ReducedModel instance. ");
292  end
293  prepared.ReducedModel= rmodel;
294  this.e0Comp.prepareForReducedModel(rmodel);
295  }
310  /* % Getter & Setter */
311  public:
312 
313 
314 
315 #if 0 //mtoc++: 'set.StateError'
316 function StateError(value) {
317  this.StateError= value;
318  }
319 
320 #endif
321 
322 
323 
324 #if 0 //mtoc++: 'set.ExtraODEDims'
325 function ExtraODEDims(value) {
326  if (~isscalar(value) || value < 0) && value ~= 0
327  error(" The value must be 0 or positive integer ");
328  end
329  this.ExtraODEDims= value;
330  }
331 
332 #endif
333 
334 
335 
336 #if 0 //mtoc++: 'set.Enabled'
337 function Enabled(value) {
338  if ~islogical(value)
339  error(" Enabled property must be a boolean flag ");
340  elseif ~value
341  this.StateError= [];
342  end
343  this.fEnabled= value;
344  }
345 
346 #endif
347 
348 
349 
350 #if 0 //mtoc++: 'get.Enabled'
351 function value = Enabled() {
352  value = this.fEnabled;
353  }
354 
355 #endif
356 
357 
358  public: /* ( Abstract ) */
359 
360  virtual function eint = evalODEPart(colvec x,double t,double ut) = 0;
379  public: /* ( Static ) */
380 
381  static function est = getEstimator(models.BaseFullModel model) {
382  if isempty(error.IterationCompLemmaEstimator.validModelForEstimator(model))
383  est = error.IterationCompLemmaEstimator;
384 /* elseif isempty(error.TPWLLocalLipEstimator.validModelForEstimator(model))
385  * est = error.TPWLLocalLipEstimator(model); */
386  elseif isempty(error.DEIMEstimator.validModelForEstimator(model))
387  est = error.DEIMEstimator;
388  elseif isempty(error.GLEstimator.validModelForEstimator(model))
389  est = error.GLEstimator;
390  else
391  est = error.DefaultEstimator;
392  fprintf(" BaseEstimator.getEstimator: No suitable error estimator found for given model. Using the default estimator (disabled).\n ");
393  end
394  }
415  public: /* ( Abstract, Static ) */
416 
417  static function errmsg = validModelForEstimator(models.ReducedModel rmodel) = 0;
440 };
441 }
442 
443 
444 
function copy = clone(copy)
Creates a copy of this error estimator. Call only allowed from subclasses.
virtual function eint = evalODEPart(colvec x,double t,double ut)
Template method for evaluation of the auxiliary ode part of the error estimator.
ICLONEABLE Interface for cloneable handle classes.
Definition: ICloneable.m:17
The base class for any KerMor detailed model.
Definition: BaseFullModel.m:18
models.BaseFullModel FullModel
The full model this reduced model was created from.
Definition: ReducedModel.m:53
models.BaseFirstOrderSystem System
The actual dynamical system used in the model.
Definition: BaseModel.m:102
OutputError
The output error from the last simulation.
Base class for any KerMor class.
Definition: KerMorObject.m:17
static function errmsg = validModelForEstimator(models.ReducedModel rmodel)
Abstract static method that forces subclasses to specify whether an estimator can be used for a given...
StateError
The reduction state-space error from the last simulation.
Definition: BaseEstimator.m:82
The KerMor reduced model class.
Definition: ReducedModel.m:18
matrix< double > V
The matrix that has been used for projection.
Definition: ReducedModel.m:72
function e0 = getE0(colvec< double > mu)
Calls the inner initial error computation strategy.
dscomponents.AInitialValue x0
Function handle to initial state evaluation.
Base class for all error estimators.
Definition: BaseEstimator.m:18
Enabled
Flag that indicates whether error estimation is used or not.
Definition: BaseEstimator.m:67
function double ct = postProcess(unused1,rowvec t, unused2)
Post-processes the error estimator ODE part after reduced simulation computation. ...
function prepared = prepareForReducedModel(models.ReducedModel rmodel)
Default implementation which simply clones this (subclass!)instance and returns the copy to use in re...
Speed test * all(1:3)
function ct = prepareConstants(colvec< double > mu, unused1)
dscomponents.LinearOutputConv C
The output conversion Defaults to an LinearOutputConv instance using a 1-matrix, which just forwards ...
function clear()
Clears the last error set by the estimator.
A matlab row vector.
static function est = getEstimator(models.BaseFullModel model)
Factory method that creates a suitable error estimator for the given model.
function offlineComputations(models.BaseFullModel model)
Performs a validity check for the given model and sets up the estimator for use with the specified mo...
models.ReducedModel ReducedModel
The reduced model associated with the error estimator.
ExtraODEDims
The dimensions added to the ODE function by the estimator.
Definition: BaseEstimator.m:97