|
1 | 1 | from FIAT.quadrature_schemes import create_quadrature |
2 | 2 | from FIAT.quadrature import FacetQuadratureRule |
3 | | -from FIAT.functional import PointEvaluation, FrobeniusIntegralMoment |
| 3 | +from FIAT.functional import PointEvaluation, FrobeniusIntegralMoment, Functional |
4 | 4 | from fuse.utils import sympy_to_numpy |
5 | 5 | import numpy as np |
6 | 6 | import sympy as sp |
@@ -40,12 +40,7 @@ def convert_to_fiat(self, ref_el, dof, interpolant_deg): |
40 | 40 |
|
41 | 41 | def get_pts(self, ref_el, total_degree): |
42 | 42 | entity = ref_el.construct_subelement(self.entity.dim()) |
43 | | - Q_ref = create_quadrature(entity, total_deg) |
44 | | - |
45 | | - ent_id = self.entity.id - ref_el.fe_cell.get_starter_ids()[self.entity.dim()] |
46 | | - Q = FacetQuadratureRule(ref_el, self.entity.dim(), ent_id, Q_ref) |
47 | | - qpts, qwts = Q.get_points(), Q.get_weights() |
48 | | - return [(1,)], [(1,)] |
| 43 | + return [(0,) * entity.get_spatial_dimension()], [1], 1 |
49 | 44 |
|
50 | 45 | def add_entity(self, entity): |
51 | 46 | res = DeltaPairing() |
@@ -101,12 +96,15 @@ def add_entity(self, entity): |
101 | 96 |
|
102 | 97 | def get_pts(self, ref_el, total_degree): |
103 | 98 | entity = ref_el.construct_subelement(self.entity.dim()) |
104 | | - Q_ref = create_quadrature(entity, total_deg) |
| 99 | + Q_ref = create_quadrature(entity, total_degree) |
105 | 100 |
|
106 | 101 | ent_id = self.entity.id - ref_el.fe_cell.get_starter_ids()[self.entity.dim()] |
107 | 102 | Q = FacetQuadratureRule(ref_el, self.entity.dim(), ent_id, Q_ref) |
108 | | - qpts, qwts = Q.get_points(), Q.get_weights() |
109 | | - return qpts, qwts |
| 103 | + Jdet = Q.jacobian_determinant() |
| 104 | + # TODO work out how to get J from attachment |
| 105 | + |
| 106 | + qpts, qwts = Q_ref.get_points(), Q_ref.get_weights() |
| 107 | + return qpts, qwts, Jdet |
110 | 108 |
|
111 | 109 | def convert_to_fiat(self, ref_el, dof, interpolant_degree): |
112 | 110 | total_deg = interpolant_degree + dof.kernel.degree() |
@@ -168,8 +166,11 @@ def permute(self, g): |
168 | 166 | def __call__(self, *args): |
169 | 167 | return self.pt |
170 | 168 |
|
171 | | - def tabulate(self, Qpts): |
172 | | - return np.array([self.pt for _ in Qpts]).astype(np.float64) |
| 169 | + def tabulate(self, Qpts, attachment=None): |
| 170 | + if attachment is None: |
| 171 | + return np.array([self.pt for _ in Qpts]).astype(np.float64) |
| 172 | + else: |
| 173 | + return np.array([attachment(*self.pt) for _ in Qpts]).astype(np.float64) |
173 | 174 |
|
174 | 175 | def _to_dict(self): |
175 | 176 | o_dict = {"pt": self.pt} |
@@ -209,8 +210,10 @@ def __call__(self, *args): |
209 | 210 | return [res] |
210 | 211 | return res |
211 | 212 |
|
212 | | - def tabulate(self, Qpts): |
213 | | - return np.array([self(*pt) for pt in Qpts]).astype(np.float64) |
| 213 | + def tabulate(self, Qpts, attachment=None): |
| 214 | + if attachment is None: |
| 215 | + return np.array([self(*pt) for pt in Qpts]).astype(np.float64) |
| 216 | + return np.array([self(*attachment(*pt)) for pt in Qpts]).astype(np.float64) |
214 | 217 |
|
215 | 218 | def _to_dict(self): |
216 | 219 | o_dict = {"fn": self.fn} |
@@ -270,7 +273,23 @@ def add_context(self, dof_gen, cell, space, g, overall_id=None, generator_id=Non |
270 | 273 |
|
271 | 274 | def convert_to_fiat(self, ref_el, interpolant_degree): |
272 | 275 | return self.pairing.convert_to_fiat(ref_el, self, interpolant_degree) |
273 | | - raise NotImplementedError("Fiat conversion only implemented for Point eval") |
| 276 | + |
| 277 | + def convert_to_fiat_new(self, ref_el, interpolant_degree): |
| 278 | + total_degree = self.kernel.degree() + interpolant_degree |
| 279 | + pts, wts, jdet = self.pairing.get_pts(ref_el, total_degree) |
| 280 | + f_pts = self.kernel.tabulate(pts).T / jdet |
| 281 | + # TODO need to work out how i can discover the shape in a better way |
| 282 | + if isinstance(self.pairing, DeltaPairing): |
| 283 | + shp = tuple() |
| 284 | + pt_dict = {tuple(p) : [(w, tuple())] for (p, w) in zip(f_pts.T, wts)} |
| 285 | + else: |
| 286 | + shp = tuple(f_pts.shape[:-1]) |
| 287 | + weights = np.transpose(np.multiply(f_pts, wts), (-1,) + tuple(range(len(shp)))) |
| 288 | + alphas = list(np.ndindex(shp)) |
| 289 | + pt_dict = {tuple(pt): [(wt[alpha], alpha) for alpha in alphas] for pt, wt in zip(pts, weights)} |
| 290 | + |
| 291 | + return Functional(ref_el, shp, pt_dict, {}, self.__repr__()) |
| 292 | + |
274 | 293 |
|
275 | 294 | def __repr__(self, fn="v"): |
276 | 295 | return str(self.pairing).format(fn=fn, kernel=self.kernel) |
@@ -309,13 +328,25 @@ def eval(self, fn, pullback=True): |
309 | 328 | def tabulate(self, Qpts): |
310 | 329 | immersion = self.target_space.tabulate(Qpts, self.trace_entity, self.g) |
311 | 330 | res = self.kernel.tabulate(Qpts) |
312 | | - # [self.attachment(*tuple(r)) for r in res] |
313 | 331 | return immersion*res |
314 | 332 |
|
315 | | - def convert_to_fiat(self, ref_el): |
316 | | - pts, wts = self.pairing.get_pts() |
317 | | - self.target_space.convert_to_fiat(tabulated, wts) |
| 333 | + def convert_to_fiat_new(self, ref_el, interpolant_degree): |
| 334 | + total_degree = self.kernel.degree() + interpolant_degree |
| 335 | + pts, wts, jdet = self.pairing.get_pts(ref_el, total_degree) |
| 336 | + f_pts = self.kernel.tabulate(pts, self.attachment) |
| 337 | + attached_pts = [self.attachment(*p) for p in pts] |
| 338 | + immersion = self.target_space.tabulate(f_pts, self.trace_entity, self.g) |
318 | 339 |
|
| 340 | + f_pts = (f_pts * immersion).T / jdet |
| 341 | + pt_dict, deriv_dict = self.target_space.convert_to_fiat(attached_pts, f_pts, wts) |
| 342 | + |
| 343 | + # breakpoint() |
| 344 | + # TODO need to work out how i can discover the shape in a better way |
| 345 | + if isinstance(self.pairing, DeltaPairing): |
| 346 | + shp = tuple() |
| 347 | + else: |
| 348 | + shp = tuple(f_pts.shape[:-1]) |
| 349 | + return Functional(ref_el, shp, pt_dict, deriv_dict, self.__repr__()) |
319 | 350 |
|
320 | 351 | def __call__(self, g): |
321 | 352 | permuted = self.cell.permute_entities(g, self.trace_entity.dim()) |
|
0 commit comments