1
$\begingroup$

I have solved the 2D Poisson equation using finite element method with simplex triangular element in MATLAB.

First, I generated the triangular mesh using pdetool in Matlab and it gives me three matrices: p (position of each node), t (element with three vertices) and e. Then, I derived the local stiffness matrix like this,

for I=1:i_elems
 
  conec(i_elem,1)=t(1,i_elem);
  conec(i_elem,2)=t(2,i_elem);
  conec(i_elem,3)=t(3,i_elem);
    
  node_1=conec(i_elem,1);
  node_2=conec(i_elem,2);
  node_3=conec(i_elem,3);

    NN_e(1,1)=(1/6) * elem_area(i_elem);
    NN_e(1,2)=(1/12)* elem_area(i_elem);
    NN_e(1,3)=(1/12)* elem_area(i_elem);
    NN_e(2,1)=(1/12)* elem_area(i_elem);
    NN_e(2,2)=(1/6) * elem_area(i_elem);
    NN_e(2,3)=(1/12)* elem_area(i_elem);
    NN_e(3,1)=(1/12)* elem_area(i_elem);
    NN_e(3,2)=(1/12)* elem_area(i_elem);
    NN_e(3,3)=(1/6) * elem_area(i_elem);

% and then I assembled that like this,

    NN(node_1,node_1)=NN(node_1,node_1)+NN_e(1,1);
    NN(node_1,node_2)=NN(node_1,node_2)+NN_e(1,2);
    NN(node_1,node_3)=NN(node_1,node_3)+NN_e(1,3);
    NN(node_2,node_1)=NN(node_2,node_1)+NN_e(2,1);
    NN(node_2,node_2)=NN(node_2,node_2)+NN_e(2,2);
    NN(node_2,node_3)=NN(node_2,node_3)+NN_e(2,3);
    NN(node_3,node_1)=NN(node_3,node_1)+NN_e(3,1);
    NN(node_3,node_2)=NN(node_3,node_2)+NN_e(3,2);
    NN(node_3,node_3)=NN(node_3,node_3)+NN_e(3,3);

end

NN matrix will be a sparse matrix. I just want to use the c.s.r technique and make the assembling process more efficient but I don't know how to assemble the global stiffness matrix in this way. I would be grateful if someone could help me.

$\endgroup$
4
  • 1
    $\begingroup$ What have you tried already? There is a large amount of material on CSR matrices online. Have you looked at libraries that implement it? $\endgroup$ Feb 27, 2021 at 0:25
  • $\begingroup$ Many thanks for your reply. Actually I already know about c.s.r matrix,but the thing is I can not assemble the local stifness matrix by this way into global form. Before assembling I don't know the position of zero arrays and the exact number of them in each row. Mathematically I know every two node that have no connection together make a zero array in global stiffness matrix. I would be more grateful if you could help me with more detail. $\endgroup$
    – Resa
    Feb 27, 2021 at 13:04
  • 2
    $\begingroup$ The usual approach is a two-pass algorithm: You first go through your finite element mesh once and store the positions of those entries you will have to write to. From this, you then allocate memory for a CRS matrix. Then you go through the mesh again and actually do the assembly. $\endgroup$ Feb 27, 2021 at 20:50
  • $\begingroup$ Many thanks for your answer. I appreciate that $\endgroup$
    – Resa
    Feb 27, 2021 at 23:38

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.