Files
fdtd-coremem/examples/toroid.rs

60 lines
2.2 KiB
Rust

use coremem::{Driver, mat, meas};
use coremem::geom::Vec2;
fn main() {
coremem::init_logging();
let width = 800;
let feat_size = 1e-3; // feature size
let peak_current = 2.5e9;
let conductivity = 1.0e5;
let inner_rad = 50;
let outer_rad = 100;
let ferro_rad = 40;
let mut driver = Driver::new(width, width, feat_size);
//driver.set_steps_per_frame(8);
//driver.set_steps_per_frame(40);
driver.add_y4m_renderer("toroid.y4m");
// driver.add_term_renderer();
driver.add_measurement(meas::Current(width / 2 + (inner_rad + outer_rad) / 2, width / 2));
driver.add_measurement(meas::Current(width / 2 + inner_rad + 2, width / 2));
driver.add_measurement(meas::Magnetization(width / 2, width / 2));
driver.add_measurement(meas::MagneticFlux(width / 2, width / 2));
driver.add_measurement(meas::MagneticStrength(width / 2, width / 2));
let center = Vec2::new((width/2) as _, (width/2) as _);
for y in 0..width {
for x in 0..width {
let d = Vec2::new(x as _, y as _) - center;
if (inner_rad as _..outer_rad as _).contains(&d.mag()) {
*driver.state.get_mut(x, y).mat_mut() = mat::Static::conductor(conductivity).into();
} else if d.mag() < ferro_rad as _ {
*driver.state.get_mut(x, y).mat_mut() = mat::db::ferroxcube_3r1();
}
}
}
driver.add_boundary(width/2 - outer_rad - 10, 0.01);
loop {
let drive_current = peak_current * match driver.state.step_no() {
0..=1000 => 1.0,
3000..=4000 => -1.0,
_ => 0.0,
};
// E = V/M
//let e = v/(2.0*feat_size);
let e = drive_current/conductivity;
for y in 0..width {
for x in 0..width {
let d = Vec2::new(x as _, y as _) - center;
if (inner_rad as _..outer_rad as _).contains(&d.mag()) {
let tangent = Vec2::new(-d.y(), d.x()).with_mag(e);
driver.state.impulse_ex(x, y, tangent.x());
driver.state.impulse_ey(x, y, tangent.y());
}
}
}
driver.step();
}
}