usnistgov / fipy

FiPy is a Finite Volume PDE solver written in Python
http://pages.nist.gov/fipy/en/latest
Other
504 stars 148 forks source link

Multiplication of MeshVariable by matrix depends on dimensionality #436

Open guyer opened 9 years ago

guyer commented 9 years ago
import fipy as fp

m2 = fp.Grid2D(nx=5, ny=1)
v2 = fp.CellVariable(mesh=m2)
v2 * [[1, 0],
      [0, 0]]

works, but

m1 = fp.Grid1D(nx=5)
v1 = fp.CellVariable(mesh=m1)
v1 * [[1, 0],
      [0, 0]]

fails with TypeError: can't multiply sequence by non-int of type 'CellVariable'.

Grid3D fails, too

guyer commented 9 years ago

The 2D case succeeds because of the explicit check for dimensionality at https://github.com/usnistgov/fipy/blob/5e4e1ba07cdf2ace16df4745493a5949fe316c09/fipy/variables/meshVariable.py#L556

I believe that bit predated vector equations and did not account for the idea that we might want to construct ranks/shapes that were not related to dimensions.