mirror of
https://github.com/Cian-H/nanoconc.git
synced 2025-12-22 22:22:01 +00:00
Working test bench for bhmie implementation
This commit is contained in:
17
.vscode/launch.json
vendored
Normal file
17
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"type": "julia",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Run active Julia file",
|
||||||
|
"program": "${file}",
|
||||||
|
"stopOnEntry": false,
|
||||||
|
"cwd": "${workspaceFolder}",
|
||||||
|
"juliaEnv": "${command:activeJuliaEnvironment}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
[deps]
|
[deps]
|
||||||
|
AirspeedVelocity = "1c8270ee-6884-45cc-9545-60fa71ec23e4"
|
||||||
|
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
|
||||||
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
|
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
|
||||||
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
|
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
|
||||||
|
Debugger = "31a5f54b-26ea-5ae9-a837-f05ce5417438"
|
||||||
HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
|
HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
|
||||||
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
|
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
|
||||||
Memoize = "c03570c3-d221-55d1-a50c-7939bbd78826"
|
Memoize = "c03570c3-d221-55d1-a50c-7939bbd78826"
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
run(`scripts/build_other_impls.sh`)
|
run(`scripts/build_other_impls.sh`)
|
||||||
|
|
||||||
|
# using Debugger
|
||||||
|
using BenchmarkTools
|
||||||
|
|
||||||
include("src/miemfp.jl")
|
include("src/miemfp.jl")
|
||||||
# using miemfp
|
# using miemfp
|
||||||
|
|
||||||
@@ -15,7 +18,7 @@ function bhmie_c(x::Float32, cxref::ComplexF32, nang::UInt32, cxs1::Vector{Compl
|
|||||||
|
|
||||||
# Call the C function
|
# Call the C function
|
||||||
ccall((:bhmie, ".bhmielibs/bhmie-c/bhmie.so"), Cvoid,
|
ccall((:bhmie, ".bhmielibs/bhmie-c/bhmie.so"), Cvoid,
|
||||||
(Float32, ComplexF32, UInt32, Ptr{ComplexF32}, Ptr{ComplexF32}, Ref{Float32}, Ref{Float32}, Ref{Float32}, Ref{Float32}),
|
(Float32, ComplexF32, UInt32, Vector{ComplexF32}, Vector{ComplexF32}, Ref{Float32}, Ref{Float32}, Ref{Float32}, Ref{Float32}),
|
||||||
x, cxref, nang, cxs1, cxs2, qext, qsca, qback, gsca)
|
x, cxref, nang, cxs1, cxs2, qext, qsca, qback, gsca)
|
||||||
|
|
||||||
# Return the output variables
|
# Return the output variables
|
||||||
@@ -54,27 +57,44 @@ function bhmie_fortran77(x::Float32, refrel::ComplexF32, nang::Int32, s1::Vector
|
|||||||
return qext[], qsca[], qback[], gsca[]
|
return qext[], qsca[], qback[], gsca[]
|
||||||
end
|
end
|
||||||
|
|
||||||
# Create test data
|
# Fixed testing values
|
||||||
x = Float32(1.0) # Example value for x
|
|
||||||
cxref = ComplexF32(1.5, 0.5) # Example complex refractive index
|
|
||||||
nang = UInt32(2) # Example number of angles
|
nang = UInt32(2) # Example number of angles
|
||||||
|
|
||||||
# Example arrays for scattering amplitudes, initialized with dummy complex values
|
c_result = @benchmark bhmie_c(x, cxref, nang, cxs1, cxs2) setup=(
|
||||||
cxs1 = [ComplexF32(0.1, 0.2) for _ in 1:nang]
|
x = rand(Float32);
|
||||||
cxs2 = [ComplexF32(0.3, 0.4) for _ in 1:nang]
|
cxref = rand(ComplexF32);
|
||||||
|
nang = UInt32($nang);
|
||||||
|
cxs1 = rand(ComplexF32, $nang);
|
||||||
|
cxs2 = rand(ComplexF32, $nang);
|
||||||
|
)
|
||||||
|
|
||||||
# Test C wrapper
|
f_result = @benchmark bhmie_fortran(x, cxref, nang, cxs1, cxs2) setup=(
|
||||||
qext, qsca, qback, gsca = bhmie_c(x, cxref, nang, cxs1, cxs2)
|
x = rand(Float32);
|
||||||
println("bhmie_c output: qext = $qext, qsca = $qsca, qback = $qback, gsca = $gsca")
|
cxref = rand(ComplexF32);
|
||||||
|
nang = Int32($nang);
|
||||||
|
cxs1 = rand(ComplexF32, $nang);
|
||||||
|
cxs2 = rand(ComplexF32, $nang);
|
||||||
|
)
|
||||||
|
|
||||||
# Test Fortran wrapper
|
f77_result = @benchmark bhmie_fortran77(x, cxref, nang, cxs1, cxs2) setup=(
|
||||||
qext, qsca, qback, gsca = bhmie_fortran(x, cxref, Int32(nang), cxs1, cxs2)
|
x = rand(Float32);
|
||||||
println("bhmie_fortran output: qext = $qext, qsca = $qsca, qback = $qback, gsca = $gsca")
|
cxref = rand(ComplexF32);
|
||||||
|
nang = Int32($nang);
|
||||||
|
cxs1 = rand(ComplexF32, $nang);
|
||||||
|
cxs2 = rand(ComplexF32, $nang);
|
||||||
|
)
|
||||||
|
|
||||||
# Test Fortran77 wrapper
|
j_result = @benchmark miemfp.bhmie(Float64(x), ComplexF64(cxref), nang) setup=(
|
||||||
qext, qsca, qback, gsca = bhmie_fortran77(x, cxref, Int32(nang), cxs1, cxs2)
|
x = rand(Float32);
|
||||||
println("bhmie_fortran77 output: qext = $qext, qsca = $qsca, qback = $qback, gsca = $gsca")
|
cxref = rand(ComplexF32);
|
||||||
|
nang = UInt32($nang);
|
||||||
|
)
|
||||||
|
|
||||||
# Test Julia wrapper
|
println("\nC Implementation")
|
||||||
qext, qsca, qback, gsca = miemfp.bhmie(Float64(x), ComplexF64(cxref), nang)
|
display(c_result)
|
||||||
println("bhmie_julia output: qext = $qext, qsca = $qsca, qback = $qback, gsca = $gsca")
|
println("\nFortran Implementation")
|
||||||
|
display(f_result)
|
||||||
|
println("\nFortran 77 Implementation")
|
||||||
|
display(f77_result)
|
||||||
|
println("\nJulia Implementation")
|
||||||
|
display(j_result)
|
||||||
|
|||||||
Reference in New Issue
Block a user