# Path: FIAT/quadrature_element.py
# class QuadratureElement(FiniteElement):
#     """A set of quadrature points pretending to be a finite element."""
# 
#     def __init__(self, ref_el, points, weights=None):
#         # Create entity dofs.
#         entity_dofs = {dim: {entity: [] for entity in entities}
#                        for dim, entities in ref_el.get_topology().items()}
#         entity_dofs[ref_el.get_dimension()] = {0: list(range(len(points)))}
# 
#         # The dual nodes are PointEvaluations at the quadrature points.
#         # FIXME: KBO: Check if this gives expected results for code like evaluate_dof.
#         nodes = [PointEvaluation(ref_el, tuple(point)) for point in points]
# 
#         # Construct the dual set
#         dual = DualSet(nodes, ref_el, entity_dofs)
# 
#         super(QuadratureElement, self).__init__(ref_el, dual, order=None)
#         self._points = points  # save the quadrature points & weights
#         self._weights = weights
# 
#     def value_shape(self):
#         "The QuadratureElement is scalar valued"
#         return ()
# 
#     def tabulate(self, order, points, entity=None):
#         """Return the identity matrix of size (num_quad_points, num_quad_points),
#         in a format that monomialintegration and monomialtabulation understands."""
# 
#         if entity is not None and entity != (self.ref_el.get_dimension(), 0):
#             raise ValueError('QuadratureElement does not "tabulate" on subentities.')
# 
#         # Derivatives are not defined on a QuadratureElement
#         if order:
#             raise ValueError("Derivatives are not defined on a QuadratureElement.")
# 
#         # Check that incoming points are equal to the quadrature points.
#         if len(points) != len(self._points) or abs(numpy.array(points) - self._points).max() > 1e-12:
#             raise AssertionError("Mismatch of quadrature points!")
# 
#         # Return the identity matrix of size len(self._points).
#         values = numpy.eye(len(self._points))
#         dim = self.ref_el.get_spatial_dimension()
#         return {(0,) * dim: values}
# 
#     @staticmethod
#     def is_nodal():
#         # No polynomial basis, but still nodal.
#         return True
# 
# Path: FIAT/quadrature.py
# def make_quadrature(ref_el, m):
#     """Returns the collapsed quadrature rule using m points per
#     direction on the given reference element. In the tensor product
#     case, m is a tuple."""
# 
#     if isinstance(m, tuple):
#         min_m = min(m)
#     else:
#         min_m = m
# 
#     msg = "Expecting at least one (not %d) quadrature point per direction" % min_m
#     assert (min_m > 0), msg
# 
#     if ref_el.get_shape() == reference_element.POINT:
#         return QuadratureRule(ref_el, [()], [1])
#     elif ref_el.get_shape() == reference_element.LINE:
#         return GaussJacobiQuadratureLineRule(ref_el, m)
#     elif ref_el.get_shape() == reference_element.TRIANGLE:
#         return CollapsedQuadratureTriangleRule(ref_el, m)
#     elif ref_el.get_shape() == reference_element.TETRAHEDRON:
#         return CollapsedQuadratureTetrahedronRule(ref_el, m)
#     elif ref_el.get_shape() == reference_element.QUADRILATERAL:
#         line_rule = GaussJacobiQuadratureLineRule(ref_el.construct_subelement(1), m)
#         return make_tensor_product_quadrature(line_rule, line_rule)
#     elif ref_el.get_shape() == reference_element.HEXAHEDRON:
#         line_rule = GaussJacobiQuadratureLineRule(ref_el.construct_subelement(1), m)
#         return make_tensor_product_quadrature(line_rule, line_rule, line_rule)
#     else:
#         raise ValueError("Unable to make quadrature for cell: %s" % ref_el)
# 
# Path: FIAT/reference_element.py
# def ufc_simplex(spatial_dim):
#     """Factory function that maps spatial dimension to an instance of
#     the UFC reference simplex of that dimension."""
#     if spatial_dim == 0:
#         return Point()
#     elif spatial_dim == 1:
#         return UFCInterval()
#     elif spatial_dim == 2:
#         return UFCTriangle()
#     elif spatial_dim == 3:
#         return UFCTetrahedron()
#     else:
#         raise RuntimeError("Can't create UFC simplex of dimension %s." % str(spatial_dim))


import pytest
import numpy as np
    import os
from FIAT import QuadratureElement, make_quadrature, ufc_simplex

@pytest.fixture(params=[1, 2, 3])
def cell(request):
    return ufc_simplex(request.param)


@pytest.fixture
def quadrature(cell):
    return make_quadrature(cell, 2)


@pytest.fixture
def element(cell, quadrature):
    return QuadratureElement(cell, quadrature.get_points())


def test_order(element, quadrature):
    with pytest.raises(ValueError):
        element.tabulate(1, quadrature.get_points())


def test_points(element, quadrature):
    points = quadrature.get_points()
    wrong_points = np.linspace(0.0, 1.0, points.size).reshape(points.shape)
    with pytest.raises(AssertionError):
        element.tabulate(0, wrong_points)


def test_entity(element, quadrature):
    dim = element.get_reference_element().get_spatial_dimension()

# Path: FIAT/quadrature_element.py
# class QuadratureElement(FiniteElement):
#     """A set of quadrature points pretending to be a finite element."""
# 
#     def __init__(self, ref_el, points, weights=None):
#         # Create entity dofs.
#         entity_dofs = {dim: {entity: [] for entity in entities}
#                        for dim, entities in ref_el.get_topology().items()}
#         entity_dofs[ref_el.get_dimension()] = {0: list(range(len(points)))}
# 
#         # The dual nodes are PointEvaluations at the quadrature points.
#         # FIXME: KBO: Check if this gives expected results for code like evaluate_dof.
#         nodes = [PointEvaluation(ref_el, tuple(point)) for point in points]
# 
#         # Construct the dual set
#         dual = DualSet(nodes, ref_el, entity_dofs)
# 
#         super(QuadratureElement, self).__init__(ref_el, dual, order=None)
#         self._points = points  # save the quadrature points & weights
#         self._weights = weights
# 
#     def value_shape(self):
#         "The QuadratureElement is scalar valued"
#         return ()
# 
#     def tabulate(self, order, points, entity=None):
#         """Return the identity matrix of size (num_quad_points, num_quad_points),
#         in a format that monomialintegration and monomialtabulation understands."""
# 
#         if entity is not None and entity != (self.ref_el.get_dimension(), 0):
#             raise ValueError('QuadratureElement does not "tabulate" on subentities.')
# 
#         # Derivatives are not defined on a QuadratureElement
#         if order:
#             raise ValueError("Derivatives are not defined on a QuadratureElement.")
# 
#         # Check that incoming points are equal to the quadrature points.
#         if len(points) != len(self._points) or abs(numpy.array(points) - self._points).max() > 1e-12:
#             raise AssertionError("Mismatch of quadrature points!")
# 
#         # Return the identity matrix of size len(self._points).
#         values = numpy.eye(len(self._points))
#         dim = self.ref_el.get_spatial_dimension()
#         return {(0,) * dim: values}
# 
#     @staticmethod
#     def is_nodal():
#         # No polynomial basis, but still nodal.
#         return True
# 
# Path: FIAT/quadrature.py
# def make_quadrature(ref_el, m):
#     """Returns the collapsed quadrature rule using m points per
#     direction on the given reference element. In the tensor product
#     case, m is a tuple."""
# 
#     if isinstance(m, tuple):
#         min_m = min(m)
#     else:
#         min_m = m
# 
#     msg = "Expecting at least one (not %d) quadrature point per direction" % min_m
#     assert (min_m > 0), msg
# 
#     if ref_el.get_shape() == reference_element.POINT:
#         return QuadratureRule(ref_el, [()], [1])
#     elif ref_el.get_shape() == reference_element.LINE:
#         return GaussJacobiQuadratureLineRule(ref_el, m)
#     elif ref_el.get_shape() == reference_element.TRIANGLE:
#         return CollapsedQuadratureTriangleRule(ref_el, m)
#     elif ref_el.get_shape() == reference_element.TETRAHEDRON:
#         return CollapsedQuadratureTetrahedronRule(ref_el, m)
#     elif ref_el.get_shape() == reference_element.QUADRILATERAL:
#         line_rule = GaussJacobiQuadratureLineRule(ref_el.construct_subelement(1), m)
#         return make_tensor_product_quadrature(line_rule, line_rule)
#     elif ref_el.get_shape() == reference_element.HEXAHEDRON:
#         line_rule = GaussJacobiQuadratureLineRule(ref_el.construct_subelement(1), m)
#         return make_tensor_product_quadrature(line_rule, line_rule, line_rule)
#     else:
#         raise ValueError("Unable to make quadrature for cell: %s" % ref_el)
# 
# Path: FIAT/reference_element.py
# def ufc_simplex(spatial_dim):
#     """Factory function that maps spatial dimension to an instance of
#     the UFC reference simplex of that dimension."""
#     if spatial_dim == 0:
#         return Point()
#     elif spatial_dim == 1:
#         return UFCInterval()
#     elif spatial_dim == 2:
#         return UFCTriangle()
#     elif spatial_dim == 3:
#         return UFCTetrahedron()
#     else:
#         raise RuntimeError("Can't create UFC simplex of dimension %s." % str(spatial_dim))


# Path: test/unit/test_quadrature_element.py
import pytest
import numpy as np
    import os
from FIAT import QuadratureElement, make_quadrature, ufc_simplex


@pytest.fixture(params=[1, 2, 3])
def cell(request):
    return ufc_simplex(request.param)


@pytest.fixture
def quadrature(cell):
    return make_quadrature(cell, 2)


@pytest.fixture
def element(cell, quadrature):
    return QuadratureElement(cell, quadrature.get_points())


def test_order(element, quadrature):
    with pytest.raises(ValueError):
        element.tabulate(1, quadrature.get_points())


def test_points(element, quadrature):
    points = quadrature.get_points()
    wrong_points = np.linspace(0.0, 1.0, points.size).reshape(points.shape)
    with pytest.raises(AssertionError):
        element.tabulate(0, wrong_points)


def test_entity(element, quadrature):
    dim = element.get_reference_element().get_spatial_dimension()

    points = make_quadrature(ufc_simplex(dim - 1), 2).get_points()