forked from ZhenyuWu1999/KNEC
-
Notifications
You must be signed in to change notification settings - Fork 2
/
grid_setup.py
56 lines (42 loc) · 1.52 KB
/
grid_setup.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
###############################################################################
#
# This file generates a pattern used for the gridding of the SNEC models
#
# Total number of grid points is equal to imax.
# Current pattern consists of two geometric progressions, connected at the
# point itran and ensuring finer resolution of the grid in the inner (explosion)
# region and the surface region of the models.
#
# ratio1 gives the ratio between the size of the first and itran-th cell
# ratio2 gives the ratio between the size of the last and itran-th cell
#
###############################################################################
from __future__ import division
import math
delta = []
grid_pattern = []
imax = 1000
itran = 100
ratio1 = 0.1
ratio2 = 0.001
f1 = ratio1**(1/(itran-2))
f2 = ratio2**(1/(imax-itran-1))
delta_tran = ( (1-f2)*(1-f1)
/((1-f2)*(1-f1**(itran-1))+(1-f1)*(1-f2**(imax-itran))) )
for l in range(0,itran-1):
delta.append(delta_tran*f1**(itran-2-l))
for l in range(0,imax-itran):
delta.append(delta_tran*f2**(l))
grid_pattern.append(0.0)
for l in range(0,imax-1):
grid_pattern.append(grid_pattern[l]+delta[l])
#increase resolution near outer boundary
for l in range(imax-201,imax-1):
grid_pattern.append((grid_pattern[l]+grid_pattern[l+1])/2)
grid_pattern.sort()
print ("grid pattern consists of", len(grid_pattern), "points")
outfile = open("GridPattern1200.dat","w")
for l in range(0,imax+200):
outfile.write(str(grid_pattern[l]) + '\n')
outfile.close()
print("done!")