Commit 04b8ef81 authored by Mosè Giordano's avatar Mosè Giordano
Browse files

Fix definition of units

The exponent applies to the multiplier as well.  Reorganize the `get_unit`
function to make it clearer what's the formula used.
parent b52d201b
......@@ -239,17 +239,22 @@ const UNIT_KIND_STRINGS_TO_UNIT = Dict(
)
# Get a `Unitful` quantity out of a `Unit_t`.
get_unit(u::VPtr) =
UNIT_KIND_STRINGS_TO_UNIT[unsafe_string(
function get_unit(u::VPtr)
multiplier = ccall(sbml(:Unit_getMultiplier), Cdouble, (VPtr,), u)
unit = UNIT_KIND_STRINGS_TO_UNIT[unsafe_string(
ccall(
sbml(:UnitKind_toString),
Cstring,
(Cint,),
ccall(sbml(:Unit_getKind), Cint, (VPtr,), u),
),
)]^ccall(sbml(:Unit_getExponent), Cint, (VPtr,), u) *
exp10(ccall(sbml(:Unit_getScale), Cint, (VPtr,), u)) *
ccall(sbml(:Unit_getMultiplier), Cdouble, (VPtr,), u)
)]
scale = ccall(sbml(:Unit_getScale), Cint, (VPtr,), u)
exponent = ccall(sbml(:Unit_getExponent), Cint, (VPtr,), u)
# See page 44 of
# http://sbml.org/Special/specifications/sbml-level-3/version-2/core/release-2/sbml-level-3-version-2-release-2-core.pdf
return (multiplier * unit * exp10(scale)) ^ exponent
end
# Get `Unitful` quantity out of a `UnitDefinition_t`.
get_units(ud::VPtr) = prod(
......
......@@ -22,7 +22,7 @@ end
sbmlfile * ".does.not.really.exist",
)
@test mdl.units["mmol_per_gDW_per_hr"] == 2.7777e-7 * u"mol * g^-1 * s^-1"
@test mdl.units["mmol_per_gDW_per_hr"] 3.6001008028224795 * u"mol * g^-1 * s^-1"
@test length(mdl.compartments) == 2
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment