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
ExplEuler.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 ExplEuler
19  :public solvers.BaseCustomSolver {
60  public:
61 
62 
63  ExplEuler(double MaxStep) {
64  this = this@solvers.BaseCustomSolver;
65 
66  this.Name= " Explicit forward euler ";
67  this.SolverType= solvers.SolverTypes.Explicit;
68  if nargin == 1
69  this.MaxStep= MaxStep;
70  end
71  }
85  protected: /* ( Sealed ) */
86 
87  function matrixx = customSolve(function_handle odefun,rowvec t,colvec x0,rowvec<integer> outputtimes) {
88 
89  /* Initialize result */
90  steps = length(t);
91  dt = t(2:end)-t(1:end-1);
92 
93  rtm = this.RealTimeMode;
94  /* Initialize output index counter */
95  outidx = 2;
96  if rtm
97  ed = solvers.SolverEventData;
98  x = [];
99  else
100  effsteps = length(outputtimes);
101  /* Create return matrix in size of effectively desired timesteps */
102  x = [x0 zeros(size(x0,1),effsteps-1)];
103  end
104 
105  /* Solve for each time step */
106  oldx = x0;
107  for idx = 2:steps;
108 
109  hlp = dt(idx-1)*odefun(t(idx-1),oldx);
110  /* Check if a mass matrix is present */
111  if ~isempty(this.M)
112  newx = oldx + this.M.evaluate(t(idx-1))\hlp;
113 /* [L,U,Q,P] = this.M.getLU(t(idx-1));
114  * newx = oldx + Q*(U\(L\(P*hlp)));
115  * newx = oldx + U\(L\hlp); */
116  else
117  newx = oldx + hlp;
118  end
119 
120  /* Only produce output at wanted timesteps */
121  if outputtimes(outidx) == idx
122  if rtm
123  /* Real time mode: Fire StepPerformed event */
124  ed.Times= t(idx);
125  ed.States= newx;
126  this.notify(" StepPerformed ",ed);
127  /* Normal mode: Collect solution in result vector */
128  else
129  x(:,outidx) = newx; /* #ok */
130 
131  end
132  outidx = outidx+1;
133  end
134  oldx = newx;
135  end
136  }
165 };
166 }
167 
168 
169 
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.
virtual function M = evaluate(double t,colvec< double > mu)
ExplEuler(double MaxStep)
Constructor for the explicit euler solver.
Definition: ExplEuler.m:63
Name
The solver's name.
Definition: BaseSolver.m:116
A MatLab function handle.
solvers.SolverTypes SolverType
The type of the solver.
Definition: BaseSolver.m:130
Explicit forward euler ODE solver.
Definition: ExplEuler.m:18
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.
A matlab row vector.
function matrix x = customSolve(function_handle odefun,rowvec t,colvec x0,rowvec< integer > outputtimes)
Solves the ODE using the explicit Euler method.
Definition: ExplEuler.m:87