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
InhibitCoreFun2D.m
Go to the documentation of this file.
1 namespace models{
2 namespace pcdi{
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 
20  :public models.pcdi.BaseCoreFun {
44  public:
45 
46 
47  InhibitCoreFun2D(dynsys) {
48  this = this@models.pcdi.BaseCoreFun(dynsys);
49  }
50 
51 
52  function copy = clone() {
53  copy = models.pcdi.InhibitCoreFun2D(this.System);
54 
55  /* Call superclass method */
56  copy = clone@models.pcdi.BaseCoreFun(this, copy);
57  }
65  function newSysDimension() {
66  s = this.System;
67  n = prod(s.Dims);
68  this.nodes= n;
69  this.hlp.d1= s.Dims(1);
70  this.hlp.d2= s.Dims(2);
71 
72  this.idxmat= zeros(s.Dims(1),s.Dims(2));
73  this.idxmat(:) = 1:this.nodes;
74 
75  /* Can use the unscaled h and original Omega for computation of
76  * ranges & distances from middle */
77  this.hlp.hs= s.hs;
78  a = s.Omega;
79  this.hlp.xr= a(1,2)-a(1,1); /* xrange */
80 
81  this.hlp.yr= a(2,2)-a(2,1); /* yrange */
82 
83  this.hlp.xd= abs(((1:this.hlp.d1)-1)*this.System.h-.5*this.hlp.xr)^t; /* x distances from middle */
84 
85  this.hlp.yd= abs(((1:this.hlp.d2)-1)*this.System.h-.5*this.hlp.yr)^t; /* y distances from middle */
86 
87 
88  /* Build sparsity pattern */
89  n = this.nodes;
90 
91  /* % 1=x_a, 2=y_a, 3=x_i, 4=y_i, 5=iap, 6=bar, 7=yb, 8=xb
92  * Add x_a dependencies
93  * rc(2)*xi.*ya - rc(5)*xa -rc(11)*xa.*bar + rc(18)*xb */
94  i = repmat(this.nodepos(1),1,5);
95  j = this.nodepos([1:3 6 8]);
96  /* Add y_a dependencies
97  * rc(1)*yi.*xa - rc(6)*ya - rc(3)*ya.*iap + rc(14)*yb; */
98  i = [i repmat(this.nodepos(2),1,5)];
99  j = [j this.nodepos([1:2 4 5 7])];
100  /* Add x_i dependencies
101  * -rc(2)*xi.*ya - rc(9)*xi + rc(16) - rb/this.hlp.hs; */
102  i = [i repmat(this.nodepos(3),1,2)];
103  j = [j this.nodepos([2 3])];
104  /* Add y_i dependencies
105  * -rc(1)*yi.*xa - rc(10)*yi + rc(17); */
106  i = [i repmat(this.nodepos(4),1,2)];
107  j = [j this.nodepos([1 4])];
108 
109  /* % 1=x_a, 2=y_a, 3=x_i, 4=y_i, 5=iap, 6=bar, 7=yb, 8=xb
110  * Add iap dependencies
111  * -(rc(3)+rc(4))*ya.*iap - rc(8)*iap + rc(15) + rc(14)*yab; */
112  i = [i repmat(this.nodepos(5),1,3)];
113  j = [j this.nodepos([2 5 7])];
114  /* Add bar dependencies
115  * -rc(11)*xa.*bar + rc(18)*xab - rc(19)*bar + rc(19); */
116  i = [i repmat(this.nodepos(6),1,3)];
117  j = [j this.nodepos([1 6 8])];
118  /* Add bar dependencies
119  * rc(3)*ya.*iap -(rc(14)+rc(7))*yab; */
120  i = [i repmat(this.nodepos(7),1,3)];
121  j = [j this.nodepos([2 5 7])];
122  /* Add bar dependencies
123  * rc(11)*xa.*bar-(rc(18)+rc(13))*xab; */
124  i = [i repmat(this.nodepos(8),1,3)];
125  j = [j this.nodepos([1 6 8])];
126  this.Ji= i;
127  this.Jj= j;
128  this.xDim= 8*n;
129  this.fDim= 8*n;
130  this.JSparsityPattern= sparse(i,j,ones(length(i),1),this.fDim,this.xDim);
131  }
138  function fx = evaluate(colvec<double> x,double t) {
139  if ~isempty(this.V)
140  x = this.V*x;
141  end
142 
143  /* Allocate result vector */
144  fx = zeros(size(x));
145 
146  m = this.nodes;
147  mu = this.mu;
148  diff = this.System.CurCXMU;
149 
150  /* Compute activation fun values (it's set up in scaled times!) */
151  ud = this.activationFun(t,mu);
152  rc = this.System.ReacCoeff;
153 
154  /* Extract single functions */
155  xa = x(1:m);
156  xan = xa.^mu(4);
157  ya = x(m+1:2*m);
158  xi = x(2*m+1:3*m);
159  yi = x(3*m+1:4*m);
160  iap = x(4*m+1:5*m);
161  bar = x(5*m+1:6*m);
162  yb = x(6*m+1:7*m);
163  xb = x(7*m+1:end);
164 
165  rb = zeros(m,1);
166 
167  /* % Top & Bottom
168  * bottom */
169  pos = this.hlp.xd <= this.hlp.xr*mu(1)/2;
170  idx = this.idxmat(pos,1);
171  rb(idx) = (xi(idx)*mu(2)*ud);
172  /* top */
173  pos = this.hlp.xd <= this.hlp.xr*mu(1)/2;
174  idx = this.idxmat(pos,end);
175  rb(idx) = rb(idx) + (xi(idx)*mu(2)*ud);
176 
177  /* % Left & Right
178  * right */
179  pos = this.hlp.yd <= this.hlp.yr*mu(1)/2;
180  idx = this.idxmat(end,pos);
181  rb(idx) = rb(idx) + (xi(idx)*mu(2)*ud);
182  /* left */
183  pos = this.hlp.yd <= this.hlp.yr*mu(1)/2;
184  idx = this.idxmat(1,pos);
185  rb(idx) = rb(idx) + (xi(idx)*mu(2)*ud);
186 
187  /* Indices:
188  * km3 = 14, km8 = 15, km12 = 19 */
189 
190  /* x_a */
191  fx(1:m) = rc(2)*xi.*ya - rc(5)*xa -rc(11)*xa.*bar + rc(18)*xb + rb/this.hlp.hs;
192  /* y_a */
193  fx(m+1:2*m) = rc(1)*yi.*xan - rc(6)*ya - rc(3)*ya.*iap + rc(14)*yb;
194  /* x_i */
195  fx(2*m+1:3*m) = -rc(2)*xi.*ya - rc(9)*xi + rc(16)*diff - rb/this.hlp.hs;
196  /* y_i */
197  fx(3*m+1:4*m) = -rc(1)*yi.*xan - rc(10)*yi + rc(17)*diff;
198  /* iap */
199  fx(4*m+1:5*m) = -(rc(3)+rc(4))*ya.*iap - rc(8)*iap + rc(15)*diff + rc(14)*yb;
200  /* bar */
201  fx(5*m+1:6*m) = -rc(11)*xa.*bar + rc(18)*xb - rc(19)*bar + rc(19)*diff;
202  /* yab */
203  fx(6*m+1:7*m) = rc(3)*ya.*iap -(rc(14)+rc(7))*yb;
204  /* xab */
205  fx(7*m+1:8*m) = rc(11)*xa.*bar-(rc(18)+rc(13))*xb;
206 
207  /* If this has been projected, project back to reduced space */
208  if ~isempty(this.W)
209  fx = this.W^t*fx;
210  end
211  }
222  function fx = evaluateMulti(colvec<double> x,double t,colvec<double> mu) {
223  error(" not usable due to spatially dependent production rates. ");
224 
225  /* Allocate result vector */
226  fx = zeros(size(x));
227 
228  m = this.nodes;
229 
230  /* Compute activation fun values (it's set up in scaled times!) */
231  ud = this.activationFun(t,mu);
232  rc = this.System.ReacCoeff;
233 
234  /* Extract single functions */
235  xa = x(1:m,:);
236  xan = bsxfun(@power,xa,mu(4,:));
237  ya = x(m+1:2*m,:);
238  xi = x(2*m+1:3*m,:);
239  yi = x(3*m+1:4*m,:);
240  iap = x(4*m+1:5*m,:);
241  bar = x(5*m+1:6*m,:);
242  yb = x(6*m+1:7*m,:);
243  xb = x(7*m+1:end,:);
244 
245  /* Compile boundary conditions */
246  nd = size(x,2);
247  rb = zeros(m,nd);
248 
249  /* % Top & Bottom */
250  xd = repmat(this.hlp.xd,1,nd); /* y distances
251  * bottom */
252 
253  pos = bsxfun(@lt,xd,this.hlp.xr*mu(1,:)/2);
254  idx = this.idxmat(:,1);
255  rb(idx,:) = pos .* (bsxfun(@times,xi(idx,:),mu(2,:).*ud));
256  /* top */
257  pos = bsxfun(@lt,xd,this.hlp.xr*mu(1,:)/2);
258  idx = this.idxmat(:,end);
259  rb(idx,:) = rb(idx,:) + pos .* (bsxfun(@times,xi(idx,:),mu(2,:).*ud));
260 
261  /* % Left & Right */
262  yd = repmat(this.hlp.yd,1,nd);
263  /* right */
264  pos = bsxfun(@lt,yd,this.hlp.yr*mu(1,:)/2);
265  idx = this.idxmat(end,:);
266  rb(idx,:) = rb(idx,:) + pos .* (bsxfun(@times,xi(idx,:),mu(2,:).*ud));
267  /* left */
268  pos = bsxfun(@lt,yd,this.hlp.yr*mu(1,:)/2);
269  idx = this.idxmat(1,:);
270  rb(idx,:) = rb(idx,:) + pos .* (bsxfun(@times,xi(idx,:),mu(2,:).*ud));
271 
272  /* x_a */
273  fx(1:m,:) = rc(2)*xi.*ya - rc(5)*xa -rc(11)*xa.*bar + rc(18)*xb + rb/this.hlp.hs;
274  /* y_a */
275  fx(m+1:2*m,:) = rc(1)*yi.*xan - rc(6)*ya - rc(3)*ya.*iap + rc(14)*yb;
276  /* x_i */
277  fx(2*m+1:3*m,:) = -rc(2)*xi.*ya - rc(9)*xi + rc(16) - rb/this.hlp.hs;
278  /* y_i */
279  fx(3*m+1:4*m,:) = -rc(1)*yi.*xan - rc(10)*yi + rc(17);
280  /* iap */
281  fx(4*m+1:5*m,:) = -(rc(3)+rc(4))*ya.*iap - rc(8)*iap + rc(15) + rc(14)*yb;
282  /* bar */
283  fx(5*m+1:6*m,:) = -rc(11)*xa.*bar + rc(18)*xb - rc(19)*bar + rc(19);
284  /* yab */
285  fx(6*m+1:7*m,:) = rc(3)*ya.*iap -(rc(14)+rc(7))*yb;
286  /* xab */
287  fx(7*m+1:8*m,:) = rc(11)*xa.*bar-(rc(18)+rc(13))*xb;
288  }
289 
290 
291  function J = getStateJacobian(colvec<double> x,double t) {
292 
293  /* If this has been projected, restore full size and compute values. */
294  if ~isempty(this.V)
295  x = this.V*x;
296  end
297 
298  n = this.nodes;
299  mu = this.mu;
300  rc = this.System.ReacCoeff;
301 
302  /* Boundary stuff */
303  bottom = this.idxmat(this.hlp.xd <= this.hlp.xr*mu(1)/2,1);
304  top = this.idxmat(this.hlp.xd <= this.hlp.xr*mu(1)/2,end);
305  right = this.idxmat(end,this.hlp.yd <= this.hlp.yr*mu(1)/2);
306  left = this.idxmat(1,this.hlp.yd <= this.hlp.yr*mu(1)/2);
307  rbxi = zeros(n,1);
308  u = this.activationFun(t,mu);
309  rbxi(bottom) = mu(2)*u;
310  rbxi(top) = mu(2)*u;
311  rbxi(right) = mu(2)*u;
312  rbxi(left) = mu(2)*u;
313  rbxi = rbxi/this.hlp.hs;
314 
315  /* yb, xb values not needed in jacobian! */
316  hlp = reshape(1:6*n" ,[],6) ";
317  o = ones(n,1);
318  xa = x(hlp(1,:)); ya = x(hlp(2,:));
319  xi = x(hlp(3,:)); yi = x(hlp(4,:));
320  iap = x(hlp(5,:)); bar = x(hlp(6,:));
321 
322  /* % 1=x_a, 2=y_a, 3=x_i, 4=y_i, 5=iap, 6=bar, 7=yb, 8=xb
323  * dxa = rc(2)*xi.*ya - rc(5)*xa -rc(11)*xa.*bar + rc(18)*xb */
324  s = [-o*rc(5)-rc(11)*bar; ... /* dx_a/x_a */
325 
326  rc(2)*xi;... /* dxa/ya */
327 
328  rc(2)*ya + rbxi; /* dxa/xi */
329 
330  -rc(11)*xa; /* dxa/bar */
331 
332  o*rc(18)]; /* dxa/xb
333  * dya = rc(1)*yi.*xan - rc(6)*ya - rc(3)*ya.*iap + rc(14)*yb; */
334 
335  nyixan_1 = mu(4)*rc(1)*yi.*xa.^(mu(4)-1);
336  k1xan = rc(1)*xa.^mu(4);
337  s = [s; nyixan_1; ... /* dya/xa */
338 
339  -o*rc(6) - rc(3)*iap;... /* dy_a/y_a */
340 
341  k1xan;... /* dy_a/y_i */
342 
343  -rc(3)*xa;... /* dya/ */
344 
345  o*rc(14)];
346  /* % 1=x_a, 2=y_a, 3=x_i, 4=y_i, 5=iap, 6=bar, 7=yb, 8=xb
347  * Add x_i dependencies
348  * dxi = -rc(2)*xi.*ya - rc(9)*xi + rc(16) - rb/this.hlp.hs; */
349  s = [s; -rc(2)*xi;... /* dxi/ya */
350 
351  -rc(2)*xa-rc(9)-rbxi]; /* dxi/xi
352  * -rc(1)*yi.*xan - rc(10)*yi + rc(17); */
353 
354  s = [s; -nyixan_1; ... /* dyi/xa */
355 
356  -k1xan-o*rc(10)]; /* dyi/yi */
357 
358 
359  /* % 1=x_a, 2=y_a, 3=x_i, 4=y_i, 5=iap, 6=bar, 7=yb, 8=xb
360  * Add iap dependencies
361  * diap = -(rc(3)+rc(4))*ya.*iap - rc(8)*iap + rc(15) + rc(14)*yb; */
362  s = [s; -(rc(3)+rc(4))*iap; ... /* diap/ya */
363 
364  -(rc(3)+rc(4))*ya-rc(8); /* diap/iap */
365 
366  o*rc(14)]; /* diap/yb
367  * dbar = -rc(11)*xa.*bar + rc(18)*xb - rc(19)*bar + rc(19); */
368 
369  s = [s; -rc(11)*bar; ... /* dbar/xa */
370 
371  -rc(11)*xa-rc(8); /* dbar/bar */
372 
373  o*rc(18)]; /* diap/xb
374  *% 1=x_a, 2=y_a, 3=x_i, 4=y_i, 5=iap, 6=bar, 7=yb, 8=xb
375  * dyb = rc(3)*ya.*iap -(rc(14)+rc(7))*yb; */
376 
377  s = [s; rc(3)*iap; ... /* dyb/ya */
378 
379  rc(3)*ya; /* dyb/iap */
380 
381  -o*(rc(14)+rc(7))]; /* dyb/yb
382  * dxb = rc(11)*xa.*bar-(rc(18)+rc(13))*xb; */
383 
384  s = [s; rc(11)*bar; ... /* dxb/xa */
385 
386  rc(11)*xa; /* dxb/bar */
387 
388  -o*(rc(18)+rc(13))]; /* dxp/xb */
389 
390 
391  n = this.fDim;
392  if ~isempty(this.V)
393  n = size(this.V,1);
394  end
395  m = this.xDim;
396  if ~isempty(this.W)
397  n = size(this.W,1);
398  end
399  J = sparse(this.Ji,this.Jj,s,n,m);
400  }
401 
402 
403  protected:
404 
405  function fxj = evaluateComponents(pts,ends,globidx,unused1,X,double t) {
406  fxj = this.evaluateComponentsMulti(pts, ends, globidx, [], X, t, this.mu);
407  }
408 
409 
410  function fxj = evaluateComponentsMulti(rowvec<integer> pts,rowvec<integer> ends,globidx,unused1,matrix<double> X,double t,matrix<double> mu) {
411  m = this.nodes;
412  nd = size(X,2);
413  fxj = zeros(length(pts),nd);
414  rc = this.System.ReacCoeff;
415  diff = this.System.CurCXMU;
416  if nd > 1
417  bottom = bsxfun(@lt,this.hlp.xd,this.hlp.xr*mu(1,:)/2);
418  top = bsxfun(@lt,this.hlp.xd,this.hlp.xr*mu(1,:)/2);
419  right = bsxfun(@lt,this.hlp.yd,this.hlp.yr*mu(1,:)/2);
420  left = bsxfun(@lt,this.hlp.yd,this.hlp.yr*mu(1,:)/2);
421  else
422  bottom = this.hlp.xd <= this.hlp.xr*mu(1,:)/2;
423  top = this.hlp.xd <= this.hlp.xr*mu(1,:)/2;
424  right = this.hlp.yd <= this.hlp.yr*mu(1,:)/2;
425  left = this.hlp.yd <= this.hlp.yr*mu(1,:)/2;
426  end
427  /* Get matrix indices */
428  J2 = mod(pts,m);
429  J2(J2==0) = m;
430 
431  /* [row2, col2] = ind2sub([this.hlp.d1 this.hlp.d2],J2);
432  * ind2sub direct replacement! */
433  row = rem(J2-1, this.hlp.d1)+1;
434  col = (J2-row)/this.hlp.d1+1;
435  u = this.activationFun(t, mu);
436  for idx=1:length(pts)
437  j = pts(idx);
438  if idx == 1
439  st = 0;
440  else
441  st = ends(idx-1);
442  end
443  /* Select the elements of x that are effectively used in f */
444  xidx = (st+1):ends(idx);
445  x = X(xidx,:);
446 
447  /* % X_a
448  * General: 1=x_a, 2=y_a, 3=x_i, 4=y_i, 5=iap, 6=bar, 7=yb, 8=xb
449  * Sel: 1=xa, 2=ya, 3=xi, 4=bar, 5=xb
450  * rc(2)*xi.*ya - rc(5)*xa -rc(11)*xa.*bar + rc(18)*xb + rb/this.hlp.hs; */
451  if j <= m
452  fj = rc(2)*x(3,:).*x(2,:) - rc(5)*x(1,:) -rc(11)*x(1,:).*x(4,:) + rc(18)*x(5,:);
453 
454  /* Boundary conditions
455  * Bottom */
456  if col(idx) == 1
457  fj = fj + bottom(row(idx),:) .* (x(3,:).*mu(2,:).*u/this.hlp.hs);
458  end
459  /* Top */
460  if col(idx) == this.hlp.d2
461  fj = fj + top(row(idx),:) .* (x(3,:).*mu(2,:).*u/this.hlp.hs);
462  end
463  /* Right */
464  if row(idx) == this.hlp.d1
465  fj = fj + right(col(idx),:) .* (x(3,:).*mu(2,:).*u/this.hlp.hs);
466  end
467  /* Left */
468  if row(idx) == 1
469  fj = fj + left(col(idx),:) .* (x(3,:).*mu(2,:).*u/this.hlp.hs);
470  end
471 
472  /* % Y_a
473  * General: 1=x_a, 2=y_a, 3=x_i, 4=y_i, 5=iap, 6=bar, 7=yb, 8=xb
474  * Sel: 1=x_a, 2=y_a, 3=y_i, 4=iap, 5=yb
475  * rc(1)*yi.*xan - rc(6)*ya - rc(3)*ya.*iap + rc(14)*yb; */
476  elseif m < j && j <= 2*m
477  fj = rc(1)*x(3,:).*x(1,:).^mu(4,:) - rc(6)*x(2,:) - rc(3)*x(2,:).*x(4,:) + rc(14)*x(5,:);
478 
479  /* % X_i
480  * General: 1=x_a, 2=y_a, 3=x_i, 4=y_i, 5=iap, 6=bar, 7=yb, 8=xb
481  * Sel: % 1=ya, 2=xi
482  * -rc(2)*xi.*ya - rc(9)*xi + rc(16) - rb/this.hlp.hs; */
483  elseif 2*m < j && j <= 3*m
484  fj = -rc(2)*x(2,:).*x(1,:) - rc(9)*x(2,:) + rc(16);
485 
486  /* Boundary conditions
487  * Bottom */
488  if col(idx) == 1
489  fj = fj - bottom(row(idx),:) .* (x(2,:).*mu(2,:).*u/this.hlp.hs);
490  end
491  /* Top */
492  if col(idx) == this.hlp.d2
493  fj = fj - top(row(idx),:) .* (x(2,:).*mu(2,:).*u/this.hlp.hs);
494  end
495  /* Right */
496  if row(idx) == this.hlp.d1
497  fj = fj - right(col(idx),:) .* (x(2,:).*mu(2,:).*u/this.hlp.hs);
498  end
499  /* Left */
500  if row(idx) == 1
501  fj = fj - left(col(idx),:) .* (x(2,:).*mu(2,:).*u/this.hlp.hs);
502  end
503 
504  /* % Y_i
505  * General: 1=x_a, 2=y_a, 3=x_i, 4=y_i, 5=iap, 6=bar, 7=yb, 8=xb
506  * Sel: 1=x_a, 2=y_i
507  * -rc(1)*yi.*xan - rc(10)*yi + rc(17); */
508  elseif 3*m < j && j <= 4*m
509  fj = -rc(1)*x(2,:).*x(1,:).^mu(4,:) - rc(10)*x(2,:) + rc(17);
510 
511  /* % IAP
512  * General: 1=x_a, 2=y_a, 3=x_i, 4=y_i, 5=iap, 6=bar, 7=yb, 8=xb
513  * Sel: 1=ya, 2=iap, 3=yb
514  * -(rc(3)+rc(4))*ya.*iap - rc(8)*iap + rc(15) + rc(14)*yb; */
515  elseif 4*m < j && j <= 5*m
516  fj = -(rc(3)+rc(4))*x(1,:).*x(2,:) - rc(8)*x(2,:) + rc(15) + rc(14)*x(3,:);
517 
518  /* % BAR
519  * General: 1=x_a, 2=y_a, 3=x_i, 4=y_i, 5=iap, 6=bar, 7=yb, 8=xb
520  * Sel: 1=xa, 2=bar, 3=xb
521  * -rc(11)*xa.*bar + rc(18)*xb - rc(19)*bar + rc(19); */
522  elseif 5*m < j && j <= 6*m
523  fj = -rc(11)*x(1,:).*x(2,:) + rc(18)*x(3,:) - rc(19)*x(2,:) + rc(19);
524 
525  /* % YB
526  * General: 1=x_a, 2=y_a, 3=x_i, 4=y_i, 5=iap, 6=bar, 7=yb, 8=xb
527  * Sel: 1=ya, 2=iap, 3=yb
528  * rc(3)*ya.*iap -(rc(14)+rc(7))*yb; */
529  elseif 6*m < j && j <= 7*m
530  fj = rc(3)*x(1,:).*x(2,:) -(rc(14)+rc(7))*x(3,:);
531 
532  /* % XB
533  * General: 1=x_a, 2=y_a, 3=x_i, 4=y_i, 5=iap, 6=bar, 7=yb, 8=xb
534  * Sel: 1=xa, 2=bar, 3=xb
535  * rc(11)*xa.*bar-(rc(18)+rc(13))*xb; */
536  else
537  fj = rc(11)*x(1,:).*x(2,:)-(rc(18)+rc(13))*x(3,:);
538  end
539  fxj(idx,:) = fj;
540  end
541  }
564  error(" Activation fun not yet implemented correctly ");
565  m = this.nodes;
566  rc = this.System.ReacCoeff;
567  nd = size(X,2);
568 
569  /* % Boundary stuff
570  * Get matrix indices of points */
571  pts2 = mod(pts,m);
572  pts2(pts2==0) = m;
573  row = rem(pts2-1, this.hlp.d1)+1;
574  col = (pts2-row)/this.hlp.d1+1;
575  if nd > 1
576  bottom = bsxfun(@lt,this.hlp.xd,this.hlp.xr*mu(1)/2);
577  top = bsxfun(@lt,this.hlp.xd,this.hlp.xr*mu(1)/2);
578  right = bsxfun(@lt,this.hlp.yd,this.hlp.yr*mu(1)/2);
579  left = bsxfun(@lt,this.hlp.yd,this.hlp.yr*mu(1)/2);
580  else
581  bottom = this.hlp.xd <= this.hlp.xr*mu(1)/2;
582  top = this.hlp.xd <= this.hlp.xr*mu(1)/2;
583  right = this.hlp.yd <= this.hlp.yr*mu(1)/2;
584  left = this.hlp.yd <= this.hlp.yr*mu(1)/2;
585  end
586 
587  /* % Derivative info per point */
588  der = false(size(X,1),1);
589  der(deriv) = true;
590 
591  /* % Main loop */
592  dfx = zeros(size(deriv,1),nd);
593  curpos = 1;
594  for idx=1:length(pts)
595  i = pts(idx);
596  if idx == 1
597  st = 0;
598  else
599  st = ends(idx-1);
600  end
601  /* Select the elements of x that are effectively used in f */
602  elem = (st+1):ends(idx);
603  x = X(elem,:);
604  d = der(elem);
605 
606  /* X_a */
607  if i <= m
608  /* 1=x_a, 2=y_a, 3=x_i {, y_i} */
609  if d(1) /* dx_a/x_a = -mu3 */
610 
611  dfx(curpos,:) = -rc(3);
612  curpos = curpos + 1;
613  end
614  if d(2) /* dx_a/y_a = mu1*x_i */
615 
616  dfx(curpos,:) = rc(1)*x(3,:);
617  curpos = curpos + 1;
618  end
619  if d(3) /* dx_a/x_i = mu1*y_a + rb' */
620 
621  dfx(curpos,:) = rc(1)*x(2,:);
622  if col(idx) == 1 /* Bottom */
623 
624  dfx(curpos,:) = dfx(curpos,:) + bottom(row(idx),:) .* mu(2,:)/this.hlp.hs;
625  end
626  if col(idx) == this.hlp.d2 /* Top */
627 
628  dfx(curpos,:) = dfx(curpos,:) + top(row(idx),:) .* mu(2,:)/this.hlp.hs;
629  end
630  if row(idx) == this.hlp.d1 /* Right */
631 
632  dfx(curpos,:) = dfx(curpos,:) + right(col(idx),:) .* mu(2,:)/this.hlp.hs;
633  end
634  if row(idx) == 1 /* Left */
635 
636  dfx(curpos,:) = dfx(curpos,:) + left(col(idx),:) .* mu(2,:)/this.hlp.hs;
637  end
638  curpos = curpos + 1;
639  end
640 
641  /* Y_a */
642  elseif m < i && i <= 2*m
643  /* 1=x_a, 2=y_a {, x_i}, 3=y_i */
644  if d(1) /* dy_a/x_a = n*mu2*y_i*x_a^(n-1) */
645 
646  dfx(curpos,:) = mu(4,:)*rc(2)*x(3,:).*x(1,:).^(mu(4,:)-1);
647  curpos = curpos + 1;
648  end
649  if d(2) /* dy_a/y_a = -mu4 */
650 
651  dfx(curpos,:) = -rc(4);
652  curpos = curpos + 1;
653  end
654  if d(3) /* dx_a/x_a = -mu3 */
655 
656  dfx(curpos,:) = rc(2)*x(1,:).^mu(4,:);
657  curpos = curpos + 1;
658  end
659 
660  /* X_i */
661  elseif 2*m < i && i <= 3*m
662  /* {x_a,} 1=y_a, 2=x_i {, y_i} */
663  if d(1) /* dx_i/y_a = -mu1*x_i */
664 
665  dfx(curpos,:) = -rc(1)*x(2,:);
666  curpos = curpos + 1;
667  end
668  if d(2) /* dx_i/x_i = -mu1*y_a -mu5 -rbxi */
669 
670  dfx(curpos,:) = -rc(1)*x(1,:)-rc(5);
671  /* Boundary conditions */
672  if col(idx) == 1 /* Bottom */
673 
674  dfx(curpos,:) = dfx(curpos,:) - bottom(row(idx),:) .* mu(2,:)/this.hlp.hs;
675  end
676  if col(idx) == this.hlp.d2 /* Top */
677 
678  dfx(curpos,:) = dfx(curpos,:) - top(row(idx),:) .* mu(2,:)/this.hlp.hs;
679  end
680  if row(idx) == this.hlp.d1 /* Right */
681 
682  dfx(curpos,:) = dfx(curpos,:) - right(col(idx),:) .* mu(2,:)/this.hlp.hs;
683  end
684  if row(idx) == 1 /* Left */
685 
686  dfx(curpos,:) = dfx(curpos,:) - left(col(idx),:) .* mu(2,:)/this.hlp.hs;
687  end
688  curpos = curpos + 1;
689  end
690 
691  /* Y_i */
692  else
693  /* 1=x_a, {y_a, x_i}, 2=y_i */
694  if d(1) /* dy_i/x_a = -n*mu2*y_i*x_a^(n-1) */
695 
696  dfx(curpos,:) = -mu(4,:)*rc(2)*x(2,:).*x(1,:).^(mu(4,:)-1);
697  curpos = curpos + 1;
698  end
699  if d(2) /* dy_i/y_i = -mu2 * x_a^n-mu6 */
700 
701  dfx(curpos,:) = -rc(2)*x(1,:).^mu(4,:) - rc(6);
702  curpos = curpos + 1;
703  end
704  end
705  end
706  }
730 };
731 }
732 }
733 
734 
735 
integer fDim
The current output dimension of the function.
Definition: ACoreFun.m:171
function copy = clone()
System already copied in constructor (see below)
function idx = nodepos(nr)
Definition: BaseCoreFun.m:212
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
function dfx = evaluateComponentPartialDerivatives(rowvec< integer > pts,rowvec< integer > ends, unused1,rowvec< integer > deriv, unused2,colvec< double > X, unused3,colvec< double > mu, unused4)
See dscomponents.ACompEvalCoreFun for more details.
function J = getStateJacobian(colvec< double > x,double t)
models.BaseFirstOrderSystem System
The system associated with the current ACoreFun.
Definition: ACoreFun.m:193
function fx = evaluate(colvec< double > x,double t)
If this has been projected, restore full size and compute values.
function f = activationFun(double t,colvec< double > mu)
Definition: BaseCoreFun.m:221
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
#define X(i, j)
The core nonlinear function of the PCD model.
sparse< logical > JSparsityPattern
Sparsity pattern for the jacobian matrix.
Definition: ACoreFun.m:127
function fxj = evaluateComponents(pts, ends, globidx, unused1, X,double t)
W
The matrix of the biorthogonal pair .
Definition: AProjectable.m:72
function fx = evaluateMulti(colvec< double > x,double t,colvec< double > mu)
function fxj = evaluateComponentsMulti(rowvec< integer > pts,rowvec< integer > ends, globidx, unused1,matrix< double > X,double t,matrix< double > mu)
The vector embedding results from the fixed ordering of the full 4*m-vector into the components x_a...
function newSysDimension()
Create diffusion matrix.