forked from jaolive/SiStER
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SiStER_interp_markers_to_shear_nodes.m
309 lines (218 loc) · 7.9 KB
/
SiStER_interp_markers_to_shear_nodes.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
function [n2interp] = SiStER_interp_markers_to_shear_nodes(xm,ym,icn,jcn,quad,x,y,varargin)
% [n2interp] = SiStER_interp_markers_to_shear_nodes(xm,ym,icn,jcn,quad,x,y,varargin)
% interpolates marker properties to shear nodes
% First cut - J.A. Olive, March 2011
% Modified by E. Mittelstaedt, April 2011, to allow variable inputs.
% Modified by B.Z. Klein, Spring 2014, for speedup
% Modified by B.Z. Klein, Summer 2014, for further speedup (vectorized)
Nx=length(x);
Ny=length(y);
dx=diff(x);
dy=diff(y);
% MITTELSTAEDT - check for number of properties to interpolate
numV = size(varargin,2);
% MITTELSTAEDT % establish interpolants matrices
n2interp = repmat(struct('data', zeros(Ny,Nx)), 1, numV);
JCN = interp1(x, 1:length(x), xm, 'nearest', 'extrap'); %% these are like the jcn and icn elsewhere, except the nodes are centered instead of upper left.
ICN = interp1(y, 1:length(y), ym, 'nearest', 'extrap'); %% this makes a lot of the indexing much simpler below.
%% Interior Cells
center = jcn>1 & jcn<Nx & icn>1 & icn<Ny;
shiftLeft = jcn<Nx-1 & icn>1 & icn<Ny;
shiftUp = jcn>1 & jcn<Nx & icn<Ny-1;
shiftBoth = jcn<Nx-1 & icn<Ny-1;
cell1 = center & ((xm-x(JCN)) > 0) & ((ym - y(ICN)) > 0); %% these are logical arrays that index the original quadrants
cell2 = shiftLeft & ((xm-x(JCN)) < 0) & ((ym - y(ICN)) > 0);
cell3 = shiftBoth & ((xm-x(JCN)) < 0) & ((ym - y(ICN)) < 0);
cell4 = shiftUp & ((xm-x(JCN)) > 0) & ((ym - y(ICN)) < 0);
%%% WEIGHTING (equal for now because that is what I'm running)
wc1 = 0.25;
wc2 = 0.25;
wc3 = 0.25;
wc4 = 0.25;
% cell 1 (i,j,1)
dxm = xm(cell1) - x(JCN(cell1));
dym = ym(cell1) - y(ICN(cell1));
ddx = dx(JCN(cell1));
ddy = dy(ICN(cell1));
wm1 = 1 - (dxm.*dym + (ddx-dxm).*dym + (ddy-dym).*dxm)./(ddx.*ddy);
w1 = accumarray([ICN(cell1)', JCN(cell1)'], wm1);
% cell 2 (i, j-1, 2)
dxm = xm(cell2) - x(JCN(cell2));
dym = ym(cell2) - y(ICN(cell2));
ddx = dx(JCN(cell2)-1);
ddy = dy(ICN(cell2));
wm2 = 1 - (dxm.*dym + (ddx-dxm).*dym + (ddy-dym).*dxm)./(ddx.*ddy);
w2 = accumarray([ICN(cell2)', JCN(cell2)'], wm2);
% cell 3 (i-1, j-1, 3)
dxm = xm(cell3) - x(JCN(cell3));
dym = ym(cell3) - y(ICN(cell3));
ddx = dx(JCN(cell3)-1);
ddy = dy(ICN(cell3)-1);
wm3 = 1 - (dxm.*dym + (ddx-dxm).*dym + (ddy-dym).*dxm)./(ddx.*ddy);
w3 = accumarray([ICN(cell3)', JCN(cell3)'], wm3);
% cell 4 (i-1, j, 4)
dxm = xm(cell4) - x(JCN(cell4));
dym = ym(cell4) - y(ICN(cell4));
ddx = dx(JCN(cell4));
ddy = dy(ICN(cell4)-1);
wm4 = 1 - (dxm.*dym + (ddx-dxm).*dym + (ddy-dym).*dxm)./(ddx.*ddy);
w4 = accumarray([ICN(cell4)', JCN(cell4)'], wm4);
%loop over material properties to interpolate
for vn = 1:numV
n2interp(vn).data = (wc1*accumarray([ICN(cell1)', JCN(cell1)'], varargin{vn}(cell1).*wm1)./w1 + ...
wc2*accumarray([ICN(cell2)', JCN(cell2)'], varargin{vn}(cell2).*wm2)./w2 + ...
wc3*accumarray([ICN(cell3)', JCN(cell3)'], varargin{vn}(cell3).*wm3)./w3 + ...
wc4*accumarray([ICN(cell4)', JCN(cell4)'], varargin{vn}(cell4).*wm4)./w4)./...
(wc1+wc2+wc4+wc4);
end
%% EDGES
%%% top edge
topEdge = jcn>1 & jcn<Nx & icn==1;
shifted = jcn<Nx-1 & icn==1;
% cell 1
cell1 = shifted & quad==2;
ddx = dx(JCN(cell1)-1);
ddy = dy(1);
dxm = xm(cell1) - x(JCN(cell1));
dym = ym(cell1) - y(ICN(cell1));
wm1 = 1 - (dxm.*dym + (ddx-dxm).*dym + (ddy-dym).*dxm)./(ddx.*ddy);
w1 = accumarray([ICN(cell1)', JCN(cell1)'], wm1);
% cell 2
cell2 = topEdge & quad==1;
ddx = dx(JCN(cell2));
ddy = dy(1);
dxm = xm(cell2) - x(JCN(cell2));
dym = ym(cell2) - y(ICN(cell2));
wm2 = 1 - (dxm.*dym + (ddx-dxm).*dym + (ddy-dym).*dxm)./(ddx.*ddy);
w2 = accumarray([ICN(cell2)', JCN(cell2)'], wm2);
%loop over material properties to interpolate
for vn = 1:numV
temp = (wc1*accumarray([ICN(cell1)', JCN(cell1)'], varargin{vn}(cell1).*wm1)./w1 + ...
wc2*accumarray([ICN(cell2)', JCN(cell2)'], varargin{vn}(cell2).*wm2)./w2)/...
(wc1+wc2);
n2interp(vn).data(1,2:end) = temp(2:end);
end
clear w1 w2
%%% bottom edge
bottomEdge = jcn>1 & jcn<Nx & icn==Ny-1;
shifted = jcn<Nx-1 & icn==Ny-1;
% cell 1
cell1 = shifted & quad==3;
ddx = dx(JCN(cell1)-1);
ddy = dy(Ny-1);
dxm = xm(cell1) - x(JCN(cell1));
dym = ym(cell1) - y(end-1);
wm1 = 1 - (dxm.*dym + (ddx-dxm).*dym + (ddy-dym).*dxm)./(ddx.*ddy);
w1 = accumarray([ones(sum(cell1),1), JCN(cell1)'], wm1);
% cell 2
cell2 = bottomEdge & quad==4;
ddx = dx(JCN(cell2));
ddy = dy(Ny-1);
dxm = xm(cell2) - x(JCN(cell2));
dym = ym(cell2) - y(end-1);
wm2 = 1 - (dxm.*dym + (ddx-dxm).*dym + (ddy-dym).*dxm)./(ddx.*ddy);
w2 = accumarray([ones(sum(cell2),1), JCN(cell2)'], wm2);
%loop over material properties to interpolate
for vn = 1:numV
temp = (wc1*accumarray([ones(sum(cell1),1), JCN(cell1)'], varargin{vn}(cell1).*wm1)./w1 + ...
wc2*accumarray([ones(sum(cell2),1), JCN(cell2)'], varargin{vn}(cell2).*wm2)./w2)/...
(wc1+wc2);
n2interp(vn).data(Ny,2:end) = temp(2:end);
end
%%% left edge
leftEdge = jcn==1 & icn>1 & icn<Ny;
shifted = jcn==1 & icn<Ny-1;
% cell 1
cell1 = shifted & quad==4;
ddx = dx(1);
ddy = dy(ICN(cell1)-1);
dxm = xm(cell1) - x(1);
dym = ym(cell1) - y(ICN(cell1));
wm1 = 1 - (dxm.*dym + (ddx-dxm).*dym + (ddy-dym).*dxm)./(ddx.*ddy);
w1 = accumarray([ICN(cell1)', ones(sum(cell1),1)], wm1);
% cell 2
cell2 = leftEdge & quad==1;
ddx = dx(1);
ddy = dy(ICN(cell2));
dxm = xm(cell2) - x(1);
dym = ym(cell2) - y(ICN(cell2));
wm2 = 1 - (dxm.*dym + (ddx-dxm).*dym + (ddy-dym).*dxm)./(ddx.*ddy);
w2 = accumarray([ICN(cell2)', ones(sum(cell2),1)], wm2);
%loop over material properties to interpolate
for vn = 1:numV
temp = (wc1*accumarray([ICN(cell1)', ones(sum(cell1),1)], varargin{vn}(cell1).*wm1)./w1 + ...
wc2*accumarray([ICN(cell2)', ones(sum(cell2),1)], varargin{vn}(cell2).*wm2)./w2)/...
(wc1+wc2);
n2interp(vn).data(2:end-1, 1) = temp(2:end);
end
%%% right edge
rightEdge = jcn==Nx-1 & icn>1 & icn<Ny;
shifted = jcn==Nx-1 & icn<Ny-1;
% cell 1
cell1 = shifted & quad==3;
ddx = dx(Nx-1);
ddy = dy(ICN(cell1)-1);
dxm = xm(cell1) - x(Nx-1);
dym = ym(cell1) - y(ICN(cell1));
wm1 = 1 - (dxm.*dym + (ddx-dxm).*dym + (ddy-dym).*dxm)./(ddx.*ddy);
w1 = accumarray([ICN(cell1)', ones(sum(cell1),1)], wm1);
% cell 2
cell2 = rightEdge & quad==2;
ddx = dx(Nx-1);
ddy = dy(ICN(cell2));
dxm = xm(cell2) - x(Nx-1);
dym = ym(cell2) - y(ICN(cell2));
wm2 = 1 - (dxm.*dym + (ddx-dxm).*dym + (ddy-dym).*dxm)./(ddx.*ddy);
w2 = accumarray([ICN(cell2)', ones(sum(cell2),1)], wm2);
%loop over material properties to interpolate
for vn = 1:numV
temp = (wc1*accumarray([ICN(cell1)', ones(sum(cell1),1)], varargin{vn}(cell1).*wm1)./w1 + ...
wc2*accumarray([ICN(cell2)', ones(sum(cell2),1)], varargin{vn}(cell2).*wm2)./w2)/...
(wc1+wc2);
n2interp(vn).data(2:end-1, Nx) = temp(2:end);
end
%% CORNERS
% upper left
upperLeft = jcn==1 & icn==1 & quad==1;
ddx = dx(1);
ddy = dy(1);
dxm = xm(upperLeft) - x(1);
dym = ym(upperLeft) - y(1);
wm = 1 - (dxm.*dym + (ddx-dxm).*dym + (ddy-dym).*dxm)/(ddx*ddy);
wco = sum(wm);
for vn = 1:numV
n2interp(vn).data(1,1) = sum(varargin{vn}(upperLeft).*wm)./wco;
end
% upper right
upperRight = icn==1 & jcn==Nx-1 & quad==2;
ddx = dx(Nx-1);
ddy = dy(1);
dxm = xm(upperRight) - x(Nx-1);
dym = ym(upperRight) - y(1);
wm = 1 - (dxm.*dym + (ddx-dxm).*dym + (ddy-dym).*dxm)/(ddx*ddy);
wco = sum(wm);
for vn = 1:numV
n2interp(vn).data(1,Nx) = sum(varargin{vn}(upperRight).*wm)./wco;
end
% lower Right
lowerRight = icn==Ny-1 & jcn==Nx-1 & quad==3;
ddx = dx(Nx-1);
ddy = dy(Ny-1);
dxm = xm(lowerRight) - x(Nx-1);
dym = ym(lowerRight) - y(Ny-1);
wm = 1 - (dxm.*dym + (ddx-dxm).*dym + (ddy-dym).*dxm)/(ddx*ddy);
wco = sum(wm);
for vn = 1:numV
n2interp(vn).data(Ny,Nx) = sum(varargin{vn}(lowerRight).*wm)./wco;
end
% lower left
lowerLeft = icn==Ny-1 & jcn==1 & quad==4;
ddx = dx(1);
ddy = dy(Ny-1);
dxm = xm(lowerLeft) - x(1);
dym = ym(lowerLeft) - y(Ny-1);
wm = 1 - (dxm.*dym + (ddx-dxm).*dym + (ddy-dym).*dxm)/(ddx*ddy);
wco = sum(wm);
for vn = 1:numV
n2interp(vn).data(Ny,1) = sum(varargin{vn}(lowerLeft).*wm)./wco;
end