15 views
Skip to first unread message

Chenyi LUO

unread,
Apr 29, 2021, 11:38:11 AM4/29/21
to dea...@googlegroups.com
Dear dealii group,

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 (const unsigned int i : fe_values_u_p.dof_indices())
{
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




Bruno Turcksin

unread,
Apr 29, 2021, 12:00:07 PM4/29/21
to deal.II User Group
Chenyi,

Unless you have measured that this is a bottleneck in you code, you should use what's the more readable. If there is a difference between these two codes, it would need to be in a hot loop to matter. My advice is to write easy to understand code and once you have made sure that the code works, then use a profiler to find the bottleneck and optimize the code.

Best,

Bruno
Reply all
Reply to author
Forward
0 new messages