diff --git a/nifty5/multi/multi_field.py b/nifty5/multi/multi_field.py index 4f385296812ac7f7d26af9fb6e48b347b01027f0..33150a033807bbbda19a383a8daaec739e6feb61 100644 --- a/nifty5/multi/multi_field.py +++ b/nifty5/multi/multi_field.py @@ -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. + + Returns + ------- + 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 + + @property + def size(self): + """ Computes the overall degrees of freedom. + + Returns + ------- + 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.