environmentalscience / essm

This package contains helpers to deal with physical variables and units.
https://environmentalscience.github.io/essm/
GNU General Public License v2.0
12 stars 5 forks source link

Dimensions and units of Derivatives not handled well #103

Closed schymans closed 1 year ago

schymans commented 1 year ago

The units and dimensions of Derivatives are not handled well, as the units of Derivative(meter, second) should be meter/second), but we get:

from sympy import Derivative, Eq, Function, symbols
from essm.variables import Variable
from essm.equations import Equation
from essm.variables.units import meter, second
from essm.variables.units import derive_unit, derive_baseunit

class v(Variable):
    """Velocity"""
    unit = meter / second

class d(Variable):
    """Distance"""
    unit = meter

class t(Variable):
    """Time"""

dt = Function(d)(t) 

print(Derivative(dt, t))
print(derive_unit(Derivative(dt, t)))
print('Even using the symbols in Derivative does not give meter/second as base units:')
print(Derivative(d,t))
print(derive_baseunit(Derivative(d,t)))

Derivative(d(t), t) 1 Even using the symbols in Derivative does not give meter/second as base units: Derivative(d, t) meter

schymans commented 1 year ago

In the above, I forgot to provide the units for t, and if this is done, everything works.