def _entity_support_dofs(self): esd = {} for entity_dim in self.cell.sub_entities.keys(): beta = self.get_indices() zeta = self.get_value_indices() entity_cell = self.cell.construct_subelement(entity_dim) quad = make_quadrature(entity_cell, (2*numpy.array(self.degree)).tolist()) eps = 1.e-8 # Is this a safe value? result = {} for f in self.entity_dofs()[entity_dim].keys(): # Tabulate basis functions on the facet vals, = self.basis_evaluation(0, quad.point_set, entity=(entity_dim, f)).values() # Integrate the square of the basis functions on the facet. ints = gem.IndexSum( gem.Product(gem.IndexSum(gem.Product(gem.Indexed(vals, beta + zeta), gem.Indexed(vals, beta + zeta)), zeta), quad.weight_expression), quad.point_set.indices ) evaluation, = evaluate([gem.ComponentTensor(ints, beta)]) ints = evaluation.arr.flatten() assert evaluation.fids == () result[f] = [dof for dof, i in enumerate(ints) if i > eps] esd[entity_dim] = result return esd
def _entity_support_dofs(self): esd = {} for entity_dim in self.cell.sub_entities.keys(): beta = self.get_indices() zeta = self.get_value_indices() entity_cell = self.cell.construct_subelement(entity_dim) quad = make_quadrature(entity_cell, (2 * numpy.array(self.degree)).tolist()) eps = 1.e-8 # Is this a safe value? result = {} for f in self.entity_dofs()[entity_dim].keys(): # Tabulate basis functions on the facet vals, = self.basis_evaluation(0, quad.point_set, entity=(entity_dim, f)).values() # Integrate the square of the basis functions on the facet. ints = gem.IndexSum( gem.Product( gem.IndexSum( gem.Product(gem.Indexed(vals, beta + zeta), gem.Indexed(vals, beta + zeta)), zeta), quad.weight_expression), quad.point_set.indices) evaluation, = evaluate([gem.ComponentTensor(ints, beta)]) ints = evaluation.arr.flatten() assert evaluation.fids == () result[f] = [dof for dof, i in enumerate(ints) if i > eps] esd[entity_dim] = result return esd
def fiat_equivalent(self): ps = self._rule.point_set weights = getattr(self._rule, 'weights', None) if weights is None: # we need the weights. weights, = evaluate([self._rule.weight_expression]) weights = weights.arr.flatten() self._rule.weights = weights return FIAT.QuadratureElement(self.cell, ps.points, weights)
def fiat_equivalent(self): ps = self._rule.point_set if isinstance(ps, UnknownPointSet): raise ValueError( "A quadrature element with rule with runtime points has no fiat equivalent!" ) weights = getattr(self._rule, 'weights', None) if weights is None: # we need the weights. weights, = evaluate([self._rule.weight_expression]) weights = weights.arr.flatten() self._rule.weights = weights return FIAT.QuadratureElement(self.cell, ps.points, weights)
def test_morley(): ref_cell = FIAT.ufc_simplex(2) ref_element = finat.Morley(ref_cell, 2) ref_pts = finat.point_set.PointSet(ref_cell.make_points(2, 0, 4)) phys_cell = FIAT.ufc_simplex(2) phys_cell.vertices = ((0.0, 0.1), (1.17, -0.09), (0.15, 1.84)) mapping = MyMapping(ref_cell, phys_cell) z = (0, 0) finat_vals_gem = ref_element.basis_evaluation(0, ref_pts, coordinate_mapping=mapping)[z] finat_vals = evaluate([finat_vals_gem])[0].arr phys_cell_FIAT = FIAT.Morley(phys_cell) phys_points = phys_cell.make_points(2, 0, 4) phys_vals = phys_cell_FIAT.tabulate(0, phys_points)[z] assert np.allclose(finat_vals, phys_vals.T)
def test_awnc(): ref_cell = FIAT.ufc_simplex(2) ref_el_finat = finat.ArnoldWintherNC(ref_cell, 2) ref_element = ref_el_finat._element ref_pts = ref_cell.make_points(2, 0, 3) ref_vals = ref_element.tabulate(0, ref_pts)[0, 0] phys_cell = FIAT.ufc_simplex(2) phys_cell.vertices = ((0.0, 0.0), (2.0, 0.1), (0.0, 1.0)) phys_element = ref_element.__class__(phys_cell, 2) phys_pts = phys_cell.make_points(2, 0, 3) phys_vals = phys_element.tabulate(0, phys_pts)[0, 0] # Piola map the reference elements J, b = FIAT.reference_element.make_affine_mapping(ref_cell.vertices, phys_cell.vertices) detJ = np.linalg.det(J) ref_vals_piola = np.zeros(ref_vals.shape) for i in range(ref_vals.shape[0]): for k in range(ref_vals.shape[3]): ref_vals_piola[i, :, :, k] = \ J @ ref_vals[i, :, :, k] @ J.T / detJ**2 # Zany map the results mappng = MyMapping(ref_cell, phys_cell) Mgem = ref_el_finat.basis_transformation(mappng) M = evaluate([Mgem])[0].arr ref_vals_zany = np.zeros((15, 2, 2, len(phys_pts))) for k in range(ref_vals_zany.shape[3]): for ell1 in range(2): for ell2 in range(2): ref_vals_zany[:, ell1, ell2, k] = \ M @ ref_vals_piola[:, ell1, ell2, k] assert np.allclose(ref_vals_zany[:12], phys_vals[:12])
def _flatten_concatenate(node, self): result, = evaluate([node]) return partial_indexed(Literal(result.arr), result.fids)
def tabulate(element, ps): tabulation, = element.basis_evaluation(0, ps).values() result, = evaluate([tabulation]) # Singleton point shape = (int(numpy.prod(element.index_shape)), ) + element.value_shape return result.arr.reshape(*shape)