Extra functionality of Tensor class #631

Merged
merged 1 commit into from Mar 2, 2015

2 participants

@davydden
Member
davydden commented Mar 2, 2015

the two commits are currently part of https://github.com/dealii/dealii/pull/621/commits
Wolfang wanted at least one of them to be in separate PR, thus I create it.

@bangerth bangerth commented on an outdated diff Mar 2, 2015
include/deal.II/base/tensor.h
inline
Number contract (const Tensor<1,dim,Number> &src1,
- const Tensor<1,dim,Number> &src2)
+ const Tensor<1,dim,OtherNumber> &src2)
@bangerth
bangerth Mar 2, 2015 Member

The return type of this should now be typename ProductType<Number,OtherNumber>::type. Same in the operator*.

@bangerth bangerth and 1 other commented on an outdated diff Mar 2, 2015
include/deal.II/base/symmetric_tensor.h
@@ -628,6 +628,13 @@ class SymmetricTensor
SymmetricTensor operator - () const;
/**
+ * Simple addition of a multiple of a tensor, i.e. *this += a*T,
+ * where the scalar is of the same base type and
+ * T is a symmetric tensor of double.
+ */
+ void add(const Number &a, const SymmetricTensor<rank,dim,double> &p);
@bangerth
bangerth Mar 2, 2015 Member

Why only add SymmetricTensor<rank,dim,double> and not SymmetricTensor<rank,dim,Number>?

@davydden
davydden Mar 2, 2015 Member

that was used to add to the resulting tensor a number multiplied by the tensor object coming from the shape functions, thus double only

@bangerth
Member
bangerth commented Mar 2, 2015

I don't recall the conversation about this. Where do you need the add functions?

@davydden
Member
davydden commented Mar 2, 2015

There was no conversation about the add function, but I use it heavily in the PR cited above, see davydden@2e30cc3

@davydden
Member
davydden commented Mar 2, 2015

I think add() shall be quicker than something like

derivatives[q_point] += value *
typename ProductType<Number,dealii::Tensor<order,spacedim> >::type(*shape_derivative_ptr++);

as it shall not require a temporary object.

@bangerth
Member
bangerth commented Mar 2, 2015

This is for small objects with a handful of elements. The compiler will optimize all of this out -- let's not worry about these micro-optimizations unless we have evidence that they are necessary.

So I would vote to just leave the existing code of the form

derivatives[q_point] += value *
typename ProductType<Number,dealii::Tensor<order,spacedim> >::type(*shape_derivative_ptr++);

in place. There is a cost to adding member functions (as this discussion shows) and it doesn't seem worth it at this point.

@davydden
Member
davydden commented Mar 2, 2015

ok

@davydden
Member
davydden commented Mar 2, 2015

will check that it compiles...

@davydden
Member
davydden commented Mar 2, 2015

builds fine.

@bangerth
Member
bangerth commented Mar 2, 2015

Looks good.

@bangerth bangerth merged commit e71080c into dealii:master Mar 2, 2015

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@davydden
Member

in reference to #2033

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment