In water treatment, for example, it is common to treat mg/l
as ppm
. Currently, UnitfulEquivalences.jl
does not allow equivalences involving nondimensional quantities such as concentration. I managed to do that with two dispatches of edconvert
:
@equivalence DensityConcentration
function edconvert(d::dimtype(Unitful.Density), x::Unitful.Quantity{T,D,U}, e::DensityConcentration) where {T,D,U}
D == NoDims ? x * 1u"kg/L" : throw(_eqconversion_error(d, D, e))
end
function edconvert(d::Unitful.Dimensions{()}, x::Unitful.Quantity{T,D,U}, e::DensityConcentration) where {T,D,U}
D == Unitful.𝐌/Unitful.𝐋^3 ? x * 1u"L/kg" : throw(_eqconversion_error(d, D, e))
end
But since it is a direct relation, it would be nice to be able to define them at once with something like
@equivalence DensityConcentration
@eqrelation DensityConcentration Unitful.Density / Unitful.NoDims = 1u"kg/l"
I extended dimtype
with dimtype(::Unitful.Dimensions{()}) = typeof(Unitful.NoDims)
(despite the type piracy warning) so it could handle nondimensional quantities, but it was not enough since apparently edrelation
also complains about Unitful.NoDims
as the second argument. I think this is also related to the fact that I had to use Unitful.Quantity{T,D,U}
in my first edconvert
solution above.
As for the second edconvert
, the following code also works for the conversion from Density
to NoDims
, without the need for Unitful.Quantity{T,D,U}
, but for some reason that I do not understand it also gives me a warning of type piracy:
edconvert(d::Unitful.Dimensions{()}, x::Unitful.Density, e::DensityConcentration) = x * 1u"L/kg"
So I guess this is a "feature request" to allow one nondimensional quantity in @eqrelation
.