Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions docs/source/quadrature.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ this estimate might be quite large, and a warning like this one will be raised:

tsfc:WARNING Estimated quadrature degree 13 more than tenfold greater than any argument/coefficient degree (max 1)

For integrals with very complicated nonlinearities, the estimated quadrature
degree might be in the hundreds or thousands, rendering the integration
prohibitively expensive, or leading to segfaults.
For integrals with very complicated or non-polynomial nonlinearities, the
estimated quadrature degree might be in the hundreds or thousands, rendering
the integration prohibitively expensive, or leading to segfaults.

Specifying the quadrature rule in the variational formulation
-------------------------------------------------------------
Expand Down Expand Up @@ -46,6 +46,17 @@ In the example above, only the integrals with unspecified quadrature degree
will be computed on a quadrature rule that exactly integrates polynomials of
the degree set in ``form_compiler_parameters``.

Rather than enforcing a specific quadrature degree, it is also possible to set
a maximum allowable degree which will only be used if UFL estimates a larger
degree. This can be set for all integrals by adding the ``"max_quadrature_degree"``
entry to the ``form_compiler_parameters``.
A maximum allowable quadrature degree can be set for a particular integral by
adding the ``"max_quadrature_degree"`` entry to the ``metadata`` of the ``Measure``:
Comment thread
pbrubeck marked this conversation as resolved.
Outdated

.. code-block:: python3

inner(sin(u)**4, v) * dx(metadata={"max_quadrature_degree": 4})

Another way to specify the quadrature rule is through the ``scheme`` keyword. This could be
either a :py:class:`~finat.quadrature.QuadratureRule`, or a string. Supported string values
are ``"default"``, ``"canonical"``, and ``"KMV"``. For more details see
Expand Down
19 changes: 14 additions & 5 deletions tsfc/kernel_interface/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,20 @@ def set_quad_rule(params, cell, integral_type, functions):
if e.family() in {"Quadrature", "Boundary Quadrature"})
if len(quad_data) == 0:
quadrature_degree = params["estimated_polynomial_degree"]
if all((asarray(quadrature_degree) > 10 * asarray(e.degree())).all() for e in elements):
logger.warning("Estimated quadrature degree %s more "
"than tenfold greater than any "
"argument/coefficient degree (max %s)",
quadrature_degree, max_degree([e.degree() for e in elements]))
if "max_quadrature_degree" in params:
max_allowed_degree = params["max_quadrature_degree"]
if quadrature_degree > max_allowed_degree:
logger.info("Estimated quadrature degree %s greater "
"than maximum allowed degree %s. "
"Using maximum degree %s instead.",
quadrature_degree, max_allowed_degree, max_allowed_degree)
quadrature_degree = max_allowed_degree
else:
if all((asarray(quadrature_degree) > 10 * asarray(e.degree())).all() for e in elements):
logger.warning("Estimated quadrature degree %s more "
"than tenfold greater than any "
"argument/coefficient degree (max %s)",
quadrature_degree, max_degree([e.degree() for e in elements]))
else:
try:
(quadrature_degree, quad_rule), = quad_data
Expand Down
Loading