MercuryDPM  0.11
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
NORMALIZED_POLYNOMIAL< T > Class Template Reference

This class is used to define polynomial axisymmetric coarse-graining functions. More...

#include <NormalisedPolynomial.h>

Public Member Functions

 NORMALIZED_POLYNOMIAL ()
 Basic constructor; note that this does not determine the particular polynomial; one needs to call set_polynomial to define the coefficients. More...
 
void set_polynomial (std::vector< Mdouble > new_coefficients, unsigned int new_dim)
 Use this function to set the polynomial coefficients $c_i$. This function calls finish_set_polynomial to normalize the coefficients. More...
 
void set_polynomial (Mdouble *new_coefficients, unsigned int num_coeff, unsigned int new_dim)
 Some as set_polynomial, but avoids the use of a vector. More...
 
void setName (const char *new_name)
 Use this function to change the name of the polynomial. More...
 
std::string getName ()
 Returns name of the polynomial. More...
 
Mdouble evaluate (Mdouble r)
 Returns the value of the polynomial, $p(r)=\sum_{i=0}^N c_i r^{N-i}$. More...
 
Mdouble evaluateGradient (Mdouble r)
 Returns the gradient of the polynomial, $\partial_\alpha p(x,y,z)=\sum_{i=0}^N c_{i,\alpha} r^{N-i},\ \alpha=x,y,z$. More...
 
Mdouble evaluateIntegral (Mdouble a, Mdouble b, Mdouble t)
 Returns the value of the line integral along the normal P1P2 "from a to b" over the axisymmetric function. More...
 
int getOrder (void)
 Returns the order of the polynomial. More...
 
template<>
double evaluate (double r)
 
template<>
double evaluate (double r)
 
template<>
double evaluate (double r)
 
template<>
double evaluate (double r)
 
template<>
double evaluate (double r)
 
template<>
double evaluate (double r)
 
template<>
double evaluateGradient (double r)
 
template<>
double evaluateGradient (double r)
 
template<>
double evaluateGradient (double r)
 
template<>
double evaluateGradient (double r)
 
template<>
double evaluateGradient (double r)
 
template<>
double evaluateGradient (double r)
 
template<>
double evaluateIntegral (double a, double b, double t)
 
template<>
double evaluateIntegral (double a, double b, double t)
 
template<>
double evaluateIntegral (double a, double b, double t)
 
template<>
double evaluateIntegral (double a, double b, double t)
 
template<>
double evaluateIntegral (double a, double b, double t)
 
template<>
double evaluateIntegral (double a, double b, double t)
 

Private Member Functions

void finish_set_polynomial ()
 Normalizes the polynomial coefficients $c_i$ such that the integral over the unit sphere of the axisymmetric function $p(r)$ is unity. More...
 
Mdouble get_volume ()
 Returns the integral over the unit sphere of the axisymmetric function $p(r)$. More...
 
Mdouble evaluate_1D (Mdouble r)
 Returns the value of the polynomial averaged over 2 dimensions. For StatType=X, $r=|x|$. See also set_average_1D. More...
 
Mdouble evaluate_2D (Mdouble r)
 Returns the value of the polynomial averaged over 1 dimension. For StatType=XY, $r=\sqrt{x^2+y^2}$. More...
 
void set_average ()
 Sets averaged_coefficients. More...
 
void set_average_1D ()
 Sets averaged_coefficients $\bar{c}_i$ for StatType=X,Y,Z such that $\sum_{i=0}^N \bar{c}_i x^{N-i} = \int\int_{|\vec{x}|\leq 1} p(|\vec{x}|) dy dz$. See evaluate_1D. More...
 
void set_average_2D ()
 For StatType=XY,XZ,XZ, averaged_coefficients is not used since $\bar{p}(r)$ can be evaluated as a function of $c_i$. See evaluate_2D. More...
 
Mdouble evaluateGradient_1D (Mdouble r)
 Returns the value of the gradient averaged over 2 dimensions. More...
 
Mdouble evaluateGradient_2D (Mdouble r)
 Returns the value of the gradient averaged over 1 dimensions. More...
 
Mdouble evaluateIntegral_1D (Mdouble a, Mdouble b, Mdouble t)
 Returns the value of the line integral along the normal P1P2 "from a to b" over the axisymmetric function averaged over 2 dimensions. More...
 
Mdouble evaluateIntegral_2D (Mdouble a, Mdouble b, Mdouble t)
 Returns the value of the line integral along the normal P1P2 "from a to b" over the axisymmetric function averaged over 1 dimensions. More...
 
Mdouble operator[] (int i) const
 Access to the coefficients. More...
 
template<>
void set_average ()
 
template<>
void set_average ()
 
template<>
void set_average ()
 
template<>
void set_average ()
 
template<>
void set_average ()
 
template<>
void set_average ()
 

Private Attributes

std::string name
 Contains the name of the polynomial which will be displayed as CGtype by the statistical code. More...
 
unsigned int dim
 The system dimension. More...
 
std::vector< Mdoublecoefficients
 Stores the coefficients $c_i$. More...
 
std::vector< Mdoubleaveraged_coefficients
 Stores some coefficients used in evaluate and evaluateIntegral for StatTypes different from XYZ. More...
 

Friends

std::ostream & operator<< (std::ostream &os, const NORMALIZED_POLYNOMIAL &P)
 Returns a text description of the polynomial. More...
 

Detailed Description

template<StatType T>
class NORMALIZED_POLYNOMIAL< T >

This class is used to define polynomial axisymmetric coarse-graining functions.

This class stores a polynomial, $p(r)=\sum_{i=0}^N c_i r^{N-i}$, which is normalized such that the integral over the unit sphere of the axisymmetric function $p(|\vec{x}|)$ is unity.
Use set_polynomial to define the polynomial. Use evaluate to evaluate the polynomial. Use evaluateGradient to evaluate the polynomial's gradient.
Calculations can be found in src/docs/Polynomials.nb
This is used to define polynomial axisymmetric coarse-graining functions (see StatisticsVector).
Note: not everything is implemented yet: only dim=3 is working, no gradients are computed.

Definition at line 51 of file NormalisedPolynomial.h.

Constructor & Destructor Documentation

template<StatType T>
NORMALIZED_POLYNOMIAL< T >::NORMALIZED_POLYNOMIAL ( )
inline

Basic constructor; note that this does not determine the particular polynomial; one needs to call set_polynomial to define the coefficients.

Definition at line 85 of file NormalisedPolynomial.h.

References NORMALIZED_POLYNOMIAL< T >::coefficients, NORMALIZED_POLYNOMIAL< T >::dim, and NORMALIZED_POLYNOMIAL< T >::setName().

86  {
87  setName("Polynomial");
88  coefficients.resize(0);
89  dim = 0;
90  }
void setName(const char *new_name)
Use this function to change the name of the polynomial.
unsigned int dim
The system dimension.
std::vector< Mdouble > coefficients
Stores the coefficients .

Member Function Documentation

template<StatType T>
double NORMALIZED_POLYNOMIAL< T >::evaluate ( Mdouble  r)

Returns the value of the polynomial, $p(r)=\sum_{i=0}^N c_i r^{N-i}$.

For averaged StatType this function is templated. If averaging statistics are used, then an averaged function is stored as well; for averaging a over certain dimensions is stored as well.

For averaging over two dimensions, $(y_{max}-y_{min})\cdot (z_{max}-z_{min})\cdot \bar{p}(x)=\int_{\vec{x}\leq1} p(|\vec{x}|) dy\,dz = \sum_{i=0}^N \bar{c}_i r^{N-i}$.

For averaging over one dimensions, $(z_{max}-z_{min})\cdot \bar{p}(x,y)=\int_{\vec{x}\leq1} p(|\vec{x}|) dz = \sum_{i=0}^N \bar{c}_i r^{N-i}$.

Todo:
I originally forgot to put a return statement here but the compiler did not give me a warning. Can we give a compiler option to throw warnings if there are no return statements?

Definition at line 130 of file NormalisedPolynomial.hcc.

References NORMALIZED_POLYNOMIAL< T >::coefficients.

131 {
132  unsigned int N = coefficients.size();
133  double value = coefficients[0];
134  for (unsigned int i = 1; i < N; i++)
135  value = value * r + coefficients[i];
137  return value;
138 }
std::vector< Mdouble > coefficients
Stores the coefficients .
template<>
double NORMALIZED_POLYNOMIAL< X >::evaluate ( double  r)

Definition at line 365 of file NormalisedPolynomial.hcc.

366 {
367  return evaluate_1D(r);
368 }
Mdouble evaluate_1D(Mdouble r)
Returns the value of the polynomial averaged over 2 dimensions. For StatType=X, . See also set_averag...
template<>
double NORMALIZED_POLYNOMIAL< Y >::evaluate ( double  r)

Definition at line 369 of file NormalisedPolynomial.hcc.

370 {
371  return evaluate_1D(r);
372 }
Mdouble evaluate_1D(Mdouble r)
Returns the value of the polynomial averaged over 2 dimensions. For StatType=X, . See also set_averag...
template<>
double NORMALIZED_POLYNOMIAL< Z >::evaluate ( double  r)

Definition at line 373 of file NormalisedPolynomial.hcc.

374 {
375  return evaluate_1D(r);
376 }
Mdouble evaluate_1D(Mdouble r)
Returns the value of the polynomial averaged over 2 dimensions. For StatType=X, . See also set_averag...
template<>
double NORMALIZED_POLYNOMIAL< XY >::evaluate ( double  r)

Definition at line 377 of file NormalisedPolynomial.hcc.

378 {
379  return evaluate_2D(r);
380 }
Mdouble evaluate_2D(Mdouble r)
Returns the value of the polynomial averaged over 1 dimension. For StatType=XY, . ...
template<>
double NORMALIZED_POLYNOMIAL< XZ >::evaluate ( double  r)

Definition at line 381 of file NormalisedPolynomial.hcc.

382 {
383  return evaluate_2D(r);
384 }
Mdouble evaluate_2D(Mdouble r)
Returns the value of the polynomial averaged over 1 dimension. For StatType=XY, . ...
template<>
double NORMALIZED_POLYNOMIAL< YZ >::evaluate ( double  r)

Definition at line 385 of file NormalisedPolynomial.hcc.

386 {
387  return evaluate_2D(r);
388 }
Mdouble evaluate_2D(Mdouble r)
Returns the value of the polynomial averaged over 1 dimension. For StatType=XY, . ...
template<StatType T>
double NORMALIZED_POLYNOMIAL< T >::evaluate_1D ( Mdouble  r)
private

Returns the value of the polynomial averaged over 2 dimensions. For StatType=X, $r=|x|$. See also set_average_1D.

Definition at line 152 of file NormalisedPolynomial.hcc.

References NORMALIZED_POLYNOMIAL< T >::averaged_coefficients.

153 {
154  unsigned int N = averaged_coefficients.size();
155  double value = averaged_coefficients[0];
156  for (unsigned int i = 1; i < N; i++)
157  value = value * r + averaged_coefficients[i];
158  return value;
159 }
std::vector< Mdouble > averaged_coefficients
Stores some coefficients used in evaluate and evaluateIntegral for StatTypes different from XYZ...
template<StatType T>
double NORMALIZED_POLYNOMIAL< T >::evaluate_2D ( Mdouble  r)
private

Returns the value of the polynomial averaged over 1 dimension. For StatType=XY, $r=\sqrt{x^2+y^2}$.

Definition at line 183 of file NormalisedPolynomial.hcc.

References NORMALIZED_POLYNOMIAL< T >::coefficients.

184 {
185  //~ std::cout << "eval_2D" << std::endl;
186  unsigned int N = coefficients.size();
187  double value1 = 2. * coefficients[N - 1];
188  double value2 = 0;
189  double r2 = r * r;
190  switch (N)
191  {
192  case 7:
193  value1 += coefficients[N - 7] * 2. / 35. * (5. + r2 * (6. + r2 * (8 * r2 + 16)));
194  //[[clang::fallthrough]];
195  case 6:
196  value1 += coefficients[N - 6] * (8. + (10. + 15. * r2) * r2) / 24.;
197  value2 += coefficients[N - 6] * (15. * r2 * r2 * r2) / 24.;
198  //[[clang::fallthrough]];
199  case 5:
200  value1 += coefficients[N - 5] * .4 * (1. + r2 * (4. / 3. + r2 * 8. / 3.));
201  //[[clang::fallthrough]];
202  case 4:
203  value1 += coefficients[N - 4] * (2. + r2 * 3.) / 4.;
204  value2 += coefficients[N - 4] * .75 * r2 * r2;
205  //[[clang::fallthrough]];
206  case 3:
207  value1 += coefficients[N - 3] * 2. / 3. * (1. + r2 * 2.);
208  //[[clang::fallthrough]];
209  case 2:
210  value1 += coefficients[N - 2] * 1.;
211  value2 += coefficients[N - 2] * r2;
212  //[[clang::fallthrough]];
213  case 1:
214  break;
215  default:
216  std::cerr << "Error: no rules set for high-order polynomials" << std::endl;
217  exit(-1);
218  }
219  double root = sqrt(1 - r2);
220  double invz = root / r;
221  double arccsch = log(sqrt(1. + invz * invz) + invz);
222  return value1 * root + value2 * arccsch;
223 }
std::vector< Mdouble > coefficients
Stores the coefficients .
template<StatType T>
double NORMALIZED_POLYNOMIAL< T >::evaluateGradient ( Mdouble  r)

Returns the gradient of the polynomial, $\partial_\alpha p(x,y,z)=\sum_{i=0}^N c_{i,\alpha} r^{N-i},\ \alpha=x,y,z$.

Definition at line 142 of file NormalisedPolynomial.hcc.

References NORMALIZED_POLYNOMIAL< T >::coefficients.

143 {
144  unsigned int N = coefficients.size();
145  double value = (N - 1) * coefficients[0];
146  for (unsigned int i = 1; i < N - 1; i++)
147  value = value * r + (N - 1 - i) * coefficients[i];
148  return value;
149 }
std::vector< Mdouble > coefficients
Stores the coefficients .
template<>
double NORMALIZED_POLYNOMIAL< X >::evaluateGradient ( double  r)

Definition at line 390 of file NormalisedPolynomial.hcc.

391 {
392  return evaluateGradient_1D(r);
393 }
Mdouble evaluateGradient_1D(Mdouble r)
Returns the value of the gradient averaged over 2 dimensions.
template<>
double NORMALIZED_POLYNOMIAL< Y >::evaluateGradient ( double  r)

Definition at line 394 of file NormalisedPolynomial.hcc.

395 {
396  return evaluateGradient_1D(r);
397 }
Mdouble evaluateGradient_1D(Mdouble r)
Returns the value of the gradient averaged over 2 dimensions.
template<>
double NORMALIZED_POLYNOMIAL< Z >::evaluateGradient ( double  r)

Definition at line 398 of file NormalisedPolynomial.hcc.

399 {
400  return evaluateGradient_1D(r);
401 }
Mdouble evaluateGradient_1D(Mdouble r)
Returns the value of the gradient averaged over 2 dimensions.
template<>
double NORMALIZED_POLYNOMIAL< XY >::evaluateGradient ( double  r)

Definition at line 402 of file NormalisedPolynomial.hcc.

403 {
404  return evaluateGradient_2D(r);
405 }
Mdouble evaluateGradient_2D(Mdouble r)
Returns the value of the gradient averaged over 1 dimensions.
template<>
double NORMALIZED_POLYNOMIAL< XZ >::evaluateGradient ( double  r)

Definition at line 406 of file NormalisedPolynomial.hcc.

407 {
408  return evaluateGradient_2D(r);
409 }
Mdouble evaluateGradient_2D(Mdouble r)
Returns the value of the gradient averaged over 1 dimensions.
template<>
double NORMALIZED_POLYNOMIAL< YZ >::evaluateGradient ( double  r)

Definition at line 410 of file NormalisedPolynomial.hcc.

411 {
412  return evaluateGradient_2D(r);
413 }
Mdouble evaluateGradient_2D(Mdouble r)
Returns the value of the gradient averaged over 1 dimensions.
template<StatType T>
double NORMALIZED_POLYNOMIAL< T >::evaluateGradient_1D ( Mdouble  r)
private

Returns the value of the gradient averaged over 2 dimensions.

Definition at line 162 of file NormalisedPolynomial.hcc.

References NORMALIZED_POLYNOMIAL< T >::coefficients, and constants::pi.

163 {
164  unsigned int N = coefficients.size();
165  double value = coefficients[0];
166  double value2 = coefficients[0];
167  for (unsigned int i = 1; i < N - 1; i++)
168  {
169  value = value * r + coefficients[i];
170  value2 += coefficients[i];
171  }
172  return 2. * constants::pi * r * (value2 - value * r);
173 }
const Mdouble pi
Definition: ExtendedMath.h:42
std::vector< Mdouble > coefficients
Stores the coefficients .
template<StatType T>
double NORMALIZED_POLYNOMIAL< T >::evaluateGradient_2D ( Mdouble  r)
private

Returns the value of the gradient averaged over 1 dimensions.

Todo:

Definition at line 176 of file NormalisedPolynomial.hcc.

177 {
179  return 0.0;
180 }
template<StatType T>
double NORMALIZED_POLYNOMIAL< T >::evaluateIntegral ( Mdouble  a,
Mdouble  b,
Mdouble  t 
)

Returns the value of the line integral along the normal P1P2 "from a to b" over the axisymmetric function.

averaging.jpeg
circle denotes the cutoff radius of the cg function around P

For averaged StatType this function is templated.

Definition at line 226 of file NormalisedPolynomial.hcc.

References A, and NORMALIZED_POLYNOMIAL< T >::coefficients.

227 {
228  unsigned int N = coefficients.size();
229  double value1 = coefficients[N - 1] * (b - a);
230  double value2 = 0;
231  double t2 = t * t;
232  double a2 = a * a;
233  double b2 = b * b;
234  double roota = sqrt(a * a + t2);
235  double rootb = sqrt(b * b + t2);
236  switch (N)
237  {
238  case 7:
239  value1 += coefficients[N - 7] * (b * (b2 * b2 * b2 / 7.0 + 0.6 * b2 * b2 * t2 + b2 * t2 * t2 + t2 * t2 * t2) - a * (a2 * a2 * a2 / 7.0 + 0.6 * a2 * a2 * t2 + a2 * t2 * t2 + t2 * t2 * t2));
240  //[[clang::fallthrough]];
241  case 6:
242  value1 += coefficients[N - 6] * (b * rootb * (8. * b2 * b2 + 26. * b2 * t2 + 33. * t2 * t2) - a * roota * (8. * a2 * a2 + 26. * a2 * t2 + 33. * t2 * t2)) / 48.;
243  value2 += coefficients[N - 6] * 15. / 48. * t2 * t2 * t2;
244  //[[clang::fallthrough]];
245  case 5:
246  value1 += coefficients[N - 5] * (b * (b2 * b2 / 5. + 2. / 3. * b2 * t2 + t2 * t2) - a * (a2 * a2 / 5. + 2. / 3. * a2 * t2 + t2 * t2));
247  //[[clang::fallthrough]];
248  case 4:
249  value1 += coefficients[N - 4] * (b * rootb * (2. * b2 + 5. * t2) - a * roota * (2. * a2 + 5. * t2)) / 8.;
250  value2 += coefficients[N - 4] * 3. / 8. * t2 * t2;
251  //[[clang::fallthrough]];
252  case 3:
253  value1 += coefficients[N - 3] * (b * (b2 / 3. + t2) - a * (a2 / 3. + t2));
254  //[[clang::fallthrough]];
255  case 2:
256  value1 += coefficients[N - 2] * (b * rootb - a * roota) / 2.;
257  value2 += coefficients[N - 2] * t2 / 2.;
258  //[[clang::fallthrough]];
259  case 1:
260  break;
261  default:
262  std::cerr << "Error: no rules set for high-order polynomials" << std::endl;
263  exit(-1);
264  }
265  double A = a / t;
266  double B = b / t;
267  double arcsinh = t < 1e-12 ? 0.0 : log(B + sqrt(1. + B * B)) - log(A + sqrt(1. + A * A));
268  //~ std::cout
269  //~ << "value1 " << value1 << std::endl
270  //~ << "value2 " << value2 << std::endl
271  //~ << "arcsinh " << arcsinh << std::endl
272  //~ << "a " << a << std::endl
273  //~ << "b " << b << std::endl
274  //~ << "t " << t << std::endl;
275  return value1 + value2 * arcsinh;
276 }
std::vector< Mdouble > coefficients
Stores the coefficients .
template<>
double NORMALIZED_POLYNOMIAL< X >::evaluateIntegral ( double  a,
double  b,
double  t 
)

Definition at line 415 of file NormalisedPolynomial.hcc.

416 {
417  return evaluateIntegral_1D(a, b, t);
418 }
Mdouble evaluateIntegral_1D(Mdouble a, Mdouble b, Mdouble t)
Returns the value of the line integral along the normal P1P2 "from a to b" over the axisymmetric func...
template<>
double NORMALIZED_POLYNOMIAL< Y >::evaluateIntegral ( double  a,
double  b,
double  t 
)

Definition at line 419 of file NormalisedPolynomial.hcc.

420 {
421  return evaluateIntegral_1D(a, b, t);
422 }
Mdouble evaluateIntegral_1D(Mdouble a, Mdouble b, Mdouble t)
Returns the value of the line integral along the normal P1P2 "from a to b" over the axisymmetric func...
template<>
double NORMALIZED_POLYNOMIAL< Z >::evaluateIntegral ( double  a,
double  b,
double  t 
)

Definition at line 423 of file NormalisedPolynomial.hcc.

424 {
425  return evaluateIntegral_1D(a, b, t);
426 }
Mdouble evaluateIntegral_1D(Mdouble a, Mdouble b, Mdouble t)
Returns the value of the line integral along the normal P1P2 "from a to b" over the axisymmetric func...
template<>
double NORMALIZED_POLYNOMIAL< XY >::evaluateIntegral ( double  a,
double  b,
double  t 
)

Definition at line 427 of file NormalisedPolynomial.hcc.

428 {
429  return evaluateIntegral_2D(a, b, t);
430 }
Mdouble evaluateIntegral_2D(Mdouble a, Mdouble b, Mdouble t)
Returns the value of the line integral along the normal P1P2 "from a to b" over the axisymmetric func...
template<>
double NORMALIZED_POLYNOMIAL< XZ >::evaluateIntegral ( double  a,
double  b,
double  t 
)

Definition at line 431 of file NormalisedPolynomial.hcc.

432 {
433  return evaluateIntegral_2D(a, b, t);
434 }
Mdouble evaluateIntegral_2D(Mdouble a, Mdouble b, Mdouble t)
Returns the value of the line integral along the normal P1P2 "from a to b" over the axisymmetric func...
template<>
double NORMALIZED_POLYNOMIAL< YZ >::evaluateIntegral ( double  a,
double  b,
double  t 
)

Definition at line 435 of file NormalisedPolynomial.hcc.

436 {
437  return evaluateIntegral_2D(a, b, t);
438 }
Mdouble evaluateIntegral_2D(Mdouble a, Mdouble b, Mdouble t)
Returns the value of the line integral along the normal P1P2 "from a to b" over the axisymmetric func...
template<StatType T>
double NORMALIZED_POLYNOMIAL< T >::evaluateIntegral_1D ( Mdouble  a,
Mdouble  b,
Mdouble  t 
)
private

Returns the value of the line integral along the normal P1P2 "from a to b" over the axisymmetric function averaged over 2 dimensions.

Definition at line 287 of file NormalisedPolynomial.hcc.

References A, and NORMALIZED_POLYNOMIAL< T >::averaged_coefficients.

288 {
289  unsigned int N = averaged_coefficients.size();
290  double value1 = averaged_coefficients[N - 1] * (b - a);
291  double value2 = 0;
292  double t2 = t * t;
293  double a2 = a * a;
294  double b2 = b * b;
295  double roota = sqrt(a * a + t2);
296  double rootb = sqrt(b * b + t2);
297  switch (N)
298  {
299  case 7:
300  value1 += averaged_coefficients[N - 7] * (b * (b2 * b2 * b2 / 7.0 + 0.6 * b2 * b2 * t2 + b2 * t2 * t2 + t2 * t2 * t2) - a * (a2 * a2 * a2 / 7.0 + 0.6 * a2 * a2 * t2 + a2 * t2 * t2 + t2 * t2 * t2));
301  //[[clang::fallthrough]];
302  case 6:
303  value1 += averaged_coefficients[N - 6] * (b * rootb * (8. * b2 * b2 + 26. * b2 * t2 + 33. * t2 * t2) - a * roota * (8. * a2 * a2 + 26. * a2 * t2 + 33. * t2 * t2)) / 48.;
304  value2 += averaged_coefficients[N - 6] * 15. / 48. * t2 * t2 * t2;
305  //[[clang::fallthrough]];
306  case 5:
307  value1 += averaged_coefficients[N - 5] * (b * (b2 * b2 / 5. + 2. / 3. * b2 * t2 + t2 * t2) - a * (a2 * a2 / 5. + 2. / 3. * a2 * t2 + t2 * t2));
308  //[[clang::fallthrough]];
309  case 4:
310  value1 += averaged_coefficients[N - 4] * (b * rootb * (2. * b2 + 5. * t2) - a * roota * (2. * a2 + 5. * t2)) / 8.;
311  value2 += averaged_coefficients[N - 4] * 3. / 8. * t2 * t2;
312  //[[clang::fallthrough]];
313  case 3:
314  value1 += averaged_coefficients[N - 3] * (b * (b2 / 3. + t2) - a * (a2 / 3. + t2));
315  //[[clang::fallthrough]];
316  case 2:
317  value1 += averaged_coefficients[N - 2] * (b * rootb - a * roota) / 2.;
318  value2 += averaged_coefficients[N - 2] * t2 / 2.;
319  //[[clang::fallthrough]];
320  case 1:
321  break;
322  default:
323  std::cerr << "Error: no rules set for high-order polynomials" << std::endl;
324  exit(-1);
325  }
326  double A = a / t;
327  double B = b / t;
328  double arcsinh = t < 1e-12 ? 0.0 : log(B + sqrt(1. + B * B)) - log(A + sqrt(1. + A * A));
329  return value1 + value2 * arcsinh;
330 
331  // 3D Heaviside: ( b-a );
332  // 3D Polynomial: evaluateIntegral(max(a,-wn)/w,min(b,wn)/w,tangential.GetLength()/w)*w;
333  // 1D Polynomial: evaluateIntegral(max(a,-wn)/w,min(b,wn)/w,tangential.GetLength()/w)*w;
334  // 1D Heaviside: ((b*pi*(wn2-mathsFunc::square(b)/3.0)))-((a*pi*(wn2-mathsFunc::square(a)/3.0)));
335  //~ averaged_coefficients[N+1] += coefficients[i]*2*pi/(N-1-i+2);
336  //~ averaged_coefficients[i] -= coefficients[i]*2*pi/(N-1-i+2);
337 
338 }
std::vector< Mdouble > averaged_coefficients
Stores some coefficients used in evaluate and evaluateIntegral for StatTypes different from XYZ...
template<StatType T>
double NORMALIZED_POLYNOMIAL< T >::evaluateIntegral_2D ( Mdouble UNUSED,
Mdouble UNUSED,
Mdouble UNUSED 
)
private

Returns the value of the line integral along the normal P1P2 "from a to b" over the axisymmetric function averaged over 1 dimensions.

Todo:
{Thomas: has yet to be implemented}

Definition at line 280 of file NormalisedPolynomial.hcc.

281 {
282  std::cerr << "evaluateIntegral_2D is not implemented yet" << std::endl;
283  exit(-1);
284 }
template<StatType T>
void NORMALIZED_POLYNOMIAL< T >::finish_set_polynomial ( )
private

Normalizes the polynomial coefficients $c_i$ such that the integral over the unit sphere of the axisymmetric function $p(r)$ is unity.

$\int_0^1 f(r) p(r) dr = 1$, with $f(r)=4\pi r^2$ for 3D, $f(r)=2\pi r$ for 2D, $f(r)=2$ for 1D systems.

Also sets averaged_coefficients

Assumes that dim and coefficients are already set.

Definition at line 45 of file NormalisedPolynomial.hcc.

References NORMALIZED_POLYNOMIAL< T >::coefficients, NORMALIZED_POLYNOMIAL< T >::get_volume(), NORMALIZED_POLYNOMIAL< T >::set_average(), and NORMALIZED_POLYNOMIAL< T >::setName().

Referenced by NORMALIZED_POLYNOMIAL< T >::set_polynomial().

46 {
47  //normalizes the Polynomial.
48  double volume = get_volume();
49  if (fabs(volume - 1.0) > 1e-12)
50  std::cout << "Warning: Polynomial has to be normalized by " << volume << std::endl;
51  for (unsigned int i = 0; i < coefficients.size(); i++)
52  coefficients[i] /= volume;
53 
54  //sets #averaged_coefficients
55  set_average();
56 
57  //std::couts the Polynomial
58  std::stringstream sstr;
59  sstr << *this;
60  setName(sstr.str().c_str());
61  std::cout << "p=" << *this << std::endl;
62 }
void setName(const char *new_name)
Use this function to change the name of the polynomial.
void set_average()
Sets averaged_coefficients.
std::vector< Mdouble > coefficients
Stores the coefficients .
Mdouble get_volume()
Returns the integral over the unit sphere of the axisymmetric function .
template<StatType T>
double NORMALIZED_POLYNOMIAL< T >::get_volume ( )
private

Returns the integral over the unit sphere of the axisymmetric function $p(r)$.

$\int_{|\vec{x}|\leq1} p(|\vec{x}|) d\vec{x} = \int_0^1 f(r) p(r) dr = 1$, with $f(r)=4\pi r^2$ for 3D, $f(r)=2\pi r$ for 2D, $f(r)=2$ for 1D systems.

For $p(r)=\sum_{i=0}^{N-1} c_i r^{N-1-i}$, we obtain $V = \sum_{i=0}^{N-1} 4\pi c_i/(2+N-i)$ for 3D, $V = \sum_{i=0}^{N-1} 2\pi c_i/(1+N-i)$ for 2D, $V = \sum_{i=0}^{N-1} 2 c_i/(N-i)$ for 1D systems.

Definition at line 65 of file NormalisedPolynomial.hcc.

References NORMALIZED_POLYNOMIAL< T >::coefficients, NORMALIZED_POLYNOMIAL< T >::dim, and constants::pi.

Referenced by NORMALIZED_POLYNOMIAL< T >::finish_set_polynomial().

66 {
67  double volume = 0;
68  unsigned int N = coefficients.size();
69  if (dim == 3)
70  {
71  for (unsigned int i = 0; i < N; i++)
72  volume += coefficients[i] / (2. + N - i);
73  volume *= 4. * constants::pi;
74  }
75  else if (dim == 2)
76  {
77  std::cerr << "dim=2 is not working yet" << std::endl;
78  exit(-1);
79  for (unsigned int i = 0; i < coefficients.size(); i++)
80  volume += coefficients[i] / (1. + N - i);
81  volume *= 2. * constants::pi;
82  }
83  else if (dim == 1)
84  {
85  std::cerr << "dim=1 is not working yet" << std::endl;
86  exit(-1);
87  for (unsigned int i = 0; i < coefficients.size(); i++)
88  volume += coefficients[i] / (0. + N - i);
89  volume *= 2.;
90  }
91  else
92  {
93  std::cerr << "Error in get_volume: dim=" << dim << std::endl;
94  exit(-1);
95  }
96  return volume;
97 }
unsigned int dim
The system dimension.
const Mdouble pi
Definition: ExtendedMath.h:42
std::vector< Mdouble > coefficients
Stores the coefficients .
template<StatType T>
std::string NORMALIZED_POLYNOMIAL< T >::getName ( )
inline

Returns name of the polynomial.

Definition at line 113 of file NormalisedPolynomial.h.

References NORMALIZED_POLYNOMIAL< T >::name.

114  {
115  return name;
116  }
std::string name
Contains the name of the polynomial which will be displayed as CGtype by the statistical code...
template<StatType T>
int NORMALIZED_POLYNOMIAL< T >::getOrder ( void  )
inline

Returns the order of the polynomial.

Definition at line 148 of file NormalisedPolynomial.h.

References NORMALIZED_POLYNOMIAL< T >::coefficients.

149  {
150  return coefficients.size() - 1;
151  }
std::vector< Mdouble > coefficients
Stores the coefficients .
template<StatType T>
Mdouble NORMALIZED_POLYNOMIAL< T >::operator[] ( int  i) const
inlineprivate

Access to the coefficients.

Definition at line 247 of file NormalisedPolynomial.h.

References NORMALIZED_POLYNOMIAL< T >::coefficients.

248  {
249  return coefficients[i];
250  }
std::vector< Mdouble > coefficients
Stores the coefficients .
template<StatType T>
void NORMALIZED_POLYNOMIAL< T >::set_average ( )
private

Sets averaged_coefficients.

This function is templated, with the default used only for StatType=XYZ, so it does nothing.

Definition at line 100 of file NormalisedPolynomial.hcc.

Referenced by NORMALIZED_POLYNOMIAL< T >::finish_set_polynomial().

101 {
102  std::cout << "set_average" << std::endl;
103 }
template<>
void NORMALIZED_POLYNOMIAL< X >::set_average ( )
private

Definition at line 340 of file NormalisedPolynomial.hcc.

341 {
342  set_average_1D();
343 }
void set_average_1D()
Sets averaged_coefficients for StatType=X,Y,Z such that . See evaluate_1D.
template<>
void NORMALIZED_POLYNOMIAL< Y >::set_average ( )
private

Definition at line 344 of file NormalisedPolynomial.hcc.

345 {
346  set_average_1D();
347 }
void set_average_1D()
Sets averaged_coefficients for StatType=X,Y,Z such that . See evaluate_1D.
template<>
void NORMALIZED_POLYNOMIAL< Z >::set_average ( )
private

Definition at line 348 of file NormalisedPolynomial.hcc.

349 {
350  set_average_1D();
351 }
void set_average_1D()
Sets averaged_coefficients for StatType=X,Y,Z such that . See evaluate_1D.
template<>
void NORMALIZED_POLYNOMIAL< XY >::set_average ( )
private

Definition at line 352 of file NormalisedPolynomial.hcc.

353 {
354  set_average_2D();
355 }
void set_average_2D()
For StatType=XY,XZ,XZ, averaged_coefficients is not used since can be evaluated as a function of ...
template<>
void NORMALIZED_POLYNOMIAL< XZ >::set_average ( )
private

Definition at line 356 of file NormalisedPolynomial.hcc.

357 {
358  set_average_2D();
359 }
void set_average_2D()
For StatType=XY,XZ,XZ, averaged_coefficients is not used since can be evaluated as a function of ...
template<>
void NORMALIZED_POLYNOMIAL< YZ >::set_average ( )
private

Definition at line 360 of file NormalisedPolynomial.hcc.

361 {
362  set_average_2D();
363 }
void set_average_2D()
For StatType=XY,XZ,XZ, averaged_coefficients is not used since can be evaluated as a function of ...
template<StatType T>
void NORMALIZED_POLYNOMIAL< T >::set_average_1D ( )
private

Sets averaged_coefficients $\bar{c}_i$ for StatType=X,Y,Z such that $\sum_{i=0}^N \bar{c}_i x^{N-i} = \int\int_{|\vec{x}|\leq 1} p(|\vec{x}|) dy dz$. See evaluate_1D.

Definition at line 106 of file NormalisedPolynomial.hcc.

References NORMALIZED_POLYNOMIAL< T >::averaged_coefficients, NORMALIZED_POLYNOMIAL< T >::coefficients, and constants::pi.

107 {
108  std::cout << "set_average_1D" << std::endl;
109  unsigned int N = coefficients.size();
110  averaged_coefficients.resize(N + 2);
111  for (unsigned int i = 0; i < N + 2; i++)
112  {
113  averaged_coefficients[i] = 0;
114  }
115  for (unsigned int i = 0; i < N; i++)
116  {
117  averaged_coefficients[N + 1] += coefficients[i] * 2 * constants::pi / (N - 1 - i + 2);
118  averaged_coefficients[i] -= coefficients[i] * 2 * constants::pi / (N - 1 - i + 2);
119  }
120 }
const Mdouble pi
Definition: ExtendedMath.h:42
std::vector< Mdouble > averaged_coefficients
Stores some coefficients used in evaluate and evaluateIntegral for StatTypes different from XYZ...
std::vector< Mdouble > coefficients
Stores the coefficients .
template<StatType T>
void NORMALIZED_POLYNOMIAL< T >::set_average_2D ( )
private

For StatType=XY,XZ,XZ, averaged_coefficients is not used since $\bar{p}(r)$ can be evaluated as a function of $c_i$. See evaluate_2D.

Definition at line 124 of file NormalisedPolynomial.hcc.

125 {
126 }
template<StatType T>
void NORMALIZED_POLYNOMIAL< T >::set_polynomial ( std::vector< Mdouble new_coefficients,
unsigned int  new_dim 
)

Use this function to set the polynomial coefficients $c_i$. This function calls finish_set_polynomial to normalize the coefficients.

Definition at line 27 of file NormalisedPolynomial.hcc.

References NORMALIZED_POLYNOMIAL< T >::coefficients, NORMALIZED_POLYNOMIAL< T >::dim, and NORMALIZED_POLYNOMIAL< T >::finish_set_polynomial().

28 {
29  coefficients = new_coefficients;
30  dim = new_dim;
32 }
unsigned int dim
The system dimension.
void finish_set_polynomial()
Normalizes the polynomial coefficients such that the integral over the unit sphere of the axisymmetr...
std::vector< Mdouble > coefficients
Stores the coefficients .
template<StatType T>
void NORMALIZED_POLYNOMIAL< T >::set_polynomial ( Mdouble new_coefficients,
unsigned int  num_coeff,
unsigned int  new_dim 
)

Some as set_polynomial, but avoids the use of a vector.

Definition at line 35 of file NormalisedPolynomial.hcc.

References NORMALIZED_POLYNOMIAL< T >::coefficients, NORMALIZED_POLYNOMIAL< T >::dim, and NORMALIZED_POLYNOMIAL< T >::finish_set_polynomial().

36 {
37  coefficients.resize(num_coeff);
38  for (unsigned int i = 0; i < num_coeff; i++)
39  coefficients[i] = new_coefficients[i];
40  dim = new_dim;
42 }
unsigned int dim
The system dimension.
void finish_set_polynomial()
Normalizes the polynomial coefficients such that the integral over the unit sphere of the axisymmetr...
std::vector< Mdouble > coefficients
Stores the coefficients .
template<StatType T>
void NORMALIZED_POLYNOMIAL< T >::setName ( const char *  new_name)
inline

Use this function to change the name of the polynomial.

Definition at line 105 of file NormalisedPolynomial.h.

References NORMALIZED_POLYNOMIAL< T >::name.

Referenced by NORMALIZED_POLYNOMIAL< T >::finish_set_polynomial(), and NORMALIZED_POLYNOMIAL< T >::NORMALIZED_POLYNOMIAL().

106  {
107  name = new_name;
108  }
std::string name
Contains the name of the polynomial which will be displayed as CGtype by the statistical code...

Friends And Related Function Documentation

template<StatType T>
std::ostream& operator<< ( std::ostream &  os,
const NORMALIZED_POLYNOMIAL< T > &  P 
)
friend

Returns a text description of the polynomial.

Definition at line 156 of file NormalisedPolynomial.h.

157  {
158  unsigned int N = P.coefficients.size();
159  for (unsigned int i = 0; i < N; i++)
160  {
161  if (P[i]==0.0)
162  continue;
163  if (P[i] >= 0)
164  os << "+";
165  os << std::setprecision(2) << P[i];
166  if (N - 1 - i > 1)
167  os << "r^" << N - 1 - i;
168  else if (N - 1 - i == 1)
169  os << "r";
170  }
171  return os;
172  }
std::vector< Mdouble > coefficients
Stores the coefficients .

Member Data Documentation

template<StatType T>
std::vector<Mdouble> NORMALIZED_POLYNOMIAL< T >::averaged_coefficients
private

Stores some coefficients used in evaluate and evaluateIntegral for StatTypes different from XYZ.

Definition at line 76 of file NormalisedPolynomial.h.

Referenced by NORMALIZED_POLYNOMIAL< T >::evaluate_1D(), NORMALIZED_POLYNOMIAL< T >::evaluateIntegral_1D(), and NORMALIZED_POLYNOMIAL< T >::set_average_1D().

template<StatType T>
unsigned int NORMALIZED_POLYNOMIAL< T >::dim
private
template<StatType T>
std::string NORMALIZED_POLYNOMIAL< T >::name
private

Contains the name of the polynomial which will be displayed as CGtype by the statistical code.

Definition at line 61 of file NormalisedPolynomial.h.

Referenced by NORMALIZED_POLYNOMIAL< T >::getName(), and NORMALIZED_POLYNOMIAL< T >::setName().


The documentation for this class was generated from the following files: