Skip to content

Instantly share code, notes, and snippets.

@sherbondy
Last active December 17, 2015 02:19
Show Gist options
  • Save sherbondy/5534855 to your computer and use it in GitHub Desktop.
Save sherbondy/5534855 to your computer and use it in GitHub Desktop.
Baby's first FEM simulation
// Need to compute:
//*************************ASSIGNMENT 4 START HERE*******************
matd = Vec3DiffMatrix3x3::createFromColumnVectors(xEl[1] - xEl[0], xEl[2] - xEl[0], xEl[3] - xEl[0]);
//Compute the deformation gradient F = d*D^{-1}
matF = matd * matDInv();
//Get the second Piola Kirchoff stress from your element
//Place the value in matS
computeSecondPiolaKirchhoff(matS, matF, matParams);
//compute 1st Piola Kirchoff stress
matP = matF*matS;
//Compute nodal forces
//nodalForces[0] = 3x1 column vector of nodal forces acting on node 0
//nodalForces[1] = 3x1 column vector of nodal forces acting on node 1
//nodalForces[2] = 3x1 column vector of nodal forces acting on node 2
//nodalForces[3] = 3x1 column vector of nodal forces acting on node 3
// f[m]_n = (V0 * matP * D^-T)_nm
Vec3DiffMatrix3x3 matDinvTrans = matDInv.transposed();
Vec3DiffMatrix3x3 forceMatrix = (V0 * matP * matDinvTrans);
for (unsigned col=1; col < 4; col++){
nodalForces[col] = forceMatrix.getColumnVector(col-1);
}
nodalForces[0] = -1*(nodalForces[1] +
nodalForces[2] +
nodalForces[3]);
//************************ASSIGNMENT 4 END HERE******************************
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment