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
JacCompEvalWrapper.m
Go to the documentation of this file.
1 namespace general{
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 
45  public:
46 
47  f;
48 
49  trafo = {""};
50 
51 
52  public:
53 
55 
56 
57  public:
58 
60 
61  /* Checks */
62  if ~isa(f," dscomponents.ACompEvalCoreFun ")
63  error(" The system "" s nonlinearity must be a component-wise evaluable function. ");
64  end
65 
66  /* Call superclass constructor */
67  this = this@dscomponents.ACompEvalCoreFun(f.System);
68 
69  /* Original full system function */
70  this.f= f;
71 
72  /* ACoreFun settings */
73  this.xDim= f.xDim;
74  /* output dim is size of jacobian */
75  if ~isempty(f.JSparsityPattern)
76  fdim = length(find(f.JSparsityPattern));
77  else
78  fdim = f.fDim * f.xDim;
79  end
80  this.fDim= fdim;
81  /* So sparsity pattern for the wrapper */
82  this.JSparsityPattern= [];
83 
84  /* Extra: Store original full dimension, as f gets possibly
85  * projected */
86  this.fullxDim= f.xDim;
87  }
98  function colvec<double>fx = evaluate(colvec<double> x,double t) {
99 
100  if ~isempty(this.f.JSparsityPattern)
101  nonzero = find(this.f.JSparsityPattern);
102  else
103  nonzero = 1:this.f.fDim*this.f.xDim;
104  end
105  J = this.f.getStateJacobian(x,t,this.mu);
106  fx = J(nonzero);
107  }
123  function colvec<double>fx = evaluateMulti(colvec<double> x,double t,colvec<double> mu) {
124 
125  if ~isempty(this.f.JSparsityPattern)
126  nonzero = find(this.f.JSparsityPattern);
127  else
128  nonzero = 1:this.f.fDim*this.f.xDim;
129  end
130  fx = zeros(length(nonzero),size(x,2));
131  singlemu = size(mu,2) == 1;
132  if singlemu
133  oldmu = this.f.mu;
134  this.f.prepareSimulation(mu);
135  else
136  for i=1:size(x,2)
137  if ~singlemu
138  this.f.prepareSimulation(mu(:,i));
139  end
140  J = this.f.getStateJacobian(x(:,i),t(i));
141  fx(:,i) = J(nonzero);
142  end
143  end
144  if singlemu
145  this.f.prepareSimulation(oldmu);
146  end
147  }
165  prepareSimulation@dscomponents.ACompEvalCoreFun(this,mu);
166  this.f.prepareSimulation(mu);
167  }
168 
169 
170  function evaluateCoreFun() {
171  error(" Boo. Do not call me. (directly implemented evaluate) ");
172  }
180  function setPointSet(nr,pts) {
181 
182  /* Transform indices to jacobian matrix indices
183  * (the jac wrapper only "works" on nonzero jacobian entries) */
184  if ~isempty(this.f.JSparsityPattern)
185  jidx = find(this.f.JSparsityPattern);
186  pts = jidx(pts)^t;
187  end
188 
189  /* Ensure row vectors */
190  if size(pts,1) > 1
191  pts = reshape(pts,1,[]);
192  end
193  if length(unique(pts)) ~= length(pts)
194  error(" Points have to be unique. ");
195  end
196 
197  /* Get matrix indexing of the desired points
198  * ind2sub direct replacement! */
199  i = rem(pts-1, this.f.fDim)+1;
200  j = (pts-i)/this.f.fDim+1;
201  /* Only use the i-th effective components of f, the j's
202  * correspond to the derivatives of the i-th components with
203  * respect to the j-th variable. */
204  ui = unique(i);
205 
206  deriv = [];
207  pos = [];
208  for k = 1:length(ui)
209  didx = find(i == ui(k));
210  deriv[k] = j(didx); /* #ok<*AGROW> */
211 
212  pos = [pos didx];
213  end
214  /* Can directly set point sets as f instance is clone of
215  * original function */
216  this.f.setPointSet(nr+2, ui, deriv);
217 
218  l = length(pos);
219  this.trafo[nr] = sparse(pos, 1:l, ones(l,1),l,l);
220  }
230  function fx = evaluateComponentSet(nr,colvec<double> x,double t) {
231  dfx = this.f.evaluateJacobianSet(nr+2, x, t);
232  fx = this.trafo[nr]*dfx;
233  }
234 
235 
237  dfx = this.f.evaluateJacobianSetMulti(nr+2, x, t, mu);
238  fx = this.trafo[nr]*dfx;
239  }
240 
241 
242  function copy = clone() {
243  copy = general.JacCompEvalWrapper(this.f);
244  copy = clone@dscomponents.ACompEvalCoreFun(this, copy);
245  copy.trafo= this.trafo;
246  copy.fullxDim= this.fullxDim;
247  }
248 
249 
250  function proj = project(V,W) {
251  proj = project@dscomponents.ACompEvalCoreFun(this, V, W, this.clone);
252  /* Project the wrapped function, too (ignores the extra copy.f
253  * created in clone as project creates a clone anyways) */
254  proj.f= this.f.project(V, W);
255  proj.xDim= proj.f.xDim;
256  /* vec-op leads to product of jacobian size dimension */
257  proj.fDim= proj.f.fDim*proj.f.xDim;
258  }
259 
260 
261  protected:
262 
263  function evaluateComponents() {
264  error(" This should not be called as this is a wrapper for ACompEvalCoreFuns ");
265  }
272 };
273 }
274 
function evaluateCoreFun()
Nothing to do here as the evaluate function is overridden directly.
integer fDim
The current output dimension of the function.
Definition: ACoreFun.m:171
JacCompEvalWrapper: Wraps the evaluation of a ACompEvalCoreFun's jacobian into a vectorized function...
function fx = evaluateComponentSetMulti(nr,colvec< double > x,double t,colvec< double > mu)
reshape
hanges the dimensions of the handle object array to the specified dimensions. See the MATLAB reshape ...
integer xDim
The current state space dimension of the function's argument .
Definition: ACoreFun.m:151
JacCompEvalWrapper(f)
Creates a new jacobian matrix wrapper for linear indexing, which implements dscomponents.ACompEvalCoreFun.
V
The matrix of the biorthogonal pair .
Definition: AProjectable.m:61
colvec< double > mu
The current model parameter mu for evaluations. Will not be persisted as only valid for runtime durin...
Definition: ACoreFun.m:208
function setPointSet(nr, pts)
Overrides the setPointSet method of dscomponents.ACompEvalCoreFun to allow transformation of the indi...
sparse< logical > JSparsityPattern
Sparsity pattern for the jacobian matrix.
Definition: ACoreFun.m:127
function proj = project(V, W)
ACompEvalCoreFun: A normal CoreFun which supports single-component evaluation.
function colvec< double > fx = evaluateMulti(colvec< double > x,double t,colvec< double > mu)
Evaluates the jacobian of the wrapped function at multiple locations and returns a vector correspondi...
function colvec< double > fx = evaluate(colvec< double > x,double t)
Evaluates the jacobian of the wrapped function and returns a vector corresponding to the natural line...
W
The matrix of the biorthogonal pair .
Definition: AProjectable.m:72
function evaluateComponents()
nothing to do here as this is a wrapper
function fx = evaluateComponentSet(nr,colvec< double > x,double t)
function prepareSimulation(colvec< double > mu)