Changeset 28136
- Timestamp:
- 03/08/24 06:15:26 (13 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/mesh/squaremesh.m
r22502 r28136 1 function md=squaremesh(md,Lx,Ly,nx,ny,computeconnectivity )1 function md=squaremesh(md,Lx,Ly,nx,ny,computeconnectivity,orientation) 2 2 %SQUAREMESH - create a structured square mesh 3 3 % … … 11 11 12 12 %process options 13 if nargin == 5 ,13 if nargin == 5 14 14 computeconnectivity = 1; 15 orientation = 1; 16 elseif nargin==6 17 orientation = 1; 15 18 end 16 19 … … 19 22 nods=nx*ny; 20 23 21 %Old method 22 if 0, 23 %initialization 24 index=zeros(nel,3); 25 x=zeros(nx*ny,1); 26 y=zeros(nx*ny,1); 24 %prepare coordinates of vertices 25 x = repmat(linspace(0,Lx,nx),[ny 1]); 26 x = reshape(x,[nx*ny 1]); 27 y = repmat(linspace(0,Ly,ny)',[1 nx]); 28 y = reshape(y,[nx*ny 1]); 27 29 28 %create coordinates 29 for n=1:nx, 30 for m=1:ny, 31 x((n-1)*ny+m)=(n-1.); 32 y((n-1)*ny+m)=(m-1.); 33 end 34 end 30 %do first column of elements first 31 nels1 = 2*(ny-1); 32 index = ones(nels1,3); 33 %First column 34 index(2:2:nels1,1) = 2:ny; 35 index(3:2:nels1,1) = 2:ny-1; 36 %2d column 37 index(1:2:nels1,2) = ny+1:2*ny-1; 38 index(2:2:nels1,2) = ny+1:2*ny-1; 39 %3rd column 40 index(1:2:nels1,3) = 2:ny; 41 index(2:2:nels1,3) = ny+2:2*ny; 35 42 36 %create index 37 for n=1:(nx-1) 38 for m=1:(ny-1), 39 A=(n-1)*ny+m; 40 B=A+1; 41 C=n*ny+m; 42 D=C+1; 43 index((n-1)*(ny-1)*2+2*(m-1)+1,:)=[A C B]; 44 index((n-1)*(ny-1)*2+2*m,:)=[B C D]; 45 end 46 end 47 48 %Scale x and y 49 x=x/max(x)*Lx; 50 y=y/max(y)*Ly; 51 else 52 %New method (faster!) 53 x = repmat(linspace(0,Lx,nx),[ny 1]); 54 x = reshape(x,[nx*ny 1]); 55 y = repmat(linspace(0,Ly,ny)',[1 nx]); 56 y = reshape(y,[nx*ny 1]); 57 58 %do first column of elements first 59 nels1 = 2*(ny-1); 60 index = ones(nels1,3); 61 %First column 62 index(2:2:nels1,1) = 2:ny; 63 index(3:2:nels1,1) = 2:ny-1; 64 %2d column 65 index(1:2:nels1,2) = ny+1:2*ny-1; 66 index(2:2:nels1,2) = ny+1:2*ny-1; 67 %3rd column 68 index(1:2:nels1,3) = 2:ny; 69 index(2:2:nels1,3) = ny+2:2*ny; 70 71 %Now copy column and offset with ny, nx times 72 index = repmat(index,[nx-1 1]); 73 offset = repmat([0:ny:(nx-2)*ny],[nels1 1]); 74 offset = reshape(offset,[(nx-1)*nels1,1]); 75 offset = repmat(offset,[1,3]); 76 index = index + offset; 77 end 78 43 %Now copy column and offset with ny, nx times 44 index = repmat(index,[nx-1 1]); 45 offset = repmat([0:ny:(nx-2)*ny],[nels1 1]); 46 offset = reshape(offset,[(nx-1)*nels1,1]); 47 offset = repmat(offset,[1,3]); 48 index = index + offset; 79 49 80 50 %create segments … … 88 58 %back edge 89 59 segments(2*(ny-1)+(nx-1)+1:2*(nx-1)+2*(ny-1),:)=[[1:ny:(nx-2)*ny+1]' [ny+1:ny:ny*(nx-1)+1]' [1:2*(ny-1):2*(nx-2)*(ny-1)+1]']; 60 61 %Do we need to change the orientation of the diagonals? 62 if orientation==1 63 %nothing to do 64 elseif orientation==2 65 %switch diagonals 66 indexold = index; 67 index(1:2:end,3) = indexold(2:2:end,3); 68 index(2:2:end,2) = indexold(1:2:end,1); 69 elseif orientation==3 70 %alternate diagonals 71 indexold = index; 72 index(1:4:end,3) = indexold(2:4:end,3); 73 index(2:4:end,2) = indexold(1:4:end,1); 74 else 75 error('not supported'); 76 end 90 77 91 78 %plug coordinates and nodes … … 102 89 103 90 %Now, build the connectivity tables for this mesh. 104 if computeconnectivity ,91 if computeconnectivity 105 92 md.mesh.vertexconnectivity=NodeConnectivity(md.mesh.elements,md.mesh.numberofvertices); 106 93 md.mesh.elementconnectivity=ElementConnectivity(md.mesh.elements,md.mesh.vertexconnectivity);
Note:
See TracChangeset
for help on using the changeset viewer.