Commit 3517e77d authored by Reimar H Leike's avatar Reimar H Leike
Browse files

added .sum() and .size method to MultiFields

parent 2ef525d5
......@@ -147,6 +147,36 @@ class MultiField(object):
return np.sqrt(np.abs(self.vdot(x=self)))
def sum(self):
""" Computes the sum all field values.
norm : float
The sum of the field values.
result = 0.0
for v in self._val:
if isinstance(v, Field):
#not using += here in case of complex numbers
result = result + v.sum()
return result
def size(self):
""" Computes the overall degrees of freedom.
size : int
The sum of the size of the individual fields
result = 0
for k in self.keys():
result += self._domain[k].size
return result
def squared_norm(self):
""" Computes the square of the L2-norm of the field values.
Supports Markdown
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