I am working on a FEM code in which I need to obtain the force vector on each node of a triangular linear element from the stress tensor in 2D. I have the shape functions, and the stress is constant over the element.
From reading the literature, I understand that the nodal force should be the derivative of the shape functions multiplied by the stress tensor, integrated over the element area:
$$f_i = \int_{S_i} \frac{\partial N}{\partial X} \cdot \sigma dS_i$$
Where N is the vector of shape functions, $\sigma$ is the stress tensor and $S_i$ is the membrane surface area Expanding and solving for this for nodes $0-2$, I obtain:
$$f_i = (f_{x,i}, f_{y,i})=\int_{S_i} \begin{pmatrix} a_0 & b_0 \\ a_1 & b_1 \\ a_2 & b_2 \\ \end{pmatrix} \cdot \begin{pmatrix} \sigma_{xx} & \sigma_{xy} \\ \sigma_{yx} & \sigma_{yy} \\ \end{pmatrix} dS_i = \begin{pmatrix} a_0\sigma_{xx} + b_0\sigma_{yx}, & a_0\sigma_{xy} + b_0\sigma_{yy} \\ a_1\sigma_{xx} + b_1\sigma_{yx}, & a_1\sigma_{xy} + b_1\sigma_{yy} \\ a_2\sigma_{xx} + b_2\sigma_{yx}, & a_2\sigma_{xy} + b_2\sigma_{yy} \end{pmatrix} \cdot S_i$$
I am getting strange bugs in my code which I think stem from these equations, but I can't find anything wrong with my derivation. Can anyone point out any mistakes I may have made?
Thanks