MercuryDPM  0.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Polynomial.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 
51 template <StatType T>
53 {
54 
55 //definition of member variables
56 
57 private:
58 
60  std::string name;
61 
63  unsigned int dim;
64 
66  std::vector<Mdouble> coefficients; //starting with the highest order
67 
69  std::vector<Mdouble> averaged_coefficients;
70 
71 //definition of member functions
72 
73 public:
74 
77  set_name("Polynomial");
78  coefficients.resize(0);
79  dim = 0;
80  }
81 
84  void set_polynomial(std::vector<Mdouble> new_coefficients, unsigned int new_dim);
85 
87  void set_polynomial(Mdouble* new_coefficients, unsigned int num_coeff, unsigned int new_dim);
88 
90  void set_name(const char* new_name) {name = new_name;}
91 
93  std::string get_name() {return name;}
94 
107 
110 
115 
117  int get_Order (void) {
118  return coefficients.size()-1;
119  }
120 
122  friend inline std::ostream& operator<<(std::ostream& os, const NORMALIZED_POLYNOMIAL &P) {
123  unsigned int N = P.coefficients.size();
124  for (unsigned int i=0; i<N; i++) {
125  if (!P[i]) continue;
126  if (P[i]>=0) os << "+";
127  os << std::setprecision(2) << P[i];
128  if (N-1-i>1) os << "r^" << N-1-i;
129  else if (N-1-i==1) os << "r";
130  }
131  return os;
132  }
133 
134 private:
146  void finish_set_polynomial();
147 
159 
163 
167 
170  void set_average();
171 
174  void set_average_1D();
175 
178  void set_average_2D();
179 
182 
185 
188 
191 
193  Mdouble operator[](int i) const {
194  return coefficients[i];
195  }
196 
197 };
198 #include "Polynomial.hcc"
199 #endif
200 
int get_Order(void)
Returns the order of the polynomial.
Definition: Polynomial.h:117
std::string name
Contains the name of the polynomial which will be displayed as CGtype by the statistical code...
Definition: Polynomial.h:60
Mdouble evaluate_2D(Mdouble r)
Returns the value of the polynomial averaged over 1 dimension.
Definition: Polynomial.hcc:157
Mdouble evaluateGradient_1D(Mdouble r)
Returns the value of the gradient averaged over 2 dimensions.
Definition: Polynomial.hcc:138
Mdouble operator[](int i) const
Access to the coefficients.
Definition: Polynomial.h:193
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...
Definition: Polynomial.hcc:191
Mdouble evaluateGradient_2D(Mdouble r)
Returns the value of the gradient averaged over 1 dimensions.
Definition: Polynomial.hcc:150
unsigned int dim
The system dimension.
Definition: Polynomial.h:63
void set_average()
Sets averaged_coefficients.
Definition: Polynomial.hcc:86
void finish_set_polynomial()
Normalizes the polynomial coefficients such that the integral over the unit sphere of the axisymmetr...
Definition: Polynomial.hcc:43
void set_polynomial(std::vector< Mdouble > new_coefficients, unsigned int new_dim)
Use this function to set the polynomial coefficients .
Definition: Polynomial.hcc:27
double Mdouble
Definition: ExtendedMath.h:33
void set_average_1D()
Sets averaged_coefficients for StatType=X,Y,Z such that .
Definition: Polynomial.hcc:89
NORMALIZED_POLYNOMIAL()
Basic constructor; note that this does not determine the particular polynomial; one needs to call set...
Definition: Polynomial.h:76
void set_average_2D()
For StatType=XY,XZ,XZ, averaged_coefficients is not used since can be evaluated as a function of ...
Definition: Polynomial.hcc:104
std::string get_name()
Returns name of the polynomial.
Definition: Polynomial.h:93
std::vector< Mdouble > averaged_coefficients
Stores some coefficients used in evaluate and evaluateIntegral for StatTypes different from XYZ...
Definition: Polynomial.h:69
friend std::ostream & operator<<(std::ostream &os, const NORMALIZED_POLYNOMIAL &P)
Returns a text description of the polynomial.
Definition: Polynomial.h:122
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...
Definition: Polynomial.hcc:242
void set_name(const char *new_name)
Use this function to change the name of the polynomial.
Definition: Polynomial.h:90
Mdouble evaluate_1D(Mdouble r)
Returns the value of the polynomial averaged over 2 dimensions.
Definition: Polynomial.hcc:129
Mdouble evaluateGradient(Mdouble r)
Returns the gradient of the polynomial, .
Definition: Polynomial.hcc:120
This class is used to define polynomial axisymmetric coarse-graining functions.
Definition: Polynomial.h:52
std::vector< Mdouble > coefficients
Stores the coefficients .
Definition: Polynomial.h:66
Mdouble get_volume()
Returns the integral over the unit sphere of the axisymmetric function .
Definition: Polynomial.hcc:62
Mdouble evaluate(Mdouble r)
Returns the value of the polynomial, .
Definition: Polynomial.hcc:109
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...
Definition: Polynomial.hcc:236