Changeset 25779
- Timestamp:
- 11/24/20 13:49:53 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/plot/plotchannels.m
r24079 r25779 4 4 % Usage: 5 5 % plotchannels(md,channelarea,options) 6 % plotchannels(md,channeldischarge,options) 6 7 % 7 8 % List of supported options … … 10 11 % - 'colormap' colormap used (default is 'gray') 11 12 % - 'linewidth' linewidth (default is 2) 13 % - 'quiver' only used for discharge(default is 2) 12 14 % 13 15 % Example: 14 16 % plotchannels(md,md.results.TransientSolution(end).ChannelArea,'min',15,'max',36); 17 % plotchannels(md,md.results.TransientSolution(end).ChannelDischarge,'min',15,'max',36,'quiver',1); 15 18 16 19 %Process options 17 20 options = pairoptions(varargin{:}); 18 21 22 %is quiver? 23 isquiver = (getfieldvalue(options,'quiver',0)==1); 24 19 25 %define level 20 level = channelarea; 26 if isquiver 27 level = abs(channelarea); 28 else 29 level = channelarea; 30 end 21 31 22 32 %Some processing … … 38 48 39 49 %Reconstruct edges 40 if 0, 41 edges = [md.mesh.edges(:,1:2) md.mesh.edges(:,1)]'; 42 else 43 tic 44 %Maximum number of edges 45 maxnbf = 3*md.mesh.numberofelements; 46 %Initialize intermediaries 47 edges = zeros(maxnbf,2); 48 %Chaining algorithm 49 head_minv = -1*ones(md.mesh.numberofvertices,1); 50 next_face = zeros(maxnbf,1); 51 %Initialize number of faces 52 nbf = 0; 53 for i=1:md.mesh.numberofelements 54 for j=1:3 55 %Get the two indices of the edge number j of the ith triangle 56 v1 = md.mesh.elements(i,j); 57 if(j==3) 58 v2 = md.mesh.elements(i,1); 59 else 60 v2 = md.mesh.elements(i,j+1); 50 % {{{ 51 tic 52 %Maximum number of edges 53 maxnbf = 3*md.mesh.numberofelements; 54 %Initialize intermediaries 55 edges = zeros(maxnbf,3); 56 exchange = zeros(maxnbf,1); 57 %Chaining algorithm 58 head_minv = -1*ones(md.mesh.numberofvertices,1); 59 next_face = zeros(maxnbf,1); 60 %Initialize number of faces 61 nbf = 0; 62 for i=1:md.mesh.numberofelements 63 for j=1:3 64 %Get the two indices of the edge number j of the ith triangle 65 v1 = md.mesh.elements(i,j); 66 if(j==3) 67 v2 = md.mesh.elements(i,1); 68 else 69 v2 = md.mesh.elements(i,j+1); 70 end 71 %sort 72 if(v2<v1) 73 v3=v2; v2=v1; v1=v3; 74 end 75 %This edge a priori has not been processed yet 76 exists = false; 77 %Go through all processed faces connected to v1 and check whether we have seen this edge yet 78 e=head_minv(v1); 79 while(e~=-1) 80 if(edges(e,2)==v2) 81 exists = true; 82 break; 61 83 end 62 %sort 63 if(v2<v1) 64 v3=v2; v2=v1; v1=v3; 65 end 66 %This edge a priori has not been processed yet 67 exists = false; 68 %Go through all processed faces connected to v1 and check whether we have seen this edge yet 69 e=head_minv(v1); 70 while(e~=-1) 71 if(edges(e,2)==v2) 72 exists = true; 73 break; 74 end 75 e=next_face(e); 76 end 77 %If this edge is new, add it to the lists 78 if(~exists) 79 %Update edges 80 edges(nbf+1,1) = v1; 81 edges(nbf+1,2) = v2; 82 %Update chain 83 next_face(nbf+1) = head_minv(v1); 84 head_minv(v1) = nbf+1; 85 %Increase number of faces 86 nbf=nbf+1; 87 end 84 e=next_face(e); 85 end 86 %If this edge is new, add it to the lists 87 if(~exists) 88 %Update edges 89 edges(nbf+1,1) = v1; %vertex 1 90 edges(nbf+1,2) = v2; %vertex 2 91 edges(nbf+1,3) = i; %element 1 (ignore second one) 92 if(v1~=md.mesh.elements(i,j)) exchange(nbf+1)=1; end 93 %Update chain 94 next_face(nbf+1) = head_minv(v1); 95 head_minv(v1) = nbf+1; 96 %Increase number of faces 97 nbf=nbf+1; 88 98 end 89 99 end 90 edges = edges(1:nbf,:);91 toc92 100 end 93 101 102 edges = edges(1:nbf,:); 103 pos = find(exchange); 104 v3 = edges(pos,1); 105 edges(pos,1) = edges(pos,2); 106 edges(pos,2) = v3; 107 toc 108 % }}} 109 94 110 %Change edges formatting so that plot looks ok 95 edges = [edges(:,1:2) edges(:,1)]';111 myedges = [edges(:,1:2) edges(:,1)]'; 96 112 97 113 %Loop over all levels and plot 98 114 for i=1:numcolors 99 115 pos=find(colorind==i); 100 hprime=plot(md.mesh.x(edges(:,pos)),md.mesh.y(edges(:,pos)),... 101 '-','Color',palette(i,:),'LineWidth',2); 116 hprime=plot(md.mesh.x(myedges(:,pos)),md.mesh.y(myedges(:,pos)),'-','Color',palette(i,:),'LineWidth',2); 102 117 if i==1; hold on; end 118 119 if isquiver 120 x1 = md.mesh.x(edges(pos,1)); x2 = md.mesh.x(edges(pos,2)); 121 y1 = md.mesh.y(edges(pos,1)); y2 = md.mesh.y(edges(pos,2)); 122 len = sqrt( (x2-x1).^2 + (y2-y1).^2); 123 124 xq = mean([x1 x2],2); 125 yq = mean([y1 y2],2); 126 tx = sign(channelarea(pos)).*(x2-x1)./len .* len/10; 127 ty = sign(channelarea(pos)).*(y2-y1)./len .* len/10; 128 px = -ty; 129 py = tx; 130 131 %hprime=quiver(xq,yq,tx,ty,'color',palette(i,:),'showarrowhead','on','autoscale','off'); 132 num = length(pos); 133 patch('Faces',reshape(1:3*num,num,3),'Vertices',[[xq;xq+(-tx+px);xq+(-tx-px)],[yq;yq+(-ty+py);yq+(-ty-py)]],'FaceColor',palette(i,:),'EdgeColor','none'); 134 end 103 135 end 104 hold off
Note:
See TracChangeset
for help on using the changeset viewer.