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
Debug.m
Go to the documentation of this file.
1 namespace models{
2 namespace muscle{
3 namespace examples{
4 
5 
6 /* (Autoinserted by mtoc++)
7  * This source code has been filtered by the mtoc++ executable,
8  * which generates code that can be processed by the doxygen documentation tool.
9  *
10  * On the other hand, it can neither be interpreted by MATLAB, nor can it be compiled with a C++ compiler.
11  * Except for the comments, the function bodies of your M-file functions are untouched.
12  * Consequently, the FILTER_SOURCE_FILES doxygen switch (default in our Doxyfile.template) will produce
13  * attached source files that are highly readable by humans.
14  *
15  * Additionally, links in the doxygen generated documentation to the source code of functions and class members refer to
16  * the correct locations in the source code browser.
17  * However, the line numbers most likely do not correspond to the line numbers in the original MATLAB source files.
18  */
19 
20 class Debug
55  public:
56 
58  if nargin == 1 && isscalar(varargin[1])
59  varargin = [" Version ",varargin[1]];
60  end
61  /* Creates a Debug simple muscle model configuration. */
62  this = this@models.muscle.AMuscleConfig(varargin[:]);
63  this.addOption(" Version ",3);
64  this.init;
65 
66  switch this.Options.Version
67  case [4,5,6]
68  this.VelocityBCTimeFun= general.functions.ConstantUntil(15);
69  this.Options.FL= 2;
70  case [7,8,9]
71  this.VelocityBCTimeFun= general.functions.ConstantUntil(15);
72  case 14
73  /* Use classical FL function with fl(1)=1 */
74  this.Options.FL= 3;
75  end
76  }
85  function configureModel(m) {
86  configureModel@models.muscle.AMuscleConfig(this, m);
87 /* sys = m.System;
88  * f = sys.f; */
89  m.T= 50;
90  m.dt= m.T / 30;
91  m.ODESolver.RelTol= 1e-5;
92  m.ODESolver.AbsTol= 1e-3;
93  switch this.Options.Version
94  case 1
95  m.DefaultMu(2) = -1;
96  case 2
97  m.DefaultMu(1:2) = [1; m.T/2];
98  case 3
99  m.T= 400;
100  m.dt= 1;
101  types = [0 .2 .4 .6 .8 1];
102  fe = this.FEM;
103  geo = fe.Geometry;
104  ftw = zeros(fe.GaussPointsPerElem,length(types),geo.NumElements);
105  /* Test: Use only slow-twitch muscles */
106  ftw(:,1,:) = .4;
107  ftw(:,2,:) = .05;
108  ftw(:,3,:) = .05;
109  ftw(:,4,:) = .1;
110  ftw(:,5,:) = .2;
111  ftw(:,6,:) = .2;
112  this.FibreTypeWeights= ftw;
113  p = models.motorunit.Pool;
114  p.FibreTypes= types;
115  this.Pool= p;
116 /* m.ODESolver.RelTol = .01;
117  * m.ODESolver.AbsTol = .1; */
118  m.Plotter.DefaultArgs= [" Pool ",true];
119  m.DefaultMu(4) = 4;
120  case [4,5,6]
121  /* % Material configuration from CMISS/3Elem_sprenger.xml
122  * c3M = 3.05907e-10 MPa */
123  m.DefaultMu(5) = 3.05907e-10; /* b1 [MPa]
124  * c4M = 47.270456264135881 */
125 
126  m.DefaultMu(6) = 47.270456264135881; /* d1 [-]
127  * c1M = 3.56463903963e-02 MPa */
128 
129  m.DefaultMu(9) = 35.6463903963; /* c10 [MPa]
130  * c2M = 3.859558659683e-3 MPa */
131 
132  m.DefaultMu(10) = 3.859558659683; /* c01 [MPa] */
133 
134 
135  /* sigma_max_calculation */
136  m.DefaultMu(13) = .300; /* [MPa]
137  * lambda_ofl_calculation */
138 
139  m.DefaultMu(14) = 1.4; /* [-] */
140 
141  m.T= 20;
142  m.dt= .25;
143  case [7,8,9]
144  /* % Using the Material configuration of Heidlauf */
145  m.DefaultMu(5) = 0.00355439810963035e-3; /* b1 [MPa] */
146 
147  m.DefaultMu(6) = 12.660539325481963; /* d1 [-] */
148 
149  m.DefaultMu(9) = 6.352e-13; /* c10 [MPa] */
150 
151  m.DefaultMu(10) = 3.627e-3; /* c01 [MPa] */
152 
153  m.T= 50;
154  m.dt= .5;
155  case 10
156  m.ODESolver.RelTol= .001;
157  m.ODESolver.AbsTol= .03;
158  m.DefaultMu(1:3) = [0;0;1];
159  m.DefaultInput= 1;
160  m.T= 1;
161  m.dt= .01;
162  case 11
163  m.ODESolver.RelTol= .001;
164  m.ODESolver.AbsTol= .05;
165  m.T= 10;
166  m.dt= .05;
167  case 12
168  m.DefaultMu(1:2) = [.1; 50];
169  m.System.UseCrossFibreStiffness= true;
170  end
171  }
172 
173 
174  function configureModelFinal() {
175  configureModelFinal@models.muscle.AMuscleConfig(this)
176  m = this.Model;
177  /* Have the PODReducer always generate the full reduced model */
178  m.SpaceReducer.Value= length(m.SpaceReducer.TargetDimensions);
179  }
180 
181 
182  function P = getBoundaryPressure(elemidx,faceidx) {
183  P = [];
184  if this.Options.Version == 10
185  if elemidx == 1 && faceidx == 2
186  P = 1;
187  end
188  end
189  }
203  function u = getInputs() {
204  u = [];
205  if this.Options.Version == 10
206  u = [this.getAlphaRamp(this.Model.T/2,.1)];
207  end
208  }
209 
210 
211  protected:
212 
213 
214  function geo = getGeometry() {
215  geo = fem.geometry.RegularHex8Grid([0 1],[0 1],[0 1]);
216  /* [pts, cubes] = fem.geometry.RegularHex8Grid([0:.5:1],[0:.5:1],[0:.5:1]); */
217  if this.Options.Version == 11 || this.Options.Version == 12
218  geo = fem.geometry.RegularHex8Grid([-1 1],[-1 1],[-1 1]);
219  pts = geo.Nodes;
220  cubes = geo.Elements;
221  pts(1,[6 8]) = 2;
222  theta = .3;
223  R = [cos(theta) -sin(theta) 0
224  sin(theta) cos(theta) 0
225  0 0 1];
226  pts = circshift(R,[1 1])*R*pts;
227  geo = fem.geometry.Cube8Node(pts, cubes);
228  end
229  geo = geo.toCube27Node;
230  }
238  function displ_dir = setPositionDirichletBC(displ_dir) {
239  geo = this.FEM.Geometry;
240  /* Always fix back side */
241  switch this.Options.Version
242  case 4
243  displ_dir(:,geo.Elements(1,geo.MasterFaces(4,:))) = true;
244  case 10
245  displ_dir(1,geo.Elements(1,geo.MasterFaces(1,:))) = true;
246  case 14
247  displ_dir(:,geo.Elements(1,geo.MasterFaces(1:2,:))) = true;
248  otherwise
249  displ_dir(:,geo.Elements(1,geo.MasterFaces(1,:))) = true;
250  end
251  }
252 
253 
254  function [velo_dir , velo_dir_val ] = setVelocityDirichletBC(velo_dir,velo_dir_val) {
255  geo = this.FEM.Geometry;
256  switch this.Options.Version
257 
258  case 4
259  velo_dir(2,geo.Elements(1,geo.MasterFaces(3,:))) = true;
260  velo_dir_val(velo_dir) = -.01;
261  case [5,6]
262  velo_dir(1,geo.Elements(1,geo.MasterFaces(2,:))) = true;
263  velo_dir_val(velo_dir) = .01;
264  case [7,8,9]
265  velo_dir(1,geo.Elements(1,geo.MasterFaces(2,:))) = true;
266  velo_dir_val(velo_dir) = .04;
267  case 11
268  velo_dir(:,geo.Elements(1,geo.MasterFaces(2,:))) = true;
269  hlp = velo_dir;
270  hlp([1 3],:) = 0;
271  velo_dir_val(hlp) = .01;
272  end
273  }
284  function anull = seta0(anull) {
285  switch this.Options.Version
286  case [2,3,5,8,12,14]
287  anull(1,:,:) = 1;
288  case [4,7]
289  /* No fibres */
290  case [6,9]
291  /* Stretch perpendicular to fibre direction */
292  anull(2,:,:) = 1;
293  case [10,11]
294  anull(:,:,:) = 0;
295  end
296  }
297 
298 
299  public: /* ( Static ) */
300 
301  static function test_DebugConfigV4_9(version) {
302  if nargin < 1
303  version = 4;
304  end
305  m = models.muscle.Model(models.muscle.examples.Debug(version));
306  [t,y] = m.simulate;
307  pdf = m.getResidualForces(t,y);
308 
309  /* 1..27 are residual forces from fixed position nodes */
310  force_on_fixed_side = sum(pdf(1:27,:),1);
311  /* 28..36 (=9) are residual forces from moved nodes */
312  force_on_moved_side = sum(pdf(28:end,:),1);
313  figure;
314  plot(t,force_on_fixed_side," r ",t,force_on_moved_side," b ");
315  xlabel(" time "); ylabel(" force [N] ");
316 
317  /* Node 15 is center -> dof indices (15-1)*3 + [1 2 3] */
318  yall = m.System.includeDirichletValues(t,y);
319  xpos = yall((15-1)*3+1,end);
320  fprintf(" Force at T=%g, x-position (center node) %g: %gN\n ",t(end),xpos,force_on_moved_side(end));
321 
322  m.plot(t,y," DF ",pdf," Velo ",true," Pause ",.02);
323  }
343  static function test_DebugConfigs(versions) {
344  if nargin < 1
345  versions = [1 2 3 10 11];
346  end
347  for k = versions
348  fprintf(" Testing DebugConfig Version %d\n ",k);
349  m = models.muscle.Model(models.muscle.examples.Debug(k));
350  [t,y] = m.simulate;
351  df = m.getResidualForces(t,y);
352  m.plot(t,y," DF ",df," Velo ",true);
353  end
354  }
355 
356 
357 
358 };
359 }
360 }
361 }
362 
363 
364 
function configureModelFinal()
Definition: Debug.m:174
function u = getInputs()
Definition: Debug.m:203
function addOption(name, default, varargin)
Definition: AFEMConfig.m:219
function alpha = getAlphaRamp(ramptime,double alphamax,double starttime)
Creates a linearly increasing scalar function starting at starttime milliseconds ranging from zero to...
function anull = seta0(anull)
Definition: Debug.m:284
function geo = getGeometry()
Single cube with same config as reference element.
Definition: Debug.m:214
function configureModel(m)
Definition: Debug.m:85
A simple configuration for Debug purposes.
Definition: Debug.m:20
function P = getBoundaryPressure(elemidx, faceidx)
Determines the neumann forces on the boundary.
Definition: Debug.m:182
A variable number of input arguments.
Debug(varargin)
Quick fix for old-style DebugConfig call passing in the version number directly.
Definition: Debug.m:57
static function test_DebugConfigV4_9(version)
Results: 4: Force at T=20, x-position (center node) 1.49844: -0.0476511N 5: Force at T=20...
Definition: Debug.m:301
double T
The final timestep up to which to simulate.
Definition: BaseModel.m:271
VelocityBCTimeFun
Velocity conditions application function.
Definition: AFEMConfig.m:65
function displ_dir = setPositionDirichletBC(displ_dir)
Definition: Debug.m:238
static function test_DebugConfigs(versions)
Definition: Debug.m:343
function [ velo_dir , velo_dir_val ] = setVelocityDirichletBC(velo_dir, velo_dir_val)
Determines the dirichlet velocities.
Definition: Debug.m:254
Model: Model for a FEM-discretized muscle model.
Definition: Model.m:19