/************************************************************************************************************* The MIT License Copyright (C) 2006-2019 David Dubbeldam, Sofia Calero, Thijs Vlugt, Donald E. Ellis, and Randall Q. Snurr. D.Dubbeldam@uva.nl http://www.uva.nl/profiel/d/u/d.dubbeldam/d.dubbeldam.html scaldia@upo.es http://www.upo.es/raspa/ t.j.h.vlugt@tudelft.nl http://homepage.tudelft.nl/v9k6y don-ellis@northwestern.edu http://dvworld.northwestern.edu/ snurr@northwestern.edu http://zeolites.cqe.northwestern.edu/ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. **************************************************************************************************************/ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include "vector.h" #include "integrate.h" #include "cubic_spline_1d.h" /* #define EPS 1.0e-8 #define JMAX 20 #define FUNC(x) ((*func)(x)) REAL Trapezoidal(CUBIC_SPLINE spline,REAL f(REAL),REAL a,REAL b,int n) { REAL x,tnm,sum,del,r; static REAL s; int it,j; static int i=0; REAL valuea,valueb; REAL tmp1,tmp2,tmp3; fprintf(stderr, "entering\n"); if(n==1) { r=a; if (r=spline.x[i+1]) i=Interval(spline.n,r,spline.x); r-=spline.x[i]; tmp1=3.0*spline.d[i]; tmp2=2.0*spline.c[i]; tmp3=2.0*tmp1; valuea=((spline.d[i]*r+spline.c[i])*r+spline.b[i])*r+spline.a[i]; r=b; if (r=spline.x[i+1]) i=Interval(spline.n,r,spline.x); r-=spline.x[i]; tmp1=3.0*spline.d[i]; tmp2=2.0*spline.c[i]; tmp3=2.0*tmp1; valueb=((spline.d[i]*r+spline.c[i])*r+spline.b[i])*r+spline.a[i]; fprintf(stderr, "leaving\n"); return (s=0.5*(b-a)*(f(valuea)+f(valueb))); } else { for (it=1,j=1;j=spline.x[i+1]) i=Interval(spline.n,r,spline.x); r-=spline.x[i]; tmp1=3.0*spline.d[i]; tmp2=2.0*spline.c[i]; tmp3=2.0*tmp1; valuea=((spline.d[i]*r+spline.c[i])*r+spline.b[i])*r+spline.a[i]; sum+=f(valuea); } s=0.5*(s+(b-a)*sum/tnm); fprintf(stderr, "leaving\n"); return s; } } REAL QuadratureSimpson(CUBIC_SPLINE spline,REAL f(REAL),REAL a,REAL b) { int j; REAL s,st,ost,os; ost = os = -1.0e30; for (j=1;j<=JMAX;j++) { st=Trapezoidal(spline,f,a,b,j); s=(4.0*st-ost)/3.0; if(fabs(s-os) < EPS*fabs(os)) return s; if((s==0)&&(os==0)&&(j>6)) return s; os=s; ost=st; } fprintf(stderr, "Too many steps in routine qsimp"); return 0.0; } #undef EPS #undef JMAX */ // Simpson's rule for abitrary number of intervals (even or odd) // Jack W. Hollingsworth and Henry F. Hunter // Rensselaer Polytechnic Institute, Troy, N.Y. // A generalization of the Simpson's rule in the sense that it is exact for cubic polynomials and is valid // for an odd as well as even number of intervals. The weights are equal except for the three points at the end. // For an even number of intervaks of length 'h', the error coefficient is 23/3 h^5, corresponding to 20/3 h^5 for Simpson's rule. REAL IntegrateGeneralizedSimpsonOrderN(REAL *data,REAL *count,REAL delta,int n) { int i; REAL value; switch(n) { case 0: return 0.0; case 1: return delta*data[0]/count[0]; case 2: return (delta/24.0)*(12.0*data[0]/count[0]+12.0*data[1]/count[1]); case 3: return (delta/24.0)*(8.0*data[0]/count[0]+32.0*data[1]/count[1]+8.0*data[2]/count[2]); case 4: return (delta/24.0)*(9.0*data[0]/count[0]+27.0*data[1]/count[1]+27.0*data[2]/count[2]+9.0*data[3]/count[3]); case 5: return (delta/24.0)*(9.0*data[0]/count[0]+28.0*data[1]/count[1]+22.0*data[2]/count[2]+28.0*data[3]/count[3]+9.0*data[4]/count[4]); case 6: return (delta/24.0)*(9.0*data[0]/count[0]+28.0*data[1]/count[1]+23.0*data[2]/count[2]+23.0*data[3]/count[3]+28.0*data[4]/count[4]+9.0*data[5]/count[5]); default: value=9.0*data[0]/count[0]+28.0*data[1]/count[1]+23.0*data[2]/count[2]+23.0*data[n-3]/count[n-3]+28.0*data[n-2]/count[n-2]+9.0*data[n-1]/count[n-1]; for(i=3;i