Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mean opacities #60

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
AstroBarker marked this conversation as resolved.
Show resolved Hide resolved
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
Loading