crouzeix_raviart_cotmatrix.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include "crouzeix_raviart_cotmatrix.h"
  2. #include "unique_simplices.h"
  3. #include "all_edges.h"
  4. #include "is_edge_manifold.h"
  5. #include "cotmatrix_entries.h"
  6. template <typename DerivedV, typename DerivedF, typename LT, typename DerivedE, typename DerivedEMAP>
  7. void igl::crouzeix_raviart_cotmatrix(
  8. const Eigen::MatrixBase<DerivedV> & V,
  9. const Eigen::MatrixBase<DerivedF> & F,
  10. Eigen::SparseMatrix<LT> & L,
  11. Eigen::PlainObjectBase<DerivedE> & E,
  12. Eigen::PlainObjectBase<DerivedEMAP> & EMAP)
  13. {
  14. // All occurances of directed edges
  15. Eigen::MatrixXi allE;
  16. all_edges(F,allE);
  17. Eigen::VectorXi _1;
  18. unique_simplices(allE,E,_1,EMAP);
  19. return crouzeix_raviart_cotmatrix(V,F,E,EMAP,L);
  20. }
  21. template <typename DerivedV, typename DerivedF, typename DerivedE, typename DerivedEMAP, typename LT>
  22. void igl::crouzeix_raviart_cotmatrix(
  23. const Eigen::MatrixBase<DerivedV> & V,
  24. const Eigen::MatrixBase<DerivedF> & F,
  25. const Eigen::MatrixBase<DerivedE> & E,
  26. const Eigen::MatrixBase<DerivedEMAP> & EMAP,
  27. Eigen::SparseMatrix<LT> & L)
  28. {
  29. assert(F.cols() == 3);
  30. // number of rows
  31. const int m = F.rows();
  32. // Mesh should be edge-manifold
  33. assert(is_edge_manifold(F));
  34. typedef Eigen::Matrix<LT,Eigen::Dynamic,Eigen::Dynamic> MatrixXS;
  35. MatrixXS C;
  36. cotmatrix_entries(V,F,C);
  37. Eigen::MatrixXi F2E(m,3);
  38. {
  39. int k =0;
  40. for(int c = 0;c<3;c++)
  41. {
  42. for(int f = 0;f<m;f++)
  43. {
  44. F2E(f,c) = k++;
  45. }
  46. }
  47. }
  48. std::vector<Eigen::Triplet<LT> > LIJV(12*m);
  49. Eigen::VectorXi LI(12),LJ(12),LV(12);
  50. LI<<0,1,2,1,2,0,0,1,2,1,2,0;
  51. LJ<<1,2,0,0,1,2,0,1,2,1,2,0;
  52. LV<<2,0,1,2,0,1,2,0,1,2,0,1;
  53. for(int f=0;f<m;f++)
  54. {
  55. for(int c = 0;c<12;c++)
  56. {
  57. LIJV.emplace_back(
  58. EMAP(F2E(f,LI(c))),
  59. EMAP(F2E(f,LJ(c))),
  60. (c<6?-1.:1.) * 4. *C(f,LV(c)));
  61. }
  62. }
  63. L.resize(E.rows(),E.rows());
  64. L.setFromTriplets(LIJV.begin(),LIJV.end());
  65. }