From a1afb945665c2be9d34ace62f0cd665131e8387c Mon Sep 17 00:00:00 2001 From: Jon Drobny Date: Wed, 19 Oct 2022 14:51:02 -0700 Subject: [PATCH 01/26] Test feature of including rotation algorithm in libRustBCA.pybca --- setup.py | 2 +- src/lib.rs | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index d2aef92f..ac2651db 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ RustExtension( "libRustBCA.pybca", binding=Binding.PyO3, - features=["python"], + features=["python", "parry3d"], #args=["+nightly", "--edition 2018", "-Z unstable-options"], #optional=True, #rust_version="1.57.0" diff --git a/src/lib.rs b/src/lib.rs index 095b5f36..ed68b50a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -74,6 +74,8 @@ pub use crate::sphere::{Sphere, SphereInput, InputSphere}; #[cfg(feature = "parry3d")] pub use crate::parry::{ParryBall, ParryBallInput, InputParryBall, ParryTriMesh, ParryTriMeshInput, InputParryTriMesh}; +#[cfg(feature = "parry3d")] +pub use parry3d_f64::na::{Point3, Vector3, Matrix3, Rotation3}; #[cfg(feature = "python")] #[pymodule] @@ -82,6 +84,8 @@ pub fn pybca(py: Python, m: &PyModule) -> PyResult<()> { m.add_function(wrap_pyfunction!(simple_bca_list_py, m)?)?; m.add_function(wrap_pyfunction!(compound_bca_list_py, m)?)?; m.add_function(wrap_pyfunction!(compound_bca_list_1D_py, m)?)?; + #[cfg(feature = "parry3d")] + m.add_function(wrap_pyfunction!(rotate_given_surface_normal_py, m)?)?; Ok(()) } @@ -1586,3 +1590,58 @@ pub fn simple_bca(x: f64, y: f64, z: f64, ux: f64, uy: f64, uz: f64, E1: f64, Z1 ] ).collect() } + +#[cfg(feature = "parry3d")] +#[no_mangle] +pub extern "C" fn rotate_given_surface_normal(nx: f64, ny: f64, nz: f64, ux: &mut f64, uy: &mut f64, uz: &mut f64) { + const DELTA: f64 = 1e-9; + let RUSTBCA_DIRECTION: Vector3:: = Vector3::::new(1.0, 0.0, 0.0); + + let into_surface = Vector3::new(-nx, -ny, -nz); + let direction = Vector3::new(*ux, *uy, *uz); + + //Rotation to local RustBCA coordinates from global + //Here's how this works: a rotation matrix is found that maps the rustbca + //into-the-surface vector (1.0, 0.0, 0.0) onto the local into-the-surface vector (negative normal w.r.t. ray origin). + //That rotation is then applied to the particle direction, and can be undone later. + //Algorithm is from here: + //https://math.stackexchange.com/questions/180418/calculate-rotation-matrix-to-align-vector-a-to-vector-b-in-3d/180436#180436 + let v: Vector3 = into_surface.cross(&RUSTBCA_DIRECTION); + let c = into_surface.dot(&RUSTBCA_DIRECTION); + let vx = Matrix3::::new(0.0, -v.z, v.y, v.z, 0.0, -v.x, -v.y, v.x, 0.0); + let rotation_matrix = if c != -1.0 { + Matrix3::identity() + vx + vx*vx/(1. + c) + } else { + //If c == -1.0, the correct rotation should simply be a 180 degree rotation + //around a non-x axis; y is chosen arbitrarily + Rotation3::from_axis_angle(&Vector3::y_axis(), PI).into() + }; + + let incident = rotation_matrix*direction; + + // ux must not be exactly 1.0 to avoid gimbal lock in RustBCA + // simple_bca does not normalize direction before proceeding, must be done manually + *ux = incident.x + DELTA; + assert!( + *ux > 0.0, "Error: RustBCA initial direction out of surface. Please check surface normals and incident direction. n = ({}, {}, {}) u = ({}, {}, {})", + nx, ny, nz, ux, uy, uz + ); + + *uy = incident.y - DELTA; + *uz = incident.z; + let mag = (ux.powf(2.) + uy.powf(2.) + uz.powf(2.)).sqrt(); + + *ux /= mag; + *uy /= mag; + *uz /= mag; +} + +#[cfg(all(feature = "python", feature = "parry3d"))] +#[pyfunction] +pub fn rotate_given_surface_normal_py(nx: f64, ny: f64, nz: f64, ux: f64, uy: f64, uz: f64) -> (f64, f64, f64) { + let mut ux = ux; + let mut uy = uy; + let mut uz = uz; + rotate_given_surface_normal(nx, ny, nz, &mut ux, &mut uy, &mut uz); + (ux, uy, uz) +} \ No newline at end of file From 4ec1ae106c5cd9970e815b7745d07979c0357580 Mon Sep 17 00:00:00 2001 From: Jon Drobny Date: Wed, 19 Oct 2022 14:54:42 -0700 Subject: [PATCH 02/26] Fix version number in setup.py. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index ac2651db..456243ab 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name="RustBCA", - version="1.2.0", + version="1.3.0", rust_extensions=[ RustExtension( "libRustBCA.pybca", From 07aa2f759df2725bfc69761bb0b01c72d749523f Mon Sep 17 00:00:00 2001 From: Jon Drobny Date: Wed, 19 Oct 2022 15:17:20 -0700 Subject: [PATCH 03/26] Added docstrings to rotation algorithm --- src/lib.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index ed68b50a..1863ea02 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1639,6 +1639,19 @@ pub extern "C" fn rotate_given_surface_normal(nx: f64, ny: f64, nz: f64, ux: &mu #[cfg(all(feature = "python", feature = "parry3d"))] #[pyfunction] pub fn rotate_given_surface_normal_py(nx: f64, ny: f64, nz: f64, ux: f64, uy: f64, uz: f64) -> (f64, f64, f64) { + /// rotate_given_surface_normal_py(nx, ny, nz, ux, uy, uz) + /// -- + /// + /// This function runs a 0D Binary Collision Approximation simulation for the given incident ions and material. + /// Args: + /// nx (f64): surface normal in global frame x-component. + /// ny (f64): surface normal in global frame y-component. + /// nz (f64): surface normal in global frame z-component. + /// ux (f64): particle direction in global frame x-component. + /// uy (f64): particle direction in global frame normal y-component. + /// uz (f64): particle direction in global frame normal z-component. + /// Returns: + /// direction (f64, f64, f64): direction vector of particle in RustBCA coordinates. let mut ux = ux; let mut uy = uy; let mut uz = uz; From 6f06f24538cb61044f210e02ea2d7559a6c66cab Mon Sep 17 00:00:00 2001 From: Jon Drobny Date: Wed, 19 Oct 2022 15:20:44 -0700 Subject: [PATCH 04/26] Fix to docstring; it was placed in the wrong location to be automatically read by PyO3. --- src/lib.rs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1863ea02..38c58dfc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1638,20 +1638,21 @@ pub extern "C" fn rotate_given_surface_normal(nx: f64, ny: f64, nz: f64, ux: &mu #[cfg(all(feature = "python", feature = "parry3d"))] #[pyfunction] +/// rotate_given_surface_normal_py(nx, ny, nz, ux, uy, uz) +/// -- +/// +/// This function runs a 0D Binary Collision Approximation simulation for the given incident ions and material. +/// Args: +/// nx (f64): surface normal in global frame x-component. +/// ny (f64): surface normal in global frame y-component. +/// nz (f64): surface normal in global frame z-component. +/// ux (f64): particle direction in global frame x-component. +/// uy (f64): particle direction in global frame normal y-component. +/// uz (f64): particle direction in global frame normal z-component. +/// Returns: +/// direction (f64, f64, f64): direction vector of particle in RustBCA coordinates. pub fn rotate_given_surface_normal_py(nx: f64, ny: f64, nz: f64, ux: f64, uy: f64, uz: f64) -> (f64, f64, f64) { - /// rotate_given_surface_normal_py(nx, ny, nz, ux, uy, uz) - /// -- - /// - /// This function runs a 0D Binary Collision Approximation simulation for the given incident ions and material. - /// Args: - /// nx (f64): surface normal in global frame x-component. - /// ny (f64): surface normal in global frame y-component. - /// nz (f64): surface normal in global frame z-component. - /// ux (f64): particle direction in global frame x-component. - /// uy (f64): particle direction in global frame normal y-component. - /// uz (f64): particle direction in global frame normal z-component. - /// Returns: - /// direction (f64, f64, f64): direction vector of particle in RustBCA coordinates. + let mut ux = ux; let mut uy = uy; let mut uz = uz; From 52d04084b2dd237cae455c80cd0d04e669592fc1 Mon Sep 17 00:00:00 2001 From: Jon Drobny Date: Fri, 21 Oct 2022 09:35:33 -0700 Subject: [PATCH 05/26] Major cleanup of library functions; implemented default options struct creation function; added ergonomic python library functions for sputtering and reflection. --- src/RustBCA.egg-info/PKG-INFO | 2 +- src/RustBCA.egg-info/SOURCES.txt | 1 - src/input.rs | 69 ++++ src/lib.rs | 652 +++++++++++-------------------- 4 files changed, 293 insertions(+), 431 deletions(-) diff --git a/src/RustBCA.egg-info/PKG-INFO b/src/RustBCA.egg-info/PKG-INFO index f9a0c9c6..a5a9006c 100644 --- a/src/RustBCA.egg-info/PKG-INFO +++ b/src/RustBCA.egg-info/PKG-INFO @@ -1,4 +1,4 @@ Metadata-Version: 2.1 Name: RustBCA -Version: 1.2.0 +Version: 1.3.0 License-File: LICENSE diff --git a/src/RustBCA.egg-info/SOURCES.txt b/src/RustBCA.egg-info/SOURCES.txt index e08c1322..63764525 100644 --- a/src/RustBCA.egg-info/SOURCES.txt +++ b/src/RustBCA.egg-info/SOURCES.txt @@ -8,7 +8,6 @@ src/bca.rs src/consts.rs src/enums.rs src/geometry.rs -src/gui.rs src/input.rs src/interactions.rs src/lib.rs diff --git a/src/input.rs b/src/input.rs index 91693aa2..2570c7c6 100644 --- a/src/input.rs +++ b/src/input.rs @@ -212,6 +212,32 @@ pub struct Options { pub track_energy_losses: bool, } +#[cfg(not(feature = "distributions"))] +impl Options { + pub fn default_options(track_recoils: bool) -> Options { + Options { + name: "default".to_string(), + track_trajectories: false, + track_recoils: false, + track_recoil_trajectories: false, + write_buffer_size: default_buffer_size(), + weak_collision_order: three(), + suppress_deep_recoils: false, + high_energy_free_flight_paths: false, + electronic_stopping_mode: default_electronic_stopping_mode(), + mean_free_path_model: default_mean_free_path_model(), + interaction_potential: default_interaction_potential(), + scattering_integral: default_scattering_integral(), + root_finder: default_rootfinder(), + num_threads: 1, + num_chunks: 1, + use_hdf5: false, + track_displacements: false, + track_energy_losses: false + } + } +} + #[cfg(feature = "distributions")] #[derive(Deserialize, Clone)] pub struct Options { @@ -240,7 +266,9 @@ pub struct Options { pub scattering_integral: Vec>, #[serde(default = "default_rootfinder")] pub root_finder: Vec>, + #[serde(default = "one_usize")] pub num_threads: usize, + #[serde(default = "one_u64")] pub num_chunks: u64, #[serde(default = "default_false")] pub use_hdf5: bool, @@ -265,6 +293,47 @@ pub struct Options { pub z_num: usize, } +#[cfg(feature = "distributions")] +impl Options { + pub fn default_options(track_recoils: bool) -> Options { + Options { + name: "default".to_string(), + track_trajectories: false, + track_recoils: false, + track_recoil_trajectories: false, + write_buffer_size: default_buffer_size(), + weak_collision_order: three(), + suppress_deep_recoils: false, + high_energy_free_flight_paths: false, + electronic_stopping_mode: default_electronic_stopping_mode(), + mean_free_path_model: default_mean_free_path_model(), + interaction_potential: default_interaction_potential(), + scattering_integral: default_scattering_integral(), + root_finder: default_rootfinder(), + num_threads: 1, + num_chunks: 1, + use_hdf5: false, + track_displacements: false, + track_energy_losses: false, + energy_min: 0.0, + energy_max: 0.0, + energy_num: 0, + angle_min: 0.0, + angle_max: 0.0, + angle_num: 0, + x_min: 0.0, + y_min: 0.0, + z_min: 0.0, + x_max: 0.0, + y_max: 0.0, + z_max: 0.0, + x_num: 0, + y_num: 0, + z_num: 0, + } + } +} + pub fn input(input_file: String) -> (Vec, material::Material, Options, OutputUnits) where ::InputFileFormat: Deserialize<'static> + 'static { diff --git a/src/lib.rs b/src/lib.rs index 38c58dfc..f565f39e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,9 +12,14 @@ extern crate intel_mkl_src; use std::{fmt}; use std::mem::discriminant; +//Parallelization - currently only used in python library functions +#[cfg(feature = "python")] +use rayon::prelude::*; +#[cfg(feature = "python")] +use rayon::*; + //Error handling crate use anyhow::{Result, Context, anyhow}; -//use anyhow::*; //Serializing/Deserializing crate use serde::*; @@ -33,6 +38,9 @@ use std::os::raw::c_int; //standard slice use std::slice; +//Mutex for multithreading in ergonomic Python library functions +#[cfg(feature = "python")] +use std::sync::Mutex; //itertools use itertools::izip; @@ -46,6 +54,8 @@ use std::f64::consts::SQRT_2; use pyo3::prelude::*; #[cfg(feature = "python")] use pyo3::wrap_pyfunction; +#[cfg(feature = "python")] +use pyo3::types::*; //Load internal modules pub mod material; @@ -84,6 +94,8 @@ pub fn pybca(py: Python, m: &PyModule) -> PyResult<()> { m.add_function(wrap_pyfunction!(simple_bca_list_py, m)?)?; m.add_function(wrap_pyfunction!(compound_bca_list_py, m)?)?; m.add_function(wrap_pyfunction!(compound_bca_list_1D_py, m)?)?; + m.add_function(wrap_pyfunction!(sputtering_yield, m)?)?; + m.add_function(wrap_pyfunction!(reflection_coefficient, m)?)?; #[cfg(feature = "parry3d")] m.add_function(wrap_pyfunction!(rotate_given_surface_normal_py, m)?)?; Ok(()) @@ -173,64 +185,7 @@ pub extern "C" fn compound_tagged_bca_list_c(input: InputTaggedBCA) -> OutputTag let mut output_weights = vec![]; let mut output_incident = vec![]; - #[cfg(feature = "distributions")] - let options = Options { - name: "test".to_string(), - track_trajectories: false, - track_recoils: true, - track_recoil_trajectories: false, - write_buffer_size: 8000, - weak_collision_order: 3, - suppress_deep_recoils: false, - high_energy_free_flight_paths: false, - electronic_stopping_mode: ElectronicStoppingMode::INTERPOLATED, - mean_free_path_model: MeanFreePathModel::LIQUID, - interaction_potential: vec![vec![InteractionPotential::KR_C]], - scattering_integral: vec![vec![ScatteringIntegral::MENDENHALL_WELLER]], - num_threads: 1, - num_chunks: 1, - use_hdf5: false, - root_finder: vec![vec![Rootfinder::DEFAULTNEWTON]], - track_displacements: false, - track_energy_losses: false, - energy_min: 0.0, - energy_max: 10.0, - energy_num: 11, - angle_min: 0.0, - angle_max: 90.0, - angle_num: 11, - x_min: 0.0, - y_min: -10.0, - z_min: -10.0, - x_max: 10.0, - y_max: 10.0, - z_max: 10.0, - x_num: 11, - y_num: 11, - z_num: 11, - }; - - #[cfg(not(feature = "distributions"))] - let options = Options { - name: "test".to_string(), - track_trajectories: false, - track_recoils: true, - track_recoil_trajectories: false, - write_buffer_size: 8000, - weak_collision_order: 3, - suppress_deep_recoils: false, - high_energy_free_flight_paths: false, - electronic_stopping_mode: ElectronicStoppingMode::INTERPOLATED, - mean_free_path_model: MeanFreePathModel::LIQUID, - interaction_potential: vec![vec![InteractionPotential::KR_C]], - scattering_integral: vec![vec![ScatteringIntegral::MENDENHALL_WELLER]], - num_threads: 1, - num_chunks: 1, - use_hdf5: false, - root_finder: vec![vec![Rootfinder::DEFAULTNEWTON]], - track_displacements: false, - track_energy_losses: false, - }; + let options = Options::default_options(true); let Z2 = unsafe { slice::from_raw_parts(input.Z2, input.num_species_target).to_vec() }; let m2 = unsafe { slice::from_raw_parts(input.m2, input.num_species_target).to_vec() }; @@ -358,31 +313,11 @@ pub extern "C" fn compound_tagged_bca_list_c(input: InputTaggedBCA) -> OutputTag #[no_mangle] -#[cfg(not(feature = "distributions"))] pub extern "C" fn reflect_single_ion_c(num_species_target: &mut c_int, ux: &mut f64, uy: &mut f64, uz: &mut f64, E1: &mut f64, Z1: &mut f64, m1: &mut f64, Ec1: &mut f64, Es1: &mut f64, Z2: *mut f64, m2: *mut f64, Ec2: *mut f64, Es2: *mut f64, Eb2: *mut f64, n2: *mut f64) { assert!(E1 > &mut 0.0); - let options = Options { - name: "test".to_string(), - track_trajectories: false, - track_recoil_trajectories: false, - track_recoils: false, - write_buffer_size: 8000, - weak_collision_order: 3, - suppress_deep_recoils: false, - high_energy_free_flight_paths: false, - electronic_stopping_mode: ElectronicStoppingMode::INTERPOLATED, - mean_free_path_model: MeanFreePathModel::LIQUID, - interaction_potential: vec![vec![InteractionPotential::KR_C]], - scattering_integral: vec![vec![ScatteringIntegral::MENDENHALL_WELLER]], - num_threads: 1, - num_chunks: 1, - use_hdf5: false, - root_finder: vec![vec![Rootfinder::DEFAULTNEWTON]], - track_displacements: false, - track_energy_losses: false, - }; + let options = Options::default_options(false); let Z2 = unsafe { slice::from_raw_parts(Z2, *num_species_target as usize).to_vec() }; let m2 = unsafe { slice::from_raw_parts(m2, *num_species_target as usize).to_vec() }; @@ -465,64 +400,7 @@ pub extern "C" fn simple_bca_list_c(input: InputSimpleBCA) -> OutputBCA { let mut total_output = vec![]; - #[cfg(feature = "distributions")] - let options = Options { - name: "test".to_string(), - track_trajectories: false, - track_recoils: true, - track_recoil_trajectories: false, - write_buffer_size: 8000, - weak_collision_order: 3, - suppress_deep_recoils: false, - high_energy_free_flight_paths: false, - electronic_stopping_mode: ElectronicStoppingMode::INTERPOLATED, - mean_free_path_model: MeanFreePathModel::LIQUID, - interaction_potential: vec![vec![InteractionPotential::KR_C]], - scattering_integral: vec![vec![ScatteringIntegral::MENDENHALL_WELLER]], - num_threads: 1, - num_chunks: 1, - use_hdf5: false, - root_finder: vec![vec![Rootfinder::DEFAULTNEWTON]], - track_displacements: false, - track_energy_losses: false, - energy_min: 0.0, - energy_max: 10.0, - energy_num: 11, - angle_min: 0.0, - angle_max: 90.0, - angle_num: 11, - x_min: 0.0, - y_min: -10.0, - z_min: -10.0, - x_max: 10.0, - y_max: 10.0, - z_max: 10.0, - x_num: 11, - y_num: 11, - z_num: 11, - }; - - #[cfg(not(feature = "distributions"))] - let options = Options { - name: "test".to_string(), - track_trajectories: false, - track_recoils: true, - track_recoil_trajectories: false, - write_buffer_size: 8000, - weak_collision_order: 3, - suppress_deep_recoils: false, - high_energy_free_flight_paths: false, - electronic_stopping_mode: ElectronicStoppingMode::INTERPOLATED, - mean_free_path_model: MeanFreePathModel::LIQUID, - interaction_potential: vec![vec![InteractionPotential::KR_C]], - scattering_integral: vec![vec![ScatteringIntegral::MENDENHALL_WELLER]], - num_threads: 1, - num_chunks: 1, - use_hdf5: false, - root_finder: vec![vec![Rootfinder::DEFAULTNEWTON]], - track_displacements: false, - track_energy_losses: false, - }; + let options = Options::default_options(true); let material_parameters = material::MaterialParameters { energy_unit: "EV".to_string(), @@ -627,64 +505,7 @@ pub extern "C" fn compound_bca_list_c(input: InputCompoundBCA) -> OutputBCA { let mut total_output = vec![]; - #[cfg(feature = "distributions")] - let options = Options { - name: "test".to_string(), - track_trajectories: false, - track_recoils: true, - track_recoil_trajectories: false, - write_buffer_size: 8000, - weak_collision_order: 3, - suppress_deep_recoils: false, - high_energy_free_flight_paths: false, - electronic_stopping_mode: ElectronicStoppingMode::INTERPOLATED, - mean_free_path_model: MeanFreePathModel::LIQUID, - interaction_potential: vec![vec![InteractionPotential::KR_C]], - scattering_integral: vec![vec![ScatteringIntegral::MENDENHALL_WELLER]], - num_threads: 1, - num_chunks: 1, - use_hdf5: false, - root_finder: vec![vec![Rootfinder::DEFAULTNEWTON]], - track_displacements: false, - track_energy_losses: false, - energy_min: 0.0, - energy_max: 10.0, - energy_num: 11, - angle_min: 0.0, - angle_max: 90.0, - angle_num: 11, - x_min: 0.0, - y_min: -10.0, - z_min: -10.0, - x_max: 10.0, - y_max: 10.0, - z_max: 10.0, - x_num: 11, - y_num: 11, - z_num: 11, - }; - - #[cfg(not(feature = "distributions"))] - let options = Options { - name: "test".to_string(), - track_trajectories: false, - track_recoils: true, - track_recoil_trajectories: false, - write_buffer_size: 8000, - weak_collision_order: 3, - suppress_deep_recoils: false, - high_energy_free_flight_paths: false, - electronic_stopping_mode: ElectronicStoppingMode::INTERPOLATED, - mean_free_path_model: MeanFreePathModel::LIQUID, - interaction_potential: vec![vec![InteractionPotential::KR_C]], - scattering_integral: vec![vec![ScatteringIntegral::MENDENHALL_WELLER]], - num_threads: 1, - num_chunks: 1, - use_hdf5: false, - root_finder: vec![vec![Rootfinder::DEFAULTNEWTON]], - track_displacements: false, - track_energy_losses: false, - }; + let options = Options::default_options(true); let Z2 = unsafe { slice::from_raw_parts(input.Z2, input.num_species_target).to_vec() }; let m2 = unsafe { slice::from_raw_parts(input.m2, input.num_species_target).to_vec() }; @@ -809,64 +630,7 @@ pub extern "C" fn compound_bca_list_fortran(num_incident_ions: &mut c_int, track let mut total_output = vec![]; - #[cfg(feature = "distributions")] - let options = Options { - name: "test".to_string(), - track_trajectories: false, - track_recoils: *track_recoils, - track_recoil_trajectories: false, - write_buffer_size: 8000, - weak_collision_order: 3, - suppress_deep_recoils: false, - high_energy_free_flight_paths: false, - electronic_stopping_mode: ElectronicStoppingMode::INTERPOLATED, - mean_free_path_model: MeanFreePathModel::LIQUID, - interaction_potential: vec![vec![InteractionPotential::KR_C]], - scattering_integral: vec![vec![ScatteringIntegral::MENDENHALL_WELLER]], - num_threads: 1, - num_chunks: 1, - use_hdf5: false, - root_finder: vec![vec![Rootfinder::DEFAULTNEWTON]], - track_displacements: false, - track_energy_losses: false, - energy_min: 0.0, - energy_max: 10.0, - energy_num: 11, - angle_min: 0.0, - angle_max: 90.0, - angle_num: 11, - x_min: 0.0, - y_min: -10.0, - z_min: -10.0, - x_max: 10.0, - y_max: 10.0, - z_max: 10.0, - x_num: 11, - y_num: 11, - z_num: 11, - }; - - #[cfg(not(feature = "distributions"))] - let options = Options { - name: "test".to_string(), - track_trajectories: false, - track_recoils: *track_recoils, - track_recoil_trajectories: false, - write_buffer_size: 8000, - weak_collision_order: 3, - suppress_deep_recoils: false, - high_energy_free_flight_paths: false, - electronic_stopping_mode: ElectronicStoppingMode::INTERPOLATED, - mean_free_path_model: MeanFreePathModel::LIQUID, - interaction_potential: vec![vec![InteractionPotential::KR_C]], - scattering_integral: vec![vec![ScatteringIntegral::MENDENHALL_WELLER]], - num_threads: 1, - num_chunks: 1, - use_hdf5: false, - root_finder: vec![vec![Rootfinder::DEFAULTNEWTON]], - track_displacements: false, - track_energy_losses: false, - }; + let options = Options::default_options(*track_recoils); let ux = unsafe { slice::from_raw_parts(ux, *num_incident_ions as usize).to_vec() }; let uy = unsafe { slice::from_raw_parts(uy, *num_incident_ions as usize).to_vec() }; @@ -1029,64 +793,7 @@ pub fn compound_bca_list_py(energies: Vec, ux: Vec, uy: Vec, uz: assert_eq!(Eb2.len(), num_species_target, "Input error: list of target bulk binding energies is not the same length as atomic numbers."); assert_eq!(n2.len(), num_species_target, "Input error: list of target number densities is not the same length as atomic numbers."); - #[cfg(feature = "distributions")] - let options = Options { - name: "test".to_string(), - track_trajectories: false, - track_recoils: true, - track_recoil_trajectories: false, - write_buffer_size: 8000, - weak_collision_order: 3, - suppress_deep_recoils: true, - high_energy_free_flight_paths: true, - electronic_stopping_mode: ElectronicStoppingMode::LOW_ENERGY_NONLOCAL, - mean_free_path_model: MeanFreePathModel::LIQUID, - interaction_potential: vec![vec![InteractionPotential::KR_C]], - scattering_integral: vec![vec![ScatteringIntegral::MENDENHALL_WELLER]], - num_threads: 1, - num_chunks: 1, - use_hdf5: false, - root_finder: vec![vec![Rootfinder::DEFAULTNEWTON]], - track_displacements: false, - track_energy_losses: false, - energy_min: 0.0, - energy_max: 10.0, - energy_num: 11, - angle_min: 0.0, - angle_max: 90.0, - angle_num: 11, - x_min: 0.0, - y_min: -10.0, - z_min: -10.0, - x_max: 10.0, - y_max: 10.0, - z_max: 10.0, - x_num: 11, - y_num: 11, - z_num: 11, - }; - - #[cfg(not(feature = "distributions"))] - let options = Options { - name: "test".to_string(), - track_trajectories: false, - track_recoils: true, - track_recoil_trajectories: false, - write_buffer_size: 8000, - weak_collision_order: 3, - suppress_deep_recoils: true, - high_energy_free_flight_paths: false, - electronic_stopping_mode: ElectronicStoppingMode::LOW_ENERGY_NONLOCAL, - mean_free_path_model: MeanFreePathModel::LIQUID, - interaction_potential: vec![vec![InteractionPotential::KR_C]], - scattering_integral: vec![vec![ScatteringIntegral::MENDENHALL_WELLER]], - num_threads: 1, - num_chunks: 1, - use_hdf5: false, - root_finder: vec![vec![Rootfinder::DEFAULTNEWTON]], - track_displacements: false, - track_energy_losses: false, - }; + let options = Options::default_options(true); let x = -2.*(n2.iter().sum::()*10E30).powf(-1./3.); let y = 0.0; @@ -1229,65 +936,7 @@ pub fn compound_bca_list_1D_py(ux: Vec, uy: Vec, uz: Vec, energie assert_eq!(n2[0].len(), num_species, "Input error: first layer species list of target number densities is not the same length as atomic numbers."); assert_eq!(dx.len(), num_layers_target, "Input error: number of layer thicknesses not the same as number of layers in atomic densities list."); - #[cfg(feature = "distributions")] - let options = Options { - name: "test".to_string(), - track_trajectories: false, - track_recoils: true, - track_recoil_trajectories: false, - write_buffer_size: 8000, - weak_collision_order: 3, - suppress_deep_recoils: true, - high_energy_free_flight_paths: true, - electronic_stopping_mode: ElectronicStoppingMode::LOW_ENERGY_NONLOCAL, - mean_free_path_model: MeanFreePathModel::LIQUID, - interaction_potential: vec![vec![InteractionPotential::KR_C]], - scattering_integral: vec![vec![ScatteringIntegral::MENDENHALL_WELLER]], - num_threads: 1, - num_chunks: 1, - use_hdf5: false, - root_finder: vec![vec![Rootfinder::DEFAULTNEWTON]], - track_displacements: false, - track_energy_losses: false, - energy_min: 0.0, - energy_max: 10.0, - energy_num: 11, - angle_min: 0.0, - angle_max: 90.0, - angle_num: 11, - x_min: 0.0, - y_min: -10.0, - z_min: -10.0, - x_max: 10.0, - y_max: 10.0, - z_max: 10.0, - x_num: 11, - y_num: 11, - z_num: 11, - }; - - #[cfg(not(feature = "distributions"))] - let options = Options { - name: "test".to_string(), - track_trajectories: false, - track_recoils: true, - track_recoil_trajectories: false, - write_buffer_size: 8000, - weak_collision_order: 3, - suppress_deep_recoils: true, - high_energy_free_flight_paths: false, - electronic_stopping_mode: ElectronicStoppingMode::LOW_ENERGY_NONLOCAL, - mean_free_path_model: MeanFreePathModel::LIQUID, - interaction_potential: vec![vec![InteractionPotential::KR_C]], - scattering_integral: vec![vec![ScatteringIntegral::MENDENHALL_WELLER]], - num_threads: 1, - num_chunks: 1, - use_hdf5: false, - root_finder: vec![vec![Rootfinder::DEFAULTNEWTON]], - track_displacements: false, - track_energy_losses: false, - }; - + let options = Options::default_options(true); let y = 0.0; let z = 0.0; @@ -1466,64 +1115,7 @@ pub fn simple_bca(x: f64, y: f64, z: f64, ux: f64, uy: f64, uz: f64, E1: f64, Z1 assert!(Ec1 > 0.0, "Error: Cutoff energy Ec1 cannot be less than or equal to 0."); assert!(Ec2 > 0.0, "Error: Cutoff energy Ec2 cannot be less than or equal to 0."); - #[cfg(feature = "distributions")] - let options = Options { - name: "test".to_string(), - track_trajectories: false, - track_recoils: true, - track_recoil_trajectories: false, - write_buffer_size: 8000, - weak_collision_order: 3, - suppress_deep_recoils: false, - high_energy_free_flight_paths: false, - electronic_stopping_mode: ElectronicStoppingMode::INTERPOLATED, - mean_free_path_model: MeanFreePathModel::LIQUID, - interaction_potential: vec![vec![InteractionPotential::KR_C]], - scattering_integral: vec![vec![ScatteringIntegral::MENDENHALL_WELLER]], - num_threads: 1, - num_chunks: 1, - use_hdf5: false, - root_finder: vec![vec![Rootfinder::DEFAULTNEWTON]], - track_displacements: false, - track_energy_losses: false, - energy_min: 0.0, - energy_max: 10.0, - energy_num: 11, - angle_min: 0.0, - angle_max: 90.0, - angle_num: 11, - x_min: 0.0, - y_min: -10.0, - z_min: -10.0, - x_max: 10.0, - y_max: 10.0, - z_max: 10.0, - x_num: 11, - y_num: 11, - z_num: 11, - }; - - #[cfg(not(feature = "distributions"))] - let options = Options { - name: "test".to_string(), - track_trajectories: false, - track_recoils: true, - track_recoil_trajectories: false, - write_buffer_size: 8000, - weak_collision_order: 3, - suppress_deep_recoils: false, - high_energy_free_flight_paths: false, - electronic_stopping_mode: ElectronicStoppingMode::INTERPOLATED, - mean_free_path_model: MeanFreePathModel::LIQUID, - interaction_potential: vec![vec![InteractionPotential::KR_C]], - scattering_integral: vec![vec![ScatteringIntegral::MENDENHALL_WELLER]], - num_threads: 1, - num_chunks: 1, - use_hdf5: false, - root_finder: vec![vec![Rootfinder::DEFAULTNEWTON]], - track_displacements: false, - track_energy_losses: false, - }; + let options = Options::default_options(true); let p = particle::Particle { m: m1*AMU, @@ -1658,4 +1250,206 @@ pub fn rotate_given_surface_normal_py(nx: f64, ny: f64, nz: f64, ux: f64, uy: f6 let mut uz = uz; rotate_given_surface_normal(nx, ny, nz, &mut ux, &mut uy, &mut uz); (ux, uy, uz) +} + +#[cfg(feature = "python")] +pub fn unpack(python_float: &PyAny) -> f64 { + python_float.downcast::().expect("Error unpacking Python float to f64. Check values.").value() +} + +#[cfg(feature = "python")] +#[pyfunction] +/// +pub fn sputtering_yield(ion: &PyDict, target: &PyDict, energy: f64, angle: f64, num_samples: usize) -> f64 { + + const DELTA: f64 = 1e-6; + + let Z1 = unpack(ion.get_item("Z").expect("Cannot get ion Z from dictionary. Ensure ion['Z'] exists.")); + let m1 = unpack(ion.get_item("m").expect("Cannot get ion mass from dictionary. Ensure ion['m'] exists.")); + let Ec1 = unpack(ion.get_item("Ec").expect("Cannot get ion cutoff energy from dictionary. Ensure ion['Ec'] exists.")); + let Es1 = unpack(ion.get_item("Es").expect("Cannot get ion surface binding energy from dictionary. Ensure ion['Es'] exists.")); + + let Z2 = unpack(target.get_item("Z").expect("Cannot get target Z from dictionary. Ensure target['Z'] exists.")); + let m2 = unpack(target.get_item("m").expect("Cannot get target mass from dictionary. Ensure target['m'] exists.")); + let Ec2 = unpack(target.get_item("Ec").expect("Cannot get target cutoff energy from dictionary. Ensure target['Ec'] exists.")); + let Es2 = unpack(target.get_item("Es").expect("Cannot get target surface binding energy from dictionary. Ensure target['Es'] exists.")); + let Eb2 = unpack(target.get_item("Eb").expect("Cannot get target bulk binding energy from dictionary. Ensure target['Eb'] exists.")); + let n2 = unpack(target.get_item("n").expect("Cannot get target density from dictionary. Ensure target['n'] exists.")); + + let options = Options::default_options(true); + + let y = 0.0; + let z = 0.0; + + let ux = (angle/180.0*PI).cos() - DELTA; + let uy = (angle/180.0*PI).sin() + DELTA; + let uz = 0.0; + + let mut direction = Vector::new(ux, uy, uz); + direction.normalize(); + + let material_parameters = material::MaterialParameters { + energy_unit: "EV".to_string(), + mass_unit: "AMU".to_string(), + Eb: vec![Eb2], + Es: vec![Es2], + Ec: vec![Ec2], + Z: vec![Z2], + m: vec![m2], + interaction_index: vec![0], + surface_binding_model: SurfaceBindingModel::AVERAGE, + bulk_binding_model: BulkBindingModel::INDIVIDUAL, + }; + + let geometry_input = geometry::Mesh0DInput { + length_unit: "M".to_string(), + densities: vec![n2], + electronic_stopping_correction_factor: 1.0 + }; + + let m = material::Material::::new(&material_parameters, &geometry_input); + + let x = -m.geometry.energy_barrier_thickness; + + let num_sputtered = Mutex::new(0); + + (0..num_samples as u64).into_par_iter().for_each( |index| { + + let p = particle::Particle { + m: m1*AMU, + Z: Z1, + E: energy*EV, + Ec: Ec1*EV, + Es: Es1*EV, + pos: Vector::new(x, y, z), + dir: direction, + pos_origin: Vector::new(x, y, z), + pos_old: Vector::new(x, y, z), + dir_old: direction, + energy_origin: energy*EV, + asymptotic_deflection: 0.0, + stopped: false, + left: false, + incident: true, + first_step: true, + trajectory: vec![], + energies: vec![], + track_trajectories: false, + number_collision_events: 0, + backreflected: false, + interaction_index : 0, + weight: 1.0, + tag: 0, + tracked_vector: Vector::new(0.0, 0.0, 0.0), + }; + + let output = bca::single_ion_bca(p, &m, &options); + + for particle in output { + if particle.E > 0.0 && particle.dir.x < 0.0 && particle.left && (!particle.incident) { + let mut num_sputtered = num_sputtered.lock().unwrap(); + *num_sputtered += 1; + } + } + }); + let num_sputtered = *num_sputtered.lock().unwrap(); + num_sputtered as f64 / num_samples as f64 +} + +#[cfg(feature = "python")] +#[pyfunction] +/// +pub fn reflection_coefficient(ion: &PyDict, target: &PyDict, energy: f64, angle: f64, num_samples: usize) -> f64 { + + const DELTA: f64 = 1e-6; + + let Z1 = unpack(ion.get_item("Z").expect("Cannot get ion Z from dictionary. Ensure ion['Z'] exists.")); + let m1 = unpack(ion.get_item("m").expect("Cannot get ion mass from dictionary. Ensure ion['m'] exists.")); + let Ec1 = unpack(ion.get_item("Ec").expect("Cannot get ion cutoff energy from dictionary. Ensure ion['Ec'] exists.")); + let Es1 = unpack(ion.get_item("Es").expect("Cannot get ion surface binding energy from dictionary. Ensure ion['Es'] exists.")); + + let Z2 = unpack(target.get_item("Z").expect("Cannot get target Z from dictionary. Ensure target['Z'] exists.")); + let m2 = unpack(target.get_item("m").expect("Cannot get target mass from dictionary. Ensure target['m'] exists.")); + let Ec2 = unpack(target.get_item("Ec").expect("Cannot get target cutoff energy from dictionary. Ensure target['Ec'] exists.")); + let Es2 = unpack(target.get_item("Es").expect("Cannot get target surface binding energy from dictionary. Ensure target['Es'] exists.")); + let Eb2 = unpack(target.get_item("Eb").expect("Cannot get target bulk binding energy from dictionary. Ensure target['Eb'] exists.")); + let n2 = unpack(target.get_item("n").expect("Cannot get target density from dictionary. Ensure target['n'] exists.")); + + let options = Options::default_options(false); + + let y = 0.0; + let z = 0.0; + + let ux = (angle/180.0*PI).cos() - DELTA; + let uy = (angle/180.0*PI).sin() + DELTA; + let uz = 0.0; + + let mut direction = Vector::new(ux, uy, uz); + direction.normalize(); + + let material_parameters = material::MaterialParameters { + energy_unit: "EV".to_string(), + mass_unit: "AMU".to_string(), + Eb: vec![Eb2], + Es: vec![Es2], + Ec: vec![Ec2], + Z: vec![Z2], + m: vec![m2], + interaction_index: vec![0], + surface_binding_model: SurfaceBindingModel::AVERAGE, + bulk_binding_model: BulkBindingModel::INDIVIDUAL, + }; + + let geometry_input = geometry::Mesh0DInput { + length_unit: "M".to_string(), + densities: vec![n2], + electronic_stopping_correction_factor: 1.0 + }; + + let m = material::Material::::new(&material_parameters, &geometry_input); + + let x = -m.geometry.energy_barrier_thickness; + + let num_reflected = Mutex::new(0); + + (0..num_samples as u64).into_par_iter().for_each( |index| { + let p = particle::Particle { + m: m1*AMU, + Z: Z1, + E: energy*EV, + Ec: Ec1*EV, + Es: Es1*EV, + pos: Vector::new(x, y, z), + dir: direction, + pos_origin: Vector::new(x, y, z), + pos_old: Vector::new(x, y, z), + dir_old: direction, + energy_origin: energy*EV, + asymptotic_deflection: 0.0, + stopped: false, + left: false, + incident: true, + first_step: true, + trajectory: vec![], + energies: vec![], + track_trajectories: false, + number_collision_events: 0, + backreflected: false, + interaction_index : 0, + weight: 1.0, + tag: 0, + tracked_vector: Vector::new(0.0, 0.0, 0.0), + }; + + let output = bca::single_ion_bca(p, &m, &options); + + for particle in output { + if particle.E > 0.0 && particle.dir.x < 0.0 && particle.left && particle.incident { + let mut num_reflected = num_reflected.lock().unwrap(); + *num_reflected += 1; + } + } + }); + let num_reflected = *num_reflected.lock().unwrap(); + num_reflected as f64 / num_samples as f64 } \ No newline at end of file From b2caefb979945ae547547ee66cccfc5b73f3aab4 Mon Sep 17 00:00:00 2001 From: Jon Drobny Date: Fri, 21 Oct 2022 10:16:09 -0700 Subject: [PATCH 06/26] Updated test_rustbca.py to include new ergonomic functions. Fixed default options to correctly set track_recoils.: --- examples/test_rustbca.py | 14 ++++++++++++++ src/input.rs | 4 ++-- src/lib.rs | 33 ++++++++++++++++++++++++++++----- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/examples/test_rustbca.py b/examples/test_rustbca.py index cee6673e..3dfd7979 100644 --- a/examples/test_rustbca.py +++ b/examples/test_rustbca.py @@ -18,6 +18,20 @@ def main(): #tungsten Eb = 0 is a 'worst-case' - accepted literature value is 3 eV target['Eb'] = 3.0 + energy = 2500.0 #eV + angle = 0.0 #degrees + num_samples = 1000 + #For automatic control, libRustBCA offers two helpful functions for the sputtering yield and reflection coefficients + Y = sputtering_yield(ion, target, energy, angle, num_samples) + + print(f'Sputtering yield for {ion["symbol"]} on {target["symbol"]} at {energy} eV is {Y} at/ion. Yamamura predicts { np.round(yamamura(ion, target, energy),3)} at/ion.') + + R_N, R_E = reflection_coefficient(ion, target, energy, angle, num_samples) + print(f'Particle reflection coefficient for {ion["symbol"]} on {target["symbol"]} at {energy} eV is {R_N}. Thomas predicts {np.round(thomas_reflection(ion, target, energy), 3)}.') + print(f'Energy reflection coefficient for {ion["symbol"]} on {target["symbol"]} at {energy} eV is {R_E}') + + + #For smooth distributions and good statistics, you should use at least 10k ions number_ions = 100000 diff --git a/src/input.rs b/src/input.rs index 2570c7c6..11d597e9 100644 --- a/src/input.rs +++ b/src/input.rs @@ -218,7 +218,7 @@ impl Options { Options { name: "default".to_string(), track_trajectories: false, - track_recoils: false, + track_recoils: track_recoils, track_recoil_trajectories: false, write_buffer_size: default_buffer_size(), weak_collision_order: three(), @@ -298,7 +298,7 @@ impl Options { pub fn default_options(track_recoils: bool) -> Options { Options { name: "default".to_string(), - track_trajectories: false, + track_trajectories: track_recoils, track_recoils: false, track_recoil_trajectories: false, write_buffer_size: default_buffer_size(), diff --git a/src/lib.rs b/src/lib.rs index f565f39e..c5c48d9f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1253,13 +1253,21 @@ pub fn rotate_given_surface_normal_py(nx: f64, ny: f64, nz: f64, ux: f64, uy: f6 } #[cfg(feature = "python")] -pub fn unpack(python_float: &PyAny) -> f64 { +/// A helper function to unpack a python float from a python any. +fn unpack(python_float: &PyAny) -> f64 { python_float.downcast::().expect("Error unpacking Python float to f64. Check values.").value() } #[cfg(feature = "python")] #[pyfunction] -/// +/// sputteirng_yield(ion, target, energy, angle, num_samples) +/// A routine the calculates the sputtering yield in atoms per ion of energetic ions incident upon materials using RustBCA. +/// Args: +/// ion: a dictionary with the keys Z (atomic number), m (atomic mass in AMU), Ec (cutoff energy in eV), Es (surface binding energy in eV) +/// target: a dictionary with the keys Z, m, Ec, Es, Eb (bulk binding energy in eV), n2 (number density in 1/m3) +/// energy: the incident energy of the ion in eV +/// angle: incident angle of the ion in degrees from surface normal +/// num_samples: number of ion trajectories to run; precision will go as 1/sqrt(N) pub fn sputtering_yield(ion: &PyDict, target: &PyDict, energy: f64, angle: f64, num_samples: usize) -> f64 { const DELTA: f64 = 1e-6; @@ -1358,8 +1366,18 @@ pub fn sputtering_yield(ion: &PyDict, target: &PyDict, energy: f64, angle: f64, #[cfg(feature = "python")] #[pyfunction] -/// -pub fn reflection_coefficient(ion: &PyDict, target: &PyDict, energy: f64, angle: f64, num_samples: usize) -> f64 { +/// reflection_coefficient(ion, target, energy, angle, num_samples) +/// A routine the calculates the reflection coefficient of energetic ions incident upon materials using RustBCA. +/// Args: +/// ion: a dictionary with the keys Z (atomic number), m (atomic mass in AMU), Ec (cutoff energy in eV), Es (surface binding energy in eV) +/// target: a dictionary with the keys Z, m, Ec, Es, Eb (bulk binding energy in eV), n2 (number density in 1/m3) +/// energy: the incident energy of the ion in eV +/// angle: incident angle of the ion in degrees from surface normal +/// num_samples: number of ion trajectories to run; precision will go as 1/sqrt(N) +/// Returns: +/// R_N (f64): reflection coefficient (number of particles reflected / number of incident particles) +/// R_E (f64): energy reflection coefficient (sum of reflected particle energies / total incident energy) +pub fn reflection_coefficient(ion: &PyDict, target: &PyDict, energy: f64, angle: f64, num_samples: usize) -> (f64, f64) { const DELTA: f64 = 1e-6; @@ -1411,6 +1429,7 @@ pub fn reflection_coefficient(ion: &PyDict, target: &PyDict, energy: f64, angle: let x = -m.geometry.energy_barrier_thickness; let num_reflected = Mutex::new(0); + let energy_reflected = Mutex::new(0.0); (0..num_samples as u64).into_par_iter().for_each( |index| { let p = particle::Particle { @@ -1447,9 +1466,13 @@ pub fn reflection_coefficient(ion: &PyDict, target: &PyDict, energy: f64, angle: if particle.E > 0.0 && particle.dir.x < 0.0 && particle.left && particle.incident { let mut num_reflected = num_reflected.lock().unwrap(); *num_reflected += 1; + let mut energy_reflected = energy_reflected.lock().unwrap(); + *energy_reflected += particle.E; } } }); let num_reflected = *num_reflected.lock().unwrap(); - num_reflected as f64 / num_samples as f64 + let energy_reflected = *energy_reflected.lock().unwrap(); + + (num_reflected as f64 / num_samples as f64, energy_reflected / EV / energy / num_samples as f64) } \ No newline at end of file From af23030ece32c2bae47f8c2ffadf7c9b6387eefd Mon Sep 17 00:00:00 2001 From: Jon Drobny Date: Fri, 21 Oct 2022 11:14:16 -0700 Subject: [PATCH 07/26] Added benchmark_eam.py which shows RustBCA's reflection coefficients qualitatively match EAM down to low energies, unlike SRIM or Thomas. --- examples/benchmark_eam.py | 60 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 examples/benchmark_eam.py diff --git a/examples/benchmark_eam.py b/examples/benchmark_eam.py new file mode 100644 index 00000000..0e606024 --- /dev/null +++ b/examples/benchmark_eam.py @@ -0,0 +1,60 @@ +from libRustBCA.pybca import * +import numpy as np +import matplotlib.pyplot as plt +import sys +import os +#This should allow the script to find materials and formulas from anywhere +sys.path.append(os.path.dirname(__file__)+'/../scripts') +sys.path.append('scripts') +from materials import * +from formulas import * + +#Data digitized from Fig. 1 of https://doi.org/10.1016/0022-3115(84)90433-1 +#Modeled reflection coefficients using EAM at 100 eV and below and experimentally at 100 eV and above +#Used to show that TRIM breaks down at higher incident energies +data = np.array( + [[0.2962771, 0.18217821], + [0.96344626, 0.4871287], + [3.0372448, 0.8930693], + [9.876638, 0.86534655], + [30.184526, 0.7841584], + [96.644066, 0.6217822], #note: this is the last EAM data point + [102.83226, 0.4950495], #note: this is the first experimental data point + [203.52855, 0.37623763], + [516.34265, 0.3980198], + [809.75903, 0.32277226], + [1006.2257, 0.2990099], + [2054.3218, 0.17821783], + [4129.5522, 0.13069306], + [6890.884, 0.0990099]] +) + +#Setting the cutoff low is necessary since the incident energies are also low. +hydrogen['Ec'] = 0.001 + +#Plotting the EAM data points. +energies = data[:6, 0] +r_benchmark = data[:6, 1] +plt.semilogx(energies, r_benchmark, marker='o', linestyle='', label='EAM') + +#Plotting the experimental data points. +energies = data[6:, 0] +r_benchmark = data[6:, 1] +plt.semilogx(energies, r_benchmark, marker='^', linestyle='', label='Exp.') + +#Plotting RustBCA data points, using the ergonomic helper function reflection_coefficient(). +energies = np.logspace(-1, 4, 25) +r_rustbca = [reflection_coefficient(hydrogen, nickel, energy, 0.0, 1000)[0] for energy in energies] +plt.semilogx(energies, r_rustbca, label='RustBCA', color='black') + +r_thomas = [thomas_reflection(hydrogen, nickel, energy) for energy in energies] +plt.semilogx(energies, r_thomas, label='Thomas', color='red', linestyle='--') + +plt.title('Reflection Coefficients of Normal Incidence H on Ni') +plt.xlabel('E [eV]') +plt.ylabel('R') +plt.gca().set_ylim([0.0, 1.0]) +plt.legend(loc='upper right') + +plt.show() + From e452a7f9298b4bafb0c5a7c6f94e9f23ce9d8427 Mon Sep 17 00:00:00 2001 From: Jon Drobny Date: Fri, 21 Oct 2022 11:28:28 -0700 Subject: [PATCH 08/26] Added .0 suffixes to all floats; PyO3 has a difficult time casting floats to integers and vice versa. --- scripts/materials.py | 52 ++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/scripts/materials.py b/scripts/materials.py index d572d66c..ad135529 100644 --- a/scripts/materials.py +++ b/scripts/materials.py @@ -1,7 +1,7 @@ titanium = { 'symbol': 'Ti', 'name': 'titanium', - 'Z': 22, + 'Z': 22.0, 'm': 47.867, 'Es': 4.84, 'Ec': 3.5, @@ -15,7 +15,7 @@ hydrogen = { 'symbol': 'H', 'name': 'hydrogen', - 'Z': 1, + 'Z': 1.0, 'm': 1.008, 'Ec': 0.95, 'Es': 1.5, @@ -24,7 +24,7 @@ lithium = { 'symbol': 'Li', 'name': 'lithium', - 'Z': 3, + 'Z': 3.0, 'm': 6.941, 'Ec': 1.0, 'Es': 1.64, @@ -35,8 +35,8 @@ nitrogen = { 'symbol': 'N', 'name': 'nitrogen', - 'Z': 7, - 'm': 14, + 'Z': 7.0, + 'm': 14.0, 'n': 5.4E25, 'Es': 0., 'Eb': 0., @@ -47,8 +47,8 @@ deuterium = { 'symbol': 'D', 'name': 'deuterium', - 'Z': 1, - 'm': 2, + 'Z': 1.0, + 'm': 2.0, 'Ec': 0.1, 'Es': 1.5, } @@ -56,7 +56,7 @@ helium = { 'symbol': 'He', 'name': 'helium', - 'Z': 2, + 'Z': 2.0, 'm': 4.002602, 'Ec': 1.0, 'Es': 0. @@ -65,7 +65,7 @@ beryllium = { 'symbol': 'Be', 'name': 'beryllium', - 'Z': 4, + 'Z': 4.0, 'm': 9.012182, 'n': 1.2347E29, 'Es': 3.31, @@ -79,7 +79,7 @@ uranium = { 'symbol': 'U', 'name': 'uranium', - 'Z': 92, + 'Z': 92.0, 'm': 237.048166, 'n': 5.195E28, 'Es': 5.19, @@ -91,7 +91,7 @@ lead = { 'symbol': 'Pb', 'name': 'lead', - 'Z': 82, + 'Z': 82.0, 'm': 207.2, 'n': 3.299E28, 'Es': 2.03, @@ -103,7 +103,7 @@ boron = { 'symbol': 'B', 'name': 'boron', - 'Z': 5, + 'Z': 5.0, 'm': 10.811, 'n': 1.309E29, 'Es': 5.76, @@ -117,7 +117,7 @@ arsenic = { 'symbol': 'As', 'name': 'arsenic', - 'Z': 33, + 'Z': 33.0, 'm': 74.921595, 'n': 4.603E28, 'Es': 3.12, @@ -131,7 +131,7 @@ neon = { 'symbol': 'Ne', 'name': 'neon', - 'Z': 10, + 'Z': 10.0, 'm': 20.1797, 'Ec': 1.0, 'Es': 0. @@ -140,7 +140,7 @@ krypton = { 'symbol': 'Kr', 'name': 'krypton', - 'Z': 36, + 'Z': 36.0, 'm': 83.80, 'Ec': 1.0, 'Es': 0. @@ -149,7 +149,7 @@ silicon = { 'symbol': 'Si', 'name': 'silicon', - 'Z': 14, + 'Z': 14.0, 'm': 28.08553, 'n': 4.90E28, 'Es': 4.72, @@ -163,7 +163,7 @@ argon = { 'symbol': 'Ar', 'name': 'argon', - 'Z': 18, + 'Z': 18.0, 'm': 39.948, 'Ec': 1.0, 'Es': 0. @@ -172,7 +172,7 @@ oxygen = { 'symbol': 'O', 'name': 'oxygen', - 'Z': 8, + 'Z': 8.0, 'm': 15.9994, 'Eb': 2.58, 'Ec': 2.0, @@ -183,7 +183,7 @@ aluminum = { 'symbol': 'Al', 'name': 'aluminum', - 'Z': 13, + 'Z': 13.0, 'm': 26.98, 'n': 6.022E28, 'Es': 3.39, #Eckstein (1991) p. 80 @@ -195,7 +195,7 @@ ytterbium = { 'symbol': 'Yb', 'name': 'ytterbium', - 'Z': 70, + 'Z': 70.0, 'm': 173.04, 'n': 2.424E28, 'Eb': 1.58, @@ -207,7 +207,7 @@ copper = { 'symbol': 'Cu', 'name': 'copper', - 'Z': 29, + 'Z': 29.0, 'm': 63.546, 'n': 8.491E28, 'Es': (4.65 + 4.26 + 4.62)/3., #Eckstein (1991) p. 80 @@ -221,7 +221,7 @@ tungsten = { 'symbol': 'W', 'name': 'tungsten', - 'Z': 74, + 'Z': 74.0, 'm': 183.84, 'n': 6.306E28, 'Es': 8.79, @@ -235,7 +235,7 @@ gold = { 'symbol': 'Au', 'name': 'gold', - 'Z': 79, + 'Z': 79.0, 'm': 196.97, 'n': 5.901E28, 'Es': 3.79, @@ -247,7 +247,7 @@ nickel = { 'symbol': 'Ni', 'name': 'nickel', - 'Z': 28, + 'Z': 28.0, 'm': 58.69, 'n': 9.14E28, 'Es': (5.61 + 5.11 + 5.55)/3., #Eckstein (1991) p. 80 @@ -259,7 +259,7 @@ cesium = { 'symbol': 'Cs', 'name': 'cesium', - 'Z': 55, + 'Z': 55.0, 'm': 132.905, 'Ec': 0.8, 'Es': 0.8, @@ -268,7 +268,7 @@ xenon = { 'symbol': 'Xe', 'name': 'xenon', - 'Z': 54, + 'Z': 54.0, 'm': 131.293, 'Ec': 1.0, 'Es': 0. From c86716b7222c07995d9cd97f7b3ab963a148d5eb Mon Sep 17 00:00:00 2001 From: Jon Drobny Date: Wed, 26 Oct 2022 16:13:35 -0700 Subject: [PATCH 09/26] Added testing of Morse potential for H on Ni reflection at low energy. --- examples/test_morse.py | 148 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 examples/test_morse.py diff --git a/examples/test_morse.py b/examples/test_morse.py new file mode 100644 index 00000000..39b0a9d2 --- /dev/null +++ b/examples/test_morse.py @@ -0,0 +1,148 @@ +from libRustBCA.pybca import * +import numpy as np +import matplotlib.pyplot as plt +import sys +import os +#This should allow the script to find materials and formulas from anywhere +sys.path.append(os.path.dirname(__file__)+'/../scripts') +sys.path.append('scripts') +from materials import * +from formulas import * + +#Corrections to hydrogen to enable low-E simualtions and to match literature Es for H on Ni +hydrogen['Ec'] = 0.001 +hydrogen['Es'] = 2.5 + +#This function simply contains an entire input file as a multi-line f-string to modify some inputs. +def run_morse_potential(energy, index, num_samples=10000, run_sim=True): + + input_file = f''' + [options] + name = "morse_{index}" + track_trajectories = false + track_recoils = false + track_recoil_trajectories = false + write_buffer_size = 8000 + weak_collision_order = 0 + suppress_deep_recoils = false + high_energy_free_flight_paths = false + electronic_stopping_mode = "LOW_ENERGY_NONLOCAL" + mean_free_path_model = "LIQUID" + interaction_potential = [[{{"MORSE"={{D=5.4971E-20, r0=2.782E-10, alpha=1.4198E10}}}}]] + scattering_integral = [[{{"GAUSS_MEHLER"={{n_points = 100}}}}]] + root_finder = [[{{"CPR"={{n0=2, nmax=100, epsilon=1E-6, complex_threshold=1E-12, truncation_threshold=1E-12, far_from_zero=1E6, interval_limit=1E-16, derivative_free=false}}}}]] + use_hdf5 = false + num_threads = 4 + num_chunks = 10 + track_displacements = false + track_energy_losses = false + + [particle_parameters] + length_unit = "ANGSTROM" + energy_unit = "EV" + mass_unit = "AMU" + N = [ {num_samples} ] + m = [ 1.008 ] + Z = [ 1 ] + E = [ {energy} ] + Ec = [ 0.001 ] + Es = [ 2.5 ] + interaction_index = [ 0 ] + pos = [ [ -4.4, 0.0, 0.0,] ] + dir = [ [ 0.9999999999984769, 1.7453292519934434e-6, 0.0,] ] + + [geometry_input] + length_unit = "ANGSTROM" + electronic_stopping_correction_factor = 1.09 + densities = [ 0.0914 ] + + [material_parameters] + energy_unit = "EV" + mass_unit = "AMU" + Eb = [ 0.0 ] + Es = [ 5.61 ] + Ec = [ 3.0 ] + Z = [ 28 ] + m = [ 58.69 ] + interaction_index = [ 0 ] + surface_binding_model = {{"PLANAR"={{calculation="INDIVIDUAL"}}}} + bulk_binding_model = "AVERAGE" + ''' + + with open(f'morse_{index}.toml', 'w') as file: + file.write(input_file) + + if run_sim: os.system(f'cargo run --release --features cpr_rootfinder_netlib 0D morse_{index}.toml') + + reflected_list = np.atleast_2d(np.genfromtxt(f'morse_{index}reflected.output', delimiter=',')) + if np.size(reflected_list) > 0: + num_reflected = np.shape(reflected_list)[0] + energy_reflected = np.sum(reflected_list[:, 2]) + else: + num_reflected = 0 + energy_reflected = 0. + + return num_reflected/num_samples, energy_reflected/energy/num_samples + + +#Data digitized from Fig. 1 of https://doi.org/10.1016/0022-3115(84)90433-1 +#Modeled reflection coefficients using EAM at 100 eV and below and experimentally at 100 eV and above +#Used to show that TRIM breaks down at higher incident energies +data = np.array( + [[0.2962771, 0.18217821], + [0.96344626, 0.4871287], + [3.0372448, 0.8930693], + [9.876638, 0.86534655], + [30.184526, 0.7841584], + [96.644066, 0.6217822], #note: this is the last EAM data point + [102.83226, 0.4950495], #note: this is the first experimental data point + [203.52855, 0.37623763], + [516.34265, 0.3980198], + [809.75903, 0.32277226], + [1006.2257, 0.2990099], + [2054.3218, 0.17821783], + [4129.5522, 0.13069306], + [6890.884, 0.0990099]] +) + +#Plotting the EAM data points. +energies = data[:6, 0] +r_benchmark = data[:6, 1] +plt.semilogx(energies, r_benchmark, marker='o', linestyle='', label='EAM') + +#Plotting the experimental data points. +energies = data[6:, 0] +r_benchmark = data[6:, 1] +plt.semilogx(energies, r_benchmark, marker='^', linestyle='', label='Exp.') + +#Running and plotting the H-Ni simulations with the Morse potential and updated Es +num_energies = 15 +energies = np.logspace(-1, 3, num_energies) +run_sim = False +num_samples = 1000 +R_N = np.zeros(num_energies) +R_E = np.zeros(num_energies) + +for index, energy in enumerate(energies): + R_N[index], R_E[index] = run_morse_potential(energy, index, num_samples=num_samples, run_sim=run_sim) + +plt.semilogx(energies, R_N, label='R_N Morse H-Ni, Es=2.5eV', color='purple') + + +#Plotting RustBCA data points, using the ergonomic helper function reflection_coefficient(). +energies = np.logspace(-1, 4, 40) +r_rustbca = np.array([reflection_coefficient(hydrogen, nickel, energy, 0.0, 10000) for energy in energies]) +r_n = r_rustbca[:, 0] +r_e = r_rustbca[:, 1] +plt.semilogx(energies, r_n, label='R_N, Default Settings', color='black') + + +r_thomas = [thomas_reflection(hydrogen, nickel, energy) for energy in energies] +plt.semilogx(energies, r_thomas, label='Thomas', color='red', linestyle='--') + +plt.legend() +plt.title('Reflection Coefficients H+ on Ni') +plt.xlabel('E [eV]') +plt.ylabel('R') + +plt.savefig('Morse.png') \ No newline at end of file From d68354420058eed62d97ffe5c8294b61d1a3af0a Mon Sep 17 00:00:00 2001 From: Jon Drobny Date: Fri, 20 Jan 2023 10:03:55 -0800 Subject: [PATCH 10/26] Particle input default for better library ergonomics. --- src/lib.rs | 165 ++++++++++++++---------------------------------- src/particle.rs | 39 ++++++++++++ 2 files changed, 88 insertions(+), 116 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c5c48d9f..b2805965 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -821,36 +821,21 @@ pub fn compound_bca_list_py(energies: Vec, ux: Vec, uy: Vec, uz: let m = material::Material::::new(&material_parameters, &geometry_input); let mut index: usize = 0; - for (((((((E1_, ux_), uy_), uz_), Z1_), Ec1_), Es1_), m1_) in energies.iter().zip(ux).zip(uy).zip(uz).zip(Z1).zip(Ec1).zip(Es1).zip(m1) { + for (energy, ux_, uy_, uz_, Z1_, Ec1_, Es1_, m1_) in izip!(energies, ux, uy, uz, Z1, Ec1, Es1, m1) { let mut energy_out; - let p = particle::Particle { - m: m1_*AMU, - Z: Z1_, - E: E1_*EV, - Ec: Ec1_*EV, - Es: Es1_*EV, - pos: Vector::new(x, y, z), - dir: Vector::new(ux_, uy_, uz_), - pos_origin: Vector::new(x, y, z), - pos_old: Vector::new(x, y, z), - dir_old: Vector::new(ux_, uy_, uz_), - energy_origin: E1_*EV, - asymptotic_deflection: 0.0, - stopped: false, - left: false, - incident: true, - first_step: true, - trajectory: vec![], - energies: vec![], - track_trajectories: false, - number_collision_events: 0, - backreflected: false, - interaction_index : 0, - weight: 0.0, - tag: 0, - tracked_vector: Vector::new(0., 0., 0.), - }; + + let p = particle::Particle::default_incident( + m1_, + Z1_, + energy, + Ec1_, + Es1_, + x, + ux_, + uy_, + uz_ + ); let output = bca::single_ion_bca(p, &m, &options); @@ -914,7 +899,6 @@ pub fn compound_bca_list_1D_py(ux: Vec, uy: Vec, uz: Vec, energie let mut total_output = vec![]; let mut incident = vec![]; let mut stopped = vec![]; - let num_layers_target = n2.len(); let num_species = Z2.len(); let num_incident_ions = energies.len(); @@ -965,39 +949,22 @@ pub fn compound_bca_list_1D_py(ux: Vec, uy: Vec, uz: Vec, energie let x = -m.geometry.top_energy_barrier_thickness/2.; let mut index: usize = 0; - for (((((((E1_, ux_), uy_), uz_), Z1_), Ec1_), Es1_), m1_) in energies.iter().zip(ux).zip(uy).zip(uz).zip(Z1).zip(Ec1).zip(Es1).zip(m1) { - let mut dir = Vector::new(ux_, uy_, uz_); - dir.normalize(); + for (energy, ux_, uy_, uz_, Z1_, Ec1_, Es1_, m1_) in izip!(energies, ux, uy, uz, Z1, Ec1, Es1, m1) {(); let mut energy_out; - let p = particle::Particle { - m: m1_*AMU, - Z: Z1_, - E: E1_*EV, - Ec: Ec1_*EV, - Es: Es1_*EV, - pos: Vector::new(x, y, z), - dir: dir, - pos_origin: Vector::new(x, y, z), - pos_old: Vector::new(x, y, z), - dir_old: dir, - energy_origin: E1_*EV, - asymptotic_deflection: 0.0, - stopped: false, - left: false, - incident: true, - first_step: true, - trajectory: vec![], - energies: vec![], - track_trajectories: false, - number_collision_events: 0, - backreflected: false, - interaction_index : 0, - weight: 0.0, - tag: 0, - tracked_vector: Vector::new(0., 0., 0.), - }; + + let p = particle::Particle::default_incident( + m1_, + Z1_, + energy, + Ec1_, + Es1_, + x, + ux_, + uy_, + uz_ + ); let output = bca::single_ion_bca(p, &m, &options); @@ -1293,9 +1260,6 @@ pub fn sputtering_yield(ion: &PyDict, target: &PyDict, energy: f64, angle: f64, let uy = (angle/180.0*PI).sin() + DELTA; let uz = 0.0; - let mut direction = Vector::new(ux, uy, uz); - direction.normalize(); - let material_parameters = material::MaterialParameters { energy_unit: "EV".to_string(), mass_unit: "AMU".to_string(), @@ -1323,33 +1287,17 @@ pub fn sputtering_yield(ion: &PyDict, target: &PyDict, energy: f64, angle: f64, (0..num_samples as u64).into_par_iter().for_each( |index| { - let p = particle::Particle { - m: m1*AMU, - Z: Z1, - E: energy*EV, - Ec: Ec1*EV, - Es: Es1*EV, - pos: Vector::new(x, y, z), - dir: direction, - pos_origin: Vector::new(x, y, z), - pos_old: Vector::new(x, y, z), - dir_old: direction, - energy_origin: energy*EV, - asymptotic_deflection: 0.0, - stopped: false, - left: false, - incident: true, - first_step: true, - trajectory: vec![], - energies: vec![], - track_trajectories: false, - number_collision_events: 0, - backreflected: false, - interaction_index : 0, - weight: 1.0, - tag: 0, - tracked_vector: Vector::new(0.0, 0.0, 0.0), - }; + let p = particle::Particle::default_incident( + m1, + Z1, + energy, + Ec1, + Es1, + x, + ux, + uy, + uz + ); let output = bca::single_ion_bca(p, &m, &options); @@ -1432,34 +1380,19 @@ pub fn reflection_coefficient(ion: &PyDict, target: &PyDict, energy: f64, angle: let energy_reflected = Mutex::new(0.0); (0..num_samples as u64).into_par_iter().for_each( |index| { - let p = particle::Particle { - m: m1*AMU, - Z: Z1, - E: energy*EV, - Ec: Ec1*EV, - Es: Es1*EV, - pos: Vector::new(x, y, z), - dir: direction, - pos_origin: Vector::new(x, y, z), - pos_old: Vector::new(x, y, z), - dir_old: direction, - energy_origin: energy*EV, - asymptotic_deflection: 0.0, - stopped: false, - left: false, - incident: true, - first_step: true, - trajectory: vec![], - energies: vec![], - track_trajectories: false, - number_collision_events: 0, - backreflected: false, - interaction_index : 0, - weight: 1.0, - tag: 0, - tracked_vector: Vector::new(0.0, 0.0, 0.0), - }; + let p = particle::Particle::default_incident( + m1, + Z1, + energy, + Ec1, + Es1, + x, + ux, + uy, + uz + ); + let output = bca::single_ion_bca(p, &m, &options); for particle in output { diff --git a/src/particle.rs b/src/particle.rs index e82412b3..4951b0dd 100644 --- a/src/particle.rs +++ b/src/particle.rs @@ -166,6 +166,45 @@ impl Particle { tracked_vector: Vector::new(0.0, 0.0, 0.0), } } + + /// Particle constructor from simplified input. + pub fn default_incident(m_amu: f64, Z: f64, E_eV: f64, Ec_eV: f64, Es_eV: f64, x: f64, dirx: f64, diry: f64, dirz: f64) -> Particle { + let dir_mag = (dirx*dirx + diry*diry + dirz*dirz).sqrt(); + + let y = 0.; + let z = 0.; + + assert!((dirx/dir_mag).abs() < 1.0 - f64::EPSILON, "Input error: incident direction cannot round to exactly (1, 0, 0) due to gimbal lock. Use a non-zero y-component."); + assert!(E_eV > 0., "Input error: incident energy {}; must be greater than zero.", E_eV); + + Particle { + m: m_amu*AMU, + Z: Z, + E: E_eV*EV, + Ec: Ec_eV*EV, + Es: Es_eV*EV, + pos: Vector::new(x, y, z), + dir: Vector::new(dirx/dir_mag, diry/dir_mag, dirz/dir_mag), + pos_old: Vector::new(x, y, z), + dir_old: Vector::new(dirx/dir_mag, diry/dir_mag, dirz/dir_mag), + pos_origin: Vector::new(x, y, z), + energy_origin: E_eV, + asymptotic_deflection: 0., + stopped: false, + left: false, + incident: true, + first_step: true, + trajectory: vec![], + energies: vec![EnergyLoss::new(0., 0., x, y, z)], + track_trajectories: false, + number_collision_events: 0, + backreflected: false, + interaction_index: 0, + weight: 1.0, + tag: 0, + tracked_vector: Vector::new(0.0, 0.0, 0.0), + } + } /// If `track_trajectories`, add the current (E, x, y, z) to the trajectory. pub fn add_trajectory(&mut self) { From 9a04fc1a4b6bc542873a58579c05a4c193b48981 Mon Sep 17 00:00:00 2001 From: Jon Drobny Date: Fri, 20 Jan 2023 16:08:57 -0800 Subject: [PATCH 11/26] Added python function to undo RustBCA coordinate transform. --- src/lib.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index b2805965..74ab52ab 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -98,6 +98,7 @@ pub fn pybca(py: Python, m: &PyModule) -> PyResult<()> { m.add_function(wrap_pyfunction!(reflection_coefficient, m)?)?; #[cfg(feature = "parry3d")] m.add_function(wrap_pyfunction!(rotate_given_surface_normal_py, m)?)?; + m.add_function(wrap_pyfunction!(rotate_back_py, m)?)?; Ok(()) } @@ -1219,6 +1220,49 @@ pub fn rotate_given_surface_normal_py(nx: f64, ny: f64, nz: f64, ux: f64, uy: f6 (ux, uy, uz) } +#[cfg(all(feature = "python", feature = "parry3d"))] +#[pyfunction] +/// rotate_given_surface_normal_py(nx, ny, nz, ux, uy, uz) +/// -- +/// +/// This function runs a 0D Binary Collision Approximation simulation for the given incident ions and material. +/// Args: +/// nx (f64): surface normal in global frame x-component. +/// ny (f64): surface normal in global frame y-component. +/// nz (f64): surface normal in global frame z-component. +/// ux (f64): particle direction in RustBCA frame x-component. +/// uy (f64): particle direction in RustBCA frame normal y-component. +/// uz (f64): particle direction in RustBCA frame normal z-component. +/// Returns: +/// direction (f64, f64, f64): direction vector of particle in global coordinates. +pub fn rotate_back_py(nx: f64, ny: f64, nz: f64, ux: f64, uy: f64, uz: f64) -> (f64, f64, f64) { + let RUSTBCA_DIRECTION: Vector3:: = Vector3::::new(1.0, 0.0, 0.0); + + let into_surface = Vector3::new(-nx, -ny, -nz); + let direction = Vector3::new(ux, uy, uz); + + //Rotation to local RustBCA coordinates from global + //Here's how this works: a rotation matrix is found that maps the rustbca + //into-the-surface vector (1.0, 0.0, 0.0) onto the local into-the-surface vector (negative normal w.r.t. ray origin). + //That rotation is then applied to the particle direction, and can be undone later. + //Algorithm is from here: + //https://math.stackexchange.com/questions/180418/calculate-rotation-matrix-to-align-vector-a-to-vector-b-in-3d/180436#180436 + let v: Vector3 = into_surface.cross(&RUSTBCA_DIRECTION); + let c = into_surface.dot(&RUSTBCA_DIRECTION); + let vx = Matrix3::::new(0.0, -v.z, v.y, v.z, 0.0, -v.x, -v.y, v.x, 0.0); + let rotation_matrix = if c != -1.0 { + Matrix3::identity() + vx + vx*vx/(1. + c) + } else { + //If c == -1.0, the correct rotation should simply be a 180 degree rotation + //around a non-x axis; y is chosen arbitrarily + Rotation3::from_axis_angle(&Vector3::y_axis(), PI).into() + }; + + let u = rotation_matrix.transpose()*direction; + + (u.x, u.y, u.z) +} + #[cfg(feature = "python")] /// A helper function to unpack a python float from a python any. fn unpack(python_float: &PyAny) -> f64 { From b315a29f59c26fbbbab1fedfddd4f894c05f96af Mon Sep 17 00:00:00 2001 From: Jon Drobny Date: Wed, 8 Mar 2023 09:09:26 -0800 Subject: [PATCH 12/26] Many small changes; simple_compound_bca, default particle, etc. --- Cargo.toml | 4 +-- src/lib.rs | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 77 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 430babd0..820ad5f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ required-features = ["gui"] [lib] name = "libRustBCA" path = "src/lib.rs" -crate-type = ["cdylib"] +crate-type = ["cdylib", "lib"] [dependencies] rand = "0.8.3" @@ -35,7 +35,7 @@ netlib-src = {version = "0.8", optional = true} intel-mkl-src = {version = "0.6.0", optional = true} rcpr = { git = "https://github.com/drobnyjt/rcpr", optional = true} ndarray = {version = "0.14.0", features = ["serde"], optional = true} -parry3d-f64 = {version = "0.2.0", optional = true} +parry3d-f64 = {optional = true, version="0.2.0"} egui = {version = "0.15.0", optional = true} [dependencies.pyo3] diff --git a/src/lib.rs b/src/lib.rs index 74ab52ab..8c3bae3c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -89,7 +89,7 @@ pub use parry3d_f64::na::{Point3, Vector3, Matrix3, Rotation3}; #[cfg(feature = "python")] #[pymodule] -pub fn pybca(py: Python, m: &PyModule) -> PyResult<()> { +pub fn libRustBCA(py: Python, m: &PyModule) -> PyResult<()> { m.add_function(wrap_pyfunction!(simple_bca_py, m)?)?; m.add_function(wrap_pyfunction!(simple_bca_list_py, m)?)?; m.add_function(wrap_pyfunction!(compound_bca_list_py, m)?)?; @@ -1151,6 +1151,80 @@ pub fn simple_bca(x: f64, y: f64, z: f64, ux: f64, uy: f64, uz: f64, E1: f64, Z1 ).collect() } +pub fn simple_compound_bca(x: f64, y: f64, z: f64, ux: f64, uy: f64, uz: f64, E1: f64, Z1: f64, m1: f64, Ec1: f64, Es1: f64, Z2: Vec, m2: Vec, Ec2: Vec, Es2: Vec, n2: Vec, Eb2: Vec) -> Vec<[f64; 9]> { + + assert!(E1 > 0.0, "Error: Incident energy cannot be less than or equal to 0."); + assert!(Ec1 > 0.0, "Error: Cutoff energy Ec1 cannot be less than or equal to 0."); + //assert!(Ec2 > 0.0, "Error: Cutoff energy Ec2 cannot be less than or equal to 0."); + + let options = Options::default_options(true); + + let p = particle::Particle { + m: m1*AMU, + Z: Z1, + E: E1*EV, + Ec: Ec1*EV, + Es: Es1*EV, + pos: Vector::new(x, y, z), + dir: Vector::new(ux, uy, uz), + pos_origin: Vector::new(x, y, z), + pos_old: Vector::new(x, y, z), + dir_old: Vector::new(ux, uy, uz), + energy_origin: E1*EV, + asymptotic_deflection: 0.0, + stopped: false, + left: false, + incident: true, + first_step: true, + trajectory: vec![], + energies: vec![], + track_trajectories: false, + number_collision_events: 0, + backreflected: false, + interaction_index : 0, + weight: 1.0, + tag: 0, + tracked_vector: Vector::new(0.0, 0.0, 0.0), + }; + + let material_parameters = material::MaterialParameters { + energy_unit: "EV".to_string(), + mass_unit: "AMU".to_string(), + Eb: Eb2, + Es: Es2, + Ec: Ec2, + Z: Z2, + m: m2, + interaction_index: vec![0], + surface_binding_model: SurfaceBindingModel::AVERAGE, + bulk_binding_model: BulkBindingModel::INDIVIDUAL, + }; + + let geometry_input = geometry::Mesh0DInput { + length_unit: "ANGSTROM".to_string(), + densities: n2, + electronic_stopping_correction_factor: 1.0 + }; + + let m = material::Material::::new(&material_parameters, &geometry_input); + + let output = bca::single_ion_bca(p, &m, &options); + + output.iter().filter(|particle| (particle.incident) | (particle.left)).map(|particle| + [ + particle.Z, + particle.m/AMU, + particle.E/EV, + particle.pos.x/ANGSTROM, + particle.pos.y/ANGSTROM, + particle.pos.z/ANGSTROM, + particle.dir.x, + particle.dir.y, + particle.dir.z + ] + ).collect() +} + #[cfg(feature = "parry3d")] #[no_mangle] pub extern "C" fn rotate_given_surface_normal(nx: f64, ny: f64, nz: f64, ux: &mut f64, uy: &mut f64, uz: &mut f64) { From 024b2e561c329f8a94bfee32fbc274b7599da5f6 Mon Sep 17 00:00:00 2001 From: Jon Drobny Date: Wed, 8 Mar 2023 09:13:37 -0800 Subject: [PATCH 13/26] Changes to python bindings. Breaking change. --- examples/test_rustbca.py | 1 - setup.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/test_rustbca.py b/examples/test_rustbca.py index 3dfd7979..5c57143d 100644 --- a/examples/test_rustbca.py +++ b/examples/test_rustbca.py @@ -31,7 +31,6 @@ def main(): print(f'Energy reflection coefficient for {ion["symbol"]} on {target["symbol"]} at {energy} eV is {R_E}') - #For smooth distributions and good statistics, you should use at least 10k ions number_ions = 100000 diff --git a/setup.py b/setup.py index 456243ab..d92bdf48 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ version="1.3.0", rust_extensions=[ RustExtension( - "libRustBCA.pybca", + "libRustBCA", binding=Binding.PyO3, features=["python", "parry3d"], #args=["+nightly", "--edition 2018", "-Z unstable-options"], From 9a94361e6937b83304f92d3de575e91ec886f439 Mon Sep 17 00:00:00 2001 From: Jon Drobny Date: Wed, 8 Mar 2023 10:11:26 -0800 Subject: [PATCH 14/26] updated workflow. --- .github/workflows/rustbca_compile_check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rustbca_compile_check.yml b/.github/workflows/rustbca_compile_check.yml index 5582eb90..f694a6ee 100644 --- a/.github/workflows/rustbca_compile_check.yml +++ b/.github/workflows/rustbca_compile_check.yml @@ -70,4 +70,4 @@ jobs: cat 2000.0eV_0.0001deg_He_TiO2_Al_Sisummary.output ./target/release/RustBCA SPHERE examples/boron_nitride_sphere.toml cargo run --release --features parry3d TRIMESH examples/tungsten_twist_trimesh.toml - + \ No newline at end of file From 3c3f95e8a9ddb0127f5b30ebac40a78679cb4f91 Mon Sep 17 00:00:00 2001 From: Jon Drobny Date: Wed, 8 Mar 2023 10:15:56 -0800 Subject: [PATCH 15/26] Removed reference to pybca. --- examples/test_rustbca.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/test_rustbca.py b/examples/test_rustbca.py index 5c57143d..dd8b58e9 100644 --- a/examples/test_rustbca.py +++ b/examples/test_rustbca.py @@ -1,4 +1,4 @@ -from libRustBCA.pybca import * +from libRustBCA import * import numpy as np import matplotlib.pyplot as plt import sys From d9576003addb83887833b2b52a3d8490c1563c66 Mon Sep 17 00:00:00 2001 From: Jon Drobny Date: Wed, 8 Mar 2023 10:20:57 -0800 Subject: [PATCH 16/26] Removed another reference to pybca from workflow. --- .github/workflows/rustbca_compile_check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rustbca_compile_check.yml b/.github/workflows/rustbca_compile_check.yml index f694a6ee..329c048a 100644 --- a/.github/workflows/rustbca_compile_check.yml +++ b/.github/workflows/rustbca_compile_check.yml @@ -44,7 +44,7 @@ jobs: python3 -m pip install setuptools_rust testresources setuptools wheel python3 -m pip install --upgrade pip setuptools wheel python3 -m pip install . - python3 -c "from libRustBCA.pybca import *;" + python3 -c "from libRustBCA import *;" python3 examples/test_rustbca.py - name: Test Fortran and C bindings run : | From b136ef207467fba8820acaa83163f6d776e1b6c3 Mon Sep 17 00:00:00 2001 From: Jon Drobny Date: Thu, 9 Mar 2023 09:11:19 -0800 Subject: [PATCH 17/26] Removed further references to pybca. --- examples/benchmark_eam.py | 2 +- examples/benchmark_nnp.py | 132 ++++++++++++++++++++++++++++++++++++++ examples/test_morse.py | 2 +- 3 files changed, 134 insertions(+), 2 deletions(-) create mode 100644 examples/benchmark_nnp.py diff --git a/examples/benchmark_eam.py b/examples/benchmark_eam.py index 0e606024..5ebc5455 100644 --- a/examples/benchmark_eam.py +++ b/examples/benchmark_eam.py @@ -1,4 +1,4 @@ -from libRustBCA.pybca import * +from libRustBCA import * import numpy as np import matplotlib.pyplot as plt import sys diff --git a/examples/benchmark_nnp.py b/examples/benchmark_nnp.py new file mode 100644 index 00000000..4d4eb45a --- /dev/null +++ b/examples/benchmark_nnp.py @@ -0,0 +1,132 @@ +from libRustBCA import * +import numpy as np +import matplotlib.pyplot as plt +import sys +import os +#This should allow the script to find materials and formulas from anywhere +sys.path.append(os.path.dirname(__file__)+'/../scripts') +sys.path.append('scripts') +from materials import * +from formulas import * + +R_T_Be = np.array( + [ + [9.67742, 0.016754618], + [20.32258, 0.09511873], + [30.0, 0.13153034], + [49.677418, 0.102242745], + [74.83871, 0.08403694], + [100.32258, 0.031002639], + ] +) + +R_D_Be = np.array( + [ + [10.32258, 0.11649077], + [20.32258, 0.19168866], + [30.32258, 0.19722955], + [49.677418, 0.17269129], + [75.16129, 0.11174142], + [100.0, 0.044459105], + ] +) + +R_H_Be = np.array( + [ + [9.67742, 0.19485489], + [19.67742, 0.32150397], + [30.0, 0.33575198], + [50.322582, 0.25105542], + [75.16129, 0.1378628], + [100.645164, 0.044459105], + ] +) + +#Plotting the MD data points. +energies = R_H_Be[:, 0] +R = R_H_Be[:, 1] +plt.plot(energies, R, marker='o', linestyle='', label='H on Be MD+NNP') + +#Plotting the MD data points. +energies = R_D_Be[:, 0] +R = R_D_Be[:, 1] +plt.plot(energies, R, marker='x', linestyle='', label='D on Be MD+NNP') + +#Plotting the MD data points. +energies = R_T_Be[:, 0] +R = R_T_Be[:, 1] +plt.plot(energies, R, marker='^', linestyle='', label='T on Be MD+NNP') + + +for ion in [hydrogen, deuterium, tritium]: + energies = np.logspace(1, 2, 25) + r_rustbca = [reflection_coefficient(ion, beryllium, energy, 0.0, 10000)[0] for energy in energies] + r_thomas = [thomas_reflection(ion, beryllium, energy) for energy in energies] + line = plt.plot(energies, r_rustbca, label=f'{ion["symbol"]} on Be RustBCA')[0] + plt.plot(energies, r_thomas, label=f'{ion["symbol"]} on Be Thomas', linestyle='--', color=line.get_color()) + +plt.xlabel('E [eV]') +plt.ylabel('R_N') +plt.title('Reflection Coefficients') +plt.legend() +plt.savefig('reflection_md_nnp_rustbca.png') + +#Data digitized from https://doi.org/10.1088/1741-4326/ac592a +#MD+NNP Sputtering Yields +y_H_Be = np.array([ + [20.004726, 0.0029361406], + [29.880848, 0.013341782], + [49.791046, 0.024575423], + [75.00529, 0.016207783], + [99.68844, 0.017530797], +]) + +y_D_Be = np.array([ + [19.9699, 0.005002439], + [29.601622, 0.021064475], + [49.76866, 0.03461476], + [74.71549, 0.030082114], + [99.954605, 0.013559438], +]) + +y_T_Be = np.array([ + [20.013433, 0.0025699555], + [29.85846, 0.01879205], + [49.756844, 0.04147379], + [74.707405, 0.034042966], + [99.68098, 0.01965117], +]) + + +plt.figure() + +#Plotting the MD data points. +energies = y_H_Be[:, 0] +y = y_H_Be[:, 1] +plt.semilogy(energies, y, marker='o', linestyle='', label='H on Be MD+NNP') + +#Plotting the MD data points. +energies = y_D_Be[:, 0] +y = y_D_Be[:, 1] +plt.semilogy(energies, y, marker='x', linestyle='', label='D on Be MD+NNP') + +#Plotting the MD data points. +energies = y_T_Be[:, 0] +y = y_T_Be[:, 1] +plt.semilogy(energies, y, marker='^', linestyle='', label='T on Be MD+NNP') + +for ion in [hydrogen, deuterium, tritium]: + energies = np.logspace(1, 2, 25) + y_rustbca = [sputtering_yield(ion, beryllium, energy, 0.0, 100000) for energy in energies] + plt.semilogy(energies, y_rustbca, label=f'{ion["symbol"]} on Be RustBCA') + +yamamura_yield = [yamamura(hydrogen, beryllium, energy) for energy in energies] +plt.semilogy(energies, yamamura_yield, label='Yamamura H on Be', linestyle='--') + +plt.title('Sputtering Yields of Hydrogenic Species on Be') +plt.xlabel('E [eV]') +plt.ylabel('Y [at/ion]') +plt.gca().set_ylim([1e-4, 1e-1]) +plt.legend(loc='lower right') + +plt.savefig('sputtering_md_nnp_rustbca.png') \ No newline at end of file diff --git a/examples/test_morse.py b/examples/test_morse.py index 39b0a9d2..e3e0607a 100644 --- a/examples/test_morse.py +++ b/examples/test_morse.py @@ -1,4 +1,4 @@ -from libRustBCA.pybca import * +from libRustBCA import * import numpy as np import matplotlib.pyplot as plt import sys From 15ddc67fb1c216508c40d0777d968d141d695c3f Mon Sep 17 00:00:00 2001 From: Jon Drobny Date: Thu, 9 Mar 2023 09:12:54 -0800 Subject: [PATCH 18/26] Removed further refs to pybca. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0f400636..72eca5eb 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ python -m pip install . python Python 3.9.6 (tags/v3.9.6:db3ff76, Jun 28 2021, 15:26:21) [MSC v.1929 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. ->>> from libRustBCA.pybca import *; from scripts.materials import * +>>> from libRustBCA import *; from scripts.materials import * >>> angle = 0.0 # deg >>> energy = 1000.0 # eV >>> num_samples = 10000 From f5c2858bee7bd33c8751d4f34e62ea1b82084afe Mon Sep 17 00:00:00 2001 From: Jon Drobny Date: Thu, 9 Mar 2023 09:15:45 -0800 Subject: [PATCH 19/26] Update version numbers. --- Cargo.toml | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 49947c1a..551fb563 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "RustBCA" -version = "1.3.0" +version = "2.0.0" default-run = "RustBCA" authors = ["Jon Drobny ", "Jon Drobny "] edition = "2018" diff --git a/setup.py b/setup.py index d92bdf48..93875739 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name="RustBCA", - version="1.3.0", + version="2.0.0", rust_extensions=[ RustExtension( "libRustBCA", From 0f5d8063dc35b53bc955c6f7757826ed74c939e3 Mon Sep 17 00:00:00 2001 From: Jon Drobny Date: Thu, 9 Mar 2023 09:45:29 -0800 Subject: [PATCH 20/26] Minor changes to readme. --- README.md | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 72eca5eb..23138029 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ and Fortran. By discretizing the collision cascade into a sequence of binary collisions, [BCA] codes can accurately and efficiently model the prompt interaction between an energetic ion and a target material. This includes reflection, -implantation, and transmission of the incident ion, s well as sputtering +implantation, and transmission of the incident ion, as well as sputtering and displacement damage of the target. Generally, [BCA] codes can be valid for incident ion energies between approximately ~1 eV/nucleon to <1 GeV/nucleon. @@ -23,11 +23,12 @@ Journal of Open Source Software by clicking the badge below: ## Getting started -The easiest way to get started is with the ergonomic Python functions currently on the development branch. Follow these steps to install, build, and run simple RustBCA simulations for sputtering yields and reflection coefficients: +The easiest way to get started is with the ergonomic Python functions. +Follow these steps to install, build, and run simple RustBCA simulations +for sputtering yields and reflection coefficients: ``` git clone https://github.com/lcpp-org/rustbca cd rustbca -git checkout dev python -m pip install . python Python 3.9.6 (tags/v3.9.6:db3ff76, Jun 28 2021, 15:26:21) [MSC v.1929 64 bit (AMD64)] on win32 @@ -44,7 +45,8 @@ Type "help", "copyright", "credits" or "license" for more information. ``` For those eager to get started with the standalone code, try running one of the examples in the -`RustBCA/examples` directory. Note that to automatically manipulate input files and reproduce the plots located on the [Wiki], these require several optional, but common, +`RustBCA/examples` directory. Note that to automatically manipulate input files and reproduce +the plots located on the [Wiki], these require several optional, but common, [Python] packages (`matplotlib`, `numpy`, `scipy`, `shapely`, and `toml`). ### H trajectories and collision cascades in a boron nitride dust grain @@ -94,17 +96,17 @@ plt.show() The following features are implemented in `rustBCA`: * Ion-material interactions for all combinations of incident ion and target species. -* Infinite, homogeneous targets (Mesh0D), Layered, finite-depth inhomogeneous targets (Mesh1D), arbitrary 2D geometry composition through a triangular mesh (Mesh2D), homogeneous spherical geometry (Sphere) and homogeneous, arbitrary triangular mesh geometry (TriMesh). +* Infinite, homogeneous targets (Mesh0D), Layered, finite-depth inhomogeneous targets (Mesh1D), arbitrary 2D composition through a triangular mesh (Mesh2D), homogeneous spherical geometry (Sphere) and homogeneous 3D triangular mesh geometry (TriMesh). * Amorphous Solid/Liquid targets, Gaseous targets, and targets with both solid/liquid and gaseous elements * Low energy (< 25 keV/nucleon) electronic stopping modes including: * local (Oen-Robinson), * nonlocal (Lindhard-Scharff), - * and equipartition forms. + * and equipartition * Biersack-Varelas interpolation is also included for electronic stopping up to ~1 GeV/nucleon. Note that high energy physics beyond electronic stopping are not included. * Optionally, the Biersack-Haggmark treatment of high-energy free-flight paths between collisions can be included to greatly speed up high-energy simulations (i.e., by neglecting very small angle scattering). * A wide range of interaction potentials are provided, including: * the Kr-C, ZBL, Lenz-Jensen, and Moliere universal, screened-Coulomb potentials. - * the Lennard-Jones 12-6, Lennard-Jones 6.5-6, and Morse attractive-repulsive potentials. + * the Lennard-Jones 12-6 and Morse attractive-repulsive potentials. * Solving the distance-of-closest-approach problem is achieved using: * the Newton-Raphson method for simple root-finding, * or, for attractive-repulsive potentials, an Adaptive Chebyshev Proxy Rootfinder with Automatic Subdivision algorithm and a Polynomial root-finding algorithm are provided through the [rcpr] crate. @@ -249,7 +251,7 @@ automatically during the build. ## Usage -To use `RustBCA`, modify the `input.toml` file, which is used to configure each +To use `RustBCA`, modify an `input.toml` file, which is used to configure each simulation. To run a simulation, execute: @@ -279,4 +281,4 @@ Also have a look at the examples on the [Wiki] for writing `.toml` input files. [rustup]: https://rustup.rs [Rust]: https://en.wikipedia.org/wiki/Rust_(programming_language) [TOML]: https://en.wikipedia.org/wiki/TOML -[Wiki]: https://github.com/lcpp-org/RustBCA/wiki +[Wiki]: https://github.com/lcpp-org/RustBCA/wiki \ No newline at end of file From 815857ed124ba6f11a47a199a0433adfa4334e30 Mon Sep 17 00:00:00 2001 From: Jon Drobny Date: Thu, 9 Mar 2023 09:55:18 -0800 Subject: [PATCH 21/26] Fix issue #204. --- src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 283efc36..f851c31c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -855,9 +855,9 @@ pub fn compound_bca_list_py(energies: Vec, ux: Vec, uy: Vec, uz: particle.Z, particle.m/AMU, energy_out, - particle.pos.x, - particle.pos.y, - particle.pos.z, + particle.pos.x/ANGSTROM, + particle.pos.y/ANGSTROM, + particle.pos.z/ANGSTROM, particle.dir.x, particle.dir.y, particle.dir.z, From 5635c12f59ddd750f0751f8052f04fc116acdfe2 Mon Sep 17 00:00:00 2001 From: Jon Drobny Date: Thu, 9 Mar 2023 15:52:44 -0800 Subject: [PATCH 22/26] GetDP triangles version. --- examples/boron_nitride.toml | 43 ---------------------------------- examples/layered_geometry.toml | 5 ++-- src/geometry.rs | 43 +++++++++++++++++++++++++++++----- src/tests.rs | 15 +++++++----- 4 files changed, 49 insertions(+), 57 deletions(-) delete mode 100644 examples/boron_nitride.toml diff --git a/examples/boron_nitride.toml b/examples/boron_nitride.toml deleted file mode 100644 index 6367a6b6..00000000 --- a/examples/boron_nitride.toml +++ /dev/null @@ -1,43 +0,0 @@ -[options] -name = "boron_dust_grain_" -track_trajectories = true -track_recoils = true -track_recoil_trajectories = true -num_threads = 4 -num_chunks = 10 - - -[material_parameters] -energy_unit = "EV" -mass_unit = "AMU" -Eb = [ 0.0, 0.0,] -Es = [ 5.76, 0.0,] -Ec = [ 0.5, 0.5,] -Z = [ 5, 7,] -m = [ 10.811, 14,] -interaction_index = [0, 0] -surface_binding_model = {"PLANAR"={calculation="TARGET"}} -bulk_binding_model = "AVERAGE" - -[particle_parameters] -length_unit = "MICRON" -energy_unit = "EV" -mass_unit = "AMU" -N = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,] -m = [ 1.008, 1.008, 1.008, 1.008, 1.008, 1.008, 1.008, 1.008, 1.008, 1.008,] -Z = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,] -E = [ 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0, 1000.0,] -Ec = [ 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,] -Es = [ 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0,] -pos = [ [ -0.021, 0.0, 0.0,], [ -0.021, 0.0, 0.0,], [ -0.021, 0.0, 0.0,], [ -0.021, 0.0, 0.0,], [ -0.021, 0.0, 0.0,], [ -0.021, 0.0, 0.0,], [ -0.021, 0.0, 0.0,], [ -0.021, 0.0, 0.0,], [ -0.021, 0.0, 0.0,], [ -0.021, 0.0, 0.0,],] -dir = [ [ 0.9999999999984769, 1.7453292519934434e-6, 0.0,], [ 0.9999999999984769, 1.7453292519934434e-6, 0.0,], [ 0.9999999999984769, 1.7453292519934434e-6, 0.0,], [ 0.9999999999984769, 1.7453292519934434e-6, 0.0,], [ 0.9999999999984769, 1.7453292519934434e-6, 0.0,], [ 0.9999999999984769, 1.7453292519934434e-6, 0.0,], [ 0.9999999999984769, 1.7453292519934434e-6, 0.0,], [ 0.9999999999984769, 1.7453292519934434e-6, 0.0,], [ 0.9999999999984769, 1.7453292519934434e-6, 0.0,], [ 0.9999999999984769, 1.7453292519934434e-6, 0.0,],] -interaction_index = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] - -[geometry_input] -length_unit = "MICRON" -energy_barrier_thickness = 1.7645653881793786e-4 -triangles = [ [ 0.0, 0.0, 0.0012558103905862675, 0.0, 0.02, 0.019960534568565433,], [ 0.0, 0.0012558103905862675, 0.0025066646712860853, 0.0, 0.019960534568565433, 0.019842294026289557,], [ 0.0, 0.0025066646712860853, 0.003747626291714493, 0.0, 0.019842294026289557, 0.019645745014573775,], [ 0.0, 0.003747626291714493, 0.004973797743297096, 0.0, 0.019645745014573775, 0.01937166322257262,], [ 0.0, 0.004973797743297096, 0.0061803398874989484, 0.0, 0.01937166322257262, 0.019021130325903073,], [ 0.0, 0.0061803398874989484, 0.00736249105369356, 0.0, 0.019021130325903073, 0.018595529717765027,], [ 0.0, 0.00736249105369356, 0.008515585831301454, 0.0, 0.018595529717765027, 0.01809654104932039,], [ 0.0, 0.008515585831301454, 0.009635073482034308, 0.0, 0.01809654104932039, 0.01752613360087727,], [ 0.0, 0.009635073482034308, 0.010716535899579934, 0.0, 0.01752613360087727, 0.0168865585100403,], [ 0.0, 0.010716535899579934, 0.011755705045849463, 0.0, 0.0168865585100403, 0.016180339887498948,], [ 0.0, 0.011755705045849463, 0.012748479794973795, 0.0, 0.016180339887498948, 0.015410264855515783,], [ 0.0, 0.012748479794973795, 0.013690942118573775, 0.0, 0.015410264855515783, 0.014579372548428232,], [ 0.0, 0.013690942118573775, 0.014579372548428232, 0.0, 0.014579372548428232, 0.013690942118573773,], [ 0.0, 0.014579372548428232, 0.015410264855515785, 0.0, 0.013690942118573773, 0.012748479794973793,], [ 0.0, 0.015410264855515785, 0.016180339887498948, 0.0, 0.012748479794973793, 0.011755705045849461,], [ 0.0, 0.016180339887498948, 0.0168865585100403, 0.0, 0.011755705045849461, 0.01071653589957993,], [ 0.0, 0.0168865585100403, 0.017526133600877274, 0.0, 0.01071653589957993, 0.009635073482034304,], [ 0.0, 0.017526133600877274, 0.018096541049320392, 0.0, 0.009635073482034304, 0.008515585831301454,], [ 0.0, 0.018096541049320392, 0.01859552971776503, 0.0, 0.008515585831301454, 0.007362491053693557,], [ 0.0, 0.01859552971776503, 0.019021130325903073, 0.0, 0.007362491053693557, 0.006180339887498949,], [ 0.0, 0.019021130325903073, 0.01937166322257262, 0.0, 0.006180339887498949, 0.004973797743297095,], [ 0.0, 0.01937166322257262, 0.019645745014573775, 0.0, 0.004973797743297095, 0.0037476262917144902,], [ 0.0, 0.019645745014573775, 0.019842294026289557, 0.0, 0.0037476262917144902, 0.0025066646712860853,], [ 0.0, 0.019842294026289557, 0.019960534568565433, 0.0, 0.0025066646712860853, 0.001255810390586266,], [ 0.0, 0.019960534568565433, 0.02, 0.0, 0.001255810390586266, -3.2162452993532734e-18,], [ 0.0, 0.02, 0.019960534568565433, 0.0, -3.2162452993532734e-18, -0.001255810390586268,], [ 0.0, 0.019960534568565433, 0.019842294026289557, 0.0, -0.001255810390586268, -0.0025066646712860875,], [ 0.0, 0.019842294026289557, 0.019645745014573772, 0.0, -0.0025066646712860875, -0.0037476262917144967,], [ 0.0, 0.019645745014573772, 0.01937166322257262, 0.0, -0.0037476262917144967, -0.004973797743297097,], [ 0.0, 0.01937166322257262, 0.019021130325903073, 0.0, -0.004973797743297097, -0.006180339887498951,], [ 0.0, 0.019021130325903073, 0.01859552971776503, 0.0, -0.006180339887498951, -0.00736249105369356,], [ 0.0, 0.01859552971776503, 0.01809654104932039, 0.0, -0.00736249105369356, -0.008515585831301454,], [ 0.0, 0.01809654104932039, 0.01752613360087727, 0.0, -0.008515585831301454, -0.00963507348203431,], [ 0.0, 0.01752613360087727, 0.0168865585100403, 0.0, -0.00963507348203431, -0.010716535899579938,], [ 0.0, 0.0168865585100403, 0.016180339887498948, 0.0, -0.010716535899579938, -0.011755705045849461,], [ 0.0, 0.016180339887498948, 0.015410264855515785, 0.0, -0.011755705045849461, -0.012748479794973795,], [ 0.0, 0.015410264855515785, 0.014579372548428228, 0.0, -0.012748479794973795, -0.013690942118573775,], [ 0.0, 0.014579372548428228, 0.01369094211857377, 0.0, -0.013690942118573775, -0.014579372548428234,], [ 0.0, 0.01369094211857377, 0.01274847979497379, 0.0, -0.014579372548428234, -0.015410264855515788,], [ 0.0, 0.01274847979497379, 0.011755705045849465, 0.0, -0.015410264855515788, -0.016180339887498948,], [ 0.0, 0.011755705045849465, 0.010716535899579934, 0.0, -0.016180339887498948, -0.0168865585100403,], [ 0.0, 0.010716535899579934, 0.009635073482034304, 0.0, -0.0168865585100403, -0.01752613360087727,], [ 0.0, 0.009635073482034304, 0.00851558583130145, 0.0, -0.01752613360087727, -0.018096541049320392,], [ 0.0, 0.00851558583130145, 0.007362491053693555, 0.0, -0.018096541049320392, -0.01859552971776503,], [ 0.0, 0.007362491053693555, 0.006180339887498942, 0.0, -0.01859552971776503, -0.019021130325903073,], [ 0.0, 0.006180339887498942, 0.004973797743297097, 0.0, -0.019021130325903073, -0.01937166322257262,], [ 0.0, 0.004973797743297097, 0.0037476262917144915, 0.0, -0.01937166322257262, -0.019645745014573775,], [ 0.0, 0.0037476262917144915, 0.002506664671286082, 0.0, -0.019645745014573775, -0.019842294026289557,], [ 0.0, 0.002506664671286082, 0.0012558103905862628, 0.0, -0.019842294026289557, -0.019960534568565433,], [ 0.0, 0.0012558103905862628, -6.432490598706547e-18, 0.0, -0.019960534568565433, -0.02,], [ 0.0, -6.432490598706547e-18, -0.0012558103905862669, 0.0, -0.02, -0.019960534568565433,], [ 0.0, -0.0012558103905862669, -0.0025066646712860858, 0.0, -0.019960534568565433, -0.019842294026289557,], [ 0.0, -0.0025066646712860858, -0.0037476262917144954, 0.0, -0.019842294026289557, -0.019645745014573772,], [ 0.0, -0.0037476262917144954, -0.0049737977432971, 0.0, -0.019645745014573772, -0.01937166322257262,], [ 0.0, -0.0049737977432971, -0.0061803398874989545, 0.0, -0.01937166322257262, -0.019021130325903073,], [ 0.0, -0.0061803398874989545, -0.007362491053693567, 0.0, -0.019021130325903073, -0.018595529717765024,], [ 0.0, -0.007362491053693567, -0.008515585831301454, 0.0, -0.018595529717765024, -0.01809654104932039,], [ 0.0, -0.008515585831301454, -0.009635073482034308, 0.0, -0.01809654104932039, -0.01752613360087727,], [ 0.0, -0.009635073482034308, -0.010716535899579936, 0.0, -0.01752613360087727, -0.0168865585100403,], [ 0.0, -0.010716535899579936, -0.011755705045849468, 0.0, -0.0168865585100403, -0.016180339887498944,], [ 0.0, -0.011755705045849468, -0.0127484797949738, 0.0, -0.016180339887498944, -0.015410264855515781,], [ 0.0, -0.0127484797949738, -0.013690942118573775, 0.0, -0.015410264855515781, -0.014579372548428232,], [ 0.0, -0.013690942118573775, -0.014579372548428232, 0.0, -0.014579372548428232, -0.013690942118573773,], [ 0.0, -0.014579372548428232, -0.015410264855515788, 0.0, -0.013690942118573773, -0.01274847979497379,], [ 0.0, -0.015410264855515788, -0.016180339887498948, 0.0, -0.01274847979497379, -0.011755705045849465,], [ 0.0, -0.016180339887498948, -0.016886558510040308, 0.0, -0.011755705045849465, -0.010716535899579927,], [ 0.0, -0.016886558510040308, -0.01752613360087727, 0.0, -0.010716535899579927, -0.009635073482034306,], [ 0.0, -0.01752613360087727, -0.018096541049320396, 0.0, -0.009635073482034306, -0.008515585831301443,], [ 0.0, -0.018096541049320396, -0.01859552971776503, 0.0, -0.008515585831301443, -0.007362491053693556,], [ 0.0, -0.01859552971776503, -0.019021130325903073, 0.0, -0.007362491053693556, -0.006180339887498951,], [ 0.0, -0.019021130325903073, -0.019371663222572624, 0.0, -0.006180339887498951, -0.004973797743297089,], [ 0.0, -0.019371663222572624, -0.019645745014573775, 0.0, -0.004973797743297089, -0.003747626291714493,], [ 0.0, -0.019645745014573775, -0.019842294026289557, 0.0, -0.003747626291714493, -0.0025066646712860745,], [ 0.0, -0.019842294026289557, -0.019960534568565433, 0.0, -0.0025066646712860745, -0.001255810390586264,], [ 0.0, -0.019960534568565433, -0.02, 0.0, -0.001255810390586264, -3.673940397442059e-18,], [ 0.0, -0.02, -0.019960534568565433, 0.0, -3.673940397442059e-18, 0.0012558103905862745,], [ 0.0, -0.019960534568565433, -0.019842294026289557, 0.0, 0.0012558103905862745, 0.0025066646712860845,], [ 0.0, -0.019842294026289557, -0.019645745014573772, 0.0, 0.0025066646712860845, 0.003747626291714503,], [ 0.0, -0.019645745014573772, -0.01937166322257262, 0.0, 0.003747626291714503, 0.004973797743297099,], [ 0.0, -0.01937166322257262, -0.019021130325903073, 0.0, 0.004973797743297099, 0.006180339887498945,], [ 0.0, -0.019021130325903073, -0.018595529717765024, 0.0, 0.006180339887498945, 0.007362491053693565,], [ 0.0, -0.018595529717765024, -0.018096541049320392, 0.0, 0.007362491053693565, 0.008515585831301452,], [ 0.0, -0.018096541049320392, -0.017526133600877267, 0.0, 0.008515585831301452, 0.009635073482034314,], [ 0.0, -0.017526133600877267, -0.0168865585100403, 0.0, 0.009635073482034314, 0.010716535899579936,], [ 0.0, -0.0168865585100403, -0.01618033988749894, 0.0, 0.010716535899579936, 0.011755705045849473,], [ 0.0, -0.01618033988749894, -0.015410264855515781, 0.0, 0.011755705045849473, 0.0127484797949738,], [ 0.0, -0.015410264855515781, -0.014579372548428232, 0.0, 0.0127484797949738, 0.013690942118573773,], [ 0.0, -0.014579372548428232, -0.013690942118573766, 0.0, 0.013690942118573773, 0.014579372548428239,], [ 0.0, -0.013690942118573766, -0.012748479794973793, 0.0, 0.014579372548428239, 0.015410264855515788,], [ 0.0, -0.012748479794973793, -0.011755705045849453, 0.0, 0.015410264855515788, 0.016180339887498955,], [ 0.0, -0.011755705045849453, -0.010716535899579927, 0.0, 0.016180339887498955, 0.016886558510040305,], [ 0.0, -0.010716535899579927, -0.009635073482034308, 0.0, 0.016886558510040305, 0.01752613360087727,], [ 0.0, -0.009635073482034308, -0.008515585831301445, 0.0, 0.01752613360087727, 0.018096541049320396,], [ 0.0, -0.008515585831301445, -0.007362491053693557, 0.0, 0.018096541049320396, 0.01859552971776503,], [ 0.0, -0.007362491053693557, -0.006180339887498935, 0.0, 0.01859552971776503, 0.019021130325903076,], [ 0.0, -0.006180339887498935, -0.00497379774329709, 0.0, 0.019021130325903076, 0.019371663222572624,], [ 0.0, -0.00497379774329709, -0.0037476262917144937, 0.0, 0.019371663222572624, 0.019645745014573775,], [ 0.0, -0.0037476262917144937, -0.002506664671286076, 0.0, 0.019645745014573775, 0.019842294026289557,], [ 0.0, -0.002506664671286076, -0.0012558103905862654, 0.0, 0.019842294026289557, 0.019960534568565433,], [ 0.0, -0.0012558103905862654, -4.898587196589413e-18, 0.0, 0.019960534568565433, 0.02,],] -densities = [ [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,], [ 6.5E+10, 6.5E+10,],] -material_boundary_points = [ [ 0.0, 0.02,], [ 0.0012558103905862675, 0.019960534568565433,], [ 0.0025066646712860853, 0.019842294026289557,], [ 0.003747626291714493, 0.019645745014573775,], [ 0.004973797743297096, 0.01937166322257262,], [ 0.0061803398874989484, 0.019021130325903073,], [ 0.00736249105369356, 0.018595529717765027,], [ 0.008515585831301454, 0.01809654104932039,], [ 0.009635073482034308, 0.01752613360087727,], [ 0.010716535899579934, 0.0168865585100403,], [ 0.011755705045849463, 0.016180339887498948,], [ 0.012748479794973795, 0.015410264855515783,], [ 0.013690942118573775, 0.014579372548428232,], [ 0.014579372548428232, 0.013690942118573773,], [ 0.015410264855515785, 0.012748479794973793,], [ 0.016180339887498948, 0.011755705045849461,], [ 0.0168865585100403, 0.01071653589957993,], [ 0.017526133600877274, 0.009635073482034304,], [ 0.018096541049320392, 0.008515585831301454,], [ 0.01859552971776503, 0.007362491053693557,], [ 0.019021130325903073, 0.006180339887498949,], [ 0.01937166322257262, 0.004973797743297095,], [ 0.019645745014573775, 0.0037476262917144902,], [ 0.019842294026289557, 0.0025066646712860853,], [ 0.019960534568565433, 0.001255810390586266,], [ 0.02, -3.2162452993532734e-18,], [ 0.019960534568565433, -0.001255810390586268,], [ 0.019842294026289557, -0.0025066646712860875,], [ 0.019645745014573772, -0.0037476262917144967,], [ 0.01937166322257262, -0.004973797743297097,], [ 0.019021130325903073, -0.006180339887498951,], [ 0.01859552971776503, -0.00736249105369356,], [ 0.01809654104932039, -0.008515585831301454,], [ 0.01752613360087727, -0.00963507348203431,], [ 0.0168865585100403, -0.010716535899579938,], [ 0.016180339887498948, -0.011755705045849461,], [ 0.015410264855515785, -0.012748479794973795,], [ 0.014579372548428228, -0.013690942118573775,], [ 0.01369094211857377, -0.014579372548428234,], [ 0.01274847979497379, -0.015410264855515788,], [ 0.011755705045849465, -0.016180339887498948,], [ 0.010716535899579934, -0.0168865585100403,], [ 0.009635073482034304, -0.01752613360087727,], [ 0.00851558583130145, -0.018096541049320392,], [ 0.007362491053693555, -0.01859552971776503,], [ 0.006180339887498942, -0.019021130325903073,], [ 0.004973797743297097, -0.01937166322257262,], [ 0.0037476262917144915, -0.019645745014573775,], [ 0.002506664671286082, -0.019842294026289557,], [ 0.0012558103905862628, -0.019960534568565433,], [ -6.432490598706547e-18, -0.02,], [ -0.0012558103905862669, -0.019960534568565433,], [ -0.0025066646712860858, -0.019842294026289557,], [ -0.0037476262917144954, -0.019645745014573772,], [ -0.0049737977432971, -0.01937166322257262,], [ -0.0061803398874989545, -0.019021130325903073,], [ -0.007362491053693567, -0.018595529717765024,], [ -0.008515585831301454, -0.01809654104932039,], [ -0.009635073482034308, -0.01752613360087727,], [ -0.010716535899579936, -0.0168865585100403,], [ -0.011755705045849468, -0.016180339887498944,], [ -0.0127484797949738, -0.015410264855515781,], [ -0.013690942118573775, -0.014579372548428232,], [ -0.014579372548428232, -0.013690942118573773,], [ -0.015410264855515788, -0.01274847979497379,], [ -0.016180339887498948, -0.011755705045849465,], [ -0.016886558510040308, -0.010716535899579927,], [ -0.01752613360087727, -0.009635073482034306,], [ -0.018096541049320396, -0.008515585831301443,], [ -0.01859552971776503, -0.007362491053693556,], [ -0.019021130325903073, -0.006180339887498951,], [ -0.019371663222572624, -0.004973797743297089,], [ -0.019645745014573775, -0.003747626291714493,], [ -0.019842294026289557, -0.0025066646712860745,], [ -0.019960534568565433, -0.001255810390586264,], [ -0.02, -3.673940397442059e-18,], [ -0.019960534568565433, 0.0012558103905862745,], [ -0.019842294026289557, 0.0025066646712860845,], [ -0.019645745014573772, 0.003747626291714503,], [ -0.01937166322257262, 0.004973797743297099,], [ -0.019021130325903073, 0.006180339887498945,], [ -0.018595529717765024, 0.007362491053693565,], [ -0.018096541049320392, 0.008515585831301452,], [ -0.017526133600877267, 0.009635073482034314,], [ -0.0168865585100403, 0.010716535899579936,], [ -0.01618033988749894, 0.011755705045849473,], [ -0.015410264855515781, 0.0127484797949738,], [ -0.014579372548428232, 0.013690942118573773,], [ -0.013690942118573766, 0.014579372548428239,], [ -0.012748479794973793, 0.015410264855515788,], [ -0.011755705045849453, 0.016180339887498955,], [ -0.010716535899579927, 0.016886558510040305,], [ -0.009635073482034308, 0.01752613360087727,], [ -0.008515585831301445, 0.018096541049320396,], [ -0.007362491053693557, 0.01859552971776503,], [ -0.006180339887498935, 0.019021130325903076,], [ -0.00497379774329709, 0.019371663222572624,], [ -0.0037476262917144937, 0.019645745014573775,], [ -0.002506664671286076, 0.019842294026289557,], [ -0.0012558103905862654, 0.019960534568565433,], [ -4.898587196589413e-18, 0.02,],] -simulation_boundary_points = [ [ 0.03, -0.03,], [ -0.03, -0.03,], [ -0.03, 0.03,], [ 0.03, 0.03,], [ 0.03, -0.03,],] -electronic_stopping_correction_factors = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] diff --git a/examples/layered_geometry.toml b/examples/layered_geometry.toml index 46d5c207..e4f3cd82 100644 --- a/examples/layered_geometry.toml +++ b/examples/layered_geometry.toml @@ -49,9 +49,10 @@ dir = [ [ 0.999, 0.001, 0.0,],] [geometry_input] length_unit = "MICRON" -triangles = [ [ 0.0, 0.01, 0.0, 0.5, 0.5, -0.5,], [ 0.0, 0.01, 0.01, -0.5, 0.5, -0.5,], [ 0.01, 0.01, 0.04, -0.5, 0.5, -0.5,], [ 0.01, 0.04, 0.04, 0.5, 0.5, -0.5,], [ 0.04, 0.5, 0.04, 0.5, 0.5, -0.5,], [ 0.04, 0.5, 0.5, -0.5, 0.5, -0.5,],] +points = [[0.0, -0.5], [0.01, -0.5], [0.04, -0.5], [0.5, -0.5], [0.5, 0.5], [0.04, 0.5], [0.01, 0.5], [0.0, 0.5]] +triangles = [[0, 1, 6], [0, 6, 7], [1, 2, 5], [1, 5, 6], [2, 3, 4], [2, 4, 5]] densities = [ [ 3.0e+10, 6.0e+10, 0.0, 0.0,], [ 3.0e+10, 6.0e+10, 0.0, 0.0,], [ 0.0, 0.0, 6.026e+10, 0.0,], [ 0.0, 0.0, 6.026e+10, 0.0,], [ 0.0, 0.0, 0.0, 4.996e+10,], [ 0.0, 0.0, 0.0, 4.996e+10,],] -material_boundary_points = [ [ 0.0, 0.5,], [ 0.5, 0.5,], [ 0.5, -0.5,], [ 0.0, -0.5,],] +boundary = [0, 3, 4, 7] simulation_boundary_points = [ [ 0.6, -0.6,], [ -0.1, -0.6,], [ -0.1, 0.6,], [ 0.6, 0.6,], [ 0.6, -0.6,],] electronic_stopping_correction_factors = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0] energy_barrier_thickness = 2.2E-4 diff --git a/src/geometry.rs b/src/geometry.rs index 5d8cdd7f..71afd041 100644 --- a/src/geometry.rs +++ b/src/geometry.rs @@ -269,8 +269,9 @@ impl Geometry for Mesh1D { #[derive(Deserialize, Clone)] pub struct Mesh2DInput { pub length_unit: String, - pub triangles: Vec<(f64, f64, f64, f64, f64, f64)>, - pub material_boundary_points: Vec<(f64, f64)>, + pub triangles: Vec<(usize, usize, usize)>, + pub points: Vec<(f64, f64)>, + pub boundary: Vec, pub simulation_boundary_points: Vec<(f64, f64)>, pub densities: Vec>, pub electronic_stopping_correction_factors: Vec, @@ -313,7 +314,9 @@ impl Geometry for Mesh2D { fn new(geometry_input: &<::InputFileFormat as GeometryInput>::GeometryInput) -> Mesh2D { let triangles = geometry_input.triangles.clone(); - let material_boundary_points = geometry_input.material_boundary_points.clone(); + let points = geometry_input.points.clone(); + let material_boundary_point_indices = geometry_input.boundary.clone(); + let simulation_boundary_points = geometry_input.simulation_boundary_points.clone(); let electronic_stopping_correction_factors = geometry_input.electronic_stopping_correction_factors.clone(); @@ -348,6 +351,31 @@ impl Geometry for Mesh2D { assert_eq!(triangles.len(), densities.len(), "Input error: coordinates and data of unequal length."); + + for ((triangle, densities), ck) in triangles.iter().zip(densities).zip(electronic_stopping_correction_factors) { + + let x1 = points[triangle.0].0; + let x2 = points[triangle.1].0; + let x3 = points[triangle.2].0; + let y1 = points[triangle.0].1; + let y2 = points[triangle.1].1; + let y3 = points[triangle.2].1; + + let coordinate_set_converted = ( + x1*length_unit, + x2*length_unit, + x3*length_unit, + y1*length_unit, + y2*length_unit, + y3*length_unit, + ); + let total_density: f64 = densities.iter().sum(); + let concentrations: Vec = densities.iter().map(|&density| density/total_density).collect::>(); + + cells.push(Cell2D::new(coordinate_set_converted, densities, concentrations, ck)); + } + + /* for ((coordinate_set, densities), ck) in triangles.iter().zip(densities).zip(electronic_stopping_correction_factors) { let coordinate_set_converted = ( coordinate_set.0*length_unit, @@ -363,10 +391,13 @@ impl Geometry for Mesh2D { cells.push(Cell2D::new(coordinate_set_converted, densities, concentrations, ck)); } + */ + + - let mut boundary_points_converted = Vec::with_capacity(material_boundary_points.len()); - for (x, y) in material_boundary_points.iter() { - boundary_points_converted.push((x*length_unit, y*length_unit)); + let mut boundary_points_converted = Vec::with_capacity(material_boundary_point_indices.len()); + for index in material_boundary_point_indices.iter() { + boundary_points_converted.push((points[*index].0*length_unit, points[*index].1*length_unit)); } let boundary: Polygon = Polygon::new(LineString::from(boundary_points_converted), vec![]); diff --git a/src/tests.rs b/src/tests.rs index a1f4a8cd..d9805a76 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -455,9 +455,10 @@ fn test_geometry() { let geometry_input_2D = geometry::Mesh2DInput { length_unit: "ANGSTROM".to_string(), - triangles: vec![(0., depth, 0., thickness/2., thickness/2., -thickness/2.), (depth, depth, 0., thickness/2., -thickness/2., -thickness/2.)], + points: vec![(0., -thickness/2.), (depth, -thickness/2.), (depth, thickness/2.), (0., thickness/2.)], + triangles: vec![(0, 1, 2), (0, 2, 3)], densities: vec![vec![0.03, 0.03], vec![0.03, 0.03]], - material_boundary_points: vec![(0., thickness/2.), (depth, thickness/2.), (depth, -thickness/2.), (0., -thickness/2.), (0., thickness/2.)], + boundary: vec![0, 1, 2, 3], simulation_boundary_points: vec![(0., 1.1*thickness/2.), (depth, 1.1*thickness/2.), (depth, -1.1*thickness/2.), (0., -1.1*thickness/2.), (0., 1.1*thickness/2.)], energy_barrier_thickness: 10., electronic_stopping_correction_factors: vec![1.0, 1.0], @@ -521,9 +522,10 @@ fn test_surface_binding_energy_barrier() { let geometry_input_2D = geometry::Mesh2DInput { length_unit: "ANGSTROM".to_string(), - triangles: vec![(0., depth, 0., thickness/2., thickness/2., -thickness/2.), (depth, depth, 0., thickness/2., -thickness/2., -thickness/2.)], + points: vec![(0., -thickness/2.), (depth, -thickness/2.), (depth, thickness/2.), (0., thickness/2.)], + triangles: vec![(0, 1, 2), (0, 2, 3)], densities: vec![vec![0.03, 0.03], vec![0.03, 0.03]], - material_boundary_points: vec![(0., thickness/2.), (depth, thickness/2.), (depth, -thickness/2.), (0., -thickness/2.), (0., thickness/2.)], + boundary: vec![0, 1, 2, 3], simulation_boundary_points: vec![(0., 1.1*thickness/2.), (depth, 1.1*thickness/2.), (depth, -1.1*thickness/2.), (0., -1.1*thickness/2.), (0., 1.1*thickness/2.)], energy_barrier_thickness: 10., electronic_stopping_correction_factors: vec![1.0, 1.0], @@ -745,9 +747,10 @@ fn test_momentum_conservation() { let depth: f64 = 1000.; let geometry_input = geometry::Mesh2DInput { length_unit: "ANGSTROM".to_string(), - triangles: vec![(0., depth, 0., thickness/2., thickness/2., -thickness/2.), (depth, depth, 0., thickness/2., -thickness/2., -thickness/2.)], + triangles: vec![(0, 1, 2), (0, 2, 3)], + points: vec![(0., -thickness/2.), (depth, -thickness/2.), (depth, thickness/2.), (0., thickness/2.)], densities: vec![vec![0.06306], vec![0.06306]], - material_boundary_points: vec![(0., thickness/2.), (depth, thickness/2.), (depth, -thickness/2.), (0., -thickness/2.), (0., thickness/2.)], + boundary: vec![0, 1, 2, 3], simulation_boundary_points: vec![(0., 1.1*thickness/2.), (depth, 1.1*thickness/2.), (depth, -1.1*thickness/2.), (0., -1.1*thickness/2.), (0., 1.1*thickness/2.)], electronic_stopping_correction_factors: vec![0.0, 0.0], energy_barrier_thickness: 0., From 3d00d9f09d81fbb5c821118953d7d35754a3c3af Mon Sep 17 00:00:00 2001 From: Jon Drobny Date: Thu, 9 Mar 2023 15:57:12 -0800 Subject: [PATCH 23/26] Removed deprecated example. --- .github/workflows/rustbca_compile_check.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/rustbca_compile_check.yml b/.github/workflows/rustbca_compile_check.yml index 329c048a..a424dbff 100644 --- a/.github/workflows/rustbca_compile_check.yml +++ b/.github/workflows/rustbca_compile_check.yml @@ -65,7 +65,6 @@ jobs: ./target/release/RustBCA 0D examples/titanium_dioxide_0D.toml ./target/release/RustBCA 1D examples/layered_geometry_1D.toml cat 2000.0eV_0.0001deg_He_TiO2_Al_Sisummary.output - ./target/release/RustBCA examples/boron_nitride.toml ./target/release/RustBCA examples/layered_geometry.toml cat 2000.0eV_0.0001deg_He_TiO2_Al_Sisummary.output ./target/release/RustBCA SPHERE examples/boron_nitride_sphere.toml From 2710f478991b759ff7d43c3cd5a4ab9ace94e5f3 Mon Sep 17 00:00:00 2001 From: Jon Drobny Date: Thu, 9 Mar 2023 16:23:38 -0800 Subject: [PATCH 24/26] Update test_morse.py to actually run the simulation. --- examples/test_morse.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/test_morse.py b/examples/test_morse.py index e3e0607a..7aa025fd 100644 --- a/examples/test_morse.py +++ b/examples/test_morse.py @@ -118,7 +118,7 @@ def run_morse_potential(energy, index, num_samples=10000, run_sim=True): #Running and plotting the H-Ni simulations with the Morse potential and updated Es num_energies = 15 energies = np.logspace(-1, 3, num_energies) -run_sim = False +run_sim = True num_samples = 1000 R_N = np.zeros(num_energies) R_E = np.zeros(num_energies) From 8c098a1479bf0a71894b02b36694ae4b12df0418 Mon Sep 17 00:00:00 2001 From: Jon Drobny Date: Thu, 16 Mar 2023 10:09:57 -0700 Subject: [PATCH 25/26] Updated 2D circular cross-section boron nitride example; added context to error message regarding zero-size triangles. --- examples/boron_nitride_wire.toml | 36 ++++++++++++++++++++++++++++++++ src/geometry.rs | 2 +- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 examples/boron_nitride_wire.toml diff --git a/examples/boron_nitride_wire.toml b/examples/boron_nitride_wire.toml new file mode 100644 index 00000000..a0007b9e --- /dev/null +++ b/examples/boron_nitride_wire.toml @@ -0,0 +1,36 @@ +[options] +name = "boron_nitride_" +weak_collision_order = 0 +num_threads = 4 + +[material_parameters] +energy_unit = "EV" +mass_unit = "AMU" +Eb = [ 0.0, 0.0,] +Es = [ 5.76, 0.0,] +Ec = [ 1.0, 1.0,] +Z = [ 5, 7,] +m = [ 10.811, 14,] + +[particle_parameters] +length_unit = "MICRON" +energy_unit = "EV" +mass_unit = "AMU" +N = [ 10000 ] +m = [ 1.008 ] +Z = [ 1 ] +E = [ 1000.0 ] +Ec = [ 1.0 ] +Es = [ 10.0 ] +pos = [ [ 0.0, 0.0, 0.0,] ] +dir = [ [ 0.9999999999984769, 1.7453292519934434e-6, 0.0,] ] + +[geometry_input] +length_unit = "ANGSTROM" +triangles = [ [ 0, 1, 2,], [ 0, 2, 3,], [ 0, 3, 4,], [ 0, 4, 5,], [ 0, 5, 6,], [ 0, 6, 7,], [ 0, 7, 8,], [ 0, 8, 9,], [ 0, 9, 10,], [ 0, 10, 11,], [ 0, 11, 12,], [ 0, 12, 13,], [ 0, 13, 14,], [ 0, 14, 15,], [ 0, 15, 16,], [ 0, 16, 17,], [ 0, 17, 18,], [ 0, 18, 19,], [ 0, 19, 20,], [ 0, 20, 21,], [ 0, 21, 22,], [ 0, 22, 23,], [ 0, 23, 24,], [ 0, 24, 25,], [ 0, 25, 26,], [ 0, 26, 27,], [ 0, 27, 28,], [ 0, 28, 29,], [ 0, 29, 30,], [ 0, 30, 31,], [ 0, 31, 32,], [ 0, 32, 33,], [ 0, 33, 34,], [ 0, 34, 35,], [ 0, 35, 36,], [ 0, 36, 37,], [ 0, 37, 38,], [ 0, 38, 39,], [ 0, 39, 40,], [ 0, 40, 41,], [ 0, 41, 42,], [ 0, 42, 43,], [ 0, 43, 44,], [ 0, 44, 45,], [ 0, 45, 46,], [ 0, 46, 47,], [ 0, 47, 48,], [ 0, 48, 49,], [ 0, 49, 50,], [ 0, 50, 51,], [ 0, 51, 52,], [ 0, 52, 53,], [ 0, 53, 54,], [ 0, 54, 55,], [ 0, 55, 56,], [ 0, 56, 57,], [ 0, 57, 58,], [ 0, 58, 59,], [ 0, 59, 60,], [ 0, 60, 61,], [ 0, 61, 62,], [ 0, 62, 63,], [ 0, 63, 64,], [ 0, 64, 65,], [ 0, 65, 66,], [ 0, 66, 67,], [ 0, 67, 68,], [ 0, 68, 69,], [ 0, 69, 70,], [ 0, 70, 71,], [ 0, 71, 72,], [ 0, 72, 73,], [ 0, 73, 74,], [ 0, 74, 75,], [ 0, 75, 76,], [ 0, 76, 77,], [ 0, 77, 78,], [ 0, 78, 79,], [ 0, 79, 80,], [ 0, 80, 81,], [ 0, 81, 82,], [ 0, 82, 83,], [ 0, 83, 84,], [ 0, 84, 85,], [ 0, 85, 86,], [ 0, 86, 87,], [ 0, 87, 88,], [ 0, 88, 89,], [ 0, 89, 90,], [ 0, 90, 91,], [ 0, 91, 92,], [ 0, 92, 93,], [ 0, 93, 94,], [ 0, 94, 95,], [ 0, 95, 96,], [ 0, 96, 97,], [ 0, 97, 98,], [ 0, 98, 99,], [ 0, 99, 100,], [ 0, 100, 101,], [ 0, 101, 1,],] +points = [ [ 0.0, 0.0,], [ 1000.0, 0.0,], [ 998.0267284282716, 62.79051952931337,], [ 992.1147013144779, 125.33323356430427,], [ 982.2872507286887, 187.38131458572462,], [ 968.5831611286311, 248.68988716485478,], [ 951.0565162951535, 309.0169943749474,], [ 929.7764858882514, 368.12455268467795,], [ 904.8270524660195, 425.7792915650727,], [ 876.3066800438636, 481.7536741017153,], [ 844.3279255020151, 535.8267949789966,], [ 809.0169943749474, 587.7852522924732,], [ 770.5132427757892, 637.4239897486898,], [ 728.9686274214115, 684.5471059286888,], [ 684.5471059286887, 728.9686274214115,], [ 637.4239897486897, 770.5132427757893,], [ 587.785252292473, 809.0169943749474,], [ 535.8267949789965, 844.3279255020151,], [ 481.75367410171515, 876.3066800438637,], [ 425.77929156507264, 904.8270524660196,], [ 368.12455268467784, 929.7764858882515,], [ 309.01699437494744, 951.0565162951535,], [ 248.68988716485475, 968.5831611286311,], [ 187.3813145857245, 982.2872507286887,], [ 125.33323356430427, 992.1147013144779,], [ 62.79051952931331, 998.0267284282716,], [ -1.6081226496766366e-13, 1000.0,], [ -62.7905195293134, 998.0267284282716,], [ -125.33323356430436, 992.1147013144778,], [ -187.38131458572482, 982.2872507286886,], [ -248.68988716485484, 968.5831611286311,], [ -309.01699437494756, 951.0565162951535,], [ -368.12455268467795, 929.7764858882515,], [ -425.7792915650727, 904.8270524660195,], [ -481.75367410171543, 876.3066800438635,], [ -535.8267949789969, 844.327925502015,], [ -587.785252292473, 809.0169943749474,], [ -637.4239897486898, 770.5132427757893,], [ -684.5471059286888, 728.9686274214115,], [ -728.9686274214116, 684.5471059286886,], [ -770.5132427757893, 637.4239897486896,], [ -809.0169943749473, 587.7852522924733,], [ -844.3279255020151, 535.8267949789966,], [ -876.3066800438636, 481.7536741017152,], [ -904.8270524660196, 425.77929156507247,], [ -929.7764858882515, 368.1245526846778,], [ -951.0565162951536, 309.0169943749471,], [ -968.5831611286311, 248.6898871648548,], [ -982.2872507286887, 187.38131458572457,], [ -992.1147013144779, 125.3332335643041,], [ -998.0267284282716, 62.79051952931314,], [ -1000.0, -3.216245299353273e-13,], [ -998.0267284282716, -62.79051952931334,], [ -992.1147013144779, -125.33323356430428,], [ -982.2872507286886, -187.38131458572477,], [ -968.5831611286311, -248.689887164855,], [ -951.0565162951535, -309.0169943749477,], [ -929.7764858882513, -368.1245526846783,], [ -904.8270524660195, -425.77929156507264,], [ -876.3066800438636, -481.7536741017154,], [ -844.327925502015, -535.8267949789968,], [ -809.0169943749472, -587.7852522924734,], [ -770.5132427757891, -637.42398974869,], [ -728.9686274214115, -684.5471059286888,], [ -684.5471059286887, -728.9686274214115,], [ -637.4239897486896, -770.5132427757893,], [ -587.7852522924733, -809.0169943749473,], [ -535.8267949789963, -844.3279255020153,], [ -481.75367410171526, -876.3066800438636,], [ -425.7792915650722, -904.8270524660198,], [ -368.1245526846778, -929.7764858882515,], [ -309.01699437494756, -951.0565162951535,], [ -248.68988716485444, -968.5831611286312,], [ -187.38131458572462, -982.2872507286887,], [ -125.33323356430373, -992.1147013144779,], [ -62.79051952931321, -998.0267284282716,], [ -1.8369701987210297e-13, -1000.0,], [ 62.79051952931372, -998.0267284282716,], [ 125.33323356430424, -992.1147013144779,], [ 187.38131458572514, -982.2872507286886,], [ 248.68988716485492, -968.5831611286311,], [ 309.0169943749472, -951.0565162951536,], [ 368.12455268467824, -929.7764858882513,], [ 425.7792915650726, -904.8270524660196,], [ 481.7536741017157, -876.3066800438634,], [ 535.8267949789968, -844.327925502015,], [ 587.7852522924737, -809.016994374947,], [ 637.42398974869, -770.5132427757891,], [ 684.5471059286887, -728.9686274214115,], [ 728.9686274214118, -684.5471059286883,], [ 770.5132427757893, -637.4239897486897,], [ 809.0169943749478, -587.7852522924726,], [ 844.3279255020152, -535.8267949789963,], [ 876.3066800438636, -481.7536741017153,], [ 904.8270524660197, -425.77929156507224,], [ 929.7764858882515, -368.12455268467784,], [ 951.0565162951538, -309.01699437494676,], [ 968.5831611286312, -248.6898871648545,], [ 982.2872507286887, -187.38131458572468,], [ 992.1147013144779, -125.33323356430378,], [ 998.0267284282716, -62.790519529313265,], [ 1000.0, -2.4492935982947065e-13,],] +boundary = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101,] +simulation_boundary_points = [ [ -1100.0, -1100.0,], [ -1100.0, 1100.0,], [ 1100.0, 1100.0,], [ 1100.0, -1100.0,],] +densities = [ [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,], [ 0.065, 0.065,],] +electronic_stopping_correction_factors = [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0,] +energy_barrier_thickness = 2.5 diff --git a/src/geometry.rs b/src/geometry.rs index 71afd041..2a11cbd0 100644 --- a/src/geometry.rs +++ b/src/geometry.rs @@ -655,7 +655,7 @@ impl Triangle2D { for segment in &self.segments { let length_2 = (segment.2 - segment.0)*(segment.2 - segment.0) + (segment.3 - segment.1)*(segment.3 - segment.1); - assert!(length_2 != 0., "Geometry error: mesh contains triangle with zero-length side."); + assert!(length_2 != 0., "Geometry error: mesh contains triangle with zero-length side. (x1, y1), (x2, y2) = ({}, {}) ({}, {})", segment.0, segment.2, segment.1, segment.3); let u = ((x - segment.0)*(segment.2 - segment.0) + (y - segment.1)*(segment.3 - segment.1))/length_2; From 6722cf64fd7a333a74e413f98710cd7fad1d8004 Mon Sep 17 00:00:00 2001 From: Jon Drobny <37962344+drobnyjt@users.noreply.github.com> Date: Thu, 16 Mar 2023 10:11:17 -0700 Subject: [PATCH 26/26] Update rustbca_compile_check.yml Include un-deprecated example. --- .github/workflows/rustbca_compile_check.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rustbca_compile_check.yml b/.github/workflows/rustbca_compile_check.yml index a424dbff..055cc5fb 100644 --- a/.github/workflows/rustbca_compile_check.yml +++ b/.github/workflows/rustbca_compile_check.yml @@ -69,4 +69,5 @@ jobs: cat 2000.0eV_0.0001deg_He_TiO2_Al_Sisummary.output ./target/release/RustBCA SPHERE examples/boron_nitride_sphere.toml cargo run --release --features parry3d TRIMESH examples/tungsten_twist_trimesh.toml - \ No newline at end of file + ./target/release/RustBCA examples/boron_nitride_wire.toml +