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
MLode15i.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 MLode15i
19  :public solvers.MLWrapper {
54  public: /* ( setObservable ) */
55 
56  double RelTol = 1e-3;
78  double AbsTol = 1e-6;
100  private:
101 
102  fED;
103 
104 
105  public:
106 
108  this = this@solvers.MLWrapper(@ode15i);
109  this.Name= " MatLab ode15i implicit solver wrapper ";
110  this.registerProps(" RelTol "," AbsTol ");
111  this.SolverType= solvers.SolverTypes.Implicit;
112  /* "Disable" MaxStep DPCM warning as implicit solvers are stable */
113  this.MaxStep= [];
114  }
115 
116 
117  protected:
118 
119  function varargout = solverCall(function_handle odefun,rowvec<double> t,x0,struct opts) {
120  opts = odeset(opts, " RelTol ", this.RelTol, " AbsTol ", this.AbsTol);
121 
122  if isempty(opts.InitialSlope)
123  error(" The ode15i solver must be provided with an initial slope. ");
124  end
125 
126  /* % Use properties from AJacobianSolver
127  * Set Jacobian or Mass matrix */
128  if ~isempty(this.JacFun) || ~isempty(this.M)
129  opts = odeset(opts, " Jacobian ", @this.FJAC);
130  end
131 
132  /* Process any sparsity patterns */
133  JP = [[],[]];
134  if ~isempty(this.JPattern)
135  JP[1] = this.JPattern;
136  end
137  /* Set df/dyp sparsity pattern, derived from mass matrix. Works
138  * only (at least can be guaranteed) for constant mass matrices. */
139  if ~isempty(this.M)
140  JP[2] = this.M.SparsityPattern;
141  else
142  JP[2] = speye(size(x0,1));
143  end
144  opts = odeset(opts, " JPattern ", JP);
145 
146  /* % Call implicit solver
147  * implfun: A handle to the implicit function `f` which describes
148  * the ODE via `f(t,x,x') = 0` */
149  if ~isempty(this.M)
150  if this.M.TimeDependent
151  implfun = @(t,x,xp)this.M.evaluate(t)*xp - odefun(t,x);
152  else
153  M = this.M.evaluate(0);
154  implfun = @(t,x,xp)M*xp - odefun(t,x);
155  end
156  else
157  implfun = @(t,x,xp)xp - odefun(t,x);
158  end
159 
160  /* Final check for consistent initial condition */
161  initialnorm = norm(implfun(0,x0,opts.InitialSlope));
162  if initialnorm > 1e-11
163  warning(" Initial conditions possibly inconsistent. ||f(0,x0,dx0)|| = %g ",initialnorm);
164  end
165 
166  /* Call ode15i solver */
167  [varargout[1:nargout]] = this.MLSolver(implfun, t, x0, opts.InitialSlope, opts);
168  }
187  private:
188 
189  function [dfdx , dfdxp ] = FJAC(t,x,xp) {
190 
191  /* Implicit funcion is M*xp - odefun(t,x), so derivatives: */
192  dfdx = [];
193  if ~isempty(this.JacFun)
194  dfdx = -this.JacFun(t, x);
195  end
196  if ~isempty(this.M)
197  dfdxp = this.M.evaluate(t);
198  else
199  dfdxp = speye(size(x,1));
200  end
201  }
219 };
220 }
221 
double RelTol
Relative error tolerance for solver.
Definition: MLode15i.m:56
double AbsTol
Absolute error tolerance for solver.
Definition: MLode15i.m:78
A double value.
logical TimeDependent
Flag that indicates time-dependency of the Mass Matrix.
Definition: AMassMatrix.m:42
virtual function M = evaluate(double t,colvec< double > mu)
Allows to wrap a MatLab ODE solver into the KerMor framework.
Definition: MLWrapper.m:18
Name
The solver's name.
Definition: BaseSolver.m:116
sparsematrix JPattern
The sparsity pattern of the jacobian .
function_handle JacFun
A function handle to compute the core function's jacobian.
function registerProps(varargin)
Call this method at any class that defines DPCM observed properties.
Definition: DPCMObject.m:125
A MatLab function handle.
function_handle MLSolver
The wrapped Matlab-Solver.
Definition: MLWrapper.m:60
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
MLode15i: Wrapper for MatLab's ode15i builtin implicit solver.
Definition: MLode15i.m:18
function varargout = solverCall(function_handle odefun,rowvec< double > t, x0,struct opts)
Solves the ode specified by odefun implicitly.
Definition: MLode15i.m:119
sparsematrix SparsityPattern
The sparsity pattern for the mass matrix.
Definition: AMassMatrix.m:57
A variable number of output arguments.