Coverage for tcvx21/grillix_post/lineouts/omp_map_m.py: 87%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

23 statements  

1""" 

2Converts from rho to R^u radial distance to separatrix and back 

3""" 

4from scipy.interpolate import make_interp_spline 

5import xarray as xr 

6 

7from .lineouts_m import outboard_midplane_chord 

8from tcvx21.units_m import Quantity, Dimensionless 

9 

10 

11class OutboardMidplaneMap: 

12 

13 def __init__(self, grid, equi, norm): 

14 """ 

15 Builds an interpolator which uses the flux surface label to translate the flux surface label along an arbitrary line 

16 to the equivalent distance to the separatrix, if the line was at the outboard midplane. 

17 

18 This is useful for accounting for flux expansion when comparing fall-off lengths at different positions 

19 """ 

20 

21 lineout = outboard_midplane_chord(grid, equi) 

22 self.rho_points = equi.normalised_flux_surface_label(lineout.r_points, lineout.z_points, grid=False) 

23 self.arc_points = lineout.poloidal_arc_length(norm=norm) 

24 

25 omp_map = make_interp_spline(self.rho_points, self.arc_points) 

26 # Call again to make the separatrix have a value of '0.0' 

27 self.separatrix_arc = omp_map(1.0) 

28 omp_map = make_interp_spline(self.rho_points, self.arc_points - self.separatrix_arc) 

29 

30 self.equi = equi 

31 self.omp_map = omp_map 

32 

33 def __call__(self, r_points, z_points): 

34 """ 

35 Uses the flux surface label to map the points back to the outboard midplane, and then calculates the equivalent distance 

36 to the separatrix. 

37 

38 If the curve includes points in the private flux region, the rho < 1.0 (private flux region) or equivalently  

39 omp_mapped_distance < 0.0 is mapped to the core, which may have significantly different flux-surface expansion 

40 """ 

41 rho_points = self.equi.normalised_flux_surface_label(r_points, z_points, grid=False) 

42 return self.convert_rho_to_distance(rho_points=rho_points) 

43 

44 def convert_rho_to_distance(self, rho_points): 

45 """ 

46 Uses the flux surface label to map an array of normalised flux surface label to outboard-midplane-equivalent distance 

47 to the separatrix. 

48 """ 

49 return xr.DataArray(self.omp_map(rho_points)).assign_attrs( 

50 norm=self.arc_points.norm, 

51 name="OMP-mapped distance to sep." 

52 ) 

53 

54 def convert_distance_to_rho(self, arc_points: Quantity): 

55 """ 

56 Inverts the omp_map 

57 """ 

58 omp_inv = make_interp_spline(self.arc_points - self.separatrix_arc, self.rho_points) 

59 

60 arc_norm = (arc_points / self.arc_points.norm).to('') 

61 

62 return xr.DataArray(omp_inv(arc_norm)).assign_attrs( 

63 norm=Dimensionless, 

64 name="Normalised flux-surface label" 

65 )