Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Layered flux at multiple SDS #11

Open
heltonmc opened this issue Nov 4, 2021 · 1 comment
Open

Layered flux at multiple SDS #11

heltonmc opened this issue Nov 4, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@heltonmc
Copy link
Owner

heltonmc commented Nov 4, 2021

Appears to be an issue calculating the flux when rho is a vector.

julia> data = Nlayer_cylinder(a = 10.0, l = [1.0, 1.0, 1.0, 2.0], z = 5.0, ρ = [1.0, 2.0])
julia> flux_DA_Nlay_cylinder_CW(data)
ERROR: MethodError: no method matching Float64(::ForwardDiff.Dual{ForwardDiff.Tag{LightPropagation.var"#69#71"{Vector{Float64}, Vector{Float64}, Vector{Float64}, Float64, Vector{Float64}, Vector{Float64}, Float64, Vector{Float64}}, Float64}, Float64, 1})
Closest candidates are:
  (::Type{T})(::Real, ::RoundingMode) where T<:AbstractFloat at rounding.jl:200
  (::Type{T})(::T) where T<:Number at boot.jl:760
  (::Type{T})(::AbstractChar) where T<:Union{AbstractChar, Number} at char.jl:50
  ...
Stacktrace:
 [1] convert(#unused#::Type{Float64}, x::ForwardDiff.Dual{ForwardDiff.Tag{LightPropagation.var"#69#71"{Vector{Float64}, Vector{Float64}, Vector{Float64}, Float64, Vector{Float64}, Vector{Float64}, Float64, Vector{Float64}}, Float64}, Float64, 1})
   @ Base ./number.jl:7
 [2] setindex!(A::Vector{Float64}, x::ForwardDiff.Dual{ForwardDiff.Tag{LightPropagation.var"#69#71"{Vector{Float64}, Vector{Float64}, Vector{Float64}, Float64, Vector{Float64}, Vector{Float64}, Float64, Vector{Float64}}, Float64}, Float64, 1}, i1::Int64)
   @ Base ./array.jl:839
 [3] _kernel_fluence_DA_Nlay_cylinder::Vector{Float64}, D::Vector{Float64}, μa::Vector{Float64}, a::Float64, zb::Vector{Float64}, z::ForwardDiff.Dual{ForwardDiff.Tag{LightPropagation.var"#69#71"{Vector{Float64}, Vector{Float64}, Vector{Float64}, Float64, Vector{Float64}, Vector{Float64}, Float64, Vector{Float64}}, Float64}, Float64, 1}, z0::Float64, l::Vector{Float64}, n_med::Vector{Float64}, besselroots::Vector{Float64}, green::typeof(LightPropagation._green_Nlaycylin_bottom), N::Int64)
   @ LightPropagation ~/.julia/packages/LightPropagation/fzSt3/src/forwardmodels/Diffusion Approximation/DAcylinder_layered.jl:322
 [4] fluence_DA_Nlay_cylinder_CW::Vector{Float64}, μa::Vector{Float64}, μsp::Vector{Float64}, n_ext::Float64, n_med::Vector{Float64}, l::Vector{Float64}, a::Float64, z::ForwardDiff.Dual{ForwardDiff.Tag{LightPropagation.var"#69#71"{Vector{Float64}, Vector{Float64}, Vector{Float64}, Float64, Vector{Float64}, Vector{Float64}, Float64, Vector{Float64}}, Float64}, Float64, 1}, besselroots::Vector{Float64})
   @ LightPropagation ~/.julia/packages/LightPropagation/fzSt3/src/forwardmodels/Diffusion Approximation/DAcylinder_layered.jl:63
 [5] #69
   @ ~/.julia/packages/LightPropagation/fzSt3/src/forwardmodels/Diffusion Approximation/DAcylinder_layered.jl:108 [inlined]
 [6] derivative
   @ ~/.julia/packages/ForwardDiff/5gUap/src/derivative.jl:14 [inlined]
 [7] flux_DA_Nlay_cylinder_CW::Vector{Float64}, μa::Vector{Float64}, μsp::Vector{Float64}, n_ext::Float64, n_med::Vector{Float64}, l::Vector{Float64}, a::Float64, z::Float64, besselroots::Vector{Float64})
   @ LightPropagation ~/.julia/packages/LightPropagation/fzSt3/src/forwardmodels/Diffusion Approximation/DAcylinder_layered.jl:108
 [8] flux_DA_Nlay_cylinder_CW(data::Nlayer_cylinder{Float64})
   @ LightPropagation ~/.julia/packages/LightPropagation/fzSt3/src/forwardmodels/Diffusion Approximation/DAcylinder_layered.jl:121
 [9] top-level scope
   @ REPL[8]:1
@heltonmc
Copy link
Owner Author

heltonmc commented Nov 11, 2021

Want to specify this works when ρ is a scalar.

julia> data = Nlayer_cylinder(a = 10.0, l = [1.0, 1.0, 1.0, 2.0], z = 5.0, ρ = 1.0)
Nlayer_cylinder{Float64}

julia> flux_DA_Nlay_cylinder_CW(data)
4.342134601324081e-6

A work around is to just call the scalar version on many values of ρ

julia> map-> flux_DA_Nlay_cylinder_CW(Nlayer_cylinder(a = 10.0, ρ = ρ)), [0.5, 1.0, 1.5])
3-element Vector{Float64}:
 0.1298666669051858
 0.011815624951152489
 0.0020139880886783975

Though this does come at a computational hit because we are redoing a bunch of similar calculations. I am not actively working on fixing this right now. I am hoping to maybe transition to some of the new AD platforms in the future....

Edit: I will probably implement the analytical derivatives for this which will resolve this issue.

@heltonmc heltonmc added bug Something isn't working wontfix This will not be worked on labels Nov 11, 2021
@heltonmc heltonmc removed the wontfix This will not be worked on label Apr 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant