slender_element.hpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. #ifndef _SCTL_SLENDER_ELEMENT_HPP_
  2. #define _SCTL_SLENDER_ELEMENT_HPP_
  3. #include <sctl/common.hpp>
  4. #include SCTL_INCLUDE(mem_mgr.hpp)
  5. #include SCTL_INCLUDE(vector.hpp)
  6. namespace SCTL_NAMESPACE {
  7. class Comm;
  8. struct VTUData;
  9. template <class Real> class FFT;
  10. template <class ValueType> class Vector;
  11. template <class ValueType> class Matrix;
  12. template <class Real> class ElementListBase;
  13. template <class Real, class Kernel> class BoundaryIntegralOp;
  14. template <class Real, Integer Nm = 12, Integer Nr = 20, Integer Nt = 16> class ToroidalGreensFn {
  15. static constexpr Integer COORD_DIM = 3;
  16. static constexpr Real min_dist = 0.0;
  17. static constexpr Real max_dist = 0.2;
  18. public:
  19. /**
  20. * Constructor
  21. */
  22. ToroidalGreensFn() {}
  23. /**
  24. * Precompute tables for modal Green's funcation
  25. */
  26. template <class Kernel> void Setup(const Kernel& ker, Real R0);
  27. /**
  28. * Build modal Green's function operator for a given target point
  29. * (x0,x1,x2).
  30. */
  31. template <class Kernel> void BuildOperatorModal(Matrix<Real>& M, const Real x0, const Real x1, const Real x2, const Kernel& ker) const;
  32. private:
  33. /**
  34. * Basis functions in which to represent the potential.
  35. */
  36. template <class ValueType> class BasisFn { // p(x) log(x) + q(x) + 1/x
  37. public:
  38. static ValueType Eval(const Vector<ValueType>& coeff, ValueType x);
  39. static void EvalBasis(Vector<ValueType>& f, ValueType x);
  40. static const Vector<ValueType>& nds(Integer ORDER);
  41. };
  42. /**
  43. * Precompute tables for modal Green's funcation
  44. */
  45. template <class ValueType, class Kernel> void PrecompToroidalGreensFn(const Kernel& ker, ValueType R0);
  46. /**
  47. * Compute reference potential using adaptive integration.
  48. */
  49. template <class ValueType, class Kernel> static void ComputePotential(Vector<ValueType>& U, const Vector<ValueType>& Xtrg, ValueType R0, const Vector<ValueType>& F_, const Kernel& ker, ValueType tol = 1e-18);
  50. /**
  51. * Compute modal Green's function operator using trapezoidal quadrature
  52. * rule (for distant target points).
  53. */
  54. template <Integer Nnds, class Kernel> void BuildOperatorModalDirect(Matrix<Real>& M, const Real x0, const Real x1, const Real x2, const Kernel& ker) const;
  55. Real R0_;
  56. FFT<Real> fft_Nm_R2C, fft_Nm_C2R;
  57. Matrix<Real> Mnds2coeff0, Mnds2coeff1;
  58. Vector<Real> U; // KDIM0*Nmm*KDIM1*Nr*Ntt
  59. Vector<Real> Ut; // Nr*Ntt*KDIM0*Nmm*KDIM1
  60. };
  61. /**
  62. * Implements the abstract class ElementListBase for slender boundary
  63. * elements with circular cross-section.
  64. *
  65. * @see ElementListBase
  66. */
  67. template <class Real> class SlenderElemList : public ElementListBase<Real> {
  68. static constexpr Integer FARFIELD_UPSAMPLE = 1;
  69. static constexpr Integer COORD_DIM = 3;
  70. static constexpr Integer ModalUpsample = 1; // toroidal quadrature order is FourierModes+ModalUpsample
  71. public:
  72. /**
  73. * Constructor
  74. */
  75. SlenderElemList() {}
  76. /**
  77. * Constructor
  78. */
  79. SlenderElemList(const Vector<Long>& cheb_order0, const Vector<Long>& fourier_order0, const Vector<Real>& coord0, const Vector<Real>& radius0, const Vector<Real>& orientation0 = Vector<Real>());
  80. /**
  81. * Initialize list of elements
  82. */
  83. void Init(const Vector<Long>& cheb_order0, const Vector<Long>& fourier_order0, const Vector<Real>& coord0, const Vector<Real>& radius0, const Vector<Real>& orientation0 = Vector<Real>());
  84. /**
  85. * Destructor
  86. */
  87. virtual ~SlenderElemList() {}
  88. /**
  89. * Return the number of elements in the list.
  90. */
  91. Long Size() const;
  92. /**
  93. * Returns the position and normals of the surface nodal points for each
  94. * element.
  95. *
  96. * @see ElementListBase::GetNodeCoord()
  97. */
  98. void GetNodeCoord(Vector<Real>* X, Vector<Real>* Xn, Vector<Long>* element_wise_node_cnt) const override;
  99. /**
  100. * Given an accuracy tolerance, returns the quadrature node positions,
  101. * the normals at the nodes, the weights and the cut-off distance from
  102. * the nodes for computing the far-field potential from the surface (at
  103. * target points beyond the cut-off distance).
  104. *
  105. * @see ElementListBase::GetFarFieldNodes()
  106. */
  107. void GetFarFieldNodes(Vector<Real>& X, Vector<Real>& Xn, Vector<Real>& wts, Vector<Real>& dist_far, Vector<Long>& element_wise_node_cnt, const Real tol) const override;
  108. /**
  109. * Interpolates the density from surface node points to far-field
  110. * quadrature node points.
  111. *
  112. * @see ElementListBase::GetFarFieldDensity()
  113. */
  114. void GetFarFieldDensity(Vector<Real>& Fout, const Vector<Real>& Fin) const override;
  115. /**
  116. * Apply the transpose of the GetFarFieldDensity() operator applied to
  117. * the column-vectors of Min and the result is returned in Mout.
  118. *
  119. * @see ElementListBase::FarFieldDensityOperatorTranspose()
  120. */
  121. void FarFieldDensityOperatorTranspose(Matrix<Real>& Mout, const Matrix<Real>& Min, const Long elem_idx) const override;
  122. /**
  123. * Compute self-interaction operator for each element.
  124. *
  125. * @see ElementListBase::SelfInterac()
  126. */
  127. template <class Kernel> static void SelfInterac(Vector<Matrix<Real>>& M_lst, const Kernel& ker, Real tol, bool trg_dot_prod, const ElementListBase<Real>* self);
  128. /**
  129. * Compute near-interaction operator for a given element-idx and each each target.
  130. *
  131. * @see ElementListBase::NearInterac()
  132. */
  133. template <class Kernel> static void NearInterac(Matrix<Real>& M, const Vector<Real>& Xtrg, const Vector<Real>& normal_trg, const Kernel& ker, Real tol, const Long elem_idx, const ElementListBase<Real>* self);
  134. /**
  135. * Returns the Chebyshev node points for a given order.
  136. */
  137. static const Vector<Real>& CenterlineNodes(const Integer Order);
  138. /**
  139. * Write elements to file.
  140. */
  141. void Write(const std::string& fname, const Comm& comm = Comm::Self()) const;
  142. /**
  143. * Read elements from file.
  144. */
  145. void Read(const std::string& fname, const Comm& comm = Comm::Self());
  146. /**
  147. * Get geometry data for an element.
  148. */
  149. void GetGeom(Vector<Real>* X, Vector<Real>* Xn, Vector<Real>* Xa, Vector<Real>* dX_ds, Vector<Real>* dX_dt, const Vector<Real>& s_param, const Vector<Real>& sin_theta_, const Vector<Real>& cos_theta_, const Long elem_idx) const;
  150. /**
  151. * Get the VTU (Visualization Toolkit for Unstructured grids) data for
  152. * one or all elements.
  153. */
  154. void GetVTUData(VTUData& vtu_data, const Vector<Real>& F = Vector<Real>(), const Long elem_idx = -1) const;
  155. /**
  156. * Write VTU data to file.
  157. */
  158. void WriteVTK(const std::string& fname, const Vector<Real>& F = Vector<Real>(), const Comm& comm = Comm::Self()) const;
  159. /**
  160. * Test example for Laplace double-layer kernel.
  161. */
  162. template <class Kernel> static void test(const Comm& comm = Comm::Self(), Real tol = 1e-10);
  163. /**
  164. * Test example for Green's identity with Laplace kernel.
  165. */
  166. static void test_greens_identity(const Comm& comm = Comm::Self(), Real tol = 1e-10);
  167. template <class ValueType> void Copy(SlenderElemList<ValueType>& elem_lst) const;
  168. private:
  169. template <class Kernel> Matrix<Real> SelfInteracHelper_(const Kernel& ker, const Long elem_idx, const Real tol) const; // constant radius
  170. template <Integer digits, bool trg_dot_prod, class Kernel> Matrix<Real> SelfInteracHelper(const Kernel& ker, const Long elem_idx) const;
  171. template <Integer digits, bool trg_dot_prod, class Kernel> void NearInteracHelper(Matrix<Real>& M, const Vector<Real>& Xtrg, const Vector<Real>& normal_trg, const Kernel& ker, const Long elem_idx) const;
  172. Vector<Real> radius, coord, e1;
  173. Vector<Long> cheb_order, fourier_order, elem_dsp;
  174. Vector<Real> dr, dx, d2x; // derived quantities
  175. };
  176. }
  177. #include SCTL_INCLUDE(slender_element.txx)
  178. #endif //_SCTL_SLENDER_ELEMENT_HPP_