1 function s=cell_sizes(X)
3 % compute averaged sizes and areas projected on cartesian planes of cells in a deformed
4 % and vertical stretched mesh
7 % X cell array, nodal coordinatees x y z
9 % s structure contains arrays
10 % same shape as u, v, w:
11 % dz_at_u averaged increment in z on u-sides etc
13 % area_u area of u-side
23 % same shape as x,y,z:
24 % depth_x increment in x from x side to next
30 x = X{1}; y = X{2}; z = X{3};
31 [nx1,ny1,nz1] = size(x);
32 nx = nx1-1; ny = ny1-1; nz = nz1-1;
36 % (i,j+1,k+1)---------(i+1,j+1,k+1 |
40 %(i,j,k+1)----------(i+1,j,k+1) | /
41 % | /| | | |--------> x,u,i
45 % | (i,j+1,k)---------(i+1,j+1,k)
49 %(i,j,k)----------(i+1,j,k)
51 % cell dimensions - distances between midpoints
52 s.dz_at_u = zeros(nx+1,ny,nz); % dz for u etc.
53 s.dy_at_u = zeros(nx+1,ny,nz); % dz for u etc.
54 s.area_u = zeros(nx+1,ny,nz); % dz for u etc.
58 s.dz_at_u(i,j,k) = 0.5*(z(i,j,k+1)-z(i,j,k)+z(i,j+1,k+1)-z(i,j+1,k));
59 s.dy_at_u(i,j,k) = 0.5*(y(i,j+1,k)-y(i,j,k)+y(i,j+1,k+1)-y(i,j,k+1));
60 s.area_u (i,j,k) = s.dy_at_u(i,j,k)*s.dz_at_u(i,j,k);
66 s.dz_at_v = zeros(nx,ny+1,nz);
67 s.dx_at_v = zeros(nx,ny+1,nz);
68 s.area_v = zeros(nx,ny+1,nz);
72 s.dz_at_v(i,j,k) = 0.5*(z(i,j,k+1)-z(i,j,k)+z(i+1,j,k+1)-z(i+1,j,k));
73 s.dx_at_v(i,j,k) = 0.5*(x(i+1,j,k)-x(i,j,k)+x(i+1,j,k+1)-x(i,j,k+1));
74 s.area_v(i,j,k)=s.dx_at_v(i,j,k)*s.dz_at_v(i,j,k);
79 s.dx_at_w = zeros(nx,ny,nz+1);
80 s.dy_at_w = zeros(nx,ny,nz+1);
81 s.area_w = zeros(nx,ny,nz+1);
85 s.dx_at_w(i,j,k) = 0.5*(x(i+1,j,k)-x(i,j,k)+x(i+1,j,k)-x(i,j+1,k));
86 s.dy_at_w(i,j,k) = 0.5*(y(i,j+1,k)-y(i,j,k)+y(i+1,j+1,k)-y(i+1,j,k));
87 s.area_w(i,j,k) = s.dx_at_w(i,j,k) * s.dy_at_w(i,j,k);
92 % averaged depth of cells in the 3 directions
93 s.depth_x=zeros(nx,ny,nz);
94 s.depth_y=zeros(nx,ny,nz);
95 s.depth_z=zeros(nx,ny,nz);
101 s.depth_x(i,j,k)=s.depth_x(i,j,k)+0.25*(x(i+1,j+l1,k+l2)-x(i,j+l1,k+l2));
102 s.depth_y(i,j,k)=s.depth_y(i,j,k)+0.25*(y(i+l1,j+1,k+l2)-y(i+l1,j,k+l2));
103 s.depth_z(i,j,k)=s.depth_z(i,j,k)+0.25*(z(i+l1,j+l2,k+1)-z(i+l1,j+l2,k));
110 s.weight_u=zeros(nx+1,ny,nz);
111 s.weight_v=zeros(nx,ny+1,nz);
112 s.weight_w=zeros(nx,ny,nz+1);
116 s.weight_u(i,j,k)=0.5*s.depth_x(i,j,k)*(s.area_u(i+1,j,k)+s.area_u(i,j,k));
119 s.weight_u(i,j,k)=s.depth_x(i-1,j,k)*s.area_u(i,j,k);
125 s.weight_v(i,j,k)=0.5*s.depth_y(i,j,k)*(s.area_v(i,j+1,k)+s.area_v(i,j,k));
128 s.weight_v(i,j,k)=s.depth_y(i,j-1,k)*s.area_v(i,j,k);
134 s.weight_w(i,j,k)=0.5*s.depth_z(i,j,k)*(s.area_w(i,j,k+1)+s.area_w(i,j,k));
137 s.weight_w(i,j,k)=s.depth_z(i,j,k-1)*s.area_w(i,j,k);