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

On Thursday, April 29, 2021 at 11:38:11 AM UTC-4 swa...@gmail.com wrote:

> 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
>
>
>
>
>

-- 
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 dealii+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/dealii/a5d9e77e-63f9-40cb-b7b0-2cfdcc3457a9n%40googlegroups.com.

Reply via email to