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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions essm/variables/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,10 @@ def collect_factor_and_basedimension(expr):
elif isinstance(expr, Function):
fds = {Variable.collect_factor_and_basedimension(
arg)[1] for arg in expr.args}
if fds != {Dimension(1)}:
raise ValueError(
'Arguments in function are not dimensionless, '
'but have dimensions of {0}'.format(fds))
# if fds != {Dimension(1)}:
# raise ValueError(
# 'Arguments in function are not dimensionless, '
# 'but have dimensions of {0}'.format(fds))
return expr, Dimension(1)
elif isinstance(expr, Dimension):
return 1, expr
Expand Down
11 changes: 10 additions & 1 deletion tests/test_equations.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
derive_baseunit)
from essm.variables.utils import (extract_variables, replace_defaults,
replace_variables)
from sympy import cos, Derivative, exp, log, S, Symbol, solve, sqrt
from sympy import cos, Derivative, exp, Function, log, S, Symbol, solve, sqrt
from sympy.physics.units import Quantity, length, meter


Expand Down Expand Up @@ -288,6 +288,15 @@ class var_joule_base(Variable):
1 - exp(var_joule/var_joule_base)


def test_check_unit_function():
"""
Make sure that check_unit works with symbolic functions"""

f = Function('f')(demo_t)
assert Variable.check_unit(Derivative(f, demo_t)) == \
Derivative(f, demo_t)


def test_double_registration():
"""Check double registration warning."""

Expand Down