-
Notifications
You must be signed in to change notification settings - Fork 24
/
prometeo.rg
1595 lines (1360 loc) · 67.4 KB
/
prometeo.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"
-------------------------------------------------------------------------------
-- IMPORTS
-------------------------------------------------------------------------------
local C = regentlib.c
local SCHEMA = terralib.includec("config_schema.h")
local MAPPER = terralib.includec("prometeo_mapper.h")
local REGISTRAR = terralib.includec("prometeo_registrar.h")
local UTIL = require "util"
local VERSION = require "version"
-------------------------------------------------------------------------------
-- ACTIVATE DEBUG_OUTPUT
-------------------------------------------------------------------------------
local DEBUG_OUTPUT = false
if os.getenv("DEBUG_OUTPUT") == "1" then
DEBUG_OUTPUT = true
print("#############################################################################")
print("WARNING: You are compiling with debug output.")
print(" This might affect the performance of the solver.")
print("#############################################################################")
end
-------------------------------------------------------------------------------
-- ACTIVATE ATOMIC COHERENCE MODE
-------------------------------------------------------------------------------
local ATOMIC = true
if os.getenv("NO_ATOMIC") == "1" then
ATOMIC = false
print("#############################################################################")
print("WARNING: You are compiling without atomic coherence mode.")
print(" This might affect the performance of the solver.")
print("#############################################################################")
end
-------------------------------------------------------------------------------
-- ACTIVATE AVERAGES
-------------------------------------------------------------------------------
local AVERAGES = true
if os.getenv("AVERAGES") == "0" then
AVERAGES = false
print("#############################################################################")
print("WARNING: You are compiling without averaging tools.")
print("#############################################################################")
end
-------------------------------------------------------------------------------
-- ACTIVATE ELECTRIC FIELD SOLVER
-------------------------------------------------------------------------------
local ELECTRIC_FIELD = false
if os.getenv("ELECTRIC_FIELD") == "1" then
ELECTRIC_FIELD = true
print("#############################################################################")
print("WARNING: You are compiling with electric field solver.")
print("#############################################################################")
end
-------------------------------------------------------------------------------
-- CHECK THAT MIXTURE VARIABLE IS WELL SET
-------------------------------------------------------------------------------
local MIX
if (os.getenv("EOS") == "ConstPropMix") then
elseif (os.getenv("EOS") == "IsentropicMix") then
elseif (os.getenv("EOS") == "AirMix") then
elseif (os.getenv("EOS") == "CH41StMix") then
elseif (os.getenv("EOS") == "CH4_30SpMix") then
elseif (os.getenv("EOS") == "CH4_43SpIonsMix") then
elseif (os.getenv("EOS") == "CH4_26SpIonsMix") then
elseif (os.getenv("EOS") == "FFCM1Mix") then
elseif (os.getenv("EOS") == "BoivinMix") then
elseif (os.getenv("EOS") == "H2_UCSDMix") then
elseif (os.getenv("EOS") == nil) then
error ("You must define EOS enviromnment variable")
else
error ("Unrecognized mixture: " .. os.getenv("EOS"))
end
-------------------------------------------------------------------------------
-- DATA STRUCTURES
-------------------------------------------------------------------------------
local Config = SCHEMA.Config
--local MultiConfig = SCHEMA.MultiConfig
local types_inc_flags = terralib.newlist({"-DEOS="..os.getenv("EOS")})
if ELECTRIC_FIELD then
types_inc_flags:insert("-DELECTRIC_FIELD")
end
local TYPES = terralib.includec("prometeo_types.h", types_inc_flags)
local Fluid_columns = TYPES.Fluid_columns
local bBoxType = TYPES.bBoxType
-------------------------------------------------------------------------------
-- CONSTANTS
-------------------------------------------------------------------------------
local CONST = require "prometeo_const"
-- Runge-Kutta coefficients
local RK_C = CONST.RK_C
local RK_T = CONST.RK_T
-- Variable indices
local nSpec = TYPES.nSpec -- Number of species composing the mixture
local nEq = CONST.GetnEq(TYPES) -- Total number of unknowns for the implicit solver
-------------------------------------------------------------------------------
-- DEFINE I/O VARIABLES
-------------------------------------------------------------------------------
local IOVars = terralib.newlist({
'rho',
'pressure',
'temperature',
'MolarFracs',
'velocity',
'dudtBoundary',
'dTdtBoundary'
})
local vProbesVars = terralib.newlist({
'rho',
'pressure',
'temperature',
'MolarFracs',
'velocity'
})
local DebugVars = terralib.newlist({
'rho',
'pressure',
'temperature',
'MolarFracs',
'velocity',
'Conserved',
'shockSensorX',
'shockSensorY',
'shockSensorZ'
})
-- Add electric varaibles to the output
if ELECTRIC_FIELD then
IOVars:insert("electricPotential")
DebugVars:insert("electricPotential")
end
-------------------------------------------------------------------------------
-- EXTERNAL MODULES IMPORTS
-------------------------------------------------------------------------------
local HDF = (require 'hdf_helper')(int3d, int3d, Fluid_columns,
IOVars,
{timeStep=int, simTime=double, channelForcing=double},
{SpeciesNames={nSpec, 20}, Versions={2, VERSION.Length}})
local HDF_VPROBES = (require 'hdf_helper')(int3d, int3d, Fluid_columns,
vProbesVars,
{timeStep=int, simTime=double},
{SpeciesNames={nSpec, 20}, Versions={2, VERSION.Length}})
local HDF_DEBUG
if DEBUG_OUTPUT then
HDF_DEBUG = (require 'hdf_helper')(int3d, int3d, Fluid_columns,
DebugVars,
{timeStep=int, simTime=double, channelForcing=double},
{SpeciesNames={nSpec, 20}, Versions={2, VERSION.Length}})
end
-- Macro
local MACRO = require "prometeo_macro"
-- I/O routines
local IO = (require 'prometeo_IO')(SCHEMA)
-- Mixture registration routines
local MIX = (require 'prometeo_mixture')(SCHEMA, TYPES)
-- Partitioning routines
local PART = (require 'prometeo_partitioner')(SCHEMA, Fluid_columns)
-- Mesh routines
local GRID = (require 'prometeo_grid')(SCHEMA, IO, Fluid_columns, bBoxType,
PART.zones_partitions, PART.output_partitions)
-- Metric routines
local METRIC = (require 'prometeo_metric')(SCHEMA, TYPES,
PART.zones_partitions, PART.ghost_partitions)
-- Stability conditions routines
local CFL = (require 'prometeo_cfl')(MIX, TYPES, ELECTRIC_FIELD)
-- Chemistry routines
local CHEM = (require 'prometeo_chem')(SCHEMA, MIX, TYPES, ATOMIC)
-- Initialization routines
local INIT = (require 'prometeo_init')(SCHEMA, MIX, Fluid_columns, bBoxType)
-- Conserved->Primitives/Primitives->Conserved and properties routines
local VARS = (require 'prometeo_variables')(SCHEMA, MIX, METRIC, TYPES, ELECTRIC_FIELD)
-- Fluxes routines
local SENSOR = (require 'prometeo_sensor')(SCHEMA, MIX, TYPES, Fluid_columns,
PART.zones_partitions, PART.ghost_partitions)
-- BCOND routines
local BCOND = (require 'prometeo_bc')(SCHEMA, MIX, TYPES, PART.zones_partitions,
ELECTRIC_FIELD)
-- RK routines
local RK = (require 'prometeo_rk')(nEq, Fluid_columns)
-- Volume averages routines
local STAT = (require 'prometeo_stat')(MIX, Fluid_columns)
-- RHS routines
local RHS = (require 'prometeo_rhs')(SCHEMA, MIX, METRIC, TYPES, STAT,
PART.zones_partitions, PART.ghost_partitions,
BCOND.IncomingShockParams,
ATOMIC)
-- Laser routines
local LASER = (require 'prometeo_laser')(SCHEMA, MIX,
Fluid_columns, PART.zones_partitions, PART.ghost_partitions,
ATOMIC)
-- Profiles routines
local PROFILES = (require 'prometeo_profiles')(SCHEMA, MIX, Fluid_columns)
-- Averages routines
local AVG
if AVERAGES then
AVG = (require 'prometeo_average')(SCHEMA, MIX, TYPES, PART,
ELECTRIC_FIELD)
end
-- Probes routines
local PROBES = (require 'prometeo_probe')(SCHEMA, MIX, IO, Fluid_columns)
local Efield
if ELECTRIC_FIELD then
EFIELD = (require "prometeo_electricField")(SCHEMA, MIX, TYPES,
PART.zones_partitions, PART.ghost_partitions,
ATOMIC)
end
-------------------------------------------------------------------------------
-- INITIALIZATION ROUTINES
-------------------------------------------------------------------------------
local function emitFill(p, t, f, val) return rquote
var v = [val]
__demand(__index_launch)
for c in t do fill(([p][c]).[f], v) end
end end
__demand(__inline)
task InitializeCell(Fluid : region(ispace(int3d), Fluid_columns),
tiles : ispace(int3d),
Fluid_Zones : PART.zones_partitions(Fluid, tiles))
where
writes(Fluid)
do
-- Unpack the partitions that we are going to need
var {p_All} = Fluid_Zones;
[emitFill(p_All, tiles, "centerCoordinates", rexpr array(0.0, 0.0, 0.0) end)];
[emitFill(p_All, tiles, "nType_x", rexpr 0 end)];
[emitFill(p_All, tiles, "nType_y", rexpr 0 end)];
[emitFill(p_All, tiles, "nType_z", rexpr 0 end)];
[emitFill(p_All, tiles, "dcsi_e", rexpr 0.0 end)];
[emitFill(p_All, tiles, "deta_e", rexpr 0.0 end)];
[emitFill(p_All, tiles, "dzet_e", rexpr 0.0 end)];
[emitFill(p_All, tiles, "dcsi_d", rexpr 0.0 end)];
[emitFill(p_All, tiles, "deta_d", rexpr 0.0 end)];
[emitFill(p_All, tiles, "dzet_d", rexpr 0.0 end)];
[emitFill(p_All, tiles, "dcsi_s", rexpr 0.0 end)];
[emitFill(p_All, tiles, "deta_s", rexpr 0.0 end)];
[emitFill(p_All, tiles, "dzet_s", rexpr 0.0 end)];
[emitFill(p_All, tiles, "rho", rexpr 0.0 end)];
[emitFill(p_All, tiles, "mu" , rexpr 0.0 end)];
[emitFill(p_All, tiles, "lam", rexpr 0.0 end)];
[emitFill(p_All, tiles, "Di" , UTIL.mkArrayConstant(nSpec, rexpr 0.0 end))];
[emitFill(p_All, tiles, "SoS", rexpr 0.0 end)];
rescape if (ELECTRIC_FIELD and (MIX.nIons > 0)) then remit rquote
[emitFill(p_All, tiles, "Ki", UTIL.mkArrayConstant(MIX.nIons, rexpr 0.0 end))];
end end end
[emitFill(p_All, tiles, "pressure", rexpr 0.0 end)];
[emitFill(p_All, tiles, "temperature", rexpr 0.0 end)];
[emitFill(p_All, tiles, "MassFracs", UTIL.mkArrayConstant(nSpec, rexpr 0.0 end))];
[emitFill(p_All, tiles, "MolarFracs", UTIL.mkArrayConstant(nSpec, rexpr 0.0 end))];
[emitFill(p_All, tiles, "velocity", rexpr array(0.0, 0.0, 0.0) end)];
rescape if ELECTRIC_FIELD then remit rquote
[emitFill(p_All, tiles, "electricPotential", rexpr 0.0 end)];
[emitFill(p_All, tiles, "electricField", rexpr array(0.0, 0.0, 0.0) end)];
end end end
[emitFill(p_All, tiles, "Conserved", UTIL.mkArrayConstant(nEq, rexpr 0.0 end))];
[emitFill(p_All, tiles, "Conserved_old", UTIL.mkArrayConstant(nEq, rexpr 0.0 end))];
[emitFill(p_All, tiles, "Conserved_t", UTIL.mkArrayConstant(nEq, rexpr 0.0 end))];
[emitFill(p_All, tiles, "Conserved_t_old", UTIL.mkArrayConstant(nEq, rexpr 0.0 end))];
[emitFill(p_All, tiles, "shockSensorX", rexpr true end)];
[emitFill(p_All, tiles, "shockSensorY", rexpr true end)];
[emitFill(p_All, tiles, "shockSensorZ", rexpr true end)];
[emitFill(p_All, tiles, "DucrosSensor", rexpr 0.0 end)];
[emitFill(p_All, tiles, "dudtBoundary", rexpr array(0.0, 0.0, 0.0) end)];
[emitFill(p_All, tiles, "dTdtBoundary", rexpr 0.0 end)];
[emitFill(p_All, tiles, "velocity_old_NSCBC", rexpr array(0.0, 0.0, 0.0) end)];
[emitFill(p_All, tiles, "temperature_old_NSCBC", rexpr 0.0 end)];
[emitFill(p_All, tiles, "MolarFracs_profile", UTIL.mkArrayConstant(nSpec, rexpr 0.0 end))];
[emitFill(p_All, tiles, "velocity_profile", rexpr array(0.0, 0.0, 0.0) end)];
[emitFill(p_All, tiles, "temperature_profile", rexpr 0.0 end)];
[emitFill(p_All, tiles, "temperature_recycle", rexpr 0.0 end)];
[emitFill(p_All, tiles, "MolarFracs_recycle", UTIL.mkArrayConstant(nSpec, rexpr 0.0 end))];
[emitFill(p_All, tiles, "velocity_recycle", rexpr array(0.0, 0.0, 0.0) end)];
[emitFill(p_All, tiles, "kernelProfile", rexpr 0.0 end)];
end
-------------------------------------------------------------------------------
-- DEBUG ROUTINES
-------------------------------------------------------------------------------
local DetectNaN
local CheckDebugOutput
if DEBUG_OUTPUT then
local isnan = regentlib.isnan(double)
__demand(__cuda, __leaf) -- MANUALLY PARALLELIZED
task DetectNaN(Fluid : region(ispace(int3d), Fluid_columns))
where
reads(Fluid.{pressure, temperature}),
reads(Fluid.Conserved)
do
var err = 0
__demand(__openmp)
for c in Fluid do
if ([bool](isnan(Fluid[c].pressure ))) then err += 1 end
if ([bool](isnan(Fluid[c].temperature))) then err += 1 end
for i=0, nEq do
if ([bool](isnan(Fluid[c].Conserved[i]))) then err += 1 end
end
end
return err
end
__demand(__inline)
task CheckDebugOutput(Fluid : region(ispace(int3d), Fluid_columns),
Fluid_copy : region(ispace(int3d), Fluid_columns),
tiles : ispace(int3d),
tiles_output : ispace(int3d),
Fluid_Zones : PART.zones_partitions(Fluid, tiles),
Fluid_Output : PART.output_partitions(Fluid, tiles_output),
Fluid_Output_copy : PART.output_partitions(Fluid_copy, tiles_output),
config : Config,
Mix : MIX.Mixture,
Integrator_timeStep : int,
Integrator_simTime : double)
where
reads(Fluid),
reads writes(Fluid_copy),
Fluid * Fluid_copy
do
-- Unpack the partitions that we are going to need
var {p_All} = Fluid_Zones
var {p_Output } = Fluid_Output
var {p_Output_copy=p_Output} = Fluid_Output_copy
var err = 0
__demand(__index_launch)
for c in tiles do
err += DetectNaN(p_All[c])
end
if err ~= 0 then
var dirname = [&int8](C.malloc(256))
C.snprintf(dirname, 256, '%s/debugOut', config.Mapping.outDir)
var _1 = IO.createDir(0, dirname)
_1 = HDF_DEBUG.dump( _1, tiles_output, dirname, Fluid, Fluid_copy, p_Output, p_Output_copy)
_1 = HDF_DEBUG.write.timeStep( _1, dirname, Integrator_timeStep)
_1 = HDF_DEBUG.write.simTime( _1, dirname, Integrator_simTime)
_1 = HDF_DEBUG.write.SpeciesNames( _1, dirname, MIX.GetSpeciesNames(Mix))
_1 = HDF_DEBUG.write.Versions( _1, dirname, array(regentlib.string([VERSION.SolverVersion]), regentlib.string([VERSION.LegionVersion])))
_1 = HDF_DEBUG.write.channelForcing( _1, dirname, config.Flow.turbForcing.u.CHANNEL.Forcing);
C.free(dirname)
__fence(__execution, __block)
regentlib.assert(false, "NaN detected! Debug fields dumped in debugOut")
end
end
end
-------------------------------------------------------------------------------
-- RK-LOOP ROUTINES
-------------------------------------------------------------------------------
__demand(__inline)
task UpdatePrimitivesAndBCsFromConserved(Fluid : region(ispace(int3d), Fluid_columns),
tiles : ispace(int3d),
Fluid_Zones : PART.zones_partitions(Fluid, tiles),
Fluid_Ghost : PART.ghost_partitions(Fluid, tiles),
BCParams : BCOND.BCParamsStruct(Fluid, tiles),
BCRecycleAverage : region(ispace(int1d), BCOND.RecycleAverageType),
BCRecycleAverageFI : region(ispace(int1d), BCOND.RecycleAverageFIType),
config : Config,
Mix : MIX.Mixture,
bBox : bBoxType,
Integrator_simTime : double)
where
reads(BCRecycleAverageFI),
reads writes(Fluid),
reads writes(BCRecycleAverage)
do
-- Unpack the partitions that we are going to need
var {p_All, p_Interior, p_AllBCs} = Fluid_Zones;
var {p_GradientGhosts} = Fluid_Ghost;
-- Update all primitive variables...
__demand(__index_launch)
for c in tiles do
VARS.UpdatePrimitiveFromConserved(p_Interior[c], Mix)
end
-- ...also in the ghost cells
BCOND.UpdateGhostPrimitives(Fluid,
tiles,
Fluid_Zones,
BCParams,
BCRecycleAverage,
BCRecycleAverageFI,
config,
Mix,
bBox,
Integrator_simTime);
-- Update the mixture properties everywhere
__demand(__index_launch)
for c in tiles do
VARS.UpdatePropertiesFromPrimitive(p_All[c], Mix)
end
-- update values of conserved variables in ghost cells
__demand(__index_launch)
for c in tiles do
VARS.UpdateConservedFromPrimitive(p_AllBCs[c], Mix)
end
end
__demand(__inline)
task UpdateDerivatives(Fluid : region(ispace(int3d), Fluid_columns),
tiles : ispace(int3d),
Fluid_Zones : PART.zones_partitions(Fluid, tiles),
Fluid_Ghost : PART.ghost_partitions(Fluid, tiles),
BCParams : BCOND.BCParamsStruct(Fluid, tiles),
LaserData : LASER.LaserStruct(Fluid, tiles),
config : Config,
Mix : MIX.Mixture,
bBox : bBoxType,
RK_coeffs : double[2],
Integrator_deltaTime : double,
Integrator_simTime : double,
interior_volume : double,
UseOldDerivatives : bool)
where
reads writes(Fluid)
do
-- Unpack the partitions that we are going to need
var {p_All, p_Interior, p_solved} = Fluid_Zones;
var {p_GradientGhosts} = Fluid_Ghost;
-- Initialize time derivatives to 0 or minus the old value
if UseOldDerivatives then
__demand(__index_launch)
for c in tiles do
[RK.mkInitializeTimeDerivatives(true)](p_All[c])
end
-- In this case we advance the equations by half deltaTime
Integrator_deltaTime *= 0.5
else
__demand(__index_launch)
for c in tiles do
[RK.mkInitializeTimeDerivatives(false)](p_All[c])
end
end
if (not config.Integrator.implicitChemistry) then
-- Add chemistry source terms
__demand(__index_launch)
for c in tiles do
CHEM.AddChemistrySources(p_solved[c], Mix)
end
end
-- Add body forces
__demand(__index_launch)
for c in tiles do
RHS.AddBodyForces(p_solved[c], config.Flow.bodyForce)
end
-- Add ion-wind source terms
rescape if ELECTRIC_FIELD then remit rquote
__demand(__index_launch)
for c in tiles do
EFIELD.AddIonWindSources(p_GradientGhosts[c], p_solved[c], Fluid.bounds, Mix);
end
end end end
-- Add laser source
if (config.Flow.laser.type == SCHEMA.LaserModel_Algebraic) then
__demand(__index_launch)
for c in LaserData.Laser_tiles do
LASER.AddLaserAlgebraic(LaserData.p_Laser[c],
config.Flow.laser.u.Algebraic.Dimension,
config.Flow.laser.u.Algebraic.Amplitude,
config.Flow.laser.u.Algebraic.Center,
config.Flow.laser.u.Algebraic.Radius,
config.Flow.laser.u.Algebraic.Delay,
config.Flow.laser.u.Algebraic.Duration,
Integrator_simTime)
end
elseif (config.Flow.laser.type == SCHEMA.LaserModel_GeometricKernel) then
__demand(__index_launch)
for c in LaserData.Laser_tiles do
LASER.AddLaserGeometricKernel(LaserData.p_Laser[c], Integrator_simTime, config)
end
end
-- Add turbulent forcing
if config.Flow.turbForcing.type == SCHEMA.TurbForcingModel_CHANNEL then
-- Add forcing
__demand(__index_launch)
for c in tiles do
RHS.AddBodyForces(p_solved[c],
array(config.Flow.turbForcing.u.CHANNEL.Forcing, 0.0, 0.0))
end
elseif config.Flow.turbForcing.type == SCHEMA.TurbForcingModel_HIT then
RHS.UpdateUsingHITForcing(Fluid, tiles, Fluid_Zones, Fluid_Ghost,
Mix, config, interior_volume)
end
-- Use Euler fluxes to update conserved value derivatives
RHS.UpdateUsingEulerFlux(Fluid, tiles, Fluid_Zones, Fluid_Ghost, RK_coeffs, Integrator_deltaTime, Mix, config);
-- Use diffusion fluxes to update conserved variables derivatives
RHS.UpdateUsingDiffusionFlux(Fluid, tiles, Fluid_Zones, Fluid_Ghost, Mix, config);
rescape if (ELECTRIC_FIELD and (MIX.nIons > 0)) then remit rquote
-- Use ion drift fluxes to update conserved variables derivatives
EFIELD.UpdateUsingIonDriftFlux(Fluid, tiles, Fluid_Zones, Fluid_Ghost, Mix, config);
end end end
-- Add buffer zone sources
if (config.BC.bufferZone.type == SCHEMA.BufferZoneBC_Basic) then
__demand(__index_launch)
for c in tiles do
RHS.AddBufferZoneSource(p_solved[c], Mix, bBox, config)
end
end
-- Update using NSCBC_Outflow bcs
RHS.UpdateUsingNSCBCOutflow(Fluid, tiles, Fluid_Zones, Fluid_Ghost, Mix, config);
-- Update using NSCBC_FarField bcs
RHS.UpdateUsingNSCBCFarField(Fluid, tiles, Fluid_Zones, Fluid_Ghost, Mix, config);
-- Update using IncomingShock bcs
RHS.UpdateUsingNSCBCIncomingShock(Fluid, tiles, Fluid_Zones, Fluid_Ghost,
BCParams.IncomingShock, Mix, config);
-- Update using NSCBC_Inflow bcs
RHS.UpdateUsingNSCBCInflow(Fluid, tiles, Fluid_Zones, Fluid_Ghost, Mix, config);
end
-------------------------------------------------------------------------------
-- MAIN SIMULATION
-------------------------------------------------------------------------------
local function mkInstance() local INSTANCE = {}
-----------------------------------------------------------------------------
-- Symbols shared between quotes
-----------------------------------------------------------------------------
local startTime = regentlib.newsymbol()
local Grid = {
xBnum = regentlib.newsymbol(),
yBnum = regentlib.newsymbol(),
zBnum = regentlib.newsymbol(),
NX = regentlib.newsymbol(),
NY = regentlib.newsymbol(),
NZ = regentlib.newsymbol(),
boundingBox = regentlib.newsymbol(bBoxType),
numTiles = regentlib.newsymbol(),
NXout = regentlib.newsymbol(),
NYout = regentlib.newsymbol(),
NZout = regentlib.newsymbol(),
numTilesOut = regentlib.newsymbol(),
}
-- Boundary conditions symbols
local BC = BCOND.mkBCDataList()
local Integrator_deltaTime = regentlib.newsymbol()
local Integrator_simTime = regentlib.newsymbol()
local Integrator_timeStep = regentlib.newsymbol()
local Integrator_exitCond = regentlib.newsymbol()
local Mix = regentlib.newsymbol()
local Fluid = regentlib.newsymbol("Fluid")
local Fluid_copy = regentlib.newsymbol("Fluid_copy")
local Fluid_bounds = regentlib.newsymbol("Fluid_bounds")
local tiles = regentlib.newsymbol()
local tiles_output = regentlib.newsymbol()
local Fluid_Zones = regentlib.newsymbol("Fluid_Zones")
local Fluid_Ghost = regentlib.newsymbol("Fluid_Ghost")
local Fluid_Output = regentlib.newsymbol("Fluid_Output")
local Fluid_Output_copy = regentlib.newsymbol("Fluid_Output_copy")
local interior_volume = regentlib.newsymbol(double)
-- Averages symbols
local Averages
if AVERAGES then
Averages = AVG.mkAvgList()
end
-- Probes symbols
local Probes = PROBES.mkProbesList()
-- Laser data
local Laser = LASER.mkLaserList()
-- Electric field symbols
local EfieldData
if ELECTRIC_FIELD then
EfieldData = EFIELD.mkDataList()
end
-----------------------------------------------------------------------------
-- Exported symbols
-----------------------------------------------------------------------------
INSTANCE.Grid = Grid
INSTANCE.Integrator_deltaTime = Integrator_deltaTime
INSTANCE.Integrator_simTime = Integrator_simTime
INSTANCE.Integrator_timeStep = Integrator_timeStep
INSTANCE.Integrator_exitCond = Integrator_exitCond
INSTANCE.Fluid = Fluid
INSTANCE.Fluid_copy = Fluid_copy
INSTANCE.tiles = tiles
INSTANCE.Fluid_Zones = Fluid_Zones
-----------------------------------------------------------------------------
-- Symbol declaration & initialization
-----------------------------------------------------------------------------
function INSTANCE.DeclSymbols(config) return rquote
---------------------------------------------------------------------------
-- Preparation
---------------------------------------------------------------------------
-- Start timer
var [startTime] = __future(int64, C.legion_issue_timing_op_microseconds(__runtime(), __context()));
-- Write console header
IO.Console_WriteHeader([&int8](config.Mapping.outDir))
---------------------------------------------------------------------------
-- Declare & initialize state variables
---------------------------------------------------------------------------
-- Determine number of ghost cells in each direction
-- 0 ghost cells if periodic and 1 otherwise
var [Grid.xBnum] = 1
var [Grid.yBnum] = 1
var [Grid.zBnum] = 1
if config.BC.xBCLeft.type == SCHEMA.FlowBC_Periodic then Grid.xBnum = 0 end
if config.BC.yBCLeft.type == SCHEMA.FlowBC_Periodic then Grid.yBnum = 0 end
if config.BC.zBCLeft.type == SCHEMA.FlowBC_Periodic then Grid.zBnum = 0 end
if config.BC.xBCLeft.type ~= SCHEMA.FlowBC_Periodic then regentlib.assert(config.Grid.xNum > 4, "HTR needs at least five points along non-periodic boundaries (x dir)") end
if config.BC.yBCLeft.type ~= SCHEMA.FlowBC_Periodic then regentlib.assert(config.Grid.yNum > 4, "HTR needs at least five points along non-periodic boundaries (y dir)") end
if config.BC.zBCLeft.type ~= SCHEMA.FlowBC_Periodic then regentlib.assert(config.Grid.zNum > 4, "HTR needs at least five points along non-periodic boundaries (z dir)") end
var [Grid.NX] = config.Mapping.tiles[0]
var [Grid.NY] = config.Mapping.tiles[1]
var [Grid.NZ] = config.Mapping.tiles[2]
var [Grid.numTiles] = Grid.NX * Grid.NY * Grid.NZ
var [Grid.NXout] = int(config.Mapping.tiles[0]/config.Mapping.tilesPerRank[0])
var [Grid.NYout] = int(config.Mapping.tiles[1]/config.Mapping.tilesPerRank[1])
var [Grid.NZout] = int(config.Mapping.tiles[2]/config.Mapping.tilesPerRank[2])
var [Grid.numTilesOut] = Grid.NXout * Grid.NYout * Grid.NZout
var [Integrator_exitCond] = true
var [Integrator_simTime] = config.Integrator.startTime
var [Integrator_timeStep] = config.Integrator.startIter
var [Integrator_deltaTime] = 0.0;
---------------------------------------------------------------------------
-- Initialize forcing values
---------------------------------------------------------------------------
if config.Flow.turbForcing.type == SCHEMA.TurbForcingModel_CHANNEL then
config.Flow.turbForcing.u.CHANNEL.Forcing max= 1.0
end
---------------------------------------------------------------------------
-- Create Regions and Partitions
---------------------------------------------------------------------------
var sampleId = config.Mapping.sampleId
-- Create Fluid Regions
var is_Fluid = ispace(int3d, {x = config.Grid.xNum + 2*Grid.xBnum,
y = config.Grid.yNum + 2*Grid.yBnum,
z = config.Grid.zNum + 2*Grid.zBnum})
var [Fluid] = region(is_Fluid, Fluid_columns);
[UTIL.emitRegionTagAttach(Fluid, MAPPER.SAMPLE_ID_TAG, sampleId, int)];
var [Fluid_bounds] = [Fluid].bounds
var [Fluid_copy] = region(is_Fluid, Fluid_columns);
[UTIL.emitRegionTagAttach(Fluid_copy, MAPPER.SAMPLE_ID_TAG, sampleId, int)];
-- Partitioning domain
var [tiles] = ispace(int3d, {Grid.NX, Grid.NY, Grid.NZ})
-- Fluid Partitioning
var [Fluid_Zones] = PART.PartitionZones(Fluid, tiles, config, Grid.xBnum, Grid.yBnum, Grid.zBnum)
-- Create partitions to support stencils
var [Fluid_Ghost] = PART.PartitionGhost(Fluid, tiles, Fluid_Zones, config)
-- Unpack the partitions that we are going to need
var {p_All} = Fluid_Zones;
-- Output partitionig
var [tiles_output] = ispace(int3d, {Grid.NXout, Grid.NYout, Grid.NZout})
var [Fluid_Output] = PART.PartitionOutput(Fluid, tiles_output, config,
Grid.xBnum, Grid.yBnum, Grid.zBnum)
var [Fluid_Output_copy] = PART.PartitionOutput(Fluid_copy, tiles_output, config,
Grid.xBnum, Grid.yBnum, Grid.zBnum)
---------------------------------------------------------------------------
-- Initialize the mixture
---------------------------------------------------------------------------
var [Mix] = MIX.InitMixture(Fluid, tiles, Fluid_Zones.p_All, config);
---------------------------------------------------------------------------
-- Declare BC symbols
---------------------------------------------------------------------------
[BCOND.DeclSymbols(BC, Fluid, Grid, config)];
---------------------------------------------------------------------------
-- Declare averages symbols
---------------------------------------------------------------------------
rescape if AVERAGES then remit rquote
[AVG.DeclSymbols(Averages, Grid, Fluid, p_All, config, MAPPER)];
-- Create averages partitions
[AVG.InitPartitions(Averages, Grid, Fluid, p_All, config)];
end end end
---------------------------------------------------------------------------
-- Declare probes symbols
---------------------------------------------------------------------------
[PROBES.DeclSymbols(Probes, Grid, Fluid, p_All, config)];
---------------------------------------------------------------------------
-- Create directory for volume probes
---------------------------------------------------------------------------
for p=0, config.IO.volumeProbes.length do
var vProbe = config.IO.volumeProbes.values[p]
var dirname = [&int8](C.malloc(256))
C.snprintf(dirname, 256, '%s/%s', config.Mapping.outDir, vProbe.outDir)
var _1 = IO.createDir(0, dirname)
C.free(dirname)
end
---------------------------------------------------------------------------
-- Declare symbols for laser model
---------------------------------------------------------------------------
[LASER.DeclSymbols(Laser, Grid, Fluid, tiles, p_All, config)];
---------------------------------------------------------------------------
-- Declare electric field solver symbols
---------------------------------------------------------------------------
rescape if ELECTRIC_FIELD then remit rquote
[EFIELD.DeclSymbols(EfieldData, Fluid, tiles, Fluid_Zones, Grid, config, MAPPER)];
end end end
end end -- DeclSymbols
-----------------------------------------------------------------------------
-- Region initialization
-----------------------------------------------------------------------------
function INSTANCE.InitRegions(config) return rquote
---------------------------------------------------------------------------
-- Initialize fluid region
---------------------------------------------------------------------------
InitializeCell(Fluid, tiles, Fluid_Zones);
-- Unpack the partitions that we are going to need
var {p_All, p_Interior, p_AllBCs,
xNeg, xPos, yNeg, yPos, zNeg, zPos} = Fluid_Zones
var {p_Output} = Fluid_Output
var {p_Output_copy=p_Output} = Fluid_Output_copy
---------------------------------------------------------------------------
-- Initialize grid operators
---------------------------------------------------------------------------
METRIC.InitializeOperators(Fluid, tiles, Fluid_Zones, config,
Grid.xBnum, Grid.yBnum, Grid.zBnum)
---------------------------------------------------------------------------
-- Initialize the grid geometry
---------------------------------------------------------------------------
var [Grid.boundingBox] = GRID.InitializeGeometry(Fluid, tiles, Fluid_Zones, config)
---------------------------------------------------------------------------
-- Dump cell center grid once and for all
---------------------------------------------------------------------------
GRID.dumpCellCenterGrid(Fluid, Fluid_copy, tiles_output, Fluid_Output, Fluid_Output_copy, config)
---------------------------------------------------------------------------
-- Initialize averages
---------------------------------------------------------------------------
rescape if AVERAGES then remit rquote
-- Initialize averages
[AVG.InitRakesAndPlanes(Averages)];
end end end
---------------------------------------------------------------------------
-- Initialize solution
---------------------------------------------------------------------------
if config.Flow.initCase.type == SCHEMA.FlowInitCase_Uniform then
var initMolarFracs = MIX.ParseConfigMixture(config.Flow.initCase.u.Uniform.molarFracs, Mix)
__demand(__index_launch)
for c in tiles do
INIT.InitializeUniform(p_All[c],
config.Flow.initCase.u.Uniform.pressure,
config.Flow.initCase.u.Uniform.temperature,
config.Flow.initCase.u.Uniform.velocity,
initMolarFracs)
end
elseif config.Flow.initCase.type == SCHEMA.FlowInitCase_Random then
var initMolarFracs = MIX.ParseConfigMixture(config.Flow.initCase.u.Random.molarFracs, Mix)
__demand(__index_launch)
for c in tiles do
INIT.InitializeRandom(p_All[c],
config.Flow.initCase.u.Random.pressure,
config.Flow.initCase.u.Random.temperature,
config.Flow.initCase.u.Random.magnitude,
initMolarFracs)
end
elseif config.Flow.initCase.type == SCHEMA.FlowInitCase_TaylorGreen2DVortex then
var initMolarFracs = MIX.ParseConfigMixture(config.Flow.initCase.u.TaylorGreen2DVortex.molarFracs, Mix)
__demand(__index_launch)
for c in tiles do
INIT.InitializeTaylorGreen2D(p_All[c],
config.Flow.initCase.u.TaylorGreen2DVortex.pressure,
config.Flow.initCase.u.TaylorGreen2DVortex.temperature,
config.Flow.initCase.u.TaylorGreen2DVortex.velocity,
initMolarFracs,
Mix)
end
elseif config.Flow.initCase.type == SCHEMA.FlowInitCase_TaylorGreen3DVortex then
var initMolarFracs = MIX.ParseConfigMixture(config.Flow.initCase.u.TaylorGreen3DVortex.molarFracs, Mix)
__demand(__index_launch)
for c in tiles do
INIT.InitializeTaylorGreen3D(p_All[c],
config.Flow.initCase.u.TaylorGreen3DVortex.pressure,
config.Flow.initCase.u.TaylorGreen3DVortex.temperature,
config.Flow.initCase.u.TaylorGreen3DVortex.velocity,
initMolarFracs,
Mix)
end
elseif config.Flow.initCase.type == SCHEMA.FlowInitCase_Perturbed then
var initMolarFracs = MIX.ParseConfigMixture(config.Flow.initCase.u.Perturbed.molarFracs, Mix)
__demand(__index_launch)
for c in tiles do
INIT.InitializePerturbed(p_All[c],
config.Flow.initCase.u.Perturbed.pressure,
config.Flow.initCase.u.Perturbed.temperature,
config.Flow.initCase.u.Perturbed.velocity,
initMolarFracs)
end
elseif config.Flow.initCase.type == SCHEMA.FlowInitCase_RiemannTestOne then
var initMolarFracs = MIX.ParseConfigMixture(config.Flow.initMixture, Mix)
__demand(__index_launch)
for c in tiles do
INIT.InitializeRiemannTestOne(p_All[c], initMolarFracs)
end
elseif config.Flow.initCase.type == SCHEMA.FlowInitCase_RiemannTestTwo then
var initMolarFracs = MIX.ParseConfigMixture(config.Flow.initMixture, Mix)
__demand(__index_launch)
for c in tiles do
INIT.InitializeRiemannTestTwo(p_All[c], initMolarFracs)
end
elseif config.Flow.initCase.type == SCHEMA.FlowInitCase_SodProblem then
var initMolarFracs = MIX.ParseConfigMixture(config.Flow.initMixture, Mix)
__demand(__index_launch)
for c in tiles do
INIT.InitializeSodProblem(p_All[c], initMolarFracs)
end
elseif config.Flow.initCase.type == SCHEMA.FlowInitCase_LaxProblem then
var initMolarFracs = MIX.ParseConfigMixture(config.Flow.initMixture, Mix)
__demand(__index_launch)
for c in tiles do
INIT.InitializeLaxProblem(p_All[c], initMolarFracs)
end
elseif config.Flow.initCase.type == SCHEMA.FlowInitCase_ShuOsherProblem then
var initMolarFracs = MIX.ParseConfigMixture(config.Flow.initMixture, Mix)
__demand(__index_launch)
for c in tiles do
INIT.InitializeShuOsherProblem(p_All[c], initMolarFracs)
end
elseif config.Flow.initCase.type == SCHEMA.FlowInitCase_VortexAdvection2D then
var initMolarFracs = MIX.ParseConfigMixture(config.Flow.initMixture, Mix)
__demand(__index_launch)
for c in tiles do
INIT.InitializeVortexAdvection2D(p_All[c],
config.Flow.initCase.u.VortexAdvection2D.pressure,
config.Flow.initCase.u.VortexAdvection2D.temperature,
config.Flow.initCase.u.VortexAdvection2D.velocity[0],
config.Flow.initCase.u.VortexAdvection2D.velocity[1],
initMolarFracs,
Mix)
end
elseif config.Flow.initCase.type == SCHEMA.FlowInitCase_GrossmanCinnellaProblem then
__demand(__index_launch)
for c in tiles do
INIT.InitializeGrossmanCinnellaProblem(p_All[c], Mix)
end
elseif config.Flow.initCase.type == SCHEMA.FlowInitCase_ChannelFlow then
var initMolarFracs = MIX.ParseConfigMixture(config.Flow.initCase.u.ChannelFlow.molarFracs, Mix)
__demand(__index_launch)
for c in tiles do
INIT.InitializeChannelFlow(p_All[c],
config.Flow.initCase.u.ChannelFlow.pressure,
config.Flow.initCase.u.ChannelFlow.temperature,
config.Flow.initCase.u.ChannelFlow.velocity,
config.Flow.initCase.u.ChannelFlow.StreaksIntensity,
config.Flow.initCase.u.ChannelFlow.RandomIntensity,
initMolarFracs,
Mix,
Grid.boundingBox)
end
elseif config.Flow.initCase.type == SCHEMA.FlowInitCase_Restart then