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
Dynamics.m
Go to the documentation of this file.
1 namespace models{
2 namespace muscle{
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 Dynamics
28  public:
29 
30  b1cf = 5.316372204148964;
38 d1cf = 0.014991843974911;
80 
82 
84 
85 
94 
95 
96  public:
97 
99 
101 
103 
105 
107 
108 
109  public:
110 
122 
123 
125 
126 
127  public: /* ( Transient ) */
128 
143 
145 
146 
147  public: /* ( Transient ) */
148 
163  private: /* ( Transient ) */
164 
165  usemassinv;
177  crossfibres = false;
189  private:
190 
191  fsys;
199  public:
200 
201  Dynamics(sys) {
202  this = this@dscomponents.ACompEvalCoreFun(sys);
203 
204  /* % Load AP expansion
205  * d = fileparts(which('models.muscle.Dynamics'));
206  * s = load(fullfile(d,'AP'));
207  * s.kexp.Ma = s.kexp.Ma(1,:);
208  * this.APExp = s.kexp; */
209  }
210 
211 
212  function configUpdated() {
213  sys = this.fsys;
214  mc = sys.Model.Config;
215  if ~isempty(mc.FibreTypeWeights)
216  this.nfibres= size(mc.FibreTypeWeights,2);
217  end
218  if ~isempty(mc)
219  this.xDim= sys.NumTotalDofs;
220  this.fDim= sys.NumDerivativeDofs;
222 
223  /* % Sigma assembly matrix */
224  this.precomputeUnassembledData;
225  end
226  }
227 
228 
230  prepareSimulation@dscomponents.ACompEvalCoreFun(this, mu);
231 
232  /* Reset counters */
233  this.nfevals= 0;
234  this.nJevals= 0;
235 
236  sys = this.fsys;
237  mc = sys.Model.Config;
238  if ~isempty(mc.Pool)
239  mc.Pool.prepareSimulation(sys.Model.T,mu(4));
240  end
241  /* Returns an all zero function if mu(2) is less or equal to zero! */
242  this.alpha= mc.getAlphaRamp(mu(2));
243 
244  /* Prepare force-length fun */
245  mc.setForceLengthFun(this);
246 
247  /* Muscle anisotropic passive law */
248  mlfg = models.muscle.functions.MarkertLawOriginal(mu(5),mu(6));
249  [this.AnisoPassiveMuscle, this.AnisoPassiveMuscleDeriv] = mlfg.getFunction;
250 
251  /* Tendon anisotropic passive law */
252  mlfg = general.functions.CubicToLinear(mu(7),mu(8));
253 /* mlfg = general.functions.MarkertLaw(1.3895e+07,11.1429,1.637893706954065e+05); */
254  [this.AnisoPassiveTendon, this.AnisoPassiveTendonDeriv] = mlfg.getFunction;
255 
256  /* Get the law function handles that also take b,d as arguments.
257  * Needed due to possibly inhomogeneous material.
258  *[~,~,this.MarkertLawFun,this.MarkertLawFunDeriv] = mlfg.getFunction; */
259 
260  /* Cache stuff */
261  this.usemassinv= sys.UseDirectMassInversion;
262  this.crossfibres= sys.HasFibres && sys.UseCrossFibreStiffness;
263  }
264 
265 
266  function fx = evaluateCoreFun(colvec<double> x,double t) {
267  error(" Do not call directly; have custom evaluate method. ");
268  }
269 
270 
271  function fx = evaluateComponentSet(integer nr,colvec<double> x,double t) {
272  fx = this.evaluate(x,t);
273  fx = this.V(this.PointSets[nr],:)*fx;
274  }
289  fx = this.evaluateMulti(x,t,mu);
290  fx = fx(this.PointSets[nr],:);
291  }
308  function res = test_Jacobian(matrix<double> y,double t,colvec<double> mu) {
309 
310  if nargin < 4
311  mu = this.System.Model.DefaultMu;
312  if nargin < 3
313  t = 1000;
314  if nargin < 2
315  y = this.System.getX0(mu);
316  end
317  end
318  end
319 
320  /* Use nonzero t to have an effect */
321  res = test_Jacobian@dscomponents.ACoreFun(this, y, t, mu);
322  }
339  function copy = clone() {
340  copy = models.muscle.Dynamics(this.System);
341 
342  /* Call superclass clone (for deep copy) */
343  copy = clone@dscomponents.ACompEvalCoreFun(this, copy);
344 
345  /* Copy local properties
346  * No local properties are to be copied here, as so far everything is done in the
347  * constructor. */
348  }
356  function setSystem(sys) {
357  setSystem@dscomponents.ACoreFun(this, sys);
358  if isa(sys," models.ReducedSecondOrderSystem ")
359  this.fsys= sys.Model.FullModel.System;
360  else
361  this.fsys= sys;
362  end
363  }
364 
365 
366  function copy = project(V,W) {
367  copy = project@dscomponents.ACompEvalCoreFun(this, V, W);
368  }
369 
370 
371 
372 #if 0 //mtoc++: 'set.ComputeUnassembled'
373 function ComputeUnassembled(value) {
374  if value && ~isempty(this.fDim_unass)/* #ok */
375 
376  this.fDim= this.fDim_unass;/* #ok */
377 
378  elseif ~value && ~isempty(this.System)
379  this.fDim= this.System.NumDerivativeDofs;
380  end
381  this.ComputeUnassembled= value;
382  }
383 
384 #endif
385 
386 
387  function [SPK , SPg , SPalpha , SPLamDot ] = computeSparsityPattern();
388 
389  protected:
390 
391  function fx = evaluateComponents(rowvec<integer> pts,rowvec<integer> ends,unused1,unused2,matrix<double> x,unused3) {
392  }
430 
431  }
463  private:
464 
465  function precomputeUnassembledData() {
466  sys = this.System;
467  mc = sys.Model.Config;
468  geo = mc.FEM.Geometry;
469  this.num_dv_unass= 3*geo.NumElements * geo.DofsPerElement;
470 
471  /* Velocity part: x,y,z velocities */
472  [i, ~] = find(mc.FEM.Sigma);
473  I = [3*(i" -1)+1; 3*(i "-1)+2; 3*(i^t-1)+3];
474 
475  if numel(I) ~= this.num_dv_unass
476  error(" Size mismatch. Somethings wrong with FEM Sigma ");
477  end
478 
479  n = numel(I);
480  S = sparse(I,1:n,ones(n,1),3*geo.NumNodes,n);
481 
482  /* Take out nodes with dirichlet BC on output side */
483  S(sys.idx_v_bc_local,:) = [];
484  /* Find corresponding unassembled dofs that would be ignored
485  * (due to dirichlet velocity values, pressure dirichlet not
486  * implemented) */
487  bc_unass = find(sum(S,1) == 0);
488  /* Remove them, too. The unassembled evaluation also removes the
489  * corresponding entries of the unassembled vector. */
490  S(:,bc_unass) = [];
491  this.idx_uv_bc_glob_unass= bc_unass; /* [sys.idx_u_bc_glob' bc_unass]; */
492 
493  this.Sigma= S;
494  this.fDim_unass= size(S,2);
495 
496  /* Create boolean array that determines which unassembled dofs
497  * belong to which element
498  * dK dofs */
499  hlp = repmat(1:geo.NumElements, 3*geo.DofsPerElement,1);
500  hlp = hlp(:);
501  hlp(bc_unass) = [];
502  ass = false(geo.NumElements,length(hlp));
503  for k = 1:geo.NumElements
504  ass(k,:) = hlp == k;
505  end
506  this.idx_v_elems_unass= ass;
507  }
508 
514 };
515 }
516 }
517 
518 
ComputeUnassembled
% Unassembled stuff
Definition: Dynamics.m:57
integer fDim
The current output dimension of the function.
Definition: ACoreFun.m:171
Sigma
Sigma assembly matrix.
Definition: Dynamics.m:65
MuscleFibreSystem: The global dynamical system used within the MuscleFibreModel.
Definition: System.m:19
LastBCResiduals
Prepared arguments for APExpansion muprep;.
Definition: Dynamics.m:129
function copy = clone()
Create new instance.
Definition: Dynamics.m:339
RampTime
Helper value for QuickReleaseTests (or others) that use a function handle with certain alpha ramp tim...
Definition: Dynamics.m:149
function setSystem(sys)
Definition: Dynamics.m:356
function fx = evaluateComponentSet(integer nr,colvec< double > x,double t)
Computes the full or reduced component functions of the given point set.
Definition: Dynamics.m:271
Model
The Model this System is attached to.
function res = test_Jacobian(matrix< double > y,double t,colvec< double > mu)
Overrides the random argument jacobian test as restrictions on the possible x values (detF = 1) hold...
Definition: Dynamics.m:308
This class implements the nonlinear continuum mechanics as described in .
Definition: Dynamics.m:19
ForceLengthFun
% Force length function fields
Definition: Dynamics.m:86
function prepareSimulation(colvec< double > mu)
Definition: Dynamics.m:229
An integer value.
A MatLab function handle.
#define I(x, y, z)
Definition: CalcMD5.c:171
b1cf
Cross-fibre markert part [MPa] = [N/mm²].
Definition: Dynamics.m:30
matrix< double > S
The x-component selection matrices (precomputed on setting PointSet/AltPointSet). �S� is passed to ...
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
lambda_dot_pos
Helper variable for fullmodels.muscle.model.
Definition: Dynamics.m:111
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 fx = evaluate(x, t)
Evaluates the f-approximation. Depending on a possible projection and the CustomProjection-property t...
Definition: ACoreFun.m:296
idx_uv_bc_glob_unass
The indices of any dirichlet value in the unassembled vector duvw.
Definition: Dynamics.m:72
sparse< logical > JSparsityPattern
Sparsity pattern for the jacobian matrix.
Definition: ACoreFun.m:127
function fx = evaluateComponents(rowvec< integer > pts,rowvec< integer > ends, unused1, unused2,matrix< double > x, unused3)
This is the template method that actually evaluates the components at given points and values...
Definition: Dynamics.m:391
function x_xdot_c0 = getX0(colvec< double > mu)
Compiles the global x0 vector of the global dof vector.
ACompEvalCoreFun: A normal CoreFun which supports single-component evaluation.
function fx = evaluateMulti(colvec< double > x,double t,colvec< double > mu)
Evaluates this function on multiple locations and maybe multiple times and parameters.
Definition: ACoreFun.m:335
function fx = evaluateComponentSetMulti(integer nr,matrix< double > x,rowvec< double > t,matrix< double > mu)
Computes the full component functions of the given point set.
Definition: Dynamics.m:288
function_handle alpha
The activation of the muscle at time t [-].
Definition: Dynamics.m:46
function copy = project(V, W)
Definition: Dynamics.m:366
W
The matrix of the biorthogonal pair .
Definition: AProjectable.m:72
function [ SPK , SPg , SPalpha , SPLamDot ] = computeSparsityPattern()
Computes all sorts of patterns simultaneously.
function configUpdated()
Definition: Dynamics.m:212
function fx = evaluateCoreFun(colvec< double > x,double t)
Actual method used to evaluate the dynamical sytems' core function.
Definition: Dynamics.m:266
function dfx = evaluateComponentPartialDerivatives(rowvec< integer > pts,rowvec< integer > ends,rowvec< integer > idx,rowvec< integer > deriv,rowvec< integer > self,colvec< double > x,double t, dfxsel)
Computes specified partial derivatives of of the components given by pts and the selected partial de...
Definition: Dynamics.m:429