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

Simplify creating and unrolling symmetric tensors #5640

Merged

Conversation

gassmoeller
Copy link
Member

Something I noticed while reviewing #4370. We have quite a number of places in the code where we create Tensors from arrays or vectors, or unroll Tensors into arrays or vectors. We could simplify this using Tensor constructors, and appropriate unroll functions. Such functions are already provided by deal.II for the Tensor class, but they dont exist for SymmetricTensor. I here created small utility functions for SymmetricTensor, but of course it would be nice to use a version inside deal.II. Would that be of interest?

I can extend this PR to simplify a lot of places in ASPECT with the utility functions, but I first wanted to ask for feedback if the current interface is correct and if this is useful overall.

@tjhei
Copy link
Member

tjhei commented May 28, 2024

I think it is great to simplify and clean up the code based like this.
I already mentioned in the other PR that I don't like the two-step creation of an ArrayView. We could use an iterator version or not? You can also make a simplified version that only takes a begin iterator. Do you want me to try that out?

Copy link
Contributor

@bangerth bangerth left a comment

Choose a reason for hiding this comment

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

Yes, this is good. In an ideal world, the two new functions would live inside dealii::SymmetricTensor. I would gladly accept a patch.

Comment on lines 1272 to 1275
for (unsigned int i=0; i < SymmetricTensor<2,dim>::n_independent_components; ++i)
values[i] = tensor[SymmetricTensor<2,dim>::unrolled_to_component_indices(i)];
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add

  Assert (values.size() == ...n_indep_comp, ...)

?

Same for the other function.

@gassmoeller gassmoeller force-pushed the add_unroll_function_symmetric_tensor branch 5 times, most recently from 5ada0f2 to b3b9c59 Compare May 29, 2024 21:58
@gassmoeller
Copy link
Member Author

Ok, I think I addressed all comments. The new versions have more expressive names and use iterators instead of an ArrayView, which makes them more flexible to use with different data containers. Feel free to take a look and when this is merged I can prepare a similar path for deal.II.

@gassmoeller gassmoeller force-pushed the add_unroll_function_symmetric_tensor branch from b3b9c59 to 5999d1c Compare May 29, 2024 22:26
@gassmoeller gassmoeller merged commit 65c0292 into geodynamics:main May 30, 2024
7 of 8 checks passed
@gassmoeller gassmoeller deleted the add_unroll_function_symmetric_tensor branch May 30, 2024 01:30
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