Changeset 28136


Ignore:
Timestamp:
03/08/24 06:15:26 (13 months ago)
Author:
Mathieu Morlighem
Message:

CHG: allow to swap edges

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)
     1function md=squaremesh(md,Lx,Ly,nx,ny,computeconnectivity,orientation)
    22%SQUAREMESH - create a structured square mesh
    33%
     
    1111
    1212%process options
    13 if nargin == 5,
     13if nargin == 5
    1414        computeconnectivity = 1;
     15        orientation = 1;
     16elseif nargin==6
     17        orientation = 1;
    1518end
    1619
     
    1922nods=nx*ny;
    2023
    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
     25x = repmat(linspace(0,Lx,nx),[ny 1]);
     26x = reshape(x,[nx*ny 1]);
     27y = repmat(linspace(0,Ly,ny)',[1 nx]);
     28y = reshape(y,[nx*ny 1]);
    2729
    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
     31nels1 = 2*(ny-1);
     32index = ones(nels1,3);
     33%First column
     34index(2:2:nels1,1) = 2:ny;
     35index(3:2:nels1,1) = 2:ny-1;
     36%2d column
     37index(1:2:nels1,2) = ny+1:2*ny-1;
     38index(2:2:nels1,2) = ny+1:2*ny-1;
     39%3rd column
     40index(1:2:nels1,3) = 2:ny;
     41index(2:2:nels1,3) = ny+2:2*ny;
    3542
    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
     44index = repmat(index,[nx-1 1]);
     45offset = repmat([0:ny:(nx-2)*ny],[nels1 1]);
     46offset = reshape(offset,[(nx-1)*nels1,1]);
     47offset = repmat(offset,[1,3]);
     48index = index + offset;
    7949
    8050%create segments
     
    8858%back edge
    8959segments(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?
     62if orientation==1
     63        %nothing to do
     64elseif 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);
     69elseif 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);
     74else
     75        error('not supported');
     76end
    9077
    9178%plug coordinates and nodes
     
    10289
    10390%Now, build the connectivity tables for this mesh.
    104 if computeconnectivity,
     91if computeconnectivity
    10592        md.mesh.vertexconnectivity=NodeConnectivity(md.mesh.elements,md.mesh.numberofvertices);
    10693        md.mesh.elementconnectivity=ElementConnectivity(md.mesh.elements,md.mesh.vertexconnectivity);
Note: See TracChangeset for help on using the changeset viewer.