-
Notifications
You must be signed in to change notification settings - Fork 1
/
run-peregrine.py
executable file
·82 lines (62 loc) · 2.21 KB
/
run-peregrine.py
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
#!/usr/bin/env python
import mpi4py.rc
mpi4py.rc.initialize = False
import kokkos
import peregrinepy as pg
import time
import sys
def simulate(config_file_path):
# Import but do not initialise MPI
from mpi4py import MPI
# Manually initialise MPI
MPI.Init()
comm,rank,size = pg.mpicomm.mpiutils.get_comm_rank_size()
# Ensure MPI is suitably cleaned up
pg.mpicomm.mpiutils.register_finalize_handler()
config = pg.mpicomm.mpiread_config(config_file_path)
mb = pg.construct_mb(config)
pg.grid.generate_halo(mb)
pg.mpicomm.blockcomm.communicate(mb,['x','y','z'])
for blk in mb:
blk.init_solver_arrays(config)
pg.compute.metrics(mb)
# init flow
for blk in mb:
# Prim
blk.array['q'][:,:,:,0] = 101325.0
blk.array['q'][:,:,:,1] = 10.0 #mb.np.random.random(blk.array['q'][1:-1,1:-1,1:-1,1].shape)
#blk.array['q'][1:-1,1:-1,1:-1,2] = 0.0
#blk.array['q'][1:-1,1:-1,1:-1,3] = 0.0
blk.array['q'][:,:,:,4] = 300 #np.random.random(blk.array['q'][1:-1,1:-1,1:-1,1].shape)*300
blk.array['q'][3:6,:,:,4] = 350 #np.random.random(blk.array['q'][1:-1,1:-1,1:-1,1].shape)*300
#Get Density
mb.eos(blk,mb.thermdat,'0','prims')
#Zero out prims
blk.array['q'][1:-1,1:-1,1:-1,0] = 0.0
blk.array['q'][1:-1,1:-1,1:-1,1] = 0.0
blk.array['q'][1:-1,1:-1,1:-1,4] = 0.0
pg.consistify(mb)
pg.writers.write_restart(mb,config['io']['outputdir'],grid_path='../Grid')
niterout = 1000
#ts = time.time()
for i in range(10000):
print(mb.nrt,mb.tme)
mb.step(1e-6)
if mb.nrt%niterout == 0:
pg.writers.write_restart(mb,config['io']['outputdir'],grid_path='../Grid')
#print(time.time()-ts, 'took this many seconds')
# Finalise MPI
MPI.Finalize()
if __name__ == "__main__":
config_file_path = sys.argv[1]
try:
kokkos.initialize()
simulate(config_file_path)
kokkos.finalize()
except Exception as e:
import sys
import traceback
print(f"{e}")
exc_type, exc_value, exc_traceback = sys.exc_info()
traceback.print_exception(exc_type, exc_value, exc_traceback)
sys.exit(1)