-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDNS_case.m
3448 lines (2968 loc) · 123 KB
/
DNS_case.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
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
classdef DNS_case < handle
% DNS_CASE Class containing 3DNS case information and methods to read
% and postprocess results
properties
casename;
casepath;
casetype;
topology;
runpath;
runpaths;
run;
blk;
solver;
bcs;
gas;
% x;
% y;
nSlices;
nProbes;
nSkip;
probes;
NB;
y_inlet;
inlet_width;
nj_inlet;
meanFlow = meanSlice.empty;
meanFlowPS = meanSlice.empty;
ransFlow = RANSSlice.empty;
meanFlows = {};
instFlow = volFlow.empty;
startFlow = spanAveSlice.empty;
endFlow = spanAveSlice.empty;
iSlices;
jSlices = jSlice.empty;
kSlices = kSlice.empty;
inflowTurb = volTurbulence.empty;
spanAveFlow = kSlice.empty
inletProf = inletProfile.empty;
RANSSlices;
trip;
iTrip = false;
e_unst = [];
cell_area = [];
if_rans;
speed_up;
pitch;
end
properties (Dependent = true, Hidden=true)
ftrip;
Re_k; % Trip Reynolds number
trip_Re_x;
aspect_ratio;
end
methods
function obj = DNS_case(casename,run,args)
%DNS_CASE Construct an instance of this class
% Detailed explanation goes here
if nargin > 0 && ~isempty(casename)
obj.casename = casename;
obj.casepath = fullfile(pwd,obj.casename);
obj.runpaths = {};
if nargin < 2 || isempty(run)
obj.runpath = obj.casepath;
obj.runpaths{1} = obj.runpath;
obj.run = [];
elseif length(run) == 1
obj.run = run;
obj.runpath = fullfile(obj.casepath,['run' num2str(obj.run)]);
obj.runpaths{1} = obj.runpath;
else
obj.run = run;
obj.runpath = fullfile(obj.casepath,['run' num2str(obj.run(end))]);
for ir = 1:length(run)
obj.runpaths{ir} = fullfile(obj.casepath,['run' num2str(obj.run(ir))]);
end
end
disp(obj.casepath)
if exist(fullfile(obj.casepath,'body.txt'),'file')
obj.casetype = 'gpu';
else
obj.casetype = 'cpu';
end
fprintf('Case type: %s\n', obj.casetype);
if exist(fullfile(obj.casepath,'rans.txt'),'file')
f = fopen(fullfile(obj.casepath,'rans.txt'),'r');
try
obj.if_rans = str2num(fgetl(f));
obj.speed_up = str2num(fgetl(f));
catch
obj.if_rans = 0;
obj.speed_up = 0;
end
fclose(f)
else
obj.if_rans = false;
obj.speed_up = 1.0;
end
rcase = read_case(casename, obj.casetype, obj.run);
obj.NB = rcase.NB;
obj.blk = rcase.blk;
obj.blk.next_block = rcase.next_block;
obj.blk.next_patch = rcase.next_patch;
% obj.next_block = rcase.next_block;
% obj.next_patch = rcase.next_patch;
obj.blk.corner = rcase.corner;
obj.bcs = rcase.bcs;
obj.gas = rcase.gas;
obj.gas.rgas = obj.gas.cp * (obj.gas.gam - 1)/obj.gas.gam;
obj.solver = rcase.solver;
obj.blk.inlet_blocks{1} = rcase.inlet_blocks;
obj.blk.z = linspace(0, obj.solver.span, obj.blk.nk);
obj.blk.viewarea = [];
obj.pitch = 0;
if nargin < 3 || ~isfield(args,'topology')
if obj.NB == 9
obj.topology = 1;
elseif obj.NB == 12
obj.topology = 2;
obj.blk.viewarea = [-0.6 2 -0.5 0.5];
end
else
obj.topology = args.topology;
end
obj.construct_o_blocks;
if ~isempty(obj.blk.viewarea)
obj.blk.aspect = [(obj.blk.viewarea(2)-obj.blk.viewarea(1)) ...
(obj.blk.viewarea(4)-obj.blk.viewarea(3)) 1];
end
if isfile(fullfile(obj.runpath,'slice_time.txt'))
obj.nSlices = size(readmatrix(fullfile(obj.runpath,'slice_time.txt')),1);
end
obj.solver.nk = obj.blk.nk;
if length(obj.blk.inlet_blocks) == 1
obj.nj_inlet = 0;
y_inlet = [];
for i=1:length(obj.blk.inlet_blocks{1})
y_inlet = [y_inlet obj.blk.y{obj.blk.inlet_blocks{1}(i)}(1,:,1)];
ymidnow(i) = obj.blk.y{obj.blk.inlet_blocks{1}(i)}(1,ceil(end/2));
end
obj.y_inlet = sort(unique(y_inlet));
obj.nj_inlet = length(obj.y_inlet);
obj.inlet_width = max(obj.y_inlet) - min(obj.y_inlet);
[~,inds] = sort(ymidnow);
obj.blk.inlet_blocks{1} = obj.blk.inlet_blocks{1}(inds);
end
obj.trip = [];
if obj.solver.istability == 2
obj.iTrip = true;
obj.readTrip;
else
obj.iTrip = false;
end
slices = dir(fullfile(obj.runpath,'k_cuts','kcu2_1_*'));
obj.nSlices = length(slices);
if obj.NB == 12
obj.blk.io_surfaces.blks = [1 2 2 7 11 11 10 12 12 8 3 3];
obj.blk.io_surfaces.types = [1 1 3 3 3 2 2 2 4 4 4 1];
end
end
end
function writeCase(obj)
obj.writeGridFiles;
obj.writeInputFiles;
if ~isempty(obj.instFlow)
obj.instFlow.writeFlow();
end
end
function construct_o_blocks(obj)
% Find first wall block, assume flow im -> ip
for ib = 1:obj.NB
if (obj.blk.next_block{ib}.jm == 0 ...
&& obj.blk.next_patch{ib}.jm == 3) || ...
(obj.blk.next_block{ib}.jp == 0 ...
&& obj.blk.next_patch{ib}.jp == 3)
obj.blk.oblocks = ib;
obj.blk.oblocks_flip = 0;
break
end
end
% Construct wall blocks list and connectivity
nb = obj.blk.next_block{ib}.ip;
np = 'ip';
while nb ~= 0 && ~ismember(nb, obj.blk.oblocks)
obj.blk.oblocks(end+1) = nb;
if obj.blk.next_patch{ib}.(np) == 1
obj.blk.oblocks_flip(end+1) = 0;
nb = obj.blk.next_block{nb}.ip;
np = 'ip';
else
obj.blk.oblocks_flip(end+1) = 1;
nb = obj.blk.next_block{nb}.im;
np = 'im';
end
ib = obj.blk.oblocks(end);
end
end
function calculate_wall_distance(obj)
ib = obj.blk.oblocks(1);
if (obj.blk.next_block{ib}.jp == 0 ...
&& obj.blk.next_patch{ib}.jp == 3)
jsurf = size(obj.blk.x{ib},2);
else
jsurf = 1;
end
xprof = [];
yprof = [];
for ib = obj.blk.oblocks
xprof = [xprof obj.blk.x{ib}(:,jsurf)'];
yprof = [yprof obj.blk.y{ib}(:,jsurf)'];
end
if obj.pitch ~= 0
xprof = [xprof xprof];
yprof = [(yprof - obj.pitch) yprof];
end
xnow = obj.blk.x;
ynow = obj.blk.y;
[~,mb] = max(prod(obj.blk.blockdims(:,1:2),2));
parfor ib = 1:obj.NB
[ni, nj] = size(xnow{ib});
for i=1:ni
if ib == mb && mod(i,20) == 0
fprintf('i=%d/%d\n',[i,ni])
end
for j=1:nj
dist = sqrt((xprof - xnow{ib}(i,j)).^2 + (yprof - ynow{ib}(i,j)).^2);
walldist{ib}(i,j) = min(dist);
end
end
end
obj.blk.walldist = walldist;
end
function slice = readSingleKSlice(obj,numslice)
switch obj.casetype
case 'cpu'
slicetime = readmatrix(fullfile(obj.runpath,'slice_time.txt'));
case 'gpu'
slicetime = readmatrix(fullfile(obj.runpath,'kslice_time.txt'));
end
slicenums = slicetime(end-obj.nSlices+1:end,1);
slicenum = slicenums(numslice);
slice =kSlice(obj.blk,obj.gas,obj.bcs,obj.runpath,slicenum);
end
function slice = readSingleJSlice(obj,numslice)
slicetime = readmatrix(fullfile(obj.runpath,'slice_time.txt'));
slicenums = slicetime(end-obj.nSlices+1:end,1);
slicenum = slicenums(numslice);
slice =jSlice(obj.runpath,slicenum,obj.blk,obj.gas);
end
function readSpanAveFlo(obj)
obj.spanAveFlow = kSlice(obj.blk,obj.gas,obj.bcs,obj.runpath,'flow_2d',[],obj.casetype,true);
end
function readRansFlow(obj)
obj.ransFlow = RANSSlice(obj.blk, obj.gas, obj.bcs, '3dns', obj.runpath);
end
function readKSlices(obj, slicenums, runs)
%READKSLICES Read in instantaneous k slices
% Optional: numslices - only read last n slices if there are many
exist("runs",'var')
exist("numslices",'var')
obj.kSlices = kSlice.empty;
obj.nSlices = 0;
if nargin < 3 || isempty(runs)
runs = obj.run;
end
paths2read={};
slicenums2read=[];
time2read = [];
if isempty(runs)
ishere = true;
switch obj.casetype
case 'cpu'
slicetime = readmatrix(fullfile(obj.runpath,'slice_time.txt'));
slices = dir(fullfile(obj.runpath,'kcu2_1_*'));
case 'gpu'
slicetime = readmatrix(fullfile(obj.runpath,'kslice_time.txt'));
slices = dir(fullfile(obj.runpath,'kcut_1_*'));
end
for i=1:length(slices)
inds(i) = str2num(slices(i).name(8:end));
end
[~,inds] = sort(inds);
slices = slices(inds);
for i=1:length(slices)
slicenum = str2num(slices(i).name(8:end));
slicenums2read(end+1) = slicenum;
paths2read{i} = obj.runpath;
for j=1:size(slicetime,1)
if slicetime(j,1) == slicenum
time2read(end+1) = slicetime(j,2);
end
end
end
else
ishere=false;
for run=runs
runpath = fullfile(obj.casepath,['run' num2str(run)]);
switch obj.casetype
case 'cpu'
slicetime = readmatrix(fullfile(runpath,'slice_time.txt'));
slices = dir(fullfile(runpath,'k_cuts','kcu2_1_*'));
case 'gpu'
slicetime = readmatrix(fullfile(runpath,'kslice_time.txt'));
slices = dir(fullfile(runpath,'k_cuts','kcut_1_*'));
end
%obj.nSlices = obj.nSlices + length(slices);
inds = [];
for i=1:length(slices)
inds(i) = str2num(slices(i).name(8:end));
end
[~,inds] = sort(inds);
slices = slices(inds);
for i=1:length(slices)
paths2read{end+1} = runpath;
slicenum = str2num(slices(i).name(8:end));
slicenums2read(end+1) = slicenum;
for j=1:size(slicetime,1)
if slicetime(j,1) == slicenum
time2read(end+1) = slicetime(j,2);
end
end
end
end
end
if exist("slicenums",'var')
if length(slicenums) == 1
slicenums2read = slicenums2read(end-slicenums+1:end);
paths2read = paths2read(end-slicenums+1:end);
time2read = time2read(end-slicenums+1:end);
else
slicenums2read = slicenums2read(slicenums);
paths2read = paths2read(slicenums);
time2read = time2read(slicenums);
end
end
obj.nSlices = length(slicenums2read);
for i=1:obj.nSlices
fprintf('Reading slice %d/%d\n',[i obj.nSlices])
obj.kSlices(i) = kSlice(obj.blk,obj.gas,obj.bcs,paths2read{i},slicenums2read(i),time2read(i),obj.casetype,ishere);
%slices(i).time = slicetime(i,2);
end
end
function readJSlices(obj, slicenums, runs)
%READKSLICES Read in instantaneous j slices
% Optional: numslices - only read last n slices if there are many
exist("runs",'var')
exist("numslices",'var')
obj.jSlices = jSlice.empty;
obj.nSlices = 0;
if nargin < 3 || isempty(runs)
runs = obj.run;
end
[paths2read, slicenums2read, time2read, ishere] = obj.getSlicePaths(runs);
if exist("slicenums",'var')
if length(slicenums) == 1
slicenums2read = slicenums2read(end-slicenums+1:end);
paths2read = paths2read(end-slicenums+1:end);
time2read = time2read(end-slicenums+1:end);
else
slicenums2read = slicenums2read(slicenums);
paths2read = paths2read(slicenums);
time2read = time2read(slicenums);
end
end
obj.nSlices = length(slicenums2read);
for i=1:obj.nSlices
fprintf('Reading slice %d/%d\n',[i obj.nSlices])
obj.jSlices(i) = jSlice(obj.blk,obj.gas,paths2read{i},slicenums2read(i),time2read(i),obj.casetype,ishere);
%slices(i).time = slicetime(i,2);
end
end
function [paths2read, slicenums2read, time2read, ishere] = getSlicePaths(obj, runs)
if nargin < 2 || isempty(runs)
runs = [];
end
paths2read={};
slicenums2read=[];
time2read = [];
if isempty(runs)
ishere = true;
switch obj.casetype
case 'cpu'
slicetime = readmatrix(fullfile(obj.runpath,'slice_time.txt'));
slices = dir(fullfile(obj.runpath, ['kcu2_1_*']));
case 'gpu'
slicetime = readmatrix(fullfile(obj.runpath,'kslice_time.txt'));
slices = dir(fullfile(obj.runpath,'kcut_1_*'));
end
for i=1:length(slices)
inds(i) = str2num(slices(i).name(8:end));
end
[~,inds] = sort(inds);
slices = slices(inds);
for i=1:length(slices)
slicenum = str2num(slices(i).name(8:end));
slicenums2read(end+1) = slicenum;
paths2read{i} = obj.runpath;
for j=1:size(slicetime,1)
if slicetime(j,1) == slicenum
time2read(end+1) = slicetime(j,2);
end
end
end
else
ishere=false;
for run=runs
runpath = fullfile(obj.casepath,['run' num2str(run)]);
switch obj.casetype
case 'cpu'
slicetime = readmatrix(fullfile(runpath,'slice_time.txt'));
slices = dir(fullfile(runpath,'k_cuts','kcu2_1_*'));
case 'gpu'
slicetime = readmatrix(fullfile(runpath,'kslice_time.txt'));
slices = dir(fullfile(runpath,'k_cuts','kcut_1_*'));
end
%obj.nSlices = obj.nSlices + length(slices);
inds = [];
for i=1:length(slices)
inds(i) = str2num(slices(i).name(8:end));
end
[~,inds] = sort(inds);
slices = slices(inds);
for i=1:length(slices)
paths2read{end+1} = runpath;
slicenum = str2num(slices(i).name(8:end));
slicenums2read(end+1) = slicenum;
for j=1:size(slicetime,1)
if slicetime(j,1) == slicenum
time2read(end+1) = slicetime(j,2);
end
end
end
end
end
end
function readInstFlow(obj)
%READINSTFLOW Read in instantaneous 3D flow
obj.instFlow = volFlow(obj.blk,obj.gas,obj.bcs,obj.runpath,obj.casetype,obj.if_rans);
end
function readStartEndFlow(obj)
fid = fopen(fullfile(obj.runpaths{1},'mean_time.txt'),'r');
while ~feof(fid) % Use lastest mean files
temp=fgetl(fid);
end
% temp = fgetl(fid);
fclose(fid);
temp = str2num(temp);
nMeanStart = temp(1)-1
fid = fopen(fullfile(obj.runpaths{end},'mean_time.txt'),'r');
while ~feof(fid) % Use lastest mean files
temp=fgetl(fid);
end
% temp = fgetl(fid);
fclose(fid);
temp = str2num(temp);
nMeanEnd = temp(1)
obj.startFlow = spanAveSlice(obj.runpaths{1},obj.blk,obj.gas,obj.bcs,obj.casetype,nMeanStart);
obj.endFlow = spanAveSlice(obj.runpaths{end},obj.blk,obj.gas,obj.bcs,obj.casetype,nMeanEnd);
end
function writeInstFlow(obj, path)
%WRITEINSTFLOW Write out intantaneous 3D flow to path
if nargin < 2
path = obj.casepath;
end
obj.instFlow.writeFlow(path);
end
function readMeanFlow(obj)
%READMEANFLOW Read in 2D mean flow
if strcmp(obj.runpath, obj.casepath)
ishere = true;
else
ishere = false;
end
try
obj.meanFlow = meanSlice(obj.blk,obj.gas,obj.bcs,obj.runpath,obj.casetype,ishere);
catch
try
data = load(fullfile(obj.runpath, 'slicesAve.mat'), 'slicesAve');
obj.meanFlow = data.slicesAve;
fprintf('Read meanSlice computed from averaging slices\n')
catch
fprintf('Could not find mean flow\n')
end
end
end
function inst2mean(obj,slice)
obj.meanFlow = meanSlice(obj.blk,obj.gas,obj.bcs,[]);
obj.meanFlow.ro = slice.ro;
obj.meanFlow.u = slice.u;
obj.meanFlow.v = slice.v;
obj.meanFlow.w = slice.w;
obj.meanFlow.Et = slice.Et;
obj.meanFlow.pbar = slice.p;
obj.meanFlow.Tbar = slice.T;
obj.meanFlow.getBCs;
end
function readMeanFlows(obj, calc_s_unst)
%READMEANFLOWS Read in and average 2D mean flows for multiple
%runs
if nargin < 2
calc_s_unst = false;
end
regions = obj.getIntRegions;
for ir = 1:length(obj.run)
fprintf('Reading meanSlice %d/%d (run %d)\n', [ir length(obj.run) obj.run(ir)])
mF = meanSlice(obj.blk,obj.gas,obj.bcs,obj.runpaths{ir},obj.casetype,false, false);
if ir == 1
obj.meanFlow = mF;
if calc_s_unst
[e_unst_s, ~, ~, ~, ~] = entropy_balance(mF, regions);
end
else
obj.meanFlow.addSlice(mF)
end
if ir == length(obj.run)
if calc_s_unst
[e_unst_e, ~, ~, ~, ~] = entropy_balance(mF, regions);
end
end
clear mF
end
if calc_s_unst
obj.e_unst = e_unst_e - e_unst_s;
end
end
function readPsMeanFlows(obj, calc_s_unst)
%READMEANFLOWS Read in and average 2D mean flows for multiple
%runs
if nargin < 2
calc_s_unst = false;
end
regions = obj.getIntRegions;
for ir = 1:length(obj.run)
fprintf('Reading meanSlice %d/%d (run %d)\n', [ir length(obj.run) obj.run(ir)])
mF = meanSlice(obj.blk,obj.gas,obj.bcs,obj.runpaths{ir},obj.casetype,false, true);
if ir == 1
obj.meanFlowPS = mF;
if calc_s_unst
[e_unst_s, ~, ~, ~, ~] = entropy_balance(mF, regions);
end
else
obj.meanFlowPS.addSlice(mF)
end
if ir == length(obj.run)
if calc_s_unst
[e_unst_e, ~, ~, ~, ~] = entropy_balance(mF, regions);
end
end
clear mF
end
if calc_s_unst
obj.e_unst = e_unst_e - e_unst_s;
end
end
function readInflowTurb(obj)
%READINFLOWTURB Read inflow turbulence file
obj.inflowTurb = volTurbulence(obj.casepath,obj.y_inlet,obj.bcs.ilength,obj.blk.nk,obj.bcs.lturb,obj.solver.span);
end
function readProbes(obj)
f = fopen(fullfile(obj.runpath,'probe.txt'), 'r');
temp = str2num(char(split(fgetl(f))));
obj.nProbes = temp(1);
obj.nSkip = temp(2);
fclose(f);
% for nProbe = 1:obj.nProbes
% temp = str2num(char(split(fgetl(f))));
% blkData.nb = temp(1);
% blkData.i = temp(2);
% blkData.j = temp(3);
% blkData.k = temp(4);
% blkData.x = obj.blk.x{blkData.nb}(blkData.i,blkData.j);
% blkData.y = obj.blk.y{blkData.nb}(blkData.i,blkData.j);
% obj.probes{nProbe} = dnsProbe(obj.runpath, nProbe, obj.nSkip, blkData, obj.gas);
% end
[obj.probes, obj.nProbes, obj.nSkip] = obj.readRunProbes(obj.runpaths{1});
if length(obj.run) > 1
for ir = 2:length(obj.run)
[probesNow, nProbesNow, nSkipNow] = obj.readRunProbes(obj.runpaths{ir});
if nProbesNow ~= obj.nProbes
fprintf('nProbes mismatch\n');
return
elseif nSkipNow ~= obj.nSkip
fprintf('nSkip mismatch\n');
return
else
for ip = 1:obj.nProbes
obj.probes{ip}.concatenate(probesNow{ip});
end
end
end
end
end
function [probes, nProbes, nSkip] = readRunProbes(obj, path)
path
f = fopen(fullfile(path,'probe.txt'), 'r');
temp = str2num(char(split(fgetl(f))));
nProbes = temp(1);
nSkip = temp(2);
for nProbe = 1:obj.nProbes
temp = str2num(char(split(fgetl(f))));
blkData.nb = temp(1);
blkData.i = temp(2);
blkData.j = temp(3);
blkData.k = temp(4);
blkData.x = obj.blk.x{blkData.nb}(blkData.i,blkData.j);
blkData.y = obj.blk.y{blkData.nb}(blkData.i,blkData.j);
probes{nProbe} = dnsProbe(path, nProbe, nSkip, blkData, obj.gas);
end
fclose(f);
end
function addProbe(obj, nb, i, j, k)
blkData.nb = nb;
blkData.i = i;
blkData.j = j;
if nargin < 5
blkData.k = obj.solver.nk/2;
else
blkData.k = k;
end
blkData.x = obj.blk.x{blkData.nb}(blkData.i,blkData.j);
blkData.y = obj.blk.y{blkData.nb}(blkData.i,blkData.j);
obj.probes{end+1} = dnsProbe([], obj.nProbes+1, obj.nSkip, blkData, obj.gas);
if isempty(obj.nProbes)
obj.nProbes = 1;
else
obj.nProbes = obj.nProbes + 1;
end
end
function addProbes(obj, newProbes)
for i = 1:length(newProbes)
blkData.nb = newProbes{i}.nb;
blkData.i = newProbes{i}.i;
blkData.j = newProbes{i}.j;
blkData.k = newProbes{i}.k;
blkData.x = obj.blk.x{blkData.nb}(blkData.i,blkData.j);
blkData.y = obj.blk.y{blkData.nb}(blkData.i,blkData.j);
obj.probes{end+1} = dnsProbe([], obj.nProbes+1, obj.nSkip, blkData, obj.gas);
end
if isempty(obj.nProbes)
obj.nProbes = length(newProbes);
else
obj.nProbes = obj.nProbes + length(newProbes);
end
end
function removeProbes(obj, rmProbes)
for i = rmProbes
obj.probes(i) = [];
obj.nProbes = obj.nProbes-1;
end
end
function plot_probes(obj, nProbe, ax)
if nargin<3 || isempty(ax)
ax = gca;
end
if nargin < 2 || isempty(nProbe)
probes_to_plot = 1:obj.nProbes;
else
probes_to_plot = nProbe;
end
hold on
C = colororder;
sz = 25;
for ip = probes_to_plot
scatter(ax, obj.probes{ip}.x, obj.probes{ip}.y, sz, C(mod(ip-1,7)+1,:), 'filled')
end
end
function writeProbeInput(obj, path)
if nargin < 2
path = obj.casepath;
end
f = fopen(fullfile(path, 'probe.txt'), 'w');
fprintf(f,'%d %d\n',[obj.nProbes obj.nSkip]);
for ip = 1:obj.nProbes
fprintf(f,'%d %d %d %d\n', [obj.probes{ip}.nb obj.probes{ip}.i obj.probes{ip}.j obj.probes{ip}.k]);
end
fclose(f);
end
function s = kPlot(obj,slice,prop, varargin) % ax,lims,label,viewarea,nrepeats, rot)
defaultAx = gca;
defaultLims = [];
defaultLabel = [];
if ~isempty(obj.blk.viewarea)
defaultViewArea = obj.blk.viewarea;
else
defaultViewArea = [];
end
if isfield(obj.blk, "n_pitchwise_repeats")
defaultRepeats = obj.blk.n_pitchwise_repeats;
else
defaultRepeats = 1;
end
defaultRot = 0;
p = inputParser;
addParameter(p, 'ax', defaultAx);
addParameter(p, 'lims', defaultLims);
addParameter(p, 'label', defaultLabel);
addParameter(p, 'viewarea', defaultViewArea);
addParameter(p, 'nrepeats', defaultRepeats);
addParameter(p, 'rot', defaultRot);
addParameter(p, 'Interpreter', 'none');
addParameter(p, 'ColorMap', 'parula')
parse(p, varargin{:});
lims = p.Results.lims;
label = p.Results.label;
repeats = p.Results.nrepeats;
R = [cosd(p.Results.rot) -sind(p.Results.rot); sind(p.Results.rot) cosd(p.Results.rot)];
ax = p.Results.ax(1);
f = gcf;
if ischar(prop) || isstring(prop)
storedq = true;
if isempty(slice)
q = obj.(prop);
else
if strcmp(prop, "overlay")
q = slice.schlieren;
q2 = slice.vortZ;
else
q = slice.(prop);
end
end
else
storedq = false;
q = prop;
end
offset = 0;
if repeats > 2
offset = -obj.pitch;
end
axes(ax);
hold on
for ir = 1:repeats
for i=1:obj.NB
xnow = obj.blk.x{i};
ynow = obj.blk.y{i}+offset+(ir-1)*obj.pitch;
ni = size(xnow,1);
coords = [reshape(xnow, 1, []); reshape(ynow, 1, [])];
coords = R' * coords;
xnow = reshape(coords(1,:), ni, []);
ynow = reshape(coords(2,:), ni, []);
s = pcolor(ax, xnow, ynow, q{i});
end
end
shading('interp')
axis equal
if ~isempty(p.Results.viewarea)
aspect = [(p.Results.viewarea(2)-p.Results.viewarea(1)) (p.Results.viewarea(4)-p.Results.viewarea(3)) 1];
pbaspect(aspect)
axis(p.Results.viewarea);
end
if storedq
if string(prop) == "schlieren" || string(prop) == "overlay"
colormap(ax,gray)
map = colormap(ax);
map = flip(map,1);
colormap(ax,map);
if isempty(label)
label = '$|\nabla \rho|/\rho$';
end
elseif ismember(string(prop),["vortZ","v","w", "advK"])
val = max(abs(caxis));
caxis(ax,[-val val]);
colormap(redblue)
elseif string(prop) == "M" && string(p.Results.ColorMap) == "redblue"
if isempty(lims)
lims = [0 2];
end
colormap(ax,redblue)
end
end
colorbar('off');
cb = colorbar;
if string(prop) == "overlay"
if size(lims, 1) == 2
caxis(ax,lims(2, :));
else
caxis(ax,[0 100]);
end
elseif ~isempty(lims)
caxis(ax,lims);
end
if ~isempty(label)
cb.Label.Interpreter = 'latex';
cb.Label.String = label;
end
if string(prop) == "overlay"
axes(ax);
axis off
area = axis(ax);
axis on
if length(p.Results.ax) > 1
ax2 = p.Results.ax(2);
else
h = findobj('Type', 'Axes');
if length(h) > 1
ax2 = h(h~=ax);
cla(ax2);
else
ax2 = axes(f);
end
end
axes(ax2);
cla(ax2);
hold on
a =2000;
b = 2000;
maxnow = 0;
for ir = 1:repeats
for i=1:obj.NB
xnow = obj.blk.x{i};
ynow = obj.blk.y{i}+offset+(ir-1)*obj.pitch;
ni = size(xnow,1);
coords = [reshape(xnow, 1, []); reshape(ynow, 1, [])];
coords = R' * coords;
xnow = reshape(coords(1,:), ni, []);
ynow = reshape(coords(2,:), ni, []);
om = abs(q2{i});
mask = 0.5*(1+tanh((om-a)/b));
s = pcolor(ax2, xnow, ynow, q2{i});
alpha(s, mask);
maxnow = max(maxnow, max(abs(q2{i}), [], 'all'));
end
end
shading('interp')
axis equal
% area = axis(ax);
axis(area);
aspect = [(area(2)-area(1)) (area(4)-area(3)) 1];
pbaspect(aspect);
axis off
colormap(ax2, redblue);
if ~isempty(lims)
caxis(ax2, lims(1,:));
else
caxis(ax2, [-maxnow maxnow]);
end
set(ax2, 'Position', get(ax, 'Position'));
f.SizeChangedFcn = @copy_fig_size;
end
function copy_fig_size(src, ~)
a2 = src.Children(end);
a1 = src.Children(1);
set(a2, 'Position', get(a1, 'Position'));
end
end
function p = plotInletProf(obj,slice,prop,ax)
if nargin < 4 || isempty(ax)
ax = gca;
end
propnow = [];
ynow = [];
for nb = obj.blk.inlet_blocks{1}
ynow = [ynow; obj.blk.y{nb}(1,:)];
propnow = [propnow; slice.(prop){nb}(1,:)];
end
[ynow, inds] = unique(ynow);
propnow = propnow(inds);
p = plot(ax,propnow,ynow);
end
function [q,ynow] = getInletProf(obj,slice,prop)
propnow = [];
ynow = [];
for nb = obj.blk.inlet_blocks{1}
ynow = [ynow; obj.blk.y{nb}(1,:)];
propnow = [propnow; slice.(prop){nb}(1,:)];
end
[ynow, inds] = unique(ynow);
propnow = propnow(inds);
[ynow, inds] = sort(ynow);
propnow = propnow(inds);
q = propnow;
end
function flipbook(obj,slices, prop, varargin)
p = inputParser;