-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkSlice.m
165 lines (139 loc) · 5.88 KB
/
kSlice.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
classdef kSlice < kCut
% KSLICE Contains a 2D slice of the flow at k-boundary
% Detailed explanation goes here
properties
time;
nSlice;
casepath;
end
properties (Dependent = true, Hidden = true)
% T;
% p;
% M;
% s;
% vel;
end
methods
function obj = kSlice(blk, gas, bcs, casedir, nSlice, time, casetype, ishere)
obj@kCut(blk, gas, bcs);
disp('Constructing kSlice')
if nargin < 8
ishere = false;
end
if nargin > 3
if nargin > 2
if ~ischar(nSlice)
obj.nSlice = nSlice;
obj.time = time;
end
obj.casepath = casedir;
for nb = 1:obj.NB
ni = blk.blockdims(nb,1);
nj = blk.blockdims(nb,2);
ro = zeros(ni,nj);
ru = zeros(ni,nj);
rv = zeros(ni,nj);
rw = zeros(ni,nj);
Et = zeros(ni,nj);
switch casetype
case 'cpu'
if ishere
flopath = fullfile(casedir, ['kcu2_' num2str(nb) '_' num2str(nSlice)]);
flofile = fopen(flopath,'r');
nodfile = fopen(fullfile(casedir, ['knd2_' num2str(nb) '_' num2str(nSlice)]),'r');
else
flopath = fullfile(casedir, 'k_cuts', ['kcu2_' num2str(nb) '_' num2str(nSlice)]);
flofile = fopen(flopath,'r');
nodfile = fopen(fullfile(casedir, 'k_cuts', ['knd2_' num2str(nb) '_' num2str(nSlice)]),'r');
end
A = fread(flofile,inf,'float64');
A = reshape(A,5,length(A)/5);
B = fread(nodfile,inf,'uint32');
B = reshape(B,3,length(B)/3);
fclose(flofile);
fclose(nodfile);
for n=1:size(A,2)
i = B(1,n);
j = B(2,n);
k = B(3,n);
ro(i,j) = A(1,n);
ru(i,j) = A(2,n);
rv(i,j) = A(3,n);
rw(i,j) = A(4,n);
Et(i,j) = A(5,n);
end
case 'gpu'
if ischar(nSlice)
fid = fopen(fullfile(casedir, [nSlice '_' num2str(nb)]));
else
if ishere
fid = fopen(fullfile(casedir, ['kcut_' num2str(nb) '_' num2str(nSlice)]));
else
fid = fopen(fullfile(casedir, 'k_cuts', ['kcut_' num2str(nb) '_' num2str(nSlice)]));
end
end
A = fread(fid, ni*nj*5, 'float64');
A = reshape(A, 5, length(A)/5)';
ro = reshape(A(:,1),ni,nj);
ru = reshape(A(:,2),ni,nj);
rv = reshape(A(:,3),ni,nj);
rw = reshape(A(:,4),ni,nj);
Et = reshape(A(:,5),ni,nj);
end
obj.ro{nb} = ro;
obj.u{nb} = ru./ro;
obj.v{nb} = rv./ro;
obj.w{nb} = rw./ro;
obj.Et{nb} = Et;
end
end
end
end
% function value = get.vel(obj)
% 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.M(obj)
% value = cell(1,obj.NB);
% for nb =1:obj.NB
% value{nb} = obj.vel{nb}./sqrt(obj.gas.gam*obj.gas.rgas*obj.T{nb});
% end
% end
%
% function value = get.s(obj)
% value = cell(1,obj.NB);
% for nb =1:obj.NB
% value{nb} = obj.gas.cp*log(obj.T{nb}/300) - obj.gas.rgas*log(obj.p{nb}/1e5);
% end
% end
% function value = get.vortZ(obj)
% value = cell(1,obj.NB);
% for nb =1:obj.NB
% [~,DUDY] = gradHO(obj.blk.x{nb},obj.blk.y{nb},obj.u{nb});
% [DVDX,~] = gradHO(obj.blk.x{nb},obj.blk.y{nb},obj.v{nb});
% value{nb} = DVDX-DUDY;
% end
% end
function getSize(obj)
props = properties(obj);
totSize = 0;
for ii=1:length(props)
currentProperty = getfield(obj, char(props(ii)));
temp = whos('currentProperty');
totSize = totSize + temp.bytes;
end
fprintf(1, '%d MB\n', totSize/1e6);
end
function value = inst2ave(obj)
value = aveSlice(obj.blk, obj.gas);
value.ro = obj.ro;
value.u = obj.u;
value.v = obj.v;
value.w = obj.w;
value.Et = obj.Et;
end
end
end