| 167 | } |
| 168 | |
| 169 | ZSparseMatrix Assembler::getRigidMotionMatrix() { |
| 170 | typedef Eigen::Triplet<double> T; |
| 171 | std::vector<T> triplets; |
| 172 | size_t dim = m_mesh->getDim(); |
| 173 | |
| 174 | // Translation part. |
| 175 | for (size_t i=0; i<m_mesh->getNbrNodes(); i++) { |
| 176 | for (size_t j=0; j<dim; j++) { |
| 177 | triplets.push_back(T(j,i*dim+j, 1.0)); |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | // Compute centroid |
| 182 | VectorF c(dim); |
| 183 | c *= 0; |
| 184 | |
| 185 | // Rotation part. |
| 186 | size_t rot_degrees = 0; |
| 187 | if (dim == 2) { |
| 188 | rot_degrees = 1; |
| 189 | for (size_t i=0; i<m_mesh->getNbrNodes(); i++) { |
| 190 | VectorF x = m_mesh->getNode(i); |
| 191 | triplets.push_back(T(dim , i*dim , -x[1]+c[1])); |
| 192 | triplets.push_back(T(dim , i*dim+1, x[0]-c[0])); |
| 193 | } |
| 194 | } else { |
| 195 | rot_degrees = 3; |
| 196 | for (size_t i=0; i<m_mesh->getNbrNodes(); i++) { |
| 197 | VectorF x = m_mesh->getNode(i); |
| 198 | triplets.push_back(T(dim , i*dim+1, -x[2]+c[2])); |
| 199 | triplets.push_back(T(dim , i*dim+2, x[1]-c[1])); |
| 200 | triplets.push_back(T(dim+1, i*dim , x[2]-c[2])); |
| 201 | triplets.push_back(T(dim+1, i*dim+2, -x[0]+c[0])); |
| 202 | triplets.push_back(T(dim+2, i*dim , -x[1]+c[1])); |
| 203 | triplets.push_back(T(dim+2, i*dim+1, x[0]-c[0])); |
| 204 | } |
| 205 | } |
| 206 | |
| 207 | Eigen::SparseMatrix<double> Ru = Eigen::SparseMatrix<double>(dim + rot_degrees, dim * m_mesh->getNbrNodes()); |
| 208 | Ru.setFromTriplets(triplets.begin(), triplets.end()); |
| 209 | return ZSparseMatrix(Ru); |
| 210 | } |
nothing calls this directly
no test coverage detected