Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch particle storage to struct of array #195

Merged
merged 5 commits into from
Sep 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benches/argon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn cache_move_particle(bencher: &mut Bencher) {
let mut rng = utils::get_rng(654646);

let i: usize = rng.gen_range(0, system.size());
let mut delta = system.particle(i).position;
let mut delta = system.particles().position[i];
delta += Vector3D::new(rng.gen(), rng.gen(), rng.gen());

bencher.iter(||{
Expand Down
4 changes: 2 additions & 2 deletions benches/nacl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ fn cache_move_particle_ewald(bencher: &mut Bencher) {
let mut rng = utils::get_rng(41201154);

let i: usize = rng.gen_range(0, system.size());
let mut delta = system.particle(i).position;
let mut delta = system.particles().position[i];
delta += Vector3D::new(rng.gen(), rng.gen(), rng.gen());

bencher.iter(||{
Expand All @@ -103,7 +103,7 @@ fn cache_move_particle_wolf(bencher: &mut Bencher) {
let mut rng = utils::get_rng(474114);

let i: usize = rng.gen_range(0, system.size());
let mut delta = system.particle(i).position;
let mut delta = system.particles().position[i];
delta += Vector3D::new(rng.gen(), rng.gen(), rng.gen());

bencher.iter(||{
Expand Down
9 changes: 5 additions & 4 deletions benches/propane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ fn cache_move_particles(bencher: &mut Bencher) {
let mut rng = utils::get_rng(84541545);

let molecule = rng.choose(system.molecules()).unwrap();
let indexes = molecule.into_iter();
let mut delta = vec![];
for i in molecule {
let position = system.particle(i).position;
for position in &system.particles().position[indexes] {
delta.push(position + Vector3D::new(rng.gen(), rng.gen(), rng.gen()));
}

Expand All @@ -64,8 +64,9 @@ fn cache_move_all_rigid_molecules(bencher: &mut Bencher) {
let mut rng = utils::get_rng(7012121);
for molecule in system.molecules().to_owned() {
let delta = Vector3D::new(rng.gen(), rng.gen(), rng.gen());
for i in molecule {
system.particle_mut(i).position += delta;
let indexes = molecule.into_iter();
for position in &mut system.particles_mut().position[indexes] {
*position += delta;
}
}

Expand Down
18 changes: 10 additions & 8 deletions benches/water.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ fn cache_move_particles_wolf(bencher: &mut Bencher) {
let mut rng = utils::get_rng(454548784);

let molecule = rng.choose(system.molecules()).unwrap();
let indexes = molecule.into_iter();
let mut delta = vec![];
for i in molecule {
let position = system.particle(i).position;
for position in &system.particles().position[indexes] {
delta.push(position + Vector3D::new(rng.gen(), rng.gen(), rng.gen()));
}

Expand All @@ -116,9 +116,9 @@ fn cache_move_particles_ewald(bencher: &mut Bencher) {
let mut rng = utils::get_rng(9886565);

let molecule = rng.choose(system.molecules()).unwrap();
let indexes = molecule.into_iter();
let mut delta = vec![];
for i in molecule {
let position = system.particle(i).position;
for position in &system.particles().position[indexes] {
delta.push(position + Vector3D::new(rng.gen(), rng.gen(), rng.gen()));
}

Expand All @@ -137,8 +137,9 @@ fn cache_move_all_rigid_molecules_wolf(bencher: &mut Bencher) {
let mut rng = utils::get_rng(3);
for molecule in system.molecules().to_owned() {
let delta = Vector3D::new(rng.gen(), rng.gen(), rng.gen());
for i in molecule {
system.particle_mut(i).position += delta;
let indexes = molecule.into_iter();
for position in &mut system.particles_mut().position[indexes] {
*position += delta;
}
}

Expand All @@ -157,8 +158,9 @@ fn cache_move_all_rigid_molecules_ewald(bencher: &mut Bencher) {
let mut rng = utils::get_rng(2121);
for molecule in system.molecules().to_owned() {
let delta = Vector3D::new(rng.gen(), rng.gen(), rng.gen());
for i in molecule {
system.particle_mut(i).position += delta;
let indexes = molecule.into_iter();
for position in &mut system.particles_mut().position[indexes] {
*position += delta;
}
}

Expand Down
11 changes: 8 additions & 3 deletions examples/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
extern crate lumol;
extern crate lumol_input as input;

use lumol::sys::{Molecule, Particle, TrajectoryBuilder, UnitCell};
use lumol::sys::{Molecule, Particle, ParticleVec, TrajectoryBuilder, UnitCell};
use lumol::sys::{read_molecule, molecule_type};
use lumol::sim::Simulation;
use lumol::sim::mc::{MonteCarlo, Translate, Rotate};
Expand All @@ -30,7 +30,7 @@ fn main() {
let co2 = {
// We can read files to get molecule type
let (molecule, atoms) = read_molecule("data/CO2.xyz").unwrap();
molecule_type(&molecule, &atoms)
molecule_type(&molecule, atoms.as_slice())
};
let h2o = {
// Or define a new molecule by hand
Expand All @@ -41,7 +41,12 @@ fn main() {
molecule.add_bond(0, 1);
molecule.add_bond(1, 2);

molecule_type(&molecule, &[Particle::new("H"), Particle::new("O"), Particle::new("H")])
let mut atoms = ParticleVec::new();
atoms.push(Particle::new("H"));
atoms.push(Particle::new("O"));
atoms.push(Particle::new("H"));

molecule_type(&molecule, atoms.as_slice())
};

let mut mc = MonteCarlo::new(units::from(500.0, "K").unwrap());
Expand Down
8 changes: 3 additions & 5 deletions examples/mc_npt_spce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,10 @@ fn get_system() -> System {
system.add_angle_potential("H", "O", "H", angle);

// Set charges
let h = 0.42380;
let o = - 2.0 * h;
for particle in system.particles_mut() {
match particle.name() {
"H" => particle.charge = h,
"O" => particle.charge = o,
match particle.name.as_ref() {
"H" => *particle.charge = 0.42380,
"O" => *particle.charge = -2.0 * 0.42380,
_ => panic!("Unknown particle name in charge setting."),
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ num-traits = "0.1"
rayon = "0.8"
thread_local = "0.3"
caldyn = "0.4"
itertools = "0.6"
soa_derive = "0.4"

[dev-dependencies]
tempfile = "2.1"
Expand Down
Loading