From d2db27eb668f9ee21a8e571ac80503dad0a10fbb Mon Sep 17 00:00:00 2001 From: Jon Drobny Date: Fri, 19 Nov 2021 15:43:28 -0800 Subject: [PATCH 01/14] Fortran routine tests. --- examples/test_rustbca.f90 | 75 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 examples/test_rustbca.f90 diff --git a/examples/test_rustbca.f90 b/examples/test_rustbca.f90 new file mode 100644 index 0000000..f59d5fe --- /dev/null +++ b/examples/test_rustbca.f90 @@ -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 \ No newline at end of file From 96462d626c0df7d8d0647d0a0c7e0636f70770ac Mon Sep 17 00:00:00 2001 From: Jon Drobny Date: Sat, 20 Nov 2021 09:19:38 -0800 Subject: [PATCH 02/14] added C example to examples folder. --- examples/RustBCA.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 examples/RustBCA.c diff --git a/examples/RustBCA.c b/examples/RustBCA.c new file mode 100644 index 0000000..a218531 --- /dev/null +++ b/examples/RustBCA.c @@ -0,0 +1,54 @@ +#include "RustBCA.h" +#include +#include + +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; +} From ca25e27f7daf08361ed0b0d71b3632bb9983db57 Mon Sep 17 00:00:00 2001 From: Jon Drobny <37962344+drobnyjt@users.noreply.github.com> Date: Sat, 20 Nov 2021 09:22:32 -0800 Subject: [PATCH 03/14] Update rustbca_compile_check.yml --- .github/workflows/rustbca_compile_check.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rustbca_compile_check.yml b/.github/workflows/rustbca_compile_check.yml index fa9829e..dd648f4 100644 --- a/.github/workflows/rustbca_compile_check.yml +++ b/.github/workflows/rustbca_compile_check.yml @@ -45,9 +45,10 @@ jobs: python3 setup.py install --root . cp -r usr/local/lib/python3.8/dist-packages/libRustBCA . python3 -c "from libRustBCA.pybca import *;" - - name: Test Fortran bindings + - name: Test Fortran and C bindings run : | - gfortran -c rustbca.f90 target/release/liblibRustBCA.so + gfortran -c examples/rustbca.f90 target/release/liblibRustBCA.so + g++ examples/RustBCA.c RustBCA.h target/release/liblibRustBCA.so - name: Test RustBCA run: | sudo cargo test --features cpr_rootfinder_netlib,hdf5_input,distributions,parry3d From 5dca803bafa47333641aca94c63bef52c724a62f Mon Sep 17 00:00:00 2001 From: Jon Drobny <37962344+drobnyjt@users.noreply.github.com> Date: Sat, 20 Nov 2021 09:38:32 -0800 Subject: [PATCH 04/14] add g++ compilation of C libraries --- .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 dd648f4..68ac613 100644 --- a/.github/workflows/rustbca_compile_check.yml +++ b/.github/workflows/rustbca_compile_check.yml @@ -48,7 +48,8 @@ jobs: - name: Test Fortran and C bindings run : | gfortran -c examples/rustbca.f90 target/release/liblibRustBCA.so - g++ examples/RustBCA.c RustBCA.h target/release/liblibRustBCA.so + cp examples/RustBCA.c . + g++ RustBCA.c RustBCA.h target/release/liblibRustBCA.so -I examples - name: Test RustBCA run: | sudo cargo test --features cpr_rootfinder_netlib,hdf5_input,distributions,parry3d From 56333cdda76a136955c291a4ff35e492c57b6d6b Mon Sep 17 00:00:00 2001 From: Jon Drobny <37962344+drobnyjt@users.noreply.github.com> Date: Sat, 20 Nov 2021 09:44:57 -0800 Subject: [PATCH 05/14] Update rustbca_compile_check.yml --- .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 68ac613..856fe94 100644 --- a/.github/workflows/rustbca_compile_check.yml +++ b/.github/workflows/rustbca_compile_check.yml @@ -47,7 +47,7 @@ jobs: python3 -c "from libRustBCA.pybca import *;" - name: Test Fortran and C bindings run : | - gfortran -c examples/rustbca.f90 target/release/liblibRustBCA.so + gfortran -c rustbca.f90 target/release/liblibRustBCA.so cp examples/RustBCA.c . g++ RustBCA.c RustBCA.h target/release/liblibRustBCA.so -I examples - name: Test RustBCA From d55f728e088c42316a0ce5bc163aa52d35c19a64 Mon Sep 17 00:00:00 2001 From: Jon Drobny <37962344+drobnyjt@users.noreply.github.com> Date: Sat, 20 Nov 2021 09:51:23 -0800 Subject: [PATCH 06/14] Update rustbca_compile_check.yml --- .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 856fe94..e8880b8 100644 --- a/.github/workflows/rustbca_compile_check.yml +++ b/.github/workflows/rustbca_compile_check.yml @@ -47,9 +47,10 @@ jobs: python3 -c "from libRustBCA.pybca import *;" - name: Test Fortran and C bindings run : | + cargo build --release gfortran -c rustbca.f90 target/release/liblibRustBCA.so cp examples/RustBCA.c . - g++ RustBCA.c RustBCA.h target/release/liblibRustBCA.so -I examples + g++ RustBCA.c RustBCA.h target/release/liblibRustBCA.so -I examples /usr/include/python3.8 - name: Test RustBCA run: | sudo cargo test --features cpr_rootfinder_netlib,hdf5_input,distributions,parry3d From 559ba45523efbbe11d518809132aba7dca66d905 Mon Sep 17 00:00:00 2001 From: Jon Drobny <37962344+drobnyjt@users.noreply.github.com> Date: Sat, 20 Nov 2021 09:57:03 -0800 Subject: [PATCH 07/14] Made sure Python headers are installed --- .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 e8880b8..4564fd8 100644 --- a/.github/workflows/rustbca_compile_check.yml +++ b/.github/workflows/rustbca_compile_check.yml @@ -27,7 +27,7 @@ jobs: sudo apt-get install rustc - name: Install pip for Python-3 run: | - sudo apt-get install python3-pip + sudo apt-get install python3-pip python3-dev - name: Install Python libraries run: | python3 -m pip install numpy shapely scipy From ed472a68a015a1dde8c433869455bcf1c79d9bc7 Mon Sep 17 00:00:00 2001 From: Jon Drobny <37962344+drobnyjt@users.noreply.github.com> Date: Sat, 20 Nov 2021 10:02:37 -0800 Subject: [PATCH 08/14] Update rustbca_compile_check.yml --- .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 4564fd8..c886f22 100644 --- a/.github/workflows/rustbca_compile_check.yml +++ b/.github/workflows/rustbca_compile_check.yml @@ -50,7 +50,7 @@ jobs: cargo build --release gfortran -c rustbca.f90 target/release/liblibRustBCA.so cp examples/RustBCA.c . - g++ RustBCA.c RustBCA.h target/release/liblibRustBCA.so -I examples /usr/include/python3.8 + g++ RustBCA.c RustBCA.h target/release/liblibRustBCA.so -Iexamples/ -I/usr/include/python3.8 - name: Test RustBCA run: | sudo cargo test --features cpr_rootfinder_netlib,hdf5_input,distributions,parry3d From 25c3b1b2d7800036837d9792c5010e43bb835bff Mon Sep 17 00:00:00 2001 From: Jon Drobny <37962344+drobnyjt@users.noreply.github.com> Date: Sat, 20 Nov 2021 10:54:27 -0800 Subject: [PATCH 09/14] Update rustbca_compile_check.yml --- .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 c886f22..9a3d2a3 100644 --- a/.github/workflows/rustbca_compile_check.yml +++ b/.github/workflows/rustbca_compile_check.yml @@ -48,7 +48,7 @@ jobs: - name: Test Fortran and C bindings run : | cargo build --release - gfortran -c rustbca.f90 target/release/liblibRustBCA.so + gfortran examples/test_rustbca.f90 rustbca.f90 target/release/liblibRustBCA.so cp examples/RustBCA.c . g++ RustBCA.c RustBCA.h target/release/liblibRustBCA.so -Iexamples/ -I/usr/include/python3.8 - name: Test RustBCA From 52b23a8e197ed063b768ff6e5d1d954d8fb5624b Mon Sep 17 00:00:00 2001 From: Jon Drobny <37962344+drobnyjt@users.noreply.github.com> Date: Sat, 20 Nov 2021 10:59:26 -0800 Subject: [PATCH 10/14] Update rustbca_compile_check.yml --- .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 9a3d2a3..0cf7a95 100644 --- a/.github/workflows/rustbca_compile_check.yml +++ b/.github/workflows/rustbca_compile_check.yml @@ -48,7 +48,8 @@ jobs: - name: Test Fortran and C bindings run : | cargo build --release - gfortran examples/test_rustbca.f90 rustbca.f90 target/release/liblibRustBCA.so + cp examples test_rustbca.f90 . + gfortran test_rustbca.f90 rustbca.f90 target/release/liblibRustBCA.so cp examples/RustBCA.c . g++ RustBCA.c RustBCA.h target/release/liblibRustBCA.so -Iexamples/ -I/usr/include/python3.8 - name: Test RustBCA From 8af04f002164c5b3e676eb8b58c28de77bed6b77 Mon Sep 17 00:00:00 2001 From: Jon Drobny <37962344+drobnyjt@users.noreply.github.com> Date: Sat, 20 Nov 2021 11:03:40 -0800 Subject: [PATCH 11/14] Update rustbca_compile_check.yml --- .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 0cf7a95..ffab5fd 100644 --- a/.github/workflows/rustbca_compile_check.yml +++ b/.github/workflows/rustbca_compile_check.yml @@ -48,7 +48,7 @@ jobs: - name: Test Fortran and C bindings run : | cargo build --release - cp examples test_rustbca.f90 . + cp examples/test_rustbca.f90 . gfortran test_rustbca.f90 rustbca.f90 target/release/liblibRustBCA.so cp examples/RustBCA.c . g++ RustBCA.c RustBCA.h target/release/liblibRustBCA.so -Iexamples/ -I/usr/include/python3.8 From f6baee775e8ec0ee2a4780e3b47ea2e010ec49e0 Mon Sep 17 00:00:00 2001 From: Jon Drobny <37962344+drobnyjt@users.noreply.github.com> Date: Sat, 20 Nov 2021 11:12:24 -0800 Subject: [PATCH 12/14] Update rustbca_compile_check.yml --- .github/workflows/rustbca_compile_check.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/rustbca_compile_check.yml b/.github/workflows/rustbca_compile_check.yml index ffab5fd..c6a751c 100644 --- a/.github/workflows/rustbca_compile_check.yml +++ b/.github/workflows/rustbca_compile_check.yml @@ -49,6 +49,7 @@ jobs: run : | cargo build --release cp examples/test_rustbca.f90 . + gfortran -c rustbca.f90 target/release/liblibRustBCA.so gfortran test_rustbca.f90 rustbca.f90 target/release/liblibRustBCA.so cp examples/RustBCA.c . g++ RustBCA.c RustBCA.h target/release/liblibRustBCA.so -Iexamples/ -I/usr/include/python3.8 From ccbad254f52eec18e4fd7935a50f1eb8a3a31c15 Mon Sep 17 00:00:00 2001 From: Jon Drobny <37962344+drobnyjt@users.noreply.github.com> Date: Sat, 20 Nov 2021 11:30:35 -0800 Subject: [PATCH 13/14] Update rustbca_compile_check.yml --- .github/workflows/rustbca_compile_check.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/rustbca_compile_check.yml b/.github/workflows/rustbca_compile_check.yml index c6a751c..e31aa05 100644 --- a/.github/workflows/rustbca_compile_check.yml +++ b/.github/workflows/rustbca_compile_check.yml @@ -51,8 +51,10 @@ jobs: cp examples/test_rustbca.f90 . gfortran -c rustbca.f90 target/release/liblibRustBCA.so gfortran test_rustbca.f90 rustbca.f90 target/release/liblibRustBCA.so + ./a.out cp examples/RustBCA.c . g++ RustBCA.c RustBCA.h target/release/liblibRustBCA.so -Iexamples/ -I/usr/include/python3.8 + ./a.out - name: Test RustBCA run: | sudo cargo test --features cpr_rootfinder_netlib,hdf5_input,distributions,parry3d From 731c77a6880fd8057b981ef15aaf57fc26169fff Mon Sep 17 00:00:00 2001 From: Jon Drobny <37962344+drobnyjt@users.noreply.github.com> Date: Sat, 20 Nov 2021 11:38:11 -0800 Subject: [PATCH 14/14] Update test_rustbca.f90 --- examples/test_rustbca.f90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/test_rustbca.f90 b/examples/test_rustbca.f90 index f59d5fe..c0b8cae 100644 --- a/examples/test_rustbca.f90 +++ b/examples/test_rustbca.f90 @@ -70,6 +70,6 @@ program test_rustbca call cpu_time(stop) write(*,*) "Elapsed time in ions per eV per s: ", (stop - start)/N_ions/1000.0 - call exit(1) + !call exit(1) -end program test_rustbca \ No newline at end of file +end program test_rustbca