extern crate nalgebra;
extern crate specs;
use crate::constant::PI;
use crate::integrator::{Step, Timestep};
use crate::magnetic::MagneticFieldSampler;
use crate::ramp::Lerp;
use nalgebra::Vector3;
use specs::{Component, HashMapStorage, Join, ReadExpect, ReadStorage, System, WriteStorage};
#[derive(Clone, Lerp)]
pub struct TimeOrbitingPotential {
pub amplitude: f64,
pub frequency: f64,
}
impl TimeOrbitingPotential {
pub fn gauss(amplitude: f64, frequency: f64) -> Self {
Self {
amplitude: amplitude * 1e-4,
frequency,
}
}
}
impl Component for TimeOrbitingPotential {
type Storage = HashMapStorage<Self>;
}
pub struct TimeOrbitingPotentialSystem;
impl<'a> System<'a> for TimeOrbitingPotentialSystem {
type SystemData = (
WriteStorage<'a, MagneticFieldSampler>,
ReadStorage<'a, TimeOrbitingPotential>,
ReadExpect<'a, Timestep>,
ReadExpect<'a, Step>,
);
fn run(&mut self, (mut samplers, tops, timestep, step): Self::SystemData) {
use rayon::prelude::*;
use specs::ParJoin;
for top in (&tops).join() {
(&mut samplers).par_join().for_each(|sampler| {
let time = timestep.delta * step.n as f64;
let top_field = top.amplitude
* Vector3::new(
(2.0 * PI * top.frequency * time).cos(),
(2.0 * PI * top.frequency * time).sin(),
0.0,
);
sampler.field += top_field;
});
}
}
}