-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmeanSlice2.m
217 lines (183 loc) · 7.57 KB
/
meanSlice2.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
classdef meanSlice2
% MEANSLICE Contains the 2D (spanwise averaged) mean flow
properties
NB;
gam;
cp;
rgas;
ro;
u;
v;
w;
Et;
time;
nMean;
meanTime;
oblocks;
oblocks_flip;
p0in;
end
properties (Dependent = true)
T; % Temperature
p; % p stat
M; % Mach No
s; % Entropy ( cp*log(T/300) - R*log(p/1e5) )
vel; % Velocity
Msurf; % Surface Mach No
Pr; % Turbulence production
end
methods
function obj = meanSlice2(casedir, blk, gas)
nstats = 17;
obj.oblocks = blk.oblocks;
obj.oblocks_flip = blk.oblocks_flip;
if nargin > 0
obj.gam = gas.gam;
obj.cp = gas.cp;
obj.rgas = obj.cp*(1-1/obj.gam);
obj.NB = size(blk.blockdims,1);
fid = fopen(fullfile(casedir, 'mean_flo', 'mean_time.txt'));
while ~feof(fid) % Use lastest mean files
temp=fgetl(fid);
end
fclose(fid);
temp = str2num(temp);
obj.nMean = temp(1);
obj.meanTime = temp(3);
for nb = 1:obj.NB
flopath = fullfile(casedir, 'mean_flo', ['mean2_' num2str(nb) '_' num2str(obj.nMean)]);
flofile = fopen(flopath,'r');
nodfile = fopen(fullfile(casedir, 'mean_flo', ['mnod2_' num2str(nb) '_' num2str(obj.nMean)]),'r');
A = fread(flofile,inf,'float64');
A = reshape(A,nstats,length(A)/nstats);
B = fread(nodfile,inf,'uint32');
B = reshape(B,3,length(B)/3);
fclose(flofile);
fclose(nodfile);
rodt = zeros(blk.blockdims(nb,1),blk.blockdims(nb,2));
rudt = zeros(blk.blockdims(nb,1),blk.blockdims(nb,2));
rvdt = zeros(blk.blockdims(nb,1),blk.blockdims(nb,2));
rwdt = zeros(blk.blockdims(nb,1),blk.blockdims(nb,2));
Etdt = zeros(blk.blockdims(nb,1),blk.blockdims(nb,2));
ro2 = zeros(blk.blockdims(nb,1),blk.blockdims(nb,2));
rou2 = zeros(blk.blockdims(nb,1),blk.blockdims(nb,2));
rov2 = zeros(blk.blockdims(nb,1),blk.blockdims(nb,2));
row2 = zeros(blk.blockdims(nb,1),blk.blockdims(nb,2));
rouv = zeros(blk.blockdims(nb,1),blk.blockdims(nb,2));
rouw = zeros(blk.blockdims(nb,1),blk.blockdims(nb,2));
rovw = zeros(blk.blockdims(nb,1),blk.blockdims(nb,2));
p2 = zeros(blk.blockdims(nb,1),blk.blockdims(nb,2));
p = zeros(blk.blockdims(nb,1),blk.blockdims(nb,2));
T = zeros(blk.blockdims(nb,1),blk.blockdims(nb,2));
ros = zeros(blk.blockdims(nb,1),blk.blockdims(nb,2));
diss = zeros(blk.blockdims(nb,1),blk.blockdims(nb,2));
for n=1:size(A,2)
i = B(1,n);
j = B(2,n);
k = B(3,n);
rodt(i,j) = A(1,n);
rudt(i,j) = A(2,n);
rvdt(i,j) = A(3,n);
rwdt(i,j) = A(4,n);
Etdt(i,j) = A(5,n);
ro2(i,j) = A(6,n);
rou2(i,j) = A(7,n);
rov2(i,j) = A(8,n);
row2(i,j) = A(9,n);
rouv(i,j) = A(10,n);
rouw(i,j) = A(11,n);
rovw(i,j) = A(12,n);
p2(i,j) = A(13,n);
p(i,j) = A(14,n);
T(i,j) = A(15,n);
ros(i,j) = A(16,n);
diss(i,j) = A(17,n);
end
obj.ro{nb} = rodt/obj.meanTime;
obj.u{nb} = rudt./(rodt);
obj.v{nb} = rvdt./(rodt);
obj.w{nb} = rwdt./(rodt);
obj.Et{nb} = Etdt/obj.meanTime;
end
end
Mnow = obj.M;
%Mnow = Mnow{blk.inlet_blocks{1}};
pnow = obj.p;
%pnow = pnow{blk.inlet_blocks{1}};
p0 = [];
for i=1:length(blk.inlet_blocks{1})
p0now = pnow{blk.inlet_blocks{1}(i)}.*(1+((obj.gam - 1)/2)*Mnow{blk.inlet_blocks{1}(i)}.^2).^(obj.gam/(obj.gam-1));
p0 = [p0 p0now(40:100,:)];
end
obj.p0in = mean(p0,'all');
end
function value = get.p(obj)
disp('Calculating p')
value = cell(1,obj.NB);
for nb =1:obj.NB
value{nb} = (obj.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)
disp('Calculating T')
value = cell(1,obj.NB);
for nb =1:obj.NB
pnow = (obj.gam -1)*(obj.Et{nb} - 0.5*(obj.u{nb}.^2 + obj.v{nb}.^2 + obj.w{nb}.^2).*obj.ro{nb});
value{nb} = pnow./(obj.ro{nb}*obj.rgas);
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.M(obj)
disp('Calculating M')
value = cell(1,obj.NB);
for nb =1:obj.NB
pnow = (obj.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.rgas);
velnow = sqrt(obj.u{nb}.^2 + obj.v{nb}.^2 + obj.w{nb}.^2);
value{nb} = velnow./sqrt(obj.gam*obj.rgas*Tnow);
end
end
function value = get.s(obj)
disp('Calculating s')
value = cell(1,obj.NB);
for nb =1:obj.NB
pnow = (obj.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.rgas);
value{nb} = obj.cp*log(Tnow/300) - obj.rgas*log(pnow/1e5);
end
end
function value = get.Msurf(obj)
disp('Calculating surface M')
psurf = [];
pnow = obj.p;
size(pnow{4})
for i=1:length(obj.oblocks)
clear temp
temp = pnow{obj.oblocks(i)}(:,end);
size(temp)
if obj.oblocks_flip(i) == 1
i
temp = flip(temp);
end
psurf = [psurf temp'];
end
value = sqrt((2/(obj.gam - 1)) * ( (psurf/obj.p0in).^(-(obj.gam-1)/obj.gam) - 1));
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
end
end