From d833c7a8151e3259967747447ba0cf1ab8edcf88 Mon Sep 17 00:00:00 2001 From: Segev BenZvi Date: Tue, 13 Aug 2024 17:49:07 -0500 Subject: [PATCH 1/7] Cosmetic updates: replace tabs with spaces. --- src/BEMEWS/_ext/output.BEMEWS.cpp | 208 +++++++++++------------ src/BEMEWS/_ext/output_matrix.BEMEWS.cpp | 46 ++--- 2 files changed, 127 insertions(+), 127 deletions(-) diff --git a/src/BEMEWS/_ext/output.BEMEWS.cpp b/src/BEMEWS/_ext/output.BEMEWS.cpp index d9151a9..49e4bc5 100644 --- a/src/BEMEWS/_ext/output.BEMEWS.cpp +++ b/src/BEMEWS/_ext/output.BEMEWS.cpp @@ -48,18 +48,18 @@ void Output_Pvslambda(bool firsttime,bool lasttime,ofstream &fPvslambda,double l { array,NF,NF>,NM> VfMSW, dVfMSWdlambda; double r = sqrt( RE*RE + lambda*lambda - 2.*RE*lambda*sin(-altitude) ); - if(r > RE){ r = RE;} + if(r > RE){ r = RE;} double rrho=rho(r); double YYe=Ye(r); VfMSW[nu][e][e]=Ve(rrho,YYe); VfMSW[nu][mu][mu]=Vmu(rrho,YYe); VfMSW[nu][tau][tau]=Vtau(rrho,YYe); - VfMSW[antinu]=-VfMSW[nu]; + VfMSW[antinu]=-VfMSW[nu]; - vector,NF,NF> > > Hf(NM,vector,NF,NF> >(NE)); - vector,NF,NF> > > UU(NM,vector,NF,NF> >(NE)); - vector,NF,NF> > > Sa(NM,vector,NF,NF> >(NE)), Sm(NM,vector,NF,NF> >(NE)), Smf(NM,vector,NF,NF> >(NE)), Sfm(NM,vector,NF,NF> >(NE)), Sf(NM,vector,NF,NF> >(NE)); + vector,NF,NF> > > Hf(NM,vector,NF,NF> >(NE)); + vector,NF,NF> > > UU(NM,vector,NF,NF> >(NE)); + vector,NF,NF> > > Sa(NM,vector,NF,NF> >(NE)), Sm(NM,vector,NF,NF> >(NE)), Smf(NM,vector,NF,NF> >(NE)), Sfm(NM,vector,NF,NF> >(NE)), Sf(NM,vector,NF,NF> >(NE)); vector > > kk(NM,vector >(NE)); vector > > dkk(NM,vector >(NE)); @@ -69,47 +69,47 @@ void Output_Pvslambda(bool firsttime,bool lasttime,ofstream &fPvslambda,double l for(i=0;i<=NE-1;i++) { Hf[nu][i]=HfV[nu][i] + VfMSW[nu]; kk[nu][i]=k(Hf[nu][i]); - dkk[nu][i]=deltak(kk[nu][i]); - UU[nu][i]=MixingMatrix(Hf[nu][i],kk[nu][i],dkk[nu][i]); + dkk[nu][i]=deltak(kk[nu][i]); + UU[nu][i]=MixingMatrix(Hf[nu][i],kk[nu][i],dkk[nu][i]); - Sa[nu][i] = W(Y[nu][i]) * B(Y[nu][i]); + Sa[nu][i] = W(Y[nu][i]) * B(Y[nu][i]); - if(firsttime==false && lasttime==false){ Sm[nu][i] = Sa[nu][i] * Scumulative[nu][i];} - else{ Sm[nu][i] = Adjoint(UV[nu])*UU[nu][i] * Sa[nu][i] * Scumulative[nu][i];} - + if(firsttime==false && lasttime==false){ Sm[nu][i] = Sa[nu][i] * Scumulative[nu][i];} + else{ Sm[nu][i] = Adjoint(UV[nu])*UU[nu][i] * Sa[nu][i] * Scumulative[nu][i];} + Smf[nu][i]= Sm[nu][i] * Adjoint(UV[nu]); - if(lasttime==false){ - Sfm[nu][i] = UU[nu][i] * Sm[nu][i]; - Sf[nu][i] = UU[nu][i] * Smf[nu][i]; - } + if(lasttime==false){ + Sfm[nu][i] = UU[nu][i] * Sm[nu][i]; + Sf[nu][i] = UU[nu][i] * Smf[nu][i]; + } else{ Sfm[nu][i] = UV[nu] * Sm[nu][i]; - Sf[nu][i] = UV[nu] * Smf[nu][i]; - } + Sf[nu][i] = UV[nu] * Smf[nu][i]; + } // ******* Hf[antinu][i]=HfV[antinu][i] + VfMSW[antinu]; - kk[antinu][i]=kbar(Hf[antinu][i]); - dkk[antinu][i]=deltakbar(kk[antinu][i]); - UU[antinu][i]=MixingMatrix(Hf[antinu][i],kk[antinu][i],dkk[antinu][i]); + kk[antinu][i]=kbar(Hf[antinu][i]); + dkk[antinu][i]=deltakbar(kk[antinu][i]); + UU[antinu][i]=MixingMatrix(Hf[antinu][i],kk[antinu][i],dkk[antinu][i]); - Sa[antinu][i] = W(Y[antinu][i]) * B(Y[antinu][i]); + Sa[antinu][i] = W(Y[antinu][i]) * B(Y[antinu][i]); - if(firsttime==false && lasttime==false){ Sm[antinu][i] = Sa[antinu][i] * Scumulative[antinu][i];} - else{ Sm[antinu][i] = Adjoint(UV[antinu])*UU[antinu][i] * Sa[antinu][i] * Scumulative[antinu][i];} - + if(firsttime==false && lasttime==false){ Sm[antinu][i] = Sa[antinu][i] * Scumulative[antinu][i];} + else{ Sm[antinu][i] = Adjoint(UV[antinu])*UU[antinu][i] * Sa[antinu][i] * Scumulative[antinu][i];} + Smf[antinu][i]= Sm[antinu][i] * Adjoint(UV[antinu]); - if(lasttime==false) - { Sfm[antinu][i] = UU[antinu][i] * Sm[antinu][i]; - Sf[antinu][i] = UU[antinu][i] * Smf[antinu][i]; - } + if(lasttime==false) + { Sfm[antinu][i] = UU[antinu][i] * Sm[antinu][i]; + Sf[antinu][i] = UU[antinu][i] * Smf[antinu][i]; + } else{ Sfm[antinu][i] = UV[antinu] * Sm[antinu][i]; - Sf[antinu][i] = UV[antinu] * Smf[antinu][i]; - } - } + Sf[antinu][i] = UV[antinu] * Smf[antinu][i]; + } + } - for(i=0;i<=NE-1;i++) + for(i=0;i<=NE-1;i++) { fPvslambda.open(fPvslambdafilename[i].c_str(),std::ofstream::app); fPvslambda.precision(12); @@ -130,33 +130,33 @@ void Output_Pvslambda(bool firsttime,bool lasttime,ofstream &fPvslambda,double l if(lasttime==true){ fPvslambda<<"\n"< RE){ r = RE;} + if(r > RE){ r = RE;} rrho=rho(r); YYe=Ye(r); @@ -182,60 +182,60 @@ void Output_PvsE(bool lasttime,ofstream &fPvsE,string outputfilenamestem,double VfMSW[nu][e][e]=Ve(rrho,YYe); VfMSW[nu][mu][mu]=Vmu(rrho,YYe); VfMSW[nu][tau][tau]=Vtau(rrho,YYe); - VfMSW[antinu]=-VfMSW[nu]; + VfMSW[antinu]=-VfMSW[nu]; - vector,NF,NF> > > Hf(NM,vector,NF,NF> >(NE)); - vector,NF,NF> > > UU(NM,vector,NF,NF> >(NE)); - vector,NF,NF> > > Sa(NM,vector,NF,NF> >(NE)), Sm(NM,vector,NF,NF> >(NE)), Smf(NM,vector,NF,NF> >(NE)), Sfm(NM,vector,NF,NF> >(NE)), Sf(NM,vector,NF,NF> >(NE)); + vector,NF,NF> > > Hf(NM,vector,NF,NF> >(NE)); + vector,NF,NF> > > UU(NM,vector,NF,NF> >(NE)); + vector,NF,NF> > > Sa(NM,vector,NF,NF> >(NE)), Sm(NM,vector,NF,NF> >(NE)), Smf(NM,vector,NF,NF> >(NE)), Sfm(NM,vector,NF,NF> >(NE)), Sf(NM,vector,NF,NF> >(NE)); vector > > kk(NM,vector >(NE)); vector > > dkk(NM,vector >(NE)); int i; #pragma omp parallel for schedule(static) - for(i=0;i<=NE-1;i++) + for(i=0;i<=NE-1;i++) { Hf[nu][i]=HfV[nu][i] + VfMSW[nu]; kk[nu][i]=k(Hf[nu][i]); - dkk[nu][i]=deltak(kk[nu][i]); - UU[nu][i]=MixingMatrix(Hf[nu][i],kk[nu][i],dkk[nu][i]); + dkk[nu][i]=deltak(kk[nu][i]); + UU[nu][i]=MixingMatrix(Hf[nu][i],kk[nu][i],dkk[nu][i]); - Sa[nu][i] = W(Y[nu][i]) * B(Y[nu][i]); + Sa[nu][i] = W(Y[nu][i]) * B(Y[nu][i]); if(lasttime==false){ Sm[nu][i] = Sa[nu][i] * Scumulative[nu][i];} - else{ Sm[nu][i] = Adjoint(UV[nu])*UU[nu][i] * Sa[nu][i] * Scumulative[nu][i];} + else{ Sm[nu][i] = Adjoint(UV[nu])*UU[nu][i] * Sa[nu][i] * Scumulative[nu][i];} Smf[nu][i]= Sm[nu][i] * Adjoint(UV[nu]); - if(lasttime==false){ - Sfm[nu][i] = UU[nu][i] * Sm[nu][i]; - Sf[nu][i] = UU[nu][i] * Smf[nu][i]; - } + if(lasttime==false){ + Sfm[nu][i] = UU[nu][i] * Sm[nu][i]; + Sf[nu][i] = UU[nu][i] * Smf[nu][i]; + } else{ Sfm[nu][i] = UV[nu] * Sm[nu][i]; - Sf[nu][i] = UV[nu] * Smf[nu][i]; - } + Sf[nu][i] = UV[nu] * Smf[nu][i]; + } - // ********* - + // ********* + Hf[antinu][i]=HfV[antinu][i] + VfMSW[antinu]; - kk[antinu][i]=kbar(Hf[antinu][i]); - dkk[antinu][i]=deltakbar(kk[antinu][i]); - UU[antinu][i]=MixingMatrix(Hf[antinu][i],kk[antinu][i],dkk[antinu][i]); + kk[antinu][i]=kbar(Hf[antinu][i]); + dkk[antinu][i]=deltakbar(kk[antinu][i]); + UU[antinu][i]=MixingMatrix(Hf[antinu][i],kk[antinu][i],dkk[antinu][i]); - Sa[antinu][i] = W(Y[antinu][i]) * B(Y[antinu][i]); + Sa[antinu][i] = W(Y[antinu][i]) * B(Y[antinu][i]); if(lasttime==false){ Sm[antinu][i] = Sa[antinu][i] * Scumulative[antinu][i];} - else{ Sm[antinu][i] = Adjoint(UV[antinu])*UU[antinu][i] * Sa[antinu][i] * Scumulative[antinu][i];} - + else{ Sm[antinu][i] = Adjoint(UV[antinu])*UU[antinu][i] * Sa[antinu][i] * Scumulative[antinu][i];} + Smf[antinu][i]= Sm[antinu][i] * Adjoint(UV[antinu]); - if(lasttime==false) - { Sfm[antinu][i] = UU[antinu][i] * Sm[antinu][i]; - Sf[antinu][i] = UU[antinu][i] * Smf[antinu][i]; - } + if(lasttime==false) + { Sfm[antinu][i] = UU[antinu][i] * Sm[antinu][i]; + Sf[antinu][i] = UU[antinu][i] * Smf[antinu][i]; + } else{ Sfm[antinu][i] = UV[antinu] * Sm[antinu][i]; - Sf[antinu][i] = UV[antinu] * Smf[antinu][i]; - } - } + Sf[antinu][i] = UV[antinu] * Smf[antinu][i]; + } + } // ******* @@ -252,33 +252,33 @@ void Output_PvsE(bool lasttime,ofstream &fPvsE,string outputfilenamestem,double fPvsE<<"\t Pee \t Pemu \t Petau \t Pmue \t Pmumu \t Pmutau \t Ptaue \t Ptaumu \t Ptautau"; fPvsE<<"\t Pbaree \t Pbaremu \t Pbaretau \t Pbarmue \t Pbarmumu \t Pbarmutau \t Pbartaue \t Pbartaumu \t Pbartautau"; - for(i=0;i<=NE-1;i++) + for(i=0;i<=NE-1;i++) { fPvsE<<"\n"< RE){ r = RE;} + if(r > RE){ r = RE;} rrho=YYe=0.; // **************** diff --git a/src/BEMEWS/_ext/output_matrix.BEMEWS.cpp b/src/BEMEWS/_ext/output_matrix.BEMEWS.cpp index ea8207f..dcfa57f 100644 --- a/src/BEMEWS/_ext/output_matrix.BEMEWS.cpp +++ b/src/BEMEWS/_ext/output_matrix.BEMEWS.cpp @@ -16,7 +16,7 @@ void Pfm(double lambda,vector > > &Y,vector RE){ r = RE;} + if(r > RE){ r = RE;} rrho=rho(r); YYe=Ye(r); @@ -25,53 +25,53 @@ void Pfm(double lambda,vector > > &Y,vector,NF,NF> > > Hf(NM,vector,NF,NF> >(NE)); - vector,NF,NF> > > UU(NM,vector,NF,NF> >(NE)); - vector,NF,NF> > > Sa(NM,vector,NF,NF> >(NE)), Sm(NM,vector,NF,NF> >(NE)), Sfm(NM,vector,NF,NF> >(NE)); + vector,NF,NF> > > Hf(NM,vector,NF,NF> >(NE)); + vector,NF,NF> > > UU(NM,vector,NF,NF> >(NE)); + vector,NF,NF> > > Sa(NM,vector,NF,NF> >(NE)), Sm(NM,vector,NF,NF> >(NE)), Sfm(NM,vector,NF,NF> >(NE)); vector > > kk(NM,vector >(NE)); vector > > dkk(NM,vector >(NE)); int i; #pragma omp parallel for schedule(static) - for(i=0;i<=NE-1;i++) + for(i=0;i<=NE-1;i++) { Hf[nu][i]=HfV[nu][i] + VfMSW[nu]; kk[nu][i]=k(Hf[nu][i]); - dkk[nu][i]=deltak(kk[nu][i]); + dkk[nu][i]=deltak(kk[nu][i]); UU[nu][i] = MixingMatrix(Hf[nu][i],kk[nu][i],dkk[nu][i]); - Sa[nu][i] = W(Y[nu][i]) * B(Y[nu][i]); + Sa[nu][i] = W(Y[nu][i]) * B(Y[nu][i]); // take into account the density jump from Earth matter back to vacuum - Sm[nu][i] = Adjoint(UV[nu])*UU[nu][i] * Sa[nu][i] * Scumulative[nu][i]; + Sm[nu][i] = Adjoint(UV[nu])*UU[nu][i] * Sa[nu][i] * Scumulative[nu][i]; Sfm[nu][i]= UV[nu] * Sm[nu][i]; - // ********* - Hf[antinu][i]=HfV[antinu][i] + VfMSW[antinu]; - kk[antinu][i]=kbar(Hf[antinu][i]); - dkk[antinu][i]=deltakbar(kk[antinu][i]); - UU[antinu][i]=MixingMatrix(Hf[antinu][i],kk[antinu][i],dkk[antinu][i]); + // ********* + Hf[antinu][i]=HfV[antinu][i] + VfMSW[antinu]; + kk[antinu][i]=kbar(Hf[antinu][i]); + dkk[antinu][i]=deltakbar(kk[antinu][i]); + UU[antinu][i]=MixingMatrix(Hf[antinu][i],kk[antinu][i],dkk[antinu][i]); - Sa[antinu][i] = W(Y[antinu][i]) * B(Y[antinu][i]); + Sa[antinu][i] = W(Y[antinu][i]) * B(Y[antinu][i]); // take into account the density jump from Earth matter back to vacuum - Sm[antinu][i] = Adjoint(UV[antinu])*UU[antinu][i] * Sa[antinu][i] * Scumulative[antinu][i]; + Sm[antinu][i] = Adjoint(UV[antinu])*UU[antinu][i] * Sa[antinu][i] * Scumulative[antinu][i]; Sfm[antinu][i]= UV[antinu] * Sm[antinu][i]; - } + } // ******* - for(i=0;i<=NE-1;i++) + for(i=0;i<=NE-1;i++) { PPfm[nu][i][e][0]=norm(Sfm[nu][i][e][0]); PPfm[nu][i][e][1]=norm(Sfm[nu][i][e][1]); PPfm[nu][i][e][2]=norm(Sfm[nu][i][e][2]); - PPfm[nu][i][mu][0]=norm(Sfm[nu][i][mu][0]); PPfm[nu][i][mu][1]=norm(Sfm[nu][i][mu][1]); PPfm[nu][i][mu][2]=norm(Sfm[nu][i][mu][2]); - PPfm[nu][i][tau][0]=norm(Sfm[nu][i][tau][0]); PPfm[nu][i][tau][1]=norm(Sfm[nu][i][tau][1]); PPfm[nu][i][tau][2]=norm(Sfm[nu][i][tau][2]); + PPfm[nu][i][mu][0]=norm(Sfm[nu][i][mu][0]); PPfm[nu][i][mu][1]=norm(Sfm[nu][i][mu][1]); PPfm[nu][i][mu][2]=norm(Sfm[nu][i][mu][2]); + PPfm[nu][i][tau][0]=norm(Sfm[nu][i][tau][0]); PPfm[nu][i][tau][1]=norm(Sfm[nu][i][tau][1]); PPfm[nu][i][tau][2]=norm(Sfm[nu][i][tau][2]); - PPfm[antinu][i][e][0]=norm(Sfm[antinu][i][e][0]); PPfm[antinu][i][e][1]=norm(Sfm[antinu][i][e][1]); PPfm[antinu][i][e][2]=norm(Sfm[antinu][i][e][2]); - PPfm[antinu][i][mu][0]=norm(Sfm[antinu][i][mu][0]); PPfm[antinu][i][mu][1]=norm(Sfm[antinu][i][mu][1]); PPfm[antinu][i][mu][2]=norm(Sfm[antinu][i][mu][2]); + PPfm[antinu][i][e][0]=norm(Sfm[antinu][i][e][0]); PPfm[antinu][i][e][1]=norm(Sfm[antinu][i][e][1]); PPfm[antinu][i][e][2]=norm(Sfm[antinu][i][e][2]); + PPfm[antinu][i][mu][0]=norm(Sfm[antinu][i][mu][0]); PPfm[antinu][i][mu][1]=norm(Sfm[antinu][i][mu][1]); PPfm[antinu][i][mu][2]=norm(Sfm[antinu][i][mu][2]); PPfm[antinu][i][tau][0]=norm(Sfm[antinu][i][tau][0]); PPfm[antinu][i][tau][1]=norm(Sfm[antinu][i][tau][1]); PPfm[antinu][i][tau][2]=norm(Sfm[antinu][i][tau][2]); - } + } //return PPfm; } From b5bd06dc93bc5eeb40ce54436df4f074b6823849 Mon Sep 17 00:00:00 2001 From: Segev BenZvi Date: Tue, 13 Aug 2024 18:03:07 -0500 Subject: [PATCH 2/7] Add option to output to ECSV format. --- src/BEMEWS/_ext/output.BEMEWS.cpp | 8 ++++---- src/BEMEWS/_ext/output.h | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/BEMEWS/_ext/output.BEMEWS.cpp b/src/BEMEWS/_ext/output.BEMEWS.cpp index 49e4bc5..d5d6997 100644 --- a/src/BEMEWS/_ext/output.BEMEWS.cpp +++ b/src/BEMEWS/_ext/output.BEMEWS.cpp @@ -18,7 +18,7 @@ using namespace prefixes; std::vector fPvslambdafilename; -void Initialize_Output(string outputfilenamestem,ofstream &fPvslambda,ofstream &fHvslambda) +void Initialize_Output(string outputfilenamestem,ofstream &fPvslambda,ofstream &fHvslambda, bool ecsvformat) { stringstream filename; fPvslambdafilename=vector(NE); @@ -44,7 +44,7 @@ void Close_Output(ofstream &fHvslambda) // ****************************************************** -void Output_Pvslambda(bool firsttime,bool lasttime,ofstream &fPvslambda,double lambda,vector > > &Y,vector,NF,NF> > > &Scumulative) +void Output_Pvslambda(bool firsttime,bool lasttime,ofstream &fPvslambda,double lambda,vector > > &Y,vector,NF,NF> > > &Scumulative, bool ecsvformat) { array,NF,NF>,NM> VfMSW, dVfMSWdlambda; double r = sqrt( RE*RE + lambda*lambda - 2.*RE*lambda*sin(-altitude) ); @@ -161,7 +161,7 @@ void Output_Pvslambda(bool firsttime,bool lasttime,ofstream &fPvslambda,double l // ************************************************************************ -void Output_PvsE(bool lasttime,ofstream &fPvsE,string outputfilenamestem,double lambda,vector > > &Y,vector,NF,NF> > > &Scumulative) +void Output_PvsE(bool lasttime,ofstream &fPvsE,string outputfilenamestem,double lambda,vector > > &Y,vector,NF,NF> > > &Scumulative, bool ecsvformat) { string cmdotdat("cm.dat"); stringstream filename; @@ -286,7 +286,7 @@ void Output_PvsE(bool lasttime,ofstream &fPvsE,string outputfilenamestem,double // ************************************************************************ -void Output_Hvslambda(bool firsttime,bool lasttime,ofstream &fHvslambda,double lambda,vector > > &Y,vector,NF,NF> > > &Scumulative) +void Output_Hvslambda(bool firsttime,bool lasttime,ofstream &fHvslambda,double lambda,vector > > &Y,vector,NF,NF> > > &Scumulative, bool ecsvformat) { MATRIX,NF,NF> VfMSW,VfMSWbar; double r, rrho, YYe; diff --git a/src/BEMEWS/_ext/output.h b/src/BEMEWS/_ext/output.h index c93c9ff..777f642 100644 --- a/src/BEMEWS/_ext/output.h +++ b/src/BEMEWS/_ext/output.h @@ -6,14 +6,14 @@ extern std::vector fPvsrfilename; -void Initialize_Output(std::string outputfilenamestem,std::ofstream &fPvslambda,std::ofstream &fHvslambda); +void Initialize_Output(std::string outputfilenamestem, std::ofstream &fPvslambda, std::ofstream &fHvslambda, bool ecsvformat=false); void Close_Output(std::ofstream &fHvslambda); -void Output_Pvslambda(bool firsttime,bool lasttime,std::ofstream &fPvslambda,double lambda,std::vector > > &Y,std::vector,NF,NF> > > &Scumulative); +void Output_Pvslambda(bool firsttime, bool lasttime, std::ofstream &fPvslambda, double lambda, std::vector > > &Y, std::vector, NF, NF> > > &Scumulative, bool ecsvformat=false); -void Output_PvsE(bool lasttime,std::ofstream &fPvsE,std::string outputfilenamestem,double lambda,std::vector > > &Y,std::vector,NF,NF> > > &Scumulative); +void Output_PvsE(bool lasttime, std::ofstream &fPvsE, std::string outputfilenamestem, double lambda, std::vector > > &Y, std::vector, NF, NF> > > &Scumulative, bool ecsvformat=false); -void Output_Hvslambda(bool firsttime,bool lasttime,std::ofstream &fHvslambda,double lambda,std::vector > > &Y,std::vector,NF,NF> > > &Scumulative); +void Output_Hvslambda(bool firsttime, bool lasttime, std::ofstream &fHvslambda, double lambda, std::vector > > &Y, std::vector, NF, NF> > > &Scumulative, bool ecsvformat=false); #endif From c0586aa2db1e76ecc2fe8ce457a71c8d51436fa4 Mon Sep 17 00:00:00 2001 From: Segev BenZvi Date: Tue, 13 Aug 2024 19:46:33 -0500 Subject: [PATCH 3/7] Add capability for ECSV output. --- src/BEMEWS/_ext/output.BEMEWS.cpp | 232 ++++++++++++++++++++---------- 1 file changed, 159 insertions(+), 73 deletions(-) diff --git a/src/BEMEWS/_ext/output.BEMEWS.cpp b/src/BEMEWS/_ext/output.BEMEWS.cpp index d5d6997..d2eb79c 100644 --- a/src/BEMEWS/_ext/output.BEMEWS.cpp +++ b/src/BEMEWS/_ext/output.BEMEWS.cpp @@ -25,14 +25,20 @@ void Initialize_Output(string outputfilenamestem,ofstream &fPvslambda,ofstream & for(int i=0;i<=NE-1;i++) { filename.str(""); - if(NE>1){ filename << outputfilenamestem << string(":E=") << ((NE-1.-i)*EminMeV+i*EmaxMeV)/(NE-1.) << string("MeV:Pvslambda.dat");} - else{ filename << outputfilenamestem << string(":E=") << EminMeV << string("MeV:Pvslambda.dat");} + if(NE>1){ + filename << outputfilenamestem << string(":E=") << ((NE-1.-i)*EminMeV+i*EmaxMeV)/(NE-1.) + << (ecsvformat ? string("MeV:Pvslambda.ecsv") : string("MeV:Pvslambda.dat")); + } + else{ + filename << outputfilenamestem << string(":E=") << EminMeV + << (ecsvformat ? string("MeV:Pvslambda.ecsv") : string("MeV:Pvslambda.dat")); + } fPvslambdafilename[i]=filename.str(); fPvslambda.open(fPvslambdafilename[i].c_str()); fPvslambda.close(); // clears the file - } + } filename.str(""); - filename << outputfilenamestem < > > kk(NM,vector >(NE)); vector > > dkk(NM,vector >(NE)); + + const string delimiter = ecsvformat ? string(",") : string("\t"); int i; #pragma omp parallel for schedule(static) @@ -114,45 +122,73 @@ void Output_Pvslambda(bool firsttime,bool lasttime,ofstream &fPvslambda,double l fPvslambda.precision(12); if(firsttime==true){ - fPvslambda<<"lambda [cm] \t r [cm]"; - - fPvslambda<<"\t P11 \t P12 \t P13 \t P21 \t P22 \t P23 \t P31 \t P32 \t P33"; - fPvslambda<<"\t Pbar11 \t Pbar12 \t Pbar13 \t Pbar21 \t Pbar22 \t Pbar23 \t Pbar31 \t Pbar32 \t Pbar33"; - - fPvslambda<<"\t Pe1 \t Pe2 \t Pe3 \t Pmu1 \t Pmu2 \t Pmu3 \t Ptau1 \t Ptau2 \t Ptau3"; - fPvslambda<<"\t Pbare1 \t Pbare2 \t Pbare3 \t Pbarmu1 \t Pbarmu2 \t Pbarmu3 \t Pbartau1 \t Pbartau2 \t Pbartau3"; - - fPvslambda<<"\t Pee \t Pemu \t Petau \t Pmue \t Pmumu \t Pmutau \t Ptaue \t Ptaumu \t Ptautau"; - fPvslambda<<"\t Pbaree \t Pbaremu \t Pbaretau \t Pbarmue \t Pbarmumu \t Pbarmutau \t Pbartaue \t Pbartaumu \t Pbartautau"; + if (ecsvformat) { + fPvslambda << "# %ECSV 1.0\n# ---\n# datatype:\n" + << "# - {name: lambda, unit: cm, datatype: float64, description: path length}\n" + << "# - {name: r, unit: cm, datatype: float64, description: radial distance}\n"; + + const char* pcl[2] = { "", "bar" }; + const char* flavor[3] = { "e", "mu", "tau" }; + + // Mass-mass transitions + for (int j=0; j<2; ++j) + for (int k=1; k<=3; ++k) + for (int l=1; l<=3; ++l) + fPvslambda << "# - {name: P" << pcl[j] << k << l << ", datetype: float64, description: " << k << "->" << l << " transition probability\n"; + + // Flavor-mass transitions + for (int j=0; j<2; ++j) + for (int k=0; k<=2; ++k) + for (int l=1; l<=3; ++l) + fPvslambda << "# - {name: P" << pcl[j] << flavor[k] << l << ", datetype: float64, description: " << flavor[k] << "->" << l << " transition probability\n"; + + // Flavor-flavor transitions + for (int j=0; j<2; ++j) + for (int k=0; k<=2; ++k) + for (int l=0; l<=2; ++l) + fPvslambda << "# - {name: P" << pcl[j] << flavor[k] << flavor[l] << ", datetype: float64, description: " << flavor[k] << "->" << flavor[l] << " transition probability\n"; + } + else { + fPvslambda<<"lambda [cm] \t r [cm]"; + + fPvslambda<<"\t P11 \t P12 \t P13 \t P21 \t P22 \t P23 \t P31 \t P32 \t P33"; + fPvslambda<<"\t Pbar11 \t Pbar12 \t Pbar13 \t Pbar21 \t Pbar22 \t Pbar23 \t Pbar31 \t Pbar32 \t Pbar33"; + + fPvslambda<<"\t Pe1 \t Pe2 \t Pe3 \t Pmu1 \t Pmu2 \t Pmu3 \t Ptau1 \t Ptau2 \t Ptau3"; + fPvslambda<<"\t Pbare1 \t Pbare2 \t Pbare3 \t Pbarmu1 \t Pbarmu2 \t Pbarmu3 \t Pbartau1 \t Pbartau2 \t Pbartau3"; + + fPvslambda<<"\t Pee \t Pemu \t Petau \t Pmue \t Pmumu \t Pmutau \t Ptaue \t Ptaumu \t Ptautau"; + fPvslambda<<"\t Pbaree \t Pbaremu \t Pbaretau \t Pbarmue \t Pbarmumu \t Pbarmutau \t Pbartaue \t Pbartaumu \t Pbartautau"; } + } - if(firsttime==true){ fPvslambda<<"\n"< > > &Y,vector,NF,NF> > > &Scumulative, bool ecsvformat) - { string cmdotdat("cm.dat"); + { string cmdotdat = ecsvformat ? string("cm.ecsv") : string("cm.dat"); stringstream filename; - if(lasttime==false){ filename.str(""); filename<" << l << " transition probability\n"; + + // Flavor-mass transitions + for (int j=0; j<2; ++j) + for (int k=0; k<=2; ++k) + for (int l=1; l<=3; ++l) + fPvsE << "# - {name: P" << pcl[j] << flavor[k] << l << ", datetype: float64, description: " << flavor[k] << "->" << l << " transition probability\n"; + + // Flavor-flavor transitions + for (int j=0; j<2; ++j) + for (int k=0; k<=2; ++k) + for (int l=0; l<=2; ++l) + fPvsE << "# - {name: P" << pcl[j] << flavor[k] << flavor[l] << ", datetype: float64, description: " << flavor[k] << "->" << flavor[l] << " transition probability\n"; + } + else { + fPvsE<<"E [MeV]"; + + fPvsE<<"\t P11 \t P12 \t P13 \t P21 \t P22 \t P23 \t P31 \t P32 \t P33"; + fPvsE<<"\t Pbar11 \t Pbar12 \t Pbar13 \t Pbar21 \t Pbar22 \t Pbar23 \t Pbar31 \t Pbar32 \t Pbar33"; - fPvsE<<"\t P11 \t P12 \t P13 \t P21 \t P22 \t P23 \t P31 \t P32 \t P33"; - fPvsE<<"\t Pbar11 \t Pbar12 \t Pbar13 \t Pbar21 \t Pbar22 \t Pbar23 \t Pbar31 \t Pbar32 \t Pbar33"; + fPvsE<<"\t Pe1 \t Pe2 \t Pe3 \t Pmu1 \t Pmu2 \t Pmu3 \t Ptau1 \t Ptau2 \t Ptau3"; + fPvsE<<"\t Pbare1 \t Pbare2 \t Pbare3 \t Pbarmu1 \t Pbarmu2 \t Pbarmu3 \t Pbartau1 \t Pbartau2 \t Pbartau3"; - fPvsE<<"\t Pe1 \t Pe2 \t Pe3 \t Pmu1 \t Pmu2 \t Pmu3 \t Ptau1 \t Ptau2 \t Ptau3"; - fPvsE<<"\t Pbare1 \t Pbare2 \t Pbare3 \t Pbarmu1 \t Pbarmu2 \t Pbarmu3 \t Pbartau1 \t Pbartau2 \t Pbartau3"; + fPvsE<<"\t Pee \t Pemu \t Petau \t Pmue \t Pmumu \t Pmutau \t Ptaue \t Ptaumu \t Ptautau"; + fPvsE<<"\t Pbaree \t Pbaremu \t Pbaretau \t Pbarmue \t Pbarmumu \t Pbarmutau \t Pbartaue \t Pbartaumu \t Pbartautau"; + } - fPvsE<<"\t Pee \t Pemu \t Petau \t Pmue \t Pmumu \t Pmutau \t Ptaue \t Ptaumu \t Ptautau"; - fPvsE<<"\t Pbaree \t Pbaremu \t Pbaretau \t Pbarmue \t Pbarmumu \t Pbarmutau \t Pbartaue \t Pbartaumu \t Pbartautau"; + const string delimiter = ecsvformat ? string(",") : string("\t"); for(i=0;i<=NE-1;i++) - { fPvsE<<"\n"< Date: Tue, 13 Aug 2024 19:53:22 -0500 Subject: [PATCH 4/7] Connect ecsv flag to input struct and outputs. --- src/BEMEWS/_ext/BEMEWS.cpp | 27 ++++++++++++++------------- src/BEMEWS/_ext/input_class.h | 1 + 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/BEMEWS/_ext/BEMEWS.cpp b/src/BEMEWS/_ext/BEMEWS.cpp index f63bfec..ce70c01 100644 --- a/src/BEMEWS/_ext/BEMEWS.cpp +++ b/src/BEMEWS/_ext/BEMEWS.cpp @@ -93,6 +93,7 @@ PYBIND11_MODULE(_ext, m) .def_readwrite("stepcounterlimit", &InputDataBEMEWS::stepcounterlimit) .def_readwrite("NE", &InputDataBEMEWS::NE) .def_readwrite("outputflag", &InputDataBEMEWS::outputflag) + .def_readwrite("ecsvformat", &InputDataBEMEWS::ecsvformat) ; /*class_ > > > >("stl_vectorx4") @@ -162,7 +163,7 @@ vector > > > Run(InputDataBEMEWS ID) ofstream fHvslambda; // a file for anything else ofstream fSvsE; - if(ID.outputflag==true){ Initialize_Output(outputfilenamestem,fPvslambda,fHvslambda);} + if(ID.outputflag==true){ Initialize_Output(outputfilenamestem,fPvslambda,fHvslambda,ID.ecsvformat);} // ***************************************************** // ***************************************************** @@ -330,14 +331,14 @@ vector > > > Run(InputDataBEMEWS ID) if(ID.outputflag==true){ output=true;} if(output==true){ if(firsttime==true){ - Output_Pvslambda(firsttime,lasttime,fPvslambda,lambdamin,Y,Scumulative); - Output_Hvslambda(firsttime,lasttime,fHvslambda,lambdamin,Y,Scumulative); + Output_Pvslambda(firsttime,lasttime,fPvslambda,lambdamin,Y,Scumulative,ID.ecsvformat); + Output_Hvslambda(firsttime,lasttime,fHvslambda,lambdamin,Y,Scumulative,ID.ecsvformat); } firsttime = false; - Output_Pvslambda(firsttime,lasttime,fPvslambda,lambdamin,Y,Scumulative); - Output_Hvslambda(firsttime,lasttime,fHvslambda,lambdamin,Y,Scumulative); + Output_Pvslambda(firsttime,lasttime,fPvslambda,lambdamin,Y,Scumulative,ID.ecsvformat); + Output_Hvslambda(firsttime,lasttime,fHvslambda,lambdamin,Y,Scumulative,ID.ecsvformat); output = false; } @@ -454,9 +455,9 @@ vector > > > Run(InputDataBEMEWS ID) if(output==true) { cout<<"\nOutput at\t"< > > > Run(InputDataBEMEWS ID) else{ // output at the end of the code if(ID.outputflag==true){ output = true;} if(output==true){ - Output_Pvslambda(firsttime,lasttime,fPvslambda,lambdamax,Y,Scumulative); - Output_Hvslambda(firsttime,lasttime,fHvslambda,lambdamax,Y,Scumulative); + Output_Pvslambda(firsttime,lasttime,fPvslambda,lambdamax,Y,Scumulative,ID.ecsvformat); + Output_Hvslambda(firsttime,lasttime,fHvslambda,lambdamax,Y,Scumulative,ID.ecsvformat); lasttime = true; - Output_Pvslambda(firsttime,lasttime,fPvslambda,lambdamax,Y,Scumulative); - Output_Hvslambda(firsttime,lasttime,fHvslambda,lambdamax,Y,Scumulative); - Output_PvsE(lasttime,fPvsE,outputfilenamestem,lambdamax,Y,Scumulative); + Output_Pvslambda(firsttime,lasttime,fPvslambda,lambdamax,Y,Scumulative,ID.ecsvformat); + Output_Hvslambda(firsttime,lasttime,fHvslambda,lambdamax,Y,Scumulative,ID.ecsvformat); + Output_PvsE(lasttime,fPvsE,outputfilenamestem,lambdamax,Y,Scumulative,ID.ecsvformat); output = false; } diff --git a/src/BEMEWS/_ext/input_class.h b/src/BEMEWS/_ext/input_class.h index 8339828..1cb067e 100644 --- a/src/BEMEWS/_ext/input_class.h +++ b/src/BEMEWS/_ext/input_class.h @@ -28,6 +28,7 @@ struct InputDataBEMEWS double accuracy; double stepcounterlimit; // how often it outputs data bool outputflag; // whether the code outputs data as it does the integration + bool ecsvformat; // whether the output is in ECSV or tab-separated text files InputDataBEMEWS(void) {;} }; From a3d40ca3baae7616fbaa24bd2907d173611e701d Mon Sep 17 00:00:00 2001 From: Segev BenZvi Date: Tue, 13 Aug 2024 20:29:36 -0500 Subject: [PATCH 5/7] Fix typos, test ECSV output successfully. --- BEMEWS_example.py | 5 ++++ src/BEMEWS/_ext/BEMEWS.cpp | 2 +- src/BEMEWS/_ext/output.BEMEWS.cpp | 45 ++++++++++++++++++++++++------- 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/BEMEWS_example.py b/BEMEWS_example.py index 1c52916..343cdb4 100644 --- a/BEMEWS_example.py +++ b/BEMEWS_example.py @@ -57,6 +57,11 @@ ID.stepcounterlimit = 1 + # Test of output in ECSV format + ID.ecsvformat = True + ID.outputflag = True + ID.stepcounterlimit = 100 + # do the calculation. The return is a four dimensional array of transition probabilities nu_alpha -> nu_i: # index order is matter/antimatter, energy, i, alpha diff --git a/src/BEMEWS/_ext/BEMEWS.cpp b/src/BEMEWS/_ext/BEMEWS.cpp index ce70c01..b3fd6e5 100644 --- a/src/BEMEWS/_ext/BEMEWS.cpp +++ b/src/BEMEWS/_ext/BEMEWS.cpp @@ -92,8 +92,8 @@ PYBIND11_MODULE(_ext, m) .def_readwrite("accuracy", &InputDataBEMEWS::accuracy) .def_readwrite("stepcounterlimit", &InputDataBEMEWS::stepcounterlimit) .def_readwrite("NE", &InputDataBEMEWS::NE) - .def_readwrite("outputflag", &InputDataBEMEWS::outputflag) .def_readwrite("ecsvformat", &InputDataBEMEWS::ecsvformat) + .def_readwrite("outputflag", &InputDataBEMEWS::outputflag) ; /*class_ > > > >("stl_vectorx4") diff --git a/src/BEMEWS/_ext/output.BEMEWS.cpp b/src/BEMEWS/_ext/output.BEMEWS.cpp index d2eb79c..be0518c 100644 --- a/src/BEMEWS/_ext/output.BEMEWS.cpp +++ b/src/BEMEWS/_ext/output.BEMEWS.cpp @@ -70,7 +70,7 @@ void Output_Pvslambda(bool firsttime,bool lasttime,ofstream &fPvslambda,double l vector > > kk(NM,vector >(NE)); vector > > dkk(NM,vector >(NE)); - const string delimiter = ecsvformat ? string(",") : string("\t"); + const string delimiter = ecsvformat ? string(" ") : string("\t"); int i; #pragma omp parallel for schedule(static) @@ -123,6 +123,7 @@ void Output_Pvslambda(bool firsttime,bool lasttime,ofstream &fPvslambda,double l if(firsttime==true){ if (ecsvformat) { + // ECSV YAML header fPvslambda << "# %ECSV 1.0\n# ---\n# datatype:\n" << "# - {name: lambda, unit: cm, datatype: float64, description: path length}\n" << "# - {name: r, unit: cm, datatype: float64, description: radial distance}\n"; @@ -134,19 +135,31 @@ void Output_Pvslambda(bool firsttime,bool lasttime,ofstream &fPvslambda,double l for (int j=0; j<2; ++j) for (int k=1; k<=3; ++k) for (int l=1; l<=3; ++l) - fPvslambda << "# - {name: P" << pcl[j] << k << l << ", datetype: float64, description: " << k << "->" << l << " transition probability\n"; + fPvslambda << "# - {name: P" << pcl[j] << k << l << ", datatype: float64, description: " << k << "->" << l << " transition probability}\n"; // Flavor-mass transitions for (int j=0; j<2; ++j) for (int k=0; k<=2; ++k) for (int l=1; l<=3; ++l) - fPvslambda << "# - {name: P" << pcl[j] << flavor[k] << l << ", datetype: float64, description: " << flavor[k] << "->" << l << " transition probability\n"; + fPvslambda << "# - {name: P" << pcl[j] << flavor[k] << l << ", datatype: float64, description: " << flavor[k] << "->" << l << " transition probability}\n"; // Flavor-flavor transitions for (int j=0; j<2; ++j) for (int k=0; k<=2; ++k) for (int l=0; l<=2; ++l) - fPvslambda << "# - {name: P" << pcl[j] << flavor[k] << flavor[l] << ", datetype: float64, description: " << flavor[k] << "->" << flavor[l] << " transition probability\n"; + fPvslambda << "# - {name: P" << pcl[j] << flavor[k] << flavor[l] << ", datatype: float64, description: " << flavor[k] << "->" << flavor[l] << " transition probability}\n"; + + // First-line column names + fPvslambda<<"lambda r"; + + fPvslambda<<" P11 P12 P13 P21 P22 P23 P31 P32 P33"; + fPvslambda<<" Pbar11 Pbar12 Pbar13 Pbar21 Pbar22 Pbar23 Pbar31 Pbar32 Pbar33"; + + fPvslambda<<" Pe1 Pe2 Pe3 Pmu1 Pmu2 Pmu3 Ptau1 Ptau2 Ptau3"; + fPvslambda<<" Pbare1 Pbare2 Pbare3 Pbarmu1 Pbarmu2 Pbarmu3 Pbartau1 Pbartau2 Pbartau3"; + + fPvslambda<<" Pee Pemu Petau Pmue Pmumu Pmutau Ptaue Ptaumu Ptautau"; + fPvslambda<<" Pbaree Pbaremu Pbaretau Pbarmue Pbarmumu Pbarmutau Pbartaue Pbartaumu Pbartautau"; } else { fPvslambda<<"lambda [cm] \t r [cm]"; @@ -288,6 +301,7 @@ void Output_PvsE(bool lasttime,ofstream &fPvsE,string outputfilenamestem,double // ******* if (ecsvformat) { + // ECSV YAML header fPvsE << "# %ECSV 1.0\n# ---\n# datatype:\n" << "# - {name: E, unit: MeV, datatype: float64, description: neutrino energy}\n"; @@ -298,19 +312,31 @@ void Output_PvsE(bool lasttime,ofstream &fPvsE,string outputfilenamestem,double for (int j=0; j<2; ++j) for (int k=1; k<=3; ++k) for (int l=1; l<=3; ++l) - fPvsE << "# - {name: P" << pcl[j] << k << l << ", datetype: float64, description: " << k << "->" << l << " transition probability\n"; + fPvsE << "# - {name: P" << pcl[j] << k << l << ", datatype: float64, description: " << k << "->" << l << " transition probability}\n"; // Flavor-mass transitions for (int j=0; j<2; ++j) for (int k=0; k<=2; ++k) for (int l=1; l<=3; ++l) - fPvsE << "# - {name: P" << pcl[j] << flavor[k] << l << ", datetype: float64, description: " << flavor[k] << "->" << l << " transition probability\n"; + fPvsE << "# - {name: P" << pcl[j] << flavor[k] << l << ", datatype: float64, description: " << flavor[k] << "->" << l << " transition probability}\n"; // Flavor-flavor transitions for (int j=0; j<2; ++j) for (int k=0; k<=2; ++k) for (int l=0; l<=2; ++l) - fPvsE << "# - {name: P" << pcl[j] << flavor[k] << flavor[l] << ", datetype: float64, description: " << flavor[k] << "->" << flavor[l] << " transition probability\n"; + fPvsE << "# - {name: P" << pcl[j] << flavor[k] << flavor[l] << ", datatype: float64, description: " << flavor[k] << "->" << flavor[l] << " transition probability}\n"; + + // First line: column names + fPvsE<<"E"; + + fPvsE<<" P11 P12 P13 P21 P22 P23 P31 P32 P33"; + fPvsE<<" Pbar11 Pbar12 Pbar13 Pbar21 Pbar22 Pbar23 Pbar31 Pbar32 Pbar33"; + + fPvsE<<" Pe1 Pe2 Pe3 Pmu1 Pmu2 Pmu3 Ptau1 Ptau2 Ptau3"; + fPvsE<<" Pbare1 Pbare2 Pbare3 Pbarmu1 Pbarmu2 Pbarmu3 Pbartau1 Pbartau2 Pbartau3"; + + fPvsE<<" Pee Pemu Petau Pmue Pmumu Pmutau Ptaue Ptaumu Ptautau"; + fPvsE<<" Pbaree Pbaremu Pbaretau Pbarmue Pbarmumu Pbarmutau Pbartaue Pbartaumu Pbartautau"; } else { fPvsE<<"E [MeV]"; @@ -325,7 +351,7 @@ void Output_PvsE(bool lasttime,ofstream &fPvsE,string outputfilenamestem,double fPvsE<<"\t Pbaree \t Pbaremu \t Pbaretau \t Pbarmue \t Pbarmumu \t Pbarmutau \t Pbartaue \t Pbartaumu \t Pbartautau"; } - const string delimiter = ecsvformat ? string(",") : string("\t"); + const string delimiter = ecsvformat ? string(" ") : string("\t"); for(i=0;i<=NE-1;i++) { fPvsE << "\n" << E[i]/(mega*cgs::units::eV); @@ -385,7 +411,7 @@ void Output_Hvslambda(bool firsttime,bool lasttime,ofstream &fHvslambda,double l } // ************** - const string delimiter = ecsvformat ? string(",") : string("\t"); + const string delimiter = ecsvformat ? string(" ") : string("\t"); if(firsttime==true){ if (ecsvformat) { @@ -395,6 +421,7 @@ void Output_Hvslambda(bool firsttime,bool lasttime,ofstream &fHvslambda,double l << "# - {name: rho, unit: g / cm3, datatype: float64, description: density}\n" << "# - {name: Ye, datatype: float64, description: electron fraction}\n" << "# - {name: HMSW_ee, unit: erg, datatype: float64, description: MSW potential}\n"; + fHvslambda << "lambda r rho Ye HMSW_ee"; } else { fHvslambda << "lambda [cm] \t r [cm] \t rho [g/cm^3] \t Ye [] \t HMSW_ee [erg]"; From 498ac3be5b6da6d4bf627a268cd5b109e8965abc Mon Sep 17 00:00:00 2001 From: Segev BenZvi Date: Tue, 13 Aug 2024 21:12:56 -0500 Subject: [PATCH 6/7] Pass ID to output, store settings in ECSV meta. --- src/BEMEWS/_ext/BEMEWS.cpp | 26 +++++------ src/BEMEWS/_ext/output.BEMEWS.cpp | 76 +++++++++++++++++++++++++------ src/BEMEWS/_ext/output.h | 10 ++-- 3 files changed, 81 insertions(+), 31 deletions(-) diff --git a/src/BEMEWS/_ext/BEMEWS.cpp b/src/BEMEWS/_ext/BEMEWS.cpp index b3fd6e5..1776bdf 100644 --- a/src/BEMEWS/_ext/BEMEWS.cpp +++ b/src/BEMEWS/_ext/BEMEWS.cpp @@ -163,7 +163,7 @@ vector > > > Run(InputDataBEMEWS ID) ofstream fHvslambda; // a file for anything else ofstream fSvsE; - if(ID.outputflag==true){ Initialize_Output(outputfilenamestem,fPvslambda,fHvslambda,ID.ecsvformat);} + if(ID.outputflag==true){ Initialize_Output(outputfilenamestem,fPvslambda,fHvslambda,ID);} // ***************************************************** // ***************************************************** @@ -331,14 +331,14 @@ vector > > > Run(InputDataBEMEWS ID) if(ID.outputflag==true){ output=true;} if(output==true){ if(firsttime==true){ - Output_Pvslambda(firsttime,lasttime,fPvslambda,lambdamin,Y,Scumulative,ID.ecsvformat); - Output_Hvslambda(firsttime,lasttime,fHvslambda,lambdamin,Y,Scumulative,ID.ecsvformat); + Output_Pvslambda(firsttime,lasttime,fPvslambda,lambdamin,Y,Scumulative,ID); + Output_Hvslambda(firsttime,lasttime,fHvslambda,lambdamin,Y,Scumulative,ID); } firsttime = false; - Output_Pvslambda(firsttime,lasttime,fPvslambda,lambdamin,Y,Scumulative,ID.ecsvformat); - Output_Hvslambda(firsttime,lasttime,fHvslambda,lambdamin,Y,Scumulative,ID.ecsvformat); + Output_Pvslambda(firsttime,lasttime,fPvslambda,lambdamin,Y,Scumulative,ID); + Output_Hvslambda(firsttime,lasttime,fHvslambda,lambdamin,Y,Scumulative,ID); output = false; } @@ -455,9 +455,9 @@ vector > > > Run(InputDataBEMEWS ID) if(output==true) { cout<<"\nOutput at\t"< > > > Run(InputDataBEMEWS ID) else{ // output at the end of the code if(ID.outputflag==true){ output = true;} if(output==true){ - Output_Pvslambda(firsttime,lasttime,fPvslambda,lambdamax,Y,Scumulative,ID.ecsvformat); - Output_Hvslambda(firsttime,lasttime,fHvslambda,lambdamax,Y,Scumulative,ID.ecsvformat); + Output_Pvslambda(firsttime,lasttime,fPvslambda,lambdamax,Y,Scumulative,ID); + Output_Hvslambda(firsttime,lasttime,fHvslambda,lambdamax,Y,Scumulative,ID); lasttime = true; - Output_Pvslambda(firsttime,lasttime,fPvslambda,lambdamax,Y,Scumulative,ID.ecsvformat); - Output_Hvslambda(firsttime,lasttime,fHvslambda,lambdamax,Y,Scumulative,ID.ecsvformat); - Output_PvsE(lasttime,fPvsE,outputfilenamestem,lambdamax,Y,Scumulative,ID.ecsvformat); + Output_Pvslambda(firsttime,lasttime,fPvslambda,lambdamax,Y,Scumulative,ID); + Output_Hvslambda(firsttime,lasttime,fHvslambda,lambdamax,Y,Scumulative,ID); + Output_PvsE(lasttime,fPvsE,outputfilenamestem,lambdamax,Y,Scumulative,ID); output = false; } diff --git a/src/BEMEWS/_ext/output.BEMEWS.cpp b/src/BEMEWS/_ext/output.BEMEWS.cpp index be0518c..81e3570 100644 --- a/src/BEMEWS/_ext/output.BEMEWS.cpp +++ b/src/BEMEWS/_ext/output.BEMEWS.cpp @@ -18,7 +18,7 @@ using namespace prefixes; std::vector fPvslambdafilename; -void Initialize_Output(string outputfilenamestem,ofstream &fPvslambda,ofstream &fHvslambda, bool ecsvformat) +void Initialize_Output(string outputfilenamestem,ofstream &fPvslambda,ofstream &fHvslambda, const InputDataBEMEWS &id) { stringstream filename; fPvslambdafilename=vector(NE); @@ -27,18 +27,18 @@ void Initialize_Output(string outputfilenamestem,ofstream &fPvslambda,ofstream & { filename.str(""); if(NE>1){ filename << outputfilenamestem << string(":E=") << ((NE-1.-i)*EminMeV+i*EmaxMeV)/(NE-1.) - << (ecsvformat ? string("MeV:Pvslambda.ecsv") : string("MeV:Pvslambda.dat")); + << (id.ecsvformat ? string("MeV:Pvslambda.ecsv") : string("MeV:Pvslambda.dat")); } else{ filename << outputfilenamestem << string(":E=") << EminMeV - << (ecsvformat ? string("MeV:Pvslambda.ecsv") : string("MeV:Pvslambda.dat")); + << (id.ecsvformat ? string("MeV:Pvslambda.ecsv") : string("MeV:Pvslambda.dat")); } fPvslambdafilename[i]=filename.str(); fPvslambda.open(fPvslambdafilename[i].c_str()); fPvslambda.close(); // clears the file } filename.str(""); - filename << outputfilenamestem << (ecsvformat ? string(":Hvslambda.ecsv") : string(":Hvslambda.dat")); + filename << outputfilenamestem << (id.ecsvformat ? string(":Hvslambda.ecsv") : string(":Hvslambda.dat")); fHvslambda.open((filename.str()).c_str()); fHvslambda.precision(12); } @@ -50,7 +50,7 @@ void Close_Output(ofstream &fHvslambda) // ****************************************************** -void Output_Pvslambda(bool firsttime,bool lasttime,ofstream &fPvslambda,double lambda,vector > > &Y,vector,NF,NF> > > &Scumulative, bool ecsvformat) +void Output_Pvslambda(bool firsttime,bool lasttime,ofstream &fPvslambda,double lambda,vector > > &Y,vector,NF,NF> > > &Scumulative, const InputDataBEMEWS &id) { array,NF,NF>,NM> VfMSW, dVfMSWdlambda; double r = sqrt( RE*RE + lambda*lambda - 2.*RE*lambda*sin(-altitude) ); @@ -70,7 +70,7 @@ void Output_Pvslambda(bool firsttime,bool lasttime,ofstream &fPvslambda,double l vector > > kk(NM,vector >(NE)); vector > > dkk(NM,vector >(NE)); - const string delimiter = ecsvformat ? string(" ") : string("\t"); + const string delimiter = id.ecsvformat ? string(" ") : string("\t"); int i; #pragma omp parallel for schedule(static) @@ -122,7 +122,7 @@ void Output_Pvslambda(bool firsttime,bool lasttime,ofstream &fPvslambda,double l fPvslambda.precision(12); if(firsttime==true){ - if (ecsvformat) { + if (id.ecsvformat) { // ECSV YAML header fPvslambda << "# %ECSV 1.0\n# ---\n# datatype:\n" << "# - {name: lambda, unit: cm, datatype: float64, description: path length}\n" @@ -149,6 +149,21 @@ void Output_Pvslambda(bool firsttime,bool lasttime,ofstream &fPvslambda,double l for (int l=0; l<=2; ++l) fPvslambda << "# - {name: P" << pcl[j] << flavor[k] << flavor[l] << ", datatype: float64, description: " << flavor[k] << "->" << flavor[l] << " transition probability}\n"; + // Simulation settings metadata + fPvslambda << "# meta: !!omap\n" + << "# - settings:\n" + << "# - {Ebins: " << id.NE << ", description: number of energy bins}\n" + << "# - {Emin: " << id.Emin << ", unit: MeV, description: minimum energy}\n" + << "# - {Emax: " << id.Emax << ", unit: MeV, description: maximum energy}\n" + << "# - {deltam_21: " << id.deltam_21 << ", unit: eV2, description: 2->1 mass splitting}\n" + << "# - {deltam_32: " << id.deltam_32 << ", unit: eV2, description: 3->2 mass splitting}\n" + << "# - {theta_12: " << id.theta12 << ", unit: deg, description: 1->2 mixing angle}\n" + << "# - {theta_13: " << id.theta13 << ", unit: deg, description: 1->3 mixing angle}\n" + << "# - {theta_23: " << id.theta23 << ", unit: deg, description: 2->3 mixing angle}\n" + << "# - {delta_CP: " << id.deltaCP << ", unit: deg, description: CP violating phase}\n" + << "# - {accuracy: " << id.accuracy << ", description: accuracy of Runge-Kutta solver}\n" + << "# - {stepcounterlimit: " << id.stepcounterlimit << ", description: output data every N steps}\n"; + // First-line column names fPvslambda<<"lambda r"; @@ -210,8 +225,8 @@ void Output_Pvslambda(bool firsttime,bool lasttime,ofstream &fPvslambda,double l // ************************************************************************ -void Output_PvsE(bool lasttime,ofstream &fPvsE,string outputfilenamestem,double lambda,vector > > &Y,vector,NF,NF> > > &Scumulative, bool ecsvformat) - { string cmdotdat = ecsvformat ? string("cm.ecsv") : string("cm.dat"); +void Output_PvsE(bool lasttime,ofstream &fPvsE,string outputfilenamestem,double lambda,vector > > &Y,vector,NF,NF> > > &Scumulative, const InputDataBEMEWS &id) + { string cmdotdat = id.ecsvformat ? string("cm.ecsv") : string("cm.dat"); stringstream filename; if(lasttime==false){ @@ -300,7 +315,7 @@ void Output_PvsE(bool lasttime,ofstream &fPvsE,string outputfilenamestem,double // ******* - if (ecsvformat) { + if (id.ecsvformat) { // ECSV YAML header fPvsE << "# %ECSV 1.0\n# ---\n# datatype:\n" << "# - {name: E, unit: MeV, datatype: float64, description: neutrino energy}\n"; @@ -326,6 +341,21 @@ void Output_PvsE(bool lasttime,ofstream &fPvsE,string outputfilenamestem,double for (int l=0; l<=2; ++l) fPvsE << "# - {name: P" << pcl[j] << flavor[k] << flavor[l] << ", datatype: float64, description: " << flavor[k] << "->" << flavor[l] << " transition probability}\n"; + // Simulation settings metadata + fPvsE << "# meta: !!omap\n" + << "# - settings:\n" + << "# - {Ebins: " << id.NE << ", description: number of energy bins}\n" + << "# - {Emin: " << id.Emin << ", unit: MeV, description: minimum energy}\n" + << "# - {Emax: " << id.Emax << ", unit: MeV, description: maximum energy}\n" + << "# - {deltam_21: " << id.deltam_21 << ", unit: eV2, description: 2->1 mass splitting}\n" + << "# - {deltam_32: " << id.deltam_32 << ", unit: eV2, description: 3->2 mass splitting}\n" + << "# - {theta_12: " << id.theta12 << ", unit: deg, description: 1->2 mixing angle}\n" + << "# - {theta_13: " << id.theta13 << ", unit: deg, description: 1->3 mixing angle}\n" + << "# - {theta_23: " << id.theta23 << ", unit: deg, description: 2->3 mixing angle}\n" + << "# - {delta_CP: " << id.deltaCP << ", unit: deg, description: CP violating phase}\n" + << "# - {accuracy: " << id.accuracy << ", description: accuracy of Runge-Kutta solver}\n" + << "# - {stepcounterlimit: " << id.stepcounterlimit << ", description: output data every N steps}\n"; + // First line: column names fPvsE<<"E"; @@ -351,7 +381,7 @@ void Output_PvsE(bool lasttime,ofstream &fPvsE,string outputfilenamestem,double fPvsE<<"\t Pbaree \t Pbaremu \t Pbaretau \t Pbarmue \t Pbarmumu \t Pbarmutau \t Pbartaue \t Pbartaumu \t Pbartautau"; } - const string delimiter = ecsvformat ? string(" ") : string("\t"); + const string delimiter = id.ecsvformat ? string(" ") : string("\t"); for(i=0;i<=NE-1;i++) { fPvsE << "\n" << E[i]/(mega*cgs::units::eV); @@ -387,7 +417,7 @@ void Output_PvsE(bool lasttime,ofstream &fPvsE,string outputfilenamestem,double // ************************************************************************ -void Output_Hvslambda(bool firsttime,bool lasttime,ofstream &fHvslambda,double lambda,vector > > &Y,vector,NF,NF> > > &Scumulative, bool ecsvformat) +void Output_Hvslambda(bool firsttime,bool lasttime,ofstream &fHvslambda,double lambda,vector > > &Y,vector,NF,NF> > > &Scumulative, const InputDataBEMEWS &id) { MATRIX,NF,NF> VfMSW,VfMSWbar; double r, rrho, YYe; @@ -411,16 +441,34 @@ void Output_Hvslambda(bool firsttime,bool lasttime,ofstream &fHvslambda,double l } // ************** - const string delimiter = ecsvformat ? string(" ") : string("\t"); + const string delimiter = id.ecsvformat ? string(" ") : string("\t"); if(firsttime==true){ - if (ecsvformat) { + if (id.ecsvformat) { + // YAML header with datatypes fHvslambda << "# %ECSV 1.0\n# ---\n# datatype:\n" << "# - {name: lambda, unit: cm, datatype: float64, description: path length}\n" << "# - {name: r, unit: cm, datatype: float64, description: radial distance}\n" << "# - {name: rho, unit: g / cm3, datatype: float64, description: density}\n" << "# - {name: Ye, datatype: float64, description: electron fraction}\n" << "# - {name: HMSW_ee, unit: erg, datatype: float64, description: MSW potential}\n"; + + // Simulation settings metadata + fHvslambda << "# meta: !!omap\n" + << "# - settings:\n" + << "# - {Ebins: " << id.NE << ", description: number of energy bins}\n" + << "# - {Emin: " << id.Emin << ", unit: MeV, description: minimum energy}\n" + << "# - {Emax: " << id.Emax << ", unit: MeV, description: maximum energy}\n" + << "# - {deltam_21: " << id.deltam_21 << ", unit: eV2, description: 2->1 mass splitting}\n" + << "# - {deltam_32: " << id.deltam_32 << ", unit: eV2, description: 3->2 mass splitting}\n" + << "# - {theta_12: " << id.theta12 << ", unit: deg, description: 1->2 mixing angle}\n" + << "# - {theta_13: " << id.theta13 << ", unit: deg, description: 1->3 mixing angle}\n" + << "# - {theta_23: " << id.theta23 << ", unit: deg, description: 2->3 mixing angle}\n" + << "# - {delta_CP: " << id.deltaCP << ", unit: deg, description: CP violating phase}\n" + << "# - {accuracy: " << id.accuracy << ", description: accuracy of Runge-Kutta solver}\n" + << "# - {stepcounterlimit: " << id.stepcounterlimit << ", description: output data every N steps}\n"; + + // First line with column names fHvslambda << "lambda r rho Ye HMSW_ee"; } else { diff --git a/src/BEMEWS/_ext/output.h b/src/BEMEWS/_ext/output.h index 777f642..6a12034 100644 --- a/src/BEMEWS/_ext/output.h +++ b/src/BEMEWS/_ext/output.h @@ -1,19 +1,21 @@ #include "BEMEWS.h" +struct InputDataBEMEWS; + #ifndef output_H #define output_H extern std::vector fPvsrfilename; -void Initialize_Output(std::string outputfilenamestem, std::ofstream &fPvslambda, std::ofstream &fHvslambda, bool ecsvformat=false); +void Initialize_Output(std::string outputfilenamestem, std::ofstream &fPvslambda, std::ofstream &fHvslambda, const InputDataBEMEWS &id); void Close_Output(std::ofstream &fHvslambda); -void Output_Pvslambda(bool firsttime, bool lasttime, std::ofstream &fPvslambda, double lambda, std::vector > > &Y, std::vector, NF, NF> > > &Scumulative, bool ecsvformat=false); +void Output_Pvslambda(bool firsttime, bool lasttime, std::ofstream &fPvslambda, double lambda, std::vector > > &Y, std::vector, NF, NF> > > &Scumulative, const InputDataBEMEWS &id); -void Output_PvsE(bool lasttime, std::ofstream &fPvsE, std::string outputfilenamestem, double lambda, std::vector > > &Y, std::vector, NF, NF> > > &Scumulative, bool ecsvformat=false); +void Output_PvsE(bool lasttime, std::ofstream &fPvsE, std::string outputfilenamestem, double lambda, std::vector > > &Y, std::vector, NF, NF> > > &Scumulative, const InputDataBEMEWS &id); -void Output_Hvslambda(bool firsttime, bool lasttime, std::ofstream &fHvslambda, double lambda, std::vector > > &Y, std::vector, NF, NF> > > &Scumulative, bool ecsvformat=false); +void Output_Hvslambda(bool firsttime, bool lasttime, std::ofstream &fHvslambda, double lambda, std::vector > > &Y, std::vector, NF, NF> > > &Scumulative, const InputDataBEMEWS &id); #endif From ac1ee63cbdf34fb5b99f75b7fd32315628b0ec82 Mon Sep 17 00:00:00 2001 From: Segev BenZvi Date: Wed, 14 Aug 2024 14:06:57 -0500 Subject: [PATCH 7/7] Final cleanup for ECSV output option. --- BEMEWS_example.py | 11 +++++++---- config.ini | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/BEMEWS_example.py b/BEMEWS_example.py index f96efa7..ffe1b7f 100644 --- a/BEMEWS_example.py +++ b/BEMEWS_example.py @@ -45,6 +45,10 @@ help='Maximum energy ax MeV') p.add_argument('--accuracy', type=float, help='Accuracy of Runge-Kutta solver') + p.add_argument('--output', action='store_true', + help='Output calculations to file(s)') + p.add_argument('--ecsvformat', action='store_true', + help='Output using astropy-compatible ECSV format') p.add_argument('--stepcounterlimit', type=int, help='Output every N steps through the Earth (higher = less output)') @@ -57,9 +61,7 @@ for k in config.keys(): defaults.update(dict(config[k])) settings = defaults - settings.update({k: v for k, v in args.items() if v is not None}) - - print(settings) + settings.update({k: v for k, v in args.items() if v is not None and v is not False}) # skycoordinates of neutrino source source = SkyCoord.from_name(settings['source']) @@ -103,8 +105,9 @@ # if set to True the BEMEWS module will output files in the 'out' directory # The stepcounterlimit controls how often output is written. The larger the number, the less often it happens. ID.outputflag = settings['output'] in ['True', 'true'] + ID.ecsvformat = settings['ecsvformat'] if isinstance(settings['ecsvformat'], bool) else settings['ecsvformat'] in ['True', 'true'] ID.stepcounterlimit = int(settings['stepcounterlimit']) - + if ID.outputflag: os.makedirs('out', exist_ok=True) diff --git a/config.ini b/config.ini index 2e6b58b..0d1ec67 100644 --- a/config.ini +++ b/config.ini @@ -23,4 +23,5 @@ Emin = 1 Emax = 60 accuracy = 1.01e-9 output = True +ecsvformat = False stepcounterlimit = 1