Skip to content

Modernize magfie interface to eliminate global procedure pointer #292

@krystophny

Description

@krystophny

Priority: Low

Problem

The magfie interface uses a module-level procedure pointer (magfie_ptr) to select field evaluation at runtime. This global state pattern:

procedure(magfie_iface), pointer :: magfie_ptr => null()

subroutine init_magfie(mode)
    select case (mode)
        case (VMEC)
            magfie_ptr => magfie_vmec
        case (BOOZER)
            magfie_ptr => magfie_can_boozer
        ! ...
    end select
end subroutine

While functional, this could be modernized to use object-oriented dispatch.

Proposed Solution

Consider passing a field object directly to integrators instead of using global procedure pointer:

type(orbit_symplectic_t) :: orbit
class(magnetic_field_t), pointer :: field

call orbit%init(field)  ! Field object passed directly
call orbit%timestep(z, dtau)  ! Uses field internally

Benefits

  • Eliminates global state
  • Enables multiple simultaneous field configurations
  • Better encapsulation

Caveats

  • Significant refactoring effort
  • Current approach works fine for typical use cases
  • May impact performance if virtual dispatch adds overhead in hot loops

Related

  • See DOC/coordinates-and-fields.md Section 4

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions