1 %ifile = 'wrfinput_d01';
2 %si = nc2struct(ifile,{'XLONG','XLAT','HGT','U','V','W','PH','PHB'},{'DX','DY'});
3 %ofile = 'wrfout_d01_2010-07-01_01:00:00';
4 %so = nc2struct(ofile,{'U','V','W'},{});
5 s = load('WRF_20.mat');
7 % transformation matrix from wind at x,y,z coordinates to two constant
15 % intial wind at the faces
16 v0x = (s.u0(1:end-1,:,:)+s.u0(2:end,:,:))/2;
17 v0y = (s.v0(:,1:end-1,:)+s.v0(:,2:end,:))/2;
18 v0z = (s.w0(:,:,1:end-1)+s.w0(:,:,2:end))/2;
19 v0 = T*[v0x(:),v0y(:),v0z(:)]';
21 % final wind at the center from WRF
22 uWx = (s.u(1:end-1,:,:)+s.u(2:end,:,:))/2;
23 uWy = (s.v(:,1:end-1,:)+s.v(:,2:end,:))/2;
24 uWz = (s.w(:,:,1:end-1)+s.w(:,:,2:end))/2;
25 uW = T*[uWx(:),uWy(:),uWz(:)]';
28 gh = (s.ph+s.phb)/9.81;
30 % dimensions and spacings
34 % create meshes from input file
35 xm = repmat(s.xlong,[1,1,n(3)]);
36 ym = repmat(s.xlat,[1,1,n(3)]);
37 zm = (gh(:,:,1:end-1)+gh(:,:,2:end))/2;
39 [xx,yy,~] = ndgrid(h(1)*(0:n(1)),h(2)*(0:n(2)),0:n(3));
40 ghm = (gh(1:end-1,1:end-1,:)+gh(2:end,1:end-1,:)+gh(1:end-1,2:end,:)+gh(2:end,2:end,:))/4;
41 ghm = [ghm(1,:,:);ghm;ghm(end,:,:)];
42 ghm = [ghm(:,1,:),ghm,ghm(:,end,:)];
46 % assembly sparse matrices
47 [A,D,E,B,C,~] = sparse_assembly(X,h);
52 % transform resulting fluxes into cartesian winds at the centers
55 % transform WRF winds at the face to the center
61 mesh(xx(:,:,1),yy(:,:,1),zz(:,:,1))
63 plot_wind_3d(Xm,v0c,'Initial WRF wind',1);
65 mesh(xx(:,:,1),yy(:,:,1),zz(:,:,1))
67 plot_wind_3d(Xm,uWc,'Final WRF wind',1);
69 mesh(xx(:,:,1),yy(:,:,1),zz(:,:,1))
71 plot_wind_3d(Xm,u,'Final mass-consistent wind',1);
73 mesh(xx(:,:,1),yy(:,:,1),zz(:,:,1))
75 plot_wind_3d(Xm,u-uWc,'Mass-consistent vs WRF wind',1);
79 ux = reshape(u(1:3:end),n); uy = reshape(u(2:3:end),n); uz = reshape(u(3:3:end),n);
81 mesh(Xm{1}(:,:,1),Xm{2}(:,:,1),ux(:,:,1)-uWx(:,:,1))
82 xlabel('x'), ylabel('y'), zlabel('z')
83 title('Differences in x direction')
85 mesh(Xm{1}(:,:,1),Xm{2}(:,:,1),uy(:,:,1)-uWy(:,:,1))
86 xlabel('x'), ylabel('y'), zlabel('z')
87 title('Differences in y direction')
89 mesh(Xm{1}(:,:,1),Xm{2}(:,:,1),uz(:,:,1)-uWz(:,:,1))
90 xlabel('x'), ylabel('y'), zlabel('z')
91 title('Differences in z direction')
94 max_diff = max(max(max(u-uWc)))
96 % save previous results
107 % transform resulting fluxes into cartesian winds at the centers
112 mesh(xx(:,:,1),yy(:,:,1),zz(:,:,1))
114 plot_wind_3d(Xm,u,'Final mass-consistent wind new initial',1);
116 mesh(xx(:,:,1),yy(:,:,1),zz(:,:,1))
118 plot_wind_3d(Xm,u-uWc,'Mass-consistent new initial vs WRF wind',1);
119 max_diff_new = max(max(max(u-uWc)))
121 mesh(xx(:,:,1),yy(:,:,1),zz(:,:,1))
123 plot_wind_3d(Xm,up-u,'Mass-consistent vs Mass-consistent new initial',1);
124 max_diff_mcs = max(max(max(up-u)))
127 plot_conditions(n,B*v0p,C,D,'WRF input')
128 plot_conditions(n,B*uW,C,D,'WRF final')
129 plot_conditions(n,vp,C,D,'Mass-consistent')
130 plot_conditions(n,v,C,D,'Mass-consistent new input')