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

Use an array-of-scalars as the base case for Tensor. #16480

Merged
merged 4 commits into from Jan 18, 2024

Conversation

bangerth
Copy link
Member

In #16474, I replaced the data structure to store the elements of a tensor from a C-style array to a std::array. But for rank-1 tensors, this is still an array of Tensor<0,dim>. This patch breaks the recursion one level higher: Rather than going to to std::array<Tensor<0,dim>,dim>, we now use std::array<Number,dim>.

The marginally non-trivial part is that we now have to initialize this array where before the default constructor of Tensor<0,dim> did that. This is awkward because std::array by default does not initialize its elements if they are built-in types. The first commit lets std::array not initialize its elements, and then uses std::fill to initialize the elements.

The second commit avoids this two-step process by direct initialization of the elements using a brace-enclosed initializer list. This took me a little bit to come up, and I will admit that the solution is perhaps not easy to understand at first read. But it is localized, and I tried to document it well enough. It uses some fun features of C++ :-)

Related to #16465.

@bangerth
Copy link
Member Author

The third commit also adjusts value_type and array_type accordingly.

Following commits work around compiler warnings :-(

@bangerth bangerth force-pushed the tensor-scalar-array branch 3 times, most recently from fd3c9ec to a85a7a4 Compare January 16, 2024 23:31
Copy link
Member

@kronbichler kronbichler left a comment

Choose a reason for hiding this comment

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

Thank you @bangerth for the explanations; I am fine with this version (albeit I would probably been too lazy myself to go away from fill).

@kronbichler
Copy link
Member

Would you mind squashing together some of the commits that do not work on their own. (I realize it might not be worth to restructure the commits cleanly, so feel free to ignore this request.)

@bangerth
Copy link
Member Author

I made the commits more self-contained and complete.

@tamiko tamiko merged commit 20d2176 into dealii:master Jan 18, 2024
15 checks passed
@bangerth bangerth deleted the tensor-scalar-array branch January 18, 2024 23:19
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.

None yet

3 participants