Commit Graph

331 Commits

Author SHA1 Message Date
Michele Guerini Rocco
3f75cbd357
default.nix: pass system argument to nixpkgs 2024-12-12 03:13:17 +01:00
Michele Guerini Rocco
c0b313a0f0
package the python scripts 2024-12-12 02:28:27 +01:00
Michele Guerini Rocco
bc28d14ebe
add infrastructure for making releases
Idea: a release will be a git tag, distributed as an autogenerated
archive (eg. by GitLab release feature).
This version string must therefore be stored in a revisioned file, so we
use `.version` for this purpose. Before tagging a new release this file
will have to be updated with the new version number.

When building gray the revision (shown in the output headers and usage
screen) will be set to either

- the latest commit hash when building from a git checkout,

- from the .version file when building from release archive.

The implementation is based on whether the .git directory is present.
2024-12-04 16:39:25 +01:00
Michele Guerini Rocco
fda4ff8a3b
README.md: finally add a README 2024-12-04 16:39:25 +01:00
Michele Guerini Rocco
27e3ffc7b7
default.nix: avoid more warnings in sandboxed builds 2024-12-03 16:54:18 +01:00
Michele Guerini Rocco
a8a35bc783
src/pec.f90: remove leftover file 2024-12-03 16:33:54 +01:00
Michele Guerini Rocco
1a8011f2b7
src/gray_equil.f90: export COCOS subroutines 2024-12-03 16:09:30 +01:00
Michele Guerini Rocco
beccd00b30
src/gray_core.f90: fix power at step 0
The fraction of power in ray jk at the step zero is P₀(jk), not
necessarily 1 with more than one ray.
2024-12-03 16:04:49 +01:00
4a5c858ae7 src/gray_errors.f90: use macros for error message padding 2024-11-20 11:12:06 +00:00
6693fdf9b9 src/gray_errors.f90: avoid reshape in parameter initialization
The unused elements of the array are now initialized explicitly
with empty strings to add compatibility with ifort 2020, that
otherwise fails with internal error.
2024-11-20 10:12:41 +00:00
Michele Guerini Rocco
0ab0fcbf60
document the wave polarisation convention 2024-11-09 21:19:45 +01:00
Michele Guerini Rocco
16ec1a1d06
default.nix: silence missing fontconfig cache warnings 2024-11-09 21:16:05 +01:00
Michele Guerini Rocco
68358ac506
Makefile: propagate up the docs prerequisites 2024-11-09 18:36:24 +01:00
Michele Guerini Rocco
fd175ad0da
src/gray_equil.f90: make Gaussian beam notation consistent
To keep the notation used in compute_initial_conds consistent with the
source linked (Q = K - iW for the complex curvature tensor), we need to
adds a minus sign in a few places where ∇S_I is computed.
2024-11-08 15:39:19 +01:00
Michele Guerini Rocco
2368a0ba33
src/gray_tables.f90: avoid floating point exception
Due to Fortran non-shortcircuiting expressions, if info /= 0 and
psi_n = NaN or is undefined, it will still raise an exception.
2024-11-04 12:05:54 +01:00
Michele Guerini Rocco
72eb224568
remove unnecessary deallocations
1. Local variables are automatically deallocated when they go out of
   scope.

2. When calling exit() during CLI processing some stuff wasn't being
   deallocated, but it doesnt matter because the OS does it anyway.
   So, get rid of it entirely.
2024-11-04 12:05:50 +01:00
Michele Guerini Rocco
fde048d3ee
src/gray_core.f90: fix polarisation shown in summary table
This changes the ψ, χ polarisation ellipse angles shown in the summary
table to be those of the current plasma wave mode, not the polarisation
of the beam upon re-entering the plasma boundary after reflecting.

Note that the former has always been the intended value, but was likely
changed inadvertently when reflections have been implemented.
2024-11-04 12:05:49 +01:00
Michele Guerini Rocco
2e8cbb78ef
src/gray_core.f90: fix use of uninitialised variable
When the beam reflects before entering the boundary the Jones vector
(ext, eyt) is still uninitialised, set it at the beginning to avoid
raising an exception in debug mode.
2024-11-04 12:05:48 +01:00
Michele Guerini Rocco
42fcac0726
src/gray_tables.f90: fix floating point exception
Skip ψ=0 when computing the flux surfaces contours.
2024-11-04 12:05:46 +01:00
Michele Guerini Rocco
e9e3a4d697
src/gray_equil.f90: fix compilation on intel compilers 2024-11-04 12:05:45 +01:00
Michele Guerini Rocco
9d09c99314
src/eccd.f90: remove caching functionality from eccdeff
The caching is cool, but it's implemented using static variables and
therefore not thread-safe. Since the savings are pretty modest (about
20% of the total eccdeff calls, itself 3% of the total execution) let's
just drop it.
2024-11-04 12:05:44 +01:00
Michele Guerini Rocco
ae6ac735e8
tests: update references after pec rewrite 2024-11-04 12:05:42 +01:00
Michele Guerini Rocco
6f66317541
replace pec module with an object
This was the final module with global variables to be rewritten.
The functionaly of pec: `pec_init`, `spec`, `postproc_profiles` has been
replaced by the `ray_projector` object in `gray_project.f90` with the
following methods: `projector%init`, `projector%project` and
`projector%statistics`.

The new code is functionally identically with only breaking change being
in Δρ_J, the full-width at max/e of the current density.
Before this change Δρ_J could be negative to signal the J_φ profile had
at least one positive and one negative peak, after the value is always
positive. Note: in either case Δρ_J was given by the largest peak only.
2024-11-04 12:05:26 +01:00
12f15239df
tests: check flux averages 2024-11-04 12:00:21 +01:00
Michele Guerini Rocco
bd6e1521b0
tests: check EC profiles 2024-11-04 12:00:20 +01:00
Michele Guerini Rocco
a4a39571ce
src/pec.f90: don't rely on P_inside, I_cd_inside
When combining multiple independent simulations with `gray -s`, the
statistics in sum-summary.txt are computed by summing the profiles
pointwise and calling `postproc_profiles` with their (supposedly common)
MHD equilibrium.

The subroutine assumes the normalisations of dP/dV⋅dV and J_φ⋅dA are
P_inside(ρ=1), I_cd_inside(ρ=1), however if the individual profiles have
been computed with different versions of Gray, built with different
compilers, or on different machines, the values may be very slightly off.
Further, due to the use of the relation Δρ² = ⟨ρ²⟩ - ⟨ρ⟩², the profile
widths are very sensible to the normalisation, producing wildly
incorrect values.

For example, due to the refactor of `magsurf_data`, a change of about
0.05% in dV resulted in Δρ² being off by 300%.
2024-11-04 12:00:20 +01:00
Michele Guerini Rocco
7477fffb43
move flux averages inside gray_equil 2024-11-04 12:00:20 +01:00
Michele Guerini Rocco
8c144c3892
make the sign of q consistent with cocos=3 2024-11-04 12:00:20 +01:00
Michele Guerini Rocco
fdf5ef72fe
src/magsurf_data.f90: cleanup 2024-11-04 12:00:20 +01:00
Michele Guerini Rocco
2e2ab16273
tests/01-ITER: fix G-EQDSK format 2024-11-04 12:00:19 +01:00
Michele Guerini Rocco
45017c417e
scripts/gray_visual.py: fix default of -k 2024-11-04 12:00:19 +01:00
Michele Guerini Rocco
10d65c1b8e
tests: remove workaround for empty files
Inactive tables no longer produce an empty file, even if requested
2024-11-04 12:00:19 +01:00
Michele Guerini Rocco
e5e471725c
tests: avoid scipy dependency
The χ² in test_error_biased can be easily minimised analytically
2024-11-04 12:00:19 +01:00
Michele Guerini Rocco
5c78af975a
add support for intel compilers 2024-11-04 12:00:19 +01:00
Michele Guerini Rocco
ee4183faa7
tests: update references with new tables format 2024-11-04 12:00:18 +01:00
Michele Guerini Rocco
3e853dd60f
tests/02-ITER-half-field: update reference
This was supposed to test an X mode polarisation, but due to the
issue in `read_beam2`, it was actually O mode.
2024-11-04 12:00:17 +01:00
Michele Guerini Rocco
03443f1195
src/beams.f90: add option to not change iox in read_beam2
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.
2024-11-04 12:00:17 +01:00
Michele Guerini Rocco
cdac0ca361
fixup 15fc891 2024-11-04 12:00:17 +01:00
Michele Guerini Rocco
864cf23b78
scripts/gray_visual.py: rewrite and extend scope 2024-11-04 12:00:17 +01:00
Michele Guerini Rocco
24e0e6e472
src: remove unnecessary one, zero uses 2024-11-04 12:00:16 +01:00
Michele Guerini Rocco
80782a58fc
Makefile: add flag for loop parallelisation 2024-11-04 12:00:16 +01:00
Michele Guerini Rocco
d52e125d9c
src/gray_core: improve error reporting
- 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
2024-11-04 12:00:16 +01:00
Michele Guerini Rocco
86d5b5a672
src/gray_core: refactor ic_gb 2024-11-03 09:19:22 +01:00
Michele Guerini Rocco
d5bbda1ea2
src/gray_tables: fix memory error with disabled table 2024-11-03 09:19:22 +01:00
Michele Guerini Rocco
10f783ca37
src/gray_errors.f90: avoid strange macro
Some compilers are not happy with this.
2024-11-03 09:19:22 +01:00
Michele Guerini Rocco
918d239b34
src/logger.f90: allow changing output unit and colors 2024-11-03 09:19:22 +01:00
Michele Guerini Rocco
52693be83e
tests/11-vacuum: use exp notation on colorbar 2024-11-03 09:19:21 +01:00
Michele Guerini Rocco
d5c81268de
src/utils.f90: clean up
- 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`.
2024-11-03 09:19:21 +01:00
Michele Guerini Rocco
751cca3bfc
mark some procedures as pure 2024-11-03 09:19:18 +01:00
Michele Guerini Rocco
166086d369
replace equilibrium module with an object
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.
2024-11-03 09:18:33 +01:00