Struct AxialSystem

Source
pub struct AxialSystem { /* private fields */ }
Expand description

Structure which defines a system of primitives with a shared symmetry axis.

This allows for large number of primitive shapes to be combined to generate a more complicated magentic field struture. The system is defined by an origin vector and a orientation vector. Currently only orientations along the x,y,z axes and placed at the origin of the global coordinate system are allowed.

individual primitives can be added to the AxialSystem and are stored in a HashMap with String based keys. These keys allow individual primitives to be accessed and modifies. Functions exist to modify individual physical parameters such as radius,length,thickness,position,current. The magnetic field is computed currently by working out the individual magentic field of each primitive individually. TO-DO: include rayon support for parallel compuation of the primitive magnetic fields.

Implementations§

Source§

impl AxialSystem

Source

pub fn new(origin: [f64; 3], orientation: [f64; 3]) -> AxialSystem

Returns a new AxialSystem

Currently only supports objects located at the origin with their orientation along any of the x,y,z directions and so internally calls the default method.

§Examples

Basic usage:

let axial = AxialSystem::new([0.0,0.0,0.0],[1.0,0.0,0.0]);
Source

pub fn default() -> AxialSystem

Returns the default AxialSystem

This has the shared symmetry axis located at the global origin (0,0,0) with its symmetry axis along the x axis (1,0,0).

§Examples

Basic usage:

let axial = AxialSystem::default();
Source§

impl AxialSystem

Source

pub fn add_loop( &mut self, id: String, radius: f64, origin: f64, current: f64, ) -> Result<(), AxialError>

Adds an instance of the ideal loop to the AxialSystem

Provide a unique identifer for the primitive as a String method checks if the identifier is allowed due to either clashing with a reserved word or due to a primitive already sharing the name.

§Examples

Basic usage:

let mut axial = AxialSystem::default();
let result = axial.add_loop("loop1".to_string(),1.0,0.0,1.0);
assert_eq!(result,Ok(()));
let result2 = axial.add_loop("loop1".to_string(),2.0,1.0,1.0);
assert_eq!(result2,Err(AxialError::KeyDuplicateError("loop1".to_string())));
let result3 = axial.add_loop("LOOP".to_string(),2.0,1.0,1.0);
assert_eq!(result3,Err(AxialError::ReservedWordError("LOOP".to_string())));
Source

pub fn add_annular( &mut self, id: String, radius: f64, thickness: f64, origin: f64, current: f64, ) -> Result<(), AxialError>

Adds an instance of the annular primitive to the AxialSystem

Provide a unique identifer for the primitive as a String method checks if the identifier is allowed due to either clashing with a reserved word or due to a primitive already sharing the name.

§Examples

Basic usage:

let mut axial = AxialSystem::default();
let result = axial.add_annular("annular1".to_string(),1.0,0.1,0.0,1.0);
assert_eq!(result,Ok(()));
let result2 = axial.add_annular("annular1".to_string(),2.0,0.1,1.0,1.0);
assert_eq!(result2,Err(AxialError::KeyDuplicateError("annular1".to_string())));
let result3 = axial.add_annular("ANNULAR".to_string(),2.0,0.1,1.0,1.0);
assert_eq!(result3,Err(AxialError::ReservedWordError("ANNULAR".to_string())));
Source

pub fn add_thin_solenoid( &mut self, id: String, radius: f64, length: f64, origin: f64, current: f64, ) -> Result<(), AxialError>

Adds an instance of the thin solenoid primitive to the AxialSystem

Provide a unique identifer for the primitive as a String method checks if the identifier is allowed due to either clashing with a reserved word or due to a primitive already sharing the name.

§Examples

Basic usage:

let mut axial = AxialSystem::default();
let result = axial.add_thin_solenoid("solenoid1".to_string(),1.0,10.0,0.0,1.0);
assert_eq!(result,Ok(()));
let result2 = axial.add_thin_solenoid("solenoid1".to_string(),2.0,0.1,1.0,1.0);
assert_eq!(result2,Err(AxialError::KeyDuplicateError("solenoid1".to_string())));
let result3 = axial.add_thin_solenoid("SOLENOID".to_string(),2.0,0.1,1.0,1.0);
assert_eq!(result3,Err(AxialError::ReservedWordError("SOLENOID".to_string())));
Source

pub fn add_coil_solenoid( &mut self, id: String, radius: f64, length: f64, thickness: f64, origin: f64, current: f64, ) -> Result<(), AxialError>

Adds an instance of the coil solenoid primitive to the AxialSystem

Provide a unique identifer for the primitive as a String method checks if the identifier is allowed due to either clashing with a reserved word or due to a primitive already sharing the name.

§Examples

Basic usage:

let mut axial = AxialSystem::default();
let result = axial.add_coil_solenoid("coil1".to_string(),1.0,10.0,0.1,0.0,1.0);
assert_eq!(result,Ok(()));
let result2 = axial.add_coil_solenoid("coil1".to_string(),2.0,10.0,0.1,1.0,1.0);
assert_eq!(result2,Err(AxialError::KeyDuplicateError("coil1".to_string())));
let result3 = axial.add_coil_solenoid("COIL".to_string(),2.0,10.0,0.1,1.0,1.0);
assert_eq!(result3,Err(AxialError::ReservedWordError("COIL".to_string())));
Source

pub fn remove(&mut self, id: &str) -> Result<(), AxialError>

Removes the primitive matching the provided id.

§Arguments
  • id - &str containing the ID to remove
§Examples
let mut axial = AxialSystem::default();

let result = axial.add_loop("loop1".to_string(),1.0,0.0,1.0);
let result_wrong_id = axial.remove("loop2");
assert_eq!(result_wrong_id,Err(AxialError::KeyMissingError("loop2".to_string())));
Source§

impl AxialSystem

Source

pub fn view(&self, id: &str) -> Result<String, AxialError>

Returns the display string of the primitive.

§Arguments
  • id - &str containing the ID to view
§Examples
let mut axial = AxialSystem::default();

let result = axial.add_loop("loop1".to_string(),1.0,0.0,1.0);
let result_wrong_id = axial.view("loop1");
Source§

impl AxialSystem

Source

pub fn transform_x(&mut self)

Transforms the symmetry axis to point along the x axis

i.e. converts the AxialSystems orientation to (1,0,0)

§Examples
let mut axial = AxialSystem::default();
axial.transform_x();
Source

pub fn transform_y(&mut self)

Transforms the symmetry axis to point along the y axis

i.e. converts the AxialSystems orientation to (0,1,0)

§Examples
let mut axial = AxialSystem::default();
axial.transform_y();
Source

pub fn transform_z(&mut self)

Transforms the symmetry axis to point along the z axis

i.e. converts the AxialSystems orientation to (0,0,1)

§Examples
let mut axial = AxialSystem::default();
axial.transform_z();
Source§

impl AxialSystem

Source

pub fn modify_radius(&mut self, id: &str, radius: f64) -> Result<(), AxialError>

Modifies the radius of a given primitive/ set of primitives

Can provide the ID of a single primitive or provide one of the possible reserved keywords to modify a set of primitives

*LOOP change radius of all loop primitives *ANNULAR change radius of all annular primitives *SOLENOID change radius of all solenoid primitives *COILS change radius of all coil primitives

§Arguments
  • id contains the ID of the primitive to modify
  • radius new radius of the primitive
§Examples
let mut axial = AxialSystem::default();
let res = axial.add_loop("loop1".to_string(),1.0,0.0,0.0);
let res = axial.modify_radius("loop1",2.0);
assert_eq!(res,Ok(()));
let res = axial.modify_radius("loop2",2.0);
assert_eq!(res,Err(AxialError::KeyMissingError("loop2".to_string())));
Source

pub fn modify_position( &mut self, id: &str, position: f64, ) -> Result<(), AxialError>

Modifies the position of a given primitive/set of primitives relative to the AxialSystem along the symmetry axis

Can provide the ID of a single primitive or provide one of the possible reserved keywords to modify a set of primitives

*LOOP change radius of all loop primitives *ANNULAR change radius of all annular primitives *SOLENOID change radius of all solenoid primitives *COILS change radius of all coil primitives

§Arguments
  • id contains the ID of the primitive to modify
  • position new position of the primitive
§Examples
let mut axial = AxialSystem::default();
let res = axial.add_loop("loop1".to_string(),1.0,0.0,0.0);
let res = axial.modify_position("loop1",1.0);
assert_eq!(res,Ok(()));
Source

pub fn modify_length(&mut self, id: &str, length: f64) -> Result<(), AxialError>

Modifies the length of a given primitive/set of primitives

Can provide the ID of a single primitive or provide one of the possible reserved keywords to modify a set of primitives If the provided ID belongs to a primitive that does not possess length as a parameter returns a AxialError::IncompatiblePrimitiveError

*LOOP change radius of all loop primitives *ANNULAR change radius of all annular primitives *SOLENOID change radius of all solenoid primitives *COILS change radius of all coil primitives

§Arguments
  • id contains the ID of the primitive to modify
  • length new position of the primitive
§Examples
let mut axial = AxialSystem::default();
let res = axial.add_thin_solenoid("solenoid1".to_string(),1.0,10.0,0.0,0.0);
let res = axial.modify_length("solenoid1",5.0);
assert_eq!(res,Ok(()));
let res = axial.add_loop("loop1".to_string(),1.0,0.0,0.0);
let res = axial.modify_length("loop1",5.0);
assert_eq!(res,Err(AxialError::IncompatiblePrimitiveError("loop1".to_string(),"LOOP".to_string())));
Source

pub fn modify_thickness( &mut self, id: &str, thickness: f64, ) -> Result<(), AxialError>

Modifies the thickness of a given primitive/set of primitives

Can provide the ID of a single primitive or provide one of the possible reserved keywords to modify a set of primitives If the provided ID belongs to a primitive that does not possess length as a parameter returns a AxialError::IncompatiblePrimitiveError

*LOOP change radius of all loop primitives *ANNULAR change radius of all annular primitives *SOLENOID change radius of all solenoid primitives *COILS change radius of all coil primitives

§Arguments
  • id contains the ID of the primitive to modify
  • thickness new position of the primitive
§Examples
let mut axial = AxialSystem::default();
let res = axial.add_annular("annular1".to_string(),1.0,1.0,0.0,0.0);
let res = axial.modify_thickness("annular1",5.0);
assert_eq!(res,Ok(()));
let res = axial.add_loop("loop1".to_string(),1.0,0.0,0.0);
let res = axial.modify_thickness("loop1",5.0);
assert_eq!(res,Err(AxialError::IncompatiblePrimitiveError("loop1".to_string(),"LOOP".to_string())));
Source

pub fn modify_current( &mut self, id: &str, current: f64, ) -> Result<(), AxialError>

Modifies the current of a given primitive/set of primitives

Can provide the ID of a single primitive or provide one of the possible reserved keywords to modify a set of primitives

*LOOP change radius of all loop primitives *ANNULAR change radius of all annular primitives *SOLENOID change radius of all solenoid primitives *COILS change radius of all coil primitives

§Arguments
  • id contains the ID of the primitive to modify
  • thickness new position of the primitive
§Examples
let mut axial = AxialSystem::default();
let res = axial.add_annular("annular1".to_string(),1.0,1.0,0.0,0.0);
let res = axial.modify_current("annular1",5.0);
assert_eq!(res,Ok(()));
Source§

impl AxialSystem

Source

pub fn get_field(&self, pos: [f64; 3], tol: &f64) -> [f64; 3]

Computes the magnetic field of the axial system

Takes the position coordinates of the location for which the magentic field is desired. These coordinates are in the global space and not relative to the axial system.

§Arguments
  • (x,y,z) tuple containing the x,y,z coordinates.
  • tol the tolerance at which the series expansion shuold terminate.
§Examples
let mut axial = AxialSystem::default();
let res = axial.add_loop("loop1".to_string(),1.0,0.0,1.0);
let magnetic_field = axial.get_field([0.0,0.0,0.0],&1e-16);
Source

pub fn get_field_axial(&self, position: &[f64; 2], tol: &f64) -> [f64; 2]

Computes the magnetic field of the axial system in relative frame

Takes the position coordinates of the location for which the magentic field is desired. These coordinates are in the global space and not relative to the axial system.

§Arguments
  • z axial position relative to AxialSystem
  • r radial position relative to AxialSystem
  • tol the tolerance at which the series expansion shuold terminate.
§Examples
let mut axial = AxialSystem::default();
let res = axial.add_loop("loop1".to_string(),1.0,0.0,1.0);
let magnetic_field = axial.get_field_axial(&[2.0,0.1],&1e-16);

Trait Implementations§

Source§

impl Clone for AxialSystem

Source§

fn clone(&self) -> AxialSystem

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AxialSystem

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for AxialSystem

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for AxialSystem

Source§

fn eq(&self, other: &AxialSystem) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for AxialSystem

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.