1
0
Fork 0
mirror of https://github.com/gwm17/catima.git synced 2024-11-26 12:08:52 -05:00

Merged in constexpr (pull request #2)

EnergyTable is not constexpr now to support older compiler, + small other fixes like missing returns
This commit is contained in:
Andrej Prochazka 2017-07-26 18:29:27 +00:00
commit b76f98cda3
6 changed files with 28 additions and 8 deletions

View File

@ -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);
}
}

View File

@ -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

View File

@ -3,7 +3,7 @@
#include "storage.h"
namespace catima {
Data _storage;
EnergyTable<max_datapoints> 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)){

View File

@ -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<int N>
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<int N>
struct EnergyTable{
EnergyTable(double logmin, double logmax):values(),step(0.0),num(N){
step = (logmax-logmin)/(N - 1.0);
for(auto i=0;i<N;i++){
values[i]=exp(M_LN10*(logmin + ((double)i)*step));
}
}
double operator()(int i)const{return values[i];}
double values[N];
double step;
std::size_t num;
};
extern EnergyTable<max_datapoints> energy_table;
template<int N>
int EnergyTable_index(const EnergyTable<N> &table, double val){
@ -68,6 +85,7 @@ namespace catima{
r = (x*y[i]) + ((1-x)*y[i+1]);
return r;
}
/*
template<int N>
struct EnergyTableLinear{
@ -81,7 +99,6 @@ namespace catima{
std::size_t num;
};
*/
constexpr EnergyTable<max_datapoints> energy_table(logEmin,logEmax);
class DataPoint{
public:

View File

@ -92,6 +92,7 @@ Layers operator+(const Layers &a, const Material &m){
res.add(e);
}
res.add(m);
return res;
}

View File

@ -46,7 +46,8 @@ int main(){
file<<"constexpr double logEmin = "<<logEmin_forLS<<";\n";
file<<"constexpr double logEmax = "<<logEmax_forLS<<";\n";
file<<"// energy points array in MeV/u \n";
file<<"constexpr EnergyTable<"<<num_LS_datapoints<<"> ls_energy_table("<<logEmin_forLS<<","<<logEmax_forLS<<");\n";
//file<<"constexpr EnergyTable<"<<num_LS_datapoints<<"> ls_energy_table("<<logEmin_forLS<<","<<logEmax_forLS<<");\n";
file<<"EnergyTable<"<<num_LS_datapoints<<"> ls_energy_table("<<logEmin_forLS<<","<<logEmax_forLS<<");\n";
/*
file<<"double ls_energy_points["<<num_LS_datapoints<<"]={";