Simsopt C++ API

Biot Savart

Typedefs

typedef xt::pyarray<double> Array

Functions

void biot_savart(Array &points, vector<Array> &gammas, vector<Array> &dgamma_by_dphis, vector<Array> &B, vector<Array> &dB_by_dX, vector<Array> &d2B_by_dXdX)
Array biot_savart_B(Array &points, vector<Array> &gammas, vector<Array> &dgamma_by_dphis, vector<double> &currents)

Defines

MYIF(c)

Functions

template<class T, int derivs>
void biot_savart_kernel(AlignedPaddedVec &pointsx, AlignedPaddedVec &pointsy, AlignedPaddedVec &pointsz, T &gamma, T &dgamma_by_dphi, T &B, T &dB_by_dX, T &d2B_by_dXdX)
template<class T, int derivs>
void biot_savart_kernel_A(AlignedPaddedVec &pointsx, AlignedPaddedVec &pointsy, AlignedPaddedVec &pointsz, T &gamma, T &dgamma_by_dphi, T &A, T &dA_by_dX, T &d2A_by_dXdX)
namespace std

Functions

template<class T, int derivs>
void biot_savart_vjp_kernel(AlignedPaddedVec &pointsx, AlignedPaddedVec &pointsy, AlignedPaddedVec &pointsz, T &gamma, T &dgamma_by_dphi, T &v, T &res_gamma, T &res_dgamma_by_dphi, T &vgrad, T &res_grad_gamma, T &res_grad_dgamma_by_dphi)

Typedefs

typedef xt::pyarray<double> Array

Functions

void biot_savart_vjp(Array &points, vector<Array> &gammas, vector<Array> &dgamma_by_dphis, vector<double> &currents, Array &v, Array &vgrad, vector<Array> &dgamma_by_dcoeffs, vector<Array> &d2gamma_by_dphidcoeffs, vector<Array> &res_B, vector<Array> &res_dB)
void biot_savart_vjp_graph(Array &points, vector<Array> &gammas, vector<Array> &dgamma_by_dphis, vector<double> &currents, Array &v, vector<Array> &res_gamma, vector<Array> &res_dgamma_by_dphi, Array &vgrad, vector<Array> &res_grad_gamma, vector<Array> &res_grad_dgamma_by_dphi)
void biot_savart_vector_potential_vjp_graph(Array &points, vector<Array> &gammas, vector<Array> &dgamma_by_dphis, vector<double> &currents, Array &v, vector<Array> &res_gamma, vector<Array> &res_dgamma_by_dphi, Array &vgrad, vector<Array> &res_grad_gamma, vector<Array> &res_grad_dgamma_by_dphi)

Defines

MYIF(c)

Functions

template<class T, int derivs>
void biot_savart_vjp_kernel(AlignedPaddedVec &pointsx, AlignedPaddedVec &pointsy, AlignedPaddedVec &pointsz, T &gamma, T &dgamma_by_dphi, T &v, T &res_gamma, T &res_dgamma_by_dphi, T &vgrad, T &res_grad_gamma, T &res_grad_dgamma_by_dphi)
template<class T, int derivs>
void biot_savart_vector_potential_vjp_kernel(AlignedPaddedVec &pointsx, AlignedPaddedVec &pointsy, AlignedPaddedVec &pointsz, T &gamma, T &dgamma_by_dphi, T &v, T &res_gamma, T &res_dgamma_by_dphi, T &vgrad, T &res_grad_gamma, T &res_grad_dgamma_by_dphi)

Boozer classes

template<template<class, std::size_t, xt::layout_type> class T>
class BoozerMagneticField

Subclassed by InterpolatedBoozerField< T >, PyBoozerMagneticFieldTrampoline< BoozerMagneticFieldBase >

Public Types

using Tensor1 = T<double, 1, xt::layout_type::row_major>
using Tensor2 = T<double, 2, xt::layout_type::row_major>
using Tensor3 = T<double, 3, xt::layout_type::row_major>
using Tensor4 = T<double, 4, xt::layout_type::row_major>

Public Functions

inline BoozerMagneticField(double psi0)
inline virtual void invalidate_cache()
inline BoozerMagneticField &set_points(Tensor2 &p)
inline Tensor2 get_points()
inline Tensor2 &get_points_ref()
inline Tensor2 &K_ref()
inline Tensor2 &K_derivs_ref()
inline Tensor2 &dKdtheta_ref()
inline Tensor2 &dKdzeta_ref()
inline Tensor2 &nu_ref()
inline Tensor2 &dnudtheta_ref()
inline Tensor2 &dnudzeta_ref()
inline Tensor2 &dnuds_ref()
inline Tensor2 &nu_derivs_ref()
inline Tensor2 &R_ref()
inline Tensor2 &dRdtheta_ref()
inline Tensor2 &dRdzeta_ref()
inline Tensor2 &dRds_ref()
inline Tensor2 &R_derivs_ref()
inline Tensor2 &Z_ref()
inline Tensor2 &dZdtheta_ref()
inline Tensor2 &dZdzeta_ref()
inline Tensor2 &dZds_ref()
inline Tensor2 &Z_derivs_ref()
inline Tensor2 &modB_ref()
inline Tensor2 &dmodBdtheta_ref()
inline Tensor2 &dmodBdzeta_ref()
inline Tensor2 &dmodBds_ref()
inline Tensor2 &modB_derivs_ref()
inline Tensor2 &d2modBdtheta2_ref()
inline Tensor2 &d2modBdzeta2_ref()
inline Tensor2 &d2modBdthetadzeta_ref()
inline Tensor2 &I_ref()
inline Tensor2 &G_ref()
inline Tensor2 &psip_ref()
inline Tensor2 &iota_ref()
inline Tensor2 &dGds_ref()
inline Tensor2 &dIds_ref()
inline Tensor2 &diotads_ref()
inline Tensor2 K()
inline Tensor2 dKdtheta()
inline Tensor2 dKdzeta()
inline Tensor2 K_derivs()
inline Tensor2 nu()
inline Tensor2 dnudtheta()
inline Tensor2 dnudzeta()
inline Tensor2 dnuds()
inline Tensor2 nu_derivs()
inline Tensor2 R()
inline Tensor2 Z()
inline Tensor2 dRdtheta()
inline Tensor2 dZdtheta()
inline Tensor2 dRdzeta()
inline Tensor2 dZdzeta()
inline Tensor2 dRds()
inline Tensor2 dZds()
inline Tensor2 R_derivs()
inline Tensor2 Z_derivs()
inline Tensor2 modB()
inline Tensor2 dmodBdtheta()
inline Tensor2 dmodBdzeta()
inline Tensor2 dmodBds()
inline Tensor2 modB_derivs()
inline Tensor2 d2modBdtheta2()
inline Tensor2 d2modBdzeta2()
inline Tensor2 d2modBdthetadzeta()
inline Tensor2 G()
inline Tensor2 I()
inline Tensor2 psip()
inline Tensor2 iota()
inline Tensor2 dGds()
inline Tensor2 dIds()
inline Tensor2 diotads()

Public Members

double psi0

Protected Functions

inline virtual void _set_points_cb()
inline virtual void _K_impl(Tensor2 &K)
inline virtual void _dKdtheta_impl(Tensor2 &dKdtheta)
inline virtual void _dKdzeta_impl(Tensor2 &dKdzeta)
inline virtual void _K_derivs_impl(Tensor2 &K_derivs)
inline virtual void _nu_impl(Tensor2 &nu)
inline virtual void _dnudtheta_impl(Tensor2 &dnudtheta)
inline virtual void _dnudzeta_impl(Tensor2 &dnudzeta)
inline virtual void _dnuds_impl(Tensor2 &dnuds)
inline virtual void _nu_derivs_impl(Tensor2 &nu_derivs)
inline virtual void _R_impl(Tensor2 &R)
inline virtual void _Z_impl(Tensor2 &Z)
inline virtual void _dRdtheta_impl(Tensor2 &dRdtheta)
inline virtual void _dZdtheta_impl(Tensor2 &dZdtheta)
inline virtual void _dRdzeta_impl(Tensor2 &dRdzeta)
inline virtual void _dZdzeta_impl(Tensor2 &dZdzeta)
inline virtual void _dRds_impl(Tensor2 &dRds)
inline virtual void _dZds_impl(Tensor2 &dZds)
inline virtual void _R_derivs_impl(Tensor2 &R_derivs)
inline virtual void _Z_derivs_impl(Tensor2 &Z_derivs)
inline virtual void _modB_impl(Tensor2 &modB)
inline virtual void _d2modBdthetadzeta_impl(Tensor2 &d2modBdthetadzeta)
inline virtual void _d2modBdzeta2_impl(Tensor2 &d2modBdzeta2)
inline virtual void _d2modBdtheta2_impl(Tensor2 &d2modBdtheta2)
inline virtual void _dmodBdtheta_impl(Tensor2 &dmodBdtheta)
inline virtual void _dmodBdzeta_impl(Tensor2 &dmodBdzeta)
inline virtual void _dmodBds_impl(Tensor2 &dmodBds)
inline virtual void _modB_derivs_impl(Tensor2 &modB_derivs)
inline virtual void _I_impl(Tensor2 &I)
inline virtual void _G_impl(Tensor2 &G)
inline virtual void _dIds_impl(Tensor2 &dIds)
inline virtual void _dGds_impl(Tensor2 &dGds)
inline virtual void _psip_impl(Tensor2 &psip)
inline virtual void _iota_impl(Tensor2 &iota)
inline virtual void _diotads_impl(Tensor2 &diotads)
inline virtual void _set_points()

Protected Attributes

CachedTensor<T, 2> points
CachedTensor<T, 2> data_modB
CachedTensor<T, 2> data_dmodBdtheta
CachedTensor<T, 2> data_dmodBdzeta
CachedTensor<T, 2> data_dmodBds
CachedTensor<T, 2> data_modB_derivs
CachedTensor<T, 2> data_G
CachedTensor<T, 2> data_iota
CachedTensor<T, 2> data_dGds
CachedTensor<T, 2> data_diotads
CachedTensor<T, 2> data_psip
CachedTensor<T, 2> data_I
CachedTensor<T, 2> data_dIds
CachedTensor<T, 2> data_R
CachedTensor<T, 2> data_Z
CachedTensor<T, 2> data_nu
CachedTensor<T, 2> data_K
CachedTensor<T, 2> data_dRdtheta
CachedTensor<T, 2> data_dRdzeta
CachedTensor<T, 2> data_dRds
CachedTensor<T, 2> data_R_derivs
CachedTensor<T, 2> data_dZdtheta
CachedTensor<T, 2> data_dZdzeta
CachedTensor<T, 2> data_dZds
CachedTensor<T, 2> data_Z_derivs
CachedTensor<T, 2> data_dnudtheta
CachedTensor<T, 2> data_dnudzeta
CachedTensor<T, 2> data_dnuds
CachedTensor<T, 2> data_nu_derivs
CachedTensor<T, 2> data_dKdtheta
CachedTensor<T, 2> data_dKdzeta
CachedTensor<T, 2> data_K_derivs
CachedTensor<T, 2> data_d2modBdtheta2
CachedTensor<T, 2> data_d2modBdzeta2
CachedTensor<T, 2> data_d2modBdthetadzeta
int npoints
template<template<class, std::size_t, xt::layout_type> class T>
class InterpolatedBoozerField : public BoozerMagneticField<T>

Public Functions

inline InterpolatedBoozerField(shared_ptr<BoozerMagneticField<T>> field, InterpolationRule rule, RangeTriplet s_range, RangeTriplet theta_range, RangeTriplet zeta_range, bool extrapolate, int nfp, bool stellsym)
inline InterpolatedBoozerField(shared_ptr<BoozerMagneticField<T>> field, int degree, RangeTriplet s_range, RangeTriplet theta_range, RangeTriplet zeta_range, bool extrapolate, int nfp, bool stellsym)
inline std::pair<double, double> estimate_error_modB(int samples)
inline std::pair<double, double> estimate_error_K(int samples)
inline std::pair<double, double> estimate_error_R(int samples)
inline std::pair<double, double> estimate_error_Z(int samples)
inline std::pair<double, double> estimate_error_nu(int samples)
inline std::pair<double, double> estimate_error_G(int samples)
inline std::pair<double, double> estimate_error_I(int samples)
inline std::pair<double, double> estimate_error_iota(int samples)

Public Members

const shared_ptr<BoozerMagneticField<T>> field
const RangeTriplet s_range
const RangeTriplet theta_range
const RangeTriplet zeta_range
const RangeTriplet angle0_range = {0., M_PI, 1}
const InterpolationRule rule

Protected Functions

inline virtual void _psip_impl(Tensor2 &psip) override
inline virtual void _G_impl(Tensor2 &G) override
inline virtual void _I_impl(Tensor2 &I) override
inline virtual void _iota_impl(Tensor2 &iota) override
inline virtual void _dGds_impl(Tensor2 &dGds) override
inline virtual void _dIds_impl(Tensor2 &dIds) override
inline virtual void _diotads_impl(Tensor2 &diotads) override
inline virtual void _K_impl(Tensor2 &K) override
inline virtual void _dKdtheta_impl(Tensor2 &dKdtheta) override
inline virtual void _dKdzeta_impl(Tensor2 &dKdzeta) override
inline virtual void _K_derivs_impl(Tensor2 &K_derivs) override
inline virtual void _nu_impl(Tensor2 &nu) override
inline virtual void _dnudtheta_impl(Tensor2 &dnudtheta) override
inline virtual void _dnudzeta_impl(Tensor2 &dnudzeta) override
inline virtual void _dnuds_impl(Tensor2 &dnuds) override
inline virtual void _nu_derivs_impl(Tensor2 &nu_derivs) override
inline virtual void _R_impl(Tensor2 &R) override
inline virtual void _dRdtheta_impl(Tensor2 &dRdtheta) override
inline virtual void _dRdzeta_impl(Tensor2 &dRdzeta) override
inline virtual void _dRds_impl(Tensor2 &dRds) override
inline virtual void _R_derivs_impl(Tensor2 &R_derivs) override
inline virtual void _Z_impl(Tensor2 &Z) override
inline virtual void _dZdtheta_impl(Tensor2 &dZdtheta) override
inline virtual void _dZdzeta_impl(Tensor2 &dZdzeta) override
inline virtual void _dZds_impl(Tensor2 &dZds) override
inline virtual void _Z_derivs_impl(Tensor2 &Z_derivs) override
inline virtual void _modB_impl(Tensor2 &modB) override
inline virtual void _dmodBdtheta_impl(Tensor2 &dmodBdtheta) override
inline virtual void _dmodBdzeta_impl(Tensor2 &dmodBdzeta) override
inline virtual void _dmodBds_impl(Tensor2 &dmodBds) override
inline virtual void _modB_derivs_impl(Tensor2 &modB_derivs) override
inline virtual void _d2modBdtheta2_impl(Tensor2 &d2modBdtheta2) override
inline virtual void _d2modBdthetadzeta_impl(Tensor2 &d2modBdthetadzeta) override
inline virtual void _d2modBdzeta2_impl(Tensor2 &d2modBdzeta2) override
inline void exploit_fluxfunction_points(Tensor2 &stz, Tensor2 &stz0)
inline void exploit_symmetries_points(Tensor2 &stz, Tensor2 &stz_sym)
inline void apply_odd_symmetry(Tensor2 &field)
inline void apply_even_symmetry(Tensor2 &field)
inline Vec fbatch_scalar(Vec s, Vec theta, Vec zeta, string which_scalar)

Private Members

CachedTensor<T, 2> points_cyl_sym
shared_ptr<RegularGridInterpolant3D<Tensor2>> interp_modB
shared_ptr<RegularGridInterpolant3D<Tensor2>> interp_dmodBdtheta
shared_ptr<RegularGridInterpolant3D<Tensor2>> interp_dmodBdzeta
shared_ptr<RegularGridInterpolant3D<Tensor2>> interp_dmodBds
shared_ptr<RegularGridInterpolant3D<Tensor2>> interp_G
shared_ptr<RegularGridInterpolant3D<Tensor2>> interp_iota
shared_ptr<RegularGridInterpolant3D<Tensor2>> interp_dGds
shared_ptr<RegularGridInterpolant3D<Tensor2>> interp_I
shared_ptr<RegularGridInterpolant3D<Tensor2>> interp_dIds
shared_ptr<RegularGridInterpolant3D<Tensor2>> interp_diotads
shared_ptr<RegularGridInterpolant3D<Tensor2>> interp_psip
shared_ptr<RegularGridInterpolant3D<Tensor2>> interp_R
shared_ptr<RegularGridInterpolant3D<Tensor2>> interp_Z
shared_ptr<RegularGridInterpolant3D<Tensor2>> interp_nu
shared_ptr<RegularGridInterpolant3D<Tensor2>> interp_K
shared_ptr<RegularGridInterpolant3D<Tensor2>> interp_dRdtheta
shared_ptr<RegularGridInterpolant3D<Tensor2>> interp_dRdzeta
shared_ptr<RegularGridInterpolant3D<Tensor2>> interp_dRds
shared_ptr<RegularGridInterpolant3D<Tensor2>> interp_dZdtheta
shared_ptr<RegularGridInterpolant3D<Tensor2>> interp_dZdzeta
shared_ptr<RegularGridInterpolant3D<Tensor2>> interp_dZds
shared_ptr<RegularGridInterpolant3D<Tensor2>> interp_dnudtheta
shared_ptr<RegularGridInterpolant3D<Tensor2>> interp_dnudzeta
shared_ptr<RegularGridInterpolant3D<Tensor2>> interp_dnuds
shared_ptr<RegularGridInterpolant3D<Tensor2>> interp_dKdtheta
shared_ptr<RegularGridInterpolant3D<Tensor2>> interp_dKdzeta
shared_ptr<RegularGridInterpolant3D<Tensor2>> interp_K_derivs
shared_ptr<RegularGridInterpolant3D<Tensor2>> interp_nu_derivs
shared_ptr<RegularGridInterpolant3D<Tensor2>> interp_R_derivs
shared_ptr<RegularGridInterpolant3D<Tensor2>> interp_Z_derivs
shared_ptr<RegularGridInterpolant3D<Tensor2>> interp_modB_derivs
shared_ptr<RegularGridInterpolant3D<Tensor2>> interp_d2modBdtheta2
shared_ptr<RegularGridInterpolant3D<Tensor2>> interp_d2modBdzeta2
shared_ptr<RegularGridInterpolant3D<Tensor2>> interp_d2modBdthetadzeta
bool status_modB = false
bool status_dmodBdtheta = false
bool status_dmodBdzeta = false
bool status_dmodBds = false
bool status_G = false
bool status_I = false
bool status_iota = false
bool status_dGds = false
bool status_dIds = false
bool status_diotads = false
bool status_psip = false
bool status_R = false
bool status_Z = false
bool status_nu = false
bool status_K = false
bool status_dRdtheta = false
bool status_dRdzeta = false
bool status_dRds = false
bool status_dZdtheta = false
bool status_dZdzeta = false
bool status_dZds = false
bool status_dnudtheta = false
bool status_dnudzeta = false
bool status_dnuds = false
bool status_dKdtheta = false
bool status_dKdzeta = false
bool status_K_derivs = false
bool status_R_derivs = false
bool status_Z_derivs = false
bool status_nu_derivs = false
bool status_modB_derivs = false
bool status_d2modBdtheta2 = false
bool status_d2modBdthetadzeta = false
bool status_d2modBdzeta2 = false
const bool extrapolate
const bool stellsym = false
const int nfp = 1
vector<bool> symmetries = vector<bool>(1, false)

Typedefs

typedef xt::pyarray<double> Array

Functions

Array fourier_transform_odd(Array &K, Array &xm, Array &xn, Array &thetas, Array &zetas)
Array fourier_transform_even(Array &K, Array &xm, Array &xn, Array &thetas, Array &zetas)
void inverse_fourier_transform_odd(Array &K, Array &kmns, Array &xm, Array &xn, Array &thetas, Array &zetas)
void inverse_fourier_transform_even(Array &K, Array &kmns, Array &xm, Array &xn, Array &thetas, Array &zetas)
Array compute_kmns(Array &rmnc, Array &drmncds, Array &zmns, Array &dzmnsds, Array &numns, Array &dnumnsds, Array &bmnc, Array &iota, Array &G, Array &I, Array &xm, Array &xn, Array &thetas, Array &zetas)
Array compute_kmnc_kmns(Array &rmnc, Array &drmncds, Array &zmns, Array &dzmnsds, Array &numns, Array &dnumnsds, Array &bmnc, Array &rmns, Array &drmnsds, Array &zmnc, Array &dzmncds, Array &numnc, Array &dnumncds, Array &bmns, Array &iota, Array &G, Array &I, Array &xm, Array &xn, Array &thetas, Array &zetas)

Typedefs

typedef xt::pyarray<double> Array

Functions

double boozer_residual(double G, double iota, Array &xphi, Array &xtheta, Array &B, bool weight_inv_modB)
std::tuple<double, Array> boozer_residual_ds(double G, double iota, Array &B, Array &dB_dx, Array &xphi, Array &xtheta, Array &dx_ds, Array &dxphi_ds, Array &dxtheta_ds, bool weight_inv_modB)
std::tuple<double, Array, Array> boozer_residual_ds2(double G, double iota, Array &B, Array &dB_dx, Array &d2B_dx2, Array &xphi, Array &xtheta, Array &dx_ds, Array &dxphi_ds, Array &dxtheta_ds, bool weight_inv_modB)

Defines

MYIF(c)

Functions

template<class T, int deriv>
void boozer_residual_impl(double G, double iota, T &B, T &dB_dx, T &d2B_dx2, T &xphi, T &xtheta, T &dx_ds, T &dxphi_ds, T &dxtheta_ds, double &res, T &dres, T &d2res, size_t ndofs, bool weight_inv_modB)

Simsopt++ Caching Mechanism

template<class Array>
class Cache

Public Functions

inline bool get_status(string key) const
inline Array &get_or_create(string key, vector<int> dims)
inline Array &get_or_create_and_fill(string key, vector<int> dims, std::function<void(Array&)> impl)
inline void invalidate_cache()

Private Members

std::map<string, CachedArray<Array>> cache
template<class Array>
struct CachedArray

Public Functions

inline CachedArray(Array _data)

Public Members

Array data
bool status
template<template<class, std::size_t, xt::layout_type> class Tensor, std::size_t rank>
class CachedTensor

Public Types

using Shape = std::array<int, rank>

Public Functions

inline CachedTensor(const Shape &dims)
inline CachedTensor()
inline T &get_or_create(const Shape &new_dims)
inline bool get_status() const
inline T &get_or_create_and_fill(const Shape &new_dims, const std::function<void(T&)> &impl)
inline void invalidate_cache()

Private Types

using T = Tensor<double, rank, xt::layout_type::row_major>

Private Members

T data = {}
bool status
array<int, rank> dims

Curves and Coils

template<class Array>
class Coil

Public Functions

inline Coil(shared_ptr<Curve<Array>> curve, shared_ptr<CurrentBase<Array>> current)

Public Members

const shared_ptr<Curve<Array>> curve
const shared_ptr<CurrentBase<Array>> current
template<class Array>
class CurrentBase

Subclassed by Current< Array >, PyCurrentBaseTrampoline

Public Functions

virtual double get_value() = 0
inline virtual ~CurrentBase()
template<class Array>
class Current : public CurrentBase<Array>

Public Functions

inline Current(double value)
inline void set_dofs(Array &dofs)
inline Array get_dofs()
inline virtual double get_value() override

Private Members

double value

Functions

template<class Array>
Array curve_vjp_contraction(const Array &mat, const Array &v)
template<class Array>
class Curve

Subclassed by CurvePlanarFourier< Array >, CurveRZFourier< Array >, CurveXYZFourier< Array >, PyCurveTrampoline< CurveBase >

Public Functions

inline Curve(int _numquadpoints)
inline Curve(vector<double> _quadpoints)
inline Curve(Array _quadpoints)
inline void invalidate_cache()
inline virtual void set_dofs(const vector<double> &_dofs)
void least_squares_fit(Array &target_values)
virtual int num_dofs() = 0
virtual void set_dofs_impl(const vector<double> &_dofs) = 0
virtual vector<double> get_dofs() = 0
virtual void gamma_impl(Array &data, Array &quadpoints) = 0
inline virtual void gammadash_impl(Array &data)
inline virtual void gammadashdash_impl(Array &data)
inline virtual void gammadashdashdash_impl(Array &data)
inline virtual void dgamma_by_dcoeff_impl(Array &data)
inline virtual void dgammadash_by_dcoeff_impl(Array &data)
inline virtual void dgammadashdash_by_dcoeff_impl(Array &data)
inline virtual void dgammadashdashdash_by_dcoeff_impl(Array &data)
inline virtual void kappa_impl(Array &data)
inline virtual void dkappa_by_dcoeff_impl(Array &data)
inline virtual void torsion_impl(Array &data)
inline virtual void dtorsion_by_dcoeff_impl(Array &data)
void incremental_arclength_impl(Array &data)
void dincremental_arclength_by_dcoeff_impl(Array &data)
inline Array &gamma()
inline Array &gammadash()
inline Array &gammadashdash()
inline Array &gammadashdashdash()
inline virtual Array &dgamma_by_dcoeff()
inline virtual Array &dgammadash_by_dcoeff()
inline virtual Array &dgammadashdash_by_dcoeff()
inline virtual Array &dgammadashdashdash_by_dcoeff()
inline virtual Array dgamma_by_dcoeff_vjp_impl(Array &v)
inline virtual Array dgammadash_by_dcoeff_vjp_impl(Array &v)
inline virtual Array dgammadashdash_by_dcoeff_vjp_impl(Array &v)
inline virtual Array dgammadashdashdash_by_dcoeff_vjp_impl(Array &v)
inline Array &kappa()
inline Array &dkappa_by_dcoeff()
inline Array &torsion()
inline Array &dtorsion_by_dcoeff()
inline Array &incremental_arclength()
inline Array &dincremental_arclength_by_dcoeff()
virtual ~Curve() = default

Public Members

int numquadpoints
Array quadpoints

Protected Functions

inline Array &check_the_cache(string key, vector<int> dims, std::function<void(Array&)> impl)
inline Array &check_the_persistent_cache(string key, vector<int> dims, std::function<void(Array&)> impl)

Protected Attributes

std::unique_ptr<Eigen::FullPivHouseholderQR<Eigen::MatrixXd>> qr

Private Members

map<string, CachedArray<Array>> cache
map<string, CachedArray<Array>> cache_persistent
template<class Array>
class CurvePlanarFourier : public Curve<Array>

Public Functions

inline CurvePlanarFourier(int _numquadpoints, int _order)
inline CurvePlanarFourier(vector<double> _quadpoints, int _order)
inline CurvePlanarFourier(Array _quadpoints, int _order)
inline virtual int num_dofs() override
inline virtual void set_dofs_impl(const vector<double> &dofs) override
inline virtual vector<double> get_dofs() override
inline virtual Array &dgamma_by_dcoeff() override
inline virtual Array &dgammadash_by_dcoeff() override
inline virtual Array &dgammadashdash_by_dcoeff() override
inline virtual Array &dgammadashdashdash_by_dcoeff() override
virtual void gamma_impl(Array &data, Array &quadpoints) override
virtual void gammadash_impl(Array &data) override
virtual void gammadashdash_impl(Array &data) override
virtual void gammadashdashdash_impl(Array &data) override
virtual void dgamma_by_dcoeff_impl(Array &data) override
virtual void dgammadash_by_dcoeff_impl(Array &data) override
virtual void dgammadashdash_by_dcoeff_impl(Array &data) override
virtual void dgammadashdashdash_by_dcoeff_impl(Array &data) override

Public Members

const int order
Array rc
Array rs
Array q
Array center

Private Functions

double inv_magnitude()

Warning

doxygenfile: Cannot find file “curveprzfourier.h

template<class Array>
class CurveXYZFourier : public Curve<Array>

Public Functions

inline CurveXYZFourier(int _numquadpoints, int _order)
inline CurveXYZFourier(vector<double> _quadpoints, int _order)
inline CurveXYZFourier(Array _quadpoints, int _order)
inline virtual int num_dofs() override
inline virtual void set_dofs_impl(const vector<double> &_dofs) override
inline virtual vector<double> get_dofs() override
inline virtual Array &dgamma_by_dcoeff() override
inline virtual Array &dgammadash_by_dcoeff() override
inline virtual Array &dgammadashdash_by_dcoeff() override
inline virtual Array &dgammadashdashdash_by_dcoeff() override
virtual void gamma_impl(Array &data, Array &quadpoints) override
virtual void gammadash_impl(Array &data) override
virtual void gammadashdash_impl(Array &data) override
virtual void gammadashdashdash_impl(Array &data) override
virtual void dgamma_by_dcoeff_impl(Array &data) override
virtual void dgammadash_by_dcoeff_impl(Array &data) override
virtual void dgammadashdash_by_dcoeff_impl(Array &data) override
virtual void dgammadashdashdash_by_dcoeff_impl(Array &data) override

Public Members

vector<vector<double>> dofs
const int order

Fields

Typedefs

typedef xt::pyarray<double> Array

Functions

Array dipole_field_B(Array &points, Array &m_points, Array &m)
Array dipole_field_A(Array &points, Array &m_points, Array &m)
Array dipole_field_dB(Array &points, Array &m_points, Array &m)
Array dipole_field_dA(Array &points, Array &m_points, Array &m)
Array dipole_field_Bn(Array &points, Array &m_points, Array &unitnormal, int nfp, int stellsym, Array &b, std::string coordinate_flag = "cartesian", double R0 = 0.0)
Array define_a_uniform_cartesian_grid_between_two_toroidal_surfaces(Array &normal_inner, Array &normal_outer, Array &xyz_uniform, Array &xyz_inner, Array &xyz_outer)

Typedefs

typedef xt::pyarray<double> Array

Functions

Array DommaschkB(Array &mArray, Array &nArray, Array &coeffs, Array &points)
Array DommaschkdB(Array &mArray, Array &nArray, Array &coeffs, Array &points)

Typedefs

typedef xt::pyarray<double> PyArray

Functions

double integral_BdotN(PyArray &Bcoil, PyArray &Btarget, PyArray &n, std::string definition)

Compute quadratic flux and similar quantities.

This function is used in simsopt.objectives.SquaredFlux. See the documentation of that class for the definitions of the quantities computed here.

template<template<class, std::size_t, xt::layout_type> class T>
class MagneticField

Subclassed by BiotSavart< T, Array >, InterpolatedField< T >, PyMagneticFieldTrampoline< MagneticFieldBase >, WireframeField< T, Array, IntArray >

Public Types

using Tensor1 = T<double, 1, xt::layout_type::row_major>
using Tensor2 = T<double, 2, xt::layout_type::row_major>
using Tensor3 = T<double, 3, xt::layout_type::row_major>
using Tensor4 = T<double, 4, xt::layout_type::row_major>

Public Functions

inline MagneticField()
inline virtual void invalidate_cache()
inline MagneticField &set_points_cyl(Tensor2 &p)
inline MagneticField &set_points_cart(Tensor2 &p)
inline MagneticField &set_points(Tensor2 &p)
inline Tensor2 get_points_cyl()
inline Tensor2 &get_points_cyl_ref()
inline Tensor2 get_points_cart()
inline Tensor2 &get_points_cart_ref()
inline Tensor2 &B_ref()
inline Tensor3 &dB_by_dX_ref()
inline Tensor4 &d2B_by_dXdX_ref()
inline Tensor2 B()
inline Tensor3 dB_by_dX()
inline Tensor4 d2B_by_dXdX()
inline Tensor2 &A_ref()
inline Tensor3 &dA_by_dX_ref()
inline Tensor4 &d2A_by_dXdX_ref()
inline Tensor2 A()
inline Tensor3 dA_by_dX()
inline Tensor4 d2A_by_dXdX()
inline Tensor2 B_cyl()
inline Tensor2 &B_cyl_ref()
inline Tensor2 A_cyl()
inline Tensor2 &A_cyl_ref()
inline Tensor2 AbsB()
inline Tensor2 &AbsB_ref()
inline Tensor2 GradAbsB()
inline Tensor2 &GradAbsB_ref()
inline Tensor2 GradAbsB_cyl()
inline Tensor2 &GradAbsB_cyl_ref()

Protected Functions

inline void get_points_cyl_impl(Tensor2 &points_cyl)
inline void get_points_cart_impl(Tensor2 &points_cart)
inline virtual void _set_points_cb()
inline virtual void _AbsB_impl(Tensor2 &AbsB)
inline virtual void _GradAbsB_impl(Tensor2 &GradAbsB)
inline virtual void _B_cyl_impl(Tensor2 &B_cyl)
inline virtual void _A_cyl_impl(Tensor2 &A_cyl)
inline virtual void _GradAbsB_cyl_impl(Tensor2 &GradAbsB_cyl)
inline virtual void _B_impl(Tensor2 &B)
inline virtual void _dB_by_dX_impl(Tensor3 &dB_by_dX)
inline virtual void _d2B_by_dXdX_impl(Tensor4 &d2B_by_dXdX)
inline virtual void _A_impl(Tensor2 &A)
inline virtual void _dA_by_dX_impl(Tensor3 &dA_by_dX)
inline virtual void _d2A_by_dXdX_impl(Tensor4 &d2A_by_dXdX)

Protected Attributes

CachedTensor<T, 2> points_cart
CachedTensor<T, 2> points_cyl
CachedTensor<T, 2> data_B
CachedTensor<T, 2> data_A
CachedTensor<T, 2> data_GradAbsB
CachedTensor<T, 2> data_AbsB
CachedTensor<T, 2> data_Bcyl
CachedTensor<T, 2> data_Acyl
CachedTensor<T, 2> data_GradAbsBcyl
CachedTensor<T, 3> data_dB
CachedTensor<T, 3> data_dA
CachedTensor<T, 4> data_ddB
CachedTensor<T, 4> data_ddA
int npoints
template<template<class, std::size_t, xt::layout_type> class T, class Array>
class BiotSavart : public MagneticField<T>

Public Functions

inline BiotSavart(vector<shared_ptr<Coil<Array>>> coils)
void compute(int derivatives)
void compute_A(int derivatives)
inline virtual void invalidate_cache() override
inline Array &fieldcache_get_or_create(string key, vector<int> dims)
inline bool fieldcache_get_status(string key)

Public Members

const vector<shared_ptr<Coil<Array>>> coils

Protected Functions

inline virtual void _B_impl(Tensor2 &B) override
inline virtual void _dB_by_dX_impl(Tensor3 &dB_by_dX) override
inline virtual void _d2B_by_dXdX_impl(Tensor4 &d2B_by_dXdX) override
inline virtual void _A_impl(Tensor2 &A) override
inline virtual void _dA_by_dX_impl(Tensor3 &dA_by_dX) override
inline virtual void _d2A_by_dXdX_impl(Tensor4 &d2A_by_dXdX) override

Private Functions

inline void fill_points(const Tensor2 &points)

Private Members

Cache<Array> field_cache
AlignedPaddedVec pointsx
AlignedPaddedVec pointsy
AlignedPaddedVec pointsz
template<template<class, std::size_t, xt::layout_type> class T>
class InterpolatedField : public MagneticField<T>

Public Functions

inline InterpolatedField(shared_ptr<MagneticField<T>> field, InterpolationRule rule, RangeTriplet r_range, RangeTriplet phi_range, RangeTriplet z_range, bool extrapolate, int nfp, bool stellsym, std::function<std::vector<bool>(Vec, Vec, Vec)> skip)
inline InterpolatedField(shared_ptr<MagneticField<T>> field, int degree, RangeTriplet r_range, RangeTriplet phi_range, RangeTriplet z_range, bool extrapolate, int nfp, bool stellsym, std::function<std::vector<bool>(Vec, Vec, Vec)> skip)
inline std::pair<double, double> estimate_error_B(int samples)
inline std::pair<double, double> estimate_error_GradAbsB(int samples)

Public Members

const shared_ptr<MagneticField<T>> field
const RangeTriplet r_range
const RangeTriplet phi_range
const RangeTriplet z_range
const InterpolationRule rule

Protected Functions

inline virtual void _B_cyl_impl(Tensor2 &B_cyl) override
inline virtual void _GradAbsB_cyl_impl(Tensor2 &GradAbsB_cyl) override
inline virtual void _B_impl(Tensor2 &B) override
inline virtual void _GradAbsB_impl(Tensor2 &GradAbsB) override
inline void exploit_symmetries_points(Tensor2 &rphiz, Tensor2 &rphiz_sym)
inline void apply_symmetries_to_B_cyl(Tensor2 &field)
inline void apply_symmetries_to_GradAbsB_cyl(Tensor2 &field)

Private Members

CachedTensor<T, 2> points_cyl_sym
std::function<Vec(Vec, Vec, Vec)> fbatch_B
std::function<Vec(Vec, Vec, Vec)> fbatch_GradAbsB
std::function< std::vector< bool >Vec, Vec, Vec)> skip
shared_ptr<RegularGridInterpolant3D<Tensor2>> interp_B
shared_ptr<RegularGridInterpolant3D<Tensor2>> interp_GradAbsB
bool status_B = false
bool status_GradAbsB = false
const bool extrapolate
const bool stellsym = false
const int nfp = 1
vector<bool> symmetries = vector<bool>(1, false)
template<template<class, std::size_t, xt::layout_type> class T, class Array, class IntArray>
class WireframeField : public MagneticField<T>

Public Functions

inline WireframeField(vector<Array> _nodes, IntArray _segments, vector<double> _seg_signs, Array _currents)
void compute(int derivatives)
inline virtual void invalidate_cache() override
inline Array &fieldcache_get_or_create(string key, vector<int> dims)
inline bool fieldcache_get_status(string key)

Public Members

vector<Array> nodes
IntArray segments
vector<double> seg_signs
Array currents

Protected Functions

inline virtual void _B_impl(Tensor2 &B) override
inline virtual void _dB_by_dX_impl(Tensor3 &dB_by_dX) override

Private Functions

inline void fill_points(const Tensor2 &points)

Private Members

Cache<Array> field_cache
AlignedPaddedVec pointsx
AlignedPaddedVec pointsy
AlignedPaddedVec pointsz

Typedefs

typedef xt::pyarray<double> PyArray

Functions

double integral_BdotN(PyArray &Bcoil, PyArray &Btarget, PyArray &n, std::string definition)

Compute quadratic flux and similar quantities.

This function is used in simsopt.objectives.SquaredFlux. See the documentation of that class for the definitions of the quantities computed here.

Typedefs

typedef xt::pyarray<double> PyArray

Functions

double integral_BdotN(PyArray &Bcoil, PyArray &Btarget, PyArray &n, std::string definition)

Compute quadratic flux and similar quantities.

This function is used in simsopt.objectives.SquaredFlux. See the documentation of that class for the definitions of the quantities computed here.

Defines

MYIF(c)

Functions

template<class T, int derivs>
void wireframe_field_kernel(AlignedPaddedVec &pointsx, AlignedPaddedVec &pointsy, AlignedPaddedVec &pointsz, std::vector<double> &node0, std::vector<double> &node1, T &B, T &dB_by_dX, T &d2B_by_dXdX)

Surfaces

Functions

template<class Array>
Array surface_vjp_contraction(const Array &mat, const Array &v)
template<class Array>
class Surface

Subclassed by PySurfaceTrampoline< SurfaceBase >, SurfaceRZFourier< Array >, SurfaceXYZFourier< Array >, SurfaceXYZTensorFourier< Array >

Public Functions

inline Surface(vector<double> _quadpoints_phi, vector<double> _quadpoints_theta)
void least_squares_fit(Array &target_values)
void fit_to_curve(Curve<Array> &curve, double radius, bool flip_theta)
void scale(double scale)
void _extend_via_normal_for_nonuniform_phi(double distance)
void extend_via_projected_normal(double distance)
inline void invalidate_cache()
inline virtual void set_dofs(const vector<double> &_dofs)
virtual int num_dofs() = 0
virtual void set_dofs_impl(const vector<double> &_dofs) = 0
virtual vector<double> get_dofs() = 0
virtual void gamma_impl(Array &data, Array &quadpoints_phi, Array &quadpoints_theta) = 0
virtual void gamma_lin(Array &data, Array &quadpoints_phi, Array &quadpoints_theta) = 0
inline virtual void gammadash1_impl(Array &data)
inline virtual void gammadash2_impl(Array &data)
inline virtual void gammadash1dash1_impl(Array &data)
inline virtual void gammadash1dash2_impl(Array &data)
inline virtual void gammadash2dash2_impl(Array &data)
inline virtual void dgamma_by_dcoeff_impl(Array &data)
inline virtual void dgammadash1_by_dcoeff_impl(Array &data)
inline virtual void dgammadash2_by_dcoeff_impl(Array &data)
inline virtual void dgammadash2dash2_by_dcoeff_impl(Array &data)
inline virtual void dgammadash1dash2_by_dcoeff_impl(Array &data)
inline virtual void dgammadash1dash1_by_dcoeff_impl(Array &data)
inline virtual Array dgamma_by_dcoeff_vjp(Array &v)
inline virtual Array dgammadash1_by_dcoeff_vjp(Array &v)
inline virtual Array dgammadash2_by_dcoeff_vjp(Array &v)
void surface_curvatures_impl(Array &data)
void dsurface_curvatures_by_dcoeff_impl(Array &data)
void first_fund_form_impl(Array &data)
void dfirst_fund_form_by_dcoeff_impl(Array &data)
void second_fund_form_impl(Array &data)
void dsecond_fund_form_by_dcoeff_impl(Array &data)
void normal_impl(Array &data)
void dnormal_by_dcoeff_impl(Array &data)
void d2normal_by_dcoeffdcoeff_impl(Array &data)
Array dnormal_by_dcoeff_vjp(Array &v)
void unitnormal_impl(Array &data)
void dunitnormal_by_dcoeff_impl(Array &data)
double area()
void darea_by_dcoeff_impl(Array &data)
void d2area_by_dcoeffdcoeff_impl(Array &data)
double volume()
void dvolume_by_dcoeff_impl(Array &data)
void d2volume_by_dcoeffdcoeff_impl(Array &data)
inline Array &gamma()
inline Array &gammadash1()
inline Array &gammadash2()
inline Array &gammadash1dash1()
inline Array &gammadash1dash2()
inline Array &gammadash2dash2()
inline Array &dgammadash1dash1_by_dcoeff()
inline Array &dgammadash1dash2_by_dcoeff()
inline Array &dgammadash2dash2_by_dcoeff()
inline Array &surface_curvatures()
inline Array &dsurface_curvatures_by_dcoeff()
inline Array &first_fund_form()
inline Array &dfirst_fund_form_by_dcoeff()
inline Array &second_fund_form()
inline Array &dsecond_fund_form_by_dcoeff()
inline Array &dgamma_by_dcoeff()
inline Array &dgammadash1_by_dcoeff()
inline Array &dgammadash2_by_dcoeff()
inline Array &normal()
inline Array &dnormal_by_dcoeff()
inline Array &d2normal_by_dcoeffdcoeff()
inline Array &unitnormal()
inline Array &dunitnormal_by_dcoeff()
inline Array &darea_by_dcoeff()
inline Array &d2area_by_dcoeffdcoeff()
inline Array &dvolume_by_dcoeff()
inline Array &d2volume_by_dcoeffdcoeff()
virtual ~Surface() = default

Public Members

int numquadpoints_phi
int numquadpoints_theta
Array quadpoints_phi
Array quadpoints_theta

Private Functions

inline Array &check_the_cache(string key, vector<int> dims, std::function<void(Array&)> impl)
inline Array &check_the_persistent_cache(string key, vector<int> dims, std::function<void(Array&)> impl)

Private Members

map<string, CachedArray<Array>> cache
map<string, CachedArray<Array>> cache_persistent
std::unique_ptr<Eigen::FullPivHouseholderQR<Eigen::MatrixXd>> qr
template<class Array>
class SurfaceRZFourier : public Surface<Array>

Public Functions

inline SurfaceRZFourier(int _mpol, int _ntor, int _nfp, bool _stellsym, vector<double> _quadpoints_phi, vector<double> _quadpoints_theta)
inline void allocate()
inline virtual int num_dofs() override
inline virtual void set_dofs_impl(const vector<double> &dofs) override
inline virtual vector<double> get_dofs() override
virtual void gamma_impl(Array &data, Array &quadpoints_phi, Array &quadpoints_theta) override
virtual void gamma_lin(Array &data, Array &quadpoints_phi, Array &quadpoints_theta) override
virtual void gammadash1_impl(Array &data) override
virtual void gammadash2_impl(Array &data) override
virtual void gammadash1dash1_impl(Array &data) override
virtual void gammadash2dash2_impl(Array &data) override
virtual void gammadash1dash2_impl(Array &data) override
virtual void dgamma_by_dcoeff_impl(Array &data) override
virtual void dgammadash1_by_dcoeff_impl(Array &data) override
virtual void dgammadash2_by_dcoeff_impl(Array &data) override
virtual void dgammadash1dash1_by_dcoeff_impl(Array &data) override
virtual void dgammadash1dash2_by_dcoeff_impl(Array &data) override
virtual void dgammadash2dash2_by_dcoeff_impl(Array &data) override
virtual Array dgamma_by_dcoeff_vjp(Array &v) override
virtual Array dgammadash1_by_dcoeff_vjp(Array &v) override
virtual Array dgammadash2_by_dcoeff_vjp(Array &v) override

Public Members

Array rc
Array rs
Array zc
Array zs
int nfp
int mpol
int ntor
bool stellsym
template<class Array>
class SurfaceXYZFourier : public Surface<Array>

Public Functions

inline SurfaceXYZFourier(int _mpol, int _ntor, int _nfp, bool _stellsym, vector<double> _quadpoints_phi, vector<double> _quadpoints_theta)
inline virtual int num_dofs() override
inline virtual void set_dofs_impl(const vector<double> &dofs) override
inline virtual vector<double> get_dofs() override
inline double get_coeff(int dim, bool cos, int m, int i)
virtual void gamma_impl(Array &data, Array &quadpoints_phi, Array &quadpoints_theta) override
virtual void gamma_lin(Array &data, Array &quadpoints_phi, Array &quadpoints_theta) override
virtual void gammadash1_impl(Array &data) override
virtual void gammadash2_impl(Array &data) override
virtual void gammadash1dash1_impl(Array &data) override
virtual void gammadash1dash2_impl(Array &data) override
virtual void gammadash2dash2_impl(Array &data) override
virtual void dgamma_by_dcoeff_impl(Array &data) override
virtual void dgammadash1_by_dcoeff_impl(Array &data) override
virtual void dgammadash2_by_dcoeff_impl(Array &data) override
virtual void dgammadash1dash1_by_dcoeff_impl(Array &data) override
virtual void dgammadash1dash2_by_dcoeff_impl(Array &data) override
virtual void dgammadash2dash2_by_dcoeff_impl(Array &data) override

Public Members

Array xc
Array xs
Array yc
Array ys
Array zc
Array zs
int nfp
int mpol
int ntor
bool stellsym
template<class Array>
class SurfaceXYZTensorFourier : public Surface<Array>

Public Functions

inline SurfaceXYZTensorFourier(int _mpol, int _ntor, int _nfp, bool _stellsym, std::vector<bool> _clamped_dims, vector<double> _quadpoints_phi, vector<double> _quadpoints_theta)
inline virtual int num_dofs() override
inline virtual void set_dofs_impl(const vector<double> &dofs) override
inline virtual vector<double> get_dofs() override
inline virtual void gamma_impl(Array &data, Array &quadpoints_phi, Array &quadpoints_theta) override
inline virtual void gamma_lin(Array &data, Array &quadpoints_phi, Array &quadpoints_theta) override
inline virtual void gammadash1_impl(Array &data) override
inline virtual void gammadash2_impl(Array &data) override
inline virtual void gammadash2dash2_impl(Array &data) override
inline virtual void gammadash1dash2_impl(Array &data) override
inline virtual void gammadash1dash1_impl(Array &data) override
inline virtual void dgammadash1dash1_by_dcoeff_impl(Array &data) override
inline virtual void dgammadash1dash2_by_dcoeff_impl(Array &data) override
inline virtual void dgammadash2dash2_by_dcoeff_impl(Array &data) override
inline virtual void dgamma_by_dcoeff_impl(Array &data) override
inline virtual void dgammadash1_by_dcoeff_impl(Array &data) override
inline virtual void dgammadash2_by_dcoeff_impl(Array &data) override

Public Members

Array x
Array y
Array z
Array cache_basis_fun_phi
Array cache_basis_fun_phi_dash
Array cache_basis_fun_phi_dashdash
Array cache_basis_fun_theta
Array cache_basis_fun_theta_dash
Array cache_basis_fun_theta_dashdash
Array cache_enforcer
Array cache_enforcer_dphi
Array cache_enforcer_dtheta
Array cache_enforcer_dphidphi
Array cache_enforcer_dthetadtheta
int nfp
int mpol
int ntor
bool stellsym
std::vector<bool> clamped_dims

Private Functions

inline void build_cache()
inline bool apply_bc_enforcer(int dim, int n, int m)
inline double bc_enforcer_fun(int dim, int n, double phi, int m, double theta)
inline double bc_enforcer_dphi_fun(int dim, int n, double phi, int m, double theta)
inline double bc_enforcer_dphidphi_fun(int dim, int n, double phi, int m, double theta)
inline double bc_enforcer_dtheta_fun(int dim, int n, double phi, int m, double theta)
inline double bc_enforcer_dthetadtheta_fun(int dim, int n, double phi, int m, double theta)
inline double basis_fun(int dim, int n, int phiidx, int m, int thetaidx)
inline double basis_fun_dphi(int dim, int n, int phiidx, int m, int thetaidx)
inline double basis_fun_dphidphi(int dim, int n, int phiidx, int m, int thetaidx)
inline double basis_fun_dtheta(int dim, int n, int phiidx, int m, int thetaidx)
inline double basis_fun_dthetadphi(int dim, int n, int phiidx, int m, int thetaidx)
inline double basis_fun_dthetadtheta(int dim, int n, int phiidx, int m, int thetaidx)
inline double basis_fun(int dim, int n, double phi, int m, double theta)
inline double basis_fun_dphi(int dim, int n, double phi, int m, double theta)
inline double basis_fun_dtheta(int dim, int n, double phi, int m, double theta)
inline double basis_fun_dthetadtheta(int dim, int n, double phi, int m, double theta)
inline double basis_fun_dphidphi(int dim, int n, double phi, int m, double theta)
inline double basis_fun_dthetadphi(int dim, int n, double phi, int m, double theta)
inline double basis_fun_phi(int n, double phi)
inline double basis_fun_phi_dash(int n, double phi)
inline double basis_fun_phi_dashdash(int n, double phi)
inline double basis_fun_theta(int m, double theta)
inline double basis_fun_theta_dash(int m, double theta)
inline double basis_fun_theta_dashdash(int m, double theta)
inline bool skip(int dim, int m, int n)
inline double get_coeff(int dim, int m, int n)

Typedefs

typedef xt::pyarray<double> Array

Functions

Array ReimanB(double &iota0, double &iota1, Array &k_theta, Array &epsilon, int &m0_symmetry, Array &points)
Array ReimandB(double &iota0, double &iota1, Array &k_theta, Array &epsilon, int &m0_symmetry, Array &points)

Optimization

Typedefs

typedef xt::pyarray<double> Array

Functions

std::tuple<double, double, double> projection_L2_balls(double x1, double x2, double x3, double m_maxima)
std::tuple<double, double, double> phi_MwPGP(double x1, double x2, double x3, double g1, double g2, double g3, double m_maxima)
std::tuple<double, double, double> beta_tilde(double x1, double x2, double x3, double g1, double g2, double g3, double alpha, double m_maxima)
std::tuple<double, double, double> g_reduced_gradient(double x1, double x2, double x3, double g1, double g2, double g3, double alpha, double m_maxima)
std::tuple<double, double, double> g_reduced_projected_gradient(double x1, double x2, double x3, double g1, double g2, double g3, double alpha, double m_maxima)
double find_max_alphaf(double x1, double x2, double x3, double p1, double p2, double p3, double m_maxima)
void print_MwPGP(Array &A_obj, Array &b_obj, Array &x_k1, Array &m_proxy, Array &m_maxima, Array &m_history, Array &objective_history, Array &R2_history, int print_iter, int k, double nu, double reg_l0, double reg_l1, double reg_l2)
std::tuple<Array, Array, Array, Array> MwPGP_algorithm(Array &A_obj, Array &b_obj, Array &ATb, Array &m_proxy, Array &m0, Array &m_maxima, double alpha, double nu = 1.0e100, double epsilon = 1.0e-4, double reg_l0 = 0.0, double reg_l1 = 0.0, double reg_l2 = 0.0, int max_iter = 500, double min_fb = 1.0e-20, bool verbose = false)
std::tuple<Array, Array, Array, Array, Array> GPMO_backtracking(Array &A_obj, Array &b_obj, Array &mmax, Array &normal_norms, int K, bool verbose, int nhistory, int backtracking, Array &dipole_grid_xyz, int single_direction, int Nadjacent, int max_nMagnets)
std::tuple<Array, Array, Array, Array> GPMO_multi(Array &A_obj, Array &b_obj, Array &mmax, Array &normal_norms, int K, bool verbose, int nhistory, Array &dipole_grid_xyz, int single_direction, int Nadjacent)
std::tuple<Array, Array, Array, Array> GPMO_ArbVec(Array &A_obj, Array &b_obj, Array &mmax, Array &normal_norms, Array &pol_vectors, int K, bool verbose, int nhistory)
std::tuple<Array, Array, Array, Array, Array> GPMO_ArbVec_backtracking(Array &A_obj, Array &b_obj, Array &mmax, Array &normal_norms, Array &pol_vectors, int K, bool verbose, int nhistory, int backtracking, Array &dipole_grid_xyz, int Nadjacent, double thresh_angle, int max_nMagnets, Array &x_init)
std::tuple<Array, Array, Array, Array> GPMO_baseline(Array &A_obj, Array &b_obj, Array &mmax, Array &normal_norms, int K, bool verbose, int nhistory, int single_direction)
void print_GPMO(int k, int ngrid, int &print_iter, Array &x, double *Aij_mj_ptr, Array &objective_history, Array &Bn_history, Array &m_history, double mmax_sum, double *normal_norms_ptr)
Array connectivity_matrix(Array &dipole_grid_xyz, int Nadjacent)
void initialize_GPMO_ArbVec(Array &x_init, Array &pol_vectors, Array &x, vector<int> &x_vec, vector<int> &x_sign, Array &A_obj, Array &Aij_mj_sum, vector<double> &R2s, Array &Gamma_complement, int &num_nonzero)

Typedefs

typedef xt::pyarray<double> Array
typedef xt::pyarray<int> IntArray

Functions

std::tuple<Array, IntArray, IntArray, Array, IntArray, Array, Array, Array> GSCO(bool no_crossing, bool no_new_coils, bool match_current, Array &A_obj, Array &b_obj, double default_current, double max_current, int max_loop_count, IntArray &loops, IntArray &free_loops, IntArray &segments, IntArray &connections, double lambda_P, int max_iter, Array &x_init, IntArray &loop_count_init, int print_interval)
void record_iter(int iter, double curr, int loop_ind, double f_B, double f_S, double f, int *iter_hist_ptr, double *curr_hist_ptr, int *loop_hist_ptr, double *f_B_hist_ptr, double *f_S_hist_ptr, double *f_hist_ptr)
void print_iter(int iter, double f_B, double f_S, double f)
double compute_f_S(Array &x, double tol)
void check_eligibility(int nLoops, double default_current, double max_current, int max_loop_count, bool no_crossing, bool no_new_coils, bool match_current, double tol, int *loops_rep, int *freeLoops, int *loop_count, int *segments, int *connections, double *x, double *current)

Utilities

Typedefs

using Vec = std::vector<double>
using RangeTriplet = std::tuple<double, double, int>

Functions

Vec linspace(double min, double max, int n, bool endpoint)
class InterpolationRule

Subclassed by ChebyshevInterpolationRule, UniformInterpolationRule

Public Functions

inline InterpolationRule(int degree)
inline double basis_fun(int idx, double x) const

Public Members

Vec nodes
Vec scalings
const int degree

Protected Functions

inline void build_scalings()
template<class Array>
class RegularGridInterpolant3D

Public Functions

inline RegularGridInterpolant3D(InterpolationRule rule, RangeTriplet xrange, RangeTriplet yrange, RangeTriplet zrange, int value_size, bool out_of_bounds_ok, std::function<std::vector<bool>(Vec, Vec, Vec)> skip)
inline RegularGridInterpolant3D(InterpolationRule rule, RangeTriplet xrange, RangeTriplet yrange, RangeTriplet zrange, int value_size, bool out_of_bounds_ok)
void interpolate_batch(std::function<Vec(Vec, Vec, Vec)> &f)
Vec evaluate(double x, double y, double z)
void evaluate_batch(Array &xyz, Array &fxyz)
std::pair<double, double> estimate_error(std::function<Vec(Vec, Vec, Vec)> &f, int samples)

Private Functions

inline int idx_dof(int i, int j, int k)
inline int idx_cell(int i, int j, int k)
inline int idx_mesh(int i, int j, int k)
inline int idx_dof_local(int i, int j, int k)
int locate_unsafe(double x, double y, double z)
void evaluate_inplace(double x, double y, double z, double *res)
void evaluate_local(double x, double y, double z, int cell_idx, double *res)

Private Members

const int nx
const int ny
const int nz
double hx
double hy
double hz
const double xmin
const double ymin
const double zmin
const double xmax
const double ymax
const double zmax
const int value_size
const InterpolationRule rule
const bool out_of_bounds_ok
Vec xmesh
Vec ymesh
Vec zmesh
Vec xdof
Vec ydof
Vec zdof
Vec xdoftensor_reduced
Vec ydoftensor_reduced
Vec zdoftensor_reduced
Vec vals
std::unordered_map<int, AlignedPaddedVec> all_local_vals_map
std::vector<bool> skip_cell
std::vector<uint32_t> reduced_to_full_map
std::vector<uint32_t> full_to_reduced_map
uint32_t cells_to_skip
uint32_t cells_to_keep
uint32_t dofs_to_skip
uint32_t dofs_to_keep
int local_vals_size
Vec pkxs
Vec pkys
Vec pkzs
int padded_value_size

Private Static Attributes

static const int simdcount = 1
class UniformInterpolationRule : public InterpolationRule

Public Functions

inline UniformInterpolationRule(int degree)

Public Members

Vec nodes
Vec scalings
const int degree

Protected Functions

inline void build_scalings()
class ChebyshevInterpolationRule : public InterpolationRule

Public Functions

inline ChebyshevInterpolationRule(int degree)

Public Members

Vec nodes
Vec scalings
const int degree

Protected Functions

inline void build_scalings()

Defines

_USE_MATH_DEFINES
_EPS_

Functions

Vec linspace(double min, double max, int n, bool endpoint)

Typedefs

using AlignedPaddedVec = std::vector<double, AlignedPaddedAllocator<double>>

Functions

inline double rsqrt(const double &r2)
template<typename T, std::size_t ALIGNMENT_IN_BYTES = 32>
class AlignedPaddedAllocator
#include <simdhelpers.h>

Returns aligned pointers when allocations are requested. Default alignment is 64B = 512b, sufficient for AVX-512 and most cache line sizes.

Template Parameters:

ALIGNMENT_IN_BYTES – Must be a positive power of 2.

Public Types

using value_type = T

Public Functions

constexpr AlignedPaddedAllocator() noexcept = default
constexpr AlignedPaddedAllocator(const AlignedPaddedAllocator&) noexcept = default
template<typename U>
inline constexpr AlignedPaddedAllocator(AlignedPaddedAllocator<U, ALIGNMENT_IN_BYTES> const&) noexcept
inline T *allocate(std::size_t n)
inline void deallocate(T *ptr, [[maybe_unused]] std::size_t nBytesAllocated)

Public Static Attributes

static constexpr std::align_val_t ALIGNMENT = {ALIGNMENT_IN_BYTES}
template<class U>
struct rebind
#include <simdhelpers.h>

This is only necessary because AlignedAllocator has a second template argument for the alignment that will make the default std::allocator_traits implementation fail during compilation.

Public Types

using other = AlignedPaddedAllocator<U, ALIGNMENT_IN_BYTES>

Typedefs

typedef Eigen::Vector3d Vec3d

Functions

inline double inner(const Vec3d &a, const Vec3d &b)
inline Vec3d cross(const Vec3d &a, const Vec3d &b)
inline double norm(const Vec3d &a)
inline Vec3d cross(int i, Vec3d &b)
inline Vec3d cross(Vec3d &a, int i)
inline double inner(const Vec3dStd &a, const Vec3dStd &b)
inline double inner(const Vec3d &b, const Vec3dStd &a)
inline double inner(const Vec3dStd &a, const Vec3d &b)
inline double inner(int i, Vec3dStd &a)
inline Vec3dStd cross(Vec3dStd &a, Vec3dStd &b)
inline Vec3dStd cross(Vec3dStd &a, Vec3d &b)
inline Vec3dStd cross(Vec3d &a, Vec3dStd &b)
inline Vec3dStd cross(Vec3dStd &a, int i)
inline Vec3dStd cross(int i, Vec3dStd &b)
inline double normsq(Vec3dStd &a)

Variables

constexpr size_t ALIGN_BYTES = 32
struct Vec3dStd

Public Functions

inline Vec3dStd()
inline Vec3dStd(double x_, double y_, double z_)
inline Vec3dStd(Vec3d xyz)
inline Vec3dStd(double *xptr, double *yptr, double *zptr)
inline void store_aligned(double *xptr, double *yptr, double *zptr)
inline double &operator[](int i)
inline Vec3dStd &operator+=(const Vec3dStd &rhs)
inline Vec3dStd &operator-=(const Vec3dStd &rhs)
inline Vec3dStd &operator*=(const double &rhs)

Public Members

double x
double y
double z

Friends

inline friend Vec3dStd operator+(Vec3dStd lhs, const Vec3d &rhs)
inline friend Vec3dStd operator+(Vec3dStd lhs, const Vec3dStd &rhs)
inline friend Vec3dStd operator-(Vec3dStd lhs, const Vec3d &rhs)
inline friend Vec3dStd operator-(Vec3dStd lhs, const Vec3dStd &rhs)
inline friend Vec3dStd operator*(Vec3dStd lhs, const double &rhs)
inline friend Vec3dStd operator*(const double &lhs, Vec3dStd rhs)

Functions

double get_phi(double x, double y, double phi_near)
template<template<class, std::size_t, xt::layout_type> class T>
tuple<vector<array<double, 5>>, vector<array<double, 6>>> particle_guiding_center_boozer_tracing(shared_ptr<BoozerMagneticField<T>> field, array<double, 3> stz_init, double m, double q, double vtotal, double vtang, double tmax, double tol, bool vacuum, bool noK, vector<double> zetas, vector<shared_ptr<StoppingCriterion>> stopping_criteria)
template<template<class, std::size_t, xt::layout_type> class T>
tuple<vector<array<double, 5>>, vector<array<double, 6>>> particle_guiding_center_tracing(shared_ptr<MagneticField<T>> field, array<double, 3> xyz_init, double m, double q, double vtotal, double vtang, double tmax, double tol, bool vacuum, vector<double> phis, vector<shared_ptr<StoppingCriterion>> stopping_criteria)
template<template<class, std::size_t, xt::layout_type> class T>
tuple<vector<array<double, 7>>, vector<array<double, 8>>> particle_fullorbit_tracing(shared_ptr<MagneticField<T>> field, array<double, 3> xyz_init, array<double, 3> v_init, double m, double q, double tmax, double tol, vector<double> phis, vector<shared_ptr<StoppingCriterion>> stopping_criteria)
template<template<class, std::size_t, xt::layout_type> class T>
tuple<vector<array<double, 4>>, vector<array<double, 5>>> fieldline_tracing(shared_ptr<MagneticField<T>> field, array<double, 3> xyz_init, double tmax, double tol, vector<double> phis, vector<shared_ptr<StoppingCriterion>> stopping_criteria)
class StoppingCriterion

Subclassed by IterationStoppingCriterion, LevelsetStoppingCriterion< Array >, MaxRStoppingCriterion, MaxToroidalFluxStoppingCriterion, MaxZStoppingCriterion, MinRStoppingCriterion, MinToroidalFluxStoppingCriterion, MinZStoppingCriterion, ToroidalTransitStoppingCriterion

Public Functions

virtual bool operator()(int iter, double t, double x, double y, double z) = 0
inline virtual ~StoppingCriterion()
class ToroidalTransitStoppingCriterion : public StoppingCriterion

Public Functions

inline ToroidalTransitStoppingCriterion(double max_transits, bool flux)
inline virtual bool operator()(int iter, double t, double x, double y, double z) override

Private Members

double max_transits
double phi_last
double phi_init
bool flux
class MaxToroidalFluxStoppingCriterion : public StoppingCriterion

Public Functions

inline MaxToroidalFluxStoppingCriterion(double max_s)
inline virtual bool operator()(int iter, double t, double s, double theta, double zeta) override

Private Members

double max_s
class MinToroidalFluxStoppingCriterion : public StoppingCriterion

Public Functions

inline MinToroidalFluxStoppingCriterion(double min_s)
inline virtual bool operator()(int iter, double t, double s, double theta, double zeta) override

Private Members

double min_s
class MinZStoppingCriterion : public StoppingCriterion

Public Functions

inline MinZStoppingCriterion(double crit_z)
inline virtual bool operator()(int iter, double t, double x, double y, double z) override

Private Members

double crit_z
class MaxZStoppingCriterion : public StoppingCriterion

Public Functions

inline MaxZStoppingCriterion(double crit_z)
inline virtual bool operator()(int iter, double t, double x, double y, double z) override

Private Members

double crit_z
class MinRStoppingCriterion : public StoppingCriterion

Public Functions

inline MinRStoppingCriterion(double crit_r)
inline virtual bool operator()(int iter, double t, double x, double y, double z) override

Private Members

double crit_r
class MaxRStoppingCriterion : public StoppingCriterion

Public Functions

inline MaxRStoppingCriterion(double crit_r)
inline virtual bool operator()(int iter, double t, double x, double y, double z) override

Private Members

double crit_r
class IterationStoppingCriterion : public StoppingCriterion

Public Functions

inline IterationStoppingCriterion(int max_iter)
inline virtual bool operator()(int iter, double t, double x, double y, double z) override

Private Members

int max_iter
template<class Array>
class LevelsetStoppingCriterion : public StoppingCriterion

Public Functions

inline LevelsetStoppingCriterion(shared_ptr<RegularGridInterpolant3D<Array>> levelset)
inline virtual bool operator()(int iter, double t, double x, double y, double z) override

Private Members

shared_ptr<RegularGridInterpolant3D<Array>> levelset