Problems with assembling global stiffness matrix

80 Views Asked by At

Can someone plese help me to find error in my code. Although the code compiles without any issues, the output is incorrect. So, firstly I calculated stiffnes matrices (Ke) for each element using for loop. Now I need to assemble it to global stiffnes matrix, but as the output it gives me zeros and only few values are nonzero. Nodes in "elements_surface_1" are represented as 621x3 array [[252 142 371], [279,188,280], [142,322,371]...[399,303,405]].Perhaps the problem is related to the loop. I suspect that the code only calculates Ke for the last element after running the code, so I added a print statement after the loop to check the value of Ke. My code:

##Global stiffness matrix
nodes = np.delete(node_coords, 2, 1)
n_node=nodes.shape[0]
n_elem=elements_surface_1.shape[0]
K=np.zeros((n_node,n_node))
##For every element, compute element stiffness matrix Ke 
for i in range(n_elem):
  #for an element, which rows do I need to go read from the node_coords array?
  n1=elements_surface_1[i,0]
  n2=elements_surface_1[i,1]
  n3=elements_surface_1[i,2]
  x1=nodes[n1,0]
  y1=nodes[n1,1]
  x2=nodes[n2,0]
  y2=nodes[n2,1]
  x3=nodes[n3,0]
  y3=nodes[n3,1]
  Ae=Area(x1,y1,x2,y2,x3,y3)
  k=1
  B=B_matrix(x1,y1,x2,y2,x3,y3) #B_matrix is function
  Ke=1/(4*Ae)*k*np.dot(np.transpose(B),B)

  print(Ke)


  ## ASSEMBLY
  K[n1,n1]+=Ke[0,0]
  K[n1,n2]+=Ke[0,1]
  K[n1,n3]+=Ke[0,2]

  K[n2,n1]+=Ke[1,0]
  K[n2,n2]+=Ke[1,1]
  K[n2,n3]+=Ke[1,2]
  
  K[n3,n1]+=Ke[2,0]
  K[n3,n2]+=Ke[2,1]
  K[n3,n3]+=Ke[2,2]

solutions how to solve the problem

0

There are 0 best solutions below