1 |
function [FLD]=diffsmooth2D(fld,dxCsm,dyCsm); |
function [FLD]=diffsmooth2D(fld,dxCsm,dyCsm); |
2 |
|
%object: diffusive smoother (after Weaver and Courtier 2001) |
|
%object: implementation (gforget@mit.edu) of a diffusive smoother (Weaver and Courtier 2001) |
|
3 |
% |
% |
4 |
%input: fld field to be smoothed (masked with NaN) |
%input: fld field to be smoothed (masked with NaN) |
5 |
% dxCsm,dyCsm scale in first/second direction |
% dxCsm,dyCsm scale in first/second grid direction |
6 |
%output:FLD smoothed field |
%output:FLD smoothed field |
7 |
% |
% |
8 |
%asumption: dxCsm/dyCsm are assumed to be given at the positions of U/V points |
%asumption: dxCsm/dyCsm are given at U/V points (as DXC/DYC are) |
9 |
|
|
10 |
global mygrid; |
global mygrid; |
11 |
|
|
|
dxC=mygrid.DXC; dyC=mygrid.DYC; |
|
|
dxG=mygrid.DXG; dyG=mygrid.DYG; |
|
|
rA=mygrid.RAC; |
|
|
|
|
12 |
%scale the diffusive operator: |
%scale the diffusive operator: |
13 |
|
dxC=mygrid.DXC; dyC=mygrid.DYC; |
14 |
|
|
15 |
tmp0=dxCsm./dxC; tmp0(isnan(fld))=NaN; tmp00=nanmax(tmp0); |
tmp0=dxCsm./dxC; tmp0(isnan(fld))=NaN; tmp00=nanmax(tmp0); |
16 |
tmp0=dyCsm./dyC; tmp0(isnan(fld))=NaN; tmp00=max([tmp00 nanmax(tmp0)]); |
tmp0=dyCsm./dyC; tmp0(isnan(fld))=NaN; tmp00=max([tmp00 nanmax(tmp0)]); |
17 |
smooth2D_nbt=tmp00; |
nbt=tmp00; |
18 |
smooth2D_nbt=ceil(1.1*2*smooth2D_nbt^2); |
nbt=ceil(1.1*2*nbt^2); |
|
|
|
|
smooth2D_dt=1; |
|
|
smooth2D_T=smooth2D_nbt*smooth2D_dt; |
|
|
smooth2D_Kux=dxCsm.*dxCsm/smooth2D_T/2; |
|
|
smooth2D_Kvy=dyCsm.*dyCsm/smooth2D_T/2; |
|
|
|
|
|
%time-stepping loop: |
|
|
FLD=fld; |
|
|
|
|
|
for it=1:smooth2D_nbt; |
|
|
% if mod(it,ceil(smooth2D_nbt/50))==0; fprintf([num2str(it) '/' num2str(smooth2D_nbt) ' done\n']); end; |
|
|
|
|
|
[dTdxAtU,dTdyAtV]=calc_T_grad(FLD,0); |
|
|
tmpU=dTdxAtU.*smooth2D_Kux; |
|
|
tmpV=dTdyAtV.*smooth2D_Kvy; |
|
|
[fldDIV]=calc_UV_div(tmpU,tmpV,{'dh'}); |
|
|
dFLDdt=smooth2D_dt*fldDIV./rA; |
|
|
FLD=FLD-dFLDdt; |
|
19 |
|
|
20 |
end; |
dt=1; |
21 |
|
T=nbt*dt; |
22 |
|
|
23 |
|
%diffusion operator: |
24 |
|
Kux=dxCsm.*dxCsm/T/2; |
25 |
|
Kvy=dyCsm.*dyCsm/T/2; |
26 |
|
|
27 |
|
%setup problem: |
28 |
|
myOp.dt=1; |
29 |
|
myOp.nbt=nbt; |
30 |
|
myOp.Kux=Kux; |
31 |
|
myOp.Kvy=Kvy; |
32 |
|
|
33 |
|
%time step problem: |
34 |
|
FLD=gcmfaces_timestep(myOp,fld); |