The file format parsed by read_beam2 also includes the polarisation,
unlike those of read_beam0 and read_beam1.
When running gray standalone, however, we expect the mode to be set by
`antenna.iox` in gray.ini, not by the beam file.
- Avoid logging the same error over and over
- Make all the gray_errors actually warnings
- Replace `large_npl` error with `unstable_beam`, which is actually
the root cause of the former
- Use the gray_main error as exit code
- Replace the `get_free_unit` subroutine with the built-in
`newutin` option of the `open` statement.
- Replace `locatex` with just `locate` + an index offset.
- Replace `inside` with `contour%contains`.
- Merge `vmaxmin` and `vmaxmini` into a single subroutine
with optional arguments.
- Remove unused `range2rect`, `bubble`.
Similarly to eb648039 this change replaces the `equilibrium` module with
a new `gray_equil` module providing the same functionality without using
global variables.
- `read_eqdsk`, `read_equil_an` are replaced by a single `load_equil`
routine that handles all equilibrium kind (analytical, numerical,
and vacuum).
- `scale_equil` is merged into `load_equil`, which besides reading
the equilibrium from file peforms the rescaling and interpolation based
on the `gray_parameters` settings and the equilibrium kind.
To operate on G-EQDSK data specifically, the `change_cocors` and
`scale_eqdsk` are still available. The numeric equilibrium must then
be initialised manually by calling equil%init().
- `set_equil_spline`, `set_equil_an`, `unset_equil_spline`
are completely removed as the module no longer has any internal state.
- `fq` is replaced by `equil%safety`; `bfield` by `equil%b_field`;
`frhotor`, `frhopol` by `equil%pol2tor` and `equil%pol2tor`;
and the remaining subroutines by other methods of `abstract_equil`
retaining the old name.
- the `contours_psi` subroutine is replaced by `equil%flux_contour`,
with a slightly changed invocation but same functionality.
- the `gray_data` type is no longer required ans has been removed: all
the core subroutines now access the input data only though either
`abstract_equil`, `abstract_plasma` or the `limiter` contour.
This change adds a bit of documentation and simplifies the two
(internal) subroutines used to find the horizontal tangent points
and the magnetic O/X point.
Using a closure we can avoid explicitly passing parameters (psi0) to
hybrj1. Previously this required a custom `hybrj1mv` subroutine in
fitpack with an identical interface, except for our extra parameter.
This change replaces the `coreprofiles` module with a new `gray_plasma`
module providing the same functionality without using global variables.
- `read_profiles`, `read_profiles_an` are replaced by a single `load_plasma`
routines that handles both profiles kind (numerical, analytical).
- `scale_profiles` is merged into `load_plasma`, which besides reading
the profiles from file peforms the rescaling and interpolation based
on the `gray_parameters` settings.
- `set_profiles_spline`, `set_profiles_an`, `unset_profiles_spline`
are completely removed as the module no longer has any internal state.
- `density`, `ftemp`, `fzeff` are replaced by the `abstract_plasma`
type which provides the `dens`, `temp` and `zeff` methods for
either `numeric_plasma` or `analytic_plasma` subtypes.
1. Use the `contour` type for limiter and plasma boundary
(rlim, zlim, rbnd, zbnd)
2. Replace `inside` with `contour%contains`
3. Replace `range2rect` with a `contour` interface
4. Remove the limiter module which just re-exports the limiter
as a global; instead just pass the contour object around
This change replaces the output files (Fortran units) with a derived
type called table, that hold the data in memory until further
processing. The data stored in a table can be dumped to a file, as
before, or processed in other ways, for example converted to other
derived type.
This change replaces pointers with automatic arrays to greatly simplify
the memory management in the main subroutine:
- All arrays are defined in a single location and with their final
dimension explicitely shown.
- The allocation/deallocation is performed automatically when
entering/leaving the gray_main routine.
- Remove the Stokes parameters as an intermediate step in the
conversion between Jones vectors and polarisation ellipses.
- Document every single step performed when converting between
different parametrisations and how the polarisation at the
plasma boundary is computed. This includes how everything
was derived from first principles.
- Mark the subroutines as pure.
- Remove `set_pol` entirely.
In situations when multiple beams are traced, either when allowing
multiple plasma crossings (raytracing.ipass > 0) or the initial polarisation
is mixed (raytracing.ipol == .true.), the couplings of all but the first
beam (with least index_rt) were invalid.
The bug is due to the re-use of the psipol,chipol variables as the beams
are traced sequentially over the beam_loop. For the first beam being
traced the psipol,chipol are correctly initialised to the user-defined
value and the resulting coupling is correct.
However, in each subsequent beam the values were not set to those of the
parent beam (or to the user-defined value in the case of the first X
mode beam), but to those of the previous beams (current index_rt - 1).
This change repurposes the psipv,chipv arrays to store the polarisation
of the parent beams, including the initial user-defined value and makes
plasma_in always use these to compute the coupling.
In addition, in the case the polarisation is not immediately known (i.e.
if raytracing.ipol == .false.), this change postpones the computation of
the Jones vector (ext, eyt) from the launch point, if the magnetic
equilibrium is available, to when the ray actually crosses the
plasma boundary.
The original code, besides being strictly incorrect, can lead to
non-negligible alterations to the coupling. This change also mean:
1. most of the functionality of `set_pol` has been merged with
`plasma_in`
2. the polarisation is undefined and the Jones vector is set to the
placeholder value [1, 0] till `plasma_im` is called
Finally, `polarcold` is removed because it's unused.
While technically accepted by GRAY, these indices do not carry a special
meaning, as wrongly implied by the documentation: they are equivalent
to 8, 18 and specifically don't change the meaning of sgnbi,sgni.
Since 24edfdc4 print_prof tabulates the input profiles up to ψ_bnd,
however the torr_curr_psi may fail (producing FPEs) outside ψ=1.
Moreover, torr_curr_psi gives the current on the LFS on the specific
line z=z_maxis, while the flux surface average is usually more
interesting, say when comparing J_φ with Jcd.
This change fixes both issues.
If frhopol is called with a very small ρ_p, less than then step size of
ε_machine^⅓, the two sided finite step differentiation evaluates frhotor
at ρ_p < 0, producing a floating point exception.
In this case we use the single- sided definition.
This adds a proper procedure to rescale and shift a 2D B-spline by
manipulating the coefficients.
Note: the previous code in set_equil_spline did work, but by
transforming the whole partial(i,j) triggered warnings about operations
on uninitialised memory.
When a call to regrid results in ier=-1 (data needs to be refitted with
interpolating spline) the computation of the sum of the residuals can
overflow. In this case we can exit immediately (avoiding raising a FPE)
ignoring the results. The latter need to be recomputed anyway.
The minimisation algorithm may try to evaluate a function outside of its
domain triggering a floating point exception. However, this is not a
concern because it won't affect the final result, so they can be ignored
1. Introduces enumerations (and some booleans) intended to replace all
the magic numbers used throughout the code to represent multiple
choices.
2. Replace the gray_params.sh script a new one that automatically
generates code for all the GRAY parameters by parsing
gray_params.f90.
3. Also generate extra code to accept the enum identifiers as valid
values in the configuration files and command line arguments.
4. Set sensible default values for parameters that are rarely changes.
This change limits the evaluation of the poloidal flux spline ψ(R,z) to
a particular domain where ψ(R,z) is strictly monotonic. This choice
ensures that ψ_n < 1 only inside the plasma boundary; so plasma
parameters like q(ψ), Te(ψ), etc. can be mapped to the physical space
without ambiguities.
Before this change, anywhere ψ_n happened to decrease below 1 (either as
a result of a physical current or simply from the spline extrapolation),
Gray would effectively create a spurious plasma region.
This behavior is seriously problematic because it completely invalidates
the simulation: it can alter the ray directions, the power disribution
and total power if the beam enters one such region.
The domain is computed by applying a transformation to the contour of
the plasma boundary: for each contour point we cast a ray from the
magnetic axis to that point and extend the ray until the restriction of
ψ(R,z) on the ray starts decreasing or reach a maximum scaling factor.
The endpoint of the ray is then taken as the new point.
If ψ(R,z) is globally monotonic, the transformation is a homotety wrt
the magnetic axis, so the domain will be an enlarged boundary; otherwise
the shape will be more irregular (an intersection of the enlarged
boundary and several level curves of ψ).
Finally, each `pol_flux(r, z)` call is now guarded behind a check
`inside(psi_domain, r, z)`. For points outside the domain the subroutine
returns, as usual, -1 for ψ and 0 for derivatives.
Previously the ray initial positions were set to the wavefront
S_R(x,y,z) = 0, with (x,y) chosen such that S_I(x,y,0) = const.
The wavefront itself, however, was determined using the value of the
beam parameters (k_ξ, k_η, w_ξ, w_η, etc.) fixed at z=0, which is valid
only when the initial wavefront is approximately flat.
Moreover, since the ray are distributed according to S_I(z=0), this
choice creates an inconsistency between the phase (from S_R at z≠0) and
the power (from S_I at z=0) assigned to the rays.
Satisfying both conditions on S_R and S_I exactly is really hard;
however, given we do not really care about the phase and we want to
precisely track the power, so it's more sensible to simply set z=0.
This means that when integrating in the phase (idst=2), gray will no
longer construct wavefronts, but merely transport the initial phase
on the z=0 plane.
Note that k₀⋅s will still give the correct phase. so if necessary, a
wavefront could be reconstructed by interpolating the (s, x̅, y̅, z̅)
points.
To improve the analytical model correctness this changes the formula
of the toroidal flux to lift the large aspect ratio approximation (a << R₀).
In fact, Φ(r) = B₀πr² is technically inconsistent with the field varying
as B₀R₀/R. The exact expression is:
Φ(r) = B₀πr² 2/[1 + √(1 - r²/R₀²)],
which is approximately equal to the former for r << R₀.
Note that this change introduces a divergence in the poloidal field at
r=R₀ (since ∂Φ/∂r → +∞), so the domain of the equilibrium has been
restricted to r<R₀, as expected.
This should not be a concern because the field outside the plasma
boundary is never directly, particularly not by the integrator.