27 if(alpha <= -1.0L) alpha = 0.0L;
28 if(beta <= -1.0L) beta = 0.0L;
35 PZError <<
"TPZGaussRule criation, order = " << order <<
" not allowable\n";
45 fOrder = ComputingGaussLobattoQuadrature(order);
49 if(
IsZero(fAlpha) &&
IsZero(fBeta)) fAlpha = fBeta = 1.0L;
51 fOrder = ComputingGaussJacobiQuadrature(order,fAlpha,fBeta);
54 fAlpha = fBeta = -0.5L;
55 fOrder = ComputingGaussChebyshevQuadrature(order);
59 fOrder = ComputingGaussLegendreQuadrature(order);
67 fWeight(copy.fWeight), fAlpha(copy.fAlpha), fBeta(copy.fBeta), fOrder(copy.fOrder)
100 PZError <<
"ERROR(TPZGaussRule::loc) Out of bounds!!\n";
111 PZError <<
"ERROR(TPZGaussRule::w) Out of bounds!!\n";
118 out <<
"\nGaussian Quadrature ";
119 if(!
fType) out <<
"(Legendre) : " << std::endl;
120 else if(
fType == 1) out <<
"(Lobatto) : " << std::endl;
121 else if(
fType == 2) out <<
"(Jacobi) : " << std::endl;
122 else if(
fType == 3) out <<
"(Chebyshev) : " << std::endl;
123 else out <<
"(Unkown) : " << std::endl;
124 out <<
"\nNumber of points : " <<
fNumInt << std::endl;
132 if(order < 0) order = 1;
133 if(type < 0 || type > 3) type = 0;
172 fNumInt = (int)(0.51*(order+2));
185 long double z1, z, pp, p3, p2, p1, dif, den;
192 Location.
Resize((*npoints),0.0L);
193 Weight.
Resize((*npoints),0.0L);
195 int m = ((*npoints)+1)/2;
199 p1 = ((
long double)(i))+(0.75L);
200 p2 = ((
long double)((*npoints)))+0.5L;
201 z = cosl((M_PI*p1)/p2);
207 for(j=0;j<(*npoints);j++) {
210 p1 = (((2.0L)*((
long double)(j))+(1.0L))*z*p2-(((
long double)(j))*p3))/(((
long double)(j))+(1.0L));
213 if(
fabs(den)<1.e-16L)
215 pp = ((
long double)(*npoints))*(z*p1-p2)/den;
225 std::cout <<
"Reached maxime number of iterations for NPOINTS = " << (*npoints) <<
".\n";
232 weight = 2.0L/((1.0L-z*z)*pp*pp);
234 Weight[2*i] = weight;
235 if((2*i+1)<(*npoints)) {
237 Weight[2*i+1] = weight;
244 fNumInt = (int)(0.51*(order+2));
255 fLocation[i] = cosl(M_PI*(
long double)(i+0.5L)/((
long double)(fNumInt)));
256 fWeight[i] = M_PI/((
long double)(fNumInt));
266 int v, a1, a2, a3, a4;
270 if(n==0)
return p[0];
271 p[1] = (((
long double)(alpha+beta+2.0L))*x + ((
long double)(alpha-beta)))/2.0L;
272 if(n==1)
return p[1];
274 for(
unsigned int i=1; i<=(n-1); ++i) {
275 v = 2*i + alpha + beta;
276 a1 = 2*(i+1)*(i + alpha + beta + 1)*v;
277 a2 = (v + 1)*(alpha*alpha - beta*beta);
278 a3 = v*(v + 1)*(v + 2);
279 a4 = 2*(i+alpha)*(i+beta)*(v + 2);
281 p[i+1] =
static_cast<long double>( (((
long double)(a2)) + ((
long double)(a3))*x)*p[i] - ((
long double)(a4))*p[i-1])/((
long double)(a1));
290 fNumInt = (int)(0.51*(order+2));
308 unsigned int counter = 0;
312 const long double eps = 1.09e-19L;
313 long double deps = 2.23e-16L;
317 const long double tol = ((1.L + eps) != 1.L ? max(deps/(100.0L), eps*5.0L) : deps*5.0L);
322 fLocation[i] = - cosl(((2.0L*((
long double)(i))+1.0L)/(2.0L*((
long double)(m))))*M_PI);
324 long double r, s, J_x,
f, delta;
337 delta = f/(f*s- J_x);
347 cout <<
"Maxime number of iterations allowed in quadrature GaussLobatto. \n" ;
355 for(ii=m-1;ii>-1;ii--)
366 const long double factor = 2.L*f*f / (((
long double)(
fNumInt-1))*f*r);
381 fNumInt = (int)(0.51*(order+2));
395 long double cc, delta, dp2;
397 long double p1, prod, r1, r2, r3, temp, x0 = 0.0;
399 Location.
Resize((*npoints),0.0L);
400 Weight.
Resize((*npoints),0.0L);
402 b.
Resize((*npoints),0.0L);
403 c.
Resize((*npoints),0.0L);
407 std::cerr <<
"\nJACOBI_COMPUTE - Fatal error!\n -1.0 < ALPHA is required.\n";
411 std::cerr <<
"\nJACOBI_COMPUTE - Fatal error!\n -1.0 < BETA is required.\n";
416 for(i=1;i<=(*npoints);i++) {
417 if(alpha + beta == 0.0L || beta - alpha == 0.0L) {
421 b[i-1] = ( alpha + beta ) * ( beta - alpha ) /
422 ( ( alpha + beta + ( 2.0L * ((
long double)(i)) ) )
423 * ( alpha + beta + ( 2.0L * ((
long double)(i)) - 2.0L ) ) );
429 c[i-1] = 4.0L * ( ((
long double)(i)) - 1.0L ) * ( alpha + ( ((
long double)(i)) - 1.0L ) ) * ( beta + ( ((
long double)(i)) - 1.0L ) )
430 * ( alpha + beta + ( ((
long double)(i)) - 1.0L ) ) /
431 ( ( alpha + beta + ( 2.0L * ((
long double)(i)) - 1.0L ) ) * (
std::pow(alpha + beta + (2.0L*((
long double)(i)) - 2.0L),2.0L))
432 * ( alpha + beta + ( 2.0L * ((
long double)(i)) - 3.0L ) ) );
436 delta = (
gamma(alpha + 1.0L) *
gamma(beta + 1.0L)) /
gamma(alpha + beta + 2.0L);
439 for(i=2;i <= (*npoints);i++)
440 prod = prod * c[i-1];
441 cc = delta *
std::pow( 2.0L, alpha + beta + 1.0L ) * prod;
443 for(i=1;i<=(*npoints);i++) {
445 an = alpha / (
long double)((*npoints));
446 bn = beta / (
long double)((*npoints));
448 r1 = ( 1.0L + alpha ) * ( 2.78L / ( 4.0L + (
long double)((*npoints)*(*npoints))) + 0.768L * an / (
long double)((*npoints)));
449 r2 = 1.0L + 1.48L * an + 0.96L * bn + 0.452L * an * an + 0.83L * an * bn;
451 x0 = ( r2 - r1 ) / r2;
454 r1 = ( 4.1L + alpha ) / ( ( 1.0L + alpha ) * ( 1.0L + 0.156L * alpha ) );
456 r2 = 1.0L + 0.06L * ((
long double)((*npoints)) - 8.0L) * (1.0L + 0.12L * alpha) / (
long double)((*npoints));
457 r3 = 1.0L + 0.012L * beta * (1.0L + 0.25L * fabsl(alpha)) / (
long double)((*npoints));
459 x0 = x0 - r1*r2*r3*(1.0L - x0);
462 r1 = ( 1.67L + 0.28L * alpha ) / ( 1.0L + 0.37L * alpha );
463 r2 = 1.0L + 0.22L * ( (
long double)((*npoints)) - 8.0L) / (
long double)((*npoints));
464 r3 = 1.0L + 8.0L * beta / ( ( 6.28L + beta ) * (
long double)((*npoints)*(*npoints)));
466 x0 = x0 - r1 * r2 * r3 * ( Location[0] - x0 );
468 else if(i<(*npoints)-1) {
469 x0 = 3.0L * Location[i-2] - 3.0L * Location[i-3] + Location[i-4];
471 else if(i==(*npoints)-1) {
472 r1 = ( 1.0L + 0.235L * beta ) / (0.766L + 0.119L * beta);
473 r2 = 1.0L / ( 1.0L + 0.639L * ((
long double)((*npoints)) - 4.0L)
474 / ( 1.0L + 0.71L * ((
long double)((*npoints)) - 4.0L)));
476 r3 = 1.0L / ( 1.0L + 20.0L * alpha / ( ( 7.5L + alpha ) *
477 (
long double)((*npoints)*(*npoints))));
479 x0 = x0 + r1 * r2 * r3 * ( x0 - Location[i-3] );
481 else if(i==(*npoints)) {
482 r1 = ( 1.0L + 0.37L * beta ) / ( 1.67L + 0.28L * beta );
484 r2 = 1.0L / ( 1.0L + 0.22L * ( (
long double)((*npoints)) - 8.0L )
485 / (
long double)((*npoints)));
487 r3 = 1.0L / ( 1.0L + 8.0L * alpha /
488 ( ( 6.28L + alpha ) * (
long double)((*npoints)*(*npoints))));
490 x0 = x0 + r1 * r2 * r3 * ( x0 - Location[i-3] );
495 long double precision;
496 int itera, itera_max = 10;
500 for(itera=1;itera<=itera_max;itera++) {
504 if(fabsl(d) <= precision*(fabsl(x0) + 1.0L)) {
509 Weight[i-1] = cc/(dp2*p1);
513 for(i=1;i<=(*npoints)/2;i++) {
514 temp = Location[i-1];
515 Location[i-1] = Location[(*npoints)-i];
516 Location[(*npoints)-i] = temp;
519 for(i=1;i<=(*npoints)/2;i++) {
521 Weight[i-1] = Weight[(*npoints)-i];
522 Weight[(*npoints)-i] = temp;
530 long double p2, p0, dp0, dp1;
535 p2 = x + (alpha - beta)/(alpha + beta + 2.0L);
538 for(i=2;i<=order;i++) {
545 p2 = (x - b[i-1])*(*p1) - c[i-1]*p0;
546 *dp2 = (x - b[i-1])*dp1 + (*p1) - c[i-1]*dp0;
553 long double precision = 1.0L;
557 precision = precision / 2.0L;
559 cout <<
"\nMaxime iterations reached - epsilon() \n";
560 return 2.0*precision;
563 return 2.0L*precision;
568 long double fatorial = (
long double)(n - 1);
569 for (
int i=n-2; i>1; --i)
570 fatorial *= (
long double)i;
577 long double c[7] = { -1.910444077728E-03L, 8.4171387781295E-04L, -5.952379913043012E-04L,
578 7.93650793500350248E-04L, -2.777777777777681622553E-03L, 8.333333333333333331554247E-02L,
580 long double precision = 2.22E-16L;
581 long double fact, half = 0.5L;
583 long double p[8] = { -1.71618513886549492533811E+00L, 2.47656508055759199108314E+01L,
584 -3.79804256470945635097577E+02L, 6.29331155312818442661052E+02L, 8.66966202790413211295064E+02L,
585 -3.14512729688483675254357E+04L, -3.61444134186911729807069E+04L, 6.64561438202405440627855E+04L };
587 long double q[8] = { -3.08402300119738975254353E+01L, 3.15350626979604161529144E+02L,
588 -1.01515636749021914166146E+03L, -3.10777167157231109440444E+03L, 2.25381184209801510330112E+04L,
589 4.75584627752788110767815E+03L, -1.34659959864969306392456E+05L, -1.15132259675553483497211E+05L };
590 long double res, xnum, y, y1, ysq, z;
591 long double sqrtpi = 0.9189385332046727417803297L;
592 long double sum, value, xbig = 171.624L;
593 long double xden, xinf = 1.79E+308L;
594 long double xminin = 2.23E-308L;
604 y1 = (
long double)((
int)(y));
607 if( y1 != (
long double)(((int)(y1*half))*2.0L)) {
610 fact = - M_PI/sinl(M_PI*res);
622 if(xminin <= y) res = 1.0L/y;
638 y = y - (
long double)(n);
644 xnum = (xnum + p[i])*z;
645 xden = xden*z + q[i];
647 res = xnum/xden + 1.0L;
664 sum = sum / ysq + c[i];
666 sum = sum / y - y + sqrtpi;
667 sum = sum + (y-half)*
log(y);
677 if(parity) res = -
res;
678 if(fact != 1.0L) res = fact/
res;
long double JacobiPolinomial(long double x, int order, long double alpha, long double beta, TPZVec< long double > &b, TPZVec< long double > &c, long double *dp2, long double *p1)
Evaluates the Jacobi polinomial for real x.
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ fabs
void SetType(int &type, int order)
Sets a gaussian quadrature: 0 - Gauss Legendre, 1 - Gauss Lobatto, 2 - Gauss Jacobi with alpha = beta...
bool IsZero(long double a)
Returns if the value a is close Zero as the allowable tolerance.
long double W(int i) const
Returns weight for the ith point.
TPZVec< long double > fWeight
Weight of the integration point.
Templated vector implementation.
int ComputingGaussLobattoQuadrature(int order)
Computes the points and weights for Gauss Lobatto Quadrature over the parametric 1D element It is to...
int fOrder
order of the integration rule
int ComputingGaussJacobiQuadrature(int order, long double alpha, long double beta)
Computes the points and weights for Gauss Lobatto Quadrature over the parametric 1D element It is to...
int ComputingGaussChebyshevQuadrature(int order)
Computes the points and weights for Gauss Chebyshev Quadrature over the parametric 1D element [-1...
#define PZINTEGRAL_MAXITERATIONS_ALLOWED
TPZGaussRule & operator=(const TPZGaussRule ©)
virtual void Resize(const int64_t newsize, const T &object)
Resizes the vector object reallocating the necessary storage, copying the existing objects to the new...
#define DebugStop()
Returns a message to user put a breakpoint in.
int fNumInt
Number of integration points for this object.
long double fBeta
BETA is the exponent of (1+X) in the quadrature rule: weight = (1-X)^ALPHA * (1+X)^BETA.
TPZGaussRule(int order, int type=0, long double alpha=0.0L, long double beta=0.0L)
Constructor of quadrature rule.
long double gamma(unsigned int n)
Evaluate the factorial of a integer.
TPZFlopCounter pow(const TPZFlopCounter &orig, const TPZFlopCounter &xp)
Returns the power and increments the counter of the power.
void Print(std::ostream &out=std::cout)
Prints the number of integration points, all points and weights (as one dimension) ...
Contains the TPZIntRuleList class which creates instances of all integration rules for rapid selectio...
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ log
~TPZGaussRule()
Default destructor.
expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ expr_ exp
long double fAlpha
ALPHA is the exponent of (1-X) in the quadrature rule: weight = (1-X)^ALPHA * (1+X)^BETA.
TPZVec< long double > fLocation
Location of the integration point.
long double machinePrecision()
int fType
fType = 1 (Gauss Lobatto quadrature), fType = 2 (Gauss Jacobi quadrature) for any alpha and beta the ...
Contains the TPZGaussRule class which implements the Gaussian quadrature.
clarg::argString m("-m", "input matrix file name (text format)", "matrix.txt")
long double Loc(int i) const
Returns location of the ith point.
Implements the Gaussian quadrature. Numerical Integration Abstract class.
int ComputingGaussLegendreQuadrature(int order)
Computes the points and weights for Gauss Legendre Quadrature over the parametric 1D element [-1...
#define PZError
Defines the output device to error messages and the DebugStop() function.