Changeset 2561
- Timestamp:
- 10/29/09 08:42:31 (15 years ago)
- Location:
- issm/trunk/src/m/classes/public
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk/src/m/classes/public/plot/plot_streamlines.m
r2439 r2561 4 4 % Usage: 5 5 % plot_streamlines(md,options) 6 7 %some options8 maxiter=200; %maximum number of iterations9 precision=1; %division of each segment (higer precision increases number of segments)10 6 11 7 %process data and model … … 19 15 return 20 16 end 21 22 %take velocity for each element23 u=u(index)*[1;1;1]/3;24 v=v(index)*[1;1;1]/3;25 17 26 18 %initialize flowpath … … 37 29 end 38 30 39 %check seed points 40 tria=tsearch(x,y,index,x0,y0); 41 pos=find(isnan(tria)); 42 %seems to be a bug here: must do the test several times... 43 while ~isempty(pos) 44 x0(pos)=[]; 45 y0(pos)=[]; 46 tria=tsearch(x,y,index,x0,y0); 47 pos=find(isnan(tria)); 48 end 49 50 %initialize other variables 51 N=length(x0); 52 X=x0; Y=y0; 53 flowpath=struct('xc',cell(N,1),'yc',cell(N,1),'done',cell(N,1)); 54 for i=1:N, 55 flowpath(i).xc=x0(i); 56 flowpath(i).yc=y0(i); 57 end 58 done=zeros(N,1); 59 60 %get avegared length of each element 61 length_tria=1/3*(sqrt( (x(index(:,1))-x(index(:,2))).^2+(y(index(:,1))-y(index(:,2))).^2 )+... 62 sqrt((x(index(:,1))-x(index(:,3))).^2+(y(index(:,1))-y(index(:,3))).^2 )+... 63 sqrt((x(index(:,2))-x(index(:,3))).^2+(y(index(:,2))-y(index(:,3))).^2 )); 64 65 %initialization: 66 counter=1; 67 68 while any(~done) 69 70 %find current triangle 71 queue=find(~done); 72 tria=tsearch(x,y,index,X(queue),Y(queue)); 73 74 %check that the point is actually inside a triangle of the mesh 75 listnan=find(isnan(tria)); 76 for i=1:length(listnan) 77 %remove the last point 78 flowpath(queue(listnan(i))).xc(end)=[]; 79 flowpath(queue(listnan(i))).yc(end)=[]; 80 done(queue(listnan(i)))=1; 81 end 82 tria(listnan)=[]; 83 queue(listnan)=[]; 84 85 %velocity of the current triangle and norm it 86 ut=u(tria); vt=v(tria); normv=sqrt(ut.^2+vt.^2); 87 ut=ut./normv;vt=vt./normv; 88 89 %check counter 90 if counter>maxiter 91 disp(['Maximum number of iterations (' num2str(maxiter) ') reached while going forward']) 92 break 93 end 94 counter=counter+1; 95 96 %remove stagnant point 97 done(queue(find(ut==0 & vt==0)))=1; 98 99 %build next point 100 for i=1:length(queue) 101 X(queue(i))=flowpath(queue(i)).xc(end)+ut(i)*length_tria(tria(i))/precision; 102 Y(queue(i))=flowpath(queue(i)).yc(end)+vt(i)*length_tria(tria(i))/precision; 103 flowpath(queue(i)).xc=[flowpath(queue(i)).xc;flowpath(queue(i)).xc(end)+ut(i)*length_tria(tria(i))/precision]; 104 flowpath(queue(i)).yc=[flowpath(queue(i)).yc;flowpath(queue(i)).yc(end)+vt(i)*length_tria(tria(i))/precision]; 105 end 106 end 107 108 %same process but reverse (vel=-vel) to have a vcomplete flow line 109 counter=1; 110 X=x0; Y=y0; 111 done=zeros(N,1); 112 113 while any(~done) 114 115 %find current triangle 116 queue=find(~done); 117 tria=tsearch(x,y,index,X(queue),Y(queue)); 118 119 %check that the point is actually inside a triangle of the mesh 120 listnan=find(isnan(tria)); 121 for i=1:length(listnan) 122 %remove the last point 123 flowpath(queue(listnan(i))).xc(1)=[]; 124 flowpath(queue(listnan(i))).yc(1)=[]; 125 done(queue(listnan(i)))=1; 126 end 127 tria(listnan)=[]; 128 queue(listnan)=[]; 129 130 %velocity of the current triangle and norm it 131 ut=-u(tria); vt=-v(tria); normv=sqrt(ut.^2+vt.^2); 132 ut=ut./normv;vt=vt./normv; 133 134 %check counter 135 if counter>maxiter 136 disp(['Maximum number of iterations (' num2str(maxiter) ') reached while going backward']) 137 break 138 end 139 counter=counter+1; 140 141 %remove stagnant point 142 done(queue(find(ut==0 & vt==0)))=1; 143 144 %build next point 145 for i=1:length(queue) 146 X(queue(i))=flowpath(queue(i)).xc(1)+ut(i)*length_tria(tria(i))/precision; 147 Y(queue(i))=flowpath(queue(i)).yc(1)+vt(i)*length_tria(tria(i))/precision; 148 flowpath(queue(i)).xc=[flowpath(queue(i)).xc(1)+ut(i)*length_tria(tria(i))/precision; flowpath(queue(i)).xc]; 149 flowpath(queue(i)).yc=[flowpath(queue(i)).yc(1)+vt(i)*length_tria(tria(i))/precision; flowpath(queue(i)).yc]; 150 end 151 end 31 %Get flow lines 32 flowpath=flowlines(index,x,y,u,v,x0,y0); 152 33 153 34 %plot 154 35 hold on 155 36 for i=1:length(flowpath) 156 patch('Xdata',[flowpath(i).x c;NaN],'Ydata',[flowpath(i).yc;NaN],'facecolor','none','edgecolor','y');37 patch('Xdata',[flowpath(i).x;NaN],'Ydata',[flowpath(i).y;NaN],'facecolor','none','edgecolor','y'); 157 38 end
Note:
See TracChangeset
for help on using the changeset viewer.