Skip to content

Commit

Permalink
Merge pull request #60 from lanl/jmm/fix-mean-opacities
Browse files Browse the repository at this point in the history
  • Loading branch information
Yurlungur authored Jan 7, 2025
2 parents b4542ed + 0e1d388 commit e3dce4c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
8 changes: 8 additions & 0 deletions singularity-opac/constants/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
#ifndef SINGULARITY_OPAC_CONSTANTS_CONSTANTS_
#define SINGULARITY_OPAC_CONSTANTS_CONSTANTS_

#include <cstring>
#include <type_traits>

#include <ports-of-call/portability.hpp>

namespace singularity {
Expand Down Expand Up @@ -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 =
Expand Down
8 changes: 5 additions & 3 deletions singularity-opac/neutrinos/mean_opacity_neutrinos.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename Opacity::PC, PC>::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
Expand Down
8 changes: 5 additions & 3 deletions singularity-opac/photons/mean_opacity_photons.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename Opacity::PC, PC>::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);
Expand Down

0 comments on commit e3dce4c

Please sign in to comment.