Skip to content

Allow passing a maximum degree quadrature to a measure#4989

Open
JHopeCollins wants to merge 1 commit intomainfrom
JHopeCollins/tsfc-max-quadrature_degree
Open

Allow passing a maximum degree quadrature to a measure#4989
JHopeCollins wants to merge 1 commit 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).

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