Skip to content

Commit

Permalink
Merge branch 'devel' into devel-semi-norm
Browse files Browse the repository at this point in the history
  • Loading branch information
yguclu authored Aug 29, 2023
2 parents 5b5d658 + a623184 commit ec54bc3
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 26 deletions.
2 changes: 1 addition & 1 deletion psydac/api/ast/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from sympy import Mul,Integer
from sympy.core.singleton import Singleton
from sympy.core.containers import Tuple
from sympy.core.compatibility import with_metaclass
from sympde.old_sympy_utilities import with_metaclass

from sympde.topology import element_of
from sympde.topology import ScalarFunction, VectorFunction
Expand Down
14 changes: 5 additions & 9 deletions psydac/api/ast/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import numpy as np

from sympy import S
from sympy import IndexedBase, Indexed
from sympy import Mul, Matrix, Expr
from sympy import Add, And, StrictLessThan, Eq
Expand Down Expand Up @@ -253,9 +254,9 @@ def _visit_VectorAssign(self, expr, **kwargs):
lhs = self._visit(expr.lhs)
rhs = self._visit(expr.rhs)
if expr.op is None:
return [Assign(l,r) for l,r in zip(lhs, rhs) if l is not None and r is not None]
return [Assign(l,r) for l,r in zip(lhs, rhs) if l is not None and r is not None and l is not S.Zero]
else:
return [AugAssign(l,expr.op, r) for l,r in zip(lhs, rhs) if l is not None and r is not None]
return [AugAssign(l,expr.op, r) for l,r in zip(lhs, rhs) if l is not None and r is not None and l is not S.Zero]
# ....................................................
def _visit_Assign(self, expr, **kwargs):

Expand Down Expand Up @@ -1383,7 +1384,7 @@ def _visit_ElementOf(self, expr, **kwargs):
targets = self._visit_BlockStencilMatrixLocalBasis(target)
for i in range(targets.shape[0]):
for j in range(targets.shape[1]):
if targets[i,j] is None:
if targets[i,j] is S.Zero:
continue
if trials[j] in pads.trials_multiplicity:
trials_m = pads.trials_multiplicity[trials[j]]
Expand Down Expand Up @@ -1414,7 +1415,7 @@ def _visit_ElementOf(self, expr, **kwargs):
indices = list(rows)
for i in range(targets.shape[0]):
for j in range(targets.shape[1]):
if targets[i,j] is None:
if targets[i,j] is S.Zero:
continue
targets[i,j] = targets[i,j][indices]
return targets
Expand Down Expand Up @@ -1445,7 +1446,6 @@ def _visit_BlockStencilMatrixLocalBasis(self, expr, **kwargs):
for i, v in enumerate(tests):
for j, u in enumerate(trials):
if expr.expr[i, j] == 0:
targets[i, j] = None
continue
mat = StencilMatrixLocalBasis(u=u, v=v, pads=pads[i, j], tag=tag, dtype=dtype)
mat = self._visit_StencilMatrixLocalBasis(mat, **kwargs)
Expand All @@ -1464,7 +1464,6 @@ def _visit_BlockStencilMatrixGlobalBasis(self, expr, **kwargs):
for i, v in enumerate(tests):
for j, u in enumerate(trials):
if expr.expr[i, j] == 0:
targets[i, j] = None
continue
mat = StencilMatrixGlobalBasis(u=u, v=v, pads=pads, tag=tag, dtype=dtype)
mat = self._visit_StencilMatrixGlobalBasis(mat, **kwargs)
Expand All @@ -1480,7 +1479,6 @@ def _visit_BlockStencilVectorLocalBasis(self, expr, **kwargs):
targets = Matrix.zeros(len(tests), 1)
for i, v in enumerate(tests):
if expr.expr[i, 0] == 0:
targets[i, 0] = None
continue
mat = StencilVectorLocalBasis(v, pads, tag, dtype)
mat = self._visit_StencilVectorLocalBasis(mat, **kwargs)
Expand All @@ -1496,7 +1494,6 @@ def _visit_BlockStencilVectorGlobalBasis(self, expr, **kwargs):
targets = Matrix.zeros(len(tests), 1)
for i,v in enumerate(tests):
if expr.expr[i, 0] == 0:
targets[i, 0] = None
continue
mat = StencilVectorGlobalBasis(v, pads, tag, dtype)
mat = self._visit_StencilVectorGlobalBasis(mat, **kwargs)
Expand All @@ -1513,7 +1510,6 @@ def _visit_BlockScalarLocalBasis(self, expr, **kwargs):
for i,v in enumerate(tests):
for j,u in enumerate(trials):
if expr.expr[i, j] == 0:
targets[i, j] = None
continue
var = ScalarLocalBasis(u, v, tag, dtype)
var = self._visit_ScalarLocalBasis(var, **kwargs)
Expand Down
4 changes: 2 additions & 2 deletions psydac/api/ast/tests/test_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,11 +579,11 @@ def assembly_bilinear_form_2d_1():
#==============================================================================

def teardown_module():
from sympy import cache
from sympy.core import cache
cache.clear_cache()

def teardown_function():
from sympy import cache
from sympy.core import cache
cache.clear_cache()


Expand Down
90 changes: 84 additions & 6 deletions psydac/api/ast/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,11 +891,89 @@ def build_pythran_types_header(name, args, order=None):
from sympy import preorder_traversal
from sympy import NumberSymbol
from sympy import Pow, S
from sympy.printing.pycode import _known_functions_math
from sympy.printing.pycode import _known_constants_math
from sympy.printing.pycode import _known_functions_mpmath
from sympy.printing.pycode import _known_constants_mpmath
from sympy.printing.pycode import _known_functions_numpy

_known_functions_math = {
'acos': 'acos',
'acosh': 'acosh',
'asin': 'asin',
'asinh': 'asinh',
'atan': 'atan',
'atan2': 'atan2',
'atanh': 'atanh',
'ceiling': 'ceil',
'cos': 'cos',
'cosh': 'cosh',
'erf': 'erf',
'erfc': 'erfc',
'exp': 'exp',
'expm1': 'expm1',
'factorial': 'factorial',
'floor': 'floor',
'gamma': 'gamma',
'hypot': 'hypot',
'loggamma': 'lgamma',
'log': 'log',
'ln': 'log',
'log10': 'log10',
'log1p': 'log1p',
'log2': 'log2',
'sin': 'sin',
'sinh': 'sinh',
'Sqrt': 'sqrt',
'tan': 'tan',
'tanh': 'tanh'

} # Not used from ``math``: [copysign isclose isfinite isinf isnan ldexp frexp pow modf
# radians trunc fmod fsum gcd degrees fabs]
_known_constants_math = {
'Exp1': 'e',
'Pi': 'pi',
'E': 'e'
# Only in python >= 3.5:
# 'Infinity': 'inf',
# 'NaN': 'nan'
}

_not_in_mpmath = 'log1p log2'.split()
_in_mpmath = [(k, v) for k, v in _known_functions_math.items() if k not in _not_in_mpmath]
_known_functions_mpmath = dict(_in_mpmath, **{
'beta': 'beta',
'fresnelc': 'fresnelc',
'fresnels': 'fresnels',
'sign': 'sign',
})
_known_constants_mpmath = {
'Exp1': 'e',
'Pi': 'pi',
'GoldenRatio': 'phi',
'EulerGamma': 'euler',
'Catalan': 'catalan',
'NaN': 'nan',
'Infinity': 'inf',
'NegativeInfinity': 'ninf'
}

_not_in_numpy = 'erf erfc factorial gamma loggamma'.split()
_in_numpy = [(k, v) for k, v in _known_functions_math.items() if k not in _not_in_numpy]
_known_functions_numpy = dict(_in_numpy, **{
'acos': 'arccos',
'acosh': 'arccosh',
'asin': 'arcsin',
'asinh': 'arcsinh',
'atan': 'arctan',
'atan2': 'arctan2',
'atanh': 'arctanh',
'exp2': 'exp2',
'sign': 'sign',
})
_known_constants_numpy = {
'Exp1': 'e',
'Pi': 'pi',
'EulerGamma': 'euler_gamma',
'NaN': 'nan',
'Infinity': 'PINF',
'NegativeInfinity': 'NINF'
}


def math_atoms_as_str(expr, lib='math'):
Expand Down Expand Up @@ -929,7 +1007,7 @@ def math_atoms_as_str(expr, lib='math'):
known_constants = _known_constants_mpmath
elif lib == 'numpy':
known_functions = _known_functions_numpy
known_constants = _known_constants_math # numpy version missing
known_constants = _known_constants_numpy # numpy version missing
else:
raise ValueError("Library {} not supported.".format(mod))

Expand Down
4 changes: 2 additions & 2 deletions psydac/cad/tests/test_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def test_geometry_1():

def teardown_module():
import os
from sympy import cache
from sympy.core import cache
cache.clear_cache()

# Remove HDF5 files generated by Geometry.export()
Expand All @@ -296,5 +296,5 @@ def teardown_module():
os.remove(fname)

def teardown_function():
from sympy import cache
from sympy.core import cache
cache.clear_cache()
2 changes: 1 addition & 1 deletion psydac/feec/multipatch/examples/h1_source_pbms_conga_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def solve_h1_source_pbm(

print('building the symbolic and discrete deRham sequences...')
derham = Derham(domain, ["H1", "Hcurl", "L2"])
derham_h = discretize(derham, domain_h, degree=degree, backend=PSYDAC_BACKENDS[backend_language])
derham_h = discretize(derham, domain_h, degree=degree)

# multi-patch (broken) spaces
V0h = derham_h.V0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def solve_hcurl_source_pbm(

t_stamp = time_count(t_stamp)
print('building discrete derham sequence...')
derham_h = discretize(derham, domain_h, degree=degree, backend=PSYDAC_BACKENDS[backend_language])
derham_h = discretize(derham, domain_h, degree=degree)

t_stamp = time_count(t_stamp)
print('building commuting projection operators...')
Expand Down
2 changes: 1 addition & 1 deletion psydac/pyccel/ast/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from sympy import preorder_traversal

from sympy.simplify.radsimp import fraction
from sympy.core.compatibility import with_metaclass
from sympde.old_sympy_utilities import with_metaclass
from sympy.core.assumptions import StdFactKB
from sympy.core.singleton import S
from sympy.core.function import Function, Application
Expand Down
2 changes: 1 addition & 1 deletion psydac/pyccel/ast/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .singleton import Singleton
from .basic import Basic

from sympy.core.compatibility import with_metaclass
from sympde.old_sympy_utilities import with_metaclass

import numpy

Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["setuptools >= 64.0", "wheel", "numpy < 1.25", "pyccel >= 1.8.1"]
requires = ["setuptools >= 64.0", "wheel", "numpy < 1.25", "pyccel == 1.8.1"]
build-backend = "setuptools.build_meta"

[project]
Expand Down Expand Up @@ -33,7 +33,7 @@ dependencies = [

# Our packages from PyPi
'sympde == 0.18.1',
'pyccel >= 1.8.1',
'pyccel == 1.8.1',
'gelato == 0.12',

# Alternative backend to Pyccel is Numba
Expand Down

0 comments on commit ec54bc3

Please sign in to comment.