File size: 5,762 Bytes
7c3bfa9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
function[]=tlwplot(Lupper,Llower,U,H,a,ho,xdom,zdom,mink,maxk);
%-------------------------------------------------------------
% Matlab Subroutine tlwplot.M					
% Called from tlwmenu.M--interactive menu system.		
%									
% By Robert Hart for Meteo 574 / Fall 1995			
% Penn State University Meteorology
% Updated 1 March 2018 to increase npts given faster cpus
%									
% Program which analyzes and simulates the flow over			
% an isolated mountain in the presence of a two-			
% layer atmosphere.							
%									
% Parameters received from menu:					
%-------------------------------					
% Lupper - Scorer parameter of upper layer				
% Llower - Scorer parameter of lower layer				
% U      - Surface wind speed (in m/s)					
% H      - Height above ground of 2-layer interface (in m)		
% a      - Half-width of mountain (in m)				
% ho     - maximum height of mountain					
% xdom   - Horizontal extent of domain (m)				
% zdom   - Vertical extent of domain (m)				
% mink   - Minimum wavenumber in Fourier analysis of flow		
% maxk   - Maximum wavenumber in Fourier analysis of flow		
%									
%--------------------------------------------------------------

npts=100;                            % # cells in each direction
dk=0.367/a;                          % wavenumber interval size 
                                     %   (smaller the better, but
                                     %   need to watch calc. time!)  
nk=(maxk-mink)/dk;                   % # loops for wave# integration                   

minx=-.25*xdom;                      % leftmost limit of domain
maxx=.75*xdom;                       % rightmost limit of domain
minz=0;                              % lower limit of domain
maxz=zdom;                           % upper limit of domain

matrix1=zeros(npts+1,npts+1);        % temp matrix used in integration
matrix2=zeros(npts+1,npts+1);        % temp matrix used in integration
matrix3=zeros(npts+1,npts+1);        % sum matrix used in integration

dx=(maxx-minx)/npts;                 % grid cell size in horizontal
dz=(maxz-minz)/npts;                 % grid cell size in vertical

x=[minx:dx:maxx];                    % array of x gridpoints
z=[minz:dz:maxz];                    % array of z gridpoints
k=[mink:dk:maxk];                    % array of wavenumbers
           
                                     % mesh arrays into 2-d matrix
[x,z]=meshgrid(minx:dx:maxx,minz:dz:maxz); 

ht=0;                          	    % initialize weighting for transform
for kloop=1:nk;                      % wavenumber loop
  kk=k(kloop);                       %    horiz wavenumber
  m=sqrt(Llower*Llower-kk*kk);       %    vert wave# in lower layer
  n=sqrt(kk*kk-Lupper*Lupper);       %    vert wave# in upper layer
  if (m+i*n==0)                      %    check for divide by zero
    r=9e99;                           
  else 
    r=(m-i*n)/(m+i*n);               %    reflection coefficient
  end; 
  R=r*exp(2*i*m*H);                  %    reflection calculation
  A=(1+r)*exp(H*n+i*H*m)/(1+R);      %    calculate coefficients
  C=1/(1+R);                         
  D=R.*C;
  hs=pi*a*ho*exp(-a*abs(kk));        %    kk-component of Fourier trans.
  ht=ht+pi*dk*a*exp(-a*abs(kk));     %    sum Fourier weighting. if
                                     %    integrating over 0<k<oo
                                     %    ht will end up as pi.
                                     %    hence, ht represents the 
                                     %    fraction, in radians, of
                                     %    the spectral interval considered. 
                                            
  aboveH=A*exp(-z.*n).*(z>H);        %    calculate w in each layer         
  belowH=(C*exp(i*z.*m)+D*exp(-i*z.*m)).*(z<=H);
  
                                     %    combine layers, and multiply by
                                     %    transform of kk-component of topo.   
  matrix2=((-i*kk*hs*U*(aboveH+belowH)).*exp(-i*x.*kk));
   
  if kloop > 1                       %    trapezoidal integration/summation
    matrix3=matrix3+.5*(matrix1+matrix2).*dk;
  end;
 
  matrix1=matrix2;                   %    current w matrix becomes previous
end;                                 % end of integration loop.

w=real(matrix3./ht);                 % only interested in real comp. 
                                     
figure;                              % create new figure window                     
axis([minx maxx minz maxz]);         % define axes
grid;                                % graw grid
xlabel('X (m)');                     % X-axis title
ylabel('Height (m)');                % Z-axis title
title(['Streamline Analysis']);      % figure title
stream(x,z,U,w,10);                  % perform streamline analysis
Hline=H*ones(1,npts+1);              % create interface line        
plot(x(1,:),Hline,'m--');            % draw interface line in magenta!

figure;                              % create new figure window                                                      
colormap(jet);                       % set colormap (red=high;blue=low)
axis([minx maxx minz maxz]);         % define axes
xlabel('X (m)');                     % X-axis title
ylabel('Height (m)');                % Z-axis title
title(['Vertical Velocity (m/s)']);  % figure title
hold on;                             % hold current figure
plot(x(1,:),Hline,'m--');            % draw interface line
caxis([-10 10]);                     % define color contouring extrema
surface(x,z,w);                      % 2-d surface contour plot
shading interp;                      % interpolate between gridpoints
colorbar;                            % add contour legend
hold off;                            % remove hold on figure