From f104eff31026ebaef3a4c2056c3ca1b49e3f2178 Mon Sep 17 00:00:00 2001 From: "Eric T. Johnson" Date: Tue, 28 Nov 2023 16:33:34 -0800 Subject: [PATCH] Add constants for the allowed values of SCREEN_METHOD (#1401) An enum would be much nicer here, but the preprocessor doesn't understand those. --- Make.Microphysics_extern | 12 ++++++------ nse_solver/nse_solver.H | 4 ++-- screening/screen.H | 35 +++++++++++++++++++++-------------- screening/screen_data.H | 16 ++++++++-------- 4 files changed, 37 insertions(+), 30 deletions(-) diff --git a/Make.Microphysics_extern b/Make.Microphysics_extern index 063e029934..28526b39d2 100644 --- a/Make.Microphysics_extern +++ b/Make.Microphysics_extern @@ -23,15 +23,15 @@ endif SCREEN_METHOD ?= screen5 ifeq ($(SCREEN_METHOD), null) - DEFINES += -DSCREEN_METHOD=0 + DEFINES += -DSCREEN_METHOD=SCREEN_METHOD_null else ifeq ($(SCREEN_METHOD), screen5) - DEFINES += -DSCREEN_METHOD=1 + DEFINES += -DSCREEN_METHOD=SCREEN_METHOD_screen5 else ifeq ($(SCREEN_METHOD), chugunov2007) - DEFINES += -DSCREEN_METHOD=2 + DEFINES += -DSCREEN_METHOD=SCREEN_METHOD_chugunov2007 else ifeq ($(SCREEN_METHOD), chugunov2009) - DEFINES += -DSCREEN_METHOD=3 + DEFINES += -DSCREEN_METHOD=SCREEN_METHOD_chugunov2009 else ifeq ($(SCREEN_METHOD), chabrier1998) - DEFINES += -DSCREEN_METHOD=4 + DEFINES += -DSCREEN_METHOD=SCREEN_METHOD_chabrier1998 else $(error Invalid value for SCREEN_METHOD) endif @@ -155,4 +155,4 @@ endif clean:: @if [ -L helm_table.dat ]; then rm -f helm_table.dat; fi @if [ -L reaclib_rate_metadata.dat ]; then rm -f reaclib_rate_metadata.dat; fi - $(foreach t, $(wildcard *_betadecay.dat *_electroncapture.dat nse*.tbl), $(shell if [ -L $t ]; then rm -f $t; fi)) \ No newline at end of file + $(foreach t, $(wildcard *_betadecay.dat *_electroncapture.dat nse*.tbl), $(shell if [ -L $t ]; then rm -f $t; fi)) diff --git a/nse_solver/nse_solver.H b/nse_solver/nse_solver.H index b357f2c16b..3b6578f40f 100644 --- a/nse_solver/nse_solver.H +++ b/nse_solver/nse_solver.H @@ -92,7 +92,7 @@ void apply_nse_exponent(T& nse_state) { // if we use chabrier1998 screening // Get the required terms to calculate coulomb correction term, u_c -#if SCREEN_METHOD == 4 +#if SCREEN_METHOD == SCREEN_METHOD_chabrier1998 // Find n_e for original state; const amrex::Real n_e = nse_state.rho * nse_state.y_e / C::m_u; @@ -113,7 +113,7 @@ void apply_nse_exponent(T& nse_state) { // term for calculating u_c // if use chabrier1998 screening, calculate the coulomb correction term -#if SCREEN_METHOD == 4 +#if SCREEN_METHOD == SCREEN_METHOD_chabrier1998 gamma = std::pow(zion[n], 5.0_rt/3.0_rt) * Gamma_e; // chemical potential for coulomb correction diff --git a/screening/screen.H b/screening/screen.H index 81b1cf7701..ffb0b750e9 100644 --- a/screening/screen.H +++ b/screening/screen.H @@ -1,6 +1,13 @@ #ifndef SCREEN_H #define SCREEN_H +// these need to be defined before screen_data.H is included +#define SCREEN_METHOD_null 0 +#define SCREEN_METHOD_screen5 1 +#define SCREEN_METHOD_chugunov2007 2 +#define SCREEN_METHOD_chugunov2009 3 +#define SCREEN_METHOD_chabrier1998 4 + #include #include #include @@ -16,15 +23,15 @@ using namespace amrex; using namespace integrator_rp; -#if SCREEN_METHOD == 0 +#if SCREEN_METHOD == SCREEN_METHOD_null const std::string screen_name = "null"; -#elif SCREEN_METHOD == 1 +#elif SCREEN_METHOD == SCREEN_METHOD_screen5 const std::string screen_name = "screen5"; -#elif SCREEN_METHOD == 2 +#elif SCREEN_METHOD == SCREEN_METHOD_chugunov2007 const std::string screen_name = "chugunov2007"; -#elif SCREEN_METHOD == 3 +#elif SCREEN_METHOD == SCREEN_METHOD_chugunov2009 const std::string screen_name = "chugunov2009"; -#elif SCREEN_METHOD == 4 +#elif SCREEN_METHOD == SCREEN_METHOD_chabrier1998 const std::string screen_name = "chabrier1998"; #endif @@ -169,7 +176,7 @@ fill_plasma_state(plasma_state_t& state, const Real temp, const Real dens, Array } } -#if SCREEN_METHOD == 1 +#if SCREEN_METHOD == SCREEN_METHOD_screen5 template AMREX_GPU_HOST_DEVICE AMREX_INLINE void actual_screen5 (const plasma_state_t& state, @@ -417,7 +424,7 @@ void actual_screen5 (const plasma_state_t& state, } } -#elif SCREEN_METHOD == 2 +#elif SCREEN_METHOD == SCREEN_METHOD_chugunov2007 template AMREX_GPU_HOST_DEVICE AMREX_INLINE void chugunov2007 (const plasma_state_t& state, @@ -613,7 +620,7 @@ void chugunov2007 (const plasma_state_t& state, } } -#elif SCREEN_METHOD == 3 +#elif SCREEN_METHOD == SCREEN_METHOD_chugunov2009 template AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void chugunov2009_f0 (const Real gamma, const Real dlog_dT, Real& f, Real& df_dT) @@ -783,7 +790,7 @@ void chugunov2009 (const plasma_state_t& state, } } -#elif SCREEN_METHOD == 4 +#elif SCREEN_METHOD == SCREEN_METHOD_chabrier1998 template AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void chabrier1998_helmholtz_F(const Real gamma, const Real dgamma_dT, Real& f, Real& df_dT) { @@ -945,18 +952,18 @@ void actual_screen(const plasma_state_t& state, const scrn::screen_factors_t& scn_fac, Real& scor, Real& scordt) { -#if SCREEN_METHOD == 0 +#if SCREEN_METHOD == SCREEN_METHOD_null // null screening amrex::ignore_unused(state, scn_fac); scor = 1.0_rt; scordt = 0.0_rt; -#elif SCREEN_METHOD == 1 +#elif SCREEN_METHOD == SCREEN_METHOD_screen5 actual_screen5(state, scn_fac, scor, scordt); -#elif SCREEN_METHOD == 2 +#elif SCREEN_METHOD == SCREEN_METHOD_chugunov2007 chugunov2007(state, scn_fac, scor, scordt); -#elif SCREEN_METHOD == 3 +#elif SCREEN_METHOD == SCREEN_METHOD_chugunov2009 chugunov2009(state, scn_fac, scor, scordt); -#elif SCREEN_METHOD == 4 +#elif SCREEN_METHOD == SCREEN_METHOD_chabrier1998 chabrier1998(state, scn_fac, scor, scordt); #endif } diff --git a/screening/screen_data.H b/screening/screen_data.H index 77021fc581..f217fec44b 100644 --- a/screening/screen_data.H +++ b/screening/screen_data.H @@ -31,7 +31,7 @@ namespace scrn { // ztilde = effective ion radius factor for a MCP // ztilde3 = ztilde**3 -#if SCREEN_METHOD == 1 +#if SCREEN_METHOD == SCREEN_METHOD_screen5 amrex::Real zs53 = 0.0; amrex::Real z1_53 = 0.0; amrex::Real z2_53 = 0.0; @@ -41,10 +41,10 @@ namespace scrn { amrex::Real zhat2 = 0.0; amrex::Real lzav = 0.0; amrex::Real aznut = 0.0; -#elif SCREEN_METHOD == 2 +#elif SCREEN_METHOD == SCREEN_METHOD_chugunov2007 amrex::Real ztilde = 0.0; amrex::Real ztilde3 = 0.0; -#elif SCREEN_METHOD == 3 +#elif SCREEN_METHOD == SCREEN_METHOD_chugunov2009 amrex::Real zs52 = 0.0; amrex::Real z1_52 = 0.0; amrex::Real z2_52 = 0.0; @@ -53,7 +53,7 @@ namespace scrn { amrex::Real z2_53 = 0.0; amrex::Real aznut = 0.0; amrex::Real ztilde = 0.0; -#elif SCREEN_METHOD == 4 +#elif SCREEN_METHOD == SCREEN_METHOD_chabrier1998 amrex::Real zs53 = 0.0; amrex::Real z1_53 = 0.0; amrex::Real z2_53 = 0.0; @@ -87,7 +87,7 @@ namespace scrn { scn_fac.z2 = z2; scn_fac.a2 = a2; -#if SCREEN_METHOD == 1 +#if SCREEN_METHOD == SCREEN_METHOD_screen5 scn_fac.zs53 = gcem::pow(z1 + z2, 5.0_rt / 3.0_rt); scn_fac.z1_53 = gcem::pow(z1, 5.0_rt / 3.0_rt); scn_fac.z2_53 = gcem::pow(z2, 5.0_rt / 3.0_rt); @@ -101,12 +101,12 @@ namespace scrn { scn_fac.aznut = gcem::pow(z1 * z1 * z2 * z2 * a1 * a2 / (a1 + a2), 1.0_rt / 3.0_rt); -#elif SCREEN_METHOD == 2 +#elif SCREEN_METHOD == SCREEN_METHOD_chugunov2007 scn_fac.ztilde = 0.5_rt * (gcem::pow(z1, 1.0_rt / 3.0_rt) + gcem::pow(z2, 1.0_rt / 3.0_rt)); scn_fac.ztilde3 = gcem::pow(scn_fac.ztilde, 3); -#elif SCREEN_METHOD == 3 +#elif SCREEN_METHOD == SCREEN_METHOD_chugunov2009 scn_fac.zs52 = gcem::pow(z1 + z2, 5.0_rt / 2.0_rt); scn_fac.z1_52 = gcem::pow(z1, 5.0_rt / 2.0_rt); scn_fac.z2_52 = gcem::pow(z2, 5.0_rt / 2.0_rt); @@ -118,7 +118,7 @@ namespace scrn { scn_fac.ztilde = 0.5_rt * (gcem::pow(z1, 1.0_rt / 3.0_rt) + gcem::pow(z2, 1.0_rt / 3.0_rt)); -#elif SCREEN_METHOD == 4 +#elif SCREEN_METHOD == SCREEN_METHOD_chabrier1998 scn_fac.zs53 = gcem::pow(z1 + z2, 5.0_rt / 3.0_rt); scn_fac.z1_53 = gcem::pow(z1, 5.0_rt/3.0_rt); scn_fac.z2_53 = gcem::pow(z2, 5.0_rt/3.0_rt);