Skip to content
Snippets Groups Projects
Closed Cannot simplify piecewise function with field access in condition
  • View options
  • Cannot simplify piecewise function with field access in condition

  • View options
  • Closed Issue created by Michael Kuron

    This fails:

    from pystencils.session import *
    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))
    sp.simplify(pw)

    with the following error:

    ./pystencils/pystencils/field.py in __iter__(self)
        760             """This is necessary to work with parts of sympy that test if an object is iterable (e.g. simplify).
        761             The __getitem__ would make it iterable"""
    --> 762             raise TypeError("Field access is not iterable")
        763 
        764         @property
    
    TypeError: Field access is not iterable

    Here are two similar examples that do not produce such an error:

    s = sp.Symbol("s")
    pw = sp.Piecewise((0, 1 < sp.Max(-0.5, s+0.5)), (1, True))
    sp.simplify(pw)
    
    pw = sp.Piecewise((0, 1 < ρ.center+0.5), (1, True))
    sp.simplify(pw)

    Linked items ... 0

  • Activity

    • All activity
    • Comments only
    • History only
    • Newest first
    • Oldest first
    Loading Loading Loading Loading Loading Loading Loading Loading Loading Loading