Add TF ripple perturbation to analytical tokamak field#149
Add TF ripple perturbation to analytical tokamak field#149krystophny wants to merge 4 commits intomainfrom
Conversation
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||||||||||
Implements toroidal field ripple following ASCOT5's B_GS model with δ(r,θ,φ) = δ₀ (r/a₀)^α₀ exp(-θ²/2) cos(N_ripple φ) Changes: - Add ripple parameters to analytical_circular_eq_t type - Nripple: number of TF coils (0 = no ripple) - delta0: ripple amplitude - alpha0: radial dependency exponent - a0: minor radius reference - z0: midplane reference - New eval_bfield_ripple method accepts toroidal angle phi - Ripple modulates B_phi component while preserving poloidal field - Full test suite with automatic plotting via CTest Tests verify: - 9-coil ripple with δ₀=0.10 produces ~12.65% peak-to-peak variation - 40° periodicity (360°/9) visible in 2D (φ,Z) pcolormesh plots - Axisymmetric field recovered when Nripple=0 Test files: - test/source/test_ripple_field.f90: Fortran data generation - test/scripts/plot_ripple_comparison.py: Python visualization - Outputs: bphi_ripple_comparison.png showing unperturbed, perturbed, and difference fields
Following ASCOT5's B_GS pattern, the analytical equilibrium type now extends field_t directly instead of requiring a separate wrapper file. This allows the same type to be used both as a standalone field (via eval_bfield_ripple) and as a Poincare-compatible field_t. Added methods: - compute_bfield: field_t interface for magnetic field evaluation - compute_afield: field_t interface stub (not implemented) - compute_abfield: combined A and B evaluation - compute_analytical_field_cylindrical: public standalone function The Nripple parameter controls ripple: 0 = axisymmetric, >0 = rippled.
Tests that analytical_circular_eq_t can be used as a field_t (via pointer) and produces identical results to the direct eval_bfield_ripple interface. This verifies Poincare plot compatibility. The test creates a field_t pointer to an analytical equilibrium instance, evaluates the magnetic field at a test point using both the field_t interface and the native interface, and verifies they produce identical results within numerical tolerance (1e-12).
- Unit tests: analytical_circular, analytical_geoflux, ripple_field - Integration tests: analytical_geoflux_integration - All tests pass (3/3) - Documents field-agnostic geoflux achievement - Outlines next steps for SIMPLE system tests
93e0cec to
41a628f
Compare
User description
Summary
Adds toroidal field (TF) coil ripple perturbation support to libneo's analytical tokamak equilibrium solver, following the ASCOT5 B_GS pattern.
Changes
Core Implementation
analytical_circular_eq_t:Nripple: Number of TF coils (0 = axisymmetric)delta0: Ripple amplitudealpha0,a0,z0: Ripple shape parameterseval_bfield_ripple(R, φ, Z, ...)method with toroidal angleInterface Extensions
analytical_circular_eq_tto implementfield_tinterfacecompute_bfield,compute_afield,compute_abfieldmethodscompute_analytical_field_cylindrical()for external useTesting
Design Pattern
Following ASCOT5's B_GS.c approach:
Test Plan
PR Type
Enhancement
Description
Add TF ripple perturbation to analytical tokamak field
Extend analytical_circular_eq_t to implement field_t interface
Add comprehensive test suite with visualization
Enable Poincaré plot compatibility
Diagram Walkthrough
File Walkthrough
analytical_tokamak_field.f90
Add TF ripple and field_t interfacesrc/magfie/analytical_tokamak_field.f90
compute_abfield)
test_analytical_circular.f90
Add field_t interface testtest/source/test_analytical_circular.f90
interface
test_ripple_field.f90
Add ripple field test programtest/source/test_ripple_field.f90
plot_ripple_comparison.py
Add ripple visualization scripttest/scripts/plot_ripple_comparison.py
CMakeLists.txt
Add ripple test configurationtest/CMakeLists.txt