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
computeSparsityPattern.m
Go to the documentation of this file.
1 #include "Dynamics.m"
2 namespace models{
3 namespace muscle{
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 function [SPK , SPg , SPalpha , SPLamDot ] = models.muscle.Dynamics.computeSparsityPattern() {
21  sys = this.fsys;
22  mc = sys.Model.Config;
23  fe_pos = mc.FEM;
24  geo = fe_pos.Geometry;
25  fe_press = mc.PressureFEM;
26  pgeo = fe_press.Geometry;
27 
28  N = geo.NumNodes;
29 
30  /* Jalpha */
31  if this.nfibres > 0
32  iS = [];
33  jS = [];
34  columns_sarco_link = 53:56:56*this.nfibres;
35  end
36 
37  /* JLamDot */
38  if ~isempty(this.lambda_dot_pos)
39  ildot = [];
40  jldot = [];
41  end
42 
43  num_elements = geo.NumElements;
44  num_gausspoints = fe_pos.GaussPointsPerElem;
45  dofs_pos = N*3;
46  dofsperelem_displ = geo.DofsPerElement;
47  dofsperelem_press = pgeo.DofsPerElement;
48 
49  /* Compute indices vectors size for speed */
50  isize = num_elements*num_gausspoints*(...
51  dofsperelem_displ*...
52  (3*(3*dofsperelem_displ + dofsperelem_press)));
53  i = zeros(isize,1," int32 ");
54  j = zeros(isize,1," int32 ");
55 
56  curoff = 0;
57  for m = 1:num_elements
58  elemidx_u = sys.idx_u_elems_local(:,:,m);
59  elemidx_v = elemidx_u + dofs_pos;
60  elemidx_p_glob = sys.idx_p_elems_local(:,m)+2*dofs_pos;
61  inew = elemidx_u(:);
62  one = ones(size(inew)," int32 ");
63  for gp = 1:num_gausspoints
64  for k = 1:dofsperelem_displ
65  /* % Grad_u K(u,v,w) */
66  step = 3*3*dofsperelem_displ;
67  /* x,y,zdim */
68  i(curoff+(1:step)) = [inew; inew; inew];
69  j(curoff+(1:step)) = [one*elemidx_u(1,k)
70  one*elemidx_u(2,k)
71  one*elemidx_u(3,k)];
72  curoff = curoff + step;
73 
74  /* % Grad_v K(u,v,w) FIXME IF UNCOMMENTED
75  * if visc > 0
76  * % xdim
77  * i = [i; inew]; %#ok<*AGROW>
78  * j = [j; one*elemidx_velo(1,k)];
79  * % ydim
80  * i = [i; inew];
81  * j = [j; one*elemidx_velo(2,k)];
82  * % zdim
83  * i = [i; inew];
84  * j = [j; one*elemidx_velo(3,k)];
85  * end */
86  end
87 
88  /* % Grad_w K(u,v,w) */
89  inew = elemidx_u(:);
90  step = 3*dofsperelem_displ;
91  for k = 1:dofsperelem_press
92  i(curoff + (1:step)) = inew;
93  j(curoff + (1:step)) = one*elemidx_p_glob(k);
94  curoff = curoff + step;
95  end
96 
97  /* % Jalpha pattern */
98  for k = 1:this.nfibres
99  iS = [iS; elemidx_v(:)-dofs_pos];
100  jS = [jS; ones(3*dofsperelem_displ,1)*columns_sarco_link(k)];
101  end
102 
103  /* % Check if change rate of lambda at a certain point should be tracked */
104  if ~isempty(this.lambda_dot_pos)
105  k = find(this.lambda_dot_pos(1,:) == m & this.lambda_dot_pos(2,:) == gp);
106  if ~isempty(k)
107  ildot = [ildot; k*ones(6*dofsperelem_displ,1)];
108  jldot = [jldot; elemidx_u(:); elemidx_v(:)];
109  end
110  end
111  end
112  end
113  SPK = sparse(double(i),double(j),ones(size(i)),3*N,6*N+pgeo.NumNodes);
114 
115  /* Remove values at dirichlet nodes */
116  SPK = SPK(1:3*N,:);
117  SPK(:,sys.idx_uv_bc_glob) = [];
118  SPK([sys.idx_u_bc_local; sys.idx_expl_v_bc_local],:) = [];
119  SPK = logical(SPK);
120 
121  SPalpha = [];
122  if this.nfibres > 0
123  SPalpha = sparse(double(iS),double(jS),ones(size(iS)),3*N,this.nfibres*56);
124  /* Remove those that are connected to dirichlet values */
125  SPalpha([sys.idx_u_bc_local sys.idx_v_bc_local],:) = [];
126  SPalpha = logical(SPalpha);
127  end
128 
129  SPLamDot = [];
130  if ~isempty(this.lambda_dot_pos)
131  SPLamDot = sparse(ildot,double(jldot),true(size(ildot)),this.nfibres,6*N);
132  SPLamDot(:,sys.idx_uv_bc_glob) = [];
133  end
134 end
135 
136 
137 }
144 };
145 };
A boolean value.
function [ SPK , SPg , SPalpha , SPLamDot ] = computeSparsityPattern()
Computes all sorts of patterns simultaneously.