simsopt

repository·master·Indexed 41 days ago

https://github.com/hiddensymmetries/simsopt

A flexible Python-based framework for stellarator optimization. It integrates physics codes (such as VMEC and SPEC), geometric modeling, and magnetic field calculations, combining high-level Python routines with performance-critical C++ and Fortran implementations.

Tokens
61.8K
Snippets
157
Records
243
Agent score
51%

What's inside simsopt

  1. Overview of the simsopt.geo package

    master

    The simsopt.geo package provides a comprehensive suite of tools for geometric modeling in stellarator and tokamak design. It is organized into submodules that handle different geometric primitives, such as curves and surfaces, as well as specialized tools for optimization, plotting, and configuration.

    Key functional areas include:

    • Curves: Various representations including helical, planar Fourier, RZ Fourier, XYZ Fourier, and perturbed curves.
    • Surfaces: Modeling tools for surfaces using different basis sets like RZ Fourier, XYZ Fourier, and XYZ Tensor Fourier, as well as specialized surfaces like boozersurface and qfmsurface.
    • Optimization & Objectives: Modules for defining geometric objectives (curveobjectives, surfaceobjectives) and specialized tasks like strain_optimization.
    • Utilities: Tools for plotting geometry, managing configuration, and Just-In-Time (JIT) compilation support.
  2. Overview of the simsopt package subpackages

    master

    The simsopt package is organized into several functional subpackages that cover different aspects of stellarator optimization and simulation. When building your workflows, you will primarily interact with these modules:

    • simsopt._core: Core data structures and fundamental logic.
    • simsopt.configs: Configuration management and handling.
    • simsopt.field: Magnetic field calculation and representation.
    • simsopt.geo: Geometric definitions and shape representations.
    • simsopt.mhd: Magnetohydrodynamics (MHD) related tools and models.
    • simsopt.objectives: Definition of cost functions and optimization targets.
    • simsopt.solve: Optimization solvers and numerical solution routines.
    • simsopt.util: General utility functions and helper tools.
  3. Overview of simsopt capabilities

    master

    simsopt is a framework designed for the optimization of stellarators. It combines high-level Python routines with performance-critical C++ or Fortran implementations.

    Key components include:

    • Physics Code Interfaces: Connects to codes for MHD equilibrium (e.g., VMEC, SPEC).
    • Optimization Tools: Defines objective functions and parameter spaces.
    • Geometric Objects: Provides parameterizations for surfaces and curves essential to stellarator design.
    • Magnetic Field Representations: Efficient implementations of the Biot-Savart law and its derivatives.
    • Gradient Calculation: Tools for parallelized finite-difference gradient calculations.
  4. Overview of the simsopt.field package

    master
    The simsopt.field package provides a comprehensive suite of tools for representing, calculating, and manipulating magnetic fields in plasma physics simulations. It includes modules for different field calculation methods (e.g., Biot-Savart, Boozer, Wireframe), coil and coilset representations, and utilities for magnetic axis helpers, sampling, and field tracing.
  5. What is simsopt?

    master

    simsopt is a framework designed for the optimization of stellarators. It provides high-level Python routines that interface with C++ or Fortran for performance-critical tasks.

    Key capabilities include:

    • Physics Code Interfaces: Integration with MHD equilibrium codes.
    • Optimization Tools: Defining objective functions and parameter spaces.
    • Geometric Objects: Parameterized surfaces and curves essential for stellarator design.
    • Magnetic Field Representations: Efficient implementations of the Biot-Savart law and other representations, including derivatives.
    • Gradient Calculation: Tools for parallelized finite-difference gradient calculations.
  6. Overview of the simsopt.mhd package

    master

    The simsopt.mhd package provides tools and interfaces for Magnetohydrodynamic (MHD) equilibrium modeling. It includes submodules for handling VMEC (Variational Moments Equilibrium Code) executions, profile management, specification handling, and diagnostic tools. Key functional areas include:

    • VMEC Integration: Modules like simsopt.mhd.vmec and simsopt.mhd.vmec_diagnostics for running and analyzing VMEC equilibria.
    • Profile Management: simsopt.mhd.profiles for defining physical profiles.
    • Bootstrap & Setup: simsopt.mhd.bootstrap for initialization tasks.
    • Specialized MHD Tools: Modules for boozer coordinates, spec definitions, and virtual_casing methods.
  7. Use the simsopt.solve package for optimization and solvers

    master

    The simsopt.solve package provides various modules for solving optimization problems and executing solvers in different environments. Depending on your use case, you can use specialized modules for:

    • Parallel execution: Use simsopt.solve.mpi for MPI-based parallel solving.
    • Permanent magnet optimization: Use simsopt.solve.permanent_magnet_optimization for tasks specifically involving permanent magnet configurations.
    • Serial execution: Use simsopt.solve.serial for standard single-threaded/serial solving.
    • Wireframe optimization: Use simsopt.solve.wireframe_optimization for optimizing wireframe geometries.
  8. Trace field lines and particles in magnetic fields

    master

    The simsopt.field.tracing submodule provides tools for tracing magnetic field lines and following particle motion. Most of these tools can be accessed directly from the simsopt.field module.

    Available tracing modes include:

    • Field line tracing
    • Full particle orbits (including gyromotion) in cylindrical coordinates.
    • Guiding center trajectories in cylindrical coordinates.
    • Guiding center motion in Boozer coordinates.

    For detailed examples, refer to the following files in the repository:

    • examples/1_Simple/tracing_fieldline.py
    • examples/1_Simple/tracing_particle.py
    • examples/2_Intermediate/tracing_boozer.py
  9. Explore the simsopt.util package submodules

    master

    The simsopt.util package provides a collection of utility modules for various tasks including constants, Fourier interpolation, logging, MPI support, and specialized physics helpers.

    Available submodules include:

    • simsopt.util.constants: Physical and mathematical constants.
    • simsopt.util.famus_helpers: Helper functions for FAMUS-related tasks.
    • simsopt.util.fourier_interpolation: Tools for Fourier interpolation.
    • simsopt.util.logger: Standard logging utilities.
    • simsopt.util.mpi: MPI (Message Passing Interface) utilities for parallel computing.
    • simsopt.util.mpi_logger: Specialized logging utilities designed for MPI environments.
    • simsopt.util.permanent_magnet_helper_functions: Functions for working with permanent magnets.
    • simsopt.util.polarization_project: Utilities related to the polarization project.
  10. Explore the Simsopt C++ API (Simsopt++)

    master
    The Simsopt C++ API (often referred to as simsoptpp) provides high-performance C++ implementations for core magnetic configuration and optimization tasks. It is organized into several functional modules including Biot-Savart calculations, Boozer coordinate transformations, caching mechanisms, geometry definitions (curves, coils, surfaces), magnetic field representations, and optimization routines. Developers looking to extend simsopt with custom C++ kernels or high-performance computing components should reference these specific modules.
  11. Ways to use simsopt

    master

    Simsopt is a flexible library that can be used in several distinct ways depending on your goal:

    • Stellarator Optimization: Solve complex optimization problems involving stellarators (similar to the STELLOPT workflow).
    • Custom Objective Functions: Define an objective function using simsopt objects, but use an external optimization library to solve it.
    • General Optimization: Use the simsopt optimization infrastructure to optimize any objects, even those not related to stellarators.
    • Physics Analysis & Plotting: Use stellarator-related objects in scripts for tasks like plotting code output variations or evaluating finite-difference gradients.
    • Interactive Manipulation: Manipulate objects interactively via the Python command line or within a Jupyter notebook.
  12. Optimize for quasisymmetry using Bmn objective (Boozer coordinates)

    master

    An alternative method for quasisymmetry optimization uses the Quasisymmetry class, which is based on symmetry-breaking Fourier mode amplitudes $B_{m,n}$ in Boozer coordinates. This requires a Boozer object.

    Workflow:

    1. Initialize Boozer(vmec) (you can specify mpol and ntor for the Boozer transformation resolution).
    2. Initialize Quasisymmetry(boozer, target_radius, helicity_m, helicity_n).
    3. The target_radius can be a single value or a list of values to target multiple surfaces.

    Example:

    boozer = Boozer(vmec, mpol=64, ntor=32)
    qs = Quasisymmetry(boozer, 0.5, 1, 0)
    # Configure quasisymmetry objective:
    boozer = Boozer(vmec)
    qs = Quasisymmetry(boozer,
                       0.5, # Radius to target
                       1, 0) # (M, N) you want in |B|