Documentation
¶
Overview ¶
Package golenoid is a package for calculating the magnetic field of a solenoid.
Currently the package is focused on solenoids comprised of tightly wound coils such as those used in particle accelerators or MRI machines. This is due to the mathematics relying on simplified expressions that assume the cross-section of the conductor is negligible.
Calculations are performed assuming that the magnetic axis of the solenoid is collinear with the z-axis of the coordinate system, and infact the z-axis runs through the exact centre of the coil.
Although assumptions are made, the expressions used to calculate the magnetic field are valid in all space outside the conductor and are exact solutions that satisfy Maxwell's equations.
All units must be in SI units! (metres, amperes, teslas, etc.)
The mathematics behind the computations are described in the following paper: https://ntrs.nasa.gov/citations/20140002333
Future support for rotated solenoids and various transformations is planned.
Index ¶
- func CalculateFieldFromLoopCartesian(current, a, x, y, z float64) (Bx, By, Bz float64)
- func CalculateFieldFromLoopPolar(current, a, r, z float64) (Br, Bphi, Bz float64)
- func CartesianToPolarCoords(x, y, z float64) (float64, float64, float64)
- func CartesianToPolarField(Bx, By, Bz, phi float64) (float64, float64, float64)
- func DegreesToRadians(degrees float64) float64
- func PolarToCartesianCoords(r, phi, z float64) (float64, float64, float64)
- func PolarToCartesianField(Br, Bphi, Bz, phi float64) (float64, float64, float64)
- func RadiansToDegrees(radians float64) float64
- type CartesianPoint
- func (p *CartesianPoint) GetCartesianCoordinates() (x, y, z float64)
- func (p *CartesianPoint) GetCartesianField() (Bx, By, Bz float64)
- func (p *CartesianPoint) GetPolarCoordinates() (r, phi, z float64)
- func (p *CartesianPoint) GetPolarField() (Br, Bphi, Bz float64)
- func (p *CartesianPoint) Magnitude() float64
- func (p *CartesianPoint) SetFieldCartesian(Bx, By, Bz float64)
- func (p *CartesianPoint) SetFieldPolar(Br, Bphi, Bz float64)
- func (p *CartesianPoint) String() string
- type Field
- type FieldPoint
- type PolarPoint
- func (p *PolarPoint) GetCartesianCoordinates() (x, y, z float64)
- func (p *PolarPoint) GetCartesianField() (Bx, By, Bz float64)
- func (p *PolarPoint) GetPolarCoordinates() (r, phi, z float64)
- func (p *PolarPoint) GetPolarField() (Br, Bphi, Bz float64)
- func (p *PolarPoint) Magnitude() float64
- func (p *PolarPoint) SetFieldCartesian(Bx, By, Bz float64)
- func (p *PolarPoint) SetFieldPolar(Br, Bphi, Bz float64)
- func (p *PolarPoint) String() string
- type Solenoid
- func (s *Solenoid) CalculateFieldAtPoint(fp FieldPoint) (Bi, Bj, Bk float64)
- func (s *Solenoid) CalculateFieldAtPointSeq(fp FieldPoint) (Bi, Bj, Bk float64)
- func (s *Solenoid) CalculateFieldPoint(fp FieldPoint) FieldPoint
- func (s *Solenoid) CalculateFieldWithWorkers(rMin, rMax, phiMin, phiMax, zMin, zMax float64, nr, nphi, nz, numWorkers int) *Field
- func (s *Solenoid) CalculateFullField(field *Field)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalculateFieldFromLoopCartesian ¶
CalculateFieldFromLoopCartesian calculates the cartesian components of the magnetic field at point (x,y,z) induced from a current loop.
The coordinate (0,0,0) lies at the very centre of the current loop. The input variables are:
- current: the current in the loop in amperes
- a: the radius of the current loop in metres
- x: the x coordinate of the point in metres
- y: the y coordinate of the point in metres
- z: the z coordinate of the point in metres
func CalculateFieldFromLoopPolar ¶
CalculateFieldFromLoopPolar calculates the polar components of the magnetic field at point (r,phi,z) induced from a current loop.
The coordinate (0, 0, 0) lies at the very centre of the current loop. In a cylindrically symmetric solenoid, the magnetic field is only a function of r and z and Bphi = 0. The input variables are:
- current: the current in the loop in amperes
- a: the radius of the current loop in metres
- r: the r coordinate of the point in metres
- z: the z coordinate of the point in metres
func CartesianToPolarCoords ¶
CartesianToPolarCoords converts cartesian coordinates to cylindrical polar coordinates.
func CartesianToPolarField ¶
CartesianToPolarField converts cartesian magnetic field components to cylindrical polar magnetic field components.
func DegreesToRadians ¶
DegreesToRadians converts degrees to radians.
func PolarToCartesianCoords ¶
PolarToCartesianCoords converts cylindrical polar coordinates to cartesian coordinates.
func PolarToCartesianField ¶
PolarToCartesianField converts cylindrical polar magnetic field components to cartesian magnetic field components.
func RadiansToDegrees ¶
RadiansToDegrees converts radians to degrees.
Types ¶
type CartesianPoint ¶
CartesianPoint is a point in 3D space with a position and a magnetic field in cartesian coordinates (x,y,z)
func NewCartesianPoint ¶
func NewCartesianPoint(x, y, z float64) *CartesianPoint
NewCartesianPoint creates a new CartesianPoint from the given coordinates (x,y,z).
func (*CartesianPoint) GetCartesianCoordinates ¶
func (p *CartesianPoint) GetCartesianCoordinates() (x, y, z float64)
func (*CartesianPoint) GetCartesianField ¶
func (p *CartesianPoint) GetCartesianField() (Bx, By, Bz float64)
func (*CartesianPoint) GetPolarCoordinates ¶
func (p *CartesianPoint) GetPolarCoordinates() (r, phi, z float64)
func (*CartesianPoint) GetPolarField ¶
func (p *CartesianPoint) GetPolarField() (Br, Bphi, Bz float64)
func (*CartesianPoint) Magnitude ¶
func (p *CartesianPoint) Magnitude() float64
func (*CartesianPoint) SetFieldCartesian ¶
func (p *CartesianPoint) SetFieldCartesian(Bx, By, Bz float64)
func (*CartesianPoint) SetFieldPolar ¶
func (p *CartesianPoint) SetFieldPolar(Br, Bphi, Bz float64)
func (*CartesianPoint) String ¶
func (p *CartesianPoint) String() string
type Field ¶
type Field struct {
Points []FieldPoint
}
Field represents a magnetic field as a slice of FieldPoints.
func NewFieldGridPolar ¶
TODO @JoeLanglands figure out a better api to create fields from grids.
func (*Field) WriteToFile ¶
type FieldPoint ¶
type FieldPoint interface {
// GetPolarCoordinates returns the polar coordinates of the point.
GetPolarCoordinates() (r, phi, z float64)
// GetPolarField returns the magnetic field in polar coordinates.
GetPolarField() (Br, Bphi, Bz float64)
// GetCartesianCoordinates returns the cartesian coordinates of the point.
GetCartesianCoordinates() (x, y, z float64)
// GetCartesianField returns the magnetic field in cartesian coordinates.
GetCartesianField() (Bx, By, Bz float64)
// SetFieldPolar sets the magnetic field from polar components.
SetFieldPolar(Br, Bphi, Bz float64)
// SetFieldCartesian sets the magnetic field from cartesian components.
SetFieldCartesian(Bx, By, Bz float64)
// Magnitude returns the magnitude of the magnetic field at this point.
Magnitude() float64
}
FieldPoint is an interface for a point in 3D space with a position and a magnetic field.
type PolarPoint ¶
PolarPoint is a point in 3D space with a position and a magnetic field in cylindrical polar coordinates (r,phi,z)
func NewPolarPoint ¶
func NewPolarPoint(r, phi, z float64) *PolarPoint
NewPolarPoint creates a new PolarPoint from the given coordinates (r,phi,z).
func (*PolarPoint) GetCartesianCoordinates ¶
func (p *PolarPoint) GetCartesianCoordinates() (x, y, z float64)
func (*PolarPoint) GetCartesianField ¶
func (p *PolarPoint) GetCartesianField() (Bx, By, Bz float64)
func (*PolarPoint) GetPolarCoordinates ¶
func (p *PolarPoint) GetPolarCoordinates() (r, phi, z float64)
func (*PolarPoint) GetPolarField ¶
func (p *PolarPoint) GetPolarField() (Br, Bphi, Bz float64)
func (*PolarPoint) Magnitude ¶
func (p *PolarPoint) Magnitude() float64
func (*PolarPoint) SetFieldCartesian ¶
func (p *PolarPoint) SetFieldCartesian(Bx, By, Bz float64)
func (*PolarPoint) SetFieldPolar ¶
func (p *PolarPoint) SetFieldPolar(Br, Bphi, Bz float64)
func (*PolarPoint) String ¶
func (p *PolarPoint) String() string
type Solenoid ¶
type Solenoid struct {
Rinner float64 // Inner radius of solenoid
Router float64 // Outer radius of solenoid
Length float64 // Length of solenoid
Current float64 // Current in solenoid (in Amperes)
Nturns int // Number of turns per layer in solenoid layer
Nlayers int // Number of layers in solenoid
CentrePos float64 // Position of centre of solenoid along z-axis
}
Solenoid represents a tightly wound solenoid
func NewSolenoid ¶
NewSolenoid creates a new Solenoid with the given parameters.
func (*Solenoid) CalculateFieldAtPoint ¶
func (s *Solenoid) CalculateFieldAtPoint(fp FieldPoint) (Bi, Bj, Bk float64)
CalculateFieldAtPoint calculates the magnetic field at the point fp induced by the solenoid.
func (*Solenoid) CalculateFieldAtPointSeq ¶
func (s *Solenoid) CalculateFieldAtPointSeq(fp FieldPoint) (Bi, Bj, Bk float64)
func (*Solenoid) CalculateFieldPoint ¶
func (s *Solenoid) CalculateFieldPoint(fp FieldPoint) FieldPoint