-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRANSSlice.m
229 lines (191 loc) · 7.51 KB
/
RANSSlice.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
classdef RANSSlice < aveSlice
% MEANSLICE Contains the 2D (spanwise averaged) mean flow
properties
%blk;
turb_model;
solver;
StR_store; % Strain rate
mut_store; % Eddy viscosity
mut_ratio_store; % Eddy viscosity ratio
Pr_store;
% StR;
% mut;
k;
omega;
Reth;
gamma;
trans; % Transition model on/off
mod; % beta1 modification on/off
beta1_fac;
metadata;
end
properties (Dependent = true, Hidden = true)
Pr; % Turbulence production
Pr_dist;
end
methods
function obj = RANSSlice(blk, gas, bcs, solver, path)
obj@aveSlice(blk, gas, bcs);
disp('Constructing RANSSlice')
if nargin > 3
obj.solver = solver;
switch solver
case '3dns'
% Get latest mean_count
[~, folder] = fileparts(path);
if strcmp(string(folder(1:3)), "run")
fid = fopen(fullfile(path, 'mean_flo', 'mean_time.txt'),'r');
else
fid = fopen(fullfile(path, 'mean_time.txt'),'r');
end
while ~feof(fid) % Use lastest mean files
temp=fgetl(fid);
end
fclose(fid);
temp = str2num(temp);
mean_count = temp(1);
for ib = 1:obj.NB
ni = blk.blockdims(ib,1);
nj = blk.blockdims(ib,2);
nk = blk.blockdims(ib,3);
flowpath = fullfile(path, sprintf('flow2_%d_%d', [ib mean_count]));
f = dir(flowpath);
flofile = fopen(flowpath);
ransfile = fopen(fullfile(path, sprintf('rans_%d', ib)));
nstats = f.bytes/(ni*nj*8);
A = fread(flofile,ni*nj*nstats,'float64');
A = reshape(A,nstats,[])';
fclose(flofile);
obj.ro{ib} = reshape(A(:,1),ni,nj);
obj.u{ib} = reshape(A(:,2),ni,nj)./obj.ro{ib};
obj.v{ib} = reshape(A(:,3),ni,nj)./obj.ro{ib};
obj.w{ib} = reshape(A(:,4),ni,nj)./obj.ro{ib};
obj.Et{ib} = reshape(A(:,5),ni,nj);
A = fread(ransfile,ni*nj*nk,'float64');
A = reshape(A,ni,nj,nk);
fclose(ransfile);
obj.mut_ratio_store{ib} = mean(A,3);
end
end
end
end
function contours = kPlot(obj,prop,ax,lims,label)
disp('here')
if nargin < 3 || isempty(ax)
ax = gca;
end
q = obj.(prop);
hold on
for i=1:obj.NB
contours{i} = pcolor(ax, obj.blk.x{i}, obj.blk.y{i}, q{i});
end
shading('interp')
% pbaspect([6 2 1])
% axis([0.3 0.9 0 0.2])
%axis equal
%axis off
cb = colorbar('southoutside');
if prop == 'M'
cb.Label.String = 'M';
cb.Label.Interpreter = 'latex';
end
if nargin > 3 && ~isempty(lims)
caxis(lims)
end
if nargin > 4 && ~isempty(label)
cb.Label.String = label;
cb.Label.Interpreter = 'latex';
end
axis equal
if ~isempty(obj.blk.viewarea)
aspect = [(obj.blk.viewarea(2)-obj.blk.viewarea(1)) (obj.blk.viewarea(4)-obj.blk.viewarea(3)) 1];
pbaspect(aspect)
axis(obj.blk.viewarea);
end
end
function value = get.Pr(obj)
value = cell(1,obj.NB);
if ~isempty(obj.Pr_store)
disp('Using stored Pr')
value = obj.Pr_store;
elseif ~isempty(obj.mut_store)
disp('Calculating Pr: using stored mut')
deltaij(1,1,:,:) = [1 0 0; 0 1 0; 0 0 1];
St_an_now = obj.St_an;
vgrad = obj.duidxj;
for nb = 1:obj.NB
tauij = 2*obj.mut_store{nb}.*St_an_now{nb} - (2/3)*(obj.ro{nb}.*obj.k{nb}).*deltaij;
value{nb} = sum(sum(vgrad{nb}.*tauij, 4), 3);
end
elseif ~isempty(obj.mut_ratio_store)
disp('Calculating Pr: using stored mut ratio')
deltaij(1,1,:,:) = [1 0 0; 0 1 0; 0 0 1];
St_an_now = obj.St_an;
vgrad = obj.duidxj;
munow = obj.mu;
for nb = 1:obj.NB
tauij = 2*munow{nb}.*obj.mut_ratio_store{nb}.*St_an_now{nb} - (2/3)*(obj.ro{nb}.*obj.k{nb}).*deltaij;
value{nb} = sum(sum(vgrad{nb}.*tauij, 4), 3);
end
else
disp('Calculating Pr with k-om SST formulation')
value = obj.mut_koSST;
end
end
function value = get_StR(obj)
if isempty(obj.StR_store)
value = cell(1,obj.NB);
for nb =1:obj.NB
disp('Calculating strain rate magnitude')
value{nb} = strain_rate_magnitude(obj.blk.x{nb}, obj.blk.y{nb}, obj.u{nb}, obj.v{nb});
end
else
disp('Using stored strain rate magnitude')
value = obj.StR_store;
end
end
function value = mut_koSST(obj)
value = cell(1,obj.NB);
StRnow = obj.StR;
for ib = 1:obj.NB
arg2 = max(2*sqrt(obj.k{ib})./(0.09*obj.omega{ib}.*obj.wallDist{ib}), ...
500*obj.nu{ib}./(obj.omega{ib}.*obj.wallDist{ib}.^2));
F2 = tanh(arg2.^2);
mutnow = 0.31*obj.ro{ib}.*obj.k{ib}./max(0.31*obj.omega{ib}, StRnow{ib}.*F2);
value{ib} = mutnow.*StRnow{ib}.^2;
end
end
function value = Pr_koSST(obj)
value = cell(1,obj.NB);
end
function obj.set_mut(obj, value)
obj.mut_store = value;
end
function value = get_mut(obj)
if ~isempty(obj.mut_store)
value = obj.mut_store;
elseif ~isempty(obj.mut_ratio_store)
munow = obj.mu;
for ib = 1:obj.NB
value{ib} = munow{ib}.*obj.mut_ratio_store{ib};
end
end
end
function value = get_mut_ratio(obj)
if ~isempty(obj.mut_ratio_store)
value = obj.mut_ratio_store;
else
mutnow = obj.mut;
munow = obj.mu;
for ib = 1:obj.NB
value{ib} = mutnow{ib}./munow{ib};
end
end
end
function value = mut_opt_cleaned(obj,smoothwindow)
if nargin < 2
end
value = obj.mut;
end
end
end