1 function [hzc,icl3]=coarsening_icl(dx,dy,dz,params)
2 % [[hzc,icl3]=coarsening_icldx,dy,dz,params)
4 % dx,dy mesh spacings, scalars
5 % dz vertical element sizes, vector
8 % hzc horizontal coarsening factors in directions 1 and 2
9 % icl3 coarse indices in direction 3
12 error('dz must be a vector')
14 dz = dz(:)'; % make sure dz is a row
15 disp(['coarsening_icl: input dx,dy,dz=',num2str([dx,dy,dz])])
16 dxy=min(dx,dy); % horizontal step
18 % decide on horizontal coarsening factor
19 crit=(dz(1)/dxy)/params.a(3);
20 if crit > params.minaspect
21 hzc=[2,2]; % future proofing if they are different
25 hzcavg=sqrt(hzc(1)*hzc(2));
26 fprintf('horizontal coarsening factor %g %g because weighted height=%g\n',...
28 icl3=zeros(1,n3); % allocate max
29 lcl=1; % last coarse level
33 newlcl=lcl+1; % next coarse level by 1
35 crit = ((dz(lcl)+dz(lcl+1))/(2*dxy*hzcavg/2))/params.a(3);
36 if crit < params.maxaspect
37 newlcl=lcl+2; % next coarse level by 2
43 else % at the top already
50 error('number of coarse layers is 0')
52 disp(['vertical coarse layers ',num2str(icl3)])
55 disp(['heights above terrain ',num2str(hg)])
56 disp(['coarse heights above terrain ',num2str(hgc)])