|
@@ -3,25 +3,28 @@ import pprint
|
3
|
3
|
|
4
|
4
|
def calcH( oxx, nxx, dxx, pad ):
|
5
|
5
|
"""Calculates grid spacing along a dimension, if padding cells are requested those are incorporated too"""
|
6
|
|
- pp = 1.1 # fixed padding expansion factor
|
|
6
|
+ px = np.arange(oxx, oxx+(nxx+1)*dxx, dxx)
|
|
7
|
+ hx = dxx*np.ones(nxx)
|
7
|
8
|
if not pad:
|
8
|
|
- px = np.arange(oxx-dxx/2, oxx-dxx/2+(nxx+1)*dxx, dxx)
|
9
|
|
- hx = dxx*np.ones(nxx)
|
|
9
|
+ #px = np.arange(oxx-dxx/2, oxx-dxx/2+(nxx+1)*dxx, dxx)
|
10
|
10
|
return hx, px
|
11
|
11
|
else:
|
12
|
|
- hx = np.zeros( nxx )
|
13
|
|
- for ip in range(0,pad):
|
14
|
|
- hx[ip] = dxx*pp**(pad-ip)
|
15
|
|
- hx[pad:nxx-pad] = dxx
|
16
|
|
- ip = 1
|
17
|
|
- for ii in range (nxx-pad, nxx):
|
18
|
|
- hx[ii] = dxx*pp**ip
|
19
|
|
- ip += 1
|
20
|
|
-
|
21
|
|
- px = np.zeros( nxx + 1 ) # interfaces
|
22
|
|
- px[0] = oxx - (dxx*pp**pad)/2
|
23
|
|
- for i, h in enumerate(hx):
|
24
|
|
- px[i+1] = px[i]+h
|
|
12
|
+ pp = 1.1 # fixed padding expansion factor
|
|
13
|
+ px_padhi = np.zeros( pad+1 )
|
|
14
|
+ px_padlo = np.zeros( pad+1 )
|
|
15
|
+ hx_pad = np.zeros( pad )
|
|
16
|
+ hx_pad[0] = dxx*pp
|
|
17
|
+ px_padhi[0] = px[-1] # hi end
|
|
18
|
+ px_padlo[0] = px[0] # lo end
|
|
19
|
+ for ip in range(1,pad):
|
|
20
|
+ px_padhi[ip] = px_padhi[ip-1] + hx_pad[ip-1]
|
|
21
|
+ px_padlo[ip] = px_padlo[ip-1] - hx_pad[ip-1]
|
|
22
|
+ hx_pad[ip] = pp*hx_pad[ip-1]
|
|
23
|
+ px_padhi[-1] = px_padhi[-2] + hx_pad[-1]
|
|
24
|
+ px_padlo[-1] = px_padlo[-2] - hx_pad[-1]
|
|
25
|
+
|
|
26
|
+ hx = np.concatenate((hx_pad[::-1],hx, hx_pad))
|
|
27
|
+ px = np.concatenate((px_padlo[1::][::-1], px, px_padhi[1::]))
|
25
|
28
|
|
26
|
29
|
return hx, px
|
27
|
30
|
|
|
@@ -44,30 +47,29 @@ def writeH(fout, h, p):
|
44
|
47
|
fout.write(" ")
|
45
|
48
|
|
46
|
49
|
def writeGRD(fout, args):
|
47
|
|
-
|
48
|
|
- fout.write( "%i\t%i\t%i\t// nx ny nz\n" %(args.nx[0],args.ny[0],args.nz[0]) )
|
49
|
|
- fout.write( "%f\t%f\t%f\t// ox oy oz\n" %(args.ox[0],args.oy[0],args.oz[0]) )
|
50
|
50
|
|
51
|
|
- fout.write("\n// hx\n")
|
52
|
51
|
hx,px = calcH( args.ox[0], args.nx[0], args.dx[0], args.pad )
|
53
|
|
- writeH(fout, hx, px)
|
|
52
|
+ hy,py = calcH( args.oy[0], args.ny[0], args.dy[0], args.pad )
|
|
53
|
+ hz,pz = calcH( args.oz[0], args.nz[0], args.dz[0], args.pad )
|
|
54
|
+
|
|
55
|
+ fout.write( "%i %i %i // nx ny nz\n" %(args.nx[0]+2*args.pad,args.ny[0]+2*args.pad,args.nz[0]+2*args.pad) )
|
|
56
|
+ #fout.write( "%f %f %f // ox oy oz (cell centres)\n" %(args.ox[0]+args.dx[0]/2, args.oy[0]+args.dy[0]/2, args.oz[0]+args.dz[0]/2))
|
|
57
|
+ fout.write( "%f %f %f // ox oy oz (cell centres)\n" %(px[0]+.5*hx[0], py[0]+.5*hy[0], pz[0]+.5*hz[0]))
|
54
|
58
|
|
|
59
|
+ fout.write("\n// hx\n")
|
|
60
|
+ writeH(fout, hx, px)
|
55
|
61
|
fout.write("\n// hy\n")
|
56
|
|
- hy,py = calcH( args.oy[0], args.ny[0], args.dy[0], args.pad )
|
57
|
62
|
writeH(fout, hy, py)
|
58
|
|
-
|
59
|
63
|
fout.write("\n// hz\n")
|
60
|
|
- hz,pz = calcH( args.oz[0], args.nz[0], args.dz[0], args.pad )
|
61
|
64
|
writeH(fout, hz, pz)
|
62
|
65
|
|
63
|
|
- fout.write("\n\n")
|
64
|
|
- #fout.write( "// vim: set tabstop=4 expandtab:\n")
|
|
66
|
+ fout.write("\n")
|
65
|
67
|
fout.write( "// vim: set filetype=cpp:\n")
|
66
|
68
|
|
67
|
69
|
return px,py,pz
|
68
|
70
|
|
69
|
|
-def writeMOD(fout, args, px, py, pz):
|
70
|
|
- sigma = np.zeros( (args.nx[0], args.ny[0], args.nz[0]) )
|
|
71
|
+def writeMOD(fout, args, px, py, pz, pad=0):
|
|
72
|
+ sigma = np.zeros( (args.nx[0]+2*pad, args.ny[0]+2*pad, args.nz[0]+2*pad) )
|
71
|
73
|
sigma[:,:,pz[1:]>0] = 0.05
|
72
|
74
|
xlo = np.where( px[0:-1] >= args.bxlo[0] )[0][0]
|
73
|
75
|
xhi = np.where( px[1:] <= args.bxhi[0] )[0][-1] + 1
|
|
@@ -94,22 +96,22 @@ PAD = 0
|
94
|
96
|
parser = argparse.ArgumentParser(description='Set up test EMSchur3D block problem.')
|
95
|
97
|
|
96
|
98
|
parser.add_argument('nx', metavar='nx', type=int, nargs=1,
|
97
|
|
- help='number of cells in x')
|
|
99
|
+ help='number of cells in x, does NOT include padding cells')
|
98
|
100
|
|
99
|
101
|
parser.add_argument('ny', metavar='ny', type=int, nargs=1,
|
100
|
|
- help='number of cells in y')
|
|
102
|
+ help='number of cells in y, does NOT include padding cells')
|
101
|
103
|
|
102
|
104
|
parser.add_argument('nz', metavar='nz', type=int, nargs=1,
|
103
|
|
- help='number of cells in z')
|
|
105
|
+ help='number of cells in z, does NOT include padding cells')
|
104
|
106
|
|
105
|
107
|
parser.add_argument('ox', metavar='ox', type=float, nargs=1,
|
106
|
|
- help='offset of grid in x')
|
|
108
|
+ help='offset of grid in x (low edge of cell not centre), if pad is true ox should NOT include padding')
|
107
|
109
|
|
108
|
110
|
parser.add_argument('oy', metavar='oy', type=float, nargs=1,
|
109
|
|
- help='offset of grid in y')
|
|
111
|
+ help='offset of grid in y (low edge of cell not centre), if pad is true oy should NOT include padding')
|
110
|
112
|
|
111
|
113
|
parser.add_argument('oz', metavar='oz', type=float, nargs=1,
|
112
|
|
- help='offset of grid in z')
|
|
114
|
+ help='offset of grid in z (low edge of cell not centre), if pad is true oz should NOT include padding')
|
113
|
115
|
|
114
|
116
|
parser.add_argument('dx', metavar='dx', type=int, nargs=1,
|
115
|
117
|
help='minimum spacing in x')
|
|
@@ -149,7 +151,7 @@ px,py,pz = writeGRD(fout, args)
|
149
|
151
|
fout.close()
|
150
|
152
|
|
151
|
153
|
mout = open("example.mod", 'w')
|
152
|
|
-writeMOD(mout, args, px, py, pz)
|
|
154
|
+writeMOD(mout, args, px, py, pz, args.pad)
|
153
|
155
|
|
154
|
156
|
#print(args.nx)
|
155
|
157
|
#print(args.accumulate(args.nx))
|