Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Allow use of symbolic function in equation and add test #102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

schymans
Copy link
Collaborator

@schymans schymans commented Dec 22, 2022

In the current version, it is not possible to use symbolic functions in Equation(), e.g.:

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

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

class d(Variable):
    """Distance"""
    unit = meter
    
class t(Variable):
    """Time"""
    unit = second

dt = Function(d)(t)    
class eq_v(Equation):
    """Average velocity as a function of time"""
    expr = Eq(v, Derivative(dt, t))

ValueError: Arguments in function are not dimensionless, but have dimensions of {Dimension(time)}

This PR disables the requirement that arguments in functions must be dimensionless.

@schymans
Copy link
Collaborator Author

Now the error is different:

dt = Function(d)(t)    
class eq_v(Equation):
    """Average velocity as a function of time"""
    expr = Eq(v, Derivative(dt, t))

ValueError: Dimension of "v" is Dimension(length/time), but it should be the same as Derivative(d(t), t), i.e. Dimension(1/time)
This is because the symbolic function dt did not inherit the units of d.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant