-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add benchmark simulation * Precalculate some `AtomicTransition` numbers. * Remove all barriers. * Sampler initialisation done by using to_vec to copy blank initialised vector. * inner parallelism on most resource intensive systems.
- Loading branch information
1 parent
d12c6be
commit 87b1d38
Showing
11 changed files
with
354 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
//! Simulation of atoms cooled to the Doppler limit. | ||
extern crate magneto_optical_trap as lib; | ||
extern crate nalgebra; | ||
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::force::ApplyEmissionForceOption; | ||
use lib::laser::gaussian::GaussianBeam; | ||
use lib::laser::photons_scattered::EnableScatteringFluctuations; | ||
use lib::magnetic::quadrupole::QuadrupoleField3D; | ||
use lib::output::file; | ||
use lib::output::file::Text; | ||
use nalgebra::Vector3; | ||
use rand::distributions::{Distribution, Normal}; | ||
use specs::{Builder, World}; | ||
use std::time::Instant; | ||
|
||
fn main() { | ||
let now = Instant::now(); | ||
|
||
// Create the simulation world and builder for the ECS dispatcher. | ||
let mut world = World::new(); | ||
ecs::register_components(&mut world); | ||
ecs::register_resources(&mut world); | ||
let mut builder = ecs::create_simulation_dispatcher_builder(); | ||
|
||
// Configure thread pool. | ||
let pool = rayon::ThreadPoolBuilder::new() | ||
.num_threads(12) | ||
.build() | ||
.unwrap(); | ||
|
||
builder.add_pool(::std::sync::Arc::new(pool)); | ||
|
||
let mut dispatcher = builder.build(); | ||
dispatcher.setup(&mut world.res); | ||
|
||
// Create magnetic field. | ||
world | ||
.create_entity() | ||
.with(QuadrupoleField3D::gauss_per_cm(18.2, Vector3::z())) | ||
.with(Position { | ||
pos: Vector3::new(0.0, 0.0, 0.0), | ||
}) | ||
.build(); | ||
|
||
// Create cooling lasers. | ||
let detuning = -3.0; | ||
let power = 0.02; | ||
let radius = 66.7e-3 / (2.0_f64.sqrt()); | ||
let beam_centre = Vector3::new(0.0, 0.0, 0.0); | ||
|
||
world | ||
.create_entity() | ||
.with(GaussianBeam { | ||
intersection: beam_centre.clone(), | ||
e_radius: radius, | ||
power: power, | ||
direction: Vector3::new(0.0, 0.0, 1.0), | ||
}) | ||
.with(CoolingLight::for_species( | ||
AtomicTransition::rubidium(), | ||
detuning, | ||
-1, | ||
)) | ||
.build(); | ||
world | ||
.create_entity() | ||
.with(GaussianBeam { | ||
intersection: beam_centre.clone(), | ||
e_radius: radius, | ||
power: power, | ||
direction: Vector3::new(0.0, 0.0, -1.0), | ||
}) | ||
.with(CoolingLight::for_species( | ||
AtomicTransition::rubidium(), | ||
detuning, | ||
-1, | ||
)) | ||
.build(); | ||
world | ||
.create_entity() | ||
.with(GaussianBeam { | ||
intersection: beam_centre.clone(), | ||
e_radius: radius, | ||
power: power, | ||
direction: Vector3::new(-1.0, 0.0, 0.0), | ||
}) | ||
.with(CoolingLight::for_species( | ||
AtomicTransition::rubidium(), | ||
detuning, | ||
1, | ||
)) | ||
.build(); | ||
world | ||
.create_entity() | ||
.with(GaussianBeam { | ||
intersection: beam_centre.clone(), | ||
e_radius: radius, | ||
power: power, | ||
direction: Vector3::new(1.0, 0.0, 0.0), | ||
}) | ||
.with(CoolingLight::for_species( | ||
AtomicTransition::rubidium(), | ||
detuning, | ||
1, | ||
)) | ||
.build(); | ||
world | ||
.create_entity() | ||
.with(GaussianBeam { | ||
intersection: beam_centre.clone(), | ||
e_radius: radius, | ||
power: power, | ||
direction: Vector3::new(0.0, 1.0, 0.0), | ||
}) | ||
.with(CoolingLight::for_species( | ||
AtomicTransition::rubidium(), | ||
detuning, | ||
1, | ||
)) | ||
.build(); | ||
world | ||
.create_entity() | ||
.with(GaussianBeam { | ||
intersection: beam_centre.clone(), | ||
e_radius: radius, | ||
power: power, | ||
direction: Vector3::new(0.0, -1.0, 0.0), | ||
}) | ||
.with(CoolingLight::for_species( | ||
AtomicTransition::rubidium(), | ||
detuning, | ||
1, | ||
)) | ||
.build(); | ||
|
||
// Define timestep | ||
world.add_resource(Timestep { delta: 1.0e-6 }); | ||
|
||
let vel_dist = Normal::new(0.0, 0.22); | ||
let pos_dist = Normal::new(0.0, 1.2e-4); | ||
let mut rng = rand::thread_rng(); | ||
|
||
// Add atoms | ||
for _ in 0..10000 { | ||
world | ||
.create_entity() | ||
.with(Position { | ||
pos: Vector3::new( | ||
pos_dist.sample(&mut rng), | ||
pos_dist.sample(&mut rng), | ||
pos_dist.sample(&mut rng), | ||
), | ||
}) | ||
.with(Velocity { | ||
vel: Vector3::new( | ||
vel_dist.sample(&mut rng), | ||
vel_dist.sample(&mut rng), | ||
vel_dist.sample(&mut rng), | ||
), | ||
}) | ||
.with(Force::new()) | ||
.with(Mass { value: 87.0 }) | ||
.with(AtomicTransition::rubidium()) | ||
.with(Atom) | ||
.with(NewlyCreated) | ||
.build(); | ||
} | ||
|
||
// Enable fluctuation options | ||
// * Allow photon numbers to fluctuate. | ||
// * Allow random force from emission of photons. | ||
world.add_resource(ApplyEmissionForceOption {}); | ||
world.add_resource(EnableScatteringFluctuations {}); | ||
|
||
// Run the simulation for a number of steps. | ||
for _i in 0..5000 { | ||
dispatcher.dispatch(&mut world.res); | ||
world.maintain(); | ||
} | ||
|
||
println!("Simulation completed in {} ms.", now.elapsed().as_millis()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.