forked from stanfordhpccenter/HTR-solver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
average1DTest.rg
265 lines (220 loc) · 8.38 KB
/
average1DTest.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
import "regent"
-------------------------------------------------------------------------------
-- IMPORTS
-------------------------------------------------------------------------------
local C = regentlib.c
local fabs = regentlib.fabs(double)
local SCHEMA = terralib.includec("../../src/config_schema.h")
local UTIL = require 'util-desugared'
local format = require "std/format"
local Config = SCHEMA.Config
local CONST = require "prometeo_const"
local MACRO = require "prometeo_macro"
local MIX = (require "AirMix")(SCHEMA)
local nSpec = MIX.nSpec
local nEq = CONST.GetnEq(MIX) -- Total number of unknowns for the implicit solver
local Primitives = CONST.Primitives
local Properties = CONST.Properties
local struct Fluid_columns {
-- Grid point
centerCoordinates : double[3];
cellWidth : double[3];
-- Primitive variables
pressure : double;
temperature : double;
MassFracs : double[nSpec];
MolarFracs : double[nSpec];
velocity : double[3];
-- Properties
rho : double;
mu : double;
lam : double;
Di : double[nSpec];
SoS : double;
-- Gradients
velocityGradientX : double[3];
velocityGradientY : double[3];
velocityGradientZ : double[3];
temperatureGradient : double[3];
-- Conserved varaibles
Conserved : double[nEq];
}
--External modules
local IO = (require 'prometeo_IO')(SCHEMA)
local AVG = (require 'prometeo_average')(SCHEMA, MIX, Fluid_columns)
-- Test parameters
local Npx = 16
local Npy = 16
local Npz = 16
local Nx = 2
local Ny = 2
local Nz = 2
local Nrx = 1
local Nry = 1
local Nrz = 1
local fromCell = rexpr array( 1, 1, 1) end
local uptoCell = rexpr array(Npx, Npy, Npz) end
--local R = rexpr 8.3144598 end
local P = rexpr 101325.0 end
local T = rexpr 5000.0 end
local Xi = rexpr array(0.4, 0.2, 0.15, 0.15, 0.1) end
local v = rexpr array(1.0, 2.0, 3.0) end
local Tres = rexpr 500.0 end
-- Expected properties
local eRho = rexpr 6.2899871101668e-02 end
local eMu = rexpr 1.2424467023580e-04 end
local eLam = rexpr 2.2727742147267e-01 end
local eDi = rexpr array(2.5146873480781e-03, 2.4389311883618e-03, 2.4550965167542e-03, 3.6168277168130e-03, 3.9165634179846e-03) end
local eSoS = rexpr 1.4518705966651e+03 end
-- Expected conserved variables
local eConserved = rexpr array(2.7311049167620e-02, 1.5598263689963e-02, 1.0970170602665e-02, 5.1208217189288e-03, 3.8995659224908e-03, 6.2899871101668e-02, 1.2579974220334e-01, 1.8869961330500e-01, 5.4092397631210e+05) end
__demand(__inline)
task InitializeCell(Fluid : region(ispace(int3d), Fluid_columns))
where
writes(Fluid)
do
fill(Fluid.centerCoordinates, array(0.0, 0.0, 0.0))
fill(Fluid.cellWidth, array(0.0, 0.0, 0.0))
fill(Fluid.pressure, [P])
fill(Fluid.temperature, [T])
fill(Fluid.MassFracs, [Xi])
fill(Fluid.MolarFracs, [Xi])
fill(Fluid.velocity, [v])
fill(Fluid.rho, [eRho])
fill(Fluid.mu , [eMu])
fill(Fluid.lam, [eLam])
fill(Fluid.Di , [eDi])
fill(Fluid.SoS, [eSoS])
fill(Fluid.velocityGradientX, array(0.0, 0.0, 0.0))
fill(Fluid.velocityGradientY, array(0.0, 0.0, 0.0))
fill(Fluid.velocityGradientZ, array(0.0, 0.0, 0.0))
fill(Fluid.temperatureGradient, array(0.0, 0.0, 0.0))
fill(Fluid.Conserved, [eConserved])
end
__demand(__inline)
task InitGeometry(Fluid : region(ispace(int3d), Fluid_columns))
where
writes(Fluid.cellWidth)
do
for c in Fluid do
Fluid[c].cellWidth = array(1.0, double(c.y), 1.0)
end
end
local function checkAverages(XAverages, YAverages, ZAverages)
return rquote
for c in (ispace(int2d, {Npy+2, 1}) |
ispace(int2d, {Npy+2, 1}, { 0, Npz+1}) |
ispace(int2d, { 1, Npz+2}) |
ispace(int2d, { 1, Npz+2}, {Npy+1, 0})) do
regentlib.assert(XAverages[int3d{c.x, c.y, 0}].weight == 0.0, "average1DTest: ERROR in XAverages")
end
for c in ispace(int2d, {Npy, Npz}, {1, 1}) do
regentlib.assert(fabs(XAverages[int3d{c.x, c.y, 0}].weight/double(16.0*double(c.x)) - 1.0) < 1e-9, "averageTest: ERROR in XAverages")
end
for c in (ispace(int2d, {Npx+2, 1}) |
ispace(int2d, {Npx+2, 1}, { 0, Npz+1}) |
ispace(int2d, { 1, Npz+2}) |
ispace(int2d, { 1, Npz+2}, {Npx+1, 0})) do
regentlib.assert(YAverages[int3d{c.x, c.y, 0}].weight == 0.0, "average1DTest: ERROR in YAverages")
end
for c in ispace(int2d, {Npx, Npz}, {1, 1}) do
regentlib.assert(fabs(YAverages[int3d{c.x, c.y, 0}].weight/double(136.0) - 1.0) < 1e-9, "averageTest: ERROR in YAverages")
end
for c in (ispace(int2d, {Npx+2, 1}) |
ispace(int2d, {Npx+2, 1}, { 0, Npy+1}) |
ispace(int2d, { 1, Npy+2}) |
ispace(int2d, { 1, Npy+2}, {Npy+1, 0})) do
regentlib.assert(ZAverages[int3d{c.x, c.y, 0}].weight == 0.0, "average1DTest: ERROR in ZAverages")
end
for c in ispace(int2d, {Npx, Npy}, {1, 1}) do
regentlib.assert(fabs(ZAverages[int3d{c.x, c.y, 0}].weight/double(16.0*double(c.y)) - 1.0) < 1e-9, "averageTest: ERROR in ZAverages")
end
end
end
local Averages = AVG.AvgList
local MAPPER = {
SAMPLE_ID_TAG = 1234
}
local Grid = {
xBnum = regentlib.newsymbol(),
yBnum = regentlib.newsymbol(),
zBnum = regentlib.newsymbol(),
NX = regentlib.newsymbol(),
NY = regentlib.newsymbol(),
NZ = regentlib.newsymbol(),
numTiles = regentlib.newsymbol(),
NXout = regentlib.newsymbol(),
NYout = regentlib.newsymbol(),
NZout = regentlib.newsymbol(),
numTilesOut = regentlib.newsymbol(),
}
task main()
-- Init config
var config : Config
config.Flow.initCase.type = SCHEMA.FlowInitCase_Restart
format.snprint([&int8](config.Flow.initCase.u.Restart.restartDir), 256, ".")
config.Grid.xNum = Npx
config.Grid.yNum = Npy
config.Grid.zNum = Npz
config.IO.XAverages.length = Nrx
config.IO.YAverages.length = Nry
config.IO.ZAverages.length = Nrz
config.IO.XAverages.values[0].fromCell = [fromCell]
config.IO.XAverages.values[0].uptoCell = [uptoCell]
config.IO.YAverages.values[0].fromCell = [fromCell]
config.IO.YAverages.values[0].uptoCell = [uptoCell]
config.IO.ZAverages.values[0].fromCell = [fromCell]
config.IO.ZAverages.values[0].uptoCell = [uptoCell]
config.IO.YZAverages.length = 0
config.IO.XZAverages.length = 0
config.IO.XYAverages.length = 0
-- Init the mixture
config.Flow.mixture.type = SCHEMA.MixtureModel_AirMix
var Mix = MIX.InitMixture(config)
-- Define the domain
var [Grid.xBnum] = 1
var [Grid.yBnum] = 1
var [Grid.zBnum] = 1
var [Grid.NX] = Nx
var [Grid.NY] = Ny
var [Grid.NZ] = Nz
var [Grid.numTiles] = Grid.NX * Grid.NY * Grid.NZ
var [Grid.NXout] = 1
var [Grid.NYout] = 1
var [Grid.NZout] = 1
var [Grid.numTilesOut] = Grid.NXout * Grid.NYout * Grid.NZout
-- Define the domain
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);
-- Partitioning domain
var tiles = ispace(int3d, {Grid.NX, Grid.NY, Grid.NZ})
-- Fluid Partitioning
var p_Fluid =
[UTIL.mkPartitionByTile(int3d, int3d, Fluid_columns, "p_All")]
(Fluid, tiles, int3d{Grid.xBnum,Grid.yBnum,Grid.zBnum}, int3d{0,0,0});
[AVG.DeclSymbols(Averages, Grid, Fluid, p_Fluid, config, MAPPER)];
InitializeCell(Fluid)
InitGeometry(Fluid);
-- Initialize averages
[AVG.InitRakesAndPlanes(Averages)];
for i=0, 10 do
[AVG.AddAverages(Averages, rexpr double(0.1) end, config, Mix)];
end
var SpeciesNames = MIX.GetSpeciesNames(Mix)
var dirname = [&int8](C.malloc(256))
C.snprintf(dirname, 256, '.');
[AVG.WriteAverages(Averages, tiles, dirname, IO, SpeciesNames, config)];
[checkAverages(Averages.XAverages, Averages.YAverages, Averages.ZAverages)];
__fence(__execution, __block)
[AVG.ReadAverages(Averages, config)];
[checkAverages(Averages.XAverages, Averages.YAverages, Averages.ZAverages)];
C.free(dirname);
__fence(__execution, __block)
C.printf("average1DTest: TEST OK!\n")
end
-------------------------------------------------------------------------------
-- COMPILATION CALL
-------------------------------------------------------------------------------
regentlib.saveobj(main, "average1DTest.o", "object")