-
Notifications
You must be signed in to change notification settings - Fork 1
/
newinterpolateelh.m
70 lines (52 loc) · 3.63 KB
/
newinterpolateelh.m
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
function [lag,grid]=newinterpolateelh(lag,grid,ifc)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Input: lag,grid
% Return: lag,grid
% Flags:
% ifc = 0 if host is known to have correct host elements for current particle positions.
% ifc = 1 if host should be updated (adds computational work particle positions.
% This is always zero because newinterpolateelh is always currently called after interpolatev so the host position is known.
%
% Takes (xpt,ypt) from lag and (hin,ein,dedtin) from grid.
% Obtains a linear interpolation of the provided fields (hin,ein,dedtin) at these points.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Determine element containing point (xp,yp)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if(ifc == 1)
[allfound,lag]=newfindquick(lag,grid);
if(allfound==0)
[lag,grid]=findfull(lag,grid,0);
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Linearly interpolate free surface height and bathymetry
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
array=find(lag.indomain ~=0 & lag.inwater ~=0);
host=lag.host(array);
x0c=lag.xpt(array)-grid.xc(host);
y0c=lag.ypt(array)-grid.yc(host);
n=grid.nv(host,:);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Linear interpolation of bathymetry
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
h0 = grid.aw0(host,1).*grid.hin(n(:,1))+grid.aw0(host,2).*grid.hin(n(:,2))+grid.aw0(host,3).*grid.hin(n(:,3));
hx = grid.awx(host,1).*grid.hin(n(:,1))+grid.awx(host,2).*grid.hin(n(:,2))+grid.awx(host,3).*grid.hin(n(:,3));
hy = grid.awy(host,1).*grid.hin(n(:,1))+grid.awy(host,2).*grid.hin(n(:,2))+grid.awy(host,3).*grid.hin(n(:,3));
lag.hp(array) = h0 + hx.*x0c + hy.*y0c;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Linear interpolation of free surface height
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
e0 = grid.aw0(host,1).*grid.ein(n(:,1))+grid.aw0(host,2).*grid.ein(n(:,2))+grid.aw0(host,3).*grid.ein(n(:,3));
ex = grid.awx(host,1).*grid.ein(n(:,1))+grid.awx(host,2).*grid.ein(n(:,2))+grid.awx(host,3).*grid.ein(n(:,3));
ey = grid.awy(host,1).*grid.ein(n(:,1))+grid.awy(host,2).*grid.ein(n(:,2))+grid.awy(host,3).*grid.ein(n(:,3));
lag.ep(array) = e0 + ex.*x0c + ey.*y0c;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Linear interpolation of time derivative of free surface height
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
e0 = grid.aw0(host,1).*grid.dedtin(n(:,1))+grid.aw0(host,2).*grid.dedtin(n(:,2))+grid.aw0(host,3).*grid.dedtin(n(:,3));
ex = grid.awx(host,1).*grid.dedtin(n(:,1))+grid.awx(host,2).*grid.dedtin(n(:,2))+grid.awx(host,3).*grid.dedtin(n(:,3));
ey = grid.awy(host,1).*grid.dedtin(n(:,1))+grid.awy(host,2).*grid.dedtin(n(:,2))+grid.awy(host,3).*grid.dedtin(n(:,3));
lag.dedtp(array) = e0 + ex.*x0c + ey.*y0c;
end