SHARE
TWEET

Untitled

a guest Mar 18th, 2019 44 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use nalgebra::{Point3, Vector3};
  2. use nalgebra::{
  3.     Point3,
  4. };
  5. use natural_constants::physics::magnetic_const_vac as u0;
  6.  
  7. use std::f64::consts::PI;
  8.  
  9. use crate::wire::{
  10.     Wire
  11. };
  12.  
  13. pub struct BiotSavartSolver {
  14.     wires: Vec<Wire>
  15. }
  16.  
  17. impl BiotSavartSolver {
  18.     pub fn new() -> Self {
  19.         Self {
  20.             wires: vec![],
  21.         }
  22.     }
  23.  
  24.     pub fn from_wires(wires: Vec<Wire>) -> Self {
  25.         Self {
  26.             wires
  27.         }
  28.     }
  29.  
  30.     pub fn calculate_b(&self, points: Vec<Point3<f64>>, current: f64) -> Vec<f64> {
  31.         let mut c = 0;
  32.  
  33.         points
  34.             .iter()
  35.             .map(|point| {
  36.                 self.calculate_b_at(point, current)
  37.             })
  38.             .collect::<_>()
  39.     }
  40.  
  41.     fn calculate_b_at(&self, position: &Point3<f64>, current: f64) -> f64 {
  42.         let integral = self.wires
  43.             .iter()
  44.             .flat_map(|segment| {
  45.                 let r = position - segment.position;
  46.                 let c = segment.direction.cross(&r);
  47.             })
  48.             .sum();
  49.         u0 / (4.0 * PI) * current * integral
  50.     }
  51. }
  52.  
  53. pub struct Wire {
  54.     pub segments: Vec<WireSegment>,
  55. }
  56.  
  57. pub struct WireIterator<'w> {
  58.     iter: &'w std::slice::Iter<'w, WireSegment>,
  59. }
  60.  
  61. impl<'w> Iterator for WireIterator<'w> {
  62.     type Item = &'w WireSegment;
  63.    
  64.     fn next(&mut self) -> Option<Self::Item> {
  65.         self.iter.next()
  66.     }
  67. }
  68.  
  69. impl<'w> IntoIterator for Wire {
  70.     type Item = &'w WireSegment;
  71.     type IntoIter = WireIterator<'w>;
  72.  
  73.     fn into_iter(self) -> Self::IntoIter {
  74.         WireIterator { iter: &self.segments }
  75.     }
  76. }
  77.  
  78. pub struct WireSegment {
  79.     pub position: Point3<f64>,
  80.     pub direction: Vector3<f64>,
  81. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top