This is a static copy of a profile report

Home

generateBEMmesh (1 call, 2.406 sec)
Generated 18-Mar-2011 23:31:41 using cpu time.
M-function in file /Users/Robert/Documents/Work/Cardiff/postdoc/myrepo/NURBS/isoBEM/generateBEMmesh.m
Copy to new window for comparing multiple runs

Parents (calling functions)
No parent
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
178
legend('NURBS basis functions'...
10.788 s32.8%
215
figure(2); grid on
10.456 s19.0%
165
[N dN] = NURBSbasis(i,p,xi(poi...
69000.301 s12.5%
158
figure(1); grid on
10.228 s9.5%
172
plot(xi,NURBSvalues(:,i), 'k-'...
230.187 s7.8%
All other lines  0.446 s18.5%
Totals  2.406 s100% 
Children (called functions)

Function NameFunction TypeCallsTotal Time% TimeTime Plot
legendM-function20.933 s38.8%
legendcolorbarlayout>doParentResizeM-subfunction10.114 s4.7%
NURBSbasisMEX-function69000.104 s4.3%
holdM-function480.052 s2.2%
newplotM-function260.041 s1.7%
uniqueM-function10.031 s1.3%
axisM-function10.021 s0.9%
legendcolorbarlayout>doPixelBoundsCBM-subfunction20.021 s0.9%
gridM-function20.021 s0.9%
scribe.legend.init>setWidthHeightM-subfunction10.010 s0.4%
NURBSinterpolationMEX-function720 s0%
initprintexporttemplateM-function20 s0%
figureToolbarCreateFcnM-function20 s0%
linspaceM-function10 s0%
Self time (built-ins, overhead, etc.)  1.058 s44.0%
Totals  2.406 s100% 
M-Lint results
Line numberMessage
45The value assigned to variable 'n' might be unused.
Coverage results
[ Show coverage for parent directory ]
Total lines in function239
Non-code lines (comments, blank lines)115
Code lines (lines that can run)124
Code lines that did run88
Code lines that did not run36
Coverage (did run/can run)70.97 %
Function listing
   time   calls  line
1 function [ controlPts, knotVec, collocPts, collocCoords, bsFnConn, elConn, tracConn, elRange, tracDispConn ] = generateBEMmesh( p, refinement )
2
3 % This function generate the isogeom BEM mesh and returns
4 % controlPts : matrix of the control points
5 % knotVec : knot vector
6 % collocPts : collocation points in parametric space
7 % elConn : connectivity matrix which gives non-zero basis fns in element
8 % tracConn : traction connectivity matrix - specifies 'traction DOF' for each element
9 % elRange : the lower and upper range of the element in the parametric space ie [xi_lower, xi_upper]
10
11 % Assume p=2 : the degree of the NURBS basis
12 % refinement : 1,2,3 etc. As this number increases, the h-refinement increases
13
14
15
16 % Plate with a hole geometry
17
18 % knotVec=[0 0 0 1/9 1/9 1/3 1/3 2/3 2/3 7/9 7/9 1 1 1];
19 % controlPts=[-4 0 1; -2.5 0 1; -1 0 1; -1 1 1/sqrt(2); 0 1 1; 0 2.5 1; 0 4 1; -2 4 1; -4 4 1; -4 2 1; -4 0 1];
20
21
22
23 % L-plate problem
24 % knotVec = [0 0 0 1/6 1/6 2/6 2/6 3/6 3/6 4/6 4/6 5/6 5/6 1 1 1];
25 % controlPts = [0 -sqrt(2) 1; 1/sqrt(2) -1/sqrt(2) 1; sqrt(2) 0 1; 1/sqrt(2) 1/sqrt(2) 1; ...
26 % 0 sqrt(2) 1; -1/(2*sqrt(2)) 3/(2*sqrt(2)) 1; -1/sqrt(2) 1/sqrt(2) 1; -1/(2*sqrt(2)) 1/(2*sqrt(2)) 1;...
27 % 0 0 1; -1/(2*sqrt(2)) -1/(2*sqrt(2)) 1; -1/sqrt(2) -1/sqrt(2) 1; -1/(2*sqrt(2)) -3/(2*sqrt(2)) 1; 0 -sqrt(2) 1];
28
29
30
31 % Spanner problem
1 32 knotVec = [0 0 0 1 1 2 2 3 3 4 5 6 6 7 7 8 9 10 10 11 11 12 12 13 13 13];
1 33 controlPts = [ 0 0; -0.5 -0.5; -1 -1; -1.5, -1; -2 -1;...
34 -2 -1.25; -2 -1.5; -1 -3; 1 -1; 5 -1; 10 -1; 10 0;...
35 10 1; 5 1; 1 1; -1 3; -2 1.5; -2 1.25; -2 1; ...
36 -1.5 1; -1 1; -0.5 0.5; 0 0];
37
0.01 1 38 knotVec = knotVec/max(knotVec);
1 39 weights = ones(1,size(controlPts,1));
1 40 weights(9)=2;
1 41 weights(15)=2;
1 42 controlPts = [controlPts weights'];
43
0.04 1 44 uniqueKnots=unique(knotVec);
1 45 n=length(knotVec)-1-p;
1 46 weightedPts=[controlPts(:,1).*controlPts(:,3) controlPts(:,2).*controlPts(:,3) controlPts(:,3)];
47
48 % -------------------------------------
49 % ------------ h-refinement -----------
50 % -------------------------------------
51
52 % the idea here is to take the original knot vector and add knots at point
53 % in between existing points
54
1 55 if refinement>1
56 oldKnotVec=knotVec;
57 newKnots=zeros((length(uniqueKnots)-1),refinement-1);
58
59 for i=1:size(newKnots,1)
60 distributed=linspace(uniqueKnots(i),uniqueKnots(i+1),refinement+1);
61 newKnots(i,:)=distributed(2:end-1);
62 end
63 [m n]=size(newKnots);
64 newKnots=sort(reshape(newKnots,1,m*n));
65
66
67 % and now redefine the control points
68 for knot=1:length(newKnots) % loop over all the new knots
69 newControlPts=zeros(length(weightedPts)+1,3); % increase the array of control points
70 knot_bar=newKnots(knot);
71 kval=find(knotVec>knot_bar, 1 )-1;
72 for i=1:length(newControlPts)
73 if i<= (kval - p)
74 alpha=1;
75 elseif i>=(kval-p+1) && i<= kval
76 alpha= ( newKnots(knot) - oldKnotVec(i) ) / ( oldKnotVec(i+p) - oldKnotVec(i) );
77 else
78 alpha=0;
79 end
80 newPoints=zeros(1,3);
81 if i~=1
82 newPoints=(1-alpha).*weightedPts(i-1,:);
83 end
84 if i~= length(newControlPts)
85 newPoints=newPoints + alpha * weightedPts(i,:);
86 end
87 newControlPts(i,:)=newPoints;
88 end
89 weightedPts=newControlPts;
90 knotVec=sort([knotVec knot_bar]);
91 oldKnotVec=knotVec;
92 end
93
94 controlPts=[weightedPts(:,1)./weightedPts(:,3) weightedPts(:,2)./weightedPts(:,3) weightedPts(:,3)];
95 uniqueKnots=unique(knotVec);
96 end
97
98 % --------------------------------------------------------
99 % ------------- Define element connectivities ------------
100 % --------------------------------------------------------
101
102
1 103 ne=length(uniqueKnots)-1; % number of elements
1 104 elRange=zeros(ne,2); % initialise matrices
1 105 elConn=zeros(ne,p+1);
1 106 elKnotIndices=zeros(ne,2);
1 107 tracConn=zeros(ne,p+1);
108
109 % determine our element ranges and the corresponding knot indices
1 110 element=1;
1 111 previousKnotVal=0;
112
1 113 for i=1:length(knotVec)
26 114 currentKnotVal=knotVec(i);
26 115 if knotVec(i)~=previousKnotVal
13 116 elRange(element,:)=[previousKnotVal currentKnotVal];
13 117 elKnotIndices(element,:)=[i-1 i];
13 118 element=element+1;
13 119 end
26 120 previousKnotVal=currentKnotVal;
26 121 end
122
1 123 numRepeatedKnots=0;
1 124 for e=1:ne
13 125 indices=(elKnotIndices(e,1)-p+1):elKnotIndices(e,1);
13 126 previousKnotVals=knotVec(indices);
13 127 currentKnotVals=ones(1,p)*knotVec(elKnotIndices(e,1));
13 128 if isequal(previousKnotVals,currentKnotVals) && length(nonzeros(previousKnotVals))>1;
8 129 numRepeatedKnots=numRepeatedKnots+1;
8 130 end
13 131 elConn(e,:)=(elKnotIndices(e,1)-p):elKnotIndices(e,1);
13 132 tracConn(e,:)=elConn(e,:)+numRepeatedKnots;
13 133 end
1 134 bsFnConn=elConn;
1 135 elConn(end,end)=1; % the last point is equal to the first point
136
137 % create connectivity matrix for traction -> disp DOF
1 138 totalTractionDOF=length(knotVec)-p-1+numRepeatedKnots;
1 139 tracDispConn=zeros(totalTractionDOF,1);
1 140 for e=1:ne
13 141 tracDispConn(tracConn(e,:))=elConn(e,:);
13 142 end
143
144 % -----------------------------------
145 % ------- Plot the mesh - -----------
146 % -----------------------------------
147
148
0.01 1 149 xi=linspace(0,max(knotVec),300);
150
1 151 n=size(xi,2);
1 152 numBasisFns=length(knotVec)-1-p;
1 153 NURBSvalues=zeros(n,numBasisFns);
1 154 NURBSderivVals=zeros(n,numBasisFns);
1 155 collocPts=zeros(1,numBasisFns);
1 156 r=zeros(n,numBasisFns);
157
0.23 1 158 figure(1); grid on
159
1 160 for i=1:numBasisFns
161
23 162 collocPts(i)=sum(knotVec((i+1):(i+p)))/p;
163
23 164 for point=1:n
0.30 6900 165 [N dN] = NURBSbasis(i,p,xi(point),knotVec,controlPts(:,3)');
0.02 6900 166 NURBSvalues(point,i)=N;
0.05 6900 167 NURBSderivVals(point,i)=dN;
0.03 6900 168 r(point,i)=abs(collocPts(i)-xi(point));
0.01 6900 169 end
170
0.04 23 171 hold on
0.19 23 172 plot(xi,NURBSvalues(:,i), 'k-', collocPts(i), 0, 'kx', uniqueKnots,0,'ks')
0.02 23 173 hold off
174
0.01 23 175 end
176
177
0.79 1 178 legend('NURBS basis functions', 'collocation points', 'element edges')
179
180
181 % ---------------------------------------------------------
182 % ------- Get the coords of collocation points ------------
183 % ---------------------------------------------------------
184 %
185
1 186 collocCoords=zeros(numBasisFns,2);
1 187 for point=1:(numBasisFns)
23 188 collocCoords(point,1)=NURBSinterpolation(collocPts(point), p, knotVec, controlPts(:,1)', controlPts(:,3)');
23 189 collocCoords(point,2)=NURBSinterpolation(collocPts(point), p, knotVec, controlPts(:,2)', controlPts(:,3)');
23 190 end
191
1 192 NURBSCoords=NURBSvalues*controlPts;
193
194 % trim off last entries
1 195 collocCoords=collocCoords(1:(end-1),:);
1 196 collocPts=collocPts(1:(end-1));
197
198 % -------------------------------------------
199 % ------- Get the element points ------------
200 % -------------------------------------------
201
1 202 knotCoords=zeros(length(uniqueKnots),2);
1 203 for point=1:(length(knotCoords)-1)
13 204 knotCoords(point,1)=NURBSinterpolation(uniqueKnots(point), p, knotVec, controlPts(:,1)', controlPts(:,3)');
13 205 knotCoords(point,2)=NURBSinterpolation(uniqueKnots(point), p, knotVec, controlPts(:,2)', controlPts(:,3)');
206
13 207 end
208
209 % ---------------------------------------------------------
210 % ------- Plot the mesh and collocation points ------------
211 % ---------------------------------------------------------
212 %
213
214
0.46 1 215 figure(2); grid on
1 216 hold on
1 217 plot(NURBSCoords(:,1), NURBSCoords(:,2), 'k-', controlPts(:,1), controlPts(:,2), 'ro')
1 218 plot(collocCoords(:,1), collocCoords(:,2), 'kx', 'MarkerSize', 10)
1 219 plot(knotCoords(:,1), knotCoords(:,2), 'ks', 'MarkerSize', 6)
1 220 hold off
0.03 1 221 axis equal
222 %
223 % save 'dat_files/NURBS_geometry.dat' NURBSCoords -ASCII
224 % save 'dat_files/controlPts.dat' controlPts -ASCII
225 % save 'dat_files/collocPts.dat' collocCoords -ASCII
226 % save 'dat_files/elementEdges.dat' knotCoords -ASCII
227
228
229 % plot the exact circle geometry
230 % x=-1:0.01:0;
231 % y=sqrt(1-x.^2);
232 % figure(2); hold on
233 % plot(x,y,'g--')
234 % hold off; axis equal
235
0.16 1 236 legend('Original geometry','Control points', 'Collocation points', 'Element edges')
237
238
1 239 end

Other subfunctions in this file are not included in this listing.