forked from stanfordhpccenter/HTR-solver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prometeo_bc.rg
1785 lines (1593 loc) · 68.3 KB
/
prometeo_bc.rg
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
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- Copyright (c) "2019, by Stanford University
-- Developer: Mario Di Renzo
-- Affiliation: Center for Turbulence Research, Stanford University
-- URL: https://ctr.stanford.edu
-- Citation: Di Renzo, M., Lin, F., and Urzay, J. (2020).
-- HTR solver: An open-source exascale-oriented task-based
-- multi-GPU high-order code for hypersonic aerothermodynamics.
-- Computer Physics Communications 255, 107262"
-- All rights reserved.
--
-- Redistribution and use in source and binary forms, with or without
-- modification, are permitted provided that the following conditions are met:
-- * Redistributions of source code must retain the above copyright
-- notice, this list of conditions and the following disclaimer.
-- * Redistributions in binary form must reproduce the above copyright
-- notice, this list of conditions and the following disclaimer in the
-- documentation and/or other materials provided with the distribution.
--
-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-- ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
-- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import "regent"
return function(SCHEMA, MIX, CHEM, Fluid_columns, zones_partitions, DEBUG_OUTPUT) local Exports = {}
-------------------------------------------------------------------------------
-- IMPORTS
-------------------------------------------------------------------------------
local C = regentlib.c
local MAPPER = terralib.includec("prometeo_mapper.h")
local UTIL = require 'util-desugared'
local MATH = require 'math_utils'
local CONST = require "prometeo_const"
local MACRO = require "prometeo_macro"
local sin = regentlib.sin(double)
local cos = regentlib.cos(double)
local tan = regentlib.tan(double)
local exp = regentlib.exp(double)
local pow = regentlib.pow(double)
local asin = regentlib.asin(double)
local tanh = regentlib.tanh(double)
local fabs = regentlib.fabs(double)
local sqrt = regentlib.sqrt(double)
local atan = regentlib.atan(double)
-- Variable indices
local nSpec = MIX.nSpec -- Number of species composing the mixture
local irU = CONST.GetirU(MIX) -- Index of the momentum in Conserved vector
local irE = CONST.GetirE(MIX) -- Index of the total energy density in Conserved vector
local nEq = CONST.GetnEq(MIX) -- Total number of unknowns for the implicit solver
local PI = CONST.PI
local Primitives = CONST.Primitives
local ProfilesVars = CONST.ProfilesVars
local RecycleVars = CONST.RecycleVars
-------------------------------------------------------------------------------
-- DATA STRUCTURES
-------------------------------------------------------------------------------
local struct IncomingShockParams {
-- Index where the shock will be injected
iShock : int;
-- Constant mixture composition
MolarFracs : double[nSpec];
-- Primitive variables upstream of the shock
pressure0 : double;
temperature0 : double;
velocity0 : double[3];
-- Primitive variables downstream of the shock
pressure1 : double;
temperature1 : double;
velocity1 : double[3];
}
local struct RecycleAverageType {
-- Average weight
w : double;
-- Distance from the wall
y : double;
-- Properties
rho : double;
-- Primitive variables
temperature : double;
MolarFracs : double[nSpec];
velocity : double[3];
}
-- Load fast interpolation tool
local FIData, FIType,
FIInitData, FIInitRegion,
FIFindIndex, FIGetWeight = unpack(MATH.mkFastInterp(RecycleAverageType, "y"))
-- Boundary layer data
local struct BLDataType {
Uinf : double;
aVD : double;
bVD : double;
QVD : double;
Ueq : double;
}
-- Rescaling data
local struct RescalingDataType {
-- Data for outer scaling
delta99VD : double;
-- Data for inner scaling
rhow : double;
uTau : double;
deltaNu : double;
}
local fspace RecycleRescalingParams(Fluid : region(ispace(int3d), Fluid_columns), tiles : ispace(int3d)) {
-- Recycling plane
BCPlane : partition(disjoint, Fluid, tiles),
RecyclePlane : partition(disjoint, Fluid, tiles),
-- Interpolation partition on boundary
interp_tiles : ispace(int1d),
BC_interp : partition(disjoint, Fluid, interp_tiles),
-- Fast interpolation tools
FIdata : FIData,
-- Boundary layer data
BLData : BLDataType,
-- Rescaling data
RescalingData : RescalingDataType
}
local fspace BCParamsStruct(Fluid : region(ispace(int3d), Fluid_columns), tiles : ispace(int3d)) {
IncomingShock : IncomingShockParams,
RecycleRescaling : RecycleRescalingParams(Fluid, tiles)
}
Exports.RecycleAverageType = RecycleAverageType
Exports.RecycleAverageFIType = FIType
Exports.BCParamsStruct = BCParamsStruct
Exports.BCDataList = {
readProfiles = regentlib.newsymbol(bool),
ProfilesDir = regentlib.newsymbol(&int8),
BCParams = regentlib.newsymbol(),
RecycleAverage = regentlib.newsymbol(),
RecycleAverageFI = regentlib.newsymbol()
}
-------------------------------------------------------------------------------
-- RANKINE-HUGONIOT FOR OBLIQUE SHOCKS
-------------------------------------------------------------------------------
-- Computes the angle of the velocity vector in the x-y plane
local __demand(__inline)
task getThetaFromU(u : double[3])
return atan(u[1]/u[0])
end
-- Computes the angle of the shock-normal velocity
local __demand(__inline)
task getUnFromU(U : double[3], beta : double, theta : double)
return sqrt(U[0]*U[0] + U[1]*U[1])*sin(beta+theta)
end
-- Computes the angle of the shock-normal velocity
local __demand(__inline)
task getUFromUn(Un : double, beta : double, theta : double)
var Umag = Un/sin(beta+theta)
return array(Umag*cos(theta), Umag*sin(theta), 0.0)
end
-- Computes the post-shock density
local __demand(__inline)
task RHgetrho1(nu : double, rho0 : double) return rho0/nu end
-- Computes the post-shock normal velocity
local __demand(__inline)
task RHgetUn1(nu : double, Un0 : double) return Un0*nu end
-- Computes the post-shock pressure
local __demand(__inline)
task RHgetP1(nu : double, p0 : double , Un0 : double, rho0 : double)
return p0 + rho0*Un0*Un0*(1.0 - nu)
end
-- Computes the post-shock static enthalpy
local __demand(__inline)
task RHgetH1(nu : double, h0 : double , Un0 : double)
return h0 + 0.5*Un0*Un0*(1.0 - nu*nu)
end
-- Computes the post-shock velocity angle in the x-y plane
local __demand(__inline)
task RHgetTheta1(nu : double, beta : double, theta0 : double)
var betaEff = beta+theta0
var tanB = tan(betaEff)
return atan(tanB*(nu-1.0)/(1.0 + nu*tanB*tanB))+theta0
end
-- This assumes constant composition across the shock
local __demand(__inline)
task RHresidual(nu : double,
un0 : double, rho0 : double, P0 : double, h0 : double,
Yi : double[nSpec], MixW : double, Mix : MIX.Mixture)
var un1 = RHgetUn1(nu, un0)
var rho1 = RHgetrho1(nu, rho0)
var P1 = RHgetP1(nu, P0, un0, rho0)
var T1 = MIX.GetTFromRhoAndP(rho1, MixW, P1)
return RHgetH1(nu, h0, un0) - MIX.GetEnthalpy(T1, Yi, Mix)
end
local __demand(__inline)
task InitIncomingShockParams(config : SCHEMA.Config, Mix : MIX.Mixture)
var input = config.BC.yBCRight.u.IncomingShock
var params : IncomingShockParams
-- Index where the shock will be injected
params.iShock = input.iShock
-- Shock angle
input.beta *= PI/180
params.MolarFracs = CHEM.ParseConfigMixture(input.Mixture, Mix)
-- Primitive variables upstream of the shock
params.pressure0 = input.pressure0
params.temperature0 = input.temperature0
params.velocity0 = input.velocity0
var MixW = MIX.GetMolarWeightFromXi(params.MolarFracs, Mix)
var Yi = MIX.GetMassFractions(MixW, params.MolarFracs, Mix)
var h0 = MIX.GetEnthalpy(params.temperature0, Yi, Mix)
var rho0 = MIX.GetRho(params.pressure0, params.temperature0, MixW, Mix)
var theta0 = getThetaFromU(params.velocity0)
var un0 = getUnFromU(params.velocity0, input.beta, theta0)
-- Compute primitive variables downstream of the shock
-- Use a Newton method
var i = 0
var nu = 1e-3
while true do
var f = RHresidual(nu, un0, rho0, params.pressure0, h0, Yi, MixW, Mix)
var h = nu*1e-3
var f1 = RHresidual(nu+h, un0, rho0, params.pressure0, h0, Yi, MixW, Mix)
var fp = (f1-f)/h
nu -= f/fp
if (fabs(f/fp) < 1e-8) then break end
regentlib.assert(i ~= 100, "Too many iterations in Rankine-Hugoniot non-linear solver")
i += 1
end
var rho1 = RHgetrho1(nu, rho0)
var un1 = RHgetUn1(nu, un0)
params.pressure1 = RHgetP1(nu, params.pressure0, un0, rho0)
params.temperature1 = MIX.GetTFromRhoAndP(rho1, MixW, params.pressure1)
var theta1 = RHgetTheta1(nu, input.beta, theta0)
var u1 = getUFromUn(un1, input.beta, theta1)
params.velocity1 = array(u1[0], u1[1], params.velocity0[2])
return params
end
-------------------------------------------------------------------------------
-- RECYCLE-RESCALING FUNCTIONS
-------------------------------------------------------------------------------
local __demand(__inline)
task initRecycleRescalingParams(Fluid : region(ispace(int3d), Fluid_columns),
tiles : ispace(int3d),
p_All : partition(disjoint, Fluid, tiles),
BC : partition(disjoint, Fluid, ispace(int1d)),
p_BC : cross_product(p_All, BC),
BCinput : SCHEMA.FlowBC,
Grid_xBnum : int32, Grid_yBnum : int32, Grid_zBnum : int32)
regentlib.assert(BCinput.type == SCHEMA.FlowBC_RecycleRescaling,
"Wrong BC got into RecycleRescaling data structure initialization")
-- Extract Recycle and BC plane from fluid
var BCcoloring = regentlib.c.legion_domain_point_coloring_create()
var PLcoloring = regentlib.c.legion_domain_point_coloring_create()
for c in tiles do
var rect = p_BC[c][0].bounds
-- Include ghost
if c.y == 0 then rect.lo.y = Fluid.bounds.lo.y end
if c.z == 0 then rect.lo.z = Fluid.bounds.lo.z end
if c.y == tiles.bounds.hi.y then rect.hi.y = Fluid.bounds.hi.y end
if c.z == tiles.bounds.hi.z then rect.hi.z = Fluid.bounds.hi.z end
regentlib.c.legion_domain_point_coloring_color_domain(BCcoloring, c, rect)
rect = rect + int3d{BCinput.u.RecycleRescaling.iRecycle, 0, 0}
regentlib.c.legion_domain_point_coloring_color_domain(PLcoloring, c, rect)
end
var BCPlane = partition(disjoint, Fluid, BCcoloring, tiles);
[UTIL.emitPartitionNameAttach(BCPlane, "BCPlane")];
var RecyclePlane = partition(disjoint, Fluid, PLcoloring, tiles);
[UTIL.emitPartitionNameAttach(RecyclePlane, "RecyclePlane")];
regentlib.c.legion_domain_point_coloring_destroy(BCcoloring)
regentlib.c.legion_domain_point_coloring_destroy(PLcoloring)
-- Create tiles of the BC region that support the entire interpolation
var interp_tiles = ispace(int1d, {tiles.bounds.hi.z + 1})
var InterpColoring = regentlib.c.legion_multi_domain_point_coloring_create()
for c in tiles do
var c_interp = int1d{c.z}
var rect = p_BC[c][0].bounds
-- Include ghost
if c.y == 0 then rect.lo.y = Fluid.bounds.lo.y end
if c.y == tiles.bounds.hi.y then rect.hi.y = Fluid.bounds.hi.y end
regentlib.c.legion_multi_domain_point_coloring_color_domain(InterpColoring, c_interp, rect)
end
var BC_interp = partition(disjoint, Fluid, InterpColoring, interp_tiles);
[UTIL.emitPartitionNameAttach(BC_interp, "BC_interp")];
regentlib.c.legion_multi_domain_point_coloring_destroy(InterpColoring)
-- Create a dummy structures to be filled in the initialization phase
var dummy : FIData
var BLdata : BLDataType
var Rdata : RescalingDataType
return [RecycleRescalingParams(Fluid, tiles)] {
BCPlane = BCPlane,
RecyclePlane = RecyclePlane,
interp_tiles = interp_tiles,
BC_interp = BC_interp,
FIdata = dummy,
BLData = BLdata,
RescalingData = Rdata
}
end
local mkInitializeRecycleAverage = terralib.memoize(function(init)
local InitializeRecycleAverage
if (init == "all") then
__demand(__inline)
task InitializeRecycleAverage(avg : region(ispace(int1d), RecycleAverageType))
where
writes(avg)
do
fill(avg.w, 0.0)
fill(avg.y, 0.0)
fill(avg.rho, 0.0)
fill(avg.temperature, 0.0)
fill(avg.MolarFracs, [UTIL.mkArrayConstant(nSpec, rexpr 0.0 end)])
fill(avg.velocity, array(0.0, 0.0, 0.0))
end
elseif (init == "std") then
__demand(__inline)
task InitializeRecycleAverage(avg : region(ispace(int1d), RecycleAverageType))
where
writes(avg.{rho, temperature, MolarFracs, velocity})
do
fill(avg.rho, 0.0)
fill(avg.temperature, 0.0)
fill(avg.MolarFracs, [UTIL.mkArrayConstant(nSpec, rexpr 0.0 end)])
fill(avg.velocity, array(0.0, 0.0, 0.0))
end
else assert(false) end
return InitializeRecycleAverage
end)
local __demand(__inline)
task getVDvelocity(u : double, data : BLDataType)
var Uinf = data.Uinf
var a = data.aVD
var b = data.bVD
var Q = data.QVD
return Uinf/a*(asin((2.0*a*a*u/Uinf - b)/Q) + asin(b/Q))
end
local __demand(__leaf)
task InitializeBoundarLayerData(avg : region(ispace(int1d), RecycleAverageType),
mix : MIX.Mixture)
where
reads(avg.{y, w, rho, temperature, MolarFracs, velocity})
do
var data : BLDataType
-- Conditions at the infinity
var cinf = avg.bounds.hi
var Uinf = avg[cinf].velocity[0]/avg[cinf].rho
var Tinf = avg[cinf].temperature/avg[cinf].rho
var rhoinf = avg[cinf].rho/avg[cinf].w
var MolarFracsinf = avg[cinf].MolarFracs
for i=0, nSpec do MolarFracsinf[i] /= avg[cinf].rho end
var MixWinf = MIX.GetMolarWeightFromXi(MolarFracsinf, mix)
var Yiinf = MIX.GetMassFractions(MixWinf, MolarFracsinf, mix)
var gammainf = MIX.GetGamma(Tinf, MixWinf, Yiinf, mix)
var Mainf = Uinf/MIX.GetSpeedOfSound(Tinf, gammainf, MixWinf, mix)
var muinf = MIX.GetViscosity( Tinf, MolarFracsinf, mix)
var laminf = MIX.GetHeatConductivity(Tinf, MolarFracsinf, mix)
var cpinf = MIX.GetHeatCapacity(Tinf, Yiinf, mix)
-- Conditions at the wall
var cw = avg.bounds.lo
var Tw = avg[cw].temperature/avg[cw].rho
var rhow = avg[cw].rho/avg[cw].w
var MolarFracsw = avg[cw].MolarFracs
for i=0, nSpec do MolarFracsinf[i] /= avg[cw].rho end
var muw = MIX.GetViscosity(Tw, MolarFracsw, mix)
-- Useful numbers
var Pr = cpinf*muinf/laminf
var r = pow(Pr, 1.0/3.0)
var Taw = Tinf*(1.0 + r*0.5*(gammainf - 1.0)*Mainf*Mainf)
-- Data for outer scaling based on
-- Van Driest equivalent velocity (see page 545 White's book)
data.Uinf = Uinf
data.aVD = sqrt(r*0.5*(gammainf - 1.0)*Mainf*Mainf*Tinf/Tw)
data.bVD = Taw/Tw - 1.0
data.QVD = sqrt(data.bVD*data.bVD + 4.0*data.aVD*data.aVD)
data.Ueq = getVDvelocity(Uinf, data)
-- C.printf("Ma_inf = %10.5e Pr = %10.5e\n", Mainf, Pr)
-- C.printf("T_w = %10.5e Taw = %10.5e\n", Tw, Taw)
-- C.printf("Ueq = %10.5e, delta99VD = %10.5e\n", data.Ueq, data.delta99VD)
return data
end
local __demand(__inline)
task getdelta99VD(avg : region(ispace(int1d), RecycleAverageType),
data : BLDataType)
where
reads(avg.{y, rho, velocity})
do
var c99 = int(avg.bounds.hi)
var Ue = 0.99*data.Ueq
__demand(__openmp)
for c in avg do
var uVD = getVDvelocity(avg[c].velocity[0]/avg[c].rho, data)
if (uVD > Ue) then c99 min= int(c) end
end
c99 max= 1
var cm1 = c99 - 1
var up = getVDvelocity(avg[int1d(c99)].velocity[0]/avg[int1d(c99)].rho, data)
var um = getVDvelocity(avg[int1d(cm1)].velocity[0]/avg[int1d(cm1)].rho, data)
return avg[int1d(cm1)].y + (avg[int1d(c99)].y - avg[int1d(cm1)].y)*(Ue - um)/(up - um)
end
local __demand(__leaf)
task GetRescalingData(avg : region(ispace(int1d), RecycleAverageType),
BLdata : BLDataType,
mix : MIX.Mixture)
where
reads(avg.{y, w, rho, temperature, MolarFracs, velocity})
do
var data : RescalingDataType
-- Conditions at the wall
var c = avg.bounds.lo
var T = avg[c].temperature/avg[c].rho
var rho = avg[c].rho/avg[c].w
var MolarFracs = avg[c].MolarFracs
for i=0, nSpec do MolarFracs[i] /= avg[c].rho end
var mu = MIX.GetViscosity(T, MolarFracs, mix)
-- Data for outer scaling
data.delta99VD = getdelta99VD(avg, BLdata)
-- Data for inner scaling
var cp1 = min(c+1, avg.bounds.hi)
var tauw = mu*(avg[cp1].velocity[0]/avg[cp1].rho -
avg[c ].velocity[0]/avg[c ].rho)
data.rhow = rho
data.uTau = sqrt(fabs(tauw)/rho)
data.deltaNu = mu/(rho*data.uTau)
return data
end
local mkAddRecycleAverage = terralib.memoize(function(op)
local AddRecycleAverage
if (op == "pos") then
__demand(__cuda, __leaf) -- MANUALLY PARALLELIZED
task AddRecycleAverage(plane : region(ispace(int3d), Fluid_columns),
avg : region(ispace(int1d), RecycleAverageType))
where
reads(plane.centerCoordinates),
reads(plane.cellWidth),
reduces+(avg.{w, y})
do
__demand(__openmp)
for c in plane do
var c_avg = int1d(c.y)
var vol = plane[c].cellWidth[0]*
plane[c].cellWidth[1]*
plane[c].cellWidth[2]
avg[c_avg].w += vol
avg[c_avg].y += plane[c].centerCoordinates[1]*vol
end
end
elseif (op == "std") then
__demand(__cuda, __leaf) -- MANUALLY PARALLELIZED
task AddRecycleAverage(plane : region(ispace(int3d), Fluid_columns),
avg : region(ispace(int1d), RecycleAverageType))
where
reads(plane.cellWidth),
reads(plane.rho),
reads(plane.{temperature, MolarFracs, velocity}),
reduces+(avg.rho),
reduces+(avg.{temperature, MolarFracs, velocity})
do
__demand(__openmp)
for c in plane do
var c_avg = int1d(c.y)
var vol = (plane[c].cellWidth[0]*
plane[c].cellWidth[1]*
plane[c].cellWidth[2])
var rvol = vol*plane[c].rho
avg[c_avg].rho += plane[c].rho*vol
avg[c_avg].temperature += plane[c].temperature*rvol
avg[c_avg].MolarFracs += plane[c].MolarFracs *[UTIL.mkArrayConstant(nSpec, rvol)]
avg[c_avg].velocity += plane[c].velocity *[UTIL.mkArrayConstant( 3, rvol)]
end
end
elseif (op == "BC") then
__demand(__cuda, __leaf) -- MANUALLY PARALLELIZED
task AddRecycleAverage(plane : region(ispace(int3d), Fluid_columns),
avg : region(ispace(int1d), RecycleAverageType),
mix : MIX.Mixture,
Pbc : double)
where
reads(plane.cellWidth),
reads(plane.[ProfilesVars]),
reduces+(avg.rho),
reduces+(avg.{temperature, MolarFracs, velocity})
do
__demand(__openmp)
for c in plane do
var c_avg = int1d(c.y)
var vol = (plane[c].cellWidth[0]*
plane[c].cellWidth[1]*
plane[c].cellWidth[2])
var MixW = MIX.GetMolarWeightFromXi(plane[c].MolarFracs_profile, mix)
var rho = MIX.GetRho(Pbc, plane[c].temperature_profile, MixW, mix)
var rvol = vol*rho
avg[c_avg].rho += rho*vol
avg[c_avg].temperature += plane[c].temperature_profile*rvol
avg[c_avg].MolarFracs += plane[c].MolarFracs_profile *[UTIL.mkArrayConstant(nSpec, rvol)]
avg[c_avg].velocity += plane[c].velocity_profile *[UTIL.mkArrayConstant( 3, rvol)]
end
end
else assert(false) end
return AddRecycleAverage
end)
local __demand(__cuda, __leaf) -- MANUALLY PARALLELIZED
task ComputeRecycleAveragePosition(avg : region(ispace(int1d), RecycleAverageType))
where
reads(avg.w),
reads writes(avg.y)
do
__demand(__openmp)
for c in avg do
avg[c].y /= avg[c].w
end
end
local mkUpdateRecycleVariables = terralib.memoize(function(dir)
local UpdateRecycleVariables
local idx
if dir == "x" then
idx = 0
-- elseif dir == "y" then
-- idx = 1
-- elseif dir == "z" then
-- idx = 2
else assert(false) end
__demand(__cuda, __leaf) -- MANUALLY PARALLELIZED
task UpdateRecycleVariables(Fluid : region(ispace(int3d), Fluid_columns),
Fluid_BC : partition(disjoint, Fluid, ispace(int1d)),
avg : region(ispace(int1d), RecycleAverageType),
plane : region(ispace(int3d), Fluid_columns),
iRecycle : int)
where
reads(plane.{temperature, MolarFracs, velocity}),
reads(avg.{rho, temperature, MolarFracs, velocity}),
writes(Fluid.[RecycleVars])
do
var BC = Fluid_BC[0]
__demand(__openmp)
for c in BC do
var cPlane = int3d({iRecycle, c.y, c.z})
var cAvg = int1d(c.y)
-- Complete averaging over the plane
var iw = 1.0/avg[cAvg].rho
var AvgTemperature = avg[cAvg].temperature*iw
var AvgMolarFracs = avg[cAvg].MolarFracs
var AvgVelocity = avg[cAvg].velocity
for i=0, nSpec do AvgMolarFracs[i] *= iw end
for i=0, 3 do AvgVelocity[i] *= iw end
-- Compute the fluctuations
var MolarFracs_recycle = plane[cPlane].MolarFracs
var velocity_recycle = plane[cPlane].velocity
for i=0, nSpec do MolarFracs_recycle[i] -= AvgMolarFracs[i] end
for i=0, 3 do velocity_recycle[i] -= AvgVelocity[i] end
BC[c].temperature_recycle = plane[cPlane].temperature - AvgTemperature
BC[c].MolarFracs_recycle = MolarFracs_recycle
BC[c].velocity_recycle = velocity_recycle
end
end
return UpdateRecycleVariables
end)
-------------------------------------------------------------------------------
-- CHECK FUNCTIONS
-------------------------------------------------------------------------------
local function CheckNSCBC_Inflow(BC, NSCBC_Inflow)
return rquote
-- Check velocity profile
if NSCBC_Inflow.VelocityProfile.type == SCHEMA.InflowProfile_Constant then
-- Do nothing
elseif NSCBC_Inflow.VelocityProfile.type == SCHEMA.InflowProfile_File then
BC.readProfiles = true
BC.ProfilesDir = NSCBC_Inflow.VelocityProfile.u.File.FileDir
elseif NSCBC_Inflow.VelocityProfile.type == SCHEMA.InflowProfile_Incoming then
-- Do nothing
regentlib.assert(false, 'Incoming InflowProfile not supported')
else regentlib.assert(false, 'Unhandled case in InflowProfile switch') end
-- Check temperature profile
if NSCBC_Inflow.TemperatureProfile.type == SCHEMA.TempProfile_Constant then
-- Do nothing
elseif NSCBC_Inflow.TemperatureProfile.type == SCHEMA.TempProfile_File then
if (BC.readProfiles) then
regentlib.assert(C.strcmp(BC.ProfilesDir, NSCBC_Inflow.TemperatureProfile.u.File.FileDir) == 0, 'Only one file is allowed for profiles')
else
BC.readProfiles = true
BC.ProfilesDir = NSCBC_Inflow.TemperatureProfile.u.File.FileDir
end
elseif NSCBC_Inflow.TemperatureProfile.type == SCHEMA.TempProfile_Incoming then
-- Do nothing
regentlib.assert(false, 'Incoming heat model not supported')
else regentlib.assert(false, 'Unhandled case in TempProfile switch') end
-- Check mixture profile
if NSCBC_Inflow.MixtureProfile.type == SCHEMA.MixtureProfile_Constant then
-- Do nothing
elseif NSCBC_Inflow.MixtureProfile.type == SCHEMA.MixtureProfile_File then
if (BC.readProfiles) then
regentlib.assert(C.strcmp(BC.ProfilesDir, NSCBC_Inflow.MixtureProfile.u.File.FileDir) == 0, 'Only one file is allowed for profiles')
else
BC.readProfiles = true
BC.ProfilesDir = NSCBC_Inflow.MixtureProfile.u.File.FileDir
end
elseif NSCBC_Inflow.MixtureProfile.type == SCHEMA.MixtureProfile_Incoming then
-- Do nothing
regentlib.assert(false, 'Incoming mixture model not supported')
else regentlib.assert(false, 'Unhandled case in MixtureProfile switch') end
end
end
local function CheckDirichlet(BC, Dirichlet)
return rquote
-- Check velocity profile
if Dirichlet.VelocityProfile.type == SCHEMA.InflowProfile_Constant then
-- Do nothing
elseif Dirichlet.VelocityProfile.type == SCHEMA.InflowProfile_File then
BC.readProfiles = true
BC.ProfilesDir = Dirichlet.VelocityProfile.u.File.FileDir
elseif Dirichlet.VelocityProfile.type == SCHEMA.InflowProfile_Incoming then
-- Do nothing
regentlib.assert(false, 'Incoming InflowProfile not supported')
else regentlib.assert(false, 'Unhandled case in InflowProfile switch') end
-- Check temperature profile
if Dirichlet.TemperatureProfile.type == SCHEMA.TempProfile_Constant then
-- Do nothing
elseif Dirichlet.TemperatureProfile.type == SCHEMA.TempProfile_File then
if (BC.readProfiles) then
regentlib.assert(C.strcmp(BC.ProfilesDir, Dirichlet.TemperatureProfile.u.File.FileDir) == 0, 'Only one file is allowed for profiles')
else
BC.readProfiles = true
BC.ProfilesDir = Dirichlet.TemperatureProfile.u.File.FileDir
end
elseif Dirichlet.TemperatureProfile.type == SCHEMA.TempProfile_Incoming then
-- Do nothing
regentlib.assert(false, 'Incoming heat model not supported')
else regentlib.assert(false, 'Unhandled case in TempProfile switch') end
-- Check mixture profile
if Dirichlet.MixtureProfile.type == SCHEMA.MixtureProfile_Constant then
-- Do nothing
elseif Dirichlet.MixtureProfile.type == SCHEMA.MixtureProfile_File then
if (BC.readProfiles) then
regentlib.assert(C.strcmp(BC.ProfilesDir, Dirichlet.MixtureProfile.u.File.FileDir) == 0, 'Only one file is allowed for profiles')
else
BC.readProfiles = true
BC.ProfilesDir = Dirichlet.MixtureProfile.u.File.FileDir
end
elseif Dirichlet.MixtureProfile.type == SCHEMA.MixtureProfile_Incoming then
-- Do nothing
regentlib.assert(false, 'Incoming mixture model not supported')
else regentlib.assert(false, 'Unhandled case in MixtureProfile switch') end
end
end
local function CheckIsothermalWall(IsothermalWall)
return rquote
if IsothermalWall.TemperatureProfile.type == SCHEMA.TempProfile_Constant then
-- Do nothing
else
regentlib.assert(false, 'Only constant heat model supported')
end
end
end
local function CheckSuctionAndBlowingWall(SuctionAndBlowingWall)
return rquote
regentlib.assert(SuctionAndBlowingWall.A.length == SuctionAndBlowingWall.omega.length,
"Equal number of amplitudes and frequencies must be specified")
regentlib.assert(SuctionAndBlowingWall.A.length == SuctionAndBlowingWall.beta.length,
"Equal number of amplitudes and spanwise wave numbers must be specified")
if SuctionAndBlowingWall.TemperatureProfile.type == SCHEMA.TempProfile_Constant then
-- Do nothing
else
regentlib.assert(false, 'Only constant heat model supported')
end
end
end
local function CheckRecycleRescaling(BC, RecycleRescaling, config, initialized)
return rquote
-- We currently support only one RecycleRescaling BC
regentlib.assert(not initialized, "Only one RecycleRescaling BC is supported for now")
-- Check that we are asking to recycle an existing plane
var vaidIRecycle = ((RecycleRescaling.iRecycle >= 0) and
(RecycleRescaling.iRecycle <= config.Grid.xNum))
regentlib.assert(vaidIRecycle, 'iRecycle does not fall within the domain bounds')
-- Check velocity profile
if RecycleRescaling.VelocityProfile.type == SCHEMA.InflowProfile_Constant then
-- Do nothing
elseif RecycleRescaling.VelocityProfile.type == SCHEMA.InflowProfile_File then
BC.readProfiles = true
BC.ProfilesDir = RecycleRescaling.VelocityProfile.u.File.FileDir
elseif RecycleRescaling.VelocityProfile.type == SCHEMA.InflowProfile_Incoming then
-- Do nothing
regentlib.assert(false, 'Incoming InflowProfile not supported')
else regentlib.assert(false, 'Unhandled case in InflowProfile switch') end
-- Check temperature profile
if RecycleRescaling.TemperatureProfile.type == SCHEMA.TempProfile_Constant then
-- Do nothing
elseif RecycleRescaling.TemperatureProfile.type == SCHEMA.TempProfile_File then
if (BC.readProfiles) then
regentlib.assert(C.strcmp(BC.ProfilesDir, RecycleRescaling.TemperatureProfile.u.File.FileDir) == 0, 'Only one file is allowed for profiles')
else
BC.readProfiles = true
BC.ProfilesDir = RecycleRescaling.TemperatureProfile.u.File.FileDir
end
elseif RecycleRescaling.TemperatureProfile.type == SCHEMA.TempProfile_Incoming then
-- Do nothing
regentlib.assert(false, 'Incoming heat model not supported')
else regentlib.assert(false, 'Unhandled case in TempProfile switch') end
-- Check mixture profile
if RecycleRescaling.MixtureProfile.type == SCHEMA.MixtureProfile_Constant then
-- Do nothing
elseif RecycleRescaling.MixtureProfile.type == SCHEMA.MixtureProfile_File then
if (BC.readProfiles) then
regentlib.assert(C.strcmp(BC.ProfilesDir, RecycleRescaling.MixtureProfile.u.File.FileDir) == 0, 'Only one file is allowed for profiles')
else
BC.readProfiles = true
BC.ProfilesDir = RecycleRescaling.MixtureProfile.u.File.FileDir
end
elseif RecycleRescaling.MixtureProfile.type == SCHEMA.MixtureProfile_Incoming then
-- Do nothing
regentlib.assert(false, 'Incoming mixture model not supported')
else regentlib.assert(false, 'Unhandled case in MixtureProfile switch') end
end
end
function Exports.CheckInput(BC, config) return rquote
var [BC.readProfiles] = false
var [BC.ProfilesDir] = ''
var RecycleRescalingInitialized = false
-- Set up flow BC's in x direction
if (not((config.BC.xBCLeft.type == SCHEMA.FlowBC_Periodic) and (config.BC.xBCRight.type == SCHEMA.FlowBC_Periodic))) then
if (config.BC.xBCLeft.type == SCHEMA.FlowBC_NSCBC_Inflow) then
[CheckNSCBC_Inflow(BC, rexpr config.BC.xBCLeft.u.NSCBC_Inflow end)];
elseif (config.BC.xBCLeft.type == SCHEMA.FlowBC_Dirichlet) then
[CheckDirichlet(BC, rexpr config.BC.xBCLeft.u.Dirichlet end)];
elseif (config.BC.xBCLeft.type == SCHEMA.FlowBC_RecycleRescaling) then
[CheckRecycleRescaling(BC, rexpr config.BC.xBCLeft.u.RecycleRescaling end, config, RecycleRescalingInitialized)];
elseif (config.BC.xBCLeft.type == SCHEMA.FlowBC_AdiabaticWall) then
-- Do nothing
else
regentlib.assert(false, "Boundary conditions in xBCLeft not implemented")
end
if (config.BC.xBCRight.type == SCHEMA.FlowBC_NSCBC_Outflow) then
-- Do nothing
elseif (config.BC.xBCRight.type == SCHEMA.FlowBC_Dirichlet) then
[CheckDirichlet(BC, rexpr config.BC.xBCRight.u.Dirichlet end)];
elseif (config.BC.xBCRight.type == SCHEMA.FlowBC_AdiabaticWall) then
-- Do nothing
else
regentlib.assert(false, "Boundary conditions in xBCRight not implemented")
end
end
-- Set up flow BC's in y direction
if (not((config.BC.yBCLeft.type == SCHEMA.FlowBC_Periodic) and (config.BC.yBCRight.type == SCHEMA.FlowBC_Periodic))) then
if (config.BC.yBCLeft.type == SCHEMA.FlowBC_NSCBC_Outflow) then
-- Do nothing
elseif (config.BC.yBCLeft.type == SCHEMA.FlowBC_Dirichlet) then
[CheckDirichlet(BC, rexpr config.BC.yBCLeft.u.Dirichlet end)];
-- if (config.BC.yBCLeft.type == SCHEMA.FlowBC_Symmetry) then
elseif (config.BC.yBCLeft.type == SCHEMA.FlowBC_AdiabaticWall) then
-- Do nothing
elseif (config.BC.yBCLeft.type == SCHEMA.FlowBC_IsothermalWall) then
[CheckIsothermalWall(rexpr config.BC.yBCLeft.u.IsothermalWall end)];
elseif (config.BC.yBCLeft.type == SCHEMA.FlowBC_SuctionAndBlowingWall) then
[CheckSuctionAndBlowingWall(rexpr config.BC.yBCLeft.u.SuctionAndBlowingWall end)];
else
regentlib.assert(false, "Boundary conditions in yBCLeft not implemented")
end
if (config.BC.yBCRight.type == SCHEMA.FlowBC_NSCBC_Outflow) then
-- Do nothing
elseif (config.BC.yBCRight.type == SCHEMA.FlowBC_Dirichlet) then
[CheckDirichlet(BC, rexpr config.BC.yBCRight.u.Dirichlet end)];
-- if (config.BC.yBCRight.type == SCHEMA.FlowBC_Symmetry) then
elseif (config.BC.yBCRight.type == SCHEMA.FlowBC_AdiabaticWall) then
-- Do nothing
elseif (config.BC.yBCRight.type == SCHEMA.FlowBC_IsothermalWall) then
[CheckIsothermalWall(rexpr config.BC.yBCRight.u.IsothermalWall end)];
elseif (config.BC.yBCRight.type == SCHEMA.FlowBC_IncomingShock) then
var vaidIShock = ((config.BC.yBCRight.u.IncomingShock.iShock >= 0) and
(config.BC.yBCRight.u.IncomingShock.iShock <= config.Grid.xNum))
regentlib.assert(vaidIShock, 'iShock does not fall within the domain bounds')
else
regentlib.assert(false, "Boundary conditions in yBCRight not implemented")
end
end
-- Set up flow BC's in z direction
if (not((config.BC.zBCLeft.type == SCHEMA.FlowBC_Periodic) and (config.BC.zBCRight.type == SCHEMA.FlowBC_Periodic))) then
if (config.BC.zBCLeft.type == SCHEMA.FlowBC_Dirichlet) then
[CheckDirichlet(BC, rexpr config.BC.zBCLeft.u.Dirichlet end)];
else
regentlib.assert(false, "Boundary conditions in zBCLeft not implemented")
end
if (config.BC.zBCRight.type == SCHEMA.FlowBC_Dirichlet) then
[CheckDirichlet(BC, rexpr config.BC.yBCRight.u.Dirichlet end)];
else
regentlib.assert(false, "Boundary conditions in zBCRight not implemented")
end
end
-- Check if boundary conditions in each direction are either both periodic or both non-periodic
if (not (((config.BC.xBCLeft.type == SCHEMA.FlowBC_Periodic) and (config.BC.xBCRight.type == SCHEMA.FlowBC_Periodic))
or ((not (config.BC.xBCLeft.type == SCHEMA.FlowBC_Periodic)) and (not (config.BC.xBCRight.type == SCHEMA.FlowBC_Periodic))))) then
regentlib.assert(false, "Boundary conditions in x should match for periodicity")
end
if (not (((config.BC.yBCLeft.type == SCHEMA.FlowBC_Periodic) and (config.BC.yBCRight.type == SCHEMA.FlowBC_Periodic))
or ((not (config.BC.yBCLeft.type == SCHEMA.FlowBC_Periodic)) and (not (config.BC.yBCRight.type == SCHEMA.FlowBC_Periodic))))) then
regentlib.assert(false, "Boundary conditions in y should match for periodicity")
end
if (not (((config.BC.zBCLeft.type == SCHEMA.FlowBC_Periodic) and (config.BC.zBCRight.type == SCHEMA.FlowBC_Periodic))
or ((not (config.BC.zBCLeft.type == SCHEMA.FlowBC_Periodic)) and (not (config.BC.zBCRight.type == SCHEMA.FlowBC_Periodic))))) then
regentlib.assert(false, "Boundary conditions in z should match for periodicity")
end
end end
-------------------------------------------------------------------------------
-- DECLARE SYMBOLS
-------------------------------------------------------------------------------
function Exports.DeclSymbols(BC, Fluid, tiles, Fluid_Zones, Grid, config, Mix) return rquote
-- Unpack the partitions that we are going to need
var {p_All,
xNeg, xPos, yNeg, yPos, zNeg, zPos,
p_xNeg, p_xPos, p_yNeg, p_yPos, p_zNeg, p_zPos,
xNeg_ispace, xPos_ispace,
yNeg_ispace, yPos_ispace,
zNeg_ispace, zPos_ispace} = Fluid_Zones
var sampleId = config.Mapping.sampleId
-- IncomingShock params
var IncomingShock : IncomingShockParams
-- RecycleRescaling params
var RecycleRescaling : RecycleRescalingParams(Fluid, tiles)
var [BC.RecycleAverage] = region(ispace(int1d, config.Grid.yNum + 2*Grid.yBnum), RecycleAverageType);
[UTIL.emitRegionTagAttach(BC.RecycleAverage, MAPPER.SAMPLE_ID_TAG, sampleId, int)];
-- IncomingShock parameters
if (config.BC.yBCRight.type == SCHEMA.FlowBC_IncomingShock) then
IncomingShock = InitIncomingShockParams(config, Mix)
end
-- RecycleRescaling parameters
if (config.BC.xBCLeft.type == SCHEMA.FlowBC_RecycleRescaling) then
RecycleRescaling = initRecycleRescalingParams(Fluid, tiles, p_All,
xNeg, p_xNeg,
config.BC.xBCLeft,
Grid.xBnum, Grid.yBnum, Grid.zBnum);
end
-- Initialize BC params
var [BC.BCParams] = [BCParamsStruct(Fluid, tiles)] {
IncomingShock = IncomingShock,
RecycleRescaling = RecycleRescaling
};
end end
-------------------------------------------------------------------------------
-- BC ROUTINES
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- INITIALIZATION FUNCTIONS
-------------------------------------------------------------------------------
-- Set up stuff for RHS of NSCBC inflow
local __demand(__cuda, __leaf) -- MANUALLY PARALLELIZED
task InitializeGhostNSCBC(Fluid : region(ispace(int3d), Fluid_columns),
Fluid_BC : partition(disjoint, Fluid, ispace(int1d)),
mix : MIX.Mixture)
where
reads(Fluid.[Primitives]),
writes(Fluid.{velocity_old_NSCBC, temperature_old_NSCBC})
do
var BC = Fluid_BC[0]
__demand(__openmp)
for c in BC do
BC[c].velocity_old_NSCBC = BC[c].velocity
BC[c].temperature_old_NSCBC = BC[c].temperature
end
end
function Exports.InitBCs(BC, Fluid_Zones, config, Mix) return rquote
-- Unpack the partitions that we are going to need
var {p_All,
p_xNeg, p_xPos, p_yNeg, p_yPos, p_zNeg, p_zPos,
xNeg_ispace, xPos_ispace,
yNeg_ispace, yPos_ispace,
zNeg_ispace, zPos_ispace} = Fluid_Zones
-- initialize ghost cells values for NSCBC
if ((config.BC.xBCLeft.type == SCHEMA.FlowBC_NSCBC_Inflow) or
(config.BC.xBCLeft.type == SCHEMA.FlowBC_RecycleRescaling))then
__demand(__index_launch)
for c in xNeg_ispace do
InitializeGhostNSCBC(p_All[c], p_xNeg[c], Mix)
end
end
if config.BC.yBCRight.type == SCHEMA.FlowBC_IncomingShock then
__demand(__index_launch)
for c in yPos_ispace do
InitializeGhostNSCBC(p_All[c], p_yPos[c], Mix)
end
end
-- initialize averages for recycle-rescaling conditions