Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/examples/regression_solovev_ideal_example/equil.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

grid_type="ldp" ! Radial grid packing of equilibrium quantities. Accepts rho, ldp, pow1, pow2, or original. ldp packs points near the core and edge. pow* packs near the edge.
psilow=1e-4 ! Minimum value of psi, normalized from 0 to 1
psihigh=0.99999 ! Maximum value of psi, normalized from 0 to 1
! Kinetic data end here; extrapolating T to the LCFS gives invalid logLambda.
psihigh=0.997995992 ! Last supplied kinetic.txt surface (positive logLambda)
mpsi=16 ! Number of radial grid intervals for equilibrium quantities
mtheta=256 ! Number of equally spaced poloidal grid intervals for all splines
newq0=0 ! Grad-Shafranov solution invariant adjustment of the q profile to give the specified value of q at the axis. Default 0 uses input file value.
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/regression_solovev_kinetic_example/equil.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

grid_type="ldp" ! Radial grid packing of equilibrium quantities. Accepts rho, ldp, pow1, pow2, or original. ldp packs points near the core and edge. pow* packs near the edge.
psilow=1e-1 ! Minimum value of psi, normalized from 0 to 1
psihigh=0.99999 ! Maximum value of psi, normalized from 0 to 1
! Kinetic data end here; extrapolating T to the LCFS gives invalid logLambda.
psihigh=0.997995992 ! Last supplied kinetic.txt surface (positive logLambda)
mpsi=16 ! Number of radial grid intervals for equilibrium quantities
mtheta=256 ! Number of equally spaced poloidal grid intervals for all splines
newq0=0 ! Grad-Shafranov solution invariant adjustment of the q profile to give the specified value of q at the axis. Default 0 uses input file value.
Expand Down
4 changes: 3 additions & 1 deletion docs/namelists.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ This namelist sets the inputs, controls the behavior, and determines the outputs
The PENTRC Namelist
====================

This namelist sets the inputs, controls the behavior, and determines the outputs of the GPEC code.
This namelist sets the inputs, controls the behavior, and determines the outputs of PENTRC.

.. include:: ../input/pentrc.in
:literal:

.. include:: pentrc_supplied_rates.rst

66 changes: 66 additions & 0 deletions docs/pentrc_supplied_rates.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
PENTRC supplied collision rates
==============================

``kinetic_format = "rates-v1"`` in ``PENT_INPUT`` selects a nine-column
``kinetic_file``. The default ``"legacy"`` retains the six-column format and
its existing main-ion/impurity collision approximation. The columns are::

psi_n n_i n_e T_i T_e OmegaE logLambda nu_i nu_e

Densities are in m^-3, temperatures in eV, physical electric rotation
``OmegaE`` in rad/s, the Coulomb logarithm dimensionless, and the supplied
base Krook damping rates in s^-1. No 2*pi conversion is applied. All densities,
temperatures, logarithms and rates must be positive and finite. A selected-ion
charge density greater than the total electron density is rejected. Exact
zero rotation is retained in this format. The coordinate orientation is
unchanged: provide ``OmegaE`` in native axes with ``wefac=1``, or declare the
adapter's common-to-native axis conversion through ``wefac``. Supplied-rate
mode requires ``wpfac=1``.

The supplied rates bypass the legacy impurity-rate formula at both native
query interfaces. Native splines interpolate their logarithms on the input
radial grid, and the generated exponential kernel restores their values and
derivatives. This preserves positivity between positive input samples;
overflow, underflow and nonfinite results are rejected. Primitive drive
profiles retain the existing interpolation. As in legacy mode, ``nfac`` and
``tfac`` alter drive profiles only, leaving supplied collision rates unchanged.

One native call calculates one population. A common D/T/e mixture therefore
uses an adapter that emits three calls. For D and T, column ``n_i,T_i`` holds
that isotope's density and temperature, and ``mi`` is respectively 2 or 3
in proton-mass units. Set ``zi=zimp=1``; ``mimp`` may identify the other isotope.
For electrons set ``electron=.true.`` and use the same total ``n_e,T_e``.
All three calls carry the same physical ``OmegaE`` and common ``logLambda``.
Supply each population's rate from the declared full background mixture,
including its densities, temperatures, charges and masses. Keep that mixture
and rate convention in the adapter's provenance record: this profile contains
the selected drive and scalar rates, not the full background distribution.
This is a diagonal scalar response, not a coupled Fokker--Planck solve.

The existing pitch and energy models are unchanged. Passing particles use
the supplied base rate; trapped particles use the base rate divided by
``2*epsilon``. ``nutype="krook"`` then uses this rate without energy
dependence. ``nutype="harmonic"`` additionally multiplies it by
``(1+ell_eff**2/4)*x**(-3/2)``, with ``x=E/T``, integer ``ell_eff=ell`` for
trapped particles and ``ell_eff=ell+n*q`` for passing particles. ``nufac``
multiplies the resulting width. Do not include these geometry, harmonic,
energy or ``nufac`` factors in the supplied base columns. An energy-only
``x**(-3/2)`` operator and a geometry-uniform constant operator are not
provided by this interface. ``nutype="zero"`` selects the collisionless model;
``"small"`` retains its numerical width proportional to ``abs(OmegaE)``.

``pentrc_kinetics.out`` records the format when ``indebug=.true.``. The native
NetCDF output records ``kinetic_format``, the consumed ``collision_model`` and
``collision_multiplier``, along with the existing selected mass, charge,
densities, temperatures, logarithm, base rates and trapped ``nu_eff`` profile.

Run the focused native reader/query regressions with::

cd install
make check-pentrc-collisions

The supplied-rate oracle checks unequal D/T drive profiles, both ion and
electron rates and their derivatives, physical zero rotation, and invalid
input rejection in both Debug and ``-O3 -ffast-math`` builds. The generated
rate reconstruction is reproducible from ``gen/gen_supplied_rates.f90`` using
FortSym; the checked-in ``pentrc/supplied_rates.inc`` is used by native builds.
15 changes: 15 additions & 0 deletions gen/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Regenerate the supplied-rate exponential and its symbolic derivative with
FortSym. `FORTSYM_PREFIX` points to a verified FortSym build or installation
containing `include/` and `lib/`; supply its exact source revision below.

```sh
gfortran -I"$FORTSYM_PREFIX/include" gen/gen_supplied_rates.f90 \
-L"$FORTSYM_PREFIX/lib" -lfortsym -Wl,-rpath,"$FORTSYM_PREFIX/lib" \
-o gen_supplied_rates
./gen_supplied_rates pentrc/supplied_rates.inc FORTSYM_REVISION
```

The generated include is checked in, so normal native builds do not require
FortSym. The reader uses native spline interpolation; this generator owns only
the pointwise exponential reconstruction and its derivative. Independent
profile and invalid-input oracles run through `make check-pentrc-collisions`.
42 changes: 42 additions & 0 deletions gen/gen_supplied_rates.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
program gen_supplied_rates
use fortsym_arena, only: arena_t
use fortsym_expr, only: expr_t, sym, exp, operator(*)
use fortsym_diff, only: diff
use fortsym_kernel_emit, only: kernel_emit_spec_t, emit_fortran_kernel_ir
use fortsym_kernel_ir, only: kernel_ir_t, lower_kernel_ir
use fortsym_string, only: chars, str, str_t
implicit none
type(arena_t), target :: arena
type(expr_t) :: logarithm, logarithm_derivative, roots(2)
type(kernel_ir_t) :: ir
type(kernel_emit_spec_t) :: spec
type(str_t) :: source
character(2048) :: output, revision
character(:), allocatable :: message
integer :: unit
logical :: ok

call get_command_argument(1,output)
call get_command_argument(2,revision)
if(len_trim(output)==0.or.len_trim(revision)==0) &
error stop 'usage: gen_supplied_rates OUTPUT FORTSYM_REVISION'
call arena%init()
logarithm=sym(arena,'logarithm')
logarithm_derivative=sym(arena,'logarithm_derivative')
roots(1)=exp(logarithm)
roots(2)=diff(roots(1),logarithm)*logarithm_derivative
call lower_kernel_ir(roots,ir,ok,message)
if(.not.ok) error stop message
spec%name=str('supplied_rate_leaf')
spec%args=[str('logarithm'),str('logarithm_derivative')]
spec%outputs=[str('rate'),str('rate_derivative')]
spec%generator=str('gen/gen_supplied_rates.f90')
spec%generator_revision=str(trim(revision))
spec%regenerate_command=str( &
'gen_supplied_rates pentrc/supplied_rates.inc FORTSYM_REVISION')
source=emit_fortran_kernel_ir(ir,spec,ok,message)
if(.not.ok) error stop message
open(newunit=unit,file=trim(output),status='replace')
write(unit,'(a)',advance='no') chars(source)
close(unit)
end program gen_supplied_rates
1 change: 1 addition & 0 deletions input/pentrc.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
&PENT_INPUT
idconfile = "euler.bin" ! Eigenfunctions output by DCON run
kinetic_file = "kinetic.txt" ! Ascii profiles. columns: psi_n, ni(m^-3), ne(m^-3), ti(eV), te(eV), omega_EXB(rad/s)
kinetic_format = "legacy" ! "rates-v1" appends logLambda,nu_i(s^-1),nu_e(s^-1); positive supplied base rates
data_dir = "" ! Location of pre-formed fnml matrix used in rlar and clar methods. "default" uses $GPECHOME/pentrc.
peq_file = "" ! Ascii displacement. columns: psi_n, m, real(xi^psi), imag(xi^psi), real(xi^alpha), imag(xi^alpha). Default uses "gpec_xclebsch_n#.out"

Expand Down
2 changes: 1 addition & 1 deletion install/DEPENDENCIES.inc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
../pentrc/dcon_interface.o: ../equil/bicube.o ../equil/cspline.o ../equil/fspline.o ../equil/spline.o ../pentrc/params.o ../pentrc/utilities.o
../pentrc/diagnostics.o: ../equil/cspline.o ../equil/spline.o ../pentrc/energy.o ../pentrc/params.o ../pentrc/pitch.o ../pentrc/special.o
../pentrc/energy.o: ../pentrc/dcon_interface.o ../pentrc/lsode2.o ../pentrc/params.o ../pentrc/utilities.o
../pentrc/inputs.o: ../equil/bicube.o ../equil/cspline.o ../equil/fspline.o ../equil/spline.o ../pentrc/dcon_interface.o ../pentrc/params.o ../pentrc/utilities.o
../pentrc/inputs.o: ../equil/bicube.o ../equil/cspline.o ../equil/fspline.o ../equil/spline.o ../pentrc/dcon_interface.o ../pentrc/params.o ../pentrc/supplied_rates.inc ../pentrc/utilities.o
../pentrc/lsode1.o: ../equil/local.o
../pentrc/lsode2.o: ../equil/local.o
../pentrc/params.o: ../equil/local.o ../pentrc/version.inc
Expand Down
13 changes: 13 additions & 0 deletions install/TARGETS.inc
Original file line number Diff line number Diff line change
Expand Up @@ -431,3 +431,16 @@ mkbin: pentrc dcon rdcon stride match rmatch slayer multi sum gpec
cp ../sum/sum $(BINDIR)
cp ../gpec/gpec $(BINDIR)
$(call print_success,All binaries copied to $(BINDIR))

# Native PENTRC profile-reader/query regression; no equilibrium or solver job.
../pentrc/inputs.o: ../pentrc/supplied_rates.inc

ifeq ($(PLATFORM),Darwin)
GPEC_TEST_LDFLAGS ?= -Wl,-dead_strip
else
GPEC_TEST_LDFLAGS ?= -Wl,--gc-sections
endif
.PHONY: check-pentrc-collisions
check-pentrc-collisions:
GPEC_TEST_LDFLAGS="$(GPEC_TEST_LDFLAGS)" python3 ../regression/test/pentrc_collision_profile.py -v
GPEC_TEST_LDFLAGS="$(GPEC_TEST_LDFLAGS)" python3 ../regression/test/pentrc_supplied_rates.py -v
Loading
Loading