Commit 7efbe721 authored by Martin Reinecke's avatar Martin Reinecke
Browse files

introduce and use squared_norm()

parent 67e96903
...@@ -487,6 +487,16 @@ class Field(object): ...@@ -487,6 +487,16 @@ class Field(object):
""" """
return np.sqrt(abs(self.vdot(x=self))) return np.sqrt(abs(self.vdot(x=self)))
def squared_norm(self):
""" Computes the square of the L2-norm of the field values.
Returns
-------
float
The square of the L2-norm of the field values.
"""
return abs(self.vdot(x=self))
def conjugate(self): def conjugate(self):
""" Returns the complex conjugate of the field. """ Returns the complex conjugate of the field.
......
...@@ -45,7 +45,7 @@ class UnitLogGauss(Energy): ...@@ -45,7 +45,7 @@ class UnitLogGauss(Energy):
@property @property
@memo @memo
def value(self): def value(self):
return .5 * self._s.value.vdot(self._s.value).real return .5 * self._s.value.squared_norm()
@property @property
@memo @memo
......
...@@ -151,6 +151,16 @@ class MultiField(object): ...@@ -151,6 +151,16 @@ class MultiField(object):
""" """
return np.sqrt(np.abs(self.vdot(x=self))) return np.sqrt(np.abs(self.vdot(x=self)))
def squared_norm(self):
""" Computes the square of the L2-norm of the field values.
Returns
-------
float
The square of the L2-norm of the field values.
"""
return abs(self.vdot(x=self))
def __neg__(self): def __neg__(self):
return MultiField({key: -val for key, val in self.items()}) return MultiField({key: -val for key, val in self.items()})
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment