NormalisedPolynomial.h
Go to the documentation of this file.
1 // This file is part of the MercuryDPM project (https://www.mercurydpm.org).
2 // Copyright (c), The MercuryDPM Developers Team. All rights reserved.
3 // License: BSD 3-Clause License; see the LICENSE file in the root directory.
4 
5 #ifndef MECURYDPM_POLY_H
6 #define MECURYDPM_POLY_H
7 
8 #include <cmath>
9 #include <sstream>
10 #include <iomanip> //
11 
29 template<StatType T>
31 {
32 
33 //definition of member variables
34 
35 private:
36 
41 
45  unsigned int dim;
46 
50  std::vector<Mdouble> coefficients; //starting with the highest order
51 
55  std::vector<Mdouble> averaged_coefficients;
56 
57 //definition of member functions
58 
59 public:
60 
65  {
66  setName("Polynomial");
67  coefficients.resize(0);
68  dim = 0;
69  }
70 
74  void set_polynomial(std::vector<Mdouble> new_coefficients, unsigned int new_dim);
75 
79  void set_polynomial(Mdouble* new_coefficients, unsigned int num_coeff, unsigned int new_dim);
80 
84  void setName(const char* new_name)
85  {
86  name = new_name;
87  }
88 
93  {
94  return name;
95  }
96 
110 
115 
123 
127  int getOrder(void)
128  {
129  return coefficients.size() - 1;
130  }
131 
135  friend inline std::ostream& operator<<(std::ostream& os, const NORMALIZED_POLYNOMIAL& P)
136  {
137  unsigned int N = P.coefficients.size();
138  for (unsigned int i = 0; i < N; i++)
139  {
140  if (P[i] == 0.0)
141  continue;
142  if (P[i] >= 0)
143  os << "+";
144  os << std::setprecision(2) << P[i];
145  if (N - 1 - i > 1)
146  os << "r^" << N - 1 - i;
147  else if (N - 1 - i == 1)
148  os << "r";
149  }
150  return os;
151  }
152 
153 private:
163 
174 
179 
184 
189  void set_average();
190 
196 
202 
207 
212 
217 
222 
226  Mdouble operator[](int i) const
227  {
228  return coefficients[i];
229  }
230 
231 };
232 
233 #include "NormalisedPolynomial.hcc"
234 
235 #endif
236 
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Scalar * b
Definition: benchVecAdd.cpp:17
This class is used to define polynomial axisymmetric coarse-graining functions.
Definition: NormalisedPolynomial.h:31
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 func...
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.
Mdouble operator[](int i) const
Access to the coefficients.
Definition: NormalisedPolynomial.h:226
Mdouble evaluate_2D(Mdouble r)
Returns the value of the polynomial averaged over 1 dimension. For StatType=XY, .
NORMALIZED_POLYNOMIAL()
Basic constructor; note that this does not determine the particular polynomial; one needs to call set...
Definition: NormalisedPolynomial.h:64
Mdouble get_volume()
Returns the integral over the unit sphere of the axisymmetric function .
Mdouble evaluateGradient_2D(Mdouble r)
Returns the value of the gradient averaged over 1 dimensions.
int getOrder(void)
Returns the order of the polynomial.
Definition: NormalisedPolynomial.h:127
Mdouble evaluateGradient_1D(Mdouble r)
Returns the value of the gradient averaged over 2 dimensions.
friend std::ostream & operator<<(std::ostream &os, const NORMALIZED_POLYNOMIAL &P)
Returns a text description of the polynomial.
Definition: NormalisedPolynomial.h:135
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...
Mdouble evaluateGradient(Mdouble r)
Returns the gradient of the polynomial, .
void set_average_1D()
Sets averaged_coefficients for StatType=X,Y,Z such that . See evaluate_1D.
void finish_set_polynomial()
Normalizes the polynomial coefficients such that the integral over the unit sphere of the axisymmetr...
std::string getName()
Returns name of the polynomial.
Definition: NormalisedPolynomial.h:92
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...
void set_average_2D()
For StatType=XY,XZ,XZ, averaged_coefficients is not used since can be evaluated as a function of ....
void set_average()
Sets averaged_coefficients.
Mdouble evaluate_1D(Mdouble r)
Returns the value of the polynomial averaged over 2 dimensions. For StatType=X, . See also set_averag...
void set_polynomial(std::vector< Mdouble > new_coefficients, unsigned int new_dim)
Use this function to set the polynomial coefficients . This function calls finish_set_polynomial to n...
unsigned int dim
The system dimension.
Definition: NormalisedPolynomial.h:45
Mdouble evaluate(Mdouble r)
Returns the value of the polynomial, .
std::vector< Mdouble > coefficients
Stores the coefficients .
Definition: NormalisedPolynomial.h:50
void setName(const char *new_name)
Use this function to change the name of the polynomial.
Definition: NormalisedPolynomial.h:84
std::vector< Mdouble > averaged_coefficients
Stores some coefficients used in evaluate and evaluateIntegral for StatTypes different from XYZ.
Definition: NormalisedPolynomial.h:55
std::string name
Contains the name of the polynomial which will be displayed as CGtype by the statistical code.
Definition: NormalisedPolynomial.h:40
@ N
Definition: constructor.cpp:22
const Scalar * a
Definition: level2_cplx_impl.h:32
double P
Uniform pressure.
Definition: TwenteMeshGluing.cpp:77
r
Definition: UniformPSDSelfTest.py:20
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286
t
Definition: plotPSD.py:36