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

update pynucastro nets to have bion/mion constexpr #1437

Merged
merged 4 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
125 changes: 123 additions & 2 deletions networks/CNO_extras/actual_network.H
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <AMReX_REAL.H>
#include <AMReX_Array.H>
#include <AMReX_Loop.H>

#include <fundamental_constants.H>
#include <network_properties.H>
Expand All @@ -15,8 +16,128 @@ const std::string network_name = "pynucastro-cxx";

namespace network
{
extern AMREX_GPU_MANAGED amrex::Array1D<amrex::Real, 1, NumSpec> bion;
extern AMREX_GPU_MANAGED amrex::Array1D<amrex::Real, 1, NumSpec> mion;

template<int spec>
AMREX_GPU_HOST_DEVICE AMREX_INLINE
constexpr Real bion () {
using namespace Species;

static_assert(spec >= 1 && spec <= NumSpec);

// Set the binding energy of the element

if constexpr (spec == H1) {
return 0.0_rt;
}
else if constexpr (spec == He4) {
return 28.29566_rt;
}
else if constexpr (spec == C12) {
return 92.16172800000001_rt;
}
else if constexpr (spec == C13) {
return 97.108037_rt;
}
else if constexpr (spec == N13) {
return 94.105219_rt;
}
else if constexpr (spec == N14) {
return 104.65859599999999_rt;
}
else if constexpr (spec == N15) {
return 115.4919_rt;
}
else if constexpr (spec == O14) {
return 98.731892_rt;
}
else if constexpr (spec == O15) {
return 111.95538_rt;
}
else if constexpr (spec == O16) {
return 127.619296_rt;
}
else if constexpr (spec == O17) {
return 131.76237600000002_rt;
}
else if constexpr (spec == O18) {
return 139.807746_rt;
}
else if constexpr (spec == F17) {
return 128.21957600000002_rt;
}
else if constexpr (spec == F18) {
return 137.369484_rt;
}
else if constexpr (spec == F19) {
return 147.801342_rt;
}
else if constexpr (spec == Ne18) {
return 132.142626_rt;
}
else if constexpr (spec == Ne19) {
return 143.779517_rt;
}
else if constexpr (spec == Ne20) {
return 160.6448_rt;
}
else if constexpr (spec == Mg22) {
return 168.58074200000001_rt;
}
else if constexpr (spec == Mg24) {
return 198.25701600000002_rt;
}
else if constexpr (spec == Fe56) {
return 492.2598239999999_rt;
}


// Return zero if we don't recognize the species.
return 0.0_rt;
}

template<int spec>
AMREX_GPU_HOST_DEVICE AMREX_INLINE
constexpr Real mion () {
static_assert(spec >= 1 && spec <= NumSpec);

constexpr Real A = NetworkProperties::aion(spec);
constexpr Real Z = NetworkProperties::zion(spec);

return (A - Z) * C::Legacy::m_n + Z * (C::Legacy::m_p + C::Legacy::m_e) - bion<spec>() * C::Legacy::MeV2gr;
}

// Legacy (non-templated) interfaces

AMREX_GPU_HOST_DEVICE AMREX_INLINE
Real bion (int spec) {
using namespace Species;

Real b = 0.0_rt;

// Set the binding energy of the element
constexpr_for<1, NumSpec+1>([&] (auto n) {
if (n == spec) {
b = bion<n>();
}
});

return b;
}

AMREX_GPU_HOST_DEVICE AMREX_INLINE
Real mion (int spec) {
using namespace Species;

Real m = 0.0_rt;

constexpr_for<1, NumSpec+1>([&] (auto n) {
if (n == spec) {
m = mion<n>();
}
});

return m;
}
}

namespace Rates
Expand Down
43 changes: 0 additions & 43 deletions networks/CNO_extras/actual_network_data.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
#include <actual_network.H>


namespace network
{
AMREX_GPU_MANAGED amrex::Array1D<amrex::Real, 1, NumSpec> bion;
AMREX_GPU_MANAGED amrex::Array1D<amrex::Real, 1, NumSpec> mion;
}

#ifdef NSE_NET
namespace NSE_INDEX
{
Expand Down Expand Up @@ -54,42 +48,5 @@ namespace NSE_INDEX

void actual_network_init()
{
using namespace Species;
using namespace network;

// binding energies per nucleon in MeV
amrex::Array1D<amrex::Real, 1, NumSpec> ebind_per_nucleon;

ebind_per_nucleon(H1) = 0.0_rt;
ebind_per_nucleon(He4) = 7.073915_rt;
ebind_per_nucleon(C12) = 7.680144_rt;
ebind_per_nucleon(C13) = 7.469849_rt;
ebind_per_nucleon(N13) = 7.238863_rt;
ebind_per_nucleon(N14) = 7.475613999999999_rt;
ebind_per_nucleon(N15) = 7.69946_rt;
ebind_per_nucleon(O14) = 7.052278_rt;
ebind_per_nucleon(O15) = 7.463692_rt;
ebind_per_nucleon(O16) = 7.976206_rt;
ebind_per_nucleon(O17) = 7.7507280000000005_rt;
ebind_per_nucleon(O18) = 7.767097_rt;
ebind_per_nucleon(F17) = 7.542328_rt;
ebind_per_nucleon(F18) = 7.631638_rt;
ebind_per_nucleon(F19) = 7.779018_rt;
ebind_per_nucleon(Ne18) = 7.341257_rt;
ebind_per_nucleon(Ne19) = 7.567343_rt;
ebind_per_nucleon(Ne20) = 8.03224_rt;
ebind_per_nucleon(Mg22) = 7.662761000000001_rt;
ebind_per_nucleon(Mg24) = 8.260709_rt;
ebind_per_nucleon(Fe56) = 8.790353999999999_rt;

// convert to binding energies per nucleus in MeV
for (int i = 1; i <= NumSpec; ++i) {
bion(i) = ebind_per_nucleon(i) * aion[i-1];
}

// Set the mass -- this will be in grams
for (int i = 1; i <= NumSpec; ++i) {
mion(i) = (aion[i-1] - zion[i-1]) * C::Legacy::m_n + zion[i-1] * (C::Legacy::m_p + C::Legacy::m_e) - bion(i) * C::Legacy::MeV2gr;
}

}
Binary file modified networks/CNO_extras/cno_extras.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified networks/CNO_extras/cno_extras_hide_alpha.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
95 changes: 93 additions & 2 deletions networks/ECSN/actual_network.H
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <AMReX_REAL.H>
#include <AMReX_Array.H>
#include <AMReX_Loop.H>

#include <fundamental_constants.H>
#include <network_properties.H>
Expand All @@ -15,8 +16,98 @@ const std::string network_name = "pynucastro-cxx";

namespace network
{
extern AMREX_GPU_MANAGED amrex::Array1D<amrex::Real, 1, NumSpec> bion;
extern AMREX_GPU_MANAGED amrex::Array1D<amrex::Real, 1, NumSpec> mion;

template<int spec>
AMREX_GPU_HOST_DEVICE AMREX_INLINE
constexpr Real bion () {
using namespace Species;

static_assert(spec >= 1 && spec <= NumSpec);

// Set the binding energy of the element

if constexpr (spec == H1) {
return 0.0_rt;
}
else if constexpr (spec == He4) {
return 28.29566_rt;
}
else if constexpr (spec == O16) {
return 127.619296_rt;
}
else if constexpr (spec == O20) {
return 151.3714_rt;
}
else if constexpr (spec == F20) {
return 154.40268_rt;
}
else if constexpr (spec == Ne20) {
return 160.6448_rt;
}
else if constexpr (spec == Mg24) {
return 198.25701600000002_rt;
}
else if constexpr (spec == Al27) {
return 224.951931_rt;
}
else if constexpr (spec == Si28) {
return 236.536832_rt;
}
else if constexpr (spec == P31) {
return 262.91617699999995_rt;
}
else if constexpr (spec == S32) {
return 271.78012800000005_rt;
}


// Return zero if we don't recognize the species.
return 0.0_rt;
}

template<int spec>
AMREX_GPU_HOST_DEVICE AMREX_INLINE
constexpr Real mion () {
static_assert(spec >= 1 && spec <= NumSpec);

constexpr Real A = NetworkProperties::aion(spec);
constexpr Real Z = NetworkProperties::zion(spec);

return (A - Z) * C::Legacy::m_n + Z * (C::Legacy::m_p + C::Legacy::m_e) - bion<spec>() * C::Legacy::MeV2gr;
}

// Legacy (non-templated) interfaces

AMREX_GPU_HOST_DEVICE AMREX_INLINE
Real bion (int spec) {
using namespace Species;

Real b = 0.0_rt;

// Set the binding energy of the element
constexpr_for<1, NumSpec+1>([&] (auto n) {
if (n == spec) {
b = bion<n>();
}
});

return b;
}

AMREX_GPU_HOST_DEVICE AMREX_INLINE
Real mion (int spec) {
using namespace Species;

Real m = 0.0_rt;

constexpr_for<1, NumSpec+1>([&] (auto n) {
if (n == spec) {
m = mion<n>();
}
});

return m;
}
}

namespace Rates
Expand Down
33 changes: 0 additions & 33 deletions networks/ECSN/actual_network_data.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
#include <actual_network.H>


namespace network
{
AMREX_GPU_MANAGED amrex::Array1D<amrex::Real, 1, NumSpec> bion;
AMREX_GPU_MANAGED amrex::Array1D<amrex::Real, 1, NumSpec> mion;
}

#ifdef NSE_NET
namespace NSE_INDEX
{
Expand Down Expand Up @@ -35,32 +29,5 @@ namespace NSE_INDEX

void actual_network_init()
{
using namespace Species;
using namespace network;

// binding energies per nucleon in MeV
amrex::Array1D<amrex::Real, 1, NumSpec> ebind_per_nucleon;

ebind_per_nucleon(H1) = 0.0_rt;
ebind_per_nucleon(He4) = 7.073915_rt;
ebind_per_nucleon(O16) = 7.976206_rt;
ebind_per_nucleon(O20) = 7.568569999999999_rt;
ebind_per_nucleon(F20) = 7.720134_rt;
ebind_per_nucleon(Ne20) = 8.03224_rt;
ebind_per_nucleon(Mg24) = 8.260709_rt;
ebind_per_nucleon(Al27) = 8.331553_rt;
ebind_per_nucleon(Si28) = 8.447744_rt;
ebind_per_nucleon(P31) = 8.481167_rt;
ebind_per_nucleon(S32) = 8.493129000000001_rt;

// convert to binding energies per nucleus in MeV
for (int i = 1; i <= NumSpec; ++i) {
bion(i) = ebind_per_nucleon(i) * aion[i-1];
}

// Set the mass -- this will be in grams
for (int i = 1; i <= NumSpec; ++i) {
mion(i) = (aion[i-1] - zion[i-1]) * C::Legacy::m_n + zion[i-1] * (C::Legacy::m_p + C::Legacy::m_e) - bion(i) * C::Legacy::MeV2gr;
}

}
Binary file modified networks/He-C-Fe-group/He-C-Fe-group.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading