Go to the documentation of this file.00001 #ifndef OPENTISSUE_DYNAMICS_FEM_FEM_DYNAMICS_ASSEMBLY_H
00002 #define OPENTISSUE_DYNAMICS_FEM_FEM_DYNAMICS_ASSEMBLY_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 namespace OpenTissue
00013 {
00014 namespace fem
00015 {
00016 namespace detail
00017 {
00047 template < typename fem_mesh, typename real_type >
00048 inline void dynamics_assembly(
00049 fem_mesh & mesh,
00050 real_type const & mass_damping,
00051 real_type const & dt
00052 )
00053 {
00054 typedef typename fem_mesh::vector3_type vector3_type;
00055 typedef typename fem_mesh::matrix3x3_type matrix3x3_type;
00056 typedef typename fem_mesh::node_iterator node_iterator;
00057 typedef typename fem_mesh::node_type::matrix_iterator matrix_iterator;
00058
00059 node_iterator begin = mesh.node_begin();
00060 node_iterator end = mesh.node_end();
00061 for (node_iterator n_i = begin ; n_i != end; ++n_i)
00062 {
00063 unsigned int i = n_i->idx();
00064 vector3_type & b_i = n_i->m_b;
00065 real_type & m_i = n_i->m_mass;
00066
00067 b_i.clear();
00068
00069 matrix_iterator Kbegin = n_i->Kbegin();
00070 matrix_iterator Kend = n_i->Kend();
00071 for (matrix_iterator K = Kbegin; K != Kend;++K)
00072 {
00073 unsigned int j = K->first;
00074 matrix3x3_type & K_ij = K->second;
00075 node_iterator n_j = mesh.node(j);
00076 vector3_type & x_j = n_j->m_coord;
00077 matrix3x3_type & A_ij = n_i->A(j);
00078
00079 A_ij = K_ij * (dt*dt);
00080 b_i -= K_ij * x_j;
00081 if (i == j)
00082 {
00083 real_type c_i = mass_damping*m_i;
00084 real_type tmp = m_i + dt*c_i;
00085 A_ij(0,0) += tmp; A_ij(1,1) += tmp; A_ij(2,2) += tmp;
00086 }
00087 }
00088 b_i -= n_i->m_f0;
00089 b_i += n_i->m_f_external;
00090 b_i *= dt;
00091 b_i += n_i->m_velocity * m_i;
00092 }
00093 }
00094
00095 }
00096 }
00097 }
00098
00099
00100 #endif