On 5/1/23 16:15, Corbin Foucart wrote:

Is there an developer-intended way to view a Vector<double> object with dim entries as a Tensor<1, dim> object for ease of multiplication with other Tensor<1, dim> instances such as normal vectors?
I can do something like:

// dim = 3
Vector<double> vec({4,5,6});
ArrayView<double> view(&a[0], 3);
Tensor<1, 3, double> tensor(view);

but from the documentation this seems to make a copy, and I wondered if there was a deal.ii way to "view" the Vector<double> as a Tensor object. This operation is the result of a numerical flux computation and is called many times during assembly.

Correct, this makes a copy. There really isn't a different way (in deal.II): Tensor objects own their data, they are not "views", and so they cannot avoid the copy. Of course, if you don't want to do the copy, then you can always write out the tensor operation you are interested in from the original vector elements by hand.

That said: It would greatly surprise me if the copying of elements is limiting the speed of your program. Have you benchmarked this? Are you sure that you aren't trying to optimize a part of the program that doesn't actually need to be optimized?

Best
 W.


--
------------------------------------------------------------------------
Wolfgang Bangerth          email:                 [email protected]
                           www: http://www.math.colostate.edu/~bangerth/

--
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see 
https://groups.google.com/d/forum/dealii?hl=en
--- You received this message because you are subscribed to the Google Groups "deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/dealii/15c58c6f-f28a-47f6-304a-3259af3007a0%40colostate.edu.

Reply via email to