WaveBEM: Unsteady Nonlinear Potential Flow Solver for Ship-Wave Interaction.
local_expansion.h
Go to the documentation of this file.
1 #ifndef LOCALEXPANSION_H_
2 #define LOCALEXPANSION_H_
3 
4 #include <math.h>
5 #include <string>
6 #include <vector>
7 
8 
10 
11 #include "multipole_expansion.h"
12 #include "ass_leg_function.h"
13 #include "local_expansion_coeff.h"
14 
15 
17 {
18 
19 public:
21 
22  //static std::vector <std::vector <std::vector <std::map <int,double > > > > mExp_to_lExp_Coeff;
23 
24  static std::vector <std::vector <std::map <int,std::map <int,double > > > > lExp_to_lExp_Coeff;
25 
27 
28  mutable bool is_zero;
29 
30 
31 private:
32 
33  mutable unsigned int p;
34 
35  mutable dealii::Point<3> center;
36 
38 
39  mutable std::complex <double> *_L_n_m;
40 
41 
42 public:
44 
45  LocalExpansion(const unsigned int order, const dealii::Point<3> &center, const AssLegFunction *assLegFunction);
46 
47  LocalExpansion(const LocalExpansion &other);
48 
50 
51  void Add(const std::vector <double> &real, const std::vector <double> &imag);
52 
53 
54  void Add(const LocalExpansion &parent);
55 
56  void Add(const MultipoleExpansion &multipole);
57 
58  double Evaluate(const dealii::Point<3> &evalPoint);
59 
60  inline dealii::Point<3> &GetCenter() const
61  {
62  return this->center;
63  }
64 
65  inline void SetCenter(const dealii::Point<3> &new_center)
66  {
67  this->center = new_center;
68  }
69 
71  {
72  return this->A_n_m;
73  }
74 
75  inline unsigned int GetOrder() const
76  {
77  return this->p;
78  }
79 
80  inline std::complex <double> *GetCoeffs() const
81  {
82  return this->_L_n_m;
83  }
84 
85  inline std::complex <double> &GetCoeff(unsigned int n, unsigned int m) const
86  {
87  return this->_L_n_m[(n)*(n+1)/2+m];
88  }
89 
90  void SetCoeff(unsigned int n, unsigned int m, std::complex <double> &value) const
91  {
92  this->_L_n_m[(n)*(n+1)/2+m] = value;
93  }
94 
95  void AddToCoeff(unsigned int n, unsigned int m, std::complex <double> &value) const
96  {
97  this->_L_n_m[(n)*(n+1)/2+m] += value;
98  }
99 
100  LocalExpansion &operator=( const LocalExpansion &other );
101 
102 
103  static FullMatrix<double> A_n_m_Matrix(unsigned int dimension)
104  {
105  FullMatrix<double> A_n_m(dimension+1,dimension+1);
106  for (unsigned int n = 0; n < dimension+1 ; n++)
107 
108  {
109  for (unsigned int m = 0; m < n+1 ; m++)
110 
111  {
112  double f1 = 1.;
113  double f2 = 1.;
114 
115  for (int ii = n-m; ii > 0; ii-- )
116  f1 *= ii;
117 
118  for (int ii = n+m; ii > 0; ii-- )
119  f2 *= (ii);
120 
121  A_n_m(n,m) = pow(-1.,double(n))/sqrt(f1*f2);
122  }
123  }
124 
125  return A_n_m;
126  }
127 
128  //static std::vector <std::vector <std::vector <std::map <int,double > > > >
129  static LocalExpansionCoeff
131  {
132  LocalExpansionCoeff loc_exp_coeff(p);
133  std::complex <double> imUnit = std::complex <double> (0.,1.);
134  std::vector <std::vector <std::vector <std::map <int,double > > > > realCoeff;
135  realCoeff.resize(p+1);
136  for (int n = 0; n < int(p)+1 ; n++)
137  {
138  realCoeff[n].resize(n+1);
139  for (int m = 0; m < n+1 ; m++)
140  {
141  realCoeff[n][m].resize(p+1);
142  for (int nn = 0; nn < int(p)+1 ; nn++)
143  {
144  for (int mm = -1*nn; mm < nn+1 ; mm++)
145  {
146 
147  //double realFact = (*gsl_matrix_ptr(A_n_m,nn,abs(mm))) / (*gsl_matrix_ptr(A_n_m,n+nn,abs(m-mm))) * (*gsl_matrix_ptr(A_n_m,n,abs(m)));
148  double realFact = A_n_m(nn,abs(mm)) / A_n_m(n+nn,abs(m-mm)) * A_n_m(n,abs(m));
149  realFact *= (pow(imUnit, double(abs(m-mm)-abs(m)-abs(mm)))).real()/pow(-1.,nn);
150  realCoeff[n][m][nn][mm] = realFact;
151  loc_exp_coeff.set(n,m,nn,mm,realFact);
152 
153  }
154 
155  }
156 
157  }
158 
159 
160  }
161  return loc_exp_coeff;
162  //return realCoeff;
163  }
164 
165  static std::vector <std::vector <std::map <int,std::map <int,double > > > >
167  {
168 
169  std::complex <double> imUnit = std::complex <double> (0.,1.);
170  std::vector <std::vector <std::map <int,std::map <int,double > > > > realCoeff;
171  realCoeff.resize(p+1);
172  for (int n = 0; n < int(p)+1 ; n++)
173  {
174  realCoeff[n].resize(n+1);
175  for (int m = 0; m < n+1 ; m++)
176  {
177  for (int nn = n; nn < int(p)+1 ; nn++)
178  {
179  for (int mm = -1*nn; mm < nn+1 ; mm++)
180  {
181 
182  //double realFact = (*gsl_matrix_ptr(A_n_m,nn-n,abs(mm-m))) / (*gsl_matrix_ptr(A_n_m,nn,abs(mm))) * (*gsl_matrix_ptr(A_n_m,n,abs(m)));
183  double realFact = A_n_m(nn-n,abs(mm-m)) / A_n_m(nn,abs(mm)) * A_n_m(n,abs(m));
184  realFact *= (pow(imUnit, double(abs(mm)-abs(mm-m)-abs(m)))).real()*pow(-1.,nn+n);
185  realCoeff[n][m][nn][mm] = realFact;
186 
187  }
188 
189  }
190 
191  }
192 
193 
194  }
195 
196 
197 
198  return realCoeff;
199  }
200 
201 };
202 
203 
204 
205 
206 
207 #endif /*LOCALEXPANSION_H_*/
static std::vector< std::vector< std::map< int, std::map< int, double > > > > lExp_to_lExp_Coeff_Build(FullMatrix< double > A_n_m, unsigned int p)
void set(const unsigned int &n, const unsigned int &m, const unsigned int &nn, const unsigned int &mm, const double &value)
static LocalExpansionCoeff mExp_to_lExp_Coeff
double Evaluate(const dealii::Point< 3 > &evalPoint)
FullMatrix< double > GetA_n_m() const
unsigned int GetOrder() const
const AssLegFunction * assLegFunction
static std::vector< std::vector< std::map< int, std::map< int, double > > > > lExp_to_lExp_Coeff
void SetCenter(const dealii::Point< 3 > &new_center)
static FullMatrix< double > A_n_m_Matrix(unsigned int dimension)
LocalExpansion & operator=(const LocalExpansion &other)
dealii::Point< 3 > & GetCenter() const
static LocalExpansionCoeff mExp_to_lExp_Coeff_Build(FullMatrix< double > A_n_m, unsigned int p)
static FullMatrix< double > A_n_m
static const bool value
unsigned int p
void AddToCoeff(unsigned int n, unsigned int m, std::complex< double > &value) const
void SetCoeff(unsigned int n, unsigned int m, std::complex< double > &value) const
std::complex< double > * _L_n_m
std::complex< double > & GetCoeff(unsigned int n, unsigned int m) const
dealii::Point< 3 > center
void Add(const std::vector< double > &real, const std::vector< double > &imag)
std::complex< double > * GetCoeffs() const