Skip to content

Commit 4b3462b

Browse files
committed
Migrate the FortSym generators to the reworked API (#751)
The generators use FortSym's scoped context instead of an explicit arena, bind field_can_t members declaratively (one members(...) per quantity with the field_can_t Hessian packing) and select derivatives as sets: get_val, get_derivatives and get_derivatives2 are partials(4, 0..2), and the OpenACC Euler kernel takes the second partials touching r or p_phi. Each field-derivative kernel is now the guiding-centre statements plus one k%jet call and one emit. The CUDA spline inputs and the Boozer rates bind their names instead of substituting symbols, and the Horner leaves use FortGen derivative sets. Regenerated against FortSym b9ea95c, every generated source is byte-identical apart from the recorded FortSym revision.
1 parent b317d6a commit 4b3462b

11 files changed

Lines changed: 371 additions & 681 deletions

‎gen/generate_axis_maps.f90‎

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
program generate_axis_maps
22
! Native q is either normalized flux (R=sqrt(q)) or radius (R=q).
33
! No chart selection or boundary policy belongs in this algebraic kernel.
4-
use fortsym_arena, only: arena_t
54
use fortsym_expr, only: expr_t, sym, sin, cos, sqrt
65
use fortsym_expr, only: operator(+), operator(-), operator(*), &
76
operator(/), operator(**)
87
use fortsym_diff, only: diff
98
use fortsym_kernel, only: kernel_spec_t, emit_kernel, KERNEL_SUBROUTINE
10-
use fortsym_string, only: str, chars, str_t
9+
use fortsym_string, only: str, chars, str_t, words
1110
use fortsym_engine, only: engine_result_t
1211
use fortsym_engine_symengine, only: symengine_engine_t, make_symengine_engine
1312
implicit none
14-
type(arena_t), target :: arena
1513
type(symengine_engine_t) :: engine
1614
type(expr_t) :: q, theta, r2, x, y, qdot, thetadot
1715
type(expr_t) :: radius, inverse_q, radial_factor
@@ -22,15 +20,14 @@ program generate_axis_maps
2220

2321
output_dir = 'src/generated'
2422
if (command_argument_count() > 0) call get_command_argument(1, output_dir)
25-
call arena%init()
26-
engine = make_symengine_engine(arena)
27-
q = sym(arena, 'q')
28-
theta = sym(arena, 'theta')
29-
r2 = sym(arena, 'r2')
30-
x = sym(arena, 'x')
31-
y = sym(arena, 'y')
32-
qdot = sym(arena, 'dq')
33-
thetadot = sym(arena, 'dtheta')
23+
engine = make_symengine_engine()
24+
q = sym('q')
25+
theta = sym('theta')
26+
r2 = sym('r2')
27+
x = sym('x')
28+
y = sym('y')
29+
qdot = sym('dq')
30+
thetadot = sym('dtheta')
3431
r2 = x*x + y*y
3532
open (newunit=output_unit, file=trim(output_dir)//'/axis_map_generated.f90', &
3633
status='replace', action='write', iostat=ios)
@@ -50,19 +47,16 @@ program generate_axis_maps
5047
end if
5148
forward(1) = radius*cos(theta)
5249
forward(2) = radius*sin(theta)
53-
call emit('axis_'//mode//'_forward', forward, &
54-
[str('q'), str('theta')], [str('x'), str('y')])
50+
call emit('axis_'//mode//'_forward', forward, words('q theta'), words('x y'))
5551
inverse = [inverse_q]
56-
call emit('axis_'//mode//'_inverse', inverse, &
57-
[str('x'), str('y')], [str('q')])
52+
call emit('axis_'//mode//'_inverse', inverse, words('x y'), words('q'))
5853
! qdot=(dq/dr2)*2*(x*xdot+y*ydot). Angular velocity supplies
5954
! the orthogonal component. Derive radial factor from the inverse map.
6055
radial_factor = 1/(x*diff(inverse_q, x) + y*diff(inverse_q, y))
6156
pullback(1) = radial_factor*qdot*x - thetadot*y
6257
pullback(2) = radial_factor*qdot*y + thetadot*x
63-
call emit('axis_'//mode//'_velocity', pullback, &
64-
[str('x'), str('y'), str('dq'), str('dtheta')], &
65-
[str('dx'), str('dy')])
58+
call emit('axis_'//mode//'_velocity', pullback, words('x y dq dtheta'), &
59+
words('dx dy'))
6660
end do
6761
write (output_unit, '(a)') 'end module axis_map_generated'
6862
close (output_unit)

‎gen/generate_event_energy.f90‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
11
program generate_event_energy
2-
use fortsym_arena, only: arena_t
32
use fortsym_expr, only: expr_t, sym, operator(*), operator(**)
43
use fortsym_kernel, only: kernel_spec_t, emit_kernel, KERNEL_SUBROUTINE
5-
use fortsym_string, only: str, chars
4+
use fortsym_string, only: str, chars, words
65
implicit none
7-
type(arena_t), target :: arena
86
type(expr_t) :: energy, p, roots(1)
97
type(kernel_spec_t) :: spec
108
character(4096) :: output_dir
119
integer :: unit
1210

1311
output_dir = 'src/generated'
1412
if (command_argument_count() > 0) call get_command_argument(1, output_dir)
15-
call arena%init()
16-
energy = sym(arena, 'energy_eV')
17-
p = sym(arena, 'p')
13+
energy = sym('energy_eV')
14+
p = sym('p')
1815
roots = [energy*p**2]
1916
spec%name = str('event_energy')
2017
spec%mode = KERNEL_SUBROUTINE
2118
spec%generator = str('gen/generate_event_energy.f90')
22-
spec%args = [str('energy_eV'), str('p')]
19+
spec%args = words('energy_eV p')
2320
spec%outputs = [str('kinetic_energy_eV')]
2421
open (newunit=unit, file=trim(output_dir)//'/generated_event_energy.f90', &
25-
status='replace', action='write')
22+
status='replace', action='write')
2623
write (unit, '(a)') 'module generated_event_energy'
2724
write (unit, '(a)') 'implicit none'
2825
write (unit, '(a)') 'contains'

0 commit comments

Comments
 (0)