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
BaseCustomSolver.m
Go to the documentation of this file.
1 namespace solvers{
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 solvers.BaseSolver {
44  public:
45 
47  this = this@solvers.BaseSolver;
48  this.Name= " Base Custom Solver ";
49  }
50 
51 
52  function [rowvect , matrixx ] = solve(function_handle odefun,rowvec t,colvec x0) {
53 
54  /* Get computation times
55  *[times, outputtimes] = this.getCompTimes(t); */
56  [times, outidx] = this.getCompTimes(t);
57 
58  /* Fire PreSolve event */
59  ed = solvers.SolverEventData(times);
60  notify(this," PreSolve ",ed);
61 
62  x = this.customSolve(odefun, times, x0, outidx);
63 
64  /* Fire PostSolve event */
65  ed.States= x;
66  notify(this," PostSolve ",ed);
67 
68  /* Extract wanted values */
69  t = times(outidx);
70  /* New: x is supposed to be returned in the size of effectively desired timesteps
71  * (memory issues for large, long simulations)
72  *x = x(:,outputtimes); */
73  }
90  private:
91 
92  function [times , rowvec<integer>outidx ] = getCompTimes(rowvec<double> t) {
93 
94  /* Validity checks */
95  if any(abs(sort(t) - t) > 100*eps)
96  error(" The time vector must be strictly monotoneously increasing. ");
97  end
98 
99  /* Default values
100  * outputtimes = true(1,length(t)); */
101  outidx = 1:length(t);
102  times = t;
103  if ~isempty(this.MaxStep)
104  if numel(t) == 2
105  times = t(1):this.MaxStep:t(2);
106  /* outputtimes = true(1,length(times)); */
107  outidx = [1,length(times)];
108  else
109  len = length(t);
110  n = max(round((t(2:len)-t(1:len-1))/this.MaxStep),1); /* number of steps in interval [t(i-1),t(i)] after refinemant. If t(i-1)-t(i)>= 1.5*MaxStep, interval will be refined */
111 
112  m = ones(1,len); /* m(i) is the index of the originally i-th entry in t in times */
113 
114  m(2:len) = cumsum(n) + m(2:len);/* - (0:len-2); */
115 
116  times = zeros(1,m(len));
117  /* outputtimes = times; */
118  for i = 1:len-1
119  times(m(i):m(i+1))= t(i):(t(i+1)-t(i))/(n(i)):t(i+1); /* linspace(t(i),t(i+1),n(i));
120  * outputtimes(m(i)) = 1; */
121 
122  outidx(i) = m(i);
123  end
124  /* outputtimes(end) = 1; */
125  outidx(end) = length(times);
126  end
127  /* outputtimes = logical(outputtimes); */
128 
129  /* % Find refinement indices
130  * idx = fliplr(find(t(2:end)-t(1:end-1)-this.MaxStep>100*eps));
131  * % If any "gaps" are present, fill up with MaxStep's
132  *
133  * if ~isempty(idx)
134  * for i=idx
135  * add = times(i):this.MaxStep:times(i+1);
136  * times = [times(1:i-1) add times(i+2:end)];
137  * outputtimes = [outputtimes(1:i) false(1,length(add)-2) outputtimes(i+1:end)];
138  * end
139  * tout = times(outputtimes);
140  * if numel(tout) ~= numel(t) || any(abs(tout - t) > 100*eps)
141  * error('Unexpected error: Computed time vector differs from the desired one.');
142  * t%#ok
143  * end */
144  end
145  }
187  protected: /* ( Abstract ) */
188 
189  virtual function colvec<double>x = customSolve(odefun,t,x0,outputtimes) = 0;
216  public: /* ( Abstract ) */
217 
218  EVENT PreSolve;
234  EVENT PostSolve;
251 };
252 }
253 
notify
Broadcast a notice that a specific event is occurring on a specified handle object or array of handle...
BaseCustomSolver: Base class for all self-implemented solvers.
Name
The solver's name.
Definition: BaseSolver.m:116
sort
ort the handle objects in any array in ascending or descending order.
A MatLab function handle.
EVENT PostSolve
Gets fired after the solver has finished.
double MaxStep
Maximum time step for solver.
Definition: BaseSolver.m:48
A matlab column vector.
virtual function colvec< double > x = customSolve(odefun, t, x0, outputtimes)
The abstract solve function for custom ODE solver implementations.
A matlab row vector.
Base class for all KerMor ODE solvers.
Definition: BaseSolver.m:18
EVENT PreSolve
Gets fired before the solver starts.
function [ rowvec t , matrix x ] = solve(function_handle odefun,rowvec t,colvec x0)
Solves the ode and wraps the actual solving method.