28 coefficients = new_coefficients;
30 finish_set_polynomial();
35 coefficients.resize(num_coeff);
36 for (
unsigned int i=0; i<num_coeff; i++)
37 coefficients[i] = new_coefficients[i];
39 finish_set_polynomial();
45 double volume = get_volume();
46 if (fabs(volume-1.0)>1e-12)
47 std::cout <<
"Warning: Polynomial has to be normalized by " << volume << std::endl;
48 for (
unsigned int i=0; i<coefficients.size(); i++)
49 coefficients[i] /= volume;
55 std::stringstream sstr;
57 set_name(sstr.str().c_str());
58 std::cout <<
"p=" << *
this << std::endl;
64 unsigned int N = coefficients.size();
66 for (
unsigned int i=0; i<N; i++)
67 volume += coefficients[i]/(2.+N-i);
70 std::cerr <<
"dim=2 is not working yet" << std::endl; exit(-1);
71 for (
unsigned int i=0; i<coefficients.size(); i++)
72 volume += coefficients[i]/(1.+N-i);
75 std::cerr <<
"dim=1 is not working yet" << std::endl; exit(-1);
76 for (
unsigned int i=0; i<coefficients.size(); i++)
77 volume += coefficients[i]/(0.+N-i);
80 std::cerr <<
"Error in get_volume: dim=" << dim << std::endl; exit(-1);
90 std::cout <<
"set_average_1D" << std::endl;
91 unsigned int N = coefficients.size();
92 averaged_coefficients.resize(N+2);
93 for (
unsigned int i=0; i<N+2; i++) {
94 averaged_coefficients[i] = 0;
96 for (
unsigned int i=0; i<N; i++) {
97 averaged_coefficients[N+1] += coefficients[i]*2*
constants::pi/(N-1-i+2);
98 averaged_coefficients[i] -= coefficients[i]*2*
constants::pi/(N-1-i+2);
103 template <StatType T>
108 template <StatType T>
110 unsigned int N = coefficients.size();
111 double value = coefficients[0];
112 for (
unsigned int i=1; i<N; i++)
113 value = value*r+coefficients[i];
119 template <StatType T>
121 unsigned int N = coefficients.size();
122 double value = (N-1)*coefficients[0];
123 for (
unsigned int i=1; i<N-1; i++)
124 value = value*r+(N-1-i)*coefficients[i];
128 template <StatType T>
130 unsigned int N = averaged_coefficients.size();
131 double value = averaged_coefficients[0];
132 for (
unsigned int i=1; i<N; i++)
133 value = value*r+averaged_coefficients[i];
137 template <StatType T>
139 unsigned int N = coefficients.size();
140 double value = coefficients[0];
141 double value2 = coefficients[0];
142 for (
unsigned int i=1; i<N-1; i++) {
143 value = value*r+coefficients[i];
144 value2 += coefficients[i];
149 template <StatType T>
156 template <StatType T>
159 unsigned int N = coefficients.size();
160 double value1 = 2.*coefficients[N-1];
165 value1 += coefficients[N-7]*2./35.*(5.+r2*(6.+r2*(8*r2+16)));
167 value1 += coefficients[N-6]*(8.+(10.+15.*r2)*r2)/24.;
168 value2 += coefficients[N-6]*(15.*r2*r2*r2)/24.;
170 value1 += coefficients[N-5]*.4*(1.+r2*(4./3.+r2*8./3.));
172 value1 += coefficients[N-4]*(2.+r2*3.)/4.;
173 value2 += coefficients[N-4]*.75*r2*r2;
175 value1 += coefficients[N-3]*2./3.*(1.+r2*2.);
177 value1 += coefficients[N-2]*1.;
178 value2 += coefficients[N-2]*r2;
182 std::cerr <<
"Error: no rules set for high-order polynomials" << std::endl; exit(-1);
184 double root = sqrt(1-r2);
185 double invz = root/r;
186 double arccsch = log(sqrt(1.+invz*invz)+invz);
187 return value1*root+value2*arccsch;
190 template <StatType T>
192 unsigned int N = coefficients.size();
193 double value1 = coefficients[N-1]*(b-a);
198 double roota = sqrt(a*a+t2);
199 double rootb = sqrt(b*b+t2);
202 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));
204 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.;
205 value2 += coefficients[N-6]*15./48.*t2*t2*t2;
207 value1 += coefficients[N-5]*(b*(b2*b2/5.+2./3.*b2*t2+t2*t2)-a*(a2*a2/5.+2./3.*a2*t2+t2*t2));
209 value1 += coefficients[N-4]*(b*rootb*(2.*b2+5.*t2)-a*roota*(2.*a2+5.*t2))/8.;
210 value2 += coefficients[N-4]*3./8.*t2*t2;
212 value1 += coefficients[N-3]*(b*(b2/3.+t2)-a*(a2/3.+t2));
214 value1 += coefficients[N-2]*(b*rootb-a*roota)/2.;
215 value2 += coefficients[N-2]*t2/2.;
219 std::cerr <<
"Error: no rules set for high-order polynomials" << std::endl; exit(-1);
223 double arcsinh = t<1e-12 ? 0.0 : log(B+sqrt(1.+B*B))-log(A+sqrt(1.+A*A));
231 return value1+value2*arcsinh;
235 template <StatType T>
237 std::cerr <<
"evaluateIntegral_2D is not implemented yet" << std::endl;
241 template <StatType T>
243 unsigned int N = averaged_coefficients.size();
244 double value1 = averaged_coefficients[N-1]*(b-a);
249 double roota = sqrt(a*a+t2);
250 double rootb = sqrt(b*b+t2);
253 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));
255 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.;
256 value2 += averaged_coefficients[N-6]*15./48.*t2*t2*t2;
258 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));
260 value1 += averaged_coefficients[N-4]*(b*rootb*(2.*b2+5.*t2)-a*roota*(2.*a2+5.*t2))/8.;
261 value2 += averaged_coefficients[N-4]*3./8.*t2*t2;
263 value1 += averaged_coefficients[N-3]*(b*(b2/3.+t2)-a*(a2/3.+t2));
265 value1 += averaged_coefficients[N-2]*(b*rootb-a*roota)/2.;
266 value2 += averaged_coefficients[N-2]*t2/2.;
270 std::cerr <<
"Error: no rules set for high-order polynomials" << std::endl; exit(-1);
274 double arcsinh = t<1e-12 ? 0.0 : log(B+sqrt(1.+B*B))-log(A+sqrt(1.+A*A));
275 return value1+value2*arcsinh;
Mdouble evaluate_2D(Mdouble r)
Returns the value of the polynomial averaged over 1 dimension.
Mdouble evaluateGradient_1D(Mdouble r)
Returns the value of the gradient averaged over 2 dimensions.
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 evaluateGradient_2D(Mdouble r)
Returns the value of the gradient averaged over 1 dimensions.
void set_average()
Sets averaged_coefficients.
void finish_set_polynomial()
Normalizes the polynomial coefficients such that the integral over the unit sphere of the axisymmetr...
void set_polynomial(std::vector< Mdouble > new_coefficients, unsigned int new_dim)
Use this function to set the polynomial coefficients .
void set_average_1D()
Sets averaged_coefficients for StatType=X,Y,Z such that .
void set_average_2D()
For StatType=XY,XZ,XZ, averaged_coefficients is not used since can be evaluated as a function of ...
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_1D(Mdouble r)
Returns the value of the polynomial averaged over 2 dimensions.
Mdouble evaluateGradient(Mdouble r)
Returns the gradient of the polynomial, .
Mdouble get_volume()
Returns the integral over the unit sphere of the axisymmetric function .
Mdouble evaluate(Mdouble r)
Returns the value of the polynomial, .
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...