NormalisedPolynomial.h
Go to the documentation of this file.
1 //Copyright (c) 2013-2023, The MercuryDPM Developers Team. All rights reserved.
2 //For the list of developers, see <http://www.MercuryDPM.org/Team>.
3 //
4 //Redistribution and use in source and binary forms, with or without
5 //modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name MercuryDPM nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 //
15 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 //ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 //WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 //DISCLAIMED. IN NO EVENT SHALL THE MERCURYDPM DEVELOPERS TEAM BE LIABLE FOR ANY
19 //DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 //ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 //(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 #ifndef MECURYDPM_POLY_H
27 #define MECURYDPM_POLY_H
28 
29 #include <cmath>
30 #include <sstream>
31 #include <iomanip> //
32 
50 template<StatType T>
52 {
53 
54 //definition of member variables
55 
56 private:
57 
61  std::string name;
62 
66  unsigned int dim;
67 
71  std::vector<Mdouble> coefficients; //starting with the highest order
72 
76  std::vector<Mdouble> averaged_coefficients;
77 
78 //definition of member functions
79 
80 public:
81 
86  {
87  setName("Polynomial");
88  coefficients.resize(0);
89  dim = 0;
90  }
91 
95  void set_polynomial(std::vector<Mdouble> new_coefficients, unsigned int new_dim);
96 
100  void set_polynomial(Mdouble* new_coefficients, unsigned int num_coeff, unsigned int new_dim);
101 
105  void setName(const char* new_name)
106  {
107  name = new_name;
108  }
109 
113  std::string getName()
114  {
115  return name;
116  }
117 
131 
136 
144 
148  int getOrder(void)
149  {
150  return coefficients.size() - 1;
151  }
152 
156  friend inline std::ostream& operator<<(std::ostream& os, const NORMALIZED_POLYNOMIAL& P)
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  }
173 
174 private:
184 
195 
200 
205 
210  void set_average();
211 
217 
223 
228 
233 
238 
243 
247  Mdouble operator[](int i) const
248  {
249  return coefficients[i];
250  }
251 
252 };
253 
254 #include "NormalisedPolynomial.hcc"
255 
256 #endif
257 
This class is used to define polynomial axisymmetric coarse-graining functions.
Definition: NormalisedPolynomial.h:52
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:247
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:85
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:148
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:156
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:113
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:66
Mdouble evaluate(Mdouble r)
Returns the value of the polynomial, .
std::vector< Mdouble > coefficients
Stores the coefficients .
Definition: NormalisedPolynomial.h:71
void setName(const char *new_name)
Use this function to change the name of the polynomial.
Definition: NormalisedPolynomial.h:105
std::vector< Mdouble > averaged_coefficients
Stores some coefficients used in evaluate and evaluateIntegral for StatTypes different from XYZ.
Definition: NormalisedPolynomial.h:76
std::string name
Contains the name of the polynomial which will be displayed as CGtype by the statistical code.
Definition: NormalisedPolynomial.h:61
double P
Uniform pressure.
Definition: TwenteMeshGluing.cpp:73
const std::complex< Mdouble > i
Definition: ExtendedMath.h:51