Skip to content

Commit 0ad4acf

Browse files
authored
Merge pull request #81 from mredenti/patch-1
Generation of grid points in boutdata.resize
2 parents eec47f4 + b98f735 commit 0ad4acf

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

boutdata/restart.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def resize3DField(var, data, coordsAndSizesTuple, method, mute):
7070
# https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.RegularGridInterpolator.html
7171
# for details)
7272
gridInterpolator = RegularGridInterpolator(
73-
(xCoordOld, yCoordOld, zCoordOld), data, method
73+
(xCoordOld, yCoordOld, zCoordOld), data, method, bounds_error = False, fill_value = None
7474
)
7575

7676
# Need to fill with one exrta z plane (will only contain zeros)
@@ -184,19 +184,28 @@ def is_pow2(x):
184184
break
185185

186186
nx, ny, nz = data.shape
187+
dx, dy, dz = old['dx'].flat[0], old['dy'].flat[0], old['dz'].flat[0]
188+
# shift grid if CELL-CENTRED
189+
xshift = 0.0 if old.attributes(var)['cell_location'] == 'CELL_XLOW' else 0.5
190+
yshift = 0.0 if old.attributes(var)['cell_location'] == 'CELL_YLOW' else 0.5
191+
zshift = 0.0 if old.attributes(var)['cell_location'] == 'CELL_ZLOW' else 0.5
192+
187193
# Make coordinates
188194
# NOTE: The max min of the coordinates are irrelevant when
189195
# interpolating (as long as old and new coordinates
190196
# are consistent), so we just choose all variable to
191-
# be between 0 and 1 Calculate the old coordinates
192-
xCoordOld = np.linspace(0, 1, nx)
193-
yCoordOld = np.linspace(0, 1, ny)
194-
zCoordOld = np.linspace(0, 1, nz)
195-
197+
# be between 0 and 1 Calculate the old coordinates
198+
xCoordOld = (np.arange(nx) - mxg + xshift)*dx
199+
yCoordOld = (np.arange(ny) - myg + yshift)*dy
200+
zCoordOld = (np.arange(nz) + zshift)*dz
201+
# Calculate the new spacing
202+
newDx= dx * ((nx - 2*mxg) / (newNx - 2*mxg) )
203+
newDy= dy * ((ny - 2*myg) / (newNy - 2*myg) )
204+
newDz= dz * (nz / newNz )
196205
# Calculate the new coordinates
197-
xCoordNew = np.linspace(xCoordOld[0], xCoordOld[-1], newNx)
198-
yCoordNew = np.linspace(yCoordOld[0], yCoordOld[-1], newNy)
199-
zCoordNew = np.linspace(zCoordOld[0], zCoordOld[-1], newNz)
206+
xCoordNew = (np.arange(newNx) - mxg + xshift)*newDx
207+
yCoordNew = (np.arange(newNy) - myg + yshift)*newDy
208+
zCoordNew = (np.arange(newNz) + zshift)*newDz
200209

201210
# Make a pool of workers
202211
pool = multiprocessing.Pool(maxProc)
@@ -240,7 +249,7 @@ def is_pow2(x):
240249
else:
241250
if not (mute):
242251
print(" Copying " + var)
243-
newData = data.copy()
252+
newData = data.copy()
244253
if not (mute):
245254
print("Writing " + var)
246255
new.write(var, newData)

0 commit comments

Comments
 (0)