Physics-Stellarator-0.02/0000755000175000017500000000000015241167064014371 5ustar jovanjovanPhysics-Stellarator-0.02/Changes0000755000175000017500000000344515223004055015663 0ustar jovanjovanRevision history for Physics-Stellarator 0.02 2026-07-06 - Physics::CPD::Stellarator: theoretical fusion-power production for a 50:50 D-T plasma - Bosch-Hale reactivity (dt_reactivity), fusion power density and total fusion power (fusion_power / fusion_power_MW), the neutron/alpha split (neutron_power_MW / alpha_power_MW), neutron wall loading (neutron_wall_load), fusion gain Q (fusion_gain_Q) and a power_report; new dt_fuel_fraction attribute. - examples/power_production.pl: theoretical D-T fusion power of the W7-X-class design with ion-temperature and density scans. - README: added a full API reference for both modules and a fusion-power section; expanded method/attribute documentation in the POD. - Tests: t/05-fusion.t validates the reactivity and power relationships. 0.01 2026-07-06 - Initial release. - Physics::CPD: pure-Perl computational-plasma-dynamics engine (plasma/cyclotron frequencies, Debye length, gyroradii, thermal and Alfven speeds, ion sound speed, pressures, beta, Coulomb logarithm, collision frequency, mean free path, Spitzer resistivity, plasma parameter; multi-species support). - Physics::CPD::Stellarator: Wendelstein 7-X model extending Physics::CPD (aspect ratio, plasma volume/surface, rotational transform, ISS04 confinement scaling, stored energy, Sudo density limit, beta/density fractions, Lawson triple product, ECRH resonance field, radial profiles). - VMEC-style Fourier boundary geometry: flux surfaces, helical magnetic axis, nested surfaces and modular coils. - Plotting via PDL::Graphics::Gnuplot: 3-D design diagram, poloidal cross sections, radial profiles and confinement scans. Physics-Stellarator-0.02/examples/0000755000175000017500000000000015241167064016207 5ustar jovanjovanPhysics-Stellarator-0.02/examples/plasma_parameters.pl0000755000175000017500000000154715222763410022252 0ustar jovanjovan#!/usr/bin/env perl use strict; use warnings; use lib 'lib'; use Physics::CPD; # Base computational-plasma-dynamics engine, standalone. # A hot hydrogen plasma at fusion-relevant conditions. my $plasma = Physics::CPD->new( electron_density => 1e20, # m^-3 electron_temperature => 5000, # eV (5 keV) ion_temperature => 3000, # eV (3 keV) magnetic_field => 3.0, # T ion_species => 'D', # deuterium ); print $plasma->report; print "\nA few individual quantities:\n"; printf " ion sound speed c_s = %.3e m/s\n", $plasma->ion_sound_speed; printf " electron mean free path lambda = %.3e m\n", $plasma->mean_free_path; printf " collision frequency nu_ei = %.3e Hz\n", $plasma->collision_frequency; printf " Spitzer resistivity eta = %.3e Ohm.m\n", $plasma->spitzer_resistivity; Physics-Stellarator-0.02/examples/plot_3d_design.pl0000755000175000017500000000273715222765403021455 0ustar jovanjovan#!/usr/bin/env perl use strict; use warnings; use lib 'lib'; use Physics::CPD::Stellarator; # Produce the full set of Wendelstein 7-X visualisations as PNG files. # Requires PDL, PDL::Graphics::Gnuplot and a gnuplot binary. my $outdir = shift @ARGV || '.'; my $w7x = Physics::CPD::Stellarator->new( electron_density => 8e19, electron_temperature => 4000, ion_temperature => 2500, magnetic_field => 2.5, heating_power => 10, ); print "Writing plots to $outdir/ ...\n"; # 3-D engineering diagram: last-closed flux surface + helical magnetic axis # + modular field coils. my $f1 = $w7x->plot_3d( output => "$outdir/w7x_3d.png", title => 'Wendelstein 7-X: plasma boundary, magnetic axis and modular coils', view => [ 62, 25 ], ); print " 3D design diagram -> $f1\n"; # Poloidal flux-surface cross sections through one field period. my $f2 = $w7x->plot_cross_sections( output => "$outdir/w7x_cross_sections.png", n_angles => 5, n_surfaces => 6, ); print " flux-surface sections -> $f2\n"; # Radial density / temperature profiles. my $f3 = $w7x->plot_profiles( output => "$outdir/w7x_profiles.png" ); print " radial profiles -> $f3\n"; # ISS04 energy-confinement time vs heating power. my $f4 = $w7x->plot_confinement_scan( output => "$outdir/w7x_confinement.png", parameter => 'heating_power', from => 1, to => 20, ); print " confinement scaling -> $f4\n"; print "Done.\n"; Physics-Stellarator-0.02/examples/power_production.pl0000755000175000017500000000474215223003630022144 0ustar jovanjovan#!/usr/bin/env perl use strict; use warnings; use lib 'lib'; use Physics::CPD::Stellarator; # Theoretical fusion power production for a Wendelstein 7-X-class design. # # W7-X is a hydrogen/deuterium research device and does not itself produce # significant fusion power. Here we ask a "what if" question: how much power # would a stellarator of this geometry deliver if it were operated as a # deuterium-tritium reactor? The estimate is 0-D (uniform n_e and T_i over the # plasma volume) using the Bosch-Hale D-T reactivity built into the module. my $reactor = Physics::CPD::Stellarator->new( config_name => 'W7-X-class D-T reactor point', electron_density => 2.0e20, # m^-3 electron_temperature => 15000, # eV (15 keV) ion_temperature => 15000, # eV (15 keV) magnetic_field => 2.5, # T heating_power => 10, # MW (auxiliary heating) dt_fuel_fraction => 1.0, # pure 50:50 D-T (no dilution) ); print $reactor->power_report; # --------------------------------------------------------------------------- # Temperature scan: fusion power and gain Q across the reactor-relevant range. # --------------------------------------------------------------------------- print "\nIon-temperature scan (n_e = 2e20 m^-3, P_heat = 10 MW):\n"; printf " %-8s %-14s %-12s %-14s %-8s\n", 'T_i[keV]', '[m^3/s]', 'P_fus[MW]', 'wall[MW/m^2]', 'Q'; for my $T_keV ( 5, 10, 15, 20, 30, 50 ) { $reactor->ion_temperature( $T_keV * 1000 ); printf " %-8.0f %-14.3e %-12.1f %-14.3f %-8.1f\n", $T_keV, $reactor->dt_reactivity, $reactor->fusion_power_MW, $reactor->neutron_wall_load, $reactor->fusion_gain_Q; } # --------------------------------------------------------------------------- # Density scan at fixed 15 keV: fusion power grows as n^2. # --------------------------------------------------------------------------- $reactor->ion_temperature(15000); print "\nDensity scan (T_i = 15 keV, P_heat = 10 MW):\n"; printf " %-12s %-12s %-14s %-8s\n", 'n_e[m^-3]', 'P_fus[MW]', 'P_neutron[MW]', 'Q'; for my $ne ( 5e19, 1e20, 1.5e20, 2e20, 3e20 ) { $reactor->electron_density($ne); printf " %-12.2e %-12.1f %-14.1f %-8.1f\n", $ne, $reactor->fusion_power_MW, $reactor->neutron_power_MW, $reactor->fusion_gain_Q; } print "\nNote: a 0-D estimate assuming uniform, pure 50:50 D-T; real devices\n"; print "have peaked profiles, fuel dilution and finite burn-up.\n"; Physics-Stellarator-0.02/examples/w7x_simulation.pl0000755000175000017500000000170515222765403021543 0ustar jovanjovan#!/usr/bin/env perl use strict; use warnings; use lib 'lib'; use Physics::CPD::Stellarator; # Simulate a Wendelstein 7-X high-performance discharge. my $w7x = Physics::CPD::Stellarator->new( electron_density => 8e19, # m^-3 electron_temperature => 4000, # eV ion_temperature => 2500, # eV magnetic_field => 2.5, # T heating_power => 10, # MW (ECRH) ion_species => 'H', ); print $w7x->device_report; # Scan the operating density and report ISS04 confinement + triple product. print "\nDensity scan (ISS04 confinement + Lawson triple product):\n"; printf " %-12s %-12s %-14s %-10s\n", 'n_e[m^-3]', 'tau_E[s]', 'nTtau[keV.s/m3]', 'beta[%]'; for my $ne ( 2e19, 4e19, 6e19, 8e19, 1e20 ) { $w7x->electron_density($ne); printf " %-12.2e %-12.3f %-14.3e %-10.2f\n", $ne, $w7x->confinement_time_iss04, $w7x->triple_product, 100 * $w7x->plasma_beta; } Physics-Stellarator-0.02/lib/0000755000175000017500000000000015241167064015137 5ustar jovanjovanPhysics-Stellarator-0.02/lib/Physics/0000755000175000017500000000000015241167064016561 5ustar jovanjovanPhysics-Stellarator-0.02/lib/Physics/CPD/0000755000175000017500000000000015241167064017167 5ustar jovanjovanPhysics-Stellarator-0.02/lib/Physics/CPD/Stellarator.pm0000755000175000017500000007443315223004102022016 0ustar jovanjovanpackage Physics::CPD::Stellarator; use strict; use warnings; use Moo; use Carp qw(croak); extends 'Physics::CPD'; our $VERSION = '0.02'; use constant PI => 3.14159265358979; #--------------------------------------------------------------------------- # Fusion (deuterium-tritium) reaction data #--------------------------------------------------------------------------- # Energy released per D-T fusion reaction T(d,n)4He [MeV] use constant { DT_ENERGY_MEV => 17.59, # total energy per reaction DT_ALPHA_ENERGY_MEV => 3.52, # 4He alpha (charged, heats plasma) DT_NEUTRON_ENERGY_MEV => 14.07, # neutron (escapes to the blanket) MEV_TO_JOULE => 1.602176634e-13, }; # Bosch-Hale parametrisation of the Maxwell-averaged reactivity for # T(d,n)4He (H.-S. Bosch & G.M. Hale, Nucl. Fusion 32 (1992) 611). Valid for # ion temperatures 0.2-100 keV; accurate to better than ~0.25%. my $DT_BG = 34.3827; # Gamow constant [sqrt(keV)] my $DT_MRC2 = 1124656; # reduced-mass energy m_r c^2 [keV] my @DT_C = ( # C1 .. C7 1.17302e-9, 1.51361e-2, 7.51886e-2, 4.60643e-3, 1.35000e-2, -1.06750e-4, 1.36600e-5, ); #--------------------------------------------------------------------------- # Default Wendelstein 7-X-like boundary (VMEC-style Fourier series). # # R(u,v) = sum Rbc(m,n) cos(m u - n Nfp v) # Z(u,v) = sum Zbs(m,n) sin(m u - n Nfp v) # # u = poloidal angle, v = toroidal angle, Nfp = number of field periods. # Each element is [ m, n, Rbc, Zbs ] in metres. The m=0 terms define the # helical magnetic axis; m>=1 terms define the rotating, bean-shaped cross # section that gives the stellarator its characteristic five-fold twist. #--------------------------------------------------------------------------- sub _default_boundary_coeffs { return [ [ 0, 0, 5.50, 0.00 ], # major radius R0 [ 0, 1, -0.28, -0.18 ], # major-radius breathing + axis excursion [ 1, 0, 0.50, 0.55 ], # base (elongated) cross section [ 1, 1, 0.26, -0.28 ], # rotating elongation -> bean shape + twist [ 2, 0, -0.05, 0.04 ], # triangularity [ 2, 1, -0.05, 0.04 ], # triangularity modulation ]; } #--------------------------------------------------------------------------- # Device attributes (defaults describe Wendelstein 7-X) #--------------------------------------------------------------------------- has config_name => ( is => 'rw', default => sub { 'Wendelstein 7-X (standard EIM configuration)' }, ); has major_radius => ( # R0 [m] is => 'rw', default => sub { 5.5 }, ); has minor_radius => ( # a [m] is => 'rw', default => sub { 0.53 }, ); has num_field_periods => ( # Nfp is => 'rw', default => sub { 5 }, ); has iota => ( # rotational transform (effective, ~2/3 radius) is => 'rw', default => sub { 0.96 }, ); has heating_power => ( # P [MW] is => 'rw', default => sub { 10 }, ); has num_nonplanar_coils => ( is => 'rw', default => sub { 50 }, ); has num_planar_coils => ( is => 'rw', default => sub { 20 }, ); has beta_limit => ( # design MHD beta limit is => 'rw', default => sub { 0.05 }, ); has pulse_length => ( # [s] is => 'rw', default => sub { 1800 }, ); has gyrotron_frequency => ( # ECRH gyrotron frequency [Hz] is => 'rw', default => sub { 140e9 }, ); has dt_fuel_fraction => ( # D-T fuel-ion fraction of n_e (0..1) is => 'rw', # 1.0 = pure 50:50 D-T; lower models dilution default => sub { 1.0 }, ); has boundary_coeffs => ( is => 'rw', default => \&_default_boundary_coeffs, ); # --- coil-geometry styling (used by the 3-D diagram) --- has coil_radius => ( is => 'rw', default => sub { 0.95 } ); # [m] has coil_elongation => ( is => 'rw', default => sub { 1.25 } ); has coil_tilt => ( is => 'rw', default => sub { 0.16 } ); # rad # W7-X runs a strong field; override the CPD default of 1 T. has '+magnetic_field' => ( default => sub { 2.5 } ); #--------------------------------------------------------------------------- # Basic device geometry #--------------------------------------------------------------------------- sub aspect_ratio { my ($self) = @_; return $self->major_radius / $self->minor_radius; } # Toroidal angle spanned by one field period [rad] sub field_period_angle { my ($self) = @_; return 2 * PI / $self->num_field_periods; } # Plasma volume of the toroidal plasma V = 2 pi^2 R0 a^2 [m^3] sub plasma_volume { my ($self) = @_; return 2 * PI**2 * $self->major_radius * $self->minor_radius**2; } # Plasma surface area (approx.) S = 4 pi^2 R0 a [m^2] sub plasma_surface_area { my ($self) = @_; return 4 * PI**2 * $self->major_radius * $self->minor_radius; } # Rotational transform and its inverse, the stellarator "safety factor" sub rotational_transform { $_[0]->iota } sub safety_factor { 1 / $_[0]->iota } #--------------------------------------------------------------------------- # Confinement, limits and fusion figures of merit #--------------------------------------------------------------------------- # ISS04 international stellarator energy-confinement scaling [s] # tau_E = 0.134 a^2.28 R^0.64 P^-0.61 n19^0.54 B^0.84 iota^0.41 # a,R in m; P in MW; n19 = line-averaged density in 1e19 m^-3; B in T. sub confinement_time_iss04 { my ($self) = @_; my $a = $self->minor_radius; my $R = $self->major_radius; my $P = $self->heating_power; my $n19 = $self->electron_density / 1e19; my $B = $self->magnetic_field; my $iota = $self->iota; return 0.134 * $a**2.28 * $R**0.64 * $P**-0.61 * $n19**0.54 * $B**0.84 * $iota**0.41; } # Stored thermal plasma energy W = (3/2) p V [J] sub stored_energy { my ($self) = @_; return 1.5 * $self->plasma_pressure * $self->plasma_volume; } sub stored_energy_MJ { $_[0]->stored_energy / 1e6 } # Sudo density limit for stellarators [m^-3] # n_max = 0.25 * sqrt( P B / (a^2 R) ) * 1e20 ; P in MW, B in T, a,R in m. sub sudo_density_limit { my ($self) = @_; return 0.25 * sqrt( $self->heating_power * $self->magnetic_field / ( $self->minor_radius**2 * $self->major_radius ) ) * 1e20; } # Fraction of the design beta limit currently used sub beta_fraction { my ($self) = @_; return $self->plasma_beta / $self->beta_limit; } # Fraction of the Sudo density limit currently used sub density_fraction { my ($self) = @_; return $self->electron_density / $self->sudo_density_limit; } # Lawson triple product n T_i tau_E [keV s m^-3] sub triple_product { my ($self) = @_; return $self->electron_density * ( $self->ion_temperature / 1000 ) # eV -> keV * $self->confinement_time_iss04; } # Resonant field for electron-cyclotron heating at the gyrotron frequency # f = n * (e B) / (2 pi m_e) -> B_res = 2 pi m_e f / (n e) sub ecrh_resonance_field { my ( $self, $harmonic ) = @_; $harmonic ||= 2; # W7-X uses 2nd-harmonic X-mode at 2.5 T / 140 GHz return 2 * PI * Physics::CPD::ELECTRON_MASS() * $self->gyrotron_frequency / ( $harmonic * Physics::CPD::ELEMENTARY_CHARGE() ); } #--------------------------------------------------------------------------- # Theoretical fusion power production (assumes a 50:50 D-T plasma) # # W7-X itself is a hydrogen/deuterium research device and produces negligible # fusion power; these methods estimate the power a stellarator of this design # *would* deliver if fuelled with deuterium-tritium at the given operating # point. The model is a 0-D estimate that treats n_e and T_i as uniform over # the plasma volume, using the Bosch-Hale reactivity above. #--------------------------------------------------------------------------- # Maxwell-averaged D-T reactivity [m^3/s] at ion temperature # $Ti_keV (defaults to the model ion temperature). sub dt_reactivity { my ( $self, $Ti_keV ) = @_; $Ti_keV = $self->ion_temperature / 1000 unless defined $Ti_keV; return 0 if $Ti_keV <= 0; my $T = $Ti_keV; my $num = $T * ( $DT_C[1] + $T * ( $DT_C[3] + $T * $DT_C[5] ) ); my $den = 1 + $T * ( $DT_C[2] + $T * ( $DT_C[4] + $T * $DT_C[6] ) ); my $theta = $T / ( 1 - $num / $den ); my $xi = ( $DT_BG**2 / ( 4 * $theta ) )**( 1 / 3 ); my $sv_cm3 = $DT_C[0] * $theta * sqrt( $xi / ( $DT_MRC2 * $T**3 ) ) * exp( -3 * $xi ); return $sv_cm3 * 1e-6; # cm^3/s -> m^3/s } # Total D-T fuel-ion density n_fuel = f * n_e [m^-3] sub fuel_ion_density { my ($self) = @_; return $self->dt_fuel_fraction * $self->electron_density; } # Volumetric fusion power density P/V = n_D n_T E_DT [W/m^3] # For a 50:50 mix n_D = n_T = n_fuel/2, so n_D n_T = n_fuel^2 / 4. sub fusion_power_density { my ($self) = @_; my $nfuel = $self->fuel_ion_density; return 0.25 * $nfuel**2 * $self->dt_reactivity * DT_ENERGY_MEV * MEV_TO_JOULE; } # Total fusion power [W] and [MW] sub fusion_power { $_[0]->fusion_power_density * $_[0]->plasma_volume } sub fusion_power_MW { $_[0]->fusion_power / 1e6 } # 14.07 MeV neutron power carried to the blanket [MW] sub neutron_power_MW { my ($self) = @_; return $self->fusion_power_MW * ( DT_NEUTRON_ENERGY_MEV / DT_ENERGY_MEV ); } # 3.52 MeV alpha (charged-particle) power retained to heat the plasma [MW] sub alpha_power_MW { my ($self) = @_; return $self->fusion_power_MW * ( DT_ALPHA_ENERGY_MEV / DT_ENERGY_MEV ); } # Average neutron wall loading over the plasma surface [MW/m^2] sub neutron_wall_load { my ($self) = @_; return $self->neutron_power_MW / $self->plasma_surface_area; } # Fusion energy gain Q = P_fusion / P_heating (dimensionless) sub fusion_gain_Q { my ($self) = @_; my $p = $self->heating_power; return $p > 0 ? $self->fusion_power_MW / $p : 'inf'; } #--------------------------------------------------------------------------- # Radial profiles (illustrative, peaked shapes) # x = r/a in [0,1]; f(x) = f0 (1 - x^2)^alpha #--------------------------------------------------------------------------- sub density_profile { my ( $self, $x, $alpha ) = @_; $alpha = defined $alpha ? $alpha : 0.5; my $v = 1 - $x * $x; $v = 0 if $v < 0; return $self->electron_density * $v**$alpha; } sub temperature_profile { my ( $self, $x, $alpha ) = @_; $alpha = defined $alpha ? $alpha : 2.0; my $v = 1 - $x * $x; $v = 0 if $v < 0; return $self->electron_temperature * $v**$alpha; } #=========================================================================== # GEOMETRY (pure Perl; returns array references so no PDL is required) #=========================================================================== # Evaluate the Fourier boundary at (u,v). A scale in [0,1] shrinks the # poloidal (m>=1) modes toward the axis, generating nested flux surfaces. sub boundary_point { my ( $self, $u, $v, $scale ) = @_; $scale = 1 unless defined $scale; my $Nfp = $self->num_field_periods; my ( $R, $Z ) = ( 0, 0 ); for my $c ( @{ $self->boundary_coeffs } ) { my ( $m, $n, $rbc, $zbs ) = @$c; my $sc = $m == 0 ? 1 : $scale; my $ang = $m * $u - $n * $Nfp * $v; $R += $sc * $rbc * cos($ang); $Z += $sc * $zbs * sin($ang); } return ( $R, $Z ); } # Cartesian point on a flux surface at (u,v). sub surface_point_xyz { my ( $self, $u, $v, $scale ) = @_; my ( $R, $Z ) = $self->boundary_point( $u, $v, $scale ); return ( $R * cos($v), $R * sin($v), $Z ); } # Magnetic axis: the m=0 part of the boundary (scale = 0). # Returns ($x_aref, $y_aref, $z_aref) for $n samples over the full torus. sub magnetic_axis { my ( $self, $n ) = @_; $n ||= 400; my ( @X, @Y, @Z ); for my $i ( 0 .. $n ) { my $v = 2 * PI * $i / $n; my ( $x, $y, $z ) = $self->surface_point_xyz( 0, $v, 0 ); push @X, $x; push @Y, $y; push @Z, $z; } return ( \@X, \@Y, \@Z ); } # One poloidal cross section (R,Z) at toroidal angle $v. # Returns ($R_aref, $Z_aref). sub cross_section { my ( $self, $v, $nu, $scale ) = @_; $nu ||= 200; my ( @R, @Z ); for my $i ( 0 .. $nu ) { my $u = 2 * PI * $i / $nu; my ( $r, $z ) = $self->boundary_point( $u, $v, $scale ); push @R, $r; push @Z, $z; } return ( \@R, \@Z ); } # Flux-surface grid as arrays-of-arrays [nu+1][nv+1] for X, Y, Z. sub surface_grid { my ( $self, $nu, $nv, $scale ) = @_; $nu ||= 60; $nv ||= 180; my ( @X, @Y, @Z ); for my $i ( 0 .. $nu ) { my $u = 2 * PI * $i / $nu; my ( @xr, @yr, @zr ); for my $j ( 0 .. $nv ) { my $v = 2 * PI * $j / $nv; my ( $x, $y, $z ) = $self->surface_point_xyz( $u, $v, $scale ); push @xr, $x; push @yr, $y; push @zr, $z; } push @X, \@xr; push @Y, \@yr; push @Z, \@zr; } return ( \@X, \@Y, \@Z ); } # Modular coils as tilted, elongated rings following the magnetic axis. # Returns a list of coil loops, each an arrayref [ $x_aref, $y_aref, $z_aref ]. sub modular_coils { my ( $self, $count, $npts ) = @_; $count ||= 2 * $self->num_field_periods; # readable subset of the 50 coils $npts ||= 120; my $rc = $self->coil_radius; my $elong = $self->coil_elongation; my $tilt = $self->coil_tilt; my @coils; for my $k ( 0 .. $count - 1 ) { my $phic = ( $k + 0.5 ) * 2 * PI / $count; my ( $Rc0, $Zc0 ) = $self->boundary_point( 0, $phic, 0 ); # axis centre my ( @X, @Y, @Z ); for my $i ( 0 .. $npts ) { my $u = 2 * PI * $i / $npts; my $dR = $rc * cos($u); my $dZ = $rc * $elong * sin($u); my $phi = $phic + $tilt * sin($u) / $Rc0; my $R = $Rc0 + $dR; my $Z = $Zc0 + $dZ; push @X, $R * cos($phi); push @Y, $R * sin($phi); push @Z, $Z; } push @coils, [ \@X, \@Y, \@Z ]; } return @coils; } #=========================================================================== # PLOTTING (lazily loads PDL + PDL::Graphics::Gnuplot; writes to a file) #=========================================================================== sub _new_gpwin { my ( $self, %o ) = @_; eval { require PDL; require PDL::Graphics::Gnuplot; 1; } or croak "Plotting requires PDL and PDL::Graphics::Gnuplot to be installed: $@"; my $output = $o{output} || 'stellarator.png'; my $term = $o{terminal} || 'pngcairo'; my $size = $o{size} || [ 10, 8 ]; my $w = PDL::Graphics::Gnuplot->new( $term, output => $output, size => $size, ); return $w; } # turn an arrayref (or array-of-arrays) into a PDL piddle sub _pdl { require PDL; return PDL->pdl( $_[0] ); } # --- 3-D diagram of the stellarator design ------------------------------- # Draws the last-closed flux surface, the helical magnetic axis and a set of # modular field coils. Options: output, title, size, view [az,el], # show_axis, show_coils, coil_count, nu, nv, surface_scale. sub plot_3d { my ( $self, %o ) = @_; my $w = $self->_new_gpwin(%o); my $nu = $o{nu} || 54; my $nv = $o{nv} || 170; my $scale = defined $o{surface_scale} ? $o{surface_scale} : 1; my $view = $o{view} || [ 62, 25 ]; my $title = defined $o{title} ? $o{title} : $self->config_name . ' - 3D design'; my @items; # last-closed flux surface (wireframe) my ( $X, $Y, $Z ) = $self->surface_grid( $nu, $nv, $scale ); push @items, ( { with => 'lines', lc => '#c8b0e8' }, _pdl($X), _pdl($Y), _pdl($Z) ); # helical magnetic axis if ( !defined $o{show_axis} || $o{show_axis} ) { my ( $ax, $ay, $az ) = $self->magnetic_axis( 400 ); push @items, ( { with => 'lines', lw => 3, lc => '#000000' }, _pdl($ax), _pdl($ay), _pdl($az) ); } # modular coils if ( !defined $o{show_coils} || $o{show_coils} ) { for my $coil ( $self->modular_coils( $o{coil_count} ) ) { push @items, ( { with => 'lines', lw => 2, lc => '#d83010' }, _pdl( $coil->[0] ), _pdl( $coil->[1] ), _pdl( $coil->[2] ) ); } } $w->plot3d( { trid => 1, title => $title, view => $view, xlabel => 'X (m)', ylabel => 'Y (m)', zlabel => 'Z (m)', }, @items, ); $w->close; return $o{output} || 'stellarator.png'; } # --- nested flux-surface cross sections over one field period ------------ # Options: output, title, size, n_angles, n_surfaces, nu. sub plot_cross_sections { my ( $self, %o ) = @_; $o{output} ||= 'stellarator_cross_sections.png'; my $w = $self->_new_gpwin(%o); my $nang = $o{n_angles} || 5; my $nsurf = $o{n_surfaces} || 6; my $nu = $o{nu} || 200; my $title = defined $o{title} ? $o{title} : 'Flux-surface cross sections over one field period'; my @plots; my @palette = ( '#1f77b4', '#d62728', '#2ca02c', '#9467bd', '#ff7f0e', '#17becf', '#8c564b', '#e377c2', ); for my $a ( 0 .. $nang - 1 ) { my $v = ( $nang > 1 ? $a / ( $nang - 1 ) : 0 ) * $self->field_period_angle; my $color = $palette[ $a % @palette ]; for my $s ( 1 .. $nsurf ) { my $scale = $s / $nsurf; my ( $R, $Z ) = $self->cross_section( $v, $nu, $scale ); my %style = ( with => 'lines', lc => $color ); $style{legend} = sprintf( 'phi = %.0f deg', $v * 180 / PI ) if $s == $nsurf; # label only the outermost surface push @plots, ( \%style, _pdl($R), _pdl($Z) ); } } $w->plot( { title => $title, xlabel => 'R (m)', ylabel => 'Z (m)', }, @plots, ); $w->close; return $o{output}; } # --- radial density and temperature profiles ----------------------------- sub plot_profiles { my ( $self, %o ) = @_; $o{output} ||= 'stellarator_profiles.png'; my $w = $self->_new_gpwin(%o); my $n = $o{n_points} || 100; my $alpha_n = defined $o{alpha_n} ? $o{alpha_n} : 0.5; my $alpha_T = defined $o{alpha_T} ? $o{alpha_T} : 2.0; my ( @x, @ne, @te ); for my $i ( 0 .. $n ) { my $xr = $i / $n; push @x, $xr; push @ne, $self->density_profile( $xr, $alpha_n ) / 1e19; # 1e19 m^-3 push @te, $self->temperature_profile( $xr, $alpha_T ) / 1000; # keV } $w->plot( { title => 'W7-X radial profiles (illustrative)', xlabel => 'normalised minor radius r/a', ylabel => 'n_e (1e19 m^-3) / T_e (keV)', }, ( { with => 'lines', lw => 2, legend => 'n_e (1e19 m^-3)' }, _pdl( \@x ), _pdl( \@ne ) ), ( { with => 'lines', lw => 2, legend => 'T_e (keV)' }, _pdl( \@x ), _pdl( \@te ) ), ); $w->close; return $o{output}; } # --- ISS04 confinement-time parameter scan -------------------------------- # Scans one attribute (default 'heating_power') and plots tau_E(ISS04). sub plot_confinement_scan { my ( $self, %o ) = @_; $o{output} ||= 'stellarator_confinement.png'; my $w = $self->_new_gpwin(%o); my $param = $o{parameter} || 'heating_power'; my $from = defined $o{from} ? $o{from} : 1; my $to = defined $o{to} ? $o{to} : 20; my $n = $o{n_points} || 60; my $saved = $self->$param; # restore afterwards my ( @x, @tau ); for my $i ( 0 .. $n ) { my $val = $from + ( $to - $from ) * $i / $n; $self->$param($val); push @x, $val; push @tau, $self->confinement_time_iss04; } $self->$param($saved); ( my $plabel = $param ) =~ s/_/ /g; # avoid gnuplot subscripting $w->plot( { title => "ISS04 confinement time vs $plabel", xlabel => $plabel, ylabel => 'tau_E (s)', }, ( { with => 'lines', lw => 2, legend => 'tau_E (ISS04)' }, _pdl( \@x ), _pdl( \@tau ) ), ); $w->close; return $o{output}; } #--------------------------------------------------------------------------- # Reporting #--------------------------------------------------------------------------- sub device_report { my ($self) = @_; my @l; push @l, "== Stellarator device: " . $self->config_name . " =="; push @l, sprintf( " major radius R0 = %.3f m", $self->major_radius ); push @l, sprintf( " minor radius a = %.3f m", $self->minor_radius ); push @l, sprintf( " aspect ratio R0/a = %.2f", $self->aspect_ratio ); push @l, sprintf( " field periods Nfp = %d", $self->num_field_periods ); push @l, sprintf( " rotational transf. iota = %.3f (q = %.3f)", $self->iota, $self->safety_factor ); push @l, sprintf( " magnetic field B = %.2f T", $self->magnetic_field ); push @l, sprintf( " plasma volume V = %.2f m^3", $self->plasma_volume ); push @l, sprintf( " plasma surface S = %.2f m^2", $self->plasma_surface_area ); push @l, sprintf( " non-planar coils = %d", $self->num_nonplanar_coils ); push @l, sprintf( " planar coils = %d", $self->num_planar_coils ); push @l, " -- operating point --"; push @l, sprintf( " heating power P = %.1f MW", $self->heating_power ); push @l, sprintf( " electron density n_e = %.3e m^-3", $self->electron_density ); push @l, sprintf( " electron temp. T_e = %.2f keV", $self->electron_temperature / 1000 ); push @l, sprintf( " ion temperature T_i = %.2f keV", $self->ion_temperature / 1000 ); push @l, " -- derived performance --"; push @l, sprintf( " ISS04 confinement tau_E = %.3f s", $self->confinement_time_iss04 ); push @l, sprintf( " stored energy W = %.2f MJ", $self->stored_energy_MJ ); push @l, sprintf( " plasma beta beta = %.2f %% (%.0f%% of limit)", 100 * $self->plasma_beta, 100 * $self->beta_fraction ); push @l, sprintf( " Sudo density limit n_max = %.3e m^-3 (%.0f%% used)", $self->sudo_density_limit, 100 * $self->density_fraction ); push @l, sprintf( " triple product n T tau = %.3e keV s m^-3", $self->triple_product ); push @l, sprintf( " ECRH 2nd-harm. res. field = %.2f T (at %.0f GHz)", $self->ecrh_resonance_field(2), $self->gyrotron_frequency / 1e9 ); return join( "\n", @l ) . "\n"; } # Theoretical fusion-power summary for a 50:50 D-T operating point. sub power_report { my ($self) = @_; my @l; push @l, "== Theoretical fusion power (50:50 D-T): " . $self->config_name . " =="; push @l, " -- operating point --"; push @l, sprintf( " electron density n_e = %.3e m^-3", $self->electron_density ); push @l, sprintf( " D-T fuel fraction f = %.2f (n_fuel = %.3e m^-3)", $self->dt_fuel_fraction, $self->fuel_ion_density ); push @l, sprintf( " ion temperature T_i = %.2f keV", $self->ion_temperature / 1000 ); push @l, sprintf( " heating power P_heat = %.1f MW", $self->heating_power ); push @l, " -- fusion output --"; push @l, sprintf( " D-T reactivity = %.3e m^3/s", $self->dt_reactivity ); push @l, sprintf( " fusion power density = %.3e MW/m^3", $self->fusion_power_density / 1e6 ); push @l, sprintf( " total fusion power P_fus = %.2f MW", $self->fusion_power_MW ); push @l, sprintf( " neutrons (14.07 MeV) = %.2f MW", $self->neutron_power_MW ); push @l, sprintf( " alphas (3.52 MeV) = %.2f MW", $self->alpha_power_MW ); push @l, sprintf( " neutron wall load = %.3f MW/m^2", $self->neutron_wall_load ); push @l, sprintf( " fusion gain Q = %.2f", $self->fusion_gain_Q ); return join( "\n", @l ) . "\n"; } 1; __END__ =head1 NAME Physics::CPD::Stellarator - Model and visualise the Wendelstein 7-X stellarator =head1 SYNOPSIS use Physics::CPD::Stellarator; my $w7x = Physics::CPD::Stellarator->new( electron_density => 8e19, # m^-3 electron_temperature => 4000, # eV ion_temperature => 2000, # eV magnetic_field => 2.5, # T heating_power => 10, # MW ); print $w7x->device_report; printf "ISS04 tau_E = %.3f s\n", $w7x->confinement_time_iss04; printf "stored W = %.1f MJ\n", $w7x->stored_energy_MJ; # Theoretical fusion power if this design were fuelled with D-T: $w7x->ion_temperature(15000); # 15 keV $w7x->electron_density(2e20); print $w7x->power_report; printf "P_fusion = %.1f MW, Q = %.1f\n", $w7x->fusion_power_MW, $w7x->fusion_gain_Q; # visualisations (written to PNG files) $w7x->plot_3d( output => 'w7x_3d.png' ); $w7x->plot_cross_sections( output => 'w7x_cross.png' ); $w7x->plot_profiles( output => 'w7x_profiles.png' ); $w7x->plot_confinement_scan( parameter => 'heating_power', from => 1, to => 20 ); =head1 DESCRIPTION C extends L with the geometry and engineering/plasma parameters needed to simulate a I, using the B (W7-X) device at IPP Greifswald as its default configuration. It inherits every plasma calculation of the base class and adds: =over 4 =item * device parameters - major/minor radius, five field periods, coil counts, rotational transform C, design beta limit, pulse length; =item * derived physics - aspect ratio, plasma volume and surface, the ISS04 international stellarator confinement-time scaling, stored thermal energy, the Sudo density limit, plasma-beta and density-limit fractions, the Lawson triple product, and the electron-cyclotron-heating resonant field; =item * theoretical fusion power - Bosch-Hale D-T reactivity, fusion power density and total fusion power, the neutron/alpha split, neutron wall loading and the fusion gain C, for evaluating the design as a hypothetical D-T reactor; =item * three-dimensional geometry - the last-closed flux surface described as a VMEC-style Fourier series R(u,v), Z(u,v), the helical magnetic axis, nested flux surfaces and a set of tilted modular field coils; and =item * plotting - 3-D design diagrams, poloidal cross sections through a field period, radial profiles and confinement-scaling scans, rendered with L. =back Geometry accessors (C, C, C, C, C) are pure Perl and return array references, so they can be used and tested without PDL. Only the C methods require L and L; they are loaded on demand and render to an image file (default terminal C), so they work on headless machines. =head1 KEY ATTRIBUTES C, C (5.5 m), C (0.53 m), C (5), C (0.96), C (2.5 T), C (10 MW), C (50), C (20), C (0.05), C (1800 s), C (140 GHz), C (1.0, the D-T fuel-ion fraction of C used by the fusion-power methods), and C (the Fourier boundary, overridable to model any stellarator equilibrium). =head1 PHYSICS METHODS C, C, C, C, C, C, C / C, C, C, C, C, C, C, C, C. =head1 FUSION POWER METHODS These estimate the fusion power a stellarator of this design would produce if fuelled with a 50:50 deuterium-tritium mix. W7-X itself runs hydrogen or deuterium and produces negligible fusion power, so the numbers are a I figure of merit for the geometry and operating point. The model is 0-D (it treats C and C as uniform over C). =over 4 =item dt_reactivity([$Ti_keV]) Maxwell-averaged D-T reactivity C<< >> in m^3/s at ion temperature C<$Ti_keV> (defaults to the model C), via the Bosch-Hale parametrisation (valid 0.2-100 keV). =item fuel_ion_density Total D-T fuel-ion density C [m^-3]. =item fusion_power_density Volumetric fusion power C<(n_fuel/2)^2 E_DT> [W/m^3]. =item fusion_power / fusion_power_MW Total fusion power over the plasma volume, in W and MW. =item neutron_power_MW / alpha_power_MW The 14.07 MeV neutron power (to the blanket) and 3.52 MeV alpha power (retained to heat the plasma), in MW. =item neutron_wall_load Average neutron loading over the plasma surface [MW/m^2]. =item fusion_gain_Q Fusion energy gain C. =item power_report A formatted multi-line summary of the operating point and fusion output. =back =head1 GEOMETRY METHODS C, C, C, C, C, C. =head1 PLOTTING METHODS C, C, C, C. Each accepts an C filename (and optional C, C and method-specific options) and returns the filename it wrote. =head1 SEE ALSO L, L. W7-X reference: Klinger et al., "Overview of first Wendelstein 7-X high- performance operation", Nucl. Fusion 59 (2019). ISS04 scaling: Yamada et al., Nucl. Fusion 45 (2005) 1684. D-T reactivity: H.-S. Bosch & G.M. Hale, "Improved formulas for fusion cross-sections and thermal reactivities", Nucl. Fusion 32 (1992) 611. =head1 AUTHOR Generated for the Physics-Stellarator project. =head1 LICENSE Copyright (C) 2026 the Physics-Stellarator authors. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. See L. =cut Physics-Stellarator-0.02/lib/Physics/CPD.pm0000755000175000017500000003674715223004102017530 0ustar jovanjovanpackage Physics::CPD; use strict; use warnings; use Moo; use Carp qw(croak); our $VERSION = '0.02'; #--------------------------------------------------------------------------- # Physical constants (SI units, CODATA 2018) #--------------------------------------------------------------------------- use constant { ELEMENTARY_CHARGE => 1.602176634e-19, # C ELECTRON_MASS => 9.1093837015e-31, # kg PROTON_MASS => 1.67262192369e-27, # kg ATOMIC_MASS_UNIT => 1.66053906660e-27, # kg BOLTZMANN => 1.380649e-23, # J/K VACUUM_PERMITTIVITY => 8.8541878128e-12, # F/m VACUUM_PERMEABILITY => 1.25663706212e-6, # H/m SPEED_OF_LIGHT => 299792458, # m/s EV_TO_JOULE => 1.602176634e-19, # J per eV EV_TO_KELVIN => 11604.51812, # K per eV PI => 3.14159265358979, }; # atomic species table: name => [ mass number A, charge number Z ] my %SPECIES = ( 'e' => [ 5.48579909065e-4, -1 ], 'H' => [ 1.00782503207, 1 ], 'p' => [ 1.00727646688, 1 ], 'D' => [ 2.01410177812, 1 ], 'T' => [ 3.01604928199, 1 ], 'He' => [ 4.002602, 2 ], 'He3' => [ 3.01602932, 2 ], 'He4' => [ 4.002602, 2 ], 'C' => [ 12.011, 6 ], 'O' => [ 15.999, 8 ], ); #--------------------------------------------------------------------------- # Attributes (all plasma quantities are given in SI unless noted) # * temperatures are specified in electron-volts (eV), the plasma standard #--------------------------------------------------------------------------- has electron_density => ( # n_e [m^-3] is => 'rw', default => sub { 1e20 }, ); has electron_temperature => ( # T_e [eV] is => 'rw', default => sub { 1000 }, ); has ion_temperature => ( # T_i [eV] (defaults to T_e) is => 'rw', lazy => 1, default => sub { $_[0]->electron_temperature }, ); has magnetic_field => ( # B [T] is => 'rw', default => sub { 1 }, ); has ion_species => ( # chemical symbol, see %SPECIES is => 'rw', default => sub { 'H' }, ); has ion_mass => ( # m_i [kg] is => 'rw', lazy => 1, builder => '_build_ion_mass', ); has ion_charge => ( # Z (charge number) is => 'rw', lazy => 1, builder => '_build_ion_charge', ); sub _lookup_species { my ($self) = @_; my $s = $SPECIES{ $self->ion_species } or croak "Unknown ion species '" . $self->ion_species . "'"; return $s; } sub _build_ion_mass { my ($self) = @_; return $self->_lookup_species->[0] * ATOMIC_MASS_UNIT; } sub _build_ion_charge { my ($self) = @_; return $self->_lookup_species->[1]; } #--------------------------------------------------------------------------- # Temperature / energy helpers #--------------------------------------------------------------------------- sub electron_temperature_joules { $_[0]->electron_temperature * EV_TO_JOULE } sub ion_temperature_joules { $_[0]->ion_temperature * EV_TO_JOULE } sub electron_temperature_kelvin { $_[0]->electron_temperature * EV_TO_KELVIN } sub ion_temperature_kelvin { $_[0]->ion_temperature * EV_TO_KELVIN } # quasineutral ion density Z * n_i = n_e sub ion_density { my ($self) = @_; return $self->electron_density / abs( $self->ion_charge ); } sub mass_density { # ion mass density rho [kg/m^3] my ($self) = @_; return $self->ion_density * $self->ion_mass; } #--------------------------------------------------------------------------- # Characteristic frequencies #--------------------------------------------------------------------------- # Electron plasma (Langmuir) frequency [rad/s] sub electron_plasma_frequency { my ($self) = @_; my $ne = $self->electron_density; return sqrt( $ne * ELEMENTARY_CHARGE**2 / ( VACUUM_PERMITTIVITY * ELECTRON_MASS ) ); } sub electron_plasma_frequency_hz { $_[0]->electron_plasma_frequency / ( 2 * PI ) } # Ion plasma frequency [rad/s] sub ion_plasma_frequency { my ($self) = @_; my $ni = $self->ion_density; my $q = $self->ion_charge * ELEMENTARY_CHARGE; return sqrt( $ni * $q**2 / ( VACUUM_PERMITTIVITY * $self->ion_mass ) ); } sub ion_plasma_frequency_hz { $_[0]->ion_plasma_frequency / ( 2 * PI ) } # Electron cyclotron (gyro) frequency [rad/s] sub electron_cyclotron_frequency { my ($self) = @_; return ELEMENTARY_CHARGE * $self->magnetic_field / ELECTRON_MASS; } sub electron_cyclotron_frequency_hz { $_[0]->electron_cyclotron_frequency / ( 2 * PI ) } # Ion cyclotron frequency [rad/s] sub ion_cyclotron_frequency { my ($self) = @_; return abs( $self->ion_charge ) * ELEMENTARY_CHARGE * $self->magnetic_field / $self->ion_mass; } sub ion_cyclotron_frequency_hz { $_[0]->ion_cyclotron_frequency / ( 2 * PI ) } #--------------------------------------------------------------------------- # Characteristic lengths and speeds #--------------------------------------------------------------------------- # Debye length [m] sub debye_length { my ($self) = @_; return sqrt( VACUUM_PERMITTIVITY * $self->electron_temperature_joules / ( $self->electron_density * ELEMENTARY_CHARGE**2 ) ); } # Electron thermal speed v = sqrt(k T / m) [m/s] sub electron_thermal_velocity { my ($self) = @_; return sqrt( $self->electron_temperature_joules / ELECTRON_MASS ); } # Ion thermal speed v = sqrt(k T / m) [m/s] sub ion_thermal_velocity { my ($self) = @_; return sqrt( $self->ion_temperature_joules / $self->ion_mass ); } # Electron Larmor (gyro) radius using thermal speed [m] sub electron_gyroradius { my ($self) = @_; return ELECTRON_MASS * $self->electron_thermal_velocity / ( ELEMENTARY_CHARGE * $self->magnetic_field ); } # Ion Larmor (gyro) radius using thermal speed [m] sub ion_gyroradius { my ($self) = @_; return $self->ion_mass * $self->ion_thermal_velocity / ( abs( $self->ion_charge ) * ELEMENTARY_CHARGE * $self->magnetic_field ); } # Alfven speed v_A = B / sqrt(mu0 rho) [m/s] sub alfven_velocity { my ($self) = @_; return $self->magnetic_field / sqrt( VACUUM_PERMEABILITY * $self->mass_density ); } # Ion-acoustic (sound) speed c_s = sqrt(Z k T_e / m_i) [m/s] sub ion_sound_speed { my ($self) = @_; return sqrt( abs( $self->ion_charge ) * $self->electron_temperature_joules / $self->ion_mass ); } #--------------------------------------------------------------------------- # Pressures, beta and stored-energy density #--------------------------------------------------------------------------- # Kinetic plasma pressure p = n_e k T_e + n_i k T_i [Pa] sub plasma_pressure { my ($self) = @_; return $self->electron_density * $self->electron_temperature_joules + $self->ion_density * $self->ion_temperature_joules; } # Magnetic pressure B^2 / (2 mu0) [Pa] sub magnetic_pressure { my ($self) = @_; return $self->magnetic_field**2 / ( 2 * VACUUM_PERMEABILITY ); } # Plasma beta = kinetic pressure / magnetic pressure (dimensionless) sub plasma_beta { my ($self) = @_; return $self->plasma_pressure / $self->magnetic_pressure; } #--------------------------------------------------------------------------- # Collisional parameters (NRL Plasma Formulary) #--------------------------------------------------------------------------- # Coulomb logarithm for electron-ion collisions sub coulomb_logarithm { my ($self) = @_; my $ne_cm3 = $self->electron_density * 1e-6; # convert to cm^-3 my $Te = $self->electron_temperature; # eV my $Z = abs( $self->ion_charge ); my $ln; if ( $Te > 10 * $Z**2 ) { $ln = 24 - log( sqrt($ne_cm3) / $Te ); } else { $ln = 23 - log( sqrt($ne_cm3) * $Z * $Te**-1.5 ); } return $ln < 1 ? 1 : $ln; } # Electron-ion collision frequency [s^-1] sub collision_frequency { my ($self) = @_; my $ne_cm3 = $self->electron_density * 1e-6; my $Te = $self->electron_temperature; my $Z = abs( $self->ion_charge ); return 2.91e-6 * $Z * $ne_cm3 * $self->coulomb_logarithm * $Te**-1.5; } # Electron mean free path [m] sub mean_free_path { my ($self) = @_; my $nu = $self->collision_frequency; return $nu > 0 ? $self->electron_thermal_velocity / $nu : 'inf'; } # Parallel Spitzer resistivity [Ohm m] sub spitzer_resistivity { my ($self) = @_; my $Z = abs( $self->ion_charge ); my $Te = $self->electron_temperature; # eV return 5.2e-5 * $Z * $self->coulomb_logarithm * $Te**-1.5; } #--------------------------------------------------------------------------- # Dimensionless plasma parameter #--------------------------------------------------------------------------- # Number of particles in a Debye sphere N_D = (4/3) pi n lambda_D^3 sub plasma_parameter { my ($self) = @_; return ( 4 / 3 ) * PI * $self->electron_density * $self->debye_length**3; } #--------------------------------------------------------------------------- # Reporting #--------------------------------------------------------------------------- sub as_hash { my ($self) = @_; return { electron_density => $self->electron_density, electron_temperature_eV => $self->electron_temperature, ion_temperature_eV => $self->ion_temperature, magnetic_field_T => $self->magnetic_field, ion_species => $self->ion_species, electron_plasma_frequency_Hz => $self->electron_plasma_frequency_hz, ion_plasma_frequency_Hz => $self->ion_plasma_frequency_hz, electron_cyclotron_freq_Hz => $self->electron_cyclotron_frequency_hz, ion_cyclotron_frequency_Hz => $self->ion_cyclotron_frequency_hz, debye_length_m => $self->debye_length, electron_gyroradius_m => $self->electron_gyroradius, ion_gyroradius_m => $self->ion_gyroradius, electron_thermal_velocity_ms => $self->electron_thermal_velocity, ion_thermal_velocity_ms => $self->ion_thermal_velocity, alfven_velocity_ms => $self->alfven_velocity, ion_sound_speed_ms => $self->ion_sound_speed, plasma_pressure_Pa => $self->plasma_pressure, magnetic_pressure_Pa => $self->magnetic_pressure, plasma_beta => $self->plasma_beta, coulomb_logarithm => $self->coulomb_logarithm, collision_frequency_Hz => $self->collision_frequency, mean_free_path_m => $self->mean_free_path, spitzer_resistivity_Ohm_m => $self->spitzer_resistivity, plasma_parameter => $self->plasma_parameter, }; } sub report { my ($self) = @_; my @lines; push @lines, "== Computational Plasma Dynamics (Physics::CPD) =="; push @lines, sprintf( " electron density n_e = %.3e m^-3", $self->electron_density ); push @lines, sprintf( " electron temperature T_e = %.3g eV (%.3g K)", $self->electron_temperature, $self->electron_temperature_kelvin ); push @lines, sprintf( " ion temperature T_i = %.3g eV (%s, Z=%d)", $self->ion_temperature, $self->ion_species, $self->ion_charge ); push @lines, sprintf( " magnetic field B = %.3g T", $self->magnetic_field ); push @lines, " -- derived quantities --"; push @lines, sprintf( " plasma frequency f_pe = %.3e Hz", $self->electron_plasma_frequency_hz ); push @lines, sprintf( " e- cyclotron freq f_ce = %.3e Hz", $self->electron_cyclotron_frequency_hz ); push @lines, sprintf( " ion cyclotron freq f_ci = %.3e Hz", $self->ion_cyclotron_frequency_hz ); push @lines, sprintf( " Debye length lambda_D= %.3e m", $self->debye_length ); push @lines, sprintf( " e- gyroradius r_Le = %.3e m", $self->electron_gyroradius ); push @lines, sprintf( " ion gyroradius r_Li = %.3e m", $self->ion_gyroradius ); push @lines, sprintf( " Alfven speed v_A = %.3e m/s", $self->alfven_velocity ); push @lines, sprintf( " ion sound speed c_s = %.3e m/s", $self->ion_sound_speed ); push @lines, sprintf( " plasma pressure p = %.3e Pa", $self->plasma_pressure ); push @lines, sprintf( " plasma beta beta = %.3f %%", 100 * $self->plasma_beta ); push @lines, sprintf( " Coulomb log lnLambda= %.2f", $self->coulomb_logarithm ); push @lines, sprintf( " plasma parameter N_D = %.3e", $self->plasma_parameter ); return join( "\n", @lines ) . "\n"; } 1; __END__ =head1 NAME Physics::CPD - Computational Plasma Dynamics: fundamental magnetised-plasma parameters =head1 SYNOPSIS use Physics::CPD; my $plasma = Physics::CPD->new( electron_density => 8e19, # m^-3 electron_temperature => 4000, # eV ion_temperature => 2000, # eV magnetic_field => 2.5, # T ion_species => 'H', ); printf "Debye length = %.3e m\n", $plasma->debye_length; printf "plasma beta = %.2f %%\n", 100 * $plasma->plasma_beta; print $plasma->report; =head1 DESCRIPTION C is a lightweight, pure-Perl engine for computational plasma dynamics. It models a quasineutral, magnetised plasma from a small set of state variables (density, electron/ion temperature, magnetic field and ion species) and derives the standard characteristic frequencies, lengths, speeds, pressures and collisional parameters used throughout magnetic-confinement fusion and space-plasma physics. Temperatures are supplied in B (eV), the customary plasma unit; all other quantities use SI. The class is built with L so every state variable is a read/write accessor and derived quantities are ordinary methods. It is the computational base for L, which adds stellarator geometry and Wendelstein 7-X modelling. =head1 ATTRIBUTES =over 4 =item electron_density (n_e, m^-3, default 1e20) =item electron_temperature (T_e, eV, default 1000) =item ion_temperature (T_i, eV, defaults to T_e) =item magnetic_field (B, tesla, default 1) =item ion_species (chemical symbol; H, D, T, He, He3, C, O, ..., default 'H') =item ion_mass (kg, derived from the species unless overridden) =item ion_charge (Z, derived from the species unless overridden) =back =head1 METHODS Frequencies (rad/s, with C<_hz> variants): C, C, C, C. Lengths and speeds: C, C, C, C, C, C, C. Pressures and energetics: C, C, C. Collisional transport (NRL Plasma Formulary): C, C, C, C. Other: C, C, C, C, C. =head1 SEE ALSO L =head1 AUTHOR Generated for the Physics-Stellarator project. =head1 LICENSE Copyright (C) 2026 the Physics-Stellarator authors. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. See L. =cut Physics-Stellarator-0.02/LICENSE0000755000175000017500000010451515222764644015415 0ustar jovanjovan GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . Physics-Stellarator-0.02/Makefile.PL0000755000175000017500000000216215222765403016347 0ustar jovanjovanuse strict; use warnings; use ExtUtils::MakeMaker; WriteMakefile( NAME => 'Physics::CPD', DISTNAME => 'Physics-Stellarator', VERSION_FROM => 'lib/Physics/CPD/Stellarator.pm', ABSTRACT => 'Computational plasma dynamics with Wendelstein 7-X stellarator modelling and 3-D visualisation', AUTHOR => 'Physics-Stellarator project', LICENSE => 'gpl_3', MIN_PERL_VERSION => '5.010', # Core physics only needs Moo; plotting needs PDL (declared as recommended). PREREQ_PM => { 'Moo' => 0, 'Carp' => 0, 'Test::More' => 0, }, META_MERGE => { 'meta-spec' => { version => 2 }, prereqs => { runtime => { recommends => { 'PDL' => 0, 'PDL::Graphics::Gnuplot' => 0, }, }, }, resources => { homepage => 'https://www.ipp.mpg.de/w7x', }, }, dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz' }, clean => { FILES => 'Physics-Stellarator-* *.png' }, ); Physics-Stellarator-0.02/MANIFEST0000755000175000017500000000072215241167064015526 0ustar jovanjovanChanges examples/plasma_parameters.pl examples/plot_3d_design.pl examples/power_production.pl examples/w7x_simulation.pl lib/Physics/CPD.pm lib/Physics/CPD/Stellarator.pm LICENSE Makefile.PL MANIFEST README.md t/00-load.t t/01-cpd.t t/02-stellarator.t t/03-geometry.t t/04-plotting.t t/05-fusion.t META.yml Module YAML meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) Physics-Stellarator-0.02/META.json0000644000175000017500000000235115241167064016013 0ustar jovanjovan{ "abstract" : "Computational plasma dynamics with Wendelstein 7-X stellarator modelling and 3-D visualisation", "author" : [ "Physics-Stellarator project" ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.70, CPAN::Meta::Converter version 2.150010", "license" : [ "gpl_3" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Physics-Stellarator", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "recommends" : { "PDL" : "0", "PDL::Graphics::Gnuplot" : "0" }, "requires" : { "Carp" : "0", "Moo" : "0", "Test::More" : "0", "perl" : "5.010" } } }, "release_status" : "stable", "resources" : { "homepage" : "https://www.ipp.mpg.de/w7x" }, "version" : "0.02", "x_serialization_backend" : "JSON::PP version 4.16" } Physics-Stellarator-0.02/META.yml0000644000175000017500000000137515241167064015650 0ustar jovanjovan--- abstract: 'Computational plasma dynamics with Wendelstein 7-X stellarator modelling and 3-D visualisation' author: - 'Physics-Stellarator project' build_requires: ExtUtils::MakeMaker: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.70, CPAN::Meta::Converter version 2.150010' license: gpl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Physics-Stellarator no_index: directory: - t - inc recommends: PDL: '0' PDL::Graphics::Gnuplot: '0' requires: Carp: '0' Moo: '0' Test::More: '0' perl: '5.010' resources: homepage: https://www.ipp.mpg.de/w7x version: '0.02' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' Physics-Stellarator-0.02/README.md0000755000175000017500000002732615223004040015645 0ustar jovanjovan# Physics-Stellarator Computational plasma dynamics in Perl, with a full model and 3‑D visualisation of the **Wendelstein 7‑X** stellarator. The distribution provides two modules: | Module | Role | |--------|------| | **`Physics::CPD`** | Pure‑Perl *Computational Plasma Dynamics* engine — fundamental magnetised‑plasma parameters from density, temperature, magnetic field and ion species. | | **`Physics::CPD::Stellarator`** | Extends `Physics::CPD` with stellarator geometry and physics, using **Wendelstein 7‑X** (W7‑X, IPP Greifswald) as the default configuration, plus plotting and 3‑D design diagrams. | --- ## Features ### `Physics::CPD` — plasma physics engine (no heavy dependencies) * Characteristic frequencies: electron/ion **plasma** and **cyclotron** frequencies. * Characteristic lengths/speeds: **Debye length**, electron/ion **Larmor radii**, **thermal**, **Alfvén** and **ion‑sound** speeds. * Energetics: kinetic and magnetic **pressure**, **plasma β**. * Collisional transport (NRL Plasma Formulary): **Coulomb logarithm**, **collision frequency**, **mean free path**, **Spitzer resistivity**. * Multi‑species ions (`H, D, T, He, He3, C, O, …`); temperatures in **eV**. ### `Physics::CPD::Stellarator` — Wendelstein 7‑X model * Device parameters: major/minor radius, **5 field periods**, coil counts, rotational transform *ι*, design **β limit**, pulse length, ECRH gyrotron. * Derived physics: **aspect ratio**, **plasma volume/surface**, **ISS04 confinement‑time scaling**, **stored energy**, the stellarator **Sudo density limit**, β/density‑limit fractions, the **Lawson triple product**, and the **ECRH resonant field**. * Theoretical **fusion power production** (if fuelled with D‑T): **Bosch‑Hale D‑T reactivity** ⟨σv⟩, **fusion power density** and **total fusion power**, the **neutron/alpha split**, **neutron wall loading** and the **fusion gain *Q***. * 3‑D geometry: the last‑closed flux surface as a **VMEC‑style Fourier series** `R(u,v), Z(u,v)`, the **helical magnetic axis**, nested flux surfaces and **modular field coils** — fully parameterised so you can model other stellarators by supplying your own boundary coefficients. * Plotting via `PDL::Graphics::Gnuplot` (headless‑safe PNG output): **3‑D design diagram**, **poloidal cross sections**, **radial profiles**, **confinement scans**. --- ## Installation ```sh perl Makefile.PL make make test make install ``` Requirements: * **Runtime (core physics):** [`Moo`](https://metacpan.org/pod/Moo). * **Plotting / 3‑D (optional):** [`PDL`](https://metacpan.org/pod/PDL), [`PDL::Graphics::Gnuplot`](https://metacpan.org/pod/PDL::Graphics::Gnuplot) and a `gnuplot` binary. These are loaded on demand — the physics API works without them. --- ## Quick start ### Plasma parameters ```perl use Physics::CPD; my $plasma = Physics::CPD->new( electron_density => 1e20, # m^-3 electron_temperature => 5000, # eV ion_temperature => 3000, # eV magnetic_field => 3.0, # T ion_species => 'D', ); print $plasma->report; printf "beta = %.2f %%\n", 100 * $plasma->plasma_beta; ``` ### Wendelstein 7‑X ```perl use Physics::CPD::Stellarator; my $w7x = Physics::CPD::Stellarator->new( electron_density => 8e19, electron_temperature => 4000, ion_temperature => 2500, magnetic_field => 2.5, heating_power => 10, # MW ); print $w7x->device_report; printf "ISS04 tau_E = %.3f s\n", $w7x->confinement_time_iss04; printf "stored W = %.1f MJ\n", $w7x->stored_energy_MJ; # Visualisations (PNG files) $w7x->plot_3d( output => 'w7x_3d.png' ); # 3-D design diagram $w7x->plot_cross_sections( output => 'w7x_cross.png');# flux-surface sections $w7x->plot_profiles( output => 'w7x_profiles.png' ); # radial profiles $w7x->plot_confinement_scan( output => 'w7x_conf.png', parameter => 'heating_power', from => 1, to => 20 ); ``` The 3‑D diagram shows the twisted, bean‑shaped plasma boundary (the five field periods), the helical magnetic axis and the tilted modular coils. ### Theoretical fusion power W7‑X is a research device and does not itself produce significant fusion power, but the model can estimate what a stellarator of this design *would* deliver if run as a **deuterium–tritium** reactor (a 0‑D estimate using the Bosch‑Hale reactivity): ```perl use Physics::CPD::Stellarator; my $reactor = Physics::CPD::Stellarator->new( electron_density => 2.0e20, # m^-3 ion_temperature => 15000, # eV (15 keV) magnetic_field => 2.5, # T heating_power => 10, # MW (auxiliary) dt_fuel_fraction => 1.0, # pure 50:50 D-T ); print $reactor->power_report; printf "P_fusion = %.1f MW\n", $reactor->fusion_power_MW; # ~235 MW printf " neutrons = %.1f MW\n", $reactor->neutron_power_MW; printf " alphas = %.1f MW\n", $reactor->alpha_power_MW; printf "wall load = %.2f MW/m^2\n", $reactor->neutron_wall_load; printf "gain Q = %.1f\n", $reactor->fusion_gain_Q; # P_fus / P_heat ``` --- ## Examples Runnable scripts in [`examples/`](examples): * `plasma_parameters.pl` — `Physics::CPD` standalone. * `w7x_simulation.pl` — W7‑X report and a density scan (τ_E, triple product, β). * `power_production.pl` — theoretical D‑T fusion power of the W7‑X‑class design, with ion‑temperature and density scans (P_fus, neutron wall load, *Q*). * `plot_3d_design.pl` — writes all four PNG visualisations (`perl examples/plot_3d_design.pl [output_dir]`). --- ## API reference Both classes are built with [`Moo`](https://metacpan.org/pod/Moo): every constructor argument below is also a read/write accessor (`$obj->attr` to read, `$obj->attr($value)` to set), and every derived quantity is a plain method that recomputes from the current state. Temperatures are in **eV**; all other quantities are **SI** unless a method name carries an explicit unit suffix (`_MJ`, `_MW`, `_hz`, …). ### `Physics::CPD` **Constructor attributes** | Attribute | Symbol | Unit | Default | Description | |-----------|--------|------|---------|-------------| | `electron_density` | *n*ₑ | m⁻³ | `1e20` | electron number density | | `electron_temperature` | *T*ₑ | eV | `1000` | electron temperature | | `ion_temperature` | *T*ᵢ | eV | = *T*ₑ | ion temperature | | `magnetic_field` | *B* | T | `1` | magnetic flux density | | `ion_species` | — | — | `'H'` | `e, H, p, D, T, He, He3, He4, C, O` | | `ion_mass` | *m*ᵢ | kg | from species | override to bypass the species table | | `ion_charge` | *Z* | — | from species | ion charge number | **Derived quantities (methods)** | Group | Methods | Unit | |-------|---------|------| | Energy / density helpers | `electron_temperature_joules`, `ion_temperature_joules`, `electron_temperature_kelvin`, `ion_temperature_kelvin`, `ion_density`, `mass_density` | J, K, m⁻³, kg·m⁻³ | | Frequencies (+`_hz` variants) | `electron_plasma_frequency`, `ion_plasma_frequency`, `electron_cyclotron_frequency`, `ion_cyclotron_frequency` | rad/s (Hz) | | Lengths & speeds | `debye_length`, `electron_gyroradius`, `ion_gyroradius`, `electron_thermal_velocity`, `ion_thermal_velocity`, `alfven_velocity`, `ion_sound_speed` | m, m/s | | Pressure & energetics | `plasma_pressure`, `magnetic_pressure`, `plasma_beta` | Pa, Pa, – | | Collisional transport (NRL) | `coulomb_logarithm`, `collision_frequency`, `mean_free_path`, `spitzer_resistivity` | –, s⁻¹, m, Ω·m | | Other | `plasma_parameter` (*N*_D), `as_hash`, `report` | –, hashref, text | `as_hash` returns every quantity keyed with its unit (e.g. `debye_length_m`); `report` returns the same as a formatted, printable block. ### `Physics::CPD::Stellarator` Inherits everything above and overrides the default `magnetic_field` to 2.5 T. **Additional attributes** | Attribute | Symbol | Unit | Default | Description | |-----------|--------|------|---------|-------------| | `config_name` | — | — | `'Wendelstein 7-X …'` | free-text label | | `major_radius` | *R₀* | m | `5.5` | major radius | | `minor_radius` | *a* | m | `0.53` | minor radius | | `num_field_periods` | *N*fp | — | `5` | toroidal field periods | | `iota` | *ι* | — | `0.96` | rotational transform | | `heating_power` | *P* | MW | `10` | auxiliary heating power | | `num_nonplanar_coils` | — | — | `50` | non-planar modular coils | | `num_planar_coils` | — | — | `20` | planar coils | | `beta_limit` | — | — | `0.05` | design MHD β limit | | `pulse_length` | — | s | `1800` | pulse length | | `gyrotron_frequency` | — | Hz | `140e9` | ECRH gyrotron frequency | | `dt_fuel_fraction` | *f* | — | `1.0` | D-T fuel-ion fraction of *n*ₑ (fusion methods) | | `boundary_coeffs` | — | m | W7-X set | `[m, n, Rbc, Zbs]` Fourier rows | | `coil_radius` / `coil_elongation` / `coil_tilt` | — | m / – / rad | `0.95` / `1.25` / `0.16` | 3-D coil styling | **Geometry & performance methods** | Group | Methods | Unit | |-------|---------|------| | Device geometry | `aspect_ratio`, `field_period_angle`, `plasma_volume`, `plasma_surface_area`, `rotational_transform`, `safety_factor` | –, rad, m³, m², –, – | | Confinement & limits | `confinement_time_iss04`, `stored_energy` / `stored_energy_MJ`, `sudo_density_limit`, `beta_fraction`, `density_fraction`, `triple_product`, `ecrh_resonance_field([n])` | s, J/MJ, m⁻³, –, –, keV·s·m⁻³, T | | Radial profiles | `density_profile($x[,α])`, `temperature_profile($x[,α])` | m⁻³, eV | | Reporting | `device_report`, `power_report` | text | **Fusion power methods** (assume a 50:50 D‑T plasma; 0‑D estimate over the plasma volume, Bosch‑Hale reactivity) | Method | Returns | Unit | |--------|---------|------| | `dt_reactivity([$Ti_keV])` | ⟨σv⟩ at *T*ᵢ (default `ion_temperature`) | m³/s | | `fuel_ion_density` | `dt_fuel_fraction × electron_density` | m⁻³ | | `fusion_power_density` | (*n*_fuel/2)² ⟨σv⟩ *E*_DT | W/m³ | | `fusion_power` / `fusion_power_MW` | total fusion power | W / MW | | `neutron_power_MW` | 14.07 MeV channel (to blanket) | MW | | `alpha_power_MW` | 3.52 MeV channel (heats plasma) | MW | | `neutron_wall_load` | neutron power / plasma surface | MW/m² | | `fusion_gain_Q` | `fusion_power_MW / heating_power` | – | **Geometry accessors** (pure Perl, return array references — no PDL required) `boundary_point($u,$v[,$scale])`, `surface_point_xyz($u,$v[,$scale])`, `magnetic_axis([$n])`, `cross_section($v[,$nu,$scale])`, `surface_grid([$nu,$nv,$scale])`, `modular_coils([$count,$npts])`. **Plotting methods** (require `PDL` + `PDL::Graphics::Gnuplot`; each takes an `output =>` filename and returns the filename written) `plot_3d`, `plot_cross_sections`, `plot_profiles`, `plot_confinement_scan`. --- ## Wendelstein 7‑X reference parameters (defaults) | Quantity | Value | |----------|-------| | Major radius `R0` | 5.5 m | | Minor radius `a` | 0.53 m | | Aspect ratio | ≈ 10.4 | | Field periods | 5 | | Magnetic field | up to 3 T (2.5 T typical) | | Plasma volume | ≈ 30 m³ | | Non‑planar / planar coils | 50 / 20 | | Rotational transform *ι* | ≈ 0.8 – 1.2 | | ECRH | 140 GHz, 2nd‑harmonic X‑mode → 2.5 T | | Design β limit | ≈ 5 % | --- ## Physics references * Klinger *et al.*, “Overview of first Wendelstein 7‑X high‑performance operation”, *Nucl. Fusion* **59** (2019) 112004. * Yamada *et al.*, ISS04 confinement scaling, *Nucl. Fusion* **45** (2005) 1684. * Sudo *et al.*, stellarator density limit, *Nucl. Fusion* **30** (1990) 11. * Bosch & Hale, improved D‑T fusion reactivities, *Nucl. Fusion* **32** (1992) 611. * Huba, *NRL Plasma Formulary* (collisional parameters). ## License Released under the **GNU General Public License v3.0** — see the [`LICENSE`](LICENSE) file for the full text. Physics-Stellarator-0.02/t/0000755000175000017500000000000015241167064014634 5ustar jovanjovanPhysics-Stellarator-0.02/t/00-load.t0000755000175000017500000000103715222765403016161 0ustar jovanjovanuse strict; use warnings; use Test::More; use_ok('Physics::CPD') or BAIL_OUT('Physics::CPD failed to load'); use_ok('Physics::CPD::Stellarator') or BAIL_OUT('Physics::CPD::Stellarator failed to load'); ok( Physics::CPD->can('new'), 'Physics::CPD has a constructor' ); ok( Physics::CPD::Stellarator->can('new'), 'Stellarator has a constructor' ); my $s = Physics::CPD::Stellarator->new; isa_ok( $s, 'Physics::CPD::Stellarator', 'object' ); isa_ok( $s, 'Physics::CPD', 'inherits from Physics::CPD' ); done_testing; Physics-Stellarator-0.02/t/01-cpd.t0000755000175000017500000000602215222763244016011 0ustar jovanjovanuse strict; use warnings; use Test::More; use Physics::CPD; # fractional-tolerance comparison sub approx { my ( $got, $exp, $tol, $name ) = @_; $tol ||= 1e-3; my $ok = ( $exp == 0 ) ? abs($got) < $tol : abs( ( $got - $exp ) / $exp ) < $tol; ok( $ok, $name ) or diag(" got $got, expected $exp"); } my $p = Physics::CPD->new( electron_density => 1e19, electron_temperature => 1000, magnetic_field => 1, ion_species => 'H', ); # defaults / quasineutrality is( $p->ion_temperature, 1000, 'ion temperature defaults to electron temperature' ); approx( $p->ion_density, 1e19, 1e-9, 'ion density equals n_e/Z for Z=1' ); # electron cyclotron frequency == e B / m_e exactly approx( $p->electron_cyclotron_frequency, Physics::CPD::ELEMENTARY_CHARGE() * 1 / Physics::CPD::ELECTRON_MASS(), 1e-12, 'electron cyclotron frequency = eB/m_e' ); # 28 GHz/T rule of thumb approx( $p->electron_cyclotron_frequency_hz, 27.99e9, 2e-3, 'f_ce ~ 28 GHz/T' ); # NRL: f_pe = 8980 * sqrt(n_cm3) Hz approx( $p->electron_plasma_frequency_hz, 8980 * sqrt(1e13), 3e-3, 'f_pe ~ 8980*sqrt(n)' ); # NRL: lambda_D = 743 * sqrt(Te_eV / n_cm3) cm approx( $p->debye_length, 7.43e2 * sqrt( 1000 / 1e13 ) * 1e-2, 3e-3, 'Debye length matches NRL' ); # beta is pressure ratio, and pressure is the sum of species pressures approx( $p->plasma_beta, $p->plasma_pressure / $p->magnetic_pressure, 1e-12, 'beta = p/pmag' ); approx( $p->plasma_pressure, $p->electron_density * $p->electron_temperature_joules + $p->ion_density * $p->ion_temperature_joules, 1e-12, 'pressure is electron + ion pressure' ); # temperature conversions approx( $p->electron_temperature_kelvin, 1000 * 11604.51812, 1e-6, 'eV -> K conversion' ); approx( $p->electron_temperature_joules, 1000 * 1.602176634e-19, 1e-9, 'eV -> J conversion' ); # ion Larmor radius bigger than electron Larmor radius ok( $p->ion_gyroradius > $p->electron_gyroradius, 'ion gyroradius > electron gyroradius' ); # Alfven speed scales linearly with B my $p2 = Physics::CPD->new( electron_density => 1e19, electron_temperature => 1000, magnetic_field => 2 ); approx( $p2->alfven_velocity / $p->alfven_velocity, 2, 1e-9, 'Alfven speed ~ B' ); # species handling my $d = Physics::CPD->new( ion_species => 'D' ); approx( $d->ion_mass, 2.01410177812 * Physics::CPD::ATOMIC_MASS_UNIT(), 1e-6, 'deuterium mass' ); is( $d->ion_charge, 1, 'deuterium charge Z=1' ); my $he = Physics::CPD->new( ion_species => 'He' ); is( $he->ion_charge, 2, 'helium charge Z=2' ); # collisionality sanity: Coulomb log in a reasonable range, resistivity positive ok( $p->coulomb_logarithm > 5 && $p->coulomb_logarithm < 30, 'Coulomb log in physical range' ); ok( $p->spitzer_resistivity > 0, 'Spitzer resistivity positive' ); ok( $p->plasma_parameter > 1, 'many particles in Debye sphere (ideal plasma)' ); # report is a non-empty string like( $p->report, qr/Computational Plasma Dynamics/, 'report renders' ); ok( ref $p->as_hash eq 'HASH', 'as_hash returns a hashref' ); done_testing; Physics-Stellarator-0.02/t/02-stellarator.t0000755000175000017500000000610015222765403017574 0ustar jovanjovanuse strict; use warnings; use Test::More; use Physics::CPD::Stellarator; sub approx { my ( $got, $exp, $tol, $name ) = @_; $tol ||= 1e-6; my $ok = ( $exp == 0 ) ? abs($got) < $tol : abs( ( $got - $exp ) / $exp ) < $tol; ok( $ok, $name ) or diag(" got $got, expected $exp"); } my $w = Physics::CPD::Stellarator->new( electron_density => 8e19, electron_temperature => 4000, ion_temperature => 2000, magnetic_field => 2.5, heating_power => 10, ); #---------------------------------------------------------------- device approx( $w->aspect_ratio, 5.5 / 0.53, 1e-9, 'aspect ratio = R0/a' ); approx( $w->plasma_volume, 2 * 3.14159265358979**2 * 5.5 * 0.53**2, 1e-6, 'plasma volume 2 pi^2 R a^2' ); approx( $w->field_period_angle, 2 * 3.14159265358979 / 5, 1e-9, 'field-period angle = 2pi/Nfp' ); approx( $w->safety_factor, 1 / 0.96, 1e-9, 'q = 1/iota' ); # W7-X reference numbers land in the right place ok( abs( $w->plasma_volume - 30 ) < 1.5, 'plasma volume ~ 30 m^3 (W7-X)' ); ok( abs( $w->aspect_ratio - 10.4 ) < 0.2, 'aspect ratio ~ 10.4 (W7-X)' ); #---------------------------------------------------------------- physics # ECRH 2nd-harmonic resonance at 140 GHz sits at 2.5 T approx( $w->ecrh_resonance_field(2), 2.5, 3e-3, 'ECRH 2nd harmonic resonant field ~ 2.5 T' ); # stored energy = 3/2 p V approx( $w->stored_energy, 1.5 * $w->plasma_pressure * $w->plasma_volume, 1e-9, 'W = 3/2 p V' ); # Sudo density limit closed form approx( $w->sudo_density_limit, 0.25 * sqrt( 10 * 2.5 / ( 0.53**2 * 5.5 ) ) * 1e20, 1e-9, 'Sudo density limit' ); # ISS04 scaling exponents verified through ratios { my %base = ( electron_density => 8e19, electron_temperature => 4000, magnetic_field => 2.5, heating_power => 10 ); my $b = Physics::CPD::Stellarator->new(%base); my $bn = Physics::CPD::Stellarator->new( %base, electron_density => 1.6e20 ); my $bp = Physics::CPD::Stellarator->new( %base, heating_power => 20 ); my $bb = Physics::CPD::Stellarator->new( %base, magnetic_field => 5 ); approx( $bn->confinement_time_iss04 / $b->confinement_time_iss04, 2**0.54, 1e-6, 'ISS04 density exponent 0.54' ); approx( $bp->confinement_time_iss04 / $b->confinement_time_iss04, 2**-0.61, 1e-6, 'ISS04 power exponent -0.61' ); approx( $bb->confinement_time_iss04 / $b->confinement_time_iss04, 2**0.84, 1e-6, 'ISS04 field exponent 0.84' ); } # triple product = n * Ti[keV] * tau approx( $w->triple_product, $w->electron_density * ( $w->ion_temperature / 1000 ) * $w->confinement_time_iss04, 1e-9, 'triple product n Ti tau' ); # inherited plasma physics still works ok( $w->debye_length > 0, 'inherited debye_length works' ); ok( $w->plasma_beta > 0, 'inherited plasma_beta works' ); # beta / density fractions approx( $w->beta_fraction, $w->plasma_beta / 0.05, 1e-9, 'beta fraction vs limit' ); approx( $w->density_fraction, 8e19 / $w->sudo_density_limit, 1e-9, 'density fraction vs Sudo' ); # report like( $w->device_report, qr/Wendelstein 7-X/, 'device_report renders' ); done_testing; Physics-Stellarator-0.02/t/03-geometry.t0000755000175000017500000000545415222765403017107 0ustar jovanjovanuse strict; use warnings; use Test::More; use Physics::CPD::Stellarator; my $w = Physics::CPD::Stellarator->new; my $PI = 3.14159265358979; # boundary_point at u=v=0, scale=1 is the sum of the R cosine coefficients my ( $R0, $Z0 ) = $w->boundary_point( 0, 0, 1 ); my $sumR = 0; $sumR += $_->[2] for @{ $w->boundary_coeffs }; is_deeply( [ sprintf('%.6f',$R0), sprintf('%.6f',$Z0) ], [ sprintf('%.6f',$sumR), sprintf('%.6f',0) ], 'boundary_point(0,0,1) = (sum Rbc, 0)' ); # scale = 0 collapses to the magnetic axis (only m=0 modes survive) my ( $Ra, $Za ) = $w->boundary_point( 0, 0, 0 ); approx_ok( $Ra, 5.5 - 0.28, 'axis R at v=0 uses only m=0 modes' ); approx_ok( $Za, 0, 'axis Z at v=0 is zero' ); # magnetic axis geometry my ( $ax, $ay, $az ) = $w->magnetic_axis(400); is( scalar(@$ax), 401, 'magnetic_axis returns n+1 points (x)' ); is( scalar(@$ay), 401, 'magnetic_axis returns n+1 points (y)' ); is( scalar(@$az), 401, 'magnetic_axis returns n+1 points (z)' ); approx_ok( $ax->[0], 5.22, 'axis first point x = R(v=0)' ); approx_ok( $ay->[0], 0, 'axis first point y = 0' ); # axis has a genuine helical (non-zero Z) excursion my $zmax = 0; $zmax = $_ > $zmax ? $_ : $zmax for @$az; ok( $zmax > 0.1, 'magnetic axis has helical vertical excursion' ); # cross section closes on itself (u = 0 and u = 2pi coincide) my ( $Rc, $Zc ) = $w->cross_section( 0, 200, 1 ); is( scalar(@$Rc), 201, 'cross_section returns nu+1 points' ); approx_ok( $Rc->[0], $Rc->[-1], 'cross section closes in R' ); approx_ok( $Zc->[0], $Zc->[-1], 'cross section closes in Z' ); # nested surfaces shrink toward the axis my $extent = sub { my $scale = shift; my ( $r, $z ) = $w->cross_section( 0, 100, $scale ); my ( $min, $max ) = ( $r->[0], $r->[0] ); for (@$r) { $min = $_ if $_ < $min; $max = $_ if $_ > $max; } return $max - $min; }; ok( $extent->(1.0) > $extent->(0.5), 'outer surface wider than inner surface' ); ok( $extent->(0.5) > $extent->(0.1), 'inner nesting continues toward axis' ); # surface grid dimensions my ( $X, $Y, $Z ) = $w->surface_grid( 10, 20, 1 ); is( scalar(@$X), 11, 'surface_grid has nu+1 rows' ); is( scalar(@{$X->[0]}), 21, 'surface_grid has nv+1 columns' ); # modular coils my @coils = $w->modular_coils; is( scalar(@coils), 2 * $w->num_field_periods, 'default coil count = 2*Nfp' ); is( scalar( @{ $coils[0] } ), 3, 'each coil is [x,y,z]' ); ok( scalar( @{ $coils[0][0] } ) > 10, 'coil has many points' ); my @coils5 = $w->modular_coils(5, 50); is( scalar(@coils5), 5, 'explicit coil count honoured' ); is( scalar( @{ $coils5[0][0] } ), 51, 'explicit coil point count honoured' ); done_testing; sub approx_ok { my ( $got, $exp, $name ) = @_; my $ok = abs( $got - $exp ) < 1e-2 * ( abs($exp) > 1 ? abs($exp) : 1 ); ok( $ok, $name ) or diag(" got $got, expected $exp"); } Physics-Stellarator-0.02/t/04-plotting.t0000755000175000017500000000245315222765403017111 0ustar jovanjovanuse strict; use warnings; use Test::More; use File::Temp qw(tempdir); use File::Spec; use Physics::CPD::Stellarator; # Plotting needs PDL + PDL::Graphics::Gnuplot + a gnuplot binary. Skip cleanly # if any part of that toolchain is unavailable on the test machine. my $have_plot = eval { require PDL; require PDL::Graphics::Gnuplot; 1; }; plan skip_all => 'PDL / PDL::Graphics::Gnuplot not available' unless $have_plot; my $dir = tempdir( CLEANUP => 1 ); my $w = Physics::CPD::Stellarator->new( electron_density => 8e19, electron_temperature => 4000, ion_temperature => 2000, magnetic_field => 2.5, heating_power => 10, ); my @cases = ( [ 'plot_3d', 'w7x_3d.png' ], [ 'plot_cross_sections', 'w7x_cross.png' ], [ 'plot_profiles', 'w7x_profiles.png' ], [ 'plot_confinement_scan', 'w7x_conf.png' ], ); for my $c (@cases) { my ( $method, $file ) = @$c; my $path = File::Spec->catfile( $dir, $file ); my $ret = eval { $w->$method( output => $path ); 1 }; ok( $ret, "$method ran without error" ) or diag($@); SKIP: { skip "$method did not run", 2 unless $ret; ok( -e $path, "$method produced $file" ); ok( -s $path > 1000, "$file is a non-trivial image" ); } } done_testing; Physics-Stellarator-0.02/t/05-fusion.t0000755000175000017500000000730115223003570016541 0ustar jovanjovanuse strict; use warnings; use Test::More; use Physics::CPD::Stellarator; sub approx { my ( $got, $exp, $tol, $name ) = @_; $tol ||= 1e-6; my $ok = ( $exp == 0 ) ? abs($got) < $tol : abs( ( $got - $exp ) / $exp ) < $tol; ok( $ok, $name ) or diag(" got $got, expected $exp"); } my $w = Physics::CPD::Stellarator->new( electron_density => 2e20, electron_temperature => 15000, ion_temperature => 15000, # 15 keV magnetic_field => 2.5, heating_power => 10, ); #---------------------------------------------------------------- reactivity # Bosch-Hale D-T against published reference values (~0.25% accuracy). approx( $w->dt_reactivity(10), 1.136e-22, 3e-3, ' at 10 keV ~ 1.14e-22 m^3/s' ); approx( $w->dt_reactivity(20), 4.330e-22, 3e-3, ' at 20 keV ~ 4.33e-22 m^3/s' ); # reactivity rises with temperature through the fusion-relevant range and peaks # near ~64 keV ok( $w->dt_reactivity(20) > $w->dt_reactivity(10), ' increases 10 -> 20 keV' ); ok( $w->dt_reactivity(64) > $w->dt_reactivity(30), ' still rising toward the peak' ); ok( $w->dt_reactivity(100) < $w->dt_reactivity(64), ' falls again past the peak' ); # no fuel temperature -> no reactions is( $w->dt_reactivity(0), 0, ' is zero at zero temperature' ); # default reactivity uses the model ion temperature (15 keV) approx( $w->dt_reactivity, $w->dt_reactivity(15), 1e-12, 'default uses ion_temperature' ); #---------------------------------------------------------------- power # fuel-ion density scales with dt_fuel_fraction approx( $w->fuel_ion_density, 2e20, 1e-12, 'fuel density = f * n_e (f=1)' ); # closed-form fusion power density P/V = (n_fuel/2)^2 E_DT my $E_DT = 17.59 * 1.602176634e-13; # J per reaction approx( $w->fusion_power_density, ( 2e20 / 2 )**2 * $w->dt_reactivity * $E_DT, 1e-9, 'fusion power density closed form' ); # total power = density * volume approx( $w->fusion_power, $w->fusion_power_density * $w->plasma_volume, 1e-12, 'P_fus = power density * volume' ); approx( $w->fusion_power_MW, $w->fusion_power / 1e6, 1e-12, 'MW conversion' ); # neutron + alpha channels sum to the total and carry the right fractions approx( $w->neutron_power_MW + $w->alpha_power_MW, $w->fusion_power_MW, 1e-9, 'neutron + alpha = total fusion power' ); approx( $w->neutron_power_MW / $w->fusion_power_MW, 14.07 / 17.59, 1e-9, 'neutrons carry 14.07/17.59 of the energy' ); approx( $w->alpha_power_MW / $w->fusion_power_MW, 3.52 / 17.59, 1e-9, 'alphas carry 3.52/17.59 of the energy' ); # W7-X-class design at a reactor-relevant D-T point lands at a few hundred MW ok( $w->fusion_power_MW > 100 && $w->fusion_power_MW < 500, 'reactor-point fusion power is a few hundred MW' ); # fusion gain Q = P_fus / P_heat approx( $w->fusion_gain_Q, $w->fusion_power_MW / 10, 1e-12, 'Q = P_fus / P_heat' ); # neutron wall load = neutron power / plasma surface approx( $w->neutron_wall_load, $w->neutron_power_MW / $w->plasma_surface_area, 1e-12, 'neutron wall load = P_n / surface' ); #---------------------------------------------------------------- fuel fraction # halving the fuel fraction quarters the power (density enters squared) { my $half = Physics::CPD::Stellarator->new( electron_density => 2e20, ion_temperature => 15000, heating_power => 10, dt_fuel_fraction => 0.5, ); approx( $half->fusion_power_MW, 0.25 * $w->fusion_power_MW, 1e-9, 'fusion power scales as fuel-fraction squared' ); } # power_report renders like( $w->power_report, qr/Theoretical fusion power/, 'power_report renders' ); like( $w->power_report, qr/fusion gain/, 'power_report shows Q' ); done_testing;