MercuryDPM  Alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
NormalisedPolynomial.h
Go to the documentation of this file.
1 //Copyright (c) 2013-2014, 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 POLY_H
27 #define 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:
183  void finish_set_polynomial();
184 
195 
200 
205 
210  void set_average();
211 
216  void set_average_1D();
217 
222  void set_average_2D();
223 
228 
233 
238 
243 
247  Mdouble operator[](int i) const
248  {
249  return coefficients[i];
250  }
251 
252 };
253 #include "NormalisedPolynomial.hcc"
254 #endif
255 
void setName(const char *new_name)
Use this function to change the name of the polynomial.
Mdouble evaluateGradient_2D(Mdouble r)
Returns the value of the gradient averaged over 1 dimensions.
std::string name
Contains the name of the polynomial which will be displayed as CGtype by the statistical code...
Mdouble get_volume()
Returns the integral over the unit sphere of the axisymmetric function .
Mdouble operator[](int i) const
Access to the coefficients.
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 evaluate_2D(Mdouble r)
Returns the value of the polynomial averaged over 1 dimension. For StatType=XY, . ...
double Mdouble
unsigned int dim
The system dimension.
void set_average()
Sets averaged_coefficients.
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...
Mdouble evaluate_1D(Mdouble r)
Returns the value of the polynomial averaged over 2 dimensions. For StatType=X, . See also set_averag...
void finish_set_polynomial()
Normalizes the polynomial coefficients such that the integral over the unit sphere of the axisymmetr...
Mdouble evaluateGradient_1D(Mdouble r)
Returns the value of the gradient averaged over 2 dimensions.
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...
void set_average_1D()
Sets averaged_coefficients for StatType=X,Y,Z such that . See evaluate_1D.
NORMALIZED_POLYNOMIAL()
Basic constructor; note that this does not determine the particular polynomial; one needs to call set...
void set_average_2D()
For StatType=XY,XZ,XZ, averaged_coefficients is not used since can be evaluated as a function of ...
std::vector< Mdouble > averaged_coefficients
Stores some coefficients used in evaluate and evaluateIntegral for StatTypes different from XYZ...
friend std::ostream & operator<<(std::ostream &os, const NORMALIZED_POLYNOMIAL &P)
Returns a text description of the polynomial.
std::string getName()
Returns name of the polynomial.
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...
Mdouble evaluate(Mdouble r)
Returns the value of the polynomial, .
This class is used to define polynomial axisymmetric coarse-graining functions.
std::vector< Mdouble > coefficients
Stores the coefficients .
int getOrder(void)
Returns the order of the polynomial.
Mdouble evaluateGradient(Mdouble r)
Returns the gradient of the polynomial, .