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
Heun.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 
18 class Heun
19  :public solvers.BaseCustomSolver {
51  public:
52 
53 
54  Heun(double MaxStep) {
55 
56  this = this@solvers.BaseCustomSolver;
57 
58  this.Name= " Explicit Heun "" s method ";
59  this.SolverType= solvers.SolverTypes.Explicit;
60  if nargin == 1
61  this.MaxStep= MaxStep;
62  end
63  }
77  protected: /* ( Sealed ) */
78 
79  function matrixx = customSolve(function_handle odefun,rowvec t,colvec x0,rowvec<integer> outputtimes) {
80 
81  /* Initialize result */
82  steps = length(t);
83  dt = t(2:end)-t(1:end-1);
84 
85  rtm = this.RealTimeMode;
86 /* if rtm
87  * ed = solvers.SolverEventData;
88  * x = [];
89  * else
90  * x = [x0 zeros(size(x0,1),steps-1)];
91  * end
92  * Initialize output index counter */
93  outidx = 2;
94  if rtm
95  ed = solvers.SolverEventData;
96  x = [];
97  else
98  effsteps = length(outputtimes);
99  /* Create return matrix in size of effectively desired timesteps */
100  x = [x0 zeros(size(x0,1),effsteps-1)];
101  end
102  /* Solve for each time step */
103  oldx = x0;
104  for idx = 2:steps;
105  f = odefun(t(idx-1),oldx);
106  hlp = (dt(idx-1)/2)*(f + odefun(t(idx),oldx + dt(idx-1)*f));
107 
108  /* Check if a mass matrix is present */
109  if ~isempty(this.M)
110 /* newx = oldx + this.M.evaluate(t(idx-1))\hlp; */
111  [L,U] = this.M.getLU(t(idx-1));
112  newx = U\(L\(this.M.evaluate(t(idx-1))*oldx + hlp));
113  else
114  newx = oldx + hlp;
115  end
116 
117 /* if rtm
118  * ed.Times = t(idx);
119  * ed.States = newx;
120  * this.notify('StepPerformed',ed);
121  * else
122  * x(:,idx) = newx;%#ok
123  * end
124  * Only produce output at wanted timesteps */
125  if outputtimes(outidx) == idx
126  if rtm
127  /* Real time mode: Fire StepPerformed event */
128  ed.Times= t(idx);
129  ed.States= newx;
130  this.notify(" StepPerformed ",ed);
131  /* Normal mode: Collect solution in result vector */
132  else
133  x(:,outidx) = newx;
134  end
135  outidx = outidx+1;
136  end
137  oldx = newx;
138  end
139  }
163 };
164 }
165 
166 
167 
notify
Broadcast a notice that a specific event is occurring on a specified handle object or array of handle...
logical RealTimeMode
Determines if the solver's StepPerformed event should be used upon solving instead of returning the f...
Definition: BaseSolver.m:85
BaseCustomSolver: Base class for all self-implemented solvers.
Heun(double MaxStep)
Constructor for the explicit euler solver.
Definition: Heun.m:54
virtual function M = evaluate(double t,colvec< double > mu)
Name
The solver's name.
Definition: BaseSolver.m:116
function matrix x = customSolve(function_handle odefun,rowvec t,colvec x0,rowvec< integer > outputtimes)
Solves the ode using Heuns method.
Definition: Heun.m:79
A MatLab function handle.
solvers.SolverTypes SolverType
The type of the solver.
Definition: BaseSolver.m:130
double MaxStep
Maximum time step for solver.
Definition: BaseSolver.m:48
dscomponents.AMassMatrix M
The mass matrix of the ODE .
Definition: BaseSolver.m:101
A matlab column vector.
virtual function [ L , U , Q , P ] = getLU(double t,colvec< double > mu)
ODE solver implementing the method of heun.
Definition: Heun.m:18
A matlab row vector.