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

adding test with numpy constants #158

Merged
merged 4 commits into from
Jul 15, 2024
Merged
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
9 changes: 8 additions & 1 deletion sympde/topology/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ def get_logical_test_function(u):
el = l_space.element(u.name)
return el

import numpy as np

def numpy_to_native_python(a):
if isinstance(a, np.generic):
return a.item()
return a

#==============================================================================
class BasicCallableMapping(ABC):
"""
Expand Down Expand Up @@ -223,7 +230,7 @@ def __new__(cls, name, dim=None, **kwargs):
constants_values = {a.name:Constant(a.name) for a in constants}
# subs constants as Constant objects instead of Symbol
constants_values.update( kwargs )
d = {a:constants_values[a.name] for a in constants}
d = {a:numpy_to_native_python(constants_values[a.name]) for a in constants}
args = args.subs(d)

obj._expressions = args
Expand Down
21 changes: 20 additions & 1 deletion sympde/topology/tests/test_mapping.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# coding: utf-8

import numpy as np

from sympy.core.containers import Tuple
from sympy import Matrix
from sympy.tensor import IndexedBase
from sympy import symbols, simplify

from sympde.topology import Mapping, MappedDomain
from sympde.topology import Mapping, MappedDomain, AffineMapping
from sympde.topology import dx, dy, dz
from sympde.topology import dx1, dx2, dx3
from sympde.topology import Domain
Expand Down Expand Up @@ -127,6 +129,23 @@ def test_mapping_2d_2():
domain = Domain('Omega', dim=dim)
D = F(domain)

def test_AffineMapping():
print('============ test_AffineMapping ==============')

dim = 2
alpha = np.pi/2
c1 = 0.2
c2 = 1.5

F = AffineMapping(
name='F', dim=2, c1=c1, c2=c2,
a11=np.cos(alpha), a12=-np.sin(alpha),
a21=np.sin(alpha), a22=np.cos(alpha),
)

domain = Domain('Omega', dim=dim)
D = F(domain)

#==============================================================================
# CLEAN UP SYMPY NAMESPACE
#==============================================================================
Expand Down