1 |
function qlev=horzslicefem(zgrid,q,zlev) |
---|
2 |
%HORZSLICEFEM slice a FEM domain horizontally |
---|
3 |
% HORZSLICEFEM slices a 3-D FEM domain specified in zgrid |
---|
4 |
% horizontally at vertical position zlev, mapping the |
---|
5 |
% data in q to that level. |
---|
6 |
% |
---|
7 |
% Inputs (all three arguments REQUIRED): |
---|
8 |
% zgrid - vertical position of FEM domain, in [nn x nnv] shape |
---|
9 |
% q - [nn x nnv] scalar field, in [nn x nnv] shape |
---|
10 |
% or a 3-d array of several variables to slice, |
---|
11 |
% [nn x nnv x nqs], where nqs is the number of scalars |
---|
12 |
% to slice |
---|
13 |
% zlev - the vertical level at which to make slice |
---|
14 |
% |
---|
15 |
% Output: |
---|
16 |
% qlev - quantity q mapped to zlev |
---|
17 |
% |
---|
18 |
% ALTERNATIVE: (not yet available) |
---|
19 |
% Input (Both arguments REQUIRED): |
---|
20 |
% fem_icq4_struct - structure containing .icq4 variables |
---|
21 |
% zlev - the vertical level at which to make slice |
---|
22 |
% |
---|
23 |
% Output: |
---|
24 |
% qlev - all 3-D .icq4 field variables mapped to zlev. |
---|
25 |
% in the following order: |
---|
26 |
% UZMID,VZMID,WZMID,Q2MID,Q2LMID,TMPMID,SALMID |
---|
27 |
% |
---|
28 |
% Call as: >> qlev=horzslicefem(zgrid,q,zlev) |
---|
29 |
% OR: >> qlev=horzslicefem(fem_icq4_struct,zlev) |
---|
30 |
% |
---|
31 |
% |
---|
32 |
% Written by: Brian O. Blanton |
---|
33 |
% December 1998 |
---|
34 |
|
---|
35 |
nargchk(2,3,nargin); |
---|
36 |
|
---|
37 |
if isstruct(zgrid) |
---|
38 |
error('fem_icq4_struct input to HORZSLICEFEM not yet supported') |
---|
39 |
end |
---|
40 |
|
---|
41 |
[nn,nnv]=size(zgrid); |
---|
42 |
[n,m,nq]=size(q); |
---|
43 |
if n~=nn | nnv~=m |
---|
44 |
error('Size mismatch between zgrid and q in HORZSLICEFEM.') |
---|
45 |
end |
---|
46 |
|
---|
47 |
% yank zgrid,q around a bit; now it's nnv X nn, top down |
---|
48 |
zgrid=flipud(zgrid'); |
---|
49 |
% |
---|
50 |
|
---|
51 |
%q2=flipdim(permute(q,[2 1 3]),1); |
---|
52 |
|
---|
53 |
if nq==1 |
---|
54 |
q2=flipud(q'); |
---|
55 |
else % transpose and flipud each scalar component |
---|
56 |
q2=ones(m,n,nq); |
---|
57 |
for i=1:nq |
---|
58 |
q2(:,:,i)=flipud(q(:,:,i)'); |
---|
59 |
end |
---|
60 |
end |
---|
61 |
|
---|
62 |
% ilower is the vertical level immediately below the |
---|
63 |
% vertical position zlev for each horizontal node iok |
---|
64 |
|
---|
65 |
ilower=zgrid<zlev; |
---|
66 |
|
---|
67 |
% find which nodes can bound zlev by surface and bottom |
---|
68 |
% heights; inotok are the node numbers with zlev deeper than, |
---|
69 |
% or above, the water column; iok are the nude numbers entirely |
---|
70 |
% within the water column. |
---|
71 |
inotok=find(sum(ilower)==0); |
---|
72 |
iok=find(sum(ilower)>0); |
---|
73 |
nok=length(iok); |
---|
74 |
|
---|
75 |
% remove the "water columns" that do not bound zlev |
---|
76 |
ilower(:,inotok)=[]; |
---|
77 |
|
---|
78 |
% Determine which indices in zgrid represent the bounding |
---|
79 |
% vertical levels |
---|
80 |
[i,j]=find(ilower==1); |
---|
81 |
idx=[1 find(diff(j')==1)+1]; |
---|
82 |
ilower=i(idx); |
---|
83 |
iupper=ilower-1; |
---|
84 |
|
---|
85 |
% then convert them to vector access, whereby zgrid is essentially |
---|
86 |
% treated as a 1x(nn*nnv) vector |
---|
87 |
ilower=(0:length(iok)-1)*nnv+ilower'; |
---|
88 |
iupper=(0:length(iok)-1)*nnv+iupper'; |
---|
89 |
zt=zgrid(:,iok); |
---|
90 |
qt=q2(:,iok,:); |
---|
91 |
|
---|
92 |
% extract the bounding depths for each node in iok |
---|
93 |
zup=zt(iupper); |
---|
94 |
zdown=zt(ilower); |
---|
95 |
|
---|
96 |
% extract scalars similarly |
---|
97 |
if nq==1 |
---|
98 |
qup=qt(iupper); |
---|
99 |
qdown=qt(ilower); |
---|
100 |
else |
---|
101 |
qup=ones(nok,nq); |
---|
102 |
qdown=ones(nok,nq); |
---|
103 |
for i=1:nq |
---|
104 |
temp=qt(:,:,i); |
---|
105 |
qup(:,i)=temp(iupper'); |
---|
106 |
qdown(:,i)=temp(ilower'); |
---|
107 |
end |
---|
108 |
end |
---|
109 |
|
---|
110 |
% compute differential heights and 1-D linear basis functions |
---|
111 |
zdiff=zup-zdown; |
---|
112 |
b1=(zup-zlev)./zdiff; |
---|
113 |
b2=(zlev-zdown)./zdiff; |
---|
114 |
|
---|
115 |
% Interpolate scalars to zlev. |
---|
116 |
if nq==1 |
---|
117 |
qlev=NaN*ones(nn,nq); |
---|
118 |
qlev(iok)=qdown.*b1+qup.*b2; |
---|
119 |
else |
---|
120 |
qlev=NaN*ones(nn,nq); |
---|
121 |
for i=1:nq |
---|
122 |
qlev(iok,i)=qdown(:,i).*b1'+qup(:,i).*b2'; |
---|
123 |
end |
---|
124 |
end |
---|
125 |
|
---|
126 |
|
---|
127 |
|
---|
128 |
% IMPROVEMENTS: The only looping is over the number of scalars |
---|
129 |
% input, nq; this can and will be removes in the future. |
---|
130 |
% Also, zlev should be allowed to be a vector of vertical |
---|
131 |
% levels at which to slice. |
---|