-
Notifications
You must be signed in to change notification settings - Fork 7
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
Integration with Unitful.jl #6
Comments
I haven't thought this through, but it looks a good solution to me. |
@peremato if this looks Ok to you in principle, should I create a PR and we'll iterate on it? |
Hi @oschulz. I do not really understand how is going to work. Most of the G4 functions (99.9%) are direct calls to the CxxWrap of the C++ function. The function (constructor) |
Sorry @peremato, my example above wasn't great - we can obviously only provide the full "luxury" for the few explicitly wrapped (but also frequently used) functions like But in all other functions, users can still write As a first step we could maybe add the constants like |
I see. Perhaps you can just define a generic conversion of julia> G4unit(x::Unitful.Quantity{<:Real, Unitful.𝐋}) = Float64(ustrip(u"mm", x))
G4unit (generic function with 1 method)
julia> G4unit(x::Unitful.Quantity{<:Real, Unitful.𝐓}) = Float64(ustrip(u"ns", x))
G4unit (generic function with 2 methods)
julia> G4unit(10u"cm")
100.0
julia> G4unit(1u"s")
1.0e9 Calling |
I though about that, but then users would actually be allowed to pass a length into a volume argument if they're not careful. The idea behind separate |
The only way the user will not be able to make a mistake or fake a call would be if we could annotate each call of Geant4 with what dimension is expected for each argument. But, this is not easily possible. I see the point of indicating derived dimensions with |
Thanks, will do! |
Still to-do, sorry ... :-) |
Geant4.jl currently has it's own implementation of physical units in
Geant4.SystemOfUnits
. It would be nice to integrate Geant4 with Unitful.jl since it's pretty much the standard for units in the Julia ecosystem.We could define
and maybe also convenience functions
That way, we could use generic code like
in "G4JLInterface.jl". Users could then write either
or
or use unitless numbers directly
Or should we try to replace
Geant4.SystemOfUnits
byUnitful
(aliases) completely?@giordano, you have a lot of experience with Unitful.jl and derived packages, do you think the design above goes in the right direction?
The text was updated successfully, but these errors were encountered: