-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathopenMA_modes_interp.m
136 lines (119 loc) · 4.7 KB
/
openMA_modes_interp.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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
function [ux,uy] = openMA_modes_interp( cc, nm, dm, bm )
% OPENMA_MODES_INTERP - interpolates modes at a specific set of points
% and returns either the modes themselves or the velocities at those
% points.
%
% Usage: u = openMA_modes_interp( cc, vfm, dfm, bm )
% [ux,uy] = openMA_modes_interp( cc, vfm, dfm, bm )
%
% The first form returns the modes themselves at the coordinates in cc,
% which should be a two column matrix of x and y coordinates in the same
% units as the triangular grids of the modes themselves.
%
% The second form returns the velocities of the modes at the coordinates.
%
% NOTE that the number of output arguments is very important to the result.
%
% vfm, dfm, and bm are the vorticity-free modes (formerly known as the
% Neumann modes), divergence-free modes (formerly the Dirichlet modes) and
% the boundary modes (or harmonic modes), respectively. These should be in
% the format generated by the openMA_pdetool_neumann_modes_solve,
% openMA_pdetool_dirichlet_modes_solve and
% openMA_pdetool_boundary_modes_solve. If any of them is empty or absent,
% those modes will be ignored.
%
% The format of u, ux and uy will be an array with one row for each point
% in cc and one column for each mode in the order given.
%
% Interpolation of the modes is done via linear interpolation on the
% enclosing triangles. Interpolation of the velocities is done by
% selecting the velocity of the enclosing triangle. Both of these
% basically assume that the triangles are small enough that the linear
% approximation is valid over the triangle. If this assumption isn't
% valid, you probably didn't do a very good job of solving your original
% PDE.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% $Id: openMA_modes_interp.m 79 2007-03-05 21:51:20Z dmk $
%
% Copyright (C) 2005 David M. Kaplan
% Licence: GPL (Gnu Public License)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if ~exist('dm','var')
dm = [];
end
if ~exist('bm','var')
bm = [];
end
% Number of modes total.
nnn = length(nm) + length(dm) + length(bm);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Do interpolation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if nargout == 1
% Want modes themselves interpolated
ux = zeros(size(cc,1),nnn);
nn = 0; % Start counter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Loop over neumann modes and do interpolation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for k = 1:length(nm)
nn = nn + 1;
ux(:,nn) = pdeintrp_arbitrary( cc, nm(k).p, nm(k).t, ...
nm(k).u );
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Loop over dirichlet modes and do interpolation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for k = 1:length(dm)
nn = nn + 1;
ux(:,nn) = pdeintrp_arbitrary( cc, dm(k).p, dm(k).t, ...
dm(k).u );
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Loop over boundary modes and do interpolation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for k = 1:length(bm)
nn = nn + 1;
ux(:,nn) = pdeintrp_arbitrary( cc, bm(k).p, bm(k).t, ...
bm(k).u );
end
else
% Want vector velocities.
% Will use pdeintrp_arbitrary.
% This implicitly assumes that velocity is constant over each
% triangle, as the pde solver would do. Probably an acceptable
% assumption in this application.
[ux,uy] = deal( zeros(size(cc,1),nnn) );
nn = 0; % Start counter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Loop over neumann modes and do interpolation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for k = 1:length(nm)
nn = nn + 1;
[ux(:,nn),uy(:,nn)] = pdeintrp_arbitrary( cc, nm(k).p, nm(k).t, ...
nm(k).u );
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Loop over dirichlet modes and do interpolation
%
% Sign in definition of vorticity modes agrees with k x grad(psi)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for k = 1:length(dm)
nn = nn + 1;
[uy(:,nn),ux(:,nn)] = pdeintrp_arbitrary( cc, dm(k).p, dm(k).t, ...
dm(k).u );
% Fix sign of x term
ux(:,nn) = -ux(:,nn);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Loop over boundary modes and do interpolation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for k = 1:length(bm)
nn = nn + 1;
[ux(:,nn),uy(:,nn)] = pdeintrp_arbitrary( cc, bm(k).p, bm(k).t, ...
bm(k).u );
end
end