Skip to content
Snippets Groups Projects
Commit a2d9d1ec authored by Brian Groenke's avatar Brian Groenke
Browse files

Add additional unit macro for number type

parent 766f5a77
No related branches found
No related tags found
1 merge request!33Add new additive heat source subsurface process
......@@ -14,6 +14,8 @@ import ReverseDiff
include("macros.jl")
export @xu_str, @Float_str, @Real_str, @Number_str, @UFloat_str, @UT_str, @setscalar
# Convenience constants for units
const DistUnit{N} = Unitful.FreeUnits{N,Unitful.𝐋,nothing} where {N}
const DistQuantity{T,U} = Quantity{T,Unitful.𝐋,U} where {T,U<:DistUnit}
......@@ -83,6 +85,10 @@ dustrip(u::Unitful.Units, x::Number) = CryoGrid.CRYOGRID_DEBUG ? x : ustrip(u,x)
export dustrip
duconvert(u::Unitful.Units, x::Number) = CryoGrid.CRYOGRID_DEBUG ? x : uconvert(u,x)
export duconvert
getscalar(x::Number) = x
getscalar(a::AbstractArray) = a[1]
......
......@@ -10,11 +10,16 @@ If debug mode is not enabled, plain Float64 is used instead.
"""
macro Float_str(unit) CryoGrid.CRYOGRID_DEBUG ? :(typeof(@u_str($unit)*0.0)) : :(Float64) end
"""
Similar to @UT_str but produces a Real quantity type for the given unit if and only if debug mode is enabled.
If debug mode is not enabled, plain Float64 is used instead.
Similar to @UT_str but produces a Float64 quantity type for the given unit if and only if debug mode is enabled.
If debug mode is not enabled, plain Real is used instead.
"""
macro Real_str(unit) CryoGrid.CRYOGRID_DEBUG ? :(typeof(@u_str($unit)*0.0)) : :(Real) end
"""
Similar to @UT_str but produces a Float64 quantity type for the given unit if and only if debug mode is enabled.
If debug mode is not enabled, plain Number is used instead.
"""
macro Number_str(unit) CryoGrid.CRYOGRID_DEBUG ? :(typeof(@u_str($unit)*0.0)) : :(Number) end
"""
Similar to Unitful.@u_str (i.e. u"kg") but produces the type of the quantity rather than the instance. NOT conditional
on debug mode.
"""
......@@ -40,5 +45,3 @@ macro setscalar(expr)
$(esc(refexpr))[1] = $(esc(valexpr))
end
end
export @xu_str, @Float_str, @Real_str, @UFloat_str, @UT_str, @setscalar
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment