sph_harm.hpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #ifndef _SCTL_SPH_HARM_HPP_
  2. #define _SCTL_SPH_HARM_HPP_
  3. #define SCTL_SHMAXDEG 256
  4. #include SCTL_INCLUDE(matrix.hpp)
  5. #include SCTL_INCLUDE(fft_wrapper.hpp)
  6. #include SCTL_INCLUDE(common.hpp)
  7. namespace SCTL_NAMESPACE {
  8. template <class Real> class SphericalHarmonics{
  9. static constexpr Integer COORD_DIM = 3;
  10. public:
  11. // TODO: Ynm *= sqrt(2)*(m==0?1:2);
  12. static void SHC2Grid(const Vector<Real>& S, Long p0, Long p1, Vector<Real>& X, Vector<Real>* X_theta=nullptr, Vector<Real>* X_phi=nullptr);
  13. static void Grid2SHC(const Vector<Real>& X, Long Nt, Long Np, Long p1, Vector<Real>& S);
  14. static void Grid2SHC(const Vector<Real>& X, Long p0, Long p1, Vector<Real>& S);
  15. static void SHC2GridTranspose(const Vector<Real>& X, Long p0, Long p1, Vector<Real>& S);
  16. static void SHC2Pole(const Vector<Real>& S, Long p0, Vector<Real>& P);
  17. static void RotateAll(const Vector<Real>& S, Long p0, Long dof, Vector<Real>& S_);
  18. static void RotateTranspose(const Vector<Real>& S_, Long p0, Long dof, Vector<Real>& S);
  19. static void StokesSingularInteg(const Vector<Real>& S, Long p0, Long p1, Vector<Real>* SLMatrix=nullptr, Vector<Real>* DLMatrix=nullptr);
  20. static void WriteVTK(const char* fname, long p0, long p1, Real period=0, const Vector<Real>* S=nullptr, const Vector<Real>* f_val=nullptr, MPI_Comm comm=MPI_COMM_WORLD);
  21. private:
  22. static Vector<Real>& LegendreNodes(Long p1);
  23. static Vector<Real>& LegendreWeights(Long p1);
  24. static Vector<Real>& SingularWeights(Long p1);
  25. static Matrix<Real>& MatFourier(Long p0, Long p1);
  26. static Matrix<Real>& MatFourierInv(Long p0, Long p1);
  27. static Matrix<Real>& MatFourierGrad(Long p0, Long p1);
  28. static std::vector<Matrix<Real>>& MatLegendre(Long p0, Long p1);
  29. static std::vector<Matrix<Real>>& MatLegendreInv(Long p0, Long p1);
  30. static std::vector<Matrix<Real>>& MatLegendreGrad(Long p0, Long p1);
  31. static std::vector<Matrix<Real>>& MatRotate(Long p0);
  32. /**
  33. * \brief Computes all the Associated Legendre Polynomials (normalized) upto the specified degree.
  34. * \param[in] degree The degree upto which the legendre polynomials have to be computed.
  35. * \param[in] X The input values for which the polynomials have to be computed.
  36. * \param[in] N The number of input points.
  37. * \param[out] poly_val The output array of size (degree+1)*(degree+2)*N/2 containing the computed polynomial values.
  38. * The output values are in the order:
  39. * P(n,m)[i] => {P(0,0)[0], P(0,0)[1], ..., P(0,0)[N-1], P(1,0)[0], ..., P(1,0)[N-1],
  40. * P(2,0)[0], ..., P(degree,0)[N-1], P(1,1)[0], ...,P(2,1)[0], ..., P(degree,degree)[N-1]}
  41. */
  42. //static void LegPoly(Vector<Real>& poly_val, const Vector<Real>& X, Long degree);
  43. //static void LegPolyDeriv(Vector<Real>& poly_val, const Vector<Real>& X, Long degree);
  44. static void LegPoly(Real* poly_val, const Real* X, Long N, Long degree);
  45. static void LegPolyDeriv(Real* poly_val, const Real* X, Long N, Long degree);
  46. template <bool SLayer, bool DLayer> static void StokesSingularInteg_(const Vector<Real>& X0, Long p0, Long p1, Vector<Real>& SL, Vector<Real>& DL);
  47. struct MatrixStorage{
  48. MatrixStorage(Long size){
  49. Qx_ .resize(size);
  50. Qw_ .resize(size);
  51. Sw_ .resize(size);
  52. Mf_ .resize(size*size);
  53. Mdf_.resize(size*size);
  54. Ml_ .resize(size*size);
  55. Mdl_.resize(size*size);
  56. Mr_ .resize(size);
  57. Mfinv_ .resize(size*size);
  58. Mlinv_ .resize(size*size);
  59. }
  60. std::vector<Vector<Real>> Qx_;
  61. std::vector<Vector<Real>> Qw_;
  62. std::vector<Vector<Real>> Sw_;
  63. std::vector<Matrix<Real>> Mf_ ;
  64. std::vector<Matrix<Real>> Mdf_;
  65. std::vector<std::vector<Matrix<Real>>> Ml_ ;
  66. std::vector<std::vector<Matrix<Real>>> Mdl_;
  67. std::vector<std::vector<Matrix<Real>>> Mr_;
  68. std::vector<Matrix<Real>> Mfinv_ ;
  69. std::vector<std::vector<Matrix<Real>>> Mlinv_ ;
  70. };
  71. static MatrixStorage& MatrixStore(){
  72. static MatrixStorage storage(SCTL_SHMAXDEG);
  73. return storage;
  74. }
  75. };
  76. template class SphericalHarmonics<double>;
  77. } // end namespace
  78. #include SCTL_INCLUDE(sph_harm.txx)
  79. #endif // _SCTL_SPH_HARM_HPP_