Skip to content

Commit

Permalink
Allow turning off linearity checks in bilinear and linear forms (#153)
Browse files Browse the repository at this point in the history
Add the boolean flag `check_linearity` to the constructors of
`BilinearForm` and `LinearForm`. The default value is `True`. If set to
`False`, the linearity checks are turned off completely. This is
different than the existing flag `ignore_linearity_errors`, which
controls whether we get a warning or an error when the linearity check
fails.

The new flag might be useful when the expression in the bilinear or
linear form is complicated, because then the linearity check calls the
SymPy `Expr` method `.expand(deep=True)`, which is recursive and can
take a very long time.

---------

Co-authored-by: Yaman Güçlü <yaman.guclu@gmail.com>
  • Loading branch information
e-moral-sanchez and yguclu committed Apr 19, 2024
1 parent 75df221 commit 809b2e0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "sympde"
version = "0.18.2"
version = "0.18.3"
description = "Symbolic calculus for partial differential equations (and variational forms)"
readme = "README.rst"
requires-python = ">= 3.8, < 3.12"
Expand Down
10 changes: 5 additions & 5 deletions sympde/expr/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def space(self):
class LinearForm(BasicForm):
is_linear = True

def __new__(cls, arguments, expr, ignore_linearity_errors=False, **options):
def __new__(cls, arguments, expr, check_linearity=True, ignore_linearity_errors=False, **options):

# Trivial case: null expression
if expr == 0:
Expand All @@ -348,7 +348,7 @@ def __new__(cls, arguments, expr, ignore_linearity_errors=False, **options):
args = _sanitize_arguments(arguments, is_linear=True)

# Check linearity with respect to the given arguments
if not is_linear_expression(expr, args):
if check_linearity and not is_linear_expression(expr, args):
print(expr)
print(args)
msg = f'Expression is not linear w.r.t. [{args}]'
Expand Down Expand Up @@ -419,7 +419,7 @@ class BilinearForm(BasicForm):
is_bilinear = True
_is_symmetric = None

def __new__(cls, arguments, expr, ignore_linearity_errors=False, **options):
def __new__(cls, arguments, expr, check_linearity=True, ignore_linearity_errors=False, **options):

# Trivial case: null expression
if expr == 0:
Expand All @@ -437,7 +437,7 @@ def __new__(cls, arguments, expr, ignore_linearity_errors=False, **options):
trial_functions, test_functions = args

# Check linearity with respect to trial functions
if not is_linear_expression(expr, trial_functions):
if check_linearity and not is_linear_expression(expr, trial_functions):
msg = f'Expression is not linear w.r.t. trial functions [{trial_functions}]'
if ignore_linearity_errors:
print(msg)
Expand All @@ -446,7 +446,7 @@ def __new__(cls, arguments, expr, ignore_linearity_errors=False, **options):


# Check linearity with respect to test functions
if not is_linear_expression(expr, test_functions):
if check_linearity and not is_linear_expression(expr, test_functions):
msg = f'Expression is not linear w.r.t. test functions [{test_functions}]'
if ignore_linearity_errors:
print(msg)
Expand Down

0 comments on commit 809b2e0

Please sign in to comment.