golenoid

package
v0.0.0-...-8078776 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2023 License: MIT Imports: 4 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateFieldFromLoopCartesian

func CalculateFieldFromLoopCartesian(current, a, x, y, z float64) (Bx, By, Bz float64)

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

func CalculateFieldFromLoopPolar(current, a, r, z float64) (Br, Bphi, Bz float64)

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

func CartesianToPolarCoords(x, y, z float64) (float64, float64, float64)

CartesianToPolarCoords converts cartesian coordinates to cylindrical polar coordinates.

func CartesianToPolarField

func CartesianToPolarField(Bx, By, Bz, phi float64) (float64, float64, float64)

CartesianToPolarField converts cartesian magnetic field components to cylindrical polar magnetic field components.

func DegreesToRadians

func DegreesToRadians(degrees float64) float64

DegreesToRadians converts degrees to radians.

func PolarToCartesianCoords

func PolarToCartesianCoords(r, phi, z float64) (float64, float64, float64)

PolarToCartesianCoords converts cylindrical polar coordinates to cartesian coordinates.

func PolarToCartesianField

func PolarToCartesianField(Br, Bphi, Bz, phi float64) (float64, float64, float64)

PolarToCartesianField converts cylindrical polar magnetic field components to cartesian magnetic field components.

func RadiansToDegrees

func RadiansToDegrees(radians float64) float64

RadiansToDegrees converts radians to degrees.

Types

type CartesianPoint

type CartesianPoint struct {
	X  float64
	Y  float64
	Z  float64
	Bx float64
	By float64
	Bz float64
}

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 NewField

func NewField(n int) *Field

NewField creates a new Field with n FieldPoints.

func NewFieldGridPolar

func NewFieldGridPolar(rMin, rMax, phiMin, phiMax, zMin, zMax float64, nr, nphi, nz int) *Field

TODO @JoeLanglands figure out a better api to create fields from grids.

func (*Field) WriteToFile

func (f *Field) WriteToFile() error

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

type PolarPoint struct {
	R    float64
	Phi  float64
	Z    float64
	Br   float64
	Bphi float64
	Bz   float64
}

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

func NewSolenoid(rInner, rOuter, length, current, centre float64, nTurns, nLayers int) *Solenoid

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

func (*Solenoid) CalculateFieldWithWorkers

func (s *Solenoid) CalculateFieldWithWorkers(rMin, rMax, phiMin, phiMax, zMin, zMax float64, nr, nphi, nz, numWorkers int) *Field

func (*Solenoid) CalculateFullField

func (s *Solenoid) CalculateFullField(field *Field)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL