From a668459cd1f78da88047f928f893671100f59760 Mon Sep 17 00:00:00 2001 From: Jonah Miller Date: Thu, 2 Jan 2025 11:35:47 -0700 Subject: [PATCH 1/2] static assert into dynamic one --- singularity-opac/constants/constants.hpp | 8 ++++++++ singularity-opac/neutrinos/mean_opacity_neutrinos.hpp | 8 +++++--- singularity-opac/photons/mean_opacity_photons.hpp | 8 +++++--- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/singularity-opac/constants/constants.hpp b/singularity-opac/constants/constants.hpp index f5bbede..652276f 100644 --- a/singularity-opac/constants/constants.hpp +++ b/singularity-opac/constants/constants.hpp @@ -16,6 +16,9 @@ #ifndef SINGULARITY_OPAC_CONSTANTS_CONSTANTS_ #define SINGULARITY_OPAC_CONSTANTS_CONSTANTS_ +#include +#include + #include namespace singularity { @@ -230,6 +233,11 @@ struct RuntimePhysicalConstants { const Real Fc; const Real nu_sigma0; const Real gA; + + // Runtime physical constants are trivially copyable + bool operator==(const RuntimePhysicalConstants &other) const { + return std::memcmp(this, &other, sizeof(*this)); + } }; using PhysicalConstantsUnity = diff --git a/singularity-opac/neutrinos/mean_opacity_neutrinos.hpp b/singularity-opac/neutrinos/mean_opacity_neutrinos.hpp index 9cd578e..fa2aa1f 100644 --- a/singularity-opac/neutrinos/mean_opacity_neutrinos.hpp +++ b/singularity-opac/neutrinos/mean_opacity_neutrinos.hpp @@ -140,9 +140,11 @@ class MeanOpacity { const Real lTMax, const int NT, const Real YeMin, const Real YeMax, const int NYe, Real lNuMin, Real lNuMax, const int NNu, Real *lambda = nullptr) { - static_assert(std::is_same::value, - "Error: MeanOpacity physical constants do not match those of " - "Opacity used for construction."); +#ifndef NDEBUG + auto RPC = RuntimePhysicalConstants(PC); + auto opc = opac.GetRuntimePhysicalConstants(); + assert(RPC == opc && "Physical constants are the same"); +#endif lkappaPlanck_.resize(NRho, NT, NYe, NEUTRINO_NTYPES); // index 0 is the species and is not interpolatable diff --git a/singularity-opac/photons/mean_opacity_photons.hpp b/singularity-opac/photons/mean_opacity_photons.hpp index 6c91613..e00e61b 100644 --- a/singularity-opac/photons/mean_opacity_photons.hpp +++ b/singularity-opac/photons/mean_opacity_photons.hpp @@ -149,9 +149,11 @@ class MeanOpacity { const Real lRhoMax, const int NRho, const Real lTMin, const Real lTMax, const int NT, Real lNuMin, Real lNuMax, const int NNu, Real *lambda = nullptr) { - static_assert(std::is_same::value, - "Error: MeanOpacity physical constants do not match those of " - "Opacity used for construction."); +#ifndef NDEBUG + auto RPC = RuntimePhysicalConstants(PC); + auto opc = opac.GetRuntimePhysicalConstants(); + assert(RPC == opc && "Physical constants are the same"); +#endif lkappa_.resize(NRho, NT, 2); lkappa_.setRange(1, lTMin, lTMax, NT); From 0e1d38840ae18b1ebec038c888545edbddc63c13 Mon Sep 17 00:00:00 2001 From: Jonah Miller Date: Thu, 2 Jan 2025 13:44:16 -0700 Subject: [PATCH 2/2] oops need to call constructor... --- singularity-opac/neutrinos/mean_opacity_neutrinos.hpp | 2 +- singularity-opac/photons/mean_opacity_photons.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/singularity-opac/neutrinos/mean_opacity_neutrinos.hpp b/singularity-opac/neutrinos/mean_opacity_neutrinos.hpp index fa2aa1f..bfb15b5 100644 --- a/singularity-opac/neutrinos/mean_opacity_neutrinos.hpp +++ b/singularity-opac/neutrinos/mean_opacity_neutrinos.hpp @@ -141,7 +141,7 @@ class MeanOpacity { const Real YeMax, const int NYe, Real lNuMin, Real lNuMax, const int NNu, Real *lambda = nullptr) { #ifndef NDEBUG - auto RPC = RuntimePhysicalConstants(PC); + auto RPC = RuntimePhysicalConstants(PC()); auto opc = opac.GetRuntimePhysicalConstants(); assert(RPC == opc && "Physical constants are the same"); #endif diff --git a/singularity-opac/photons/mean_opacity_photons.hpp b/singularity-opac/photons/mean_opacity_photons.hpp index e00e61b..e9bdd02 100644 --- a/singularity-opac/photons/mean_opacity_photons.hpp +++ b/singularity-opac/photons/mean_opacity_photons.hpp @@ -150,7 +150,7 @@ class MeanOpacity { const Real lTMax, const int NT, Real lNuMin, Real lNuMax, const int NNu, Real *lambda = nullptr) { #ifndef NDEBUG - auto RPC = RuntimePhysicalConstants(PC); + auto RPC = RuntimePhysicalConstants(PC()); auto opc = opac.GetRuntimePhysicalConstants(); assert(RPC == opc && "Physical constants are the same"); #endif