From f7877610b9a372d9a1ee512fe9fb69dc8b0225a9 Mon Sep 17 00:00:00 2001 From: Stan Schymanski Date: Thu, 22 Dec 2022 00:38:41 +0100 Subject: [PATCH] Allow use of symbolic function in equation and add test --- essm/variables/_core.py | 8 ++++---- tests/test_equations.py | 11 ++++++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/essm/variables/_core.py b/essm/variables/_core.py index 0068573..e43bb70 100644 --- a/essm/variables/_core.py +++ b/essm/variables/_core.py @@ -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 diff --git a/tests/test_equations.py b/tests/test_equations.py index bad3b23..1245ecb 100644 --- a/tests/test_equations.py +++ b/tests/test_equations.py @@ -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 @@ -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."""