33import jax .numpy as jnp
44from functools import partial
55from jax import jit , jacfwd , grad , vmap , tree_util , lax
6- from essos .surfaces import SurfaceRZFourier
6+ from essos .surfaces import SurfaceRZFourier , BdotN_over_B
77from essos .plot import fix_matplotlib_3d
88from essos .util import newton
99
@@ -620,7 +620,7 @@ def compute_RZ(m, n):
620620 def B_mag (self , r , theta , phi ):
621621 return self .B0 * (1 + r * self .etabar * jnp .cos (theta - (self .iota - self .iotaN ) * phi ))
622622
623- def plot (self , r = 0.1 , ntheta = 80 , nphi = 150 , ntheta_fourier = 20 , ax = None , show = True , close = False , axis_equal = True , ** kwargs ):
623+ def plot (self , r = 0.1 , ntheta = 40 , nphi = 120 , ntheta_fourier = 20 , ax = None , show = True , close = False , axis_equal = True , ** kwargs ):
624624 kwargs .setdefault ('alpha' , 1 )
625625 import matplotlib .pyplot as plt
626626 from matplotlib import cm
@@ -657,6 +657,29 @@ def plot(self, r=0.1, ntheta=80, nphi=150, ntheta_fourier=20, ax=None, show=True
657657 if show :
658658 plt .show ()
659659
660+ def to_vtk (self , filename , r = 0.1 , ntheta = 40 , nphi = 120 , ntheta_fourier = 20 , extra_data = None , field = None ):
661+ try : import numpy as np
662+ except ImportError : raise ImportError ("The 'numpy' library is required. Please install it using 'pip install numpy'." )
663+ try : from pyevtk .hl import gridToVTK
664+ except ImportError : raise ImportError ("The 'pyevtk' library is required. Please install it using 'pip install pyevtk'." )
665+ x , y , z , _ = self .get_boundary (r = r , ntheta = ntheta , nphi = nphi , ntheta_fourier = ntheta_fourier )
666+ x = np .array (x .T .reshape ((1 , nphi , ntheta )).copy ())
667+ y = np .array (y .T .reshape ((1 , nphi , ntheta )).copy ())
668+ z = np .array (z .T .reshape ((1 , nphi , ntheta )).copy ())
669+ pointData = {}
670+ if field is not None :
671+ boundary = np .array ([x , y , z ]).transpose (1 , 2 , 3 , 0 )[0 ]
672+ B_BiotSavart = np .array (vmap (lambda surf : vmap (lambda x : field .AbsB (x ))(surf ))(boundary )).reshape ((1 , nphi , ntheta )).copy ()
673+ pointData ["B_BiotSavart" ] = B_BiotSavart
674+ theta1D = jnp .linspace (0 , 2 * jnp .pi , ntheta )
675+ phi1D = jnp .linspace (0 , 2 * jnp .pi , nphi )
676+ phi2D , theta2D = jnp .meshgrid (phi1D , theta1D )
677+ Bmag = np .array (self .B_mag (r , theta2D , phi2D )).T .reshape ((1 , nphi , ntheta )).copy ()
678+ pointData ["B_NearAxis" ]= Bmag
679+ if extra_data is not None :
680+ pointData = {** pointData , ** extra_data }
681+ gridToVTK (str (filename ), x , y , z , pointData = pointData )
682+
660683tree_util .register_pytree_node (near_axis ,
661684 near_axis ._tree_flatten ,
662685 near_axis ._tree_unflatten )
0 commit comments