Skip to content

Commit

Permalink
Tests pass but ugly impl:: usage
Browse files Browse the repository at this point in the history
  • Loading branch information
brryan committed Sep 28, 2024
1 parent bfaeb1d commit b7668f2
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 38 deletions.
14 changes: 4 additions & 10 deletions singularity-opac/neutrinos/mean_opacity_neutrinos.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ======================================================================
// © 2022. Triad National Security, LLC. All rights reserved. This
// © 2022-2024. Triad National Security, LLC. All rights reserved. This
// program was produced under U.S. Government contract
// 89233218CNA000001 for Los Alamos National Laboratory (LANL), which
// is operated by Triad National Security, LLC for the U.S.
Expand Down Expand Up @@ -37,12 +37,9 @@ namespace impl {
// TODO(BRR) Note: It is assumed that lambda is constant for all densities,
// temperatures, and Ye

template <typename pc = PhysicalConstantsCGS>
class MeanOpacity {

public:
using PC = pc;

MeanOpacity() = default;
template <typename Opacity>
MeanOpacity(const Opacity &opac, const Real lRhoMin, const Real lRhoMax,
Expand Down Expand Up @@ -136,8 +133,7 @@ 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<PC, typename Opacity::PC>::value,
"Mean opacity constants must match opacity constants");
using PC = typename Opacity::PC;

lkappaPlanck_.resize(NRho, NT, NYe, NEUTRINO_NTYPES);
// index 0 is the species and is not interpolatable
Expand Down Expand Up @@ -224,10 +220,8 @@ class MeanOpacity {

} // namespace impl

using MeanOpacityScaleFree = impl::MeanOpacity<PhysicalConstantsUnity>;
using MeanOpacityCGS = impl::MeanOpacity<PhysicalConstantsCGS>;
using MeanOpacity = impl::MeanVariant<MeanOpacityScaleFree, MeanOpacityCGS,
MeanNonCGSUnits<MeanOpacityCGS>>;
using MeanOpacity =
impl::MeanVariant<impl::MeanOpacity, MeanNonCGSUnits<impl::MeanOpacity>>;

} // namespace neutrinos
} // namespace singularity
Expand Down
1 change: 0 additions & 1 deletion singularity-opac/photons/gray_opacity_photons.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class GrayOpacity {
void PrintParams() const noexcept {
printf("Gray opacity. kappa = %g\n", kappa_);
}

inline void Finalize() noexcept {}

PORTABLE_INLINE_FUNCTION
Expand Down
12 changes: 3 additions & 9 deletions singularity-opac/photons/mean_opacity_photons.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,9 @@ namespace impl {
// TODO(BRR) Note: It is assumed that lambda is constant for all densities and
// temperatures

template <typename pc = PhysicalConstantsCGS>
class MeanOpacity {

public:
using PC = pc;

MeanOpacity() = default;
template <typename Opacity>
MeanOpacity(const Opacity &opac, const Real lRhoMin, const Real lRhoMax,
Expand Down Expand Up @@ -126,8 +123,7 @@ 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<PC, typename Opacity::PC>::value,
"Mean opacity constants must match opacity constants");
using PC = typename Opacity::PC;

lkappaPlanck_.resize(NRho, NT);
lkappaPlanck_.setRange(0, lTMin, lTMax, NT);
Expand Down Expand Up @@ -200,10 +196,8 @@ class MeanOpacity {

} // namespace impl

using MeanOpacityScaleFree = impl::MeanOpacity<PhysicalConstantsUnity>;
using MeanOpacityCGS = impl::MeanOpacity<PhysicalConstantsCGS>;
using MeanOpacity = impl::MeanVariant<MeanOpacityScaleFree, MeanOpacityCGS,
MeanNonCGSUnits<MeanOpacityCGS>>;
using MeanOpacity =
impl::MeanVariant<impl::MeanOpacity, MeanNonCGSUnits<impl::MeanOpacity>>;

} // namespace photons
} // namespace singularity
Expand Down
4 changes: 0 additions & 4 deletions singularity-opac/photons/powerlaw_opacity_photons.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ class PowerLawOpacity {
printf("Power law opacity. kappa0 = %g rho_exp = %g temp_exp = %g\n",
kappa0_, rho_exp_, temp_exp_);
}

PORTABLE_INLINE_FUNCTION
pc GetPhysicalConstants() const { return pc(); }

inline void Finalize() noexcept {}

PORTABLE_INLINE_FUNCTION
Expand Down
3 changes: 1 addition & 2 deletions test/test_gray_opacities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ TEST_CASE("Gray neutrino opacities", "[GrayNeutrinos]") {
constexpr RadiationType type = RadiationType::NU_ELECTRON;
constexpr Real nu = 1.25 * MeV2Hz; // 1 MeV

// neutrinos::Gray opac_host(1);
neutrinos::Opacity opac_host = neutrinos::Gray(1);
neutrinos::Opacity opac_host = neutrinos::Gray(1.);
neutrinos::Opacity opac = opac_host.GetOnDevice();

// Check constants from opacity
Expand Down
16 changes: 4 additions & 12 deletions test/test_mean_opacities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ TEST_CASE("Mean neutrino opacities", "[MeanNeutrinos]") {
neutrinos::Gray opac_host(kappa);
neutrinos::Opacity opac = opac_host.GetOnDevice();

neutrinos::MeanOpacity mean_opac_host = neutrinos::MeanOpacityCGS(
neutrinos::MeanOpacity mean_opac_host = neutrinos::impl::MeanOpacity(
opac_host, lRhoMin, lRhoMax, NRho, lTMin, lTMax, NT, YeMin, YeMax, NYe);
auto mean_opac = mean_opac_host.GetOnDevice();

Expand Down Expand Up @@ -412,12 +412,8 @@ TEST_CASE("Mean photon opacities", "[MeanPhotons]") {
photons::Gray opac_host(kappa);
photons::Opacity opac = opac_host.GetOnDevice();

// photons::MeanOpacity mean_opac_host = photons::MeanOpacityCGS(
// opac_host, lRhoMin, lRhoMax, NRho, lTMin, lTMax, NT);
// auto mean_opac = mean_opac_host.GetOnDevice();

photons::MeanOpacityCGS mean_opac_host(opac_host, lRhoMin, lRhoMax, NRho,
lTMin, lTMax, NT);
photons::MeanOpacity mean_opac_host = photons::impl::MeanOpacity(
opac_host, lRhoMin, lRhoMax, NRho, lTMin, lTMax, NT);
auto mean_opac = mean_opac_host.GetOnDevice();

THEN("The emissivity per nu omega is consistent with the emissity per nu") {
Expand Down Expand Up @@ -451,7 +447,7 @@ TEST_CASE("Mean photon opacities", "[MeanPhotons]") {
#ifdef SPINER_USE_HDF
THEN("We can save to disk and reload") {
mean_opac.Save(grayname);
photons::MeanOpacity mean_opac_host_load(grayname);
photons::MeanOpacityCGS mean_opac_host_load(grayname);
AND_THEN("The reloaded table matches the gray opacities") {

auto mean_opac_load = mean_opac_host_load.GetOnDevice();
Expand Down Expand Up @@ -498,10 +494,6 @@ TEST_CASE("Mean photon opacities", "[MeanPhotons]") {
constexpr Real rho_unit =
mass_unit / (length_unit * length_unit * length_unit);

// auto funny_units_host =
// photons::MeanNonCGSUnits<photons::MeanOpacityCGS>(
// std::forward<photons::MeanOpacityCGS>(mean_opac_host), time_unit,
// mean_opac_host, time_unit, mass_unit, length_unit, temp_unit);
auto funny_units_host = photons::MeanNonCGSUnits<photons::MeanOpacity>(
std::forward<photons::MeanOpacity>(mean_opac_host), time_unit,
mass_unit, length_unit, temp_unit);
Expand Down

0 comments on commit b7668f2

Please sign in to comment.