Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ dependencies = [
"matplotlib >= 3.8.0",
"netCDF4 >= 1.7",
"freeqdsk >= 0.4.0",
"shapely",
]
dynamic = ["version"]

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# the following line installs requirements from setup.py
# the following line installs requirements from pyproject.toml
-e .
24 changes: 17 additions & 7 deletions zoidberg/poloidal_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import warnings

import numpy as np
import shapely
from numpy import linspace, pi, zeros
from scipy.interpolate import RectBivariateSpline
from scipy.spatial import cKDTree as KDTree
Expand Down Expand Up @@ -281,17 +282,26 @@ def __init__(self, R, Z):
self.R = R
self.Z = Z

# Create a KDTree for quick lookup of nearest points
n = R.size
data = np.concatenate((R.reshape((n, 1)), Z.reshape((n, 1))), axis=1)
self.tree = KDTree(data)

# Create splines for quick interpolation of coordinates
nx, nz = R.shape

self.nx = nx
self.nz = nz

if nx > 4:
inner = shapely.Polygon(zip(R[2, :], Z[2, :]))
outer = shapely.Polygon(zip(R[-2, :], Z[-2, :]))

assert (
inner.area <= outer.area
), f"""You are trying to create a grid with inner boundary at high x
and outer boundary at low x. This is against the convention -
switch inner and outer boundary.
{inner.area} {outer.area}"""

# Create a KDTree for quick lookup of nearest points
data = np.concatenate((R.reshape((-1, 1)), Z.reshape((-1, 1))), axis=1)
self.tree = KDTree(data)

# Create splines for quick interpolation of coordinates
xinds = np.arange(nx)
zinds = np.arange(nz * 3)
# Repeat the data in z, to approximate periodicity
Expand Down