-
Notifications
You must be signed in to change notification settings - Fork 1
/
pois2D_july13_RegBC_Double.m
430 lines (328 loc) · 13.2 KB
/
pois2D_july13_RegBC_Double.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
%pois2D_july12.m
% for Pouiseuille flow, I want to be able to measure
% 1. Numerical convergence
% 2. Stabilization rate
% compare both for Zou/He and Regularized BCs
% compare both for LBGK and MRT
% provide parabolic inlet velocity profile for convergence testing.
% provide uniform inlet velocity profile to show flow development.
clear
clc
close('all')
location = 'office';
% 'home', 'office', 'hamming'
dynamics = 1;
% 1 =LBGK
% 2 = RBGK
% 3 = MRT
BC_type = 2;
% 1 = Zou/He
% 2 = Regularized
Boundary_Dynamics=6;
% 6 = Zou/He + MRT DP
Num_ts = 1500000;
ts_rep_freq = 1000;
plot_freq = 300000;
Re = 10;
dt = 1e-3/64;
Ny_divs = 240;
obst_type = 'none';
% 'none'
sim_name = 'pois2D_convergence';
ts_num=0;
Lx_p = 10;
Ly_p = 1;
switch obst_type
case 'none'
Lo = Ly_p;
end
fluid = 4;
switch fluid
case 1
rho_p = 1260;
nu_p = 1.49/rho_p;
case 2
rho_p = 965.3;
nu_p = 0.06/rho_p;
case 3
rho_p = 1000;
nu_p = 1e-3/rho_p;
case 4
rho_p = 1000;
nu_p = 0.001;
end
% non-dimensionalize and set up LBM lattice
Uo = nu_p*Re/Lo;
To = Lo/Uo;
Uavg = Uo;
Ld = 1; Td = 1; Ud = (To/Lo)*Uavg;
nu_d = 1/Re;
dx = 1/(Ny_divs-1);
u_lbm = (dt/dx)*Ud;
nu_lbm=(dt/(dx^2))*nu_d;
omega = get_BGK_Omega(nu_lbm);
u_conv_fact = (dt/dx)*(To/Lo);
t_conv_fact = (dt*To);
l_conv_fact = dx*Lo;
p_conv_fact = ((l_conv_fact/t_conv_fact)^2)*(1/3); % <--for EOS type methods...
rho_lbm = rho_p;
rho_out = rho_lbm;
% generate LBM lattice
xm = 0; xp = Lx_p;
ym = 0; yp = Ly_p;
Ny = ceil((Ny_divs-1)*(Ly_p/Lo))+1;
Nx = ceil((Ny_divs-1)*(Lx_p/Lo))+1;
[gcoord,~,~]=RecMesh(xm,xp,ym,yp,Nx,Ny);
[nnodes,~]=size(gcoord);
x_space = linspace(xm,xp,Nx);
y_space = linspace(ym,yp,Ny);
[X,Y]=meshgrid(x_space,y_space);
[w,ex,ey,bb_spd]=D2Q9_lattice_parameters();
%stream_tgt = genTargetVecD2Q9r2(Nx,Ny);
LatticeSize = [Nx Ny];
LatticeSpeeds = [ex; ey];
stm = genStreamTgtMat(LatticeSize,LatticeSpeeds);
numSpd=9;
M = getMomentMatrix('D2Q9');
switch dynamics
case 1
S = omega.* eye(numSpd);
case 2
% TRT model as described in Kevin Tubbs' dissertation section 3.4
S = zeros(numSpd);
S(2,2)= omega;
S(3,3)=omega;
S(8,8)=omega;
S(9,9)=omega;
t_s = (1/2)+1/(12*((1/omega)-0.5));
S(5,5)=1/t_s;
S(7,7)=1/t_s;
case 3
% parameters taken from
% Chinese Physics Vol 15 No 8 Aug 2006
% Simulating high Reynolds number flow in 2D lid driven cavity by
% MRT etc...
S = zeros(numSpd);
S(2,2)=1.1;
S(3,3)=1.0;
S(5,5)=1.2;
S(7,7)=1.2;
S(8,8)=omega;
S(9,9)=omega;
end
omega_op = M\(S*M);
% set node lists
snl=find((gcoord(:,2)==ym) | (gcoord(:,2)==yp));
inl=find(gcoord(:,1)==xm);
inl=setxor(inl,intersect(snl,inl)); % eliminate solid nodes from inlet list
onl=find(gcoord(:,1)==xp);
onl=setxor(onl,intersect(snl,onl)); % eliminate solid nodes from outlet list
% modify for obstructions
switch obst_type
case 'none'
% nothing to do here...
end
Umax = (3/2)*u_lbm;
by = Ly_p/2;
ux_p_in = Umax*(1-((gcoord(inl,2)-by)/by).^2);
uy_p_in = zeros(length(ux_p_in),1);
ux_theory = [0;ux_p_in;0]; ux_theory = (ux_theory')./u_conv_fact;
pltX = ceil(3*Nx/4);
pltX_xcoord= x_space(pltX);
pltX_list = find(gcoord(:,1)==pltX_xcoord);
[fIn,fOut,rho,ux,uy]=Initialize_F_zero(gcoord,ex,ey,w,rho_lbm);
fEq = zeros(nnodes,numSpd);
v_data = zeros(Num_ts,1);
v_data_LP = ceil(Ny/2)*Nx+ceil(Nx/2);
u_data = zeros(Num_ts,1);
p_ref = rho_out*p_conv_fact;
fprintf('Number of Lattice-points = %d.\n',nnodes);
fprintf('Number of time-steps = %d. \n',Num_ts);
fprintf('LBM viscosity = %g. \n',nu_lbm);
fprintf('LBM relaxation parameter (omega) = %g. \n',omega);
fprintf('LBM flow Mach number = %g. \n',u_lbm);
input_string = sprintf('Do you wish to continue? [Y/n] \n');
run_dec = input(input_string,'s');
if ((run_dec ~= 'n') && (run_dec ~= 'N'))
fprintf('Ok! Cross your fingers!! \n');
% add paths for Jacket libraries
switch location
case 'home'
addpath('/usr/local/jacket/engine');
addpath('/home/stu/Dropbox/matlab/jacketSDK/pc_pois2D_velBCs');
addpath('/home/stu/Dropbox/matlab/jacketSDK/bounce_back_jkt');
addpath('/home/stu/Dropbox/matlab/jacketSDK/stream_jkt');
addpath('/home/stu/Dropbox/matlab/jacketSDK/pois2D_LBGK_ts');
addpath('/home/stu/Dropbox/matlab/jacketSDK/channel2D_VW_PE_LBGK_ts');
addpath('/home/stu/Dropbox/matlab/jacketSDK/channel2D_RegVwPe_LBGK_ts');
addpath('/home/stu/Dropbox/matlab/jacketSDK/channel2D_RegVwPe_RBGK_ts');
addpath('/home/stu/Dropbox/matlab/jacketSDK/channel2D_RegVwPe_MRT_ts');
addpath('/home/stu/Dropbox/matlab/jacketSDK/channel2D_VW_PE_MRT_ts');
addpath('/home/stu/Dropbox/matlab/jacketSDK/channel2D_VW_PE_MRT_DPts');
case 'office'
addpath('/usr/local/jacket/engine');
addpath('/home/srblair/Dropbox/matlab/jacketSDK/pc_pois2D_velBCs');
addpath('/home/srblair/Dropbox/matlab/jacketSDK/bounce_back_jkt');
addpath('/home/srblair/Dropbox/matlab/jacketSDK/stream_jkt');
addpath('/home/srblair/Dropbox/matlab/jacketSDK/pois2D_LBGK_ts');
addpath('/home/srblair/Dropbox/matlab/jacketSDK/channel2D_VW_PE_LBGK_ts');
addpath('/home/srblair/Dropbox/matlab/jacketSDK/channel2D_RegVwPe_LBGK_ts');
addpath('/home/srblair/Dropbox/matlab/jacketSDK/channel2D_RegVwPe_RBGK_ts');
addpath('/home/srblair/Dropbox/matlab/jacketSDK/channel2D_RegVwPe_MRT_ts');
addpath('/home/srblair/Dropbox/matlab/jacketSDK/channel2D_VW_PE_MRT_ts');
addpath('/home/srblair/Dropbox/matlab/jacketSDK/channel2D_VW_PE_MRT_DPts');
case 'hamming'
end
% send data to the GPU
fIn = gdouble(fIn);
fOut = gdouble(fOut);
fEq = gdouble(fEq);
ux_p_h = zeros(nnodes,1); ux_p_h(inl)=ux_p_in; ux_p_h(onl)=ux_p_in;
ux_p = gdouble(ux_p_h);
%rho = gdouble(nnodes,1);
%ux = gdouble(nnodes,1);
%uy = gdouble(nnodes,1);
inl_i = zeros(nnodes,1); inl_i(inl)=1; inl_d = gint32(inl_i);
onl_i = zeros(nnodes,1); onl_i(onl)=1; onl_d = gint32(onl_i);
snl_i = zeros(nnodes,1); snl_i(snl)=1; snl_d = gint32(snl_i);
omega_op = gdouble(omega_op);
% prep stuff for writing to vtk
uz_h = zeros(nnodes,1);
gcoord_z = zeros(nnodes,1);
%stm_d = gint32(stm);
%bb_spd_d = gint32(bb_spd);
%commence time stepping
tic;
for ts = 1:Num_ts
% say something comforting about my progress...
if(mod(ts,ts_rep_freq)==0)
fprintf('Executing time step number %d.\n',ts);
end
switch Boundary_Dynamics
% case 1
%
% if(mod(ts,2)==1)
% %fIn->fOut
% channel2D_VW_PE_LBGK_ts(fOut,fIn,inl_d,onl_d,snl_d,ux_p,rho_out,nu_lbm,int32(Nx),int32(Ny));
% %rho_dp = sum(fOut(v_data_LP),2);
% %u_data(ts)=double(((fOut(v_data_LP,:)*ex')/rho_dp)./u_conv_fact);
% else
% %fOut->fIn
% channel2D_VW_PE_LBGK_ts(fIn,fOut,inl_d,onl_d,snl_d,ux_p,rho_out,nu_lbm,int32(Nx),int32(Ny));
% %rho_dp = sum(fIn(v_data_LP),2);
% %u_data(ts)=double(((fIn(v_data_LP,:)*ex'))/rho_dp./u_conv_fact);
% end
%
% case 2
% if(mod(ts,2)==1)
% %fIn->fOut
% channel2D_RegVwPe_LBGK_ts(fOut,fIn,inl_d,onl_d,snl_d,ux_p,rho_out,nu_lbm,int32(Nx),int32(Ny));
% %rho_dp = sum(fOut(v_data_LP),2);
% %u_data(ts)=double(((fOut(v_data_LP,:)*ex')/rho_dp)./u_conv_fact);
% else
% %fOut->fIn
% channel2D_RegVwPe_LBGK_ts(fIn,fOut,inl_d,onl_d,snl_d,ux_p,rho_out,nu_lbm,int32(Nx),int32(Ny));
% %rho_dp = sum(fIn(v_data_LP),2);
% % u_data(ts)=double(((fIn(v_data_LP,:)*ex'))/rho_dp./u_conv_fact);
% end
%
% case 3
%
% if(mod(ts,2)==1)
% %fIn->fOut
% channel2D_RegVwPe_RBGK_ts(fOut,fIn,inl_d,onl_d,snl_d,ux_p,rho_out,nu_lbm,int32(Nx),int32(Ny));
% %rho_dp = sum(fOut(v_data_LP),2);
% %u_data(ts)=double(((fOut(v_data_LP,:)*ex')/rho_dp)./u_conv_fact);
% else
% %fOut->fIn
% channel2D_RegVwPe_RBGK_ts(fIn,fOut,inl_d,onl_d,snl_d,ux_p,rho_out,nu_lbm,int32(Nx),int32(Ny));
% % rho_dp = sum(fIn(v_data_LP),2);
% %u_data(ts)=double(((fIn(v_data_LP,:)*ex'))/rho_dp./u_conv_fact);
% end
%
% case 4
% if(mod(ts,2)==1)
% %fIn->fOut
% channel2D_RegVwPe_MRT_ts(fOut,fIn,inl_d,onl_d,snl_d,ux_p,rho_out,omega_op,int32(Nx),int32(Ny));
% %rho_dp = sum(fOut(v_data_LP),2);
% %u_data(ts)=double(((fOut(v_data_LP,:)*ex')/rho_dp)./u_conv_fact);
% else
% %fOut->fIn
% channel2D_RegVwPe_MRT_ts(fIn,fOut,inl_d,onl_d,snl_d,ux_p,rho_out,omega_op,int32(Nx),int32(Ny));
% % rho_dp = sum(fIn(v_data_LP),2);
% % u_data(ts)=double(((fIn(v_data_LP,:)*ex'))/rho_dp./u_conv_fact);
% end
%
%
% case 5
% if(mod(ts,2)==1)
% %fIn->fOut
% channel2D_VW_PE_MRT_ts(fOut,fIn,inl_d,onl_d,snl_d,ux_p,rho_out,omega_op,int32(Nx),int32(Ny));
% %rho_dp = sum(fOut(v_data_LP),2);
% %u_data(ts)=double(((fOut(v_data_LP,:)*ex')/rho_dp)./u_conv_fact);
% else
% %fOut->fIn
% channel2D_VW_PE_MRT_ts(fIn,fOut,inl_d,onl_d,snl_d,ux_p,rho_out,omega_op,int32(Nx),int32(Ny));
% % rho_dp = sum(fIn(v_data_LP),2);
% % u_data(ts)=double(((fIn(v_data_LP,:)*ex'))/rho_dp./u_conv_fact);
% end
case 6
if(mod(ts,2)==1)
%fIn->fOut
channel2D_VW_PE_MRT_DPts(fOut,fIn,inl_d,onl_d,snl_d,ux_p,rho_out,omega_op,int32(Nx),int32(Ny));
%rho_dp = sum(fOut(v_data_LP),2);
%u_data(ts)=double(((fOut(v_data_LP,:)*ex')/rho_dp)./u_conv_fact);
else
%fOut->fIn
channel2D_VW_PE_MRT_DPts(fIn,fOut,inl_d,onl_d,snl_d,ux_p,rho_out,omega_op,int32(Nx),int32(Ny));
% rho_dp = sum(fIn(v_data_LP),2);
% u_data(ts)=double(((fIn(v_data_LP,:)*ex'))/rho_dp./u_conv_fact);
end
end
if(mod(ts,plot_freq)==0)
% plot something....
if(mod(ts,2)==1)
rho = sum(fOut,2);
ux = ((fOut*ex')./rho)./u_conv_fact;
uy = ((fOut*ey')./rho)./u_conv_fact;
else
rho = sum(fIn,2);
ux = ((fIn*ex')./rho)./u_conv_fact;
uy = ((fIn*ey')./rho)./u_conv_fact;
end
pressure = rho*p_conv_fact - p_ref;
ux(snl)=0;
uy(snl)=0;
% gather data from the GPU
ux_h = double(ux);
uy_h = double(uy);
pressure_h = double(pressure);
% write to VTK file
pv_fileStub = sprintf('_pressureAndVelocity%d.vtk',ts_num);
pv_fileName = strcat(sim_name,pv_fileStub);
save_velocityAndPressureVTK_binaryR2(pressure_h,ux_h,uy_h,uz_h,...
gcoord(:,1),gcoord(:,2),gcoord_z,pv_fileName,[Nx Ny 1]);
ts_num=ts_num+1;
end
end
ex_time = toc;
fprintf('LPU/sec = %g.\n',Num_ts*nnodes/ex_time);
% plot velocity profile and compare against theory
ux_lbm = ux_h(pltX_list);
figure(1)
plot(ux_theory,y_space,'-r',ux_h(pltX_list),gcoord(pltX_list,2),'xb');
rel_err = norm(ux_theory - ux_lbm',2)/norm(ux_theory,2);
fprintf('Relative error = %g.\n',rel_err);
fprintf('Grid Resolution = %d.\n',Ny_divs);
fprintf('dx = %g.\n',dx);
fprintf('dt = %g.\n',dt);
fprintf('omega = %g.\n',omega);
% figure(2)
% plot(1:Num_ts,u_data,'LineWidth',2);
% grid on
% title('\bf{Horizontal Velocity Fluctuation x/Lx = 0.75 vs Time Step, Re = 10}','FontSize',12);
% xlabel('\bf{Time Step}','FontSize',12);
% ylabel('\bf{Umax (m/sec)}','FontSize',12);
else
fprintf('Run aborted. Better luck next time!\n');
end