Skip to content

Commit

Permalink
Merge pull request #59 from FEniCS/test_knook_simplification_ufl
Browse files Browse the repository at this point in the history
Add native ufl test for constant complex division
  • Loading branch information
pbrubeck authored Feb 4, 2025
2 parents f769103 + 5e3296b commit d66fca3
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion test/test_evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import math

import numpy as np

from ufl import (
Argument,
Coefficient,
Expand Down Expand Up @@ -33,12 +35,28 @@
tr,
triangle,
)
from ufl.constantvalue import as_ufl
from ufl.constantvalue import ConstantValue, as_ufl
from ufl.finiteelement import FiniteElement
from ufl.pullback import identity_pullback
from ufl.sobolevspace import H1


class CustomConstant(ConstantValue):
def __init__(self, value):
super().__init__()
self._value = value

@property
def ufl_shape(self):
return ()

def evaluate(self, x, mapping, component, index_values):
return self._value

def __repr__(self):
return f"CustomConstant({self._value})"


def testScalars():
s = as_ufl(123)
e = s((5, 7))
Expand Down Expand Up @@ -132,6 +150,21 @@ def testAlgebra():
assert e == v


def testConstant():
"""Test that constant division doesn't discard the complex type in the case the value is
a numpy complex type, not a native python complex type.
"""
_a = np.complex128(1 + 1j)
_b = np.complex128(-3 + 2j)
a = CustomConstant(_a)
b = CustomConstant(_b)
expr = a / b
e = expr(())

expected = complex(_a) / complex(_b)
assert e == expected


def testIndexSum():
cell = triangle
domain = Mesh(FiniteElement("Lagrange", cell, 1, (2,), identity_pullback, H1))
Expand Down

0 comments on commit d66fca3

Please sign in to comment.