crouzeix_raviart_cotmatrix.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2017 Alec Jacobson <alecjacobson@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #include "crouzeix_raviart_cotmatrix.h"
  9. #include "unique_simplices.h"
  10. #include "oriented_facets.h"
  11. #include "is_edge_manifold.h"
  12. #include "cotmatrix_entries.h"
  13. template <typename DerivedV, typename DerivedF, typename LT, typename DerivedE, typename DerivedEMAP>
  14. void igl::crouzeix_raviart_cotmatrix(
  15. const Eigen::MatrixBase<DerivedV> & V,
  16. const Eigen::MatrixBase<DerivedF> & F,
  17. Eigen::SparseMatrix<LT> & L,
  18. Eigen::PlainObjectBase<DerivedE> & E,
  19. Eigen::PlainObjectBase<DerivedEMAP> & EMAP)
  20. {
  21. // All occurances of directed edges
  22. Eigen::MatrixXi allE;
  23. oriented_facets(F,allE);
  24. Eigen::VectorXi _1;
  25. unique_simplices(allE,E,_1,EMAP);
  26. return crouzeix_raviart_cotmatrix(V,F,E,EMAP,L);
  27. }
  28. template <typename DerivedV, typename DerivedF, typename DerivedE, typename DerivedEMAP, typename LT>
  29. void igl::crouzeix_raviart_cotmatrix(
  30. const Eigen::MatrixBase<DerivedV> & V,
  31. const Eigen::MatrixBase<DerivedF> & F,
  32. const Eigen::MatrixBase<DerivedE> & E,
  33. const Eigen::MatrixBase<DerivedEMAP> & EMAP,
  34. Eigen::SparseMatrix<LT> & L)
  35. {
  36. assert(F.cols() == 3);
  37. // number of rows
  38. const int m = F.rows();
  39. // Mesh should be edge-manifold
  40. assert(is_edge_manifold(F));
  41. typedef Eigen::Matrix<LT,Eigen::Dynamic,Eigen::Dynamic> MatrixXS;
  42. MatrixXS C;
  43. cotmatrix_entries(V,F,C);
  44. Eigen::MatrixXi F2E(m,3);
  45. {
  46. int k =0;
  47. for(int c = 0;c<3;c++)
  48. {
  49. for(int f = 0;f<m;f++)
  50. {
  51. F2E(f,c) = k++;
  52. }
  53. }
  54. }
  55. std::vector<Eigen::Triplet<LT> > LIJV(12*m);
  56. Eigen::VectorXi LI(12),LJ(12),LV(12);
  57. LI<<0,1,2,1,2,0,0,1,2,1,2,0;
  58. LJ<<1,2,0,0,1,2,0,1,2,1,2,0;
  59. LV<<2,0,1,2,0,1,2,0,1,2,0,1;
  60. for(int f=0;f<m;f++)
  61. {
  62. for(int c = 0;c<12;c++)
  63. {
  64. LIJV.emplace_back(
  65. EMAP(F2E(f,LI(c))),
  66. EMAP(F2E(f,LJ(c))),
  67. (c<6?-1.:1.) * 4. *C(f,LV(c)));
  68. }
  69. }
  70. L.resize(E.rows(),E.rows());
  71. L.setFromTriplets(LIJV.begin(),LIJV.end());
  72. }