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

Cannot dot numpy array with `MeshVariable` #962

Open guyer opened 11 months ago

guyer commented 11 months ago
>>> import fipy as fp
>>> mesh = fp.Grid1D(nx=10)
>>> n = mesh.faceNormals
>>> a = fp.FaceVariable(mesh=mesh, rank=1)
>>> n.dot(a)
Traceback (most recent call last):
  Cell In[7], line 1
    n.dot(a)
ValueError: shapes (1,11) and (1,11) not aligned: 11 (dim 1) != 1 (dim 0)

This is because numpy is expecting dot() to operate between something of shape (1,11) and something of shape (11,1), producing a single scalar. FiPy, instead, is trying to produce a field of 11 scalars from two fields of 11 vectors.

Based on the writeup on Robin conditions, this used to work, but numpy has been active lately.

Note that

>>> a.dot(n)

works fine (although it has a separate issue (#961) with the representation of an indexed variable).