1+ module rustbca
2+
3+ use , intrinsic :: iso_c_binding
4+
5+ interface
6+
7+ subroutine reflect_single_ion_c (num_species_target , ux , uy , uz , E1 , &
8+ Z1 , m1 , Ec1 , Es1 , Z2 , m2 , Ec2 , Es2 , Eb2 , n2 ) bind(c)
9+
10+ ! Runs a single ion BCA trajectory with no recoils
11+ ! Args:
12+ ! num_species_target (integer): number of species in target
13+ ! ux (real(c_double)): x-direction of incident ion, x-direction of reflected ion
14+ ! uy (real(c_double)): y-direction of incident ion, y-direction of reflected ion
15+ ! uz (real(c_double)): z-direction of incident ion, z-direction of reflected ion
16+ ! E1 (real(c_double)): initial energy of incident ion in eV
17+ ! Z1 (real(c_double)): atomic number of incident ion
18+ ! m1 (real(c_double)): atomic mass of incident ion in eV
19+ ! Ec1 (real(c_double)): cutoff energy of incident ion in eV
20+ ! Es1 (real(c_double)): surface binding energy of incident ion in eV
21+ ! Z2 (real(c_double), dimension(:)): list of atomic numbers of target speciesd
22+ ! m2 (real(c_double), dimension(:)): list of atomic masses of target species in amu
23+ ! Ec2 (real(c_double), dimension(:)): list of cutoff energies of target species in eV
24+ ! Es2 (real(c_double), dimension(:)): list of surface binding energies of target species in eV
25+ ! Eb2 (real(c_double), dimension(:)): list of bulk binding energies of target species in eV
26+ ! n2 (real(c_double), dimension(:)): list of number densities of target species in 1/angstrom^3
27+
28+ use , intrinsic :: iso_c_binding
29+ real (c_double), intent (inout ) :: ux, uy, uz, E1
30+ real (c_double), intent (in ) :: Z1, m1, Ec1, Es1
31+ integer (c_int), intent (in ) :: num_species_target
32+ real (c_double), intent (in ), dimension (* ) :: Z2, m2, Ec2, Es2, Eb2, n2
33+
34+ end subroutine reflect_single_ion_c
35+
36+ function compound_bca_list_fortran (num_incident_ions , track_recoils , ux , uy , uz , E1 , &
37+ Z1 , m1 , Ec1 , Es1 , &
38+ num_species_target , Z2 , m2 , Ec2 , Es2 , Eb2 , n2 , &
39+ num_emitted_particles ) bind(c) result(output)
40+
41+
42+ ! Runs a homogeneous, flat, compound target BCA with an arbitrary list of ions.
43+ ! Args:
44+ ! num_incident_ion (integer(c_int)): number of incident ions
45+ ! track_recoils (logical(c_bool)): whether to generate recoils (disable to turn off sputtering)
46+ ! ux (real(c_double), dimension(:)): x-direction of incident ion, x-direction of reflected ion
47+ ! uy (real(c_double), dimension(:)): y-direction of incident ion, y-direction of reflected ion
48+ ! uz (real(c_double), dimension(:)): z-direction of incident ion, z-direction of reflected ion
49+ ! E1 (real(c_double), dimension(:)): initial energy of incident ion in eV
50+ ! Z1 (real(c_double), dimension(:)): atomic number of incident ion
51+ ! m1 (real(c_double), dimension(:)): atomic mass of incident ion in eV
52+ ! Ec1 (real(c_double), dimension(:)): cutoff energy of incident ion in eV
53+ ! num_species_target(integer(c_int)): number of species in target
54+ ! Es1 (real(c_double), dimension(:)): surface binding energy of incident ion in eV
55+ ! Z2 (real(c_double), dimension(:)): list of atomic numbers of target speciesd
56+ ! m2 (real(c_double), dimension(:)): list of atomic masses of target species in amu
57+ ! Ec2 (real(c_double), dimension(:)): list of cutoff energies of target species in eV
58+ ! Es2 (real(c_double), dimension(:)): list of surface binding energies of target species in eV
59+ ! Eb2 (real(c_double), dimension(:)): list of bulk binding energies of target species in eV
60+ ! n2 (real(c_double), dimension(:)): list of number densities of target species in 1/angstrom^3
61+ ! num_emitted_particles (integer(c_int), intent(out)): NOTE THAT THIS IS INTENT(OUT) number of emitted particles in output
62+ ! Returns:
63+ ! 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
64+
65+ use , intrinsic :: iso_c_binding
66+ logical (c_bool), intent (in ) :: track_recoils
67+ integer (c_int), intent (in ) :: num_incident_ions, num_species_target
68+ integer (c_int), intent (out ) :: num_emitted_particles
69+ real (c_double), intent (in ), dimension (* ) :: ux, uy, uz, E1, Z1, m1, Ec1, Es1
70+ real (c_double), intent (in ), dimension (* ) :: Z2, m2, Ec2, Es2, EB2, n2
71+ type (c_ptr) :: output
72+ end function compound_bca_list_fortran
73+
74+ end interface
75+
76+ contains
77+
78+ subroutine transform_to_local_angle (ux , uy , uz , alpha )
79+
80+ ! Rotates a vector in 2D
81+ ! Args:
82+ ! ux (real(c_double)): x-direction
83+ ! uy (real(c_double)): y-direction
84+ ! uz (real(c_double)): z-direction
85+ ! alpha (real(c_double)): local surface angle measured counter-clockwise from x-axis in radians
86+
87+ real (8 ), intent (inout ) :: ux, uy, uz
88+ real (8 ), intent (in ) :: alpha
89+
90+ ux = ux* cos (alpha) - uy* sin (alpha)
91+ uy = ux* sin (alpha) + uy* cos (alpha)
92+
93+ end subroutine transform_to_local_angle
94+
95+ end module rustbca
0 commit comments