|
5 | 5 | import firedrake.exceptions as fexc |
6 | 6 | import numpy as np |
7 | 7 | import ufl |
| 8 | +from animate.utility import function_data_max, function_data_min, function_data_sum |
8 | 9 | from firedrake.cython.dmcommon import create_section |
9 | 10 | from firedrake.petsc import PETSc |
10 | 11 |
|
@@ -50,8 +51,8 @@ def __init__( |
50 | 51 | stacklevel=1, |
51 | 52 | ) |
52 | 53 | self.raise_convergence_errors = raise_convergence_errors |
53 | | - self.dim = self.mesh.topological_dimension() |
54 | | - self.gdim = self.mesh.geometric_dimension() |
| 54 | + self.dim = self.mesh.topological_dimension |
| 55 | + self.gdim = self.mesh.geometric_dimension |
55 | 56 |
|
56 | 57 | # DMPlex setup |
57 | 58 | self.plex = self.mesh.topology_dm |
@@ -197,18 +198,19 @@ def volume_ratio(self): |
197 | 198 | :return: the ratio of the largest and smallest element volumes. |
198 | 199 | :rtype: :class:`float` |
199 | 200 | """ |
200 | | - volume_array = self.volume.vector().gather() |
201 | | - return volume_array.max() / volume_array.min() |
| 201 | + return function_data_max(self.volume) / function_data_min(self.volume) |
202 | 202 |
|
203 | 203 | @property |
204 | 204 | def coefficient_of_variation(self): |
205 | 205 | """ |
206 | 206 | :return: the coefficient of variation (σ/μ) of element volumes. |
207 | 207 | :rtype: :class:`float` |
208 | 208 | """ |
209 | | - volume_array = self.volume.vector().gather() |
210 | | - mean = volume_array.sum() / volume_array.size |
211 | | - return np.sqrt(np.sum((volume_array - mean) ** 2) / volume_array.size) / mean |
| 209 | + size = self.volume.dat.dataset.layout_vec.getSizes()[0] |
| 210 | + mean = function_data_sum(self.volume) / size |
| 211 | + coef = firedrake.Function(self.P0) |
| 212 | + coef.interpolate((self.volume - mean) ** 2) |
| 213 | + return np.sqrt(function_data_sum(coef) / size) / mean |
212 | 214 |
|
213 | 215 | @abc.abstractmethod |
214 | 216 | def move(self): |
|
0 commit comments