/[MITgcm]/MITgcm_contrib/gael/matlab_class/gcmfaces_calc/calc_barostream.m
ViewVC logotype

Annotation of /MITgcm_contrib/gael/matlab_class/gcmfaces_calc/calc_barostream.m

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.6 - (hide annotations) (download)
Sat Aug 27 20:44:47 2011 UTC (13 years, 11 months ago) by gforget
Branch: MAIN
Changes since 1.5: +2 -2 lines
- remove hfac factor in scaling vector field to transports.
  (to be done outside of the transport routine)

1 gforget 1.3 function [fldBAR]=calc_barostream(fldU,fldV,varargin);
2 gforget 1.5 %object: compute barotropic streamfunction
3     %inputs: fldU and fldV are the fields of grid point transport
4     %optional: doRemoveDivergentPart; if 1 (default) then remove the
5     % divergent part of the flow field first. If 0 then dont.
6     %output: FLD is the streamfunction
7 gforget 1.1
8     %by assumption: grid_load is done
9     global mygrid;
10    
11 gforget 1.2 %0) prepare fldU/fldV (transport fields):
12 gforget 1.1 n3=max(size(fldU.f1,3),1); n4=max(size(fldV.f1,4),1);
13    
14     fldU(isnan(fldU))=0; fldV(isnan(fldV))=0;
15    
16     dxg=mk3D(mygrid.DXG,fldU); dyg=mk3D(mygrid.DYG,fldU); drf=mk3D(mygrid.DRF,fldU);
17     for k4=1:n4;
18 gforget 1.6 fldU(:,:,:,k4)=fldU(:,:,:,k4).*dyg.*drf*1e-6;
19     fldV(:,:,:,k4)=fldV(:,:,:,k4).*dxg.*drf*1e-6;
20 gforget 1.1 end;
21    
22 gforget 1.3 %apply mask:
23     fldU=sum(fldU,3).*mygrid.mskW(:,:,1);
24     fldV=sum(fldV,3).*mygrid.mskS(:,:,1);
25     %take out thedivergent part of the flow:
26     if nargin==3; doRemoveDivergentPart=varargin{1}; else; doRemoveDivergentPart=1; end;
27     if doRemoveDivergentPart;
28     [fldUdiv,fldVdiv,fldDivPot]=diffsmooth2D_div_inv(fldU,fldV);
29     fldU=fldU-fldUdiv; fldV=fldV-fldVdiv;
30     end;
31 gforget 1.1
32 gforget 1.2 %1) compute streamfunction face by face:
33     [fldU,fldV]=exch_UV(fldU,fldV); fldU(isnan(fldU))=0; fldV(isnan(fldV))=0;
34     tmp1=cumsum(fldV,1); for iF=1:fldU.nFaces; tmp2=tmp1{iF}; tmp1{iF}=[zeros(1,size(tmp2,2));tmp2]; end;
35     tmp2=diff(tmp1,1,2)+fldU; tmp3=cumsum(mean(tmp2,1));
36 gforget 1.3 %to check divergence implied errors:
37     %figure; for iF=1:fldU.nFaces; subplot(3,2,iF); plot(std(tmp2{iF},0,1)); end;
38 gforget 1.2 for iF=1:fldU.nFaces; tmp2=tmp1{iF}; tmp1{iF}=tmp2-ones(size(tmp2,1),1)*[0 tmp3{iF}]; end;
39     bf_step1=tmp1;
40    
41 gforget 1.3 if fldU.nFaces==1;
42 gforget 1.4 bf_step2=bf_step1;
43 gforget 1.3 else;
44 gforget 1.2 %2) match edges:
45     %... set face number field
46     TMP1=tmp1; for iF=1:TMP1.nFaces; TMP1{iF}(:)=iF; end;
47     TMP2=exch_T_N(TMP1);%!!! this is a trick, since TMP1 is (n+1 X n+1) and loc. at vorticity points
48     tmp1=bf_step1;
49     for iF=1:fldU.nFaces-1;
50     tmp2=exch_T_N(tmp1);%!!! same trick
51     tmp3=tmp2{iF+1}; tmp3(3:end-2,3:end-2)=NaN;%mask out interior points
52     TMP3=TMP2{iF+1}; tmp3(find(TMP3>iF+1))=NaN;%mask out edges points coming from unadjusted faces
53     tmp3(:,1)=tmp3(:,1)-tmp3(:,2); tmp3(:,end)=tmp3(:,end)-tmp3(:,end-1);%compare edge points
54     tmp3(1,:)=tmp3(1,:)-tmp3(2,:); tmp3(end,:)=tmp3(end,:)-tmp3(end-1,:);%compare edge points
55     tmp3(2:end-1,2:end-1)=NaN;%mask out remaining interior points
56     tmp1{iF+1}=tmp1{iF+1}+nanmedian(tmp3(:));%adjust the face data
57 gforget 1.1 end;
58 gforget 1.2 bf_step2=tmp1;
59 gforget 1.4 end;
60 gforget 1.2 %3) put streamfunction at cell center
61     tmp1=bf_step2;
62     tmp2=tmp1; for iF=1:tmp1.nFaces; tmp3=tmp2{iF}; tmp3=(tmp3(:,1:end-1)+tmp3(:,2:end))/2;
63     tmp3=(tmp3(1:end-1,:)+tmp3(2:end,:))/2; tmp2{iF}=tmp3; end;
64     bf_step3=tmp2;
65     %4) set 0 on land on average:
66     tmp1=convert2array(bf_step3);
67     tmp2=convert2array(mygrid.mskC(:,:,1)); tmp2=find(isnan(tmp2)&~isnan(tmp1));
68     tmp2=median(tmp1(tmp2)); if isnan(tmp2); tmp2=nanmedian(tmp1(:)); end;
69     bf_step4=(bf_step3-tmp2).*mygrid.mskC(:,:,1);
70 gforget 1.1
71 gforget 1.2 %5) return the result:
72     fldBAR=bf_step4;
73 gforget 1.1

  ViewVC Help
Powered by ViewVC 1.1.22