crouzeix_raviart_massmatrix.cpp 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 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_massmatrix.h"
  9. #include "unique_simplices.h"
  10. #include "oriented_facets.h"
  11. #include "is_edge_manifold.h"
  12. #include "doublearea.h"
  13. #include "volume.h"
  14. #include <cassert>
  15. #include <vector>
  16. template <typename MT, typename DerivedV, typename DerivedF, typename DerivedE, typename DerivedEMAP>
  17. void igl::crouzeix_raviart_massmatrix(
  18. const Eigen::MatrixBase<DerivedV> & V,
  19. const Eigen::MatrixBase<DerivedF> & F,
  20. Eigen::SparseMatrix<MT> & M,
  21. Eigen::PlainObjectBase<DerivedE> & E,
  22. Eigen::PlainObjectBase<DerivedEMAP> & EMAP)
  23. {
  24. // All occurrences of directed "facets"
  25. Eigen::MatrixXi allE;
  26. oriented_facets(F,allE);
  27. Eigen::VectorXi _1;
  28. unique_simplices(allE,E,_1,EMAP);
  29. return crouzeix_raviart_massmatrix(V,F,E,EMAP,M);
  30. }
  31. template <typename MT, typename DerivedV, typename DerivedF, typename DerivedE, typename DerivedEMAP>
  32. void igl::crouzeix_raviart_massmatrix(
  33. const Eigen::MatrixBase<DerivedV> & V,
  34. const Eigen::MatrixBase<DerivedF> & F,
  35. const Eigen::MatrixBase<DerivedE> & E,
  36. const Eigen::MatrixBase<DerivedEMAP> & EMAP,
  37. Eigen::SparseMatrix<MT> & M)
  38. {
  39. using namespace Eigen;
  40. using namespace std;
  41. // Mesh should be edge-manifold (TODO: replace `is_edge_manifold` with
  42. // `is_facet_manifold`)
  43. assert(F.cols() != 3 || is_edge_manifold(F));
  44. // number of elements (triangles)
  45. const int m = F.rows();
  46. // Get triangle areas/volumes
  47. VectorXd TA;
  48. // Element simplex size
  49. const int ss = F.cols();
  50. switch(ss)
  51. {
  52. default:
  53. assert(false && "Unsupported simplex size");
  54. case 3:
  55. doublearea(V,F,TA);
  56. TA *= 0.5;
  57. break;
  58. case 4:
  59. volume(V,F,TA);
  60. break;
  61. }
  62. vector<Triplet<MT> > MIJV(ss*m);
  63. assert(EMAP.size() == m*ss);
  64. for(int f = 0;f<m;f++)
  65. {
  66. for(int c = 0;c<ss;c++)
  67. {
  68. MIJV[f+m*c] = Triplet<MT>(EMAP(f+m*c),EMAP(f+m*c),TA(f)/(double)(ss));
  69. }
  70. }
  71. M.resize(E.rows(),E.rows());
  72. M.setFromTriplets(MIJV.begin(),MIJV.end());
  73. }
  74. #ifdef IGL_STATIC_LIBRARY
  75. // Explicit template instantiation
  76. // generated by autoexplicit.sh
  77. template void igl::crouzeix_raviart_massmatrix<double, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::SparseMatrix<double, 0, int>&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
  78. template void igl::crouzeix_raviart_massmatrix<double, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::SparseMatrix<double, 0, int>&);
  79. template void igl::crouzeix_raviart_massmatrix<float, Eigen::Matrix<float, -1, 3, 1, -1, 3>, Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::MatrixBase<Eigen::Matrix<float, -1, 3, 1, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::SparseMatrix<float, 0, int>&);
  80. #endif