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

subs() in equation drops left-hand-side #46

Closed schymans closed 5 years ago

schymans commented 6 years ago

Substitution into an equation drops the left-hand-side of the equation, and only returns the right hand side:

print demo_fall
print demo_fall.subs(demo_d, demo_d1)

returns

Eq(demo_d, demo_g*t**2/2)
demo_g*t**2/2

It should return instead:

Eq(demo_d, demo_g*t**2/2)
Eq(demo_d1, demo_g*t**2/2)
schymans commented 6 years ago

Here is a more complete example:

from essm.variables import Variable
from essm.equations import Equation
from sympy.physics.units import meter, second
from sympy import Eq, S

class l1(Variable):
    """Length"""
    unit = meter

class l2(Variable):
    """Length"""
    unit = meter  

class g(Variable):
    """Graviational acceleration"""
    unit = meter  / second ** 2
    default = 9.8

class t1(Variable):
    """Time"""
    unit = second

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

class eq_fall(Equation):
    """Distance of fall."""
    expr = Eq(l1, S(1) / S(2) * g * t1 ** 2)

print eq_fall
print eq_fall.subs(l1, l2)

returns:

Eq(l1, g*t1**2/2)
g*t1**2/2

This does not happen for sympy Eq():

eq_fall = Eq(l1, S(1) / S(2) * g * t1 ** 2)
print eq_fall

returns:

Eq(l1, g*t1**2/2)
Eq(l2, g*t1**2/2)
schymans commented 5 years ago

PR #47 solved this issue.