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
ReducedSystem.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 
57  public:
58 
59  R;
70  private:
71 
72  plotPtr;
73 
74 
75  public:
76 
77  ReducedSystem(rmodel) {
78  this = this@models.BaseFirstOrderSystem(rmodel);
79  }
89  function build() {
90  disp(" Start building reduced system... ");
91 
92  rmodel = this.Model;
93  fullmodel = rmodel.FullModel;
94  fullsys = fullmodel.System;
95 
96  V = rmodel.V;
97 
98  if ~isempty(fullmodel.SpaceReducer) && isempty(V)
99  error([" Model has a SpaceReducer but no projection "...
100  " matrix V is given. Forgot to call offlineGenerations? "]);
101  end
102 
103  W = rmodel.W;
104  /* Use V if W is empty (Galerkin projection) */
105  if ~isempty(V) && isempty(W)
106  W = V;
107  end
108 
109  this.updateDimensions;
110 
111  /* The state scaling for the reduced system is one, as the scaling matrices have been
112  * incorporated into the V,W matrices via V := SV and W = S^-1W inside the ReducedModel
113  * setModel method. */
114  this.StateScaling= 1;
115  SV = 1; SW = 1; /* Default: no scaling */
116 
117  s = fullmodel.System.StateScaling;
118  if s ~= 1
119  if isscalar(s)
120  dim = fullsys.NumStateDofs;
121  s(1:dim,1) = s;
122  else
123  dim = length(s);
124  end
125  SV = spdiags(s,0,dim,dim);
126  SW = spdiags(1./s,0,dim,dim);
127  end
128  /* Incorporate the state scaling into the projection matrices.
129  * They are used to project the x0 initial values and output C. */
130  if ~isempty(V)
131  SV = SV * V;
132  SW = SW * W;
133  end
134 
135  /* Clones the full system's basic (all but functions)
136  * properties */
137  this.Params= fullsys.Params;
138  this.Inputs= fullsys.Inputs;
139  this.MaxTimestep= fullsys.MaxTimestep;
140 
141  /* Copy component handles (it's NOT cloning them!)
142  * This is the default as if no reduction methods are
143  * applied (sensless but yet allowed) an identical system
144  * will be the result. */
145  this.f= fullsys.f;
146  this.B= fullsys.B;
147 
148  /* SV ~= 1 means that projection or nontrivial scaling is used. */
149  if ~isequal(SV,1)
150  if ~isempty(fullsys.x0) /* otherwise error for static models */
151 
152  this.x0= fullsys.x0.project(SV,SW);
153  end
154  SR = this.compileReconstructionMatrix(SV);
155  this.C= fullsys.C.project(SR,SW);
156  else
157  if ~isempty(fullsys.x0) /* otherwise error for static models */
158 
159  this.x0= fullsys.x0.clone;
160  end
161  this.C= fullsys.C.clone;
162  end
163 
164  /* Check whether projection was setup for this system */
165  if ~isempty(V)
166  this.R= this.compileReconstructionMatrix(V);
167 
168  /* Project input */
169  if ~isempty(fullsys.B)
170  this.B= fullsys.B.project(V,W);
171  end
172  /* Project linear part */
173  if ~isempty(fullsys.A)
174  this.A= fullsys.A.project(V,W);
175  end
176  /* Project the approximated CoreFun of the full model if exists */
177  if ~isempty(fullmodel.Approx)
178  this.f= fullmodel.Approx.project(V,W);
179  elseif ~isempty(fullsys.f)
180  /* Otherwise project the models' full function. */
181  this.f= fullsys.f.project(this.R,W);
182  end
183  /* Project mass matrix */
184  if ~isempty(fullsys.M)
185  this.M= fullsys.M.project(V,W);
186  end
187  /* Project algebraic constraints function
188  * This needs only affect the getStateJacobian function of
189  * ACoreFun */
190  if ~isempty(fullsys.g)
191  this.g= fullsys.g.project(this.R,1);
192  this.g.setSystem(this);
193  end
194  else
195  /* Only use approximated version if set */
196  if ~isempty(fullmodel.Approx)
197  this.f= fullmodel.Approx;
198  end
199  end
200  /* Set the reduced system as base system for the projected
201  * ACoreFun - it will need to change references to the full
202  * system itself if required */
203  this.f.setSystem(this);
204 
205  /* Set the plot-wrapper (uses the plot method from the full
206  * system) */
207  this.plotPtr= @fullsys.plot;
208  }
231  this.SparsityPattern= [];
232  }
239  function plot(models.BaseFullModel model,double t,matrix<double> y) {
240  this.plotPtr(model, t, y);
241  }
253  function dx = ODEFun(double t,colvec<double> x) {
254  est = this.Model.ErrorEstimator;
255  haveest = ~isempty(est) && est.Enabled;
256  if haveest
257  xall = x;
258  x = x(1:end-est.ExtraODEDims,:);
259  end
260 
261  dx = ODEFun@models.BaseFirstOrderSystem(this,t,x);
262 
263  if haveest
264  dx = [dx; est.evalODEPart(xall, t, this.u(t))];
265  end
266  }
267 
268 
269  function J = getJacobian(double t,xc) {
270  est = this.Model.ErrorEstimator;
271  haveest = ~isempty(est) && est.Enabled;
272  if haveest
273  xc = xc(1:end-est.ExtraODEDims,:);
274  end
275  J = getJacobian@models.BaseFirstOrderSystem(this, t, xc);
276  if haveest
277  J = blkdiag(J,0);
278  end
279  }
280 
281 
282  function x0 = getX0(colvec<double> mu) {
283 
284  x0 = getX0@models.BaseFirstOrderSystem(this, mu);
285  m = this.Model;
286  if ~isempty(m.ErrorEstimator) && m.ErrorEstimator.Enabled
287  x0 = [x0; m.ErrorEstimator.getE0(mu)];
288  end
289  }
302  protected:
303 
304 
305  function R = compileReconstructionMatrix(V) {
306  R = V;
307  }
308 
309 
310  function updateDimensions() {
311  rm = this.Model;
312  if ~isempty(rm.V)
313  /* This is the projection case */
314  this.NumStateDofs= size(rm.V,2);
315  else
316  /* No projection case */
317  this.NumStateDofs= rm.FullModel.System.NumStateDofs;
318  end
319  this.NumAlgebraicDofs= rm.FullModel.System.NumAlgebraicDofs;
320  this.NumTotalDofs= this.NumStateDofs + this.NumAlgebraicDofs;
321  }
322 
323 
325  if ~isa(model, " models.ReducedModel ")
326  error(" The Model property has to be a child of models.ReducedModel ");
327  end
328  }
340 };
341 }
342 
343 
344 
function updateDimensions()
Params
The parameters usable for the dynamical system.
function plot(models.BaseFullModel model,double t,matrix< double > y)
Unless overridden for specific reduced system plots this method just calls the plot method of the ori...
The base class for any KerMor detailed model.
Definition: BaseFullModel.m:18
dscomponents.AInputConv B
The input conversion.
function R = compileReconstructionMatrix(V)
Model
The Model this System is attached to.
ReducedSystem: A KerMor reduced dynamical system.
Definition: ReducedSystem.m:18
function J = getJacobian(double t, xc)
ReducedSystem(rmodel)
Creates a new ReducedSystem instance.
Definition: ReducedSystem.m:77
dscomponents.AInitialValue x0
Function handle to initial state evaluation.
function build()
Creates a reduced system from BaseFullModel child system. As default, all system's components are cop...
Definition: ReducedSystem.m:89
function x0 = getX0(colvec< double > mu)
Gets the initial value of .
mu
The current parameter for simulations, [] is none used.
function dx = ODEFun(double t,colvec< double > x)
Inputs
The system's possible input functions. A cell array of function handles, each taking a time argument ...
colvec StateScaling
The scaling for the state vectors.
disp
Handle object disp method which is called by the display method. See the MATLAB disp function...
function handle target = project(matrix< double > V,matrix< double > W,handle target)
Returns a NEW INSTANCE of the projected object that does not rely on data of the old one via referenc...
Definition: AProjectable.m:85
function copy = clone(copy)
The interface method with returns a copy of the current class instance.
Definition: AProjectable.m:117
R
The reduced dof to full dof reconstruction matrix.
Definition: ReducedSystem.m:59
function validateModel(models.BaseFullModel model)
Overrides the validateModel function in BaseFirstOrderSystem.
A
The systems core function matrix.
Definition: LinearCoreFun.m:30
dscomponents.LinearOutputConv C
The output conversion Defaults to an LinearOutputConv instance using a 1-matrix, which just forwards ...
dscomponents.ACoreFun f
The core f function from the dynamical system.
dscomponents.ACoreFun g
The system's algebraic constraints function.
SparsityPattern
The global sparsity pattern for the entire RHS.
dscomponents.AMassMatrix M
The system's mass matrix.
u
The current input function as function handle, [] if none used.
double MaxTimestep
The maximum timestep allowed for any ODE solvers.
Base class for all KerMor first-order dynamical systems.
function updateSparsityPattern()
Reduced systems are not sparse anymore.
function target = project(V, W, target)
Sets the protected matrices that can be utilized on core function evaluations after projection...
Definition: ACoreFun.m:247
dscomponents.LinearCoreFun A
Represents a linear or affine-linear component of the dynamical system.