Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix symmetric value shape #3535

Merged
merged 18 commits into from
Nov 28, 2024
Merged

Fix symmetric value shape #3535

merged 18 commits into from
Nov 28, 2024

Conversation

michalhabera
Copy link
Contributor

@michalhabera michalhabera commented Nov 25, 2024

Resolves #3516.

This PR makes symmetric rank-2 elements have block size == dim * (dim + 1) / 2 but keeps value_shape == (dim, dim).

if (symmetric) // Consistency check for symmetric elements
{
if (!value_shape)
if (symmetric && value_shape){
Copy link
Member

Choose a reason for hiding this comment

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

Run clang-format/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. I'll still suggest to wait so I test this in more elaborate tests in dolfiny. TBH, I just fixed the apparent places and I do not see completely through if all works downstream (the code is a bit complicated).

/// @param[in] symmetric Is the element a symmetric tensor? Should ony
/// set for 2nd-order tensor blocked elements.
FiniteElement(const basix::FiniteElement<geometry_type>& element,
std::optional<std::vector<std::size_t>> value_shape
= std::nullopt,
std::vector<std::size_t> value_shape = {}, int block_size = 1,
Copy link
Member

@garth-wells garth-wells Nov 27, 2024

Choose a reason for hiding this comment

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

This was better as std::optional. It's confusing to have three inter-related arguments (element, value_shape and block_size) and the logic gets complicated. Simpler is (i) an element and (ii) optional value shape. It is also good to minimise the number of default arguments, especially for int and bool which can get mixed up. An if element is symmetric it gets even more confusing. We should avoid empty containers when we mean 'unset' rather than truly empty.

Doesn't mean that the member data for value_shape can't be a std::vector.

Copy link
Contributor Author

@michalhabera michalhabera Nov 27, 2024

Choose a reason for hiding this comment

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

The whole point of extra changes is to simplify this nontrivial code.

  1. My motivation for having block size as an extra argument is that the logic to compute it already lives in basix UFL wrapper, so it is better to avoid duplicating this nontrivial assumption, pass the one from basix instead. It does not have to have a default value.
  2. I do not see the point of using std::optional<std::vector<>>. Optional is okay for when its value might not be provided. But empty std::vector is semantically correct and nicely maps in Python to an empty list or empty array. For lists/tuples on the Python side one does not use None to indicate an empty tuple/list. So here I strongly disagree. Okay, this is a bit confusing, especially the interaction with reference_value_shape and vector/tensor valued basis.

I'll revert the changes to previous commit so the regression is fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is reverted and should be good for review @garth-wells . Thanks for the comments. I had to fix the Quadrature element constructor as well as there could be a "blocked symmetric quadrature element" and none of dolfinx tests capture this.

@garth-wells garth-wells added bug Something isn't working enhancement New feature or request labels Nov 28, 2024
@garth-wells garth-wells added this pull request to the merge queue Nov 28, 2024
Merged via the queue into main with commit a2243ff Nov 28, 2024
33 checks passed
@garth-wells garth-wells deleted the michal/symmetry-value-shape branch November 28, 2024 08:48
schnellerhase pushed a commit to schnellerhase/fenics-dolfinx that referenced this pull request Dec 28, 2024
* Try with basix default value shape

* Try block size from symmetric value shape

* Fix block size logic

* Point to basix branch

* Fix oneAPI branch

* Use basix branch in more workflows

* Use basix branch in more workflows

* Apply clang-format

* Unify bs logic, fix for quadrature elements

* Simplify value_shape

* Revert "Simplify value_shape"

This reverts commit f09414a.

* Remove brew unlink

* Move some code to the initialiser list

* Revert CI to Basix main

---------

Co-authored-by: Garth N. Wells <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG]: Interpolation into symmetric rank-2 tensors broken
2 participants