forked from stanfordhpccenter/HTR-solver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
geometryTest.rg
420 lines (347 loc) · 16.3 KB
/
geometryTest.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
import "regent"
-------------------------------------------------------------------------------
-- IMPORTS
-------------------------------------------------------------------------------
local C = regentlib.c
local fabs = regentlib.fabs(double)
local sqrt = regentlib.sqrt(double)
local SCHEMA = terralib.includec("../../src/config_schema.h")
local UTIL = require 'util-desugared'
local Config = SCHEMA.Config
local TYPES = terralib.includec("prometeo_types.h", {"-DEOS="..os.getenv("EOS")})
local Fluid_columns = TYPES.Fluid_columns
--External modules
local MACRO = require "prometeo_macro"
local METRIC = (require 'prometeo_metric')(SCHEMA, Fluid_columns)
local PART = (require 'prometeo_partitioner')(SCHEMA, METRIC, Fluid_columns)
local GRID = (require 'prometeo_grid')(SCHEMA, Fluid_columns, PART.zones_partitions)
-- Test parameters
local Npx = 32
local Npy = 32
local Npz = 32
local Nx = 2
local Ny = 2
local Nz = 2
local xO = 1.0
local yO = 1.0
local zO = 1.0
local xW = 1.0
local yW = 1.0
local zW = 1.0
__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.nType_x, 0)
fill(Fluid.nType_y, 0)
fill(Fluid.nType_z, 0)
fill(Fluid.dcsi_e, 0.0)
fill(Fluid.deta_e, 0.0)
fill(Fluid.dzet_e, 0.0)
fill(Fluid.dcsi_d, 0.0)
fill(Fluid.deta_d, 0.0)
fill(Fluid.dzet_d, 0.0)
fill(Fluid.dcsi_s, 0.0)
fill(Fluid.deta_s, 0.0)
fill(Fluid.dzet_s, 0.0)
end
function runPeriodic()
local task checkGeometry(Fluid : region(ispace(int3d), Fluid_columns),
Grid_xType : SCHEMA.GridType, Grid_yType : SCHEMA.GridType, Grid_zType : SCHEMA.GridType,
Grid_xStretching : double, Grid_yStretching : double, Grid_zStretching : double,
Grid_xBnum : int32, Grid_xNum : int32, Grid_xOrigin : double, Grid_xWidth : double,
Grid_yBnum : int32, Grid_yNum : int32, Grid_yOrigin : double, Grid_yWidth : double,
Grid_zBnum : int32, Grid_zNum : int32, Grid_zOrigin : double, Grid_zWidth : double)
where
reads(Fluid.centerCoordinates),
reads(Fluid.cellWidth)
do
regentlib.assert(Grid_xType == SCHEMA.GridType_Uniform, "geometryTest: only Uniform supported for now")
regentlib.assert(Grid_yType == SCHEMA.GridType_Uniform, "geometryTest: only Uniform supported for now")
regentlib.assert(Grid_zType == SCHEMA.GridType_Uniform, "geometryTest: only Uniform supported for now")
for c in Fluid do
var x_exp = (c.x+0.5)/Grid_xNum*Grid_xWidth + Grid_xOrigin
var dx_exp = Grid_xWidth/Grid_xNum
regentlib.assert(fabs((Fluid[c].centerCoordinates[0]/(x_exp)) - 1.0) < 1e-3, "geometryTest: ERROR in checkGeometry x coordinate")
regentlib.assert(fabs((Fluid[c].cellWidth[0]/(dx_exp)) - 1.0) < 1e-3, "geometryTest: ERROR in checkGeometry dx")
var y_exp = (c.y+0.5)/Grid_yNum*Grid_yWidth + Grid_yOrigin
var dy_exp = Grid_yWidth/Grid_yNum
regentlib.assert(fabs((Fluid[c].centerCoordinates[1]/(y_exp)) - 1.0) < 1e-3, "geometryTest: ERROR in checkGeometry y coordinate")
regentlib.assert(fabs((Fluid[c].cellWidth[1]/(dy_exp)) - 1.0) < 1e-3, "geometryTest: ERROR in checkGeometry dy")
var z_exp = (c.z+0.5)/Grid_zNum*Grid_zWidth + Grid_zOrigin
var dz_exp = Grid_zWidth/Grid_zNum
regentlib.assert(fabs((Fluid[c].centerCoordinates[2]/(z_exp)) - 1.0) < 1e-3, "geometryTest: ERROR in checkGeometry z coordinate")
regentlib.assert(fabs((Fluid[c].cellWidth[2]/(dz_exp)) - 1.0) < 1e-3, "geometryTest: ERROR in checkGeometry dz")
end
end
return rquote
var config : SCHEMA.Config
config.BC.xBCLeft.type = SCHEMA.FlowBC_Periodic
config.BC.xBCRight.type = SCHEMA.FlowBC_Periodic
config.BC.yBCLeft.type = SCHEMA.FlowBC_Periodic
config.BC.yBCRight.type = SCHEMA.FlowBC_Periodic
config.BC.zBCLeft.type = SCHEMA.FlowBC_Periodic
config.BC.zBCRight.type = SCHEMA.FlowBC_Periodic
-- No ghost cells
var xBnum = 0
var yBnum = 0
var zBnum = 0
-- Define the domain
var is_Fluid = ispace(int3d, {x = Npx + 2*xBnum,
y = Npy + 2*yBnum,
z = Npz + 2*zBnum})
var Fluid = region(is_Fluid, Fluid_columns);
-- Partitioning domain
var tiles = ispace(int3d, {Nx, Ny, Nz})
-- Fluid Partitioning
var Fluid_Zones = PART.PartitionZones(Fluid, tiles, config, xBnum, yBnum, zBnum)
var {p_All} = Fluid_Zones
InitializeCell(Fluid)
__demand(__index_launch)
for c in tiles do
GRID.InitializeGeometry(p_All[c],
SCHEMA.GridType_Uniform, SCHEMA.GridType_Uniform, SCHEMA.GridType_Uniform,
1.0, 1.0, 1.0,
xBnum, Npx, xO, xW,
yBnum, Npy, yO, yW,
zBnum, Npz, zO, zW)
end
checkGeometry(Fluid,
SCHEMA.GridType_Uniform, SCHEMA.GridType_Uniform, SCHEMA.GridType_Uniform,
1.0, 1.0, 1.0,
xBnum, Npx, xO, xW,
yBnum, Npy, yO, yW,
zBnum, Npz, zO, zW)
end
end
function runStaggeredBC()
local task checkGeometry(Fluid : region(ispace(int3d), Fluid_columns),
Grid_xType : SCHEMA.GridType, Grid_yType : SCHEMA.GridType, Grid_zType : SCHEMA.GridType,
Grid_xStretching : double, Grid_yStretching : double, Grid_zStretching : double,
Grid_xBnum : int32, Grid_xNum : int32, Grid_xOrigin : double, Grid_xWidth : double,
Grid_yBnum : int32, Grid_yNum : int32, Grid_yOrigin : double, Grid_yWidth : double,
Grid_zBnum : int32, Grid_zNum : int32, Grid_zOrigin : double, Grid_zWidth : double)
where
reads(Fluid.centerCoordinates),
reads(Fluid.cellWidth)
do
regentlib.assert(Grid_xType == SCHEMA.GridType_Uniform, "geometryTest: only Uniform supported for now")
regentlib.assert(Grid_yType == SCHEMA.GridType_Uniform, "geometryTest: only Uniform supported for now")
regentlib.assert(Grid_zType == SCHEMA.GridType_Uniform, "geometryTest: only Uniform supported for now")
for c in Fluid do
var xNegGhost = MACRO.is_xNegGhost(c, Grid_xBnum)
var xPosGhost = MACRO.is_xPosGhost(c, Grid_xBnum, Grid_xNum)
var yNegGhost = MACRO.is_yNegGhost(c, Grid_yBnum)
var yPosGhost = MACRO.is_yPosGhost(c, Grid_yBnum, Grid_yNum)
var zNegGhost = MACRO.is_zNegGhost(c, Grid_zBnum)
var zPosGhost = MACRO.is_zPosGhost(c, Grid_zBnum, Grid_zNum)
var dx_exp : double
var x_exp : double
var dy_exp : double
var y_exp : double
var dz_exp : double
var z_exp : double
if xNegGhost then
dx_exp = 1e-12
x_exp = Grid_xOrigin
elseif xPosGhost then
dx_exp = 1e-12
x_exp = Grid_xWidth + Grid_xOrigin
else
dx_exp = Grid_xWidth/Grid_xNum
x_exp = (c.x-Grid_xBnum+0.5)/Grid_xNum*Grid_xWidth + Grid_xOrigin
end
if yNegGhost then
dy_exp = 1e-12
y_exp = Grid_yOrigin
elseif yPosGhost then
dy_exp = 1e-12
y_exp = Grid_yWidth + Grid_yOrigin
else
dy_exp = Grid_yWidth/Grid_yNum
y_exp = (c.y-Grid_yBnum+0.5)/Grid_yNum*Grid_yWidth + Grid_yOrigin
end
if zNegGhost then
dz_exp = 1e-12
z_exp = Grid_zOrigin
elseif zPosGhost then
dz_exp = 1e-12
z_exp = Grid_zWidth + Grid_zOrigin
else
dz_exp = Grid_zWidth/Grid_zNum
z_exp = (c.z-Grid_zBnum+0.5)/Grid_zNum*Grid_zWidth + Grid_zOrigin
end
regentlib.assert(fabs((Fluid[c].centerCoordinates[0]/(x_exp)) - 1.0) < 1e-3, "geometryTest: ERROR in checkGeometryStaggeredBC x coordinate")
regentlib.assert(Fluid[c].cellWidth[0] == dx_exp, "geometryTest: ERROR in checkGeometryStaggeredBC dx")
regentlib.assert(fabs((Fluid[c].centerCoordinates[1]/(y_exp)) - 1.0) < 1e-3, "geometryTest: ERROR in checkGeometryStaggeredBC y coordinate")
regentlib.assert(Fluid[c].cellWidth[1] == dy_exp, "geometryTest: ERROR in checkGeometryStaggeredBC dy")
regentlib.assert(fabs((Fluid[c].centerCoordinates[2]/(z_exp)) - 1.0) < 1e-3, "geometryTest: ERROR in checkGeometryStaggeredBC z coordinate")
regentlib.assert(Fluid[c].cellWidth[2] == dz_exp, "geometryTest: ERROR in checkGeometryStaggeredBC dz")
end
end
return rquote
var config : SCHEMA.Config
config.BC.xBCLeft.type = SCHEMA.FlowBC_Dirichlet
config.BC.xBCRight.type = SCHEMA.FlowBC_Dirichlet
config.BC.yBCLeft.type = SCHEMA.FlowBC_Dirichlet
config.BC.yBCRight.type = SCHEMA.FlowBC_Dirichlet
config.BC.zBCLeft.type = SCHEMA.FlowBC_Dirichlet
config.BC.zBCRight.type = SCHEMA.FlowBC_Dirichlet
-- No ghost cells
var xBnum = 1
var yBnum = 1
var zBnum = 1
-- Define the domain
var is_Fluid = ispace(int3d, {x = Npx + 2*xBnum,
y = Npy + 2*yBnum,
z = Npz + 2*zBnum})
var Fluid = region(is_Fluid, Fluid_columns);
-- Partitioning domain
var tiles = ispace(int3d, {Nx, Ny, Nz})
-- Fluid Partitioning
var Fluid_Zones = PART.PartitionZones(Fluid, tiles, config, xBnum, yBnum, zBnum)
var {p_All} = Fluid_Zones
InitializeCell(Fluid)
__demand(__index_launch)
for c in tiles do
GRID.InitializeGeometry(p_All[c],
SCHEMA.GridType_Uniform, SCHEMA.GridType_Uniform, SCHEMA.GridType_Uniform,
1.0, 1.0, 1.0,
xBnum, Npx, xO, xW,
yBnum, Npy, yO, yW,
zBnum, Npz, zO, zW)
end
-- Enforce BCs
GRID.InitializeGhostGeometry(Fluid, tiles, Fluid_Zones, config)
checkGeometry(Fluid,
SCHEMA.GridType_Uniform, SCHEMA.GridType_Uniform, SCHEMA.GridType_Uniform,
1.0, 1.0, 1.0,
xBnum, Npx, xO, xW,
yBnum, Npy, yO, yW,
zBnum, Npz, zO, zW)
end
end
function runCollocatedBC()
local task checkGeometry(Fluid : region(ispace(int3d), Fluid_columns),
Grid_xType : SCHEMA.GridType, Grid_yType : SCHEMA.GridType, Grid_zType : SCHEMA.GridType,
Grid_xStretching : double, Grid_yStretching : double, Grid_zStretching : double,
Grid_xBnum : int32, Grid_xNum : int32, Grid_xOrigin : double, Grid_xWidth : double,
Grid_yBnum : int32, Grid_yNum : int32, Grid_yOrigin : double, Grid_yWidth : double,
Grid_zBnum : int32, Grid_zNum : int32, Grid_zOrigin : double, Grid_zWidth : double)
where
reads(Fluid.centerCoordinates),
reads(Fluid.cellWidth)
do
regentlib.assert(Grid_xType == SCHEMA.GridType_Uniform, "geometryTest: only Uniform supported for now")
regentlib.assert(Grid_yType == SCHEMA.GridType_Uniform, "geometryTest: only Uniform supported for now")
regentlib.assert(Grid_zType == SCHEMA.GridType_Uniform, "geometryTest: only Uniform supported for now")
for c in Fluid do
var xNegGhost = MACRO.is_xNegGhost(c, Grid_xBnum)
var xPosGhost = MACRO.is_xPosGhost(c, Grid_xBnum, Grid_xNum)
var yNegGhost = MACRO.is_yNegGhost(c, Grid_yBnum)
var yPosGhost = MACRO.is_yPosGhost(c, Grid_yBnum, Grid_yNum)
var zNegGhost = MACRO.is_zNegGhost(c, Grid_zBnum)
var zPosGhost = MACRO.is_zPosGhost(c, Grid_zBnum, Grid_zNum)
var dx_exp : double
var x_exp : double
var dy_exp : double
var y_exp : double
var dz_exp : double
var z_exp : double
if xNegGhost then
dx_exp = Grid_xWidth/Grid_xNum
x_exp = Grid_xOrigin - 0.5*dx_exp
elseif xPosGhost then
dx_exp = Grid_xWidth/Grid_xNum
x_exp = Grid_xOrigin + Grid_xWidth + 0.5*dx_exp
else
dx_exp = Grid_xWidth/Grid_xNum
x_exp = (c.x-Grid_xBnum+0.5)/Grid_xNum*Grid_xWidth + Grid_xOrigin
end
if yNegGhost then
dy_exp = Grid_yWidth/Grid_yNum
y_exp = Grid_yOrigin - 0.5*dy_exp
elseif yPosGhost then
dy_exp = Grid_yWidth/Grid_yNum
y_exp = Grid_yOrigin + Grid_yWidth + 0.5*dy_exp
else
dy_exp = Grid_yWidth/Grid_yNum
y_exp = (c.y-Grid_yBnum+0.5)/Grid_yNum*Grid_yWidth + Grid_yOrigin
end
if zNegGhost then
dz_exp = Grid_zWidth/Grid_zNum
z_exp = Grid_zOrigin - 0.5*dz_exp
elseif zPosGhost then
dz_exp = Grid_zWidth/Grid_zNum
z_exp = Grid_zOrigin + Grid_zWidth + 0.5*dz_exp
else
dz_exp = Grid_zWidth/Grid_zNum
z_exp = (c.z-Grid_zBnum+0.5)/Grid_zNum*Grid_zWidth + Grid_zOrigin
end
regentlib.assert(fabs((Fluid[c].centerCoordinates[0]/(x_exp)) - 1.0) < 1e-3, "geometryTest: ERROR in checkGeometryCollocatedBC x coordinate")
regentlib.assert(fabs((Fluid[c].cellWidth[0]/(dx_exp)) - 1.0) < 1e-3, "geometryTest: ERROR in checkGeometryCollocatedBC dx")
regentlib.assert(fabs((Fluid[c].centerCoordinates[1]/(y_exp)) - 1.0) < 1e-3, "geometryTest: ERROR in checkGeometryCollocatedBC y coordinate")
regentlib.assert(fabs((Fluid[c].cellWidth[1]/(dy_exp)) - 1.0) < 1e-3, "geometryTest: ERROR in checkGeometryCollocatedBC dy")
regentlib.assert(fabs((Fluid[c].centerCoordinates[2]/(z_exp)) - 1.0) < 1e-3, "geometryTest: ERROR in checkGeometryCollocatedBC z coordinate")
regentlib.assert(fabs((Fluid[c].cellWidth[2]/(dz_exp)) - 1.0) < 1e-3, "geometryTest: ERROR in checkGeometryCollocatedBC dz")
end
end
return rquote
var config : SCHEMA.Config
config.BC.xBCLeft.type = SCHEMA.FlowBC_NSCBC_Inflow
config.BC.xBCRight.type = SCHEMA.FlowBC_NSCBC_Inflow
config.BC.yBCLeft.type = SCHEMA.FlowBC_NSCBC_Inflow
config.BC.yBCRight.type = SCHEMA.FlowBC_NSCBC_Inflow
config.BC.zBCLeft.type = SCHEMA.FlowBC_NSCBC_Inflow
config.BC.zBCRight.type = SCHEMA.FlowBC_NSCBC_Inflow
-- No ghost cells
var xBnum = 1
var yBnum = 1
var zBnum = 1
-- Define the domain
var is_Fluid = ispace(int3d, {x = Npx + 2*xBnum,
y = Npy + 2*yBnum,
z = Npz + 2*zBnum})
var Fluid = region(is_Fluid, Fluid_columns);
-- Partitioning domain
var tiles = ispace(int3d, {Nx, Ny, Nz})
-- Fluid Partitioning
var Fluid_Zones = PART.PartitionZones(Fluid, tiles, config, xBnum, yBnum, zBnum)
var {p_All} = Fluid_Zones
InitializeCell(Fluid)
__demand(__index_launch)
for c in tiles do
GRID.InitializeGeometry(p_All[c],
SCHEMA.GridType_Uniform, SCHEMA.GridType_Uniform, SCHEMA.GridType_Uniform,
1.0, 1.0, 1.0,
xBnum, Npx, xO, xW,
yBnum, Npy, yO, yW,
zBnum, Npz, zO, zW)
end
-- Enforce BCs
GRID.InitializeGhostGeometry(Fluid, tiles, Fluid_Zones, config)
checkGeometry(Fluid,
SCHEMA.GridType_Uniform, SCHEMA.GridType_Uniform, SCHEMA.GridType_Uniform,
1.0, 1.0, 1.0,
xBnum, Npx, xO, xW,
yBnum, Npy, yO, yW,
zBnum, Npz, zO, zW)
end
end
task main()
-- Start with a periodic case
[runPeriodic()];
-- Start with a staggered bc case
[runStaggeredBC()];
-- Start with a collocated bc case
[runCollocatedBC()];
__fence(__execution, __block)
C.printf("geometryTest: TEST OK!\n")
end
-------------------------------------------------------------------------------
-- COMPILATION CALL
-------------------------------------------------------------------------------
regentlib.saveobj(main, "geometryTest.o", "object")