From c0f0679033af095e065441975ebfd1d62fda08cc Mon Sep 17 00:00:00 2001 From: hrocho Date: Wed, 26 Jul 2017 20:22:18 +0200 Subject: [PATCH] EnergyTable is not constexpr now to support older compiler, + small other fixes like missing returns --- cwrapper.cpp | 4 ++-- generated_LS_coeff.h | 3 ++- storage.cpp | 2 +- storage.h | 23 ++++++++++++++++++++--- structures.cpp | 1 + utils/generator.cpp | 3 ++- 6 files changed, 28 insertions(+), 8 deletions(-) diff --git a/cwrapper.cpp b/cwrapper.cpp index 7cebfa1..2733401 100644 --- a/cwrapper.cpp +++ b/cwrapper.cpp @@ -34,7 +34,7 @@ extern "C" { mat.add_element(ta,tz,1.0); } - catima::angular_straggling_from_E(p,Tin,Tout,mat); + return catima::angular_straggling_from_E(p,Tin,Tout,mat); } double catima_energy_straggling_from_E(double pa, int pz, double Tin, double Tout,double ta, double tz){ @@ -46,7 +46,7 @@ extern "C" { else{ mat.add_element(ta,tz,1.0); } - catima::energy_straggling_from_E(p,Tin,Tout,mat); + return catima::energy_straggling_from_E(p,Tin,Tout,mat); } } \ No newline at end of file diff --git a/generated_LS_coeff.h b/generated_LS_coeff.h index 35f7358..c4fc9d0 100644 --- a/generated_LS_coeff.h +++ b/generated_LS_coeff.h @@ -13,7 +13,8 @@ constexpr double a_rel_increase=0.05; constexpr double logEmin = 0; constexpr double logEmax = 5; // energy points array in MeV/u -constexpr EnergyTable<200> ls_energy_table(0,5); +//constexpr EnergyTable<200> ls_energy_table(0,5); +EnergyTable<200> ls_energy_table(0,5); //arrays dimensions are [z][energy], z=1 starts from index=0 diff --git a/storage.cpp b/storage.cpp index 6360082..5bea454 100644 --- a/storage.cpp +++ b/storage.cpp @@ -3,7 +3,7 @@ #include "storage.h" namespace catima { Data _storage; - + EnergyTable energy_table(logEmin,logEmax); bool operator==(const DataPoint &a, const DataPoint &b){ if( (a.m == b.m) && (a.p == b.p) && (a.config == b.config)){ diff --git a/storage.h b/storage.h index 5fef2d8..1da1381 100644 --- a/storage.h +++ b/storage.h @@ -31,8 +31,8 @@ namespace catima{ //inline double energy_function( int i ) { return exp(M_LN10*(logEmin + ((double)i)*(logEmax-logEmin)/(max_datapoints - 1.0))); } - enum DataType{TYPE_RANGE,TYPE_LS}; - + //enum DataType{TYPE_RANGE,TYPE_LS}; + /* template struct EnergyTable{ constexpr EnergyTable(double logmin, double logmax):values(),step(0.0),num(N){ @@ -46,6 +46,23 @@ namespace catima{ double step; std::size_t num; }; + */ + + template + struct EnergyTable{ + EnergyTable(double logmin, double logmax):values(),step(0.0),num(N){ + step = (logmax-logmin)/(N - 1.0); + for(auto i=0;i energy_table; template int EnergyTable_index(const EnergyTable &table, double val){ @@ -68,6 +85,7 @@ namespace catima{ r = (x*y[i]) + ((1-x)*y[i+1]); return r; } + /* template struct EnergyTableLinear{ @@ -81,7 +99,6 @@ namespace catima{ std::size_t num; }; */ - constexpr EnergyTable energy_table(logEmin,logEmax); class DataPoint{ public: diff --git a/structures.cpp b/structures.cpp index a965efc..ce8b7cb 100644 --- a/structures.cpp +++ b/structures.cpp @@ -92,6 +92,7 @@ Layers operator+(const Layers &a, const Material &m){ res.add(e); } res.add(m); + return res; } diff --git a/utils/generator.cpp b/utils/generator.cpp index 2d3234e..2b91bdf 100644 --- a/utils/generator.cpp +++ b/utils/generator.cpp @@ -46,7 +46,8 @@ int main(){ file<<"constexpr double logEmin = "< ls_energy_table("< ls_energy_table("< ls_energy_table("<