Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[VectorArrays] fix FenicsVectorSpace.__hash__
  • Loading branch information
sdrave committed Dec 14, 2016
1 parent e0bca2c commit c312114
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/pymor/vectorarrays/fenics.py
Expand Up @@ -19,14 +19,6 @@
from pymor.vectorarrays.list import CopyOnWriteVector, ListVectorSpace


# For pyMOR's MPI support to work, VectorSpaces need to be hashable.
# However, FunctionSpace defines __eq__ but not __hash__ which
# makes it unhashable on Pyhton 3. On the other hand, equality
# for FunctionSpace seems to be the same as identity, so we can easily
# monkey-patch:
df.FunctionSpace.__hash__ = lambda self: id(self)


class FenicsVector(CopyOnWriteVector):
"""Wraps a FEniCS vector to make it usable with ListVectorArray."""

Expand Down Expand Up @@ -125,6 +117,10 @@ def dim(self):
def __eq__(self, other):
return type(other) is FenicsVectorSpace and self.V == other.V and self.id == other.id

# since we implement __eq__, we also need to implement __hash__
def __hash__(self):
return id(self.V) + hash(self.id)

def zero_vector(self):
impl = df.Function(self.V).vector()
return FenicsVector(impl)
Expand Down

0 comments on commit c312114

Please sign in to comment.