Commit fb5907a8 authored by Jean-Eric Campagne's avatar Jean-Eric Campagne
Browse files

(JEC) 22/03/16 use Discrete Cosine Transform via FFTW to compute Jnlp. Use...

(JEC) 22/03/16 use Discrete Cosine Transform via FFTW to compute Jnlp. Use OpenMP to speed the sampling of Spherical Bessel function
parent 4b2ef3c7
......@@ -39,6 +39,12 @@ SHARPLIB = $(SHARPDIR)/lib
SHARPINC = -I$(SHARPDIR)/include
SHARPLIBN = -L$(SHARPLIB) -lsharp -lc_utils -lfftpack
# ===== FFTW3 ======
FFTWDIR = /opt/local
FFTWLIB = $(FFTWDIR)/lib
FFTWINC = -I$(FFTWDIR)/include
FFTWLIBN = -L$(FFTWLIB) -lfftw3 -lfftw3_threads
SRC = ./src/
LIB = ./lib/
OBJ = ./objs/
......@@ -111,6 +117,7 @@ CXXOBJ = $(OBJ)laguerreBuilder.o \
$(OBJ)lagsht_bessel.o \
$(OBJ)laguerre2bessel.o
CXXSHOBJ = laguerreBuilder.o \
laguerreTransform.o \
lagsht_spheregeom.o \
......@@ -135,8 +142,8 @@ CXXHDR = $(SRC)lagsht_exceptions.h \
$(SRC)laguerre2bessel.h \
$(SRC)quadinteg.h
CPPFLAGS += $(BLASYES) $(SHARPINC) $(BLASINC) $(BOOSTINC)
LDFLAGS += $(SHARPLIBN) $(BLASLIBN) -lm
CPPFLAGS += $(BLASYES) $(SHARPINC) $(BLASINC) $(BOOSTINC) $(FFTWINC)
LDFLAGS += $(SHARPLIBN) $(BLASLIBN) $(FFTWLIBN) -lm
#C++ rule for compiling
......@@ -144,6 +151,7 @@ $(OBJ)%.o: $(SRC)%.cc $(CXXHDR)
echo "compile... $<"
$(CXXCOMPILE) $< -o $@
######################
.PHONY: sharelib
sharelib : $(CXXOBJ)
......
This diff is collapsed.
......@@ -12,6 +12,7 @@
#define DEBUG 0
#define LIMBER 0
namespace LagSHT {
......@@ -123,10 +124,10 @@ void Laguerre2Bessel::ComputeJInteg(string clenshawDir, string jlnpDir){
cout << "(JEC) ComputeJInteg START " << endl;
#if LIMBER>0
r_8 h2=1.0; //put to 0 to switch off the 2nd order of Limber expension approx
r_8 h3=1.0; //put to 0 to switch off the 3rd order of Limber expension approxxs
#endif
if(Nmax_<2)throw LagSHTError("Laguerre2Bessel::ComputeJInteg Nmax<2");
......@@ -137,7 +138,10 @@ void Laguerre2Bessel::ComputeJInteg(string clenshawDir, string jlnpDir){
r_8 tau3sqrt = pow(tau,(r_8)(3./2.));
r_8 rNm1 = Rmax_ / tau; // R = r[N-1] with N the original transform value. Todo (lagTrans_->GetNodes()).back()
r_8 tol4Integral = 1e-10;
#if LIMBER>0
r_8 tol4Limber = 1e-6;
#endif
typedef ClenshawCurtisQuadrature<double> Integrator_t;
string clenshawFile = clenshawDir+"/ClenshawCurtisRuleData-40.txt";
......@@ -181,7 +185,7 @@ void Laguerre2Bessel::ComputeJInteg(string clenshawDir, string jlnpDir){
cout << "(JEC) ComputeJInteg integUpperBound END " << endl;
stringstream ss; ss << "NEWNEW-jlnp-L"<<Lmax_<<"-N"<<Nmax_<<"-P"<<Pmax_<<".txt";
stringstream ss; ss << "NR-NoLimber-jlnp-L"<<Lmax_<<"-N"<<Nmax_<<"-P"<<Pmax_<<".txt";
std::ofstream ofs;
string fname(jlnpDir+"/"+ss.str());
ofs.open (fname.c_str(), std::ofstream::out);
......@@ -191,10 +195,10 @@ void Laguerre2Bessel::ComputeJInteg(string clenshawDir, string jlnpDir){
r_8 sqrt2Ovpi= sqrt(2.0/M_PI);
for(int p=0; p<Pmax_; p++){
cout << "p = " << p;
// cout << "p = " << p;
for(int l=0; l<Lmax_; l++){
cout << " l = " << l;
// cout << " l = " << l;
int ploff7 = p + l*Pmax_;
......@@ -217,7 +221,10 @@ void Laguerre2Bessel::ComputeJInteg(string clenshawDir, string jlnpDir){
r_8 ql2scaled = (*jnu_)(l,1)/klptau; // the 2nd BesselRoot rescaled
#if LIMBER>0
r_8 arg = (r8l+0.5)/klptau; // (L+1/2)/(klp*tau) for Limber development
r_8 limb0Norm = (1./klptau3) * pow((r8l+0.5),(r_8)1.5) * pow(arg,alphaOv2M1);
r_8 limb3C0 = -(h3*(8*(-3 + alpha)*(-1 + alpha)*alphap1*klptau3
......@@ -234,16 +241,17 @@ void Laguerre2Bessel::ComputeJInteg(string clenshawDir, string jlnpDir){
r_8 limb3C3 = 8*h3*fl3;
r_8 limb3Norm = pow(arg,alphaOv2M1)/(384 * klptau6 * pow(0.5+r8l,0.5));
#endif
for (int n=0; n<Nmax_; n++){
cout << " n = " << n << endl;
// cout << " n = " << n << endl;
//1. compute the Limber (Order 0) approximation
LaguerreFuncQuad* Ln = new LaguerreFuncQuad(n, alpha);
r_8 JlnpApprox = 0;
#if LIMBER>0
//1. compute the Limber (Order 0) approximation
r_8 limber0 = limb0Norm * Ln->Value(arg)*facts[n];
//2. compute a higher order Limber (Order 3) approximation
//h2: term of 2nd order; h3: term of 3rd order
......@@ -262,7 +270,7 @@ void Laguerre2Bessel::ComputeJInteg(string clenshawDir, string jlnpDir){
* ( limb3C0*lag0 + limb3C1 * lag1 + limb3C2 * lag2 + limb3C3 * lag3 );
r_8 JlnpApprox = limber3;
JlnpApprox = limber3;
int is_limberApprox = 1;
......@@ -270,19 +278,25 @@ void Laguerre2Bessel::ComputeJInteg(string clenshawDir, string jlnpDir){
if(fabs(limber0-limber3)>tol4Limber){
is_limberApprox = 0;
#endif
IntFunc1D f(l,klptau,Ln);
//upper bound of integration is the Max between the 2nd BesselRoot rescaled and the Laguerre Function "end point"
r_8 intUppBound = std::max(integUpperBound[n], ql2scaled);
theQuad.SetFuncBounded(f,intLowBound,intUppBound);
integ_val = theQuad.GlobalAdapStrat(tol4Integral);
JlnpApprox = integ_val.first * (facts[n]*sqrt2Ovpi);
}
#if LIMBER>0
}//end limber test
#endif
Jlnp_[ploff7 + n*Jstride] = JlnpApprox;
ofs <<l<<" "
<<n<<" "
<<p<< " " << setprecision(30) << Jlnp_[ploff7 + n*Jstride]
......@@ -292,9 +306,11 @@ void Laguerre2Bessel::ComputeJInteg(string clenshawDir, string jlnpDir){
Jlnp_[ploff7 + n*Jstride] *= tau3sqrt;
delete Ln;
#if LIMBER>0
delete Ln_ap1;
delete Ln_ap2;
delete Ln_ap3;
#endif
}//n
}//l
......
......@@ -43,7 +43,7 @@ using namespace std;
namespace LagSHT {
/////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
//// - -Class generalized Laguerre Function and Gauss-Laguerre Quadrature -------------- //
//// The Laguerre Function is scaled by exp(-r/2) compared to the Laguerre Polynomials //
//// the exp(r_i) scales the weights compared to the Polynomial Gauss-Laguerre Quadrature//
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment