Open jrising opened 8 years ago
Yes, I agree, we should add this!
A few random points:
UnitedObject
. This plays into the general parameter handling story. I'm not happy how that is done in general right now, but haven't really figured out a good alternative. Would be good to discuss this broader question.The Unitful package is just the sort of thing I would want to use. I'm worried though about runtime costs. Also, bizarrely, the Unitful documentation says nothing about arrays. I think we should not wed Mimi to any particular unit system.
@jrising @davidanthoff Unitful includes support for arrays (now referenced in the docs here http://ajkeller34.github.io/Unitful.jl/stable/manipulations/). They claim to have a very small performance penalty.
Let's bump this towards top of discussion as it would be a well-contained, but valuable, contribution. We also see interest on the forum here: https://forum.mimiframework.org/t/mimi-and-unitful/182/2
I think units are really important in building and validating models. In the next few weeks, I propose that I will add a unit system to Mimi, which will be optional unless it's required. I see that the
MetaVariable
andMetaParameter
types have a units field, but I don't think they're in current use and I propose some changes.The most advanced version of this would do unit conversion, and understand how arithmetic changes units. I want to put in something simpler, with some planning to help it be replaced later without too much trouble.
Parameters and variables will take an optional argument, units, which will be of any type; the typical case is that it would be a string. The units would be stored in a field in the
MetaVariable
andMetaParameter
types-- so I would just change these from UTF8String to Any. The Any type will allow conversion-aware units to be handled later, using the overloadedunitcheck
andunitconvert
functions.If a component is connected through a parameter or variable that has units, it will be required that the other side also have units and that these units match.
connectparameter
would make this check.Similarly,
setparameter
for united parameters would require that thevalue
is of type UnitedObject, which is just a wrapper around both avalue::Any
and aunits::Any
, and that the units match.To support future work, the checks between components will use a
unitcheck(Any, Any)
function. Eventually, I want to have a system that would automatically create a whole component in between two connected components, if that's what's necessary to connect two components.When using
setparameter
, the UnitedObject would be passed to aunitconvert(UnitedObject, unit::Any)
function, which returns the raw data (possibly in a converted form). In version 1,unitconvert
will just callunitcheck
and then returnvalue
.