Skip to content

Allow passing a maximum degree quadrature to a measure#4989

Merged
JHopeCollins merged 5 commits intomainfrom
JHopeCollins/tsfc-max-quadrature_degree
Apr 13, 2026
Merged

Allow passing a maximum degree quadrature to a measure#4989
JHopeCollins merged 5 commits intomainfrom
JHopeCollins/tsfc-max-quadrature_degree

Conversation

@JHopeCollins
Copy link
Copy Markdown
Member

@JHopeCollins JHopeCollins commented Mar 25, 2026

If you have a complicated or non-polynomial expression in a form then UFL may (rightly or wrongly) estimate a very high quadrature degree, then TSFC spits out the dreaded message:

tsfc: WARNING Estimated quadrature degree more than tenfold greater than any argument/coefficient

You can avoid this by telling TSFC exactly what quadrature degree to use with:
inner(expr, v)*dx(degree=fixed_degree).

However, this hardcodes the degree and if you change something in expr it will still use fixed_degree even if now UFL may estimate something lower.

This PR allows passing a maximum quadrature degree that will only be used if UFL estimates a higher degree. If UFL estimates a lower degree then that will be used. This max degree is passed via the measure metadata:

inner(expr, v)*dx(metadata={'max_quadrature_degree': max_degree})

By default nothing will be printed to screen if the maximum degree is chosen, but if you change the logging level to INFO then you can see when it happens.

Copy link
Copy Markdown
Contributor

@pbrubeck pbrubeck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also explain this in the manual

@JHopeCollins
Copy link
Copy Markdown
Member Author

JHopeCollins commented Mar 25, 2026

Just to make sure I don't mislead anyone:

If you passed form_compiler_parameters={"max_quadrature_degree": degree} to a solver, would it appear in the parameters here? Would it get overridden if you had passed a different one to the measure of a particular term?

@connorjward
Copy link
Copy Markdown
Contributor

Just to make sure I don't mislead anyone:

If you passed form_compiler_parameters={"max_quadrature_degree": degree} to a solver, would it appear in the parameters here? Would it get overridden if you had passed a different one to the measure of a particular term?

I don't know. The easiest thing to do is try and see what happens.

@pbrubeck
Copy link
Copy Markdown
Contributor

If you passed form_compiler_parameters={"max_quadrature_degree": degree} to a solver, would it appear in the parameters here? Would it get overridden if you had passed a different one to the measure of a particular term?

Are you asking about the design we want? Basically we want the analogues to dx(degree=q) and form_compiler_parameters["quadrature_degree"] . The metadata in the Measure should override anything passed on in form_compiler_parameters.

@JHopeCollins
Copy link
Copy Markdown
Member Author

Are you asking about the design we want?

No, I was checking what will actually happen so I make sure I don't write the wrong thing in the manual!

The metadata in the Measure should override anything passed on in form_compiler_parameters.

Ok great, this is the main thing I wanted to check (and actually use myself).

@JHopeCollins JHopeCollins requested a review from pbrubeck April 13, 2026 09:48
@JHopeCollins
Copy link
Copy Markdown
Member Author

We should also explain this in the manual

@pbrubeck I've added a paragraph to the manual page on quadrature rules.

@pbrubeck
Copy link
Copy Markdown
Contributor

pbrubeck commented Apr 13, 2026

We need a test, it could be something like

mesh = UnitIntervalMesh(1)
x, = SpatialCoordinate(mesh)
form = (x**4)*dx
assert np.isclose(assemble(form, fcp={"max_quadrature_degree": 2}), assemble(form, fcp={"quadrature_degree": 2}))
assert np.isclose(assemble(form, fcp={"max_quadrature_degree": 5}), assemble(form))

and similar tests for dx(metadata={"max_quadraute_degree": q})

@JHopeCollins JHopeCollins requested a review from pbrubeck April 13, 2026 13:57
Copy link
Copy Markdown
Contributor

@pbrubeck pbrubeck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, thanks. It makes much more sense to emphasize max_quadrature_degree as early as possible in the manual.

@JHopeCollins JHopeCollins enabled auto-merge (squash) April 13, 2026 14:49
@JHopeCollins JHopeCollins merged commit 437473a into main Apr 13, 2026
8 checks passed
@JHopeCollins JHopeCollins deleted the JHopeCollins/tsfc-max-quadrature_degree branch April 13, 2026 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants