Masoud,

Here is a part of the tutorial code for example 8 to calculate stiffness matrix of an element:
Screenshot 2021-10-15 at 12.48.39.png

And here is my equivalent code for the same purpose with a matrix-based 
viewpoint:
Screenshot 2021-10-15 at 23.12.13.png

it is based on the following formulation for a 3D elastic problem:
thumbnail_image.png
By "slow", I mean in comparison with the same code in tutorial (example 8). I measured the lines of the code, and I am sure the difference is for the mentioned part of the code. To be more accurate: the operations on matrices, as follow in the second image:
B[I].Tmmult(tmpM,D);
tmpM.mmult(BDB,B[J]);

You could probably make the code substantially faster already if you moved the declaration of the B, tmpM, and BDB matrices out of the loop over the quadrature points, and simply set them to zero inside the loop. Creating these variables requires allocating memory every time you do one iteration over the quadrature points, which is expensive.

But in the end, compare what work you are doing in your loop with what the equivalent code in step-8 is doing, and you shouldn't be surprised by your observation. step-8 only does 2 (and if i==j, then 3) tensor contractions for each index i,j,q. You are allocating and releasing memory, and doing two products between 6x3 and 3x3 matrices, plus a lot of index work. It does not surprise me that this is slow.

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/b674a16b-bcbe-7bcf-5ccb-cb659154e1f7%40colostate.edu.

Reply via email to