diff --git a/pystencils/field.py b/pystencils/field.py index 9fe59d1f4528d446bf5574e69be5fb787e5bd797..bdff323432c27fa953c8e123c8fefa47dc517bbe 100644 --- a/pystencils/field.py +++ b/pystencils/field.py @@ -676,6 +676,7 @@ class Field(AbstractField): >>> central_y_component.at_index(0) # change component v_C^0 """ + _iterable = False # see https://i10git.cs.fau.de/pycodegen/pystencils/-/merge_requests/166#note_10680 def __new__(cls, name, *args, **kwargs): obj = Field.Access.__xnew_cached_(cls, name, *args, **kwargs) @@ -756,11 +757,6 @@ class Field(AbstractField): def __getitem__(self, *idx): return self.__call__(*idx) - def __iter__(self): - """This is necessary to work with parts of sympy that test if an object is iterable (e.g. simplify). - The __getitem__ would make it iterable""" - raise TypeError("Field access is not iterable") - @property def field(self) -> 'Field': """Field that the Access points to""" diff --git a/pystencils_tests/test_field_access_poly.py b/pystencils_tests/test_field_access_poly.py new file mode 100644 index 0000000000000000000000000000000000000000..befeca9bd259e61e63bb24d1a9ceaf1016f4aedd --- /dev/null +++ b/pystencils_tests/test_field_access_poly.py @@ -0,0 +1,29 @@ +# +# Copyright © 2020 Stephan Seitz <stephan.seitz@fau.de> +# +# Distributed under terms of the GPLv3 license. + +""" + +""" + + +from pystencils.session import * + +from sympy import poly + + +def test_field_access_poly(): + dh = ps.create_data_handling((20, 20)) + Ï = dh.add_array('rho') + rho = Ï.center + a = poly(rho+0.5, rho) + print(a) + + +def test_field_access_piecewise(): + dh = ps.create_data_handling((20, 20)) + Ï = dh.add_array('rho') + pw = sp.Piecewise((0, 1 < sp.Max(-0.5, Ï.center+0.5)), (1, True)) + a = sp.simplify(pw) + print(a)