Skip to content

Commit

Permalink
Const generics num of laser (#71)
Browse files Browse the repository at this point in the history
* Added badges to Readme.md

* fixed wrong syntax for badges on Readme

* changed badge alignment

* changed to md syntax for badges

* fixed syntax error

* Made all fields in Quadrupole* public

Made all private fields in `QuadrupoleField3D` and `QuadrupoleField2D` public to be consistent with other magnetic field structs

* switched to const generics
  • Loading branch information
minghuaw authored Jan 7, 2022
1 parent f2a5804 commit 7c91e36
Show file tree
Hide file tree
Showing 29 changed files with 333 additions and 259 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ csv = "1.1"
byteorder = "1.3.2"
multimap = "0.8.2"
hashbrown = { version = "0.11.2", features = ["rayon"] }
serde_arrays = "0.1.0"

[dev-dependencies]
gnuplot="0.0.37"
Expand All @@ -44,4 +45,4 @@ debug-assertions = false
codegen-units = 16
panic = 'unwind'
incremental = false
overflow-checks = false
overflow-checks = false
9 changes: 6 additions & 3 deletions benches/rate_calculation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use lib::atom::{Atom, AtomicTransition, Force, Mass, Position, Velocity};
use lib::ecs;
use lib::initiate::NewlyCreated;
use lib::integrator::Timestep;
use lib::laser_cooling::CoolingLight;
use lib::laser::gaussian::GaussianBeam;
use lib::laser_cooling::force::EmissionForceOption;
use lib::laser_cooling::photons_scattered::ScatteringFluctuationsOption;
use lib::laser_cooling::CoolingLight;
use lib::magnetic::quadrupole::QuadrupoleField3D;
use nalgebra::Vector3;
use rand_distr::{Distribution, Normal};
Expand All @@ -21,7 +21,8 @@ fn criterion_benchmark(c: &mut Criterion) {
let mut world = World::new();
ecs::register_components(&mut world);
ecs::register_resources(&mut world);
let mut dispatcher = ecs::create_simulation_dispatcher_builder().build();
let mut dispatcher =
ecs::create_simulation_dispatcher_builder::<{ lib::laser::DEFAULT_BEAM_LIMIT }>().build();
dispatcher.setup(&mut world);

// Create magnetic field.
Expand Down Expand Up @@ -184,7 +185,9 @@ fn criterion_benchmark(c: &mut Criterion) {
// Now bench just a specific system.
let mut bench_builder = DispatcherBuilder::new();
bench_builder.add(
lib::laser_cooling::rate::CalculateRateCoefficientsSystem,
lib::laser_cooling::rate::CalculateRateCoefficientsSystem::<
{ lib::laser::DEFAULT_BEAM_LIMIT },
>,
"",
&[],
);
Expand Down
3 changes: 2 additions & 1 deletion examples/1d_mot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ fn main() {
let mut world = World::new();
ecs::register_components(&mut world);
ecs::register_resources(&mut world);
let mut builder = ecs::create_simulation_dispatcher_builder();
let mut builder =
ecs::create_simulation_dispatcher_builder::<{ lib::laser::DEFAULT_BEAM_LIMIT }>();

// Add some output to the simulation
builder = builder.with(
Expand Down
3 changes: 2 additions & 1 deletion examples/2d_plus_mot_from_oven.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ fn main() {
let mut world = World::new();
ecs::register_components(&mut world);
ecs::register_resources(&mut world);
let mut builder = ecs::create_simulation_dispatcher_builder();
let mut builder =
ecs::create_simulation_dispatcher_builder::<{ lib::laser::DEFAULT_BEAM_LIMIT }>();

// Configure simulation output.
builder = builder.with(
Expand Down
3 changes: 2 additions & 1 deletion examples/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ fn main() {
let mut world = World::new();
ecs::register_components(&mut world);
ecs::register_resources(&mut world);
let mut builder = ecs::create_simulation_dispatcher_builder();
let mut builder =
ecs::create_simulation_dispatcher_builder::<{ lib::laser::DEFAULT_BEAM_LIMIT }>();

// Configure thread pool.
let pool = rayon::ThreadPoolBuilder::new()
Expand Down
8 changes: 6 additions & 2 deletions examples/cross_section.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ fn main() {
let mut world = World::new();
ecs::register_components(&mut world);
ecs::register_resources(&mut world);
let mut builder = ecs::create_simulation_dispatcher_builder();
let mut builder =
ecs::create_simulation_dispatcher_builder::<{ lib::laser::DEFAULT_BEAM_LIMIT }>();

// Output scattering rate and velocity
builder = builder.with(
file::new::<ExpectedPhotonsScatteredVector, Text>("scattered.txt".to_string(), 1),
file::new::<ExpectedPhotonsScatteredVector<{ lib::laser::DEFAULT_BEAM_LIMIT }>, Text>(
"scattered.txt".to_string(),
1,
),
"",
&[],
);
Expand Down
11 changes: 4 additions & 7 deletions examples/dipole_trap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ fn main() {
let mut world = World::new();
ecs::register_components(&mut world);
ecs::register_resources(&mut world);
let mut builder = ecs::create_simulation_dispatcher_builder();
let mut builder =
ecs::create_simulation_dispatcher_builder::<{ lib::laser::DEFAULT_BEAM_LIMIT }>();

// Configure simulation output.
builder = builder.with(
Expand Down Expand Up @@ -60,9 +61,7 @@ fn main() {
world
.create_entity()
.with(gaussian_beam)
.with(dipole::DipoleLight {
wavelength,
})
.with(dipole::DipoleLight { wavelength })
.with(laser::frame::Frame {
x_vector: Vector3::y(),
y_vector: Vector3::z(),
Expand All @@ -80,9 +79,7 @@ fn main() {
world
.create_entity()
.with(gaussian_beam)
.with(dipole::DipoleLight {
wavelength,
})
.with(dipole::DipoleLight { wavelength })
.with(laser::frame::Frame {
x_vector: Vector3::x(),
y_vector: Vector3::z(),
Expand Down
3 changes: 2 additions & 1 deletion examples/doppler_limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ fn main() {
let mut world = World::new();
ecs::register_components(&mut world);
ecs::register_resources(&mut world);
let mut builder = ecs::create_simulation_dispatcher_builder();
let mut builder =
ecs::create_simulation_dispatcher_builder::<{ lib::laser::DEFAULT_BEAM_LIMIT }>();

// Configure simulation output.
builder = builder.with(
Expand Down
8 changes: 6 additions & 2 deletions examples/molasses_1d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ fn main() {
let mut world = World::new();
ecs::register_components(&mut world);
ecs::register_resources(&mut world);
let mut builder = ecs::create_simulation_dispatcher_builder();
let mut builder =
ecs::create_simulation_dispatcher_builder::<{ lib::laser::DEFAULT_BEAM_LIMIT }>();

// Add some output to the simulation
builder = builder.with(
Expand All @@ -26,7 +27,10 @@ fn main() {
);

builder = builder.with(
file::new::<ActualPhotonsScatteredVector, Text>("scattered.txt".to_string(), 10),
file::new::<ActualPhotonsScatteredVector<{ lib::laser::DEFAULT_BEAM_LIMIT }>, Text>(
"scattered.txt".to_string(),
10,
),
"",
&[],
);
Expand Down
2 changes: 1 addition & 1 deletion examples/quadrupole_trap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fn main() {
world.register::<MagneticDipole>();
let mut atomecs_builder = AtomecsDispatcherBuilder::new();
atomecs_builder.add_frame_initialisation_systems();
atomecs_builder.add_systems();
atomecs_builder.add_systems::<{ lib::laser::DEFAULT_BEAM_LIMIT }>();
atomecs_builder.builder.add(
ApplyMagneticForceSystem {},
"magnetic_force",
Expand Down
3 changes: 2 additions & 1 deletion examples/recoil_limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ fn main() {
let mut world = World::new();
ecs::register_components(&mut world);
ecs::register_resources(&mut world);
let mut builder = ecs::create_simulation_dispatcher_builder();
let mut builder =
ecs::create_simulation_dispatcher_builder::<{ lib::laser::DEFAULT_BEAM_LIMIT }>();

// Configure simulation output.
builder = builder.with(
Expand Down
2 changes: 1 addition & 1 deletion examples/top_trap_with_collisions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn main() {
world.register::<TimeOrbitingPotential>();
let mut atomecs_builder = AtomecsDispatcherBuilder::new();
atomecs_builder.add_frame_initialisation_systems();
atomecs_builder.add_systems();
atomecs_builder.add_systems::<{ lib::laser::DEFAULT_BEAM_LIMIT }>();
atomecs_builder.builder.add(
ApplyMagneticForceSystem {},
"magnetic_force",
Expand Down
6 changes: 2 additions & 4 deletions src/collisions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,7 @@ fn pos_to_id(pos: Vector3<f64>, n: i64, width: f64) -> i64 {
let bound = (n as f64) / 2.0 * width;

let id: i64;
if pos[0].abs() > bound
|| pos[1].abs() > bound
|| pos[2].abs() > bound {
if pos[0].abs() > bound || pos[1].abs() > bound || pos[2].abs() > bound {
id = i64::MAX;
} else {
let xp: i64;
Expand Down Expand Up @@ -407,7 +405,7 @@ pub mod tests {
test_world.register::<NewlyCreated>();
let mut atomecs_builder = AtomecsDispatcherBuilder::new();
atomecs_builder.add_frame_initialisation_systems();
atomecs_builder.add_systems();
atomecs_builder.add_systems::<{ crate::laser::DEFAULT_BEAM_LIMIT }>();
atomecs_builder
.builder
.add(ApplyCollisionsSystem, "collisions", &[]);
Expand Down
35 changes: 20 additions & 15 deletions src/dipole/force.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ use crate::laser::index::LaserIndex;
///
/// It uses the `LaserIntensityGradientSamplers` and the properties of the `DipoleLight`
/// to add the respective amount of force to `Force`
pub struct ApplyDipoleForceSystem;
pub struct ApplyDipoleForceSystem<const N: usize>;

impl<'a> System<'a> for ApplyDipoleForceSystem {
impl<'a, const N: usize> System<'a> for ApplyDipoleForceSystem<N> {
type SystemData = (
ReadStorage<'a, DipoleLight>,
ReadStorage<'a, LaserIndex>,
ReadStorage<'a, Polarizability>,
ReadStorage<'a, LaserIntensityGradientSamplers>,
ReadStorage<'a, LaserIntensityGradientSamplers<N>>,
WriteStorage<'a, Force>,
);

Expand All @@ -30,7 +30,8 @@ impl<'a> System<'a> for ApplyDipoleForceSystem {
.par_join()
.for_each(|(force, polarizability, sampler)| {
for (index, _dipole) in (&dipole_index, &dipole_light).join() {
force.force += polarizability.prefactor * sampler.contents[index.index].gradient;
force.force +=
polarizability.prefactor * sampler.contents[index.index].gradient;
}
});
}
Expand All @@ -47,6 +48,7 @@ pub mod tests {
use crate::constant;
use crate::laser;
use crate::laser::gaussian::GaussianBeam;
use crate::laser::DEFAULT_BEAM_LIMIT;
use nalgebra::Vector3;

#[test]
Expand All @@ -56,7 +58,7 @@ pub mod tests {
test_world.register::<LaserIndex>();
test_world.register::<DipoleLight>();
test_world.register::<Force>();
test_world.register::<LaserIntensityGradientSamplers>();
test_world.register::<LaserIntensityGradientSamplers<{ DEFAULT_BEAM_LIMIT }>>();
test_world.register::<Polarizability>();

let transition_linewidth = 32e6;
Expand All @@ -82,11 +84,11 @@ pub mod tests {
.with(LaserIntensityGradientSamplers {
contents: [crate::laser::intensity_gradient::LaserIntensityGradientSampler {
gradient: Vector3::new(0.0, 1.0, -2.0),
}; crate::laser::BEAM_LIMIT],
}; crate::laser::DEFAULT_BEAM_LIMIT],
})
.with(transition)
.build();
let mut system = ApplyDipoleForceSystem;
let mut system = ApplyDipoleForceSystem::<{ DEFAULT_BEAM_LIMIT }>;
system.run_now(&test_world);
test_world.maintain();
let sampler_storage = test_world.read_storage::<Force>();
Expand All @@ -111,7 +113,7 @@ pub mod tests {
test_world.register::<LaserIndex>();
test_world.register::<DipoleLight>();
test_world.register::<Force>();
test_world.register::<LaserIntensityGradientSamplers>();
test_world.register::<LaserIntensityGradientSamplers<{ DEFAULT_BEAM_LIMIT }>>();
test_world.register::<Polarizability>();

test_world
Expand All @@ -134,11 +136,11 @@ pub mod tests {
.with(LaserIntensityGradientSamplers {
contents: [crate::laser::intensity_gradient::LaserIntensityGradientSampler {
gradient: Vector3::new(-8.4628e+7, -4.33992902e+13, -4.33992902e+13),
}; crate::laser::BEAM_LIMIT],
}; crate::laser::DEFAULT_BEAM_LIMIT],
})
.with(transition)
.build();
let mut system = ApplyDipoleForceSystem;
let mut system = ApplyDipoleForceSystem::<{ DEFAULT_BEAM_LIMIT }>;
system.run_now(&test_world);
test_world.maintain();
let sampler_storage = test_world.read_storage::<Force>();
Expand All @@ -156,7 +158,7 @@ pub mod tests {
test_world.register::<LaserIndex>();
test_world.register::<DipoleLight>();
test_world.register::<Force>();
test_world.register::<LaserIntensityGradientSamplers>();
test_world.register::<LaserIntensityGradientSamplers<{ DEFAULT_BEAM_LIMIT }>>();
test_world.register::<Polarizability>();
test_world.register::<crate::atom::Position>();
test_world.register::<crate::laser::gaussian::GaussianBeam>();
Expand Down Expand Up @@ -223,18 +225,21 @@ pub mod tests {
})
.with(LaserIntensityGradientSamplers {
contents: [laser::intensity_gradient::LaserIntensityGradientSampler::default();
crate::laser::BEAM_LIMIT],
crate::laser::DEFAULT_BEAM_LIMIT],
})
.with(transition)
.build();
let mut grad_system = laser::intensity_gradient::SampleGaussianLaserIntensityGradientSystem;
let mut force_system = ApplyDipoleForceSystem;
let mut grad_system = laser::intensity_gradient::SampleGaussianLaserIntensityGradientSystem::<
{ DEFAULT_BEAM_LIMIT },
>;
let mut force_system = ApplyDipoleForceSystem::<{ DEFAULT_BEAM_LIMIT }>;
grad_system.run_now(&test_world);
test_world.maintain();
force_system.run_now(&test_world);
test_world.maintain();
let sampler_storage = test_world.read_storage::<Force>();
let grad_sampler_storage = test_world.read_storage::<LaserIntensityGradientSamplers>();
let grad_sampler_storage =
test_world.read_storage::<LaserIntensityGradientSamplers<{ DEFAULT_BEAM_LIMIT }>>();
let sim_result_force = sampler_storage.get(atom1).expect("Entity not found!").force;
let _sim_result_grad = grad_sampler_storage
.get(atom1)
Expand Down
11 changes: 6 additions & 5 deletions src/dipole/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ impl Polarizability {
/ (2. * (2. * constant::PI * transition_f).powf(3.0))
* optical_transition_linewidth
* -(1. / (transition_f - dipole_f) + 1. / (transition_f + dipole_f));
Polarizability {
prefactor,
}
Polarizability { prefactor }
}
}

Expand Down Expand Up @@ -90,9 +88,12 @@ impl<'a> System<'a> for AttachIndexToDipoleLightSystem {
/// `builder`: the dispatch builder to modify
///
/// `deps`: any dependencies that must be completed before the systems run.
pub fn add_systems_to_dispatch(builder: &mut DispatcherBuilder<'static, 'static>, deps: &[&str]) {
pub fn add_systems_to_dispatch<const N: usize>(
builder: &mut DispatcherBuilder<'static, 'static>,
deps: &[&str],
) {
builder.add(
force::ApplyDipoleForceSystem,
force::ApplyDipoleForceSystem::<N>,
"apply_dipole_force",
&["sample_intensity_gradient"],
);
Expand Down
Loading

0 comments on commit 7c91e36

Please sign in to comment.