From 3c2a468273fe1d07f19bf784d7f878ea008a0925 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Tue, 7 Feb 2017 14:12:00 +0800 Subject: Rename spline.h to spline.hpp --- mass_profile/Makefile | 4 +- mass_profile/calc_lx.cpp | 2 +- mass_profile/calc_lx_beta.cpp | 6 +-- mass_profile/calc_lx_dbeta.cpp | 6 +-- mass_profile/cooling_time.cpp | 2 +- mass_profile/fit_beta_sbp.cpp | 6 +-- mass_profile/fit_dbeta_sbp.cpp | 6 +-- mass_profile/fit_nfw_sbp.cpp | 6 +-- mass_profile/spline.h | 110 ----------------------------------------- mass_profile/spline.hpp | 110 +++++++++++++++++++++++++++++++++++++++++ 10 files changed, 124 insertions(+), 134 deletions(-) delete mode 100644 mass_profile/spline.h create mode 100644 mass_profile/spline.hpp diff --git a/mass_profile/Makefile b/mass_profile/Makefile index b9b6136..b6418ab 100644 --- a/mass_profile/Makefile +++ b/mass_profile/Makefile @@ -1,5 +1,5 @@ # -# Makefile for `mass_profile` tools +# Makefile for `chandra-acis-analysis/mass_profile` tools # # Junhua GU # Weitian LI @@ -29,7 +29,7 @@ TARGETS= fit_nfw_sbp fit_dbeta_sbp fit_beta_sbp \ fit_direct_beta calc_distance fit_wang2012_model \ fit_nfw_mass calc_lx fit_mt_pl fit_lt_pl fit_mt_bpl \ fit_lt_bpl cooling_time calc_lx_dbeta calc_lx_beta -HEADERS= projector.hpp spline.h vchisq.hpp +HEADERS= projector.hpp spline.hpp vchisq.hpp all: pgplot $(TARGETS) diff --git a/mass_profile/calc_lx.cpp b/mass_profile/calc_lx.cpp index b1137ff..21a508c 100644 --- a/mass_profile/calc_lx.cpp +++ b/mass_profile/calc_lx.cpp @@ -1,5 +1,5 @@ #include "calc_distance.h" -#include "spline.h" +#include "spline.hpp" #include #include #include diff --git a/mass_profile/calc_lx_beta.cpp b/mass_profile/calc_lx_beta.cpp index 59ea51c..dcbf1ad 100644 --- a/mass_profile/calc_lx_beta.cpp +++ b/mass_profile/calc_lx_beta.cpp @@ -21,7 +21,7 @@ #include #include #include -#include "spline.h" +#include "spline.hpp" using namespace std; using namespace opt_utilities; @@ -34,9 +34,7 @@ double beta_func(double r, double n0, double rc, double beta) return abs(n0) * pow(1+r*r/rc/rc, -3./2.*abs(beta)); } -//A class enclosing the spline interpolation method of cooling function -//check spline.h for more detailed information -//this class is a thin wrapper for the spline class defined in spline.h +//A class enclosing the spline interpolation method class spline_func_obj :public func_obj { diff --git a/mass_profile/calc_lx_dbeta.cpp b/mass_profile/calc_lx_dbeta.cpp index 5fa2cb6..c2f6a10 100644 --- a/mass_profile/calc_lx_dbeta.cpp +++ b/mass_profile/calc_lx_dbeta.cpp @@ -17,7 +17,7 @@ #include #include #include -#include "spline.h" +#include "spline.hpp" using namespace std; using namespace opt_utilities; @@ -34,9 +34,7 @@ double dbeta_func(double r, double n01, double rc1, double beta1, } -//A class enclosing the spline interpolation method of cooling function -//check spline.h for more detailed information -//this class is a thin wrapper for the spline class defined in spline.h +//A class enclosing the spline interpolation method class spline_func_obj :public func_obj { diff --git a/mass_profile/cooling_time.cpp b/mass_profile/cooling_time.cpp index 12b869e..eb8af2b 100644 --- a/mass_profile/cooling_time.cpp +++ b/mass_profile/cooling_time.cpp @@ -1,7 +1,7 @@ #include #include #include -#include "spline.h" +#include "spline.hpp" using namespace std; diff --git a/mass_profile/fit_beta_sbp.cpp b/mass_profile/fit_beta_sbp.cpp index c16c092..295fa1e 100644 --- a/mass_profile/fit_beta_sbp.cpp +++ b/mass_profile/fit_beta_sbp.cpp @@ -21,7 +21,7 @@ #include #include #include -#include "spline.h" +#include "spline.hpp" using namespace std; using namespace opt_utilities; @@ -46,9 +46,7 @@ static double calc_critical_density(double z, } -//A class enclosing the spline interpolation method of cooling function -//check spline.h for more detailed information -//this class is a thin wrapper for the spline class defined in spline.h +//A class enclosing the spline interpolation method class spline_func_obj :public func_obj { diff --git a/mass_profile/fit_dbeta_sbp.cpp b/mass_profile/fit_dbeta_sbp.cpp index 30c4c35..71b3089 100644 --- a/mass_profile/fit_dbeta_sbp.cpp +++ b/mass_profile/fit_dbeta_sbp.cpp @@ -17,7 +17,7 @@ #include #include #include -#include "spline.h" +#include "spline.hpp" using namespace std; using namespace opt_utilities; @@ -45,9 +45,7 @@ static double calc_critical_density(double z, } -//A class enclosing the spline interpolation method of cooling function -//check spline.h for more detailed information -//this class is a thin wrapper for the spline class defined in spline.h +//A class enclosing the spline interpolation method class spline_func_obj :public func_obj { diff --git a/mass_profile/fit_nfw_sbp.cpp b/mass_profile/fit_nfw_sbp.cpp index a7d0537..35e42a6 100644 --- a/mass_profile/fit_nfw_sbp.cpp +++ b/mass_profile/fit_nfw_sbp.cpp @@ -14,7 +14,7 @@ #include #include #include -#include "spline.h" +#include "spline.hpp" #include using namespace std; using namespace opt_utilities; @@ -22,9 +22,7 @@ using namespace opt_utilities; const double M_sun=1.988E33;//solar mass in g const double kpc=3.086E21;//kpc in cm -//A class enclosing the spline interpolation method of cooling function -//check spline.h for more detailed information -//this class is a thin wrapper for the spline class defined in spline.h +//A class enclosing the spline interpolation method class spline_func_obj :public func_obj { diff --git a/mass_profile/spline.h b/mass_profile/spline.h deleted file mode 100644 index 9645845..0000000 --- a/mass_profile/spline.h +++ /dev/null @@ -1,110 +0,0 @@ -#ifndef SPLINE_H -#define SPLINE_H - -#include -#include -#include -#include -#include - -template -class spline -{ -public: - std::vector x_list; - std::vector y_list; - std::vector y2_list; - -public: - void push_point(T x,T y) - { - if(!x_list.empty()) - { - assert(x>*(x_list.end()-1)); - } - x_list.push_back(x); - y_list.push_back(y); - } - - T get_value(T x) - { - if(x<=x_list[0]) - { - return y_list[0]; - } - if(x>=x_list.back()) - { - return y_list.back(); - } - assert(x_list.size()==y2_list.size()); - assert(x>x_list[0]); - assert(xx) - { - n2--; - } - } - T h=x_list[n2]-x_list[n1]; - double a=(x_list[n2]-x)/h; - double b=(x-x_list[n1])/h; - return a*y_list[n1]+b*y_list[n2]+((a*a*a-a)*y2_list[n1]+ - (b*b*b-b)*y2_list[n2])*(h*h)/6.; - - } - - void gen_spline(T y2_0,T y2_N) - { - int n=x_list.size(); - y2_list.resize(0); - y2_list.resize(x_list.size()); - std::vector u(x_list.size()); - if(std::abs(y2_0)::epsilon()) - { - y2_list[0]=0; - u[0]=0; - } - else - { - y2_list[0]=-.5; - u[0]=(3./(x_list[1]-x_list[0]))*((y_list[1]-y_list[0])/(x_list[1]-x_list[0])-y2_0); - } - for(int i=1;i::epsilon()) - { - qn=un=0; - } - else - { - qn=.5; - un=(3./(x_list[n-1]-x_list[n-2]))*(y2_N-(y_list[n-1]-y_list[n-2])/(x_list[n-1]-x_list[n-2])); - - } - y2_list[n-1]=(un-qn*u[n-2])/(qn*y2_list[n-2]+1.); - for(int i=n-2;i>=0;--i) - { - y2_list[i]=y2_list[i]*y2_list[i+1]+u[i]; - } - } - -}; - -#endif /* SPLINE_H */ diff --git a/mass_profile/spline.hpp b/mass_profile/spline.hpp new file mode 100644 index 0000000..1027b61 --- /dev/null +++ b/mass_profile/spline.hpp @@ -0,0 +1,110 @@ +#ifndef SPLINE_HPP +#define SPLINE_HPP + +#include +#include +#include +#include +#include + +template +class spline +{ +public: + std::vector x_list; + std::vector y_list; + std::vector y2_list; + +public: + void push_point(T x,T y) + { + if(!x_list.empty()) + { + assert(x>*(x_list.end()-1)); + } + x_list.push_back(x); + y_list.push_back(y); + } + + T get_value(T x) + { + if(x<=x_list[0]) + { + return y_list[0]; + } + if(x>=x_list.back()) + { + return y_list.back(); + } + assert(x_list.size()==y2_list.size()); + assert(x>x_list[0]); + assert(xx) + { + n2--; + } + } + T h=x_list[n2]-x_list[n1]; + double a=(x_list[n2]-x)/h; + double b=(x-x_list[n1])/h; + return a*y_list[n1]+b*y_list[n2]+((a*a*a-a)*y2_list[n1]+ + (b*b*b-b)*y2_list[n2])*(h*h)/6.; + + } + + void gen_spline(T y2_0,T y2_N) + { + int n=x_list.size(); + y2_list.resize(0); + y2_list.resize(x_list.size()); + std::vector u(x_list.size()); + if(std::abs(y2_0)::epsilon()) + { + y2_list[0]=0; + u[0]=0; + } + else + { + y2_list[0]=-.5; + u[0]=(3./(x_list[1]-x_list[0]))*((y_list[1]-y_list[0])/(x_list[1]-x_list[0])-y2_0); + } + for(int i=1;i::epsilon()) + { + qn=un=0; + } + else + { + qn=.5; + un=(3./(x_list[n-1]-x_list[n-2]))*(y2_N-(y_list[n-1]-y_list[n-2])/(x_list[n-1]-x_list[n-2])); + + } + y2_list[n-1]=(un-qn*u[n-2])/(qn*y2_list[n-2]+1.); + for(int i=n-2;i>=0;--i) + { + y2_list[i]=y2_list[i]*y2_list[i+1]+u[i]; + } + } + +}; + +#endif /* SPLINE_HPP */ -- cgit v1.2.2