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
CoreFun1D.m
Go to the documentation of this file.
1 namespace models{
2 namespace pcd{
3 
4 
5 /* (Autoinserted by mtoc++)
6  * This source code has been filtered by the mtoc++ executable,
7  * which generates code that can be processed by the doxygen documentation tool.
8  *
9  * On the other hand, it can neither be interpreted by MATLAB, nor can it be compiled with a C++ compiler.
10  * Except for the comments, the function bodies of your M-file functions are untouched.
11  * Consequently, the FILTER_SOURCE_FILES doxygen switch (default in our Doxyfile.template) will produce
12  * attached source files that are highly readable by humans.
13  *
14  * Additionally, links in the doxygen generated documentation to the source code of functions and class members refer to
15  * the correct locations in the source code browser.
16  * However, the line numbers most likely do not correspond to the line numbers in the original MATLAB source files.
17  */
18 
19 class CoreFun1D
20  :public models.pcd.BaseCoreFun {
45  private:
46 
47  nodes;
55  public:
56 
57 
58  CoreFun1D(dynsys) {
59  this = this@models.pcd.BaseCoreFun(dynsys);
60  this.TimeDependent= false;
61  }
62 
63 
64  function copy = clone() {
65  copy = models.pcd.CoreFun1D(this.System);
66 
67  /* Call superclass method */
68  copy = clone@models.pcd.BaseCoreFun(this, copy);
69  copy.nodes= this.nodes;
70  }
71 
72 
73  function newSysDimension() {
74  n = this.System.Dims(1);
75  /* Add x_a dependencies
76  * 1=x_a, 2=y_a, 3=x_i {, y_i} */
77  i = [(1:n)" ; (1:n) "; (1:n)^t];
78  j = (1:3*n)^t;
79  /* Add y_a dependencies
80  * 1=x_a, 2=y_a {, x_i}, 3=y_i */
81  i = [i; (n+1:2*n)" ; (n+1:2*n) "; (n+1:2*n)^t];
82  j = [j; (1:2*n)" ; (3*n+1:4*n) "];
83  /* Add x_i dependencies
84  * {x_a,} 1=y_a, 2=x_i {, y_i} */
85  i = [i; (2*n+1:3*n)" ; (2*n+1:3*n) "];
86  j = [j; (n+1:3*n)^t];
87  /* Add y_i dependencies
88  * 1=x_a, {y_a, x_i}, 2=y_i */
89  i = [i; (3*n+1:4*n)" ; (3*n+1:4*n) "];
90  j = [j; (1:n)" ; (3*n+1:4*n) "];
91  this.xDim= 4*n;
92  this.fDim= 4*n;
93  this.JSparsityPattern= sparse(i,j,ones(length(i),1),this.fDim,this.xDim);
94  this.nodes= n;
95  }
96 
97 
98  function fx = evaluate(colvec<double> x,unused1) {
99  fx = zeros(size(x));
100 
101  m = this.nodes;
102  n = this.System.Model.n;
103 
104  /* Non-Multidimensional case */
105  mu = [this.System.ReacCoeff; this.mu];
106 
107  /* Extract single functions */
108  xa = x(1:m);
109  xan = xa.^n;
110  ya = x(m+1:2*m);
111  xi = x(2*m+1:3*m);
112  yi = x(3*m+1:end);
113 
114  /* Boundary conditions */
115  rb = zeros(m,1);
116  rb(end) = xi(end)*mu(9)/this.System.hs; /* max((500-t)/500,0)* */
117 
118 
119  fx(1:m) = mu(1)*xi.*ya - mu(3)*xa + rb;
120  fx(m+1:2*m) = mu(2)*yi.*xan - mu(4)*ya;
121  fx(2*m+1:3*m) = -mu(1)*xi.*ya - mu(5)*xi + mu(7) - rb;
122  fx(3*m+1:end) = -mu(2)*yi.*xan - mu(6)*yi + mu(8);
123  }
134  function fx = evaluateMulti(colvec<double> x,unused1,colvec<double> mu) {
135  fx = zeros(size(x));
136 
137  m = this.nodes;
138  n = this.System.Model.n;
139 
140  mu = [repmat(this.System.ReacCoeff,1,size(mu,2)); mu];
141  /* Extract single functions */
142  xa = x(1:m,:);
143  xan = xa.^n;
144  ya = x(m+1:2*m,:);
145  xi = x(2*m+1:3*m,:);
146  yi = x(3*m+1:end,:);
147 
148  /* Boundary conditions */
149  rb = zeros(m,size(xi,2));
150  rb(end,:) = (xi(end,:).*mu(9,:))/this.System.hs;
151 
152  fx(1:m,:) = bsxfun(@times,xi.*ya,mu(1,:)) - bsxfun(@times,xa,mu(3,:)) + rb;
153  fx(m+1:2*m,:) = bsxfun(@times,yi.*xan,mu(2,:)) - bsxfun(@times,ya,mu(4,:));
154  fx(2*m+1:3*m,:) = -bsxfun(@times,xi.*ya,mu(1,:)) - bsxfun(@times,xi,mu(5,:)) + bsxfun(@times,ones(size(xi)),mu(7,:)) - rb;
155  fx(3*m+1:end,:) = -bsxfun(@times,yi.*xan,mu(2,:)) - bsxfun(@times,yi,mu(6,:)) + bsxfun(@times,ones(size(xi)),mu(8,:));
156  }
168  protected:
169 
170  function fxj = evaluateComponents(pts,ends,unused1,unused2,X,unused3) {
171  fxj = this.evaluateComponentsMulti(pts, ends, [], [], X, [], this.mu);
172  }
173 
174 
175  function fxj = evaluateComponentsMulti(rowvec<integer> pts,rowvec<integer> ends,unused1,unused2,matrix<double> X,unused3,matrix<double> mu) {
176  m = this.nodes;
177  s = this.System;
178  n = s.Model.n;
179  fxj = zeros(length(pts),size(X,2));
180 
181  mu = [repmat(s.ReacCoeff,1,size(mu,2)); mu];
182  for idx=1:length(pts)
183  j = pts(idx);
184  if idx == 1
185  st = 0;
186  else
187  st = ends(idx-1);
188  end
189  /* Select the elements of x that are effectively used in f */
190  xidx = (st+1):ends(idx);
191  x = X(xidx,:);
192 
193  /* X_a */
194  if j <= m
195  /* 1=x_a, 2=y_a, 3=x_i {, y_i}
196  * mu(1)*xi.*ya - mu(3)*xa + rb; */
197  fj = mu(1,:).*x(3,:).*x(2,:) - mu(3,:).*x(1,:);
198  /* Boundary condition */
199  if j == m
200  fj = fj + x(3,:).*mu(9,:)/s.hs;
201  end
202 
203  /* Y_a */
204  elseif m < j && j <= 2*m
205  /* 1=x_a, 2=y_a {, x_i}, 3=y_i
206  * mu(2)*yi.*xan - mu(4)*ya; */
207  fj = mu(2,:).*x(3,:).*x(1,:).^n - mu(4,:).*x(2,:);
208 
209  /* X_i */
210  elseif 2*m < j && j <= 3*m
211  /* {x_a,} 1=y_a, 2=x_i {, y_i}
212  * -mu(1)*xi.*ya - mu(5)*xi + mu(7) - rb; */
213  fj = -mu(1,:).*x(2,:).*x(1,:) - mu(5,:).*x(2,:) + mu(7,:);
214  /* Boundary condition */
215  if j == 3*m
216  fj = fj - x(2,:).*mu(9,:)/s.hs;
217  end
218 
219  /* Y_i */
220  else
221  /* 1=x_a, {y_a, x_i}, 2=y_i
222  * -mu(2)*yi.*xan - mu(6)*yi + mu(8); */
223  fj = -mu(2,:).*x(2,:).*x(1,:).^n - mu(6,:).*x(2,:) + mu(8,:);
224  end
225  fxj(idx,:) = fj;
226  end
227  }
250 };
251 }
252 }
253 
254 
255 
The core nonlinear function of the PCD model.
Definition: CoreFun1D.m:19
integer fDim
The current output dimension of the function.
Definition: ACoreFun.m:171
function fx = evaluate(colvec< double > x, unused1)
Allocate result vector.
Definition: CoreFun1D.m:98
function newSysDimension()
Definition: CoreFun1D.m:73
logical TimeDependent
Flag that indicates if the ACoreFun is (truly) time-dependent.
Definition: ACoreFun.m:84
Model
The Model this System is attached to.
function fxj = evaluateComponents(pts, ends, unused1, unused2, X, unused3)
Definition: CoreFun1D.m:170
integer xDim
The current state space dimension of the function's argument .
Definition: ACoreFun.m:151
models.BaseFirstOrderSystem System
The system associated with the current ACoreFun.
Definition: ACoreFun.m:193
colvec< double > mu
The current model parameter mu for evaluations. Will not be persisted as only valid for runtime durin...
Definition: ACoreFun.m:208
#define X(i, j)
sparse< logical > JSparsityPattern
Sparsity pattern for the jacobian matrix.
Definition: ACoreFun.m:127
function fxj = evaluateComponentsMulti(rowvec< integer > pts,rowvec< integer > ends, unused1, unused2,matrix< double > X, unused3,matrix< double > mu)
The vector embedding results from the fixed ordering of the full 4*m-vector into the components x_a...
Definition: CoreFun1D.m:175
function fx = evaluateMulti(colvec< double > x, unused1,colvec< double > mu)
Allocate result vector.
Definition: CoreFun1D.m:134
function copy = clone()
Definition: CoreFun1D.m:64