Skip to content

Handle physical units #8

@jonc125

Description

@jonc125
  • Need to parse Model level units
  • Need to parse Component level units, stored separately
  • Need to resolve units to the correct level (component, model, predefined)
  • Need all numbers in equations to be quantities with units
  • Similarly all variables have units (although, see Model manipulation #21, these may not be known when the equation is first created, and need to be calculated when all model manipulation done) (issue Adding unit conversion for code generation #77 will deal with this)
  • Need to be able to calculate the units for an expression
  • Need to be able to automate units conversions (including adding explicit conversions in generated code) (issue Adding unit conversion for code generation #77 will deal with this)
    • These are only required at connections between components
    • The protocol can define conversion functions for cases where you're not just scaling within one dimension. These specify the source dimension (actually, arbitrary source units within that dimension), target dimension, and a unary function converting a value from source to target units. This gets to the correct dimension; scaling may then be needed to get the exact required units.
  • Handle 'quirks' in the CellML units system
    • The SI base units supported are: ampere, candela, kelvin, kilogram, meter, mole, second
    • Modellers can define new 'base units' to create novel dimensions, unrelated to any other units
    • There is an explicit 'dimensionless' unit for plain numbers
    • There are some name aliases: metre/meter, litre/liter
    • pycml adds special 'boolean' units for the results of relational operators and the MathML symbols true and false. There could be other ways of handling this :)
    • CellML does have an 'offset' field to support e.g. Celsius & Fahrenheit. But no models use this and the semantics are broken, so we'll say it's not allowed!
  • Handle typical 'quirks' in CellML models, e.g.
    • exp(V) where V is in volts, not dimensionless (occasionally also in volt^2, millimolar, ...)
    • tanh(V) where V is in volts, not dimensionless
    • Many models also have more serious errors, mostly dimensional mismatches in the operands to eq, geq, gt, minus, plus, piecewise. Currently we only warn about these when generating code, as otherwise we'd need to fix lots of CellML files!

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions