-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #170 from lcpp-org/dev
Merge dev into Main for version 1.2.0
- Loading branch information
Showing
15 changed files
with
921 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
[package] | ||
name = "RustBCA" | ||
version = "1.1.1" | ||
version = "1.2.0" | ||
|
||
authors = ["Jon Drobny <[email protected]>"] | ||
edition = "2018" | ||
|
||
|
@@ -14,6 +15,7 @@ crate-type = ["cdylib"] | |
|
||
[dependencies] | ||
rand = "0.8.3" | ||
rand_distr = "0.4.2" | ||
toml = "0.5.8" | ||
anyhow = "1.0.38" | ||
itertools = "0.10.0" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include "RustBCA.h" | ||
#include <iostream> | ||
#include <vector> | ||
|
||
int main(int argc, char * argv[]) { | ||
OutputTaggedBCA output; | ||
double velocities[2][3] = {{500000.0, 0.1, 0.0}, {500000.0, 0.1, 0.0}}; | ||
double positions[2][3] = {{0.0, 0.0, 0.0}, {1.0, 1.0, 1.0}}; | ||
int tags[2] = {0, 1}; | ||
double weights[2] = {1.0, 1.0}; | ||
double Z[3] = {74.0, 74.0}; | ||
double m[2] = {184.0, 184.0}; | ||
double n[2] = {0.06306, 0.06306}; | ||
double Ec[2] = {1.0, 1.0}; | ||
double Es[2] = {8.79, 8.79}; | ||
double Eb[2] = {0.0, 0.0}; | ||
|
||
InputTaggedBCA input = { | ||
2, | ||
positions, | ||
velocities, | ||
1.0, | ||
1.0, | ||
1.0, | ||
1.0, | ||
2, | ||
Z, | ||
m, | ||
n, | ||
Ec, | ||
Es, | ||
Eb, | ||
tags, | ||
weights | ||
}; | ||
|
||
//output = simple_bca_c(0., 0., 0., 0.5, 0.5, 0.00, 2000.0, 2.0, 4.0, 1.0, 0.0, 74.0, 184.0, 1.0, 8.79, 0.06306, 0.0); | ||
//output = compound_bca_list_c(input); | ||
output = compound_tagged_bca_list_c(input); | ||
|
||
std::cout << "Particle 1 Z: "; | ||
std::cout << output.particles[0][0]; | ||
std::cout << std::endl; | ||
std::cout << "Particle 1 E [eV]: "; | ||
std::cout << output.particles[0][2]; | ||
std::cout << std::endl; | ||
std::cout << "Particle 2 Z: "; | ||
std::cout << output.particles[1][0]; | ||
std::cout << std::endl; | ||
std::cout << "Particle 2 E [eV]: "; | ||
std::cout << output.particles[1][2]; | ||
std::cout << std::endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
|
||
program test_rustbca | ||
|
||
use rustbca | ||
use, intrinsic :: iso_c_binding | ||
|
||
integer :: N_ions | ||
real(c_double), allocatable, dimension(:) :: ux, uy, uz, E, Z1, m1, Ec1, Es1 | ||
integer(c_int) :: num_species_target, num_emitted_particles | ||
real(c_double), target :: Z2(2), m2(2), Ec2(2), Es2(2), Eb2(2), n2(2) | ||
real(c_double) :: ux1, uy1, uz1, E1 | ||
type(c_ptr) :: bca_output_c | ||
real(c_double), pointer, dimension(:,:) :: bca_output_f | ||
real :: start, stop | ||
logical(c_bool) :: track_recoils | ||
|
||
!Initial ion conditions | ||
N_ions = 100000 | ||
allocate(ux(N_ions), uy(N_ions), uz(N_ions), E(N_ions), Z1(N_ions), m1(N_ions), Ec1(N_ions), Es1(N_ions)) | ||
ux(:) = 0.999 | ||
uy(:) = sqrt(1.0 - 0.999*0.999) | ||
uz(:) = 0.0 | ||
E(:) = 1000.0_8 | ||
|
||
!Hydrogen | ||
Z1(:) = 1.0_8 | ||
m1(:) = 1.008_8 | ||
Ec1(:) = 1.0_8 | ||
Es1(:) = 1.5_8 | ||
|
||
!Titanium Hydride | ||
num_species_target = 2 | ||
Z2(1) = 22.0_8 | ||
m2(1) = 47.867_8 | ||
Ec2(1) = 4.84_8 | ||
Es2(1) = 4.84_8 | ||
Eb2(1) = 3.0_8 | ||
n2(1) = 0.04527_8 | ||
|
||
Z2(2) = 1.0_8 | ||
m2(2) = 1.008_8 | ||
Ec2(2) = 1.5_8 | ||
Es2(2) = 1.5_8 | ||
Eb2(2) = 0.0_8 | ||
n2(2) = 0.09054_8 | ||
|
||
track_recoils = .false. | ||
|
||
call cpu_time(start) | ||
bca_output_c = compound_bca_list_fortran(N_ions, track_recoils, ux, uy, uz, E, & | ||
Z1, m1, Ec1, Es1, & | ||
num_species_target, Z2, m2, Ec2, Es2, Eb2, n2, & | ||
num_emitted_particles) | ||
call c_f_pointer(bca_output_c, bca_output_f, [num_emitted_particles, 6]) | ||
call cpu_time(stop) | ||
|
||
write(*,*) "Elapsed time in seconds per ion per eV: ", (stop - start)/N_ions/1000.0 | ||
|
||
!write(*,*) bca_output_f | ||
|
||
call cpu_time(start) | ||
do i = 0, N_ions | ||
!Test reflect_single_ion routine | ||
ux1 = 0.999 | ||
uy1 = sqrt(1.0 - 0.999*0.999) | ||
uz1 = 0.0 | ||
E1 = 1000.0 | ||
call reflect_single_ion_c(num_species_target, ux1, uy1, uz1, E1, Z1(1), m1(1), Ec1(1), Es1(1), Z2, m2, Ec2, Es2, Eb2, n2) | ||
end do | ||
call cpu_time(stop) | ||
write(*,*) "Elapsed time in ions per eV per s: ", (stop - start)/N_ions/1000.0 | ||
|
||
!call exit(1) | ||
|
||
end program test_rustbca |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
module rustbca | ||
|
||
use, intrinsic :: iso_c_binding | ||
|
||
interface | ||
|
||
subroutine reflect_single_ion_c(num_species_target, ux, uy, uz, E1, & | ||
Z1, m1, Ec1, Es1, Z2, m2, Ec2, Es2, Eb2, n2) bind(c) | ||
|
||
!Runs a single ion BCA trajectory with no recoils | ||
!Args: | ||
! num_species_target (integer): number of species in target | ||
! ux (real(c_double)): x-direction of incident ion, x-direction of reflected ion | ||
! uy (real(c_double)): y-direction of incident ion, y-direction of reflected ion | ||
! uz (real(c_double)): z-direction of incident ion, z-direction of reflected ion | ||
! E1 (real(c_double)): initial energy of incident ion in eV | ||
! Z1 (real(c_double)): atomic number of incident ion | ||
! m1 (real(c_double)): atomic mass of incident ion in eV | ||
! Ec1 (real(c_double)): cutoff energy of incident ion in eV | ||
! Es1 (real(c_double)): surface binding energy of incident ion in eV | ||
! Z2 (real(c_double), dimension(:)): list of atomic numbers of target speciesd | ||
! m2 (real(c_double), dimension(:)): list of atomic masses of target species in amu | ||
! Ec2 (real(c_double), dimension(:)): list of cutoff energies of target species in eV | ||
! Es2 (real(c_double), dimension(:)): list of surface binding energies of target species in eV | ||
! Eb2 (real(c_double), dimension(:)): list of bulk binding energies of target species in eV | ||
! n2 (real(c_double), dimension(:)): list of number densities of target species in 1/angstrom^3 | ||
|
||
use, intrinsic :: iso_c_binding | ||
real(c_double), intent(inout) :: ux, uy, uz, E1 | ||
real(c_double), intent(in) :: Z1, m1, Ec1, Es1 | ||
integer(c_int), intent(in) :: num_species_target | ||
real(c_double), intent(in), dimension(*) :: Z2, m2, Ec2, Es2, Eb2, n2 | ||
|
||
end subroutine reflect_single_ion_c | ||
|
||
function compound_bca_list_fortran(num_incident_ions, track_recoils, ux, uy, uz, E1, & | ||
Z1, m1, Ec1, Es1, & | ||
num_species_target, Z2, m2, Ec2, Es2, Eb2, n2, & | ||
num_emitted_particles) bind(c) result(output) | ||
|
||
|
||
!Runs a homogeneous, flat, compound target BCA with an arbitrary list of ions. | ||
!Args: | ||
! num_incident_ion (integer(c_int)): number of incident ions | ||
! track_recoils (logical(c_bool)): whether to generate recoils (disable to turn off sputtering) | ||
! ux (real(c_double), dimension(:)): x-direction of incident ion, x-direction of reflected ion | ||
! uy (real(c_double), dimension(:)): y-direction of incident ion, y-direction of reflected ion | ||
! uz (real(c_double), dimension(:)): z-direction of incident ion, z-direction of reflected ion | ||
! E1 (real(c_double), dimension(:)): initial energy of incident ion in eV | ||
! Z1 (real(c_double), dimension(:)): atomic number of incident ion | ||
! m1 (real(c_double), dimension(:)): atomic mass of incident ion in eV | ||
! Ec1 (real(c_double), dimension(:)): cutoff energy of incident ion in eV | ||
! num_species_target(integer(c_int)): number of species in target | ||
! Es1 (real(c_double), dimension(:)): surface binding energy of incident ion in eV | ||
! Z2 (real(c_double), dimension(:)): list of atomic numbers of target speciesd | ||
! m2 (real(c_double), dimension(:)): list of atomic masses of target species in amu | ||
! Ec2 (real(c_double), dimension(:)): list of cutoff energies of target species in eV | ||
! Es2 (real(c_double), dimension(:)): list of surface binding energies of target species in eV | ||
! Eb2 (real(c_double), dimension(:)): list of bulk binding energies of target species in eV | ||
! n2 (real(c_double), dimension(:)): list of number densities of target species in 1/angstrom^3 | ||
! num_emitted_particles (integer(c_int), intent(out)): NOTE THAT THIS IS INTENT(OUT) number of emitted particles in output | ||
!Returns: | ||
! output (type(c_ptr)): a c pointer to a 2D array of size (num_emitted_particles, 6) that consists of Z, m, E, ux, uy, uz | ||
|
||
use, intrinsic :: iso_c_binding | ||
logical(c_bool), intent(in) :: track_recoils | ||
integer(c_int), intent(in) :: num_incident_ions, num_species_target | ||
integer(c_int), intent(out) :: num_emitted_particles | ||
real(c_double), intent(in), dimension(*) :: ux, uy, uz, E1, Z1, m1, Ec1, Es1 | ||
real(c_double), intent(in), dimension(*) :: Z2, m2, Ec2, Es2, EB2, n2 | ||
type(c_ptr) :: output | ||
end function compound_bca_list_fortran | ||
|
||
end interface | ||
|
||
contains | ||
|
||
subroutine transform_to_local_angle(ux, uy, uz, alpha) | ||
|
||
!Rotates a vector in 2D | ||
!Args: | ||
! ux (real(c_double)): x-direction | ||
! uy (real(c_double)): y-direction | ||
! uz (real(c_double)): z-direction | ||
! alpha (real(c_double)): local surface angle measured counter-clockwise from x-axis in radians | ||
|
||
real(8), intent(inout) :: ux, uy, uz | ||
real(8), intent(in) :: alpha | ||
|
||
ux = ux*cos(alpha) - uy*sin(alpha) | ||
uy = ux*sin(alpha) + uy*cos(alpha) | ||
|
||
end subroutine transform_to_local_angle | ||
|
||
end module rustbca |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.