-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflowSlice.m
550 lines (441 loc) · 16.7 KB
/
flowSlice.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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
classdef flowSlice < handle
%FLOWSLICE Generic class containing a slice of the flow
properties
NB;
gas;
bcs;
ro;
u;
v;
w;
Et;
% xSurf;
% yBL;
% xO;
% yO;
% iO;
% jO;
% blkO;
% oblocks;
% oblocks_flip;
blk;
% iLE;
% iTE;
% n;
% ssurf; % Surface distance fron LE
% vortZ; % Z vorticity
end
properties (Dependent = true, Hidden = true)
T; % Temperature
p; % p stat
StR; % Strain rate magnitude
M; % Mach No
s; % Entropy ( cp*log(T/300) - R*log(p/1e5) )
sfunc;
ros; % Entropy per unit volume
vel; % Velocity
mu; % Viscosity
nu; % Kinematic viscosity
p0;
T0;
schlieren; % |grad(ro)|/ro
cellSize;
St;
St_an % Traceless strain
S_an_mag; % Magnitude of anisotropic componant of strain tensor
local_cfl;
wallDist; % Distance from wall
flowAng;
muSij2; % Dissipation due to mean strain
nuSij2;
duidxj; % Velocity gradient tensor
diss_ave;
x;
y;
end
methods
function obj = flowSlice(blk, gas, bcs)
%FLOWSLICE Construct a flowSlice object
disp('Constructing flowSlice')
obj.gas = gas;
obj.bcs = bcs;
obj.NB = size(blk.blockdims,1);
obj.blk = blk;
end % End of constructor
function value = get.p(obj)
value = obj.get_p;
end
function obj = set.p(obj, value)
obj.set_p(value);
end
function value = get_p(obj)
value = cell(1,obj.NB);
for nb =1:obj.NB
value{nb} = (obj.gas.gam -1)*(obj.Et{nb} - 0.5*(obj.u{nb}.^2 + obj.v{nb}.^2 + obj.w{nb}.^2).*obj.ro{nb});
end
end
function value = get.T(obj)
value = obj.get_T;
end
function obj = set.T(obj, value)
obj.set_T(value);
end
function value = get.ros(obj)
value = obj.get_ros;
end
function obj = set.ros(obj, value)
obj.set_ros(value)
end
function value = get.StR(obj)
value = obj.get_StR;
end
function obj = set.StR(obj, value)
obj.set_StR(value);
end
function set_p(obj,value)
end
function set_T(obj,value)
end
function set_StR(obj,value)
end
function set_ros(obj,value)
end
function value = get_T(obj)
value = cell(1,obj.NB);
for nb =1:obj.NB
value{nb} = obj.p{nb}./(obj.ro{nb}*obj.gas.rgas);
end
end
function value = get_ros(obj)
value = cell(1,obj.NB);
Tnow = obj.T;
pnow = obj.p;
for nb = 1:obj.NB
value{nb} = obj.ro{nb}.*(obj.gas.cp*log(Tnow{nb}/obj.bcs.Toin) - ...
obj.gas.cp*(1-1/obj.gas.gam)*log(pnow{nb}/obj.bcs.Poin));
end
end
function value = get.vel(obj)
disp('Calculating vel')
value = cell(1,obj.NB);
for nb = 1:obj.NB
value{nb} = sqrt(obj.u{nb}.^2 + obj.v{nb}.^2 + obj.w{nb}.^2);
end
end
function value = get.p0(obj)
pnow = obj.p;
Mnow = obj.M;
for nb = 1:obj.NB
value{nb} = pnow{nb}.*(1+0.5*(obj.gas.gam-1)*Mnow{nb}.^2).^(obj.gas.gam/(obj.gas.gam-1));
end
end
function value = get.T0(obj)
tnow = obj.T;
Mnow = obj.M;
for nb = 1:obj.NB
value{nb} = tnow{nb}.*(1+0.5*(obj.gas.gam-1)*Mnow{nb}.^2);
end
end
function value = get.M(obj)
disp('Calculating M')
value = cell(1,obj.NB);
pnow = obj.p;
for nb = 1:obj.NB
%pnow = (obj.gas.gam - 1)*(obj.Et{nb} - 0.5*(obj.u{nb}.^2 + obj.v{nb}.^2 + obj.w{nb}.^2).*obj.ro{nb});
Tnow = pnow{nb}./(obj.ro{nb}*obj.gas.rgas);
velnow = sqrt(obj.u{nb}.^2 + obj.v{nb}.^2 + obj.w{nb}.^2);
value{nb} = velnow./sqrt(obj.gas.gam*obj.gas.rgas*Tnow);
end
end
function value = get.s(obj)
disp('Calculating s')
value = cell(1,obj.NB);
for nb = 1:obj.NB
pnow = (obj.gas.gam - 1)*(obj.Et{nb} - 0.5*(obj.u{nb}.^2 + obj.v{nb}.^2 + obj.w{nb}.^2).*obj.ro{nb});
Tnow = pnow./(obj.ro{nb}*obj.gas.rgas);
value{nb} = obj.gas.cp*log(Tnow/obj.bcs.Toin) - obj.gas.rgas*log(pnow/obj.bcs.Poin);
end
end
function value = get.sfunc(obj)
value = cell(1,obj.NB);
for nb = 1:obj.NB
pnow = (obj.gas.gam - 1)*(obj.Et{nb} - 0.5*(obj.u{nb}.^2 + obj.v{nb}.^2 + obj.w{nb}.^2).*obj.ro{nb});
Tnow = pnow./(obj.ro{nb}*obj.gas.rgas);
value{nb} = obj.gas.cp*log(Tnow/obj.bcs.Toin) - obj.gas.rgas*log(pnow/obj.bcs.Poin);
end
end
function value = get.mu(obj)
disp('Calcualting mu')
value = cell(1,obj.NB);
for nb = 1:obj.NB
pnow = obj.p{nb};%(obj.gas.gam - 1)*(obj.Et{nb} - 0.5*(obj.u{nb}.^2 + obj.v{nb}.^2 + obj.w{nb}.^2).*obj.ro{nb});
Tnow = pnow./(obj.ro{nb}*obj.gas.rgas);
value{nb} = sutherland_mu(Tnow, obj.gas.mu_ref, obj.gas.mu_cref, obj.gas.mu_tref);%obj.gas.mu_ref*(Tnow/obj.gas.mu_tref).^(3/2) .* (obj.gas.mu_cref + obj.gas.mu_tref)./(obj.gas.mu_cref + Tnow);
end
end
function value = get.flowAng(obj)
disp('Calculating flow angle')
value = cell(1,obj.NB);
for ib = 1:obj.NB
value{ib} = atan2d(obj.v{ib},obj.u{ib});
end
end
function value = get.nu(obj)
munow = obj.mu;
ronow = obj.ro;
for nb = 1:obj.NB
value{nb} = munow{nb}./ronow{nb};
end
end
function nb = find_block(obj, x, y)
nb = NaN;
for ib=1:obj.NB
xb = [obj.blk.x{ib}(1:end-1,1); ...
obj.blk.x{ib}(end,1:end-1)'; ...
obj.blk.x{ib}(end:-1:2,end); ...
obj.blk.x{ib}(1,end:-1:2)'];
yb = [obj.blk.y{ib}(1:end-1,1); ...
obj.blk.y{ib}(end,1:end-1)'; ...
obj.blk.y{ib}(end:-1:2,end); ...
obj.blk.y{ib}(1,end:-1:2)'];
if inpolygon(x,y,xb,yb)
nb = ib;
break
end
end
end
function value = get.cellSize(obj)
fprintf('Calculating Cell Sizes\n')
dz = obj.blk.span/(obj.blk.nk{1}-1);
value = {};
for ib = 1:obj.NB
ni = size(obj.blk.x{ib},1);
nj = size(obj.blk.x{ib},2);
area = zeros(ni-1, nj-1);
for i=1:ni-1
for j=1:nj-1
xnow = [obj.blk.x{ib}(i,j) obj.blk.x{ib}(i+1,j) ...
obj.blk.x{ib}(i+1,j+1) obj.blk.x{ib}(i,j+1)];
ynow = [obj.blk.y{ib}(i,j) obj.blk.y{ib}(i+1,j) ...
obj.blk.y{ib}(i+1,j+1) obj.blk.y{ib}(i,j+1)];
area(i,j) = abs(polyarea(xnow,ynow));
end
end
area = dz*area;
value{ib}(1,1) = area(1,1);
value{ib}(1,nj) = area(1,nj-1);
value{ib}(ni,1) = area(ni-1,1);
value{ib}(ni,nj) = area(ni-1,nj-1);
for i = 2:ni-1
value{ib}(i,1) = 0.5*(area(i-1,1)+area(i,1));
value{ib}(i,end) = 0.5*(area(i-1,end)+area(i,end));
end
for j = 2:nj-1
value{ib}(1,j) = 0.5*(area(1,j-1)+area(1,j));
value{ib}(end,j) = 0.5*(area(end,j-1)+area(end,j));
end
for i=2:ni-1
for j=2:nj-1
value{ib}(i,j) = 0.25*(area(i-1,j-1)+area(i-1,j)+area(i,j-1) +area(i,j));
end
end
value{ib} = value{ib}.^(1/3);
end
end
function value = get.schlieren(obj)
disp('calculating grad(ro)/ro')
value = cell(1,obj.NB);
for nb=1:obj.NB
[drodx, drody] = gradHO(obj.blk.x{nb},obj.blk.y{nb},obj.ro{nb});
value{nb} = sqrt(drodx.^2 + drody.^2)./obj.ro{nb};
end
end
function getSize(obj)
props = properties(obj);
totSize = 0;
for ii=1:length(props)
currentProperty = obj.(props{ii});
temp = whos('currentProperty');
totSize = totSize + temp.bytes;
end
fprintf(1, '%d MB\n', totSize/1e6);
end
function value = get_StR(obj)
value = cell(1,obj.NB);
for nb =1:obj.NB
value{nb} = strain_rate_magnitude(obj.blk.x{nb}, obj.blk.y{nb}, obj.u{nb}, obj.v{nb});
end
end
function value = get.St_an(obj)
S = obj.St;
for ib = 1:obj.NB
tr = S{ib}(:,:,1,1) + S{ib}(:,:,2,2) + S{ib}(:,:,3,3);
St = S{ib};
for i=1:3
St(:,:,i,i) = St(:,:,i,i) - tr/3;
end
value{ib} = St;
% [DUDX,DUDY] = gradHO(obj.blk.x{ib},obj.blk.y{ib},obj.u{ib});
% [DVDX,DVDY] = gradHO(obj.blk.x{ib},obj.blk.y{ib},obj.v{ib});
%
% %Traceless strain tensor
% S = zeros(obj.blk.blockdims(ib,1),obj.blk.blockdims(ib,2),3,3);
%
% S(:,:,1,1) = 2*DUDX/3 - DVDY/3;
% S(:,:,2,2) = 2*DVDY/3 - DUDX/3;
% S(:,:,3,3) = -(DUDX+DVDY)/3;
%
% S(:,:,1,2) = 0.5*(DUDY+DVDX);
% S(:,:,2,1) = S(:,:,1,2);
end
end
function value = St_an2(obj)
S = obj.St_an;
for ib = 1:obj.NB
value{ib} = sum(sum(S{ib}.*S{ib},4),3);
end
end
function value = get.St(obj)
for ib = 1:obj.NB
[DUDX,DUDY] = gradHO(obj.blk.x{ib},obj.blk.y{ib},obj.u{ib});
[DVDX,DVDY] = gradHO(obj.blk.x{ib},obj.blk.y{ib},obj.v{ib});
%Traceless strain tensor
S = zeros(obj.blk.blockdims(ib,1),obj.blk.blockdims(ib,2),3,3);
S(:,:,1,1) = DUDX;
S(:,:,2,2) = DVDY;
S(:,:,1,2) = 0.5*(DUDY+DVDX);
S(:,:,2,1) = S(:,:,1,2);
value{ib} = S;
end
end
function value = get.x(obj)
value = obj.blk.x;
end
function value = get.y(obj)
value = obj.blk.y;
end
function value = get.duidxj(obj)
for ib = 1:obj.NB
[DUDX,DUDY] = gradHO(obj.blk.x{ib},obj.blk.y{ib},obj.u{ib});
[DVDX,DVDY] = gradHO(obj.blk.x{ib},obj.blk.y{ib},obj.v{ib});
S = zeros(obj.blk.blockdims(ib,1),obj.blk.blockdims(ib,2),3,3);
S(:,:,1,1) = DUDX;
S(:,:,2,2) = DVDY;
S(:,:,1,2) = DUDY;
S(:,:,2,1) = DVDX;
value{ib} = S;
end
end
function value = get.S_an_mag(obj)
Snow = obj.St_an;
for ib = 1:obj.NB
value{ib} = sqrt(sum(sum(Snow{ib}.*Snow{ib},4),3));
end
end
function value = get.muSij2(obj)
for ib = 1:obj.NB
[DUDX,DUDY] = gradHO(obj.blk.x{ib},obj.blk.y{ib},obj.u{ib});
[DVDX,DVDY] = gradHO(obj.blk.x{ib},obj.blk.y{ib},obj.v{ib});
% Strain tensor
S = zeros(obj.blk.blockdims(ib,1),obj.blk.blockdims(ib,2),3,3);
S(:,:,1,1) = DUDX;
S(:,:,2,2) = DVDY;
S(:,:,1,2) = 0.5*(DUDY+DVDX);
S(:,:,2,1) = S(:,:,1,2);
value{ib} = obj.mu{ib}.*sum(sum(S.*S,4),3);
end
end
function value = get.nuSij2(obj)
for ib = 1:obj.NB
[DUDX,DUDY] = gradHO(obj.blk.x{ib},obj.blk.y{ib},obj.u{ib});
[DVDX,DVDY] = gradHO(obj.blk.x{ib},obj.blk.y{ib},obj.v{ib});
% Strain tensor
S = zeros(obj.blk.blockdims(ib,1),obj.blk.blockdims(ib,2),3,3);
S(:,:,1,1) = DUDX;
S(:,:,2,2) = DVDY;
S(:,:,1,2) = 0.5*(DUDY+DVDX);
S(:,:,2,1) = S(:,:,1,2);
value{ib} = obj.nu{ib}.*sum(sum(S.*S,4),3);
end
end
function diss_av = get.diss_ave(obj)
for ib = 1:obj.NB
[dudx, dudy] = gradHO(obj.blk.x{ib}, obj.blk.y{ib}, obj.u{ib});
[dvdx, dvdy] = gradHO(obj.blk.x{ib}, obj.blk.y{ib}, obj.v{ib});
[dwdx, dwdy] = gradHO(obj.blk.x{ib}, obj.blk.y{ib}, obj.w{ib});
mu = obj.mu{ib};
s11 = dudx;
s22 = dvdy;
s33 = 0;
s12 = (dudy + dvdx)*0.5;
s23 = 0.5*dwdy;
s13 = 0.5*dwdx;
% dissipation due to time mean strain
diss_av{ib} = (mu.*(2*(s11.*s11 + s22.*s22 + s33.*s33) + 4*s23.*s23 + 4*s13.*s13 + 4*s12.*s12 ) ...
- (2/3)*mu.*(s11 + s22 + s33).*(s11 + s22 + s33) );
end
end
function value = get.local_cfl(obj)
cfl = 1.0;
Vnow = obj.vel;
Tnow = obj.T;
c = {};
cmax = [];
for ib = 1:obj.NB
c{ib} = sqrt(obj.gas.gam*obj.gas.rgas*Tnow{ib});
cmax(ib) = max(c{ib},[],'all');
vmax(ib) = max(Vnow{ib},[],'all');
[dxi, dxj] = gradHOij(obj.blk.x{ib});
[dyi, dyj] = gradHOij(obj.blk.y{ib});
dcelli = sqrt(dxi.^2 + dyi.^2);
dcellj = sqrt(dxj.^2 + dyj.^2);
dcell{ib} = min(dcelli, dcellj);
end
vmax = max(vmax);
cmax = max(cmax);
for ib = 1:obj.NB
dt(ib) = min(cfl*dcell{ib}/(vmax+cmax),[],'all');
end
dt = min(dt);
fprintf('Slice Δt = %5.3e\n',dt)
for ib = 1:obj.NB
value{ib} = dt*(Vnow{ib}+c{ib})./dcell{ib};
end
end
function value = get.wallDist(obj)
if ~isempty(obj.blk.walldist)
value = obj.blk.walldist;
else
p = []
for ib = 1:obj.NB
end
obj.blk.walldist = value;
end
end
function kPlot(obj, prop)
q = obj.(prop);
hold on
ax = gca;
for i=1:obj.NB
s = pcolor(ax, obj.blk.x{i}, obj.blk.y{i}, q{i});
end
shading('interp');
axis equal
end
function value = unstructured_sample(obj, x, y, prop)
bl = zeros(size(x));
value = zeros(size(x));
for i = 1:length(x)
bl(i) = obj.find_block(x(i),y(i));
end
for ib = 1:obj.NB
is = bl == ib;
if sum(is) > 0
int = scatteredInterpolant(reshape(obj.blk.x{ib},[],1), ...
reshape(obj.blk.y{ib},[],1), reshape(obj.(prop){ib},[],1));
value(is) = int(x(is), y(is));
end
end
end
end
end