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
PCDSystem2D.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 
20  :public models.pcd.BasePCDSystem {
32  public:
33 
34  logical Plot2D = false;
45  public:
46 
48  this = this@models.pcd.BasePCDSystem(model);
49 
50  /* Set core function */
51  this.f= models.pcd.CoreFun2D(this);
52 
53  /* Spatial area (unscaled!) */
54  this.Omega= [0 1.5; 0 1] * this.Model.L;
55 
56  /* Scaled! */
57  this.h= .5 * this.Model.L;
58  }
59 
60 
61  function varargout = plot(models.BaseFullModel model,double t,matrix<double> y,varargin) {
62  if ~isempty(varargin) && isa(varargin[1]," PlotManager ")
63  pm = varargin[1];
64  else
65  pm = PlotManager;
66  if nargout == 0
67  pm.LeaveOpen= true;
68  else
69  varargout[1] = pm;
70  end
71  end
72  h = pm.nextPlot([model.SaveTag " _outputplot "],...
73  sprintf(" Output plot for model %s ",model.Name)," Time "," Caspase-3 Concentration ");
74  /* plot(h,t,y,'r','LineWidth',2); */
75  semilogy(h,t,y," r "," LineWidth ",2);
76  if isempty(varargin)
77  pm.done;
78  end
79  }
80 
81 
82  function varargout = plotState(models.BaseFullModel model,double t,matrix<double> y,varargin) {
83  if ~isempty(varargin) && isa(varargin[1]," PlotManager ")
84  pm = varargin[1];
85  else
86  pm = PlotManager(false,2,2);
87  if nargout == 0
88  pm.LeaveOpen= true;
89  else
90  varargout[1] = pm;
91  end
92  end
93  if this.Plot2D
94  this.plot2DState(model, t, y, pm);
95  else
96  this.plot1DState(model, t, y, pm);
97  end
98  if isempty(varargin)
99  pm.done;
100  end
101  }
102 
103 
104  protected:
105 
106  function newSysDimension() {
107  m = prod(this.Dims);
108  x0 = zeros(4*m,1);
109  x0(1:2*m) = 1e-16; /* use 5e-13 for pcd 2d exps */
110 
111  x0(2*m+1:end) = 1e-9; /* use 3e-8 for pcd 2d exps */
112 
113  this.x0= dscomponents.ConstInitialValue(x0);
114 
115  /* Diffusion part */
116  A = MatUtils.laplacemat(this.hs, this.Dims(1), this.Dims(2));
117  A = blkdiag(A,this.Diff(1)*A,this.Diff(2)*A,this.Diff(3)*A);
118  this.A= dscomponents.LinearCoreFun(A);
119 
120  /* Output extraction */
121  p = .1; /* 10% of each dimensions span, centered in geometry. */
122 
123  d = this.Dims(1);
124  d1idx = find(abs((1:d) - d/2) <= d/2 * p);
125  if isempty(d1idx)
126  d1idx = 1;
127  end
128  d = this.Dims(2);
129  d2idx = find(abs((1:d) - d/2) <= d/2 * p);
130  if isempty(d2idx)
131  d2idx = 1;
132  end
133  [d1,d2] = meshgrid(d1idx,d2idx);
134  sel = reshape(sub2ind(this.Dims,d1,d2),1,[]);
135  C = sparse(1,4*m);
136  ca3 = m+1:2*m;
137  C(ca3(sel)) = 1/length(sel);
138  this.C= dscomponents.LinearOutputConv(C);
139  }
140 
141 
142  private:
143 
144  function plot1DState(models.BaseFullModel model,double t,matrix<double> y,pm) {
145  m = prod(this.Dims);
146 
147  /* Select cell center values */
148  idxmat = zeros(this.Dims);
149  idxmat(:) = 1:m;
150  sel = idxmat(:,round(this.Dims(2)/2));
151  sel = [sel; sel+m; sel+2*m; sel+3*m];
152  m = length(sel)/4;
153  y = y(sel,:);
154 
155  if length(t) > 150
156  idx = round(linspace(1,length(t),150));
157  t = t(idx);
158  y = y(:,idx);
159  end
160  states = [" alive "," unstable "," dead "];
161 
162  X = t;
163  Y = (this.Omega(1,1):this.h:this.Omega(1,2))/model.L;
164  doplot(y(1:m,:)," c8 "," Caspase-8 (x_a) ",1);
165  doplot(y(m+1:2*m,:)," c3 "," Caspase-3 (y_a) ",2);
166  doplot(y(2*m+1:3*m,:)," pc8 "," Pro-Caspase-8 (x_i) ",3);
167  doplot(y(3*m+1:end,:)," pc3 "," Pro-Caspase-3 (y_i) ",4);
168 
169  function doplot(y, tag, thetitle, pnr)
170  di = abs(this.Model.SteadyStates(:,pnr)-y(end));
171  reldi = di ./ (this.Model.SteadyStates(:,pnr)+eps);
172  reldistr = Utils.implode(reldi," , "," %2.3e ");
173  if any(reldi > .1) || any(reldi < 10)
174  [~, id] = min(di);
175  tit = sprintf(" Model '%s', %s concentrations\nCell state at T=%d: %s\n%s ", model.Name, thetitle,...
176  max(t),states[id],reldistr);
177  else
178  tit = sprintf(" Model '%s', %s concentrations\n%s ", model.Name, thetitle,reldistr);
179  end
180  h = pm.nextPlot(tag,tit," Time [s] "," Cell slice ");
181  surf(h,X,Y,y," EdgeColor "," none ");
182  zlabel(h,thetitle);
183  end
184  }
185 
186 
187  function plot2DState(models::BaseFullModel model,rowvec t,matrix v,pm) {
188 
189  autocols = true;
190 
191  m = prod(this.Dims);
192  xa = v(1:m,:);
193  ya = v(m+1:2*m,:);
194  xi = v(2*m+1:3*m,:);
195  yi = v(3*m+1:end,:);
196  b = [min(xa(:)) max(xa(:)); min(ya(:)) max(ya(:));...
197  min(xi(:)) max(xi(:)); min(yi(:)) max(yi(:))];
198  /* % Prepare figures */
199  rotate3d on;
200  hlpf = figure(" Visible "," off "," MenuBar "," none "," ToolBar "," none ");
201  hlpax = newplot(hlpf);
202  axis tight;
203  ax = [];
204  caps = [" Caspase-8 "," Caspase-3 "," Pro-Caspase-8 "," Pro-Caspase-3 "];
205  for p = 1:4
206  h = pm.nextPlot(sprintf(" PCD2D_plot1D_%d ",p),...
207  sprintf(" Model '%s', %s concentrations ", model.Name, caps[p]),...
208  " Left to right "," Bottom to Top ");
209  axis(h,[reshape(this.Omega^t,1,[]) b(p,:)]);
210  ar = get(gca," DataAspectRatio ");
211  set(h," DataAspectRatio ",[ar(1)/2 ar(2:3)]);
212  /* axis(a fill; */
213  set(h," Box "," on "," GridLineStyle "," none ");
214  if ~autocols
215  set(h," CLimMode "," manual "," CLim ",b(p,:));
216  end
217  view(h,-22,31);
218  zlabel(h,sprintf(" %s concentration ",caps[p]));
219  colorbar(" peer ",h);
220  ax(end+1) = h;/* #ok */
221 
222  end
223 
224  /* % Plot timesteps */
225  a = this.Omega;
226  x = a(1,1):this.h:a(1,2);
227  y = a(2,1):this.h:a(2,2);
228  [X,Y] = meshgrid(x,y);
229 
230  step = round(length(t)/40);
231  for idx=1:step:length(t)
232  h1 = doplot(xa(:,idx),ax(1));
233  h2 = doplot(ya(:,idx),ax(2));
234  h3 = doplot(xi(:,idx),ax(3));
235  h4 = doplot(yi(:,idx),ax(4));
236  set(gcf," Name ",sprintf(" Plot at t=%f ",t(idx)));
237  if idx ~= length(t)
238  pause;
239  delete([h1; h2; h3; h4]);
240  end
241  end
242 
243  close(hlpf);
244 
245  function hs = doplot(zd, ax)
246  V = reshape(zd,this.Dims(1),[])^t;
247 
248  /* bugfix: constant nonzero values cause slice to crash when
249  * setting the clim property.
250  * if V(1) ~= 0 && all(V(1) == V(:))
251  * V(1) = 1.0001*V(1);
252  * end
253  *hs = mesh(hlpax,X,Y,V); */
254  hs = surf(hlpax,X,Y,V);
255  set(hs," Parent ",ax);
256  set(hs," FaceColor "," interp "," EdgeColor "," none ");
257  end
258  }
275 };
276 }
277 }
278 
279 
280 
char Name
The name of the Model.
Definition: BaseModel.m:117
Collection of generally useful functions.
Definition: Utils.m:17
PCDSystem2D The programmed cell death model for 2D geometry.
Definition: PCDSystem2D.m:19
h
Spatial stepwidth (in unscaled size units!) is set in subclasses.
Definition: BasePCDSystem.m:62
function varargout = plot(models.BaseFullModel model,double t,matrix< double > y, varargin)
Definition: PCDSystem2D.m:61
The base class for any KerMor detailed model.
Definition: BaseFullModel.m:18
Model
The Model this System is attached to.
hs
scaled spatial stepwidth
Dims
The system's dimensions.
reshape
hanges the dimensions of the handle object array to the specified dimensions. See the MATLAB reshape ...
function varargout = plotState(models.BaseFullModel model,double t,matrix< double > y, varargin)
Definition: PCDSystem2D.m:82
LinearCoreFun(A)
No system reference needed for constant linear core fun.
Definition: LinearCoreFun.m:43
PlotManager: Small class that allows the same plots generated by some script to be either organized a...
Definition: PlotManager.m:17
A boolean value.
dscomponents.AInitialValue x0
Function handle to initial state evaluation.
function newSysDimension()
Custom updates for new system dimension.
Definition: PCDSystem2D.m:106
logical LeaveOpen
Flag indicating if the plots should be left open once the PlotManager is deleted (as variable) ...
Definition: PlotManager.m:213
A variable number of input arguments.
static function [ A , idxmat ] = laplacemat(h, d1, d2)
Computes a 2D diffusion sparse matrix with zero neuman boundary conditions.
Definition: MatUtils.m:34
delete
Handle object destructor method that is called when the object's lifecycle ends.
#define X(i, j)
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.
logical Plot2D
Flag that indicates if the plot command yields a 2D plot or a 1D slice over time plot.
Definition: PCDSystem2D.m:34
MatUtils: Matrix utility functions.
Definition: MatUtils.m:17
#define Y(i, j)
A matlab row vector.
Omega
The spatial width/area/region (in unscaled size units!)
Definition: BasePCDSystem.m:78
PCDSystem2D(models.BaseFullModel model)
Definition: PCDSystem2D.m:47
PCDSYSTEM The 2D dynamical system of the Programmed Cell Death Model by Markus Daub.
Definition: BasePCDSystem.m:19
dscomponents.LinearCoreFun A
Represents a linear or affine-linear component of the dynamical system.
Diff
Relative diffusion coefficients ([d2/d1, d3/d1, d4/d1])
char SaveTag
A custom tag that can be used as a prefix to files for corresponding model identification.
A variable number of output arguments.