freegsnke.jtor_refinement module
- class freegsnke.jtor_refinement.Jtor_refiner(eq, nnx, nny)[source]
Bases:
object
Class to allow for the refinement of the toroidal plasma current Jtor. Currently applied to the Lao85 profile family when ‘refine_flag=True’. Only grid cells that are crossed by the separatrix are refined.
- __init__(eq, nnx, nny)[source]
Instantiates the object and prepares necessary quantities.
- Parameters:
eq (freegs4e Equilibrium object) – Specifies the domain properties
nnx (even integer) – refinement factor in the R direction
nny (even integer) – refinement factor in the Z direction
- build_LCFS_mask(core_mask)[source]
Builds a mask composed of all gridpoints connected to edges crossed by the LCFS. These trigger refinement.
- Parameters:
core_mask (np.array) – Plasma core mask on the standard domain (self.nx, self.ny)
- build_bilinear_psi_interp(psi, core_mask, unrefined_jtor, thresholds)[source]
Builds the mask of cells on which to operate refinement. Cells that are crossed by the separatrix and cells with large gradient on jtor are considered. Refines psi in the same cells.
- Parameters:
psi (np.array) – Psi on the standard domain (self.nx, self.ny)
core_mask (np.array) – Plasma core mask on the standard domain (self.nx, self.ny)
unrefined_jtor (np.array) – The jtor distribution
thresholds (tuple (threshold for jtor criterion, threshold for gradient criterion)) – tuple of values used to identify where to apply refinement, by default None
- build_from_refined_jtor(unrefined_jtor, refined_jtor)[source]
Averages the refined maps to the (nx, ny) domain grid.
- Parameters:
unrefined_jtor (np.array) – (nx, ny) jtor map from unresolved method
refined_jtor (np.array) – maps of the refined jtor, dimension = (no cells to refine, nnx, nny)
- Return type:
Refined jtor on the (nx, ny) domain grid
- build_jtor_gradient_mask(unrefined_jtor, threshold, quantiles=(0.5, 0.9))[source]
Selects the cells that need to be refined based on their value of the gradient of jtor. Selection is such that it includes cells where the norm of the gradient exceeds the value calculated based on the quantiles and threshold[1].
- Parameters:
unrefined_jtor (np.array) – The jtor distribution
thresholds (float) – the relevant value (in the tuple) used to identify where to apply refinement
- build_jtor_value_mask(unrefined_jtor, threshold, quantiles=(0.5, 0.9))[source]
Selects the cells that need to be refined based on their value of jtor. Selection is such that it includes cells where jtor exceeds the value calculated based on the quantiles and threshold[0].
- Parameters:
unrefined_jtor (np.array) – The jtor distribution
thresholds (float) – the relevant value (in the tuple) used to identify where to apply refinement
- build_mask_to_refine(unrefined_jtor, core_mask, thresholds)[source]
Selects the cells that need to be refined, using the user-defined thresholds
- Parameters:
unrefined_jtor (np.array) – The jtor distribution
core_mask (np.array) – Plasma core mask on the standard domain (self.nx, self.ny)
thresholds (tuple (threshold for jtor criterion, threshold for gradient criterion)) – tuple of values used to identify where to apply refinement, by default None
- get_indexes_for_refinement(mask_to_refine)[source]
Generates the indexes of psi values to be used for bilinear interpolation.
- Parameters:
mask_to_refine (np.array) – Mask of all domain cells to be refined
- Returns:
indexes of psi values to be used for bilinear interpolation 4 points per cell to refine, already set in 2-by-2 matrix for vectorised interpolation dimensions = (no of cells to refine, 2, 2)
- Return type:
np.array