Changeset 22502
- Timestamp:
- 03/06/18 14:46:56 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/mesh/squaremesh.m
r17558 r22502 1 function md=squaremesh(md,Lx,Ly,nx,ny )1 function md=squaremesh(md,Lx,Ly,nx,ny,computeconnectivity) 2 2 %SQUAREMESH - create a structured square mesh 3 3 % … … 10 10 % [md]=squaremesh(md,Lx,Ly,nx,ny) 11 11 12 %process options 13 if nargin == 5, 14 computeconnectivity = 1; 15 end 16 12 17 %get number of elements and number of nodes 13 18 nel=(nx-1)*(ny-1)*2; 14 19 nods=nx*ny; 15 20 16 %initialization 17 index=zeros(nel,3); 18 x=zeros(nx*ny,1); 19 y=zeros(nx*ny,1); 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); 20 27 21 %create coordinates 22 for n=1:nx, 23 for m=1:ny, 24 x((n-1)*ny+m)=(n-1.); 25 y((n-1)*ny+m)=(m-1.); 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 26 34 end 35 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; 27 77 end 28 78 29 %create index30 for n=1:(nx-1)31 for m=1:(ny-1),32 A=(n-1)*ny+m;33 B=A+1;34 C=n*ny+m;35 D=C+1;36 index((n-1)*(ny-1)*2+2*(m-1)+1,:)=[A C B];37 index((n-1)*(ny-1)*2+2*m,:)=[B C D];38 end39 end40 41 %Scale x and y42 x=x/max(x)*Lx;43 y=y/max(y)*Ly;44 79 45 80 %create segments … … 67 102 68 103 %Now, build the connectivity tables for this mesh. 69 md.mesh.vertexconnectivity=NodeConnectivity(md.mesh.elements,md.mesh.numberofvertices); 70 md.mesh.elementconnectivity=ElementConnectivity(md.mesh.elements,md.mesh.vertexconnectivity); 104 if computeconnectivity, 105 md.mesh.vertexconnectivity=NodeConnectivity(md.mesh.elements,md.mesh.numberofvertices); 106 md.mesh.elementconnectivity=ElementConnectivity(md.mesh.elements,md.mesh.vertexconnectivity); 107 end
Note:
See TracChangeset
for help on using the changeset viewer.