-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjSlice.m
231 lines (199 loc) · 7.23 KB
/
jSlice.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
classdef jSlice < handle
% JSLICE Contains a 2D slice of the flow next to the blade surface
% Detailed explanation goes here
properties
NB;
blk;
gas;
bcs;
ro;
u;
v;
w;
Et;
time;
nSlice;
ssurf;
Y0;
X;
Z;
pdyn; % Freestream dynamic pressure
casepath;
end
properties (Dependent = true)
T;
p;
M;
s;
vel;
mu;
tau_w;
cf;
end
methods
function obj = jSlice(blk, gas, bcs, casedir, nSlice, time, casetype, ishere)
if nargin < 8
ishere = false;
end
if nargin > 0
obj.blk = blk;
obj.gas = gas;
obj.bcs = bcs;
end
if nargin > 3
obj.nSlice = nSlice;
obj.time = time;
obj.ro = [];
obj.u = [];
obj.v = [];
obj.w = [];
obj.Et = [];
obj.NB = size(blk.blockdims,1);
x = [];
y = [];
y0 = [];
if ~ishere
casedir = [casedir '/j_cuts'];
end
for iblk=1:length(blk.oblocks)
nb = blk.oblocks(iblk);
flopath = fullfile(casedir, ['jcu2_' num2str(nb) '_' num2str(nSlice)]);
nodpath = fullfile(casedir, ['jnd2_' num2str(nb) '_' num2str(nSlice)]);
flofile = fopen(flopath,'r');
nodfile = fopen(nodpath,'r');
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);
ro = zeros(blk.blockdims(nb,1),blk.blockdims(nb,3));
ru = zeros(blk.blockdims(nb,1),blk.blockdims(nb,3));
rv = zeros(blk.blockdims(nb,1),blk.blockdims(nb,3));
rw = zeros(blk.blockdims(nb,1),blk.blockdims(nb,3));
Et = zeros(blk.blockdims(nb,1),blk.blockdims(nb,3));
for n=1:size(A,2)
i = B(1,n);
j = B(2,n);
k = B(3,n);
ro(i,k) = A(1,n);
ru(i,k) = A(2,n);
rv(i,k) = A(3,n);
rw(i,k) = A(4,n);
Et(i,k) = A(5,n);
end
xtmp = blk.x{nb}(:,end-1);
ytmp = blk.y{nb}(:,end-1);
dxtmp = blk.x{nb}(:,end-1) - blk.x{nb}(:,end);
dytmp = blk.y{nb}(:,end-1) - blk.y{nb}(:,end);
y0tmp = sqrt(dxtmp.^2+dytmp.^2);
if blk.oblocks_flip(iblk) == 1
ro = flip(ro);
ru = flip(ru);
rv = flip(rv);
rw = flip(rw);
Et = flip(Et);
xtmp = flip(xtmp);
ytmp = flip(ytmp);
y0tmp = flip(y0tmp);
end
obj.ro = [obj.ro; ro(1:end-1,:)];
obj.u = [obj.u; ru(1:end-1,:)./ro(1:end-1,:)];
obj.v = [obj.v; rv(1:end-1,:)./ro(1:end-1,:)];
obj.w = [obj.w; rw(1:end-1,:)./ro(1:end-1,:)];
obj.Et = [obj.Et; Et(1:end-1,:)];
x = [x; xtmp(1:end-1)];
y = [y; ytmp(1:end-1)];
y0 = [y0; y0tmp];
end
x = x';
y = y';
y0 = y0';
[~, iLE] = min(x);
[~, iTE] = max(x);
obj.ro = obj.ro(iLE:iTE,:);
obj.u = obj.u(iLE:iTE,:);
obj.v = obj.v(iLE:iTE,:);
obj.w = obj.w(iLE:iTE,:);
obj.Et = obj.Et(iLE:iTE,:);
x = x(iLE:iTE);
y = y(iLE:iTE);
y0 = y0(iLE:iTE);
obj.ssurf(1) = 0;
for i=2:length(x)
dx = x(i)-x(i-1);
dy = y(i)-y(i-1);
ds = sqrt(dx^2 + dy^2);
obj.ssurf(i) = obj.ssurf(i-1)+ds;
end
z = linspace(0,blk.span,blk.nk);
[obj.Z, obj.X] = meshgrid(z,obj.ssurf);
obj.Y0 = repmat(y0',1,blk.nk);
end
end
function value = get.p(obj)
value = (obj.gas.gam -1)*(obj.Et - 0.5*(obj.u.^2 + obj.v.^2 + obj.w.^2).*obj.ro);
end
function value = get.T(obj)
value = obj.p./(obj.ro*obj.gas.rgas);
end
function value = get.vel(obj)
value = sqrt(obj.u.^2 + obj.v.^2 + obj.w.^2);
end
function value = get.M(obj)
value = obj.vel./sqrt(obj.gas.gam*obj.gas.rgas*obj.T);
end
function value = get.s(obj)
value = obj.gas.cp*log(obj.T/300) - obj.gas.rgas*log(obj.p/1e5);
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 jPlot(obj,prop,ax,lims,label)
if nargin < 3 || isempty(ax)
ax = gca;
end
q = obj.(prop);
dx = abs(obj.X(end,1)-obj.X(1,1));
dy = abs(obj.Z(1,end)-obj.Z(1,1));
pcolor(ax, obj.X, obj.Z, q);
xlabel('Surface distance')
shading('interp')
axis equal
cb = colorbar('southoutside');
if nargin > 3 && ~isempty(lims)
caxis(lims);
end
if nargin > 4 && ~isempty(label)
cb.Label.String = label;
cb.FontSize = 9;
end
pbaspect(ax, [dx dy dx]);
set(ax, 'FontSize', 9)
end
function value = get.mu(obj)
disp('Calcualting mu')
pnow = (obj.gas.gam - 1)*(obj.Et - 0.5*(obj.u.^2 + obj.v.^2 + obj.w.^2).*obj.ro);
Tnow = pnow./(obj.ro*obj.gas.rgas);
value = 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
function value = get.tau_w(obj)
value = obj.mu.*obj.vel./obj.Y0;
end
function value = get.cf(obj)
q = obj.pdyn;
if ~isempty(q)
value = obj.tau_w./repmat(obj.pdyn',[1 size(obj.tau_w,2)]);
else
fprintf('Set jSlice dynamic pressure before calculating cf\n')
end
end
end
end