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
BaseSecondOrderSystem.m
Go to the documentation of this file.
1 namespace models{
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 
36  public: /* ( setObservable ) */
37 
54  public:
55 
57 
58 
74  protected:
75 
76  JDX;
84  public:
85 
87  this = this@models.BaseFirstOrderSystem(model);
88 
89  /* Register default properties */
90  this.registerProps(" D ");
91  }
101  rsys = models.ReducedSecondOrderSystem(rmodel);
102  }
118  prepareSimulation@models.BaseFirstOrderSystem(this, mu, inputidx);
119 
120  /* Forward preparation call to D, if present */
121  if ~isempty(this.D)
122  this.D.prepareSimulation(mu);
123  end
124  }
125 
126 
127  function dx_xdot_c = ODEFun(double t,x_xdot_c) {
128  dx_xdot_c = zeros(size(x_xdot_c));
129 
130  num_x_dof = this.NumStateDofs;
131  num_xdot_dof = this.NumDerivativeDofs;
132  x = x_xdot_c(1:num_x_dof);
133  xdot = x_xdot_c(num_x_dof+(1:num_xdot_dof));
134 
135  /* % Set x'=xdot
136  * Check for derivative dirichlet conditions - insert them here
137  * as direct values */
138  if num_x_dof ~= num_xdot_dof /* Quickest check */
139 
140  dx = zeros(num_x_dof,1);
141  /* Execute callback - subclasses must provide the (possibly
142  * time-dependent) valuess */
143  val = this.getDerivativeDirichletValues(t);
145  /* Dirichlet values */
146  dx(pos) = val;
147  /* Dof values */
148  dx(~pos) = xdot;
149  /* Set in global dof vector */
150  dx_xdot_c(1:num_x_dof) = dx;
151  else
152  /* Direct forwarding - no derivative dirichlet conditions */
153  dx_xdot_c(1:num_x_dof) = xdot;
154  end
155 
156  /* % Set x''=xdot' = A(x)+D(y)+f(x,y)+Bu */
157  dy = zeros(num_xdot_dof,1);
158  if ~isempty(this.A)
159  dy = dy + this.A.evaluate(x, t);
160  end
161  if ~isempty(this.D)
162  dy = dy + this.D.evaluate(xdot, t);
163  end
164  if ~isempty(this.f)
165  dy = dy + this.f.evaluate(x_xdot_c, t);
166  end
167  if ~isempty(this.B) && ~isempty(this.inputidx)
168  B = this.B.evaluate(t, this.mu)*this.u(t);
169  dy = dy + B;
170  end
171  dx_xdot_c(num_x_dof+(1:num_xdot_dof)) = dy;
172  /* Append algebraic constraint evaluation */
173  if ~isempty(this.g)
174  dx_xdot_c(num_x_dof+num_xdot_dof+1:end) = this.g.evaluate(x_xdot_c,t);
175  end
176  }
189  function J = getJacobian(double t,x_xdot_c) {
190  td = this.NumTotalDofs;
191  sd = this.NumStateDofs;
192  dd = this.NumDerivativeDofs;
193  ad = this.NumAlgebraicDofs;
194  xdotpos = sd+(1:dd);
195  xpos = 1:sd;
196  cpos = sd+dd+(1:ad);
197  x = x_xdot_c(xpos);
198  xdot = x_xdot_c(xdotpos);
199  J = sparse(td,td);
200  J(xpos,:) = this.JDX;
201  if ~isempty(this.A)
202  J(xdotpos,xpos) = J(xdotpos,xpos) + this.A.getStateJacobian(x, t);
203  end
204  if ~isempty(this.D)
205  J(xdotpos,xdotpos) = J(xdotpos,xdotpos) + this.D.getStateJacobian(xdot, t);
206  end
207  if ~isempty(this.f)
208  J(xdotpos,:) = J(xdotpos,:) + this.f.getStateJacobian(x_xdot_c, t);
209  end
210  if ~isempty(this.g)
211  J(cpos,:) = this.g.getStateJacobian(x_xdot_c,t);
212  end
213  }
224  td = this.NumTotalDofs;
225  sd = this.NumStateDofs;
226  dd = this.NumDerivativeDofs;
227  ad = this.NumAlgebraicDofs;
228  xdotpos = sd+(1:dd);
229  JP = logical(sparse(td,td));
230  I = speye(sd);
232  this.JDX= [sparse(sd,sd) I sparse(sd,ad)];
233  JP(1:sd,:) = this.JDX;
234  if ~isempty(this.A) && ~isempty(this.A.JSparsityPattern)
235  JP(xdotpos,1:sd) = JP(xdotpos,1:sd) | this.A.JSparsityPattern;
236  end
237  if ~isempty(this.D) && ~isempty(this.D.JSparsityPattern)
238  JP(xdotpos,xdotpos) = JP(xdotpos,xdotpos) | this.D.JSparsityPattern;
239  end
240  if ~isempty(this.f) && ~isempty(this.f.JSparsityPattern)
241  JP(xdotpos,:) = JP(xdotpos,:) | this.f.JSparsityPattern;
242  end
243  if ~isempty(this.g)
244  JP(sd+dd+1:end,:) = this.g.JSparsityPattern;
245  end
246  this.SparsityPattern= JP;
247  }
258  function x_xdot_c0 = getX0(colvec<double> mu) {
259 
260  /* Gets the initial state variable at `t=0`. */
261  x_c0 = getX0@models.BaseFirstOrderSystem(this, mu);
262  num_x_dof = this.NumStateDofs;
263  num_xdot_dof = this.NumDerivativeDofs;
264  x_xdot_c0 = zeros(this.NumTotalDofs,1);
265 
266  /* Insert state initial values */
267  x_xdot_c0(1:num_x_dof) = x_c0(1:num_x_dof);
268 
269  /* Insert derivative initial values (xdot0) between */
270  x_xdot_c0(num_x_dof+(1:num_xdot_dof)) = this.getDerivativeInitialValues(mu);
271 
272  /* Insert alg cond initial values */
273  x_xdot_c0(num_x_dof+num_xdot_dof+1:end) = x_c0(num_x_dof+1:end);
274  }
284  function M = getMassMatrix() {
285  M = this.M;
286  if isempty(M)
287  M = speye(this.NumDerivativeDofs);
288  else
289  if ~isa(M," dscomponents.ConstMassMatrix ")
290  error(" Non-constant mass matrices not yet implemented for second order systems ");
291  end
292  M = this.M.M;
293  end
294  sd = this.NumStateDofs;
295  ad = this.NumAlgebraicDofs;
296  M = blkdiag(speye(sd),M,sparse(ad,ad));
297  /* Tell the mass matrix which components are algebraic
298  * constraint dofs - those wont be used determinig a suitable
299  * initial slope in e.g. solvers.MLWrapper */
300  algdofs = sd+this.NumDerivativeDofs+(1:ad);
301  M = dscomponents.ConstMassMatrix(M,algdofs);
302  }
303 
304 
305  protected:
306 
307 
308  function updateDimensions() {
309  this.NumTotalDofs= this.NumStateDofs ...
310  + this.NumDerivativeDofs + this.NumAlgebraicDofs;
311  }
312 
313 
315  if ~isa(model, " models.BaseModel ")
316  error(" The Model property has to be a child of models.BaseModel ");
317  end
318  }
331  function val = getDerivativeInitialValues(unused1) {
332  val = zeros(this.NumDerivativeDofs,1);
333  }
348  protected: /* ( Abstract ) */
349 
350  virtual function val = getDerivativeDirichletValues(double t) = 0;
370 };
371 }
372 
373 
374 
BaseSecondOrderSystem(models.BaseFullModel model)
Creates a new base dynamical system class instance.
function J = getStateJacobian(unused1, unused2, unused3)
function rsys = getReducedSystemInstance(models.ReducedModel rmodel)
Creates a reduced system given the current system and the reduced model.
function updateSparsityPattern()
The state space vector (NumTotalDofs) is composed of x: Original state space of second order model...
The base class for any KerMor detailed model.
Definition: BaseFullModel.m:18
function J = getStateJacobian(x, t)
Default implementation of jacobian matrix evaluation via finite differences.
Definition: ACoreFun.m:395
dscomponents.AInputConv B
The input conversion.
function prepareSimulation(colvec< double > mu)
A method that allows parameter-dependent computations to be performed before a simulation using this ...
Definition: ACoreFun.m:380
JDX
Pre-Computed pattern for dx-part.
function val = getDerivativeInitialValues(unused1)
Computes the derivative initial values.
function registerProps(varargin)
Call this method at any class that defines DPCM observed properties.
Definition: DPCMObject.m:125
An integer value.
The KerMor reduced model class.
Definition: ReducedModel.m:18
#define I(x, y, z)
Definition: CalcMD5.c:171
inputidx
The current inputindex of the function .
Base class for all KerMor second-order dynamical systems.
dscomponents.LinearCoreFun D
The damping matrix of the second order system.
A boolean value.
function fx = evaluate(colvec< double > x, unused1, unused2)
Definition: LinearCoreFun.m:80
mu
The current parameter for simulations, [] is none used.
DerivativeDirichletPosInStateDofs
A logical column vector containing true at the locations of explicit derivative dirichlet conditions...
function validateModel(models.BaseFullModel model)
Validates if the model to be set is a valid BaseModel at least. Extracting this function out of the s...
function J = getJacobian(double t, x_xdot_c)
Computes the global jacobian of the current RHS system.
function fx = evaluate(x, t)
Evaluates the f-approximation. Depending on a possible projection and the CustomProjection-property t...
Definition: ACoreFun.m:296
Linear core function for state space models (no time or parameter)
Definition: LinearCoreFun.m:18
virtual function B = evaluate(colvec< double > mu)
Template method that evaluates the input conversion matrix at the current time and [optional] param...
sparse< logical > JSparsityPattern
Sparsity pattern for the jacobian matrix.
Definition: ACoreFun.m:127
dscomponents.ACoreFun f
The core f function from the dynamical system.
function x_xdot_c0 = getX0(colvec< double > mu)
Compiles the global x0 vector of the global dof vector.
dscomponents.ACoreFun g
The system's algebraic constraints function.
SparsityPattern
The global sparsity pattern for the entire RHS.
function dx_xdot_c = ODEFun(double t, x_xdot_c)
The state space vector is composed of x: Original state space of second order model xdot: Substituted...
dscomponents.AMassMatrix M
The system's mass matrix.
virtual function val = getDerivativeDirichletValues(double t)
Computes the derivative dirichlet values dependent on the current time.
function prepareSimulation(colvec< double > mu,integer inputidx)
u
The current input function as function handle, [] if none used.
Base class for all KerMor first-order dynamical systems.
Simple affine-linear core function "f" for a dynamical system.
Definition: AffLinCoreFun.m:18
dscomponents.LinearCoreFun A
Represents a linear or affine-linear component of the dynamical system.