Skip to content

Add default scalar type cast - #3833

Merged
schnellerhase merged 6 commits into
mainfrom
schnellerhase/fix-ufl
Jul 30, 2025
Merged

Add default scalar type cast#3833
schnellerhase merged 6 commits into
mainfrom
schnellerhase/fix-ufl

Conversation

@schnellerhase

Copy link
Copy Markdown
Contributor

Fixes FEniCS/ufl#399.

Caused by default scalar type being complex in the ufl dolfinx integration test. In this case form, function and coefficients are constructed from default type (complex), but the boundary condition from a float value. This caused a mismatch.

Tested at https://github.com/FEniCS/ufl/actions/runs/16607427384/job/46982707793

@schnellerhase
schnellerhase marked this pull request as ready for review July 30, 2025 07:25
@garth-wells

Copy link
Copy Markdown
Member

Maybe fem.dirichletbc should be handling the cast. It's pretty natural to cast a float to complex.

@schnellerhase

Copy link
Copy Markdown
Contributor Author

So, changing from extracting the dtype from the value passed to dirichletbc, to instead extracting it from the function space (on which we want to apply it) and casting the value (array) to its dtype?

@jorgensd

Copy link
Copy Markdown
Member

So, changing from extracting the dtype from the value passed to dirichletbc, to instead extracting it from the function space (on which we want to apply it) and casting the value (array) to its dtype?

The function space doesn’t know the dtype? It is only the function we are applying it to that knows the dtype.

@schnellerhase

Copy link
Copy Markdown
Contributor Author

Ah right, function space only knows the geometry dtype. Then I don't know what to change it to.

@jorgensd

Copy link
Copy Markdown
Member

I guess this goes back to Constant not having a default dtype. I raised this a long time ago, and here is the discussion: #1997

@garth-wells

Copy link
Copy Markdown
Member

Ah right, function space only knows the geometry dtype. Then I don't know what to change it to.

I'd suggest (i) moving bc closer to where it's used, and (ii) getting the dtype from the Form it acts on. default_scalar_type is something a bit ugly we need to live with but should use as little as possible.

@schnellerhase

Copy link
Copy Markdown
Contributor Author

@jorgensd

Copy link
Copy Markdown
Member

Ah right, function space only knows the geometry dtype. Then I don't know what to change it to.

I'd suggest (i) moving bc closer to where it's used, and (ii) getting the dtype from the Form it acts on. default_scalar_type is something a bit ugly we need to live with but should use as little as possible.

That has to be slightly adapted to work with bc.set:

@schnellerhase
schnellerhase added this pull request to the merge queue Jul 30, 2025
Merged via the queue into main with commit 34996c0 Jul 30, 2025
30 checks passed
@schnellerhase
schnellerhase deleted the schnellerhase/fix-ufl branch July 30, 2025 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dolfinx integration fails

3 participants