diff --git a/pyproject.toml b/pyproject.toml index fee5180..1a44d71 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "sympde" -version = "0.18.1" +version = "0.18.2" description = "Symbolic calculus for partial differential equations (and variational forms)" readme = "README.rst" requires-python = ">= 3.8, < 3.12" diff --git a/sympde/expr/expr.py b/sympde/expr/expr.py index f0ae68f..bd87dfb 100644 --- a/sympde/expr/expr.py +++ b/sympde/expr/expr.py @@ -334,7 +334,7 @@ def space(self): class LinearForm(BasicForm): is_linear = True - def __new__(cls, arguments, expr, **options): + def __new__(cls, arguments, expr, ignore_linearity_errors=False, **options): # Trivial case: null expression if expr == 0: @@ -349,8 +349,13 @@ def __new__(cls, arguments, expr, **options): # Check linearity with respect to the given arguments if not is_linear_expression(expr, args): - msg = 'Expression is not linear w.r.t [{}]'.format(args) - raise UnconsistentLinearExpressionError(msg) + print(expr) + print(args) + msg = f'Expression is not linear w.r.t. [{args}]' + if ignore_linearity_errors: + print(msg) + else: + raise UnconsistentLinearExpressionError(msg) # Create new object of type LinearForm obj = Basic.__new__(cls, args, expr) @@ -414,7 +419,7 @@ class BilinearForm(BasicForm): is_bilinear = True _is_symmetric = None - def __new__(cls, arguments, expr, **options): + def __new__(cls, arguments, expr, ignore_linearity_errors=False, **options): # Trivial case: null expression if expr == 0: @@ -433,15 +438,20 @@ def __new__(cls, arguments, expr, **options): # Check linearity with respect to trial functions if not is_linear_expression(expr, trial_functions): - msg = ' Expression is not linear w.r.t trial functions {}'\ - .format(trial_functions) - raise UnconsistentLinearExpressionError(msg) + msg = f'Expression is not linear w.r.t. trial functions [{trial_functions}]' + if ignore_linearity_errors: + print(msg) + else: + raise UnconsistentLinearExpressionError(msg) + # Check linearity with respect to test functions if not is_linear_expression(expr, test_functions): - msg = ' Expression is not linear w.r.t test functions {}'\ - .format(test_functions) - raise UnconsistentLinearExpressionError(msg) + msg = f'Expression is not linear w.r.t. test functions [{test_functions}]' + if ignore_linearity_errors: + print(msg) + else: + raise UnconsistentLinearExpressionError(msg) # Create new object of type BilinearForm obj = Basic.__new__(cls, args, expr)