I have a question regarding the computational efficiency of two styles of codes. For example, when computing the residual of momentum balance, one can realize d_epsilon \cdot sigma (the dot production between the test function of strain and stress) by
1. compute multiplications one by one and sum them up
for (unsigned int m=0; m<dim; ++m)
{
for (unsigned int n=0; n<dim; ++n)
{
cell_rhs(i) += fe_values_u_p.shape_grad_component(i,q,index_u.first_vector_component+m)[n] * stress[m][n] * fe_values_u_p.JxW(q); //solid stress
}
}
}
2. extract the tensor and compute the dot product directly
const SymmetricTensor<2,dim> bfem_i = ShapeTools::elastic_strain_shape(fe_values,i,q);
for (const unsigned int i : fe_values_u_p.dof_indices())
{
cell_rhs(i) = contract2(bfem_i, stress) * fe_values_u_p.JxW(q);
}
Do both perform the same? or I should prevent the loop style in dealii to speed up the computation?
Best,
Chenyi