From 483e9325fc0495d9c430fb778be65b83eec0e161 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Wed, 22 Apr 2020 21:40:12 -0500 Subject: [PATCH] Changes in reaction.cpp from PullRequest Inc. review --- src/reaction.cpp | 285 ++++++++++++++++++----------------------------- src/thermal.cpp | 2 +- 2 files changed, 108 insertions(+), 179 deletions(-) diff --git a/src/reaction.cpp b/src/reaction.cpp index ce0090752..fbe2c34de 100644 --- a/src/reaction.cpp +++ b/src/reaction.cpp @@ -1,6 +1,7 @@ #include "openmc/reaction.h" #include +#include #include // for move #include @@ -86,190 +87,118 @@ Reaction::Reaction(hid_t group, const std::vector& temperatures) // Non-member functions //============================================================================== +const std::unordered_map REACTION_NAME_MAP { + {SCORE_FLUX, "flux"}, + {SCORE_TOTAL, "total"}, + {SCORE_SCATTER, "scatter"}, + {SCORE_NU_SCATTER, "nu-scatter"}, + {SCORE_ABSORPTION, "absorption"}, + {SCORE_FISSION, "fission"}, + {SCORE_NU_FISSION, "nu-fission"}, + {SCORE_DECAY_RATE, "decay-rate"}, + {SCORE_DELAYED_NU_FISSION, "delayed-nu-fission"}, + {SCORE_PROMPT_NU_FISSION, "prompt-nu-fission"}, + {SCORE_KAPPA_FISSION, "kappa-fission"}, + {SCORE_CURRENT, "current"}, + {SCORE_EVENTS, "events"}, + {SCORE_INVERSE_VELOCITY, "inverse-velocity"}, + {SCORE_FISS_Q_PROMPT, "fission-q-prompt"}, + {SCORE_FISS_Q_RECOV, "fission-q-recoverable"}, + // Normal ENDF-based reactions + {TOTAL_XS, "(n,total)"}, + {ELASTIC, "(n,elastic)"}, + {N_LEVEL, "(n,level)"}, + {N_2ND, "(n,2nd)"}, + {N_2N, "(n,2n)"}, + {N_3N, "(n,3n)"}, + {N_FISSION, "(n,fission)"}, + {N_F, "(n,f)"}, + {N_NF, "(n,nf)"}, + {N_2NF, "(n,2nf)"}, + {N_NA, "(n,na)"}, + {N_N3A, "(n,n3a)"}, + {N_2NA, "(n,2na)"}, + {N_3NA, "(n,3na)"}, + {N_NP, "(n,np)"}, + {N_N2A, "(n,n2a)"}, + {N_2N2A, "(n,2n2a)"}, + {N_ND, "(n,nd)"}, + {N_NT, "(n,nt)"}, + {N_N3HE, "(n,nHe-3)"}, + {N_ND2A, "(n,nd2a)"}, + {N_NT2A, "(n,nt2a)"}, + {N_4N, "(n,4n)"}, + {N_3NF, "(n,3nf)"}, + {N_2NP, "(n,2np)"}, + {N_3NP, "(n,3np)"}, + {N_N2P, "(n,n2p)"}, + {N_NPA, "(n,npa)"}, + {N_NC, "(n,nc)"}, + {N_DISAPPEAR, "(n,disappear)"}, + {N_GAMMA, "(n,gamma)"}, + {N_P, "(n,p)"}, + {N_D, "(n,d)"}, + {N_T, "(n,t)"}, + {N_3HE, "(n,3He)"}, + {N_A, "(n,a)"}, + {N_2A, "(n,2a)"}, + {N_3A, "(n,3a)"}, + {N_2P, "(n,2p)"}, + {N_PA, "(n,pa)"}, + {N_T2A, "(n,t2a)"}, + {N_D2A, "(n,d2a)"}, + {N_PD, "(n,pd)"}, + {N_PT, "(n,pt)"}, + {N_DA, "(n,da)"}, + {201, "(n,Xn)"}, + {202, "(n,Xgamma)"}, + {N_XP, "(n,Xp)"}, + {N_XD, "(n,Xd)"}, + {N_XT, "(n,Xt)"}, + {N_X3HE, "(n,X3He)"}, + {N_XA, "(n,Xa)"}, + {HEATING, "heating"}, + {DAMAGE_ENERGY, "damage-energy"}, + {COHERENT, "coherent scatter"}, + {INCOHERENT, "incoherent scatter"}, + {PAIR_PROD_ELEC, "pair production, electron"}, + {PAIR_PROD, "pair production"}, + {PAIR_PROD_NUC, "pair production, nuclear"}, + {PHOTOELECTRIC, "photoelectric"}, + {N_PC, "(n,pc)"}, + {N_DC, "(n,dc)"}, + {N_TC, "(n,tc)"}, + {N_3HEC, "(n,3Hec)"}, + {N_AC, "(n,ac)"}, + {N_2NC, "(n,2nc)"}, + {HEATING_LOCAL, "heating-local"}, +}; + std::string reaction_name(int mt) { - if (mt == SCORE_FLUX) { - return "flux"; - } else if (mt == SCORE_TOTAL) { - return "total"; - } else if (mt == SCORE_SCATTER) { - return "scatter"; - } else if (mt == SCORE_NU_SCATTER) { - return "nu-scatter"; - } else if (mt == SCORE_ABSORPTION) { - return "absorption"; - } else if (mt == SCORE_FISSION) { - return "fission"; - } else if (mt == SCORE_NU_FISSION) { - return "nu-fission"; - } else if (mt == SCORE_DECAY_RATE) { - return "decay-rate"; - } else if (mt == SCORE_DELAYED_NU_FISSION) { - return "delayed-nu-fission"; - } else if (mt == SCORE_PROMPT_NU_FISSION) { - return "prompt-nu-fission"; - } else if (mt == SCORE_KAPPA_FISSION) { - return "kappa-fission"; - } else if (mt == SCORE_CURRENT) { - return "current"; - } else if (mt == SCORE_EVENTS) { - return "events"; - } else if (mt == SCORE_INVERSE_VELOCITY) { - return "inverse-velocity"; - } else if (mt == SCORE_FISS_Q_PROMPT) { - return "fission-q-prompt"; - } else if (mt == SCORE_FISS_Q_RECOV) { - return "fission-q-recoverable"; - - // Normal ENDF-based reactions - } else if (mt == TOTAL_XS) { - return "(n,total)"; - } else if (mt == ELASTIC) { - return "(n,elastic)"; - } else if (mt == N_LEVEL) { - return "(n,level)"; - } else if (mt == N_2ND) { - return "(n,2nd)"; - } else if (mt == N_2N) { - return "(n,2n)"; - } else if (mt == N_3N) { - return "(n,3n)"; - } else if (mt == N_FISSION) { - return "(n,fission)"; - } else if (mt == N_F) { - return "(n,f)"; - } else if (mt == N_NF) { - return "(n,nf)"; - } else if (mt == N_2NF) { - return "(n,2nf)"; - } else if (mt == N_NA) { - return "(n,na)"; - } else if (mt == N_N3A) { - return "(n,n3a)"; - } else if (mt == N_2NA) { - return "(n,2na)"; - } else if (mt == N_3NA) { - return "(n,3na)"; - } else if (mt == N_NP) { - return "(n,np)"; - } else if (mt == N_N2A) { - return "(n,n2a)"; - } else if (mt == N_2N2A) { - return "(n,2n2a)"; - } else if (mt == N_ND) { - return "(n,nd)"; - } else if (mt == N_NT) { - return "(n,nt)"; - } else if (mt == N_N3HE) { - return "(n,nHe-3)"; - } else if (mt == N_ND2A) { - return "(n,nd2a)"; - } else if (mt == N_NT2A) { - return "(n,nt2a)"; - } else if (mt == N_4N) { - return "(n,4n)"; - } else if (mt == N_3NF) { - return "(n,3nf)"; - } else if (mt == N_2NP) { - return "(n,2np)"; - } else if (mt == N_3NP) { - return "(n,3np)"; - } else if (mt == N_N2P) { - return "(n,n2p)"; - } else if (mt == N_NPA) { - return "(n,npa)"; - } else if (N_N1 <= mt && mt <= N_N40) { + if (N_N1 <= mt && mt <= N_N40) { return fmt::format("(n,n{})", mt - 50); - } else if (mt == N_NC) { - return "(n,nc)"; - } else if (mt == N_DISAPPEAR) { - return "(n,disappear)"; - } else if (mt == N_GAMMA) { - return "(n,gamma)"; - } else if (mt == N_P) { - return "(n,p)"; - } else if (mt == N_D) { - return "(n,d)"; - } else if (mt == N_T) { - return "(n,t)"; - } else if (mt == N_3HE) { - return "(n,3He)"; - } else if (mt == N_A) { - return "(n,a)"; - } else if (mt == N_2A) { - return "(n,2a)"; - } else if (mt == N_3A) { - return "(n,3a)"; - } else if (mt == N_2P) { - return "(n,2p)"; - } else if (mt == N_PA) { - return "(n,pa)"; - } else if (mt == N_T2A) { - return "(n,t2a)"; - } else if (mt == N_D2A) { - return "(n,d2a)"; - } else if (mt == N_PD) { - return "(n,pd)"; - } else if (mt == N_PT) { - return "(n,pt)"; - } else if (mt == N_DA) { - return "(n,da)"; - } else if (mt == 201) { - return "(n,Xn)"; - } else if (mt == 202) { - return "(n,Xgamma)"; - } else if (mt == N_XP) { - return "(n,Xp)"; - } else if (mt == N_XD) { - return "(n,Xd)"; - } else if (mt == N_XT) { - return "(n,Xt)"; - } else if (mt == N_X3HE) { - return "(n,X3He)"; - } else if (mt == N_XA) { - return "(n,Xa)"; - } else if (mt == HEATING) { - return "heating"; - } else if (mt == DAMAGE_ENERGY) { - return "damage-energy"; - } else if (mt == COHERENT) { - return "coherent scatter"; - } else if (mt == INCOHERENT) { - return "incoherent scatter"; - } else if (mt == PAIR_PROD_ELEC) { - return "pair production, electron"; - } else if (mt == PAIR_PROD) { - return "pair production"; - } else if (mt == PAIR_PROD_NUC) { - return "pair production, nuclear"; - } else if (mt == PHOTOELECTRIC) { - return "photoelectric"; } else if (534 <= mt && mt <= 572) { return fmt::format("photoelectric, {} subshell", SUBSHELLS[mt - 534]); - } else if (600 <= mt && mt <= 648) { - return fmt::format("(n,p{})", mt - 600); - } else if (mt == 649) { - return "(n,pc)"; - } else if (650 <= mt && mt <= 698) { - return fmt::format("(n,d{})", mt - 650); - } else if (mt == 699) { - return "(n,dc)"; - } else if (700 <= mt && mt <= 748) { - return fmt::format("(n,t{})", mt - 700); - } else if (mt == 749) { - return "(n,tc)"; - } else if (750 <= mt && mt <= 798) { - return fmt::format("(n,3He{})", mt - 750); - } else if (mt == 799) { - return "(n,3Hec)"; - } else if (800 <= mt && mt <= 848) { - return fmt::format("(n,a{})", mt - 800); - } else if (mt == 849) { - return "(n,ac)"; - } else if (mt == HEATING_LOCAL) { - return "heating-local"; + } else if (N_P0 <= mt && mt < N_PC) { + return fmt::format("(n,p{})", mt - N_P0); + } else if (N_D0 <= mt && mt < N_DC) { + return fmt::format("(n,d{})", mt - N_D0); + } else if (N_T0 <= mt && mt < N_TC) { + return fmt::format("(n,t{})", mt - N_T0); + } else if (N_3HE0 <= mt && mt < N_3HEC) { + return fmt::format("(n,3He{})", mt - N_3HE0); + } else if (N_A0 <= mt && mt < N_AC) { + return fmt::format("(n,a{})", mt - N_A0); + } else if (N_2N0 <= mt && mt < N_2NC) { + return fmt::format("(n,2n{})", mt - N_2N0); } else { - return fmt::format("MT={}", mt); + auto it = REACTION_NAME_MAP.find(mt); + if (it != REACTION_NAME_MAP.end()) { + return it->second; + } else { + return fmt::format("MT={}", mt); + } } } diff --git a/src/thermal.cpp b/src/thermal.cpp index 67ca8905f..352ca8dd3 100644 --- a/src/thermal.cpp +++ b/src/thermal.cpp @@ -135,7 +135,7 @@ ThermalScattering::ThermalScattering(hid_t group, const std::vector& tem read_dataset(kT_group, temp_str.data(), kT); kTs_.push_back(kT); - // Open group for temperature i + // Open group for this temperature hid_t T_group = open_group(group, temp_str.data()); data_.emplace_back(T_group); close_group(T_group);