CurlStimulus: take axis and center directly from the Region

by taking more from the region, we'll be able to reuse common code
and also make this more testable
This commit is contained in:
2022-08-09 22:10:16 -07:00
parent 7d1ee0ad50
commit 1771973c6d
4 changed files with 9 additions and 18 deletions

View File

@@ -429,8 +429,6 @@ fn run_sim(id: u32, p: Params, g: Geometries) -> Results {
driver.add_stimulus(CurlStimulus::new(
region.clone(),
wave.clone(),
region.center(),
region.axis()
));
};
@@ -439,8 +437,6 @@ fn run_sim(id: u32, p: Params, g: Geometries) -> Results {
driver.add_stimulus(CurlStimulus::new(
region.clone(),
wave.clone(),
region.center(),
region.axis()
));
};
@@ -449,8 +445,6 @@ fn run_sim(id: u32, p: Params, g: Geometries) -> Results {
driver.add_stimulus(CurlStimulus::new(
region.clone(),
wave.clone(),
region.center(),
region.axis()
));
};

View File

@@ -94,8 +94,6 @@ fn main() {
CurlStimulus::new(
region.clone(),
wave.clone(),
region.center(),
region.axis(),
)
};

View File

@@ -84,8 +84,6 @@ fn main() {
driver.add_stimulus(CurlStimulus::new(
region.clone(),
wave.clone(),
region.center(),
region.axis()
));
};

View File

@@ -1,6 +1,6 @@
use crate::real::*;
use crate::cross::vec::Vec3;
use crate::geom::{Meters, Region};
use crate::geom::{Meters, Region, Torus};
use rand;
/// field densities
@@ -150,23 +150,24 @@ impl<R: Region + Sync, T: TimeVarying3 + Sync> AbstractStimulus for Stimulus<R,
pub struct CurlStimulus<R, T> {
region: R,
stim: T,
center: Meters,
axis: Meters,
}
impl<R, T> CurlStimulus<R, T> {
pub fn new(region: R, stim: T, center: Meters, axis: Meters) -> Self {
Self { region, stim, center, axis }
pub fn new(region: R, stim: T) -> Self {
Self { region, stim }
}
}
impl<R: Region + Sync, T: TimeVarying1 + Sync> AbstractStimulus for CurlStimulus<R, T> {
// TODO: don't require Torus: parameterize over anything which HasCrossSection
impl<T: TimeVarying1 + Sync> AbstractStimulus for CurlStimulus<Torus, T> {
fn at(&self, t_sec: f32, pos: Meters) -> Fields {
if self.region.contains(pos) {
let center = self.region.center();
let axis = self.region.axis();
let FieldMags { e, h } = self.stim.at(t_sec);
let from_center_to_point = *pos - *self.center;
let from_center_to_point = *pos - *center;
// TODO: is this inverted?
let rotational = from_center_to_point.cross(*self.axis);
let rotational = from_center_to_point.cross(*axis);
let impulse_e = rotational.with_mag(e.cast()).unwrap_or_default();
let impulse_h = rotational.with_mag(h.cast()).unwrap_or_default();
Fields {