Skip to content

Commit 78eafbb

Browse files
authored
Merge branch 'development' into use_cxx-20
2 parents 9713504 + f74f369 commit 78eafbb

File tree

74 files changed

+3967
-727
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+3967
-727
lines changed

interfaces/burn_type.H

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,8 @@ void normalize_abundances_sdc_burn (BurnT& state)
306306

307307
amrex::Real rhoX_sum = 0.0_rt;
308308
for (int n = 0; n < NumSpec; n++) {
309-
state.y[SFS+n] = amrex::max(amrex::min(state.y[SFS+n], state.y[SRHO]), 0.0_rt);
309+
state.y[SFS+n] = amrex::max(amrex::min(state.y[SFS+n], state.y[SRHO]),
310+
state.y[SRHO] * integrator_rp::SMALL_X_SAFE);
310311
rhoX_sum += state.y[SFS+n];
311312
}
312313
rhoX_sum /= state.y[SRHO];

networks/CNO_extras/cno_extras.png

-1.21 KB
Loading
-26 Bytes
Loading

networks/CNO_extras/partition_functions.H

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,22 @@ namespace part_fun {
1515

1616

1717

18-
// interpolation routine
18+
// index locator
1919

2020
template <typename T>
2121
AMREX_GPU_HOST_DEVICE AMREX_INLINE
22-
void interpolate_pf(const amrex::Real t9, const T& temp_array, const T& pf_array,
23-
amrex::Real& pf, amrex::Real& dpf_dT) {
22+
int
23+
index_pf(const amrex::Real t9, const T& temp_array) {
2424

2525
int left = temp_array.lo();
2626
int right = temp_array.hi();
2727

28+
int idx = -1;
29+
2830
if (t9 >= temp_array(left) && t9 < temp_array(right)) {
2931

30-
// find the largest temperature element <= t9 using a binary search
32+
// find the largest temperature element <= t9 using a
33+
// binary search
3134

3235
while (left < right) {
3336
int mid = (left + right) / 2;
@@ -38,11 +41,37 @@ namespace part_fun {
3841
}
3942
}
4043

41-
const int idx = right - 1;
44+
idx = right - 1;
45+
}
46+
47+
return idx;
48+
}
49+
50+
// interpolation routine
51+
52+
template <typename T>
53+
AMREX_GPU_HOST_DEVICE AMREX_INLINE
54+
void interpolate_pf(const amrex::Real t9, int idx,
55+
const T& temp_array, const T& pf_array,
56+
amrex::Real& pf, amrex::Real& dpf_dT) {
57+
58+
// if the index is -1, we are either outside of the bounds or
59+
// we never computed it. try recomputing here
60+
if (idx == -1) {
61+
idx = index_pf(t9, temp_array);
62+
}
63+
64+
// if the index is still -1, then we are out-of-bounds, so
65+
// just skip the interpolation
4266

43-
// now we have temp_array[idx] <= t9 < temp_array[idx+1]
67+
if (idx != -1) {
4468

45-
// construct the slope -- this is (log10(pf_{i+1}) - log10(pf_i)) / (T_{i+1} - T_i)
69+
// we have idx such that:
70+
// temp_array[idx] <= t9 < temp_array[idx+1]
71+
AMREX_ASSERT(t9 >= temp_array(idx) && t9 < temp_array(idx+1));
72+
73+
// construct the slope -- this is
74+
// (log10(pf_{i+1}) - log10(pf_i)) / (T_{i+1} - T_i)
4675

4776
amrex::Real slope = (pf_array(idx+1) - pf_array(idx)) /
4877
(temp_array(idx+1) - temp_array(idx));
@@ -67,6 +96,8 @@ namespace part_fun {
6796

6897
}
6998

99+
100+
70101
struct pf_cache_t {
71102
// Store the coefficient and derivative adjacent in memory, as they're
72103
// always accessed at the same time.
@@ -77,12 +108,18 @@ namespace part_fun {
77108

78109
}
79110

80-
// main interface
111+
// get the partition function for nucleus inuc. Here pf_cache
112+
// should already contain the index into the temp / pf arrays
81113

82114
AMREX_GPU_HOST_DEVICE AMREX_INLINE
83-
void get_partition_function(const int inuc, [[maybe_unused]] const tf_t& tfactors,
115+
void get_partition_function(const int inuc,
116+
[[maybe_unused]] const tf_t& tfactors,
117+
part_fun::pf_cache_t& pf_cache,
84118
amrex::Real& pf, amrex::Real& dpf_dT) {
85119

120+
pf = 1.0_rt;
121+
dpf_dT = 0.0_rt;
122+
86123
// inuc is the 1-based index for the species
87124

88125
switch (inuc) {
@@ -97,6 +134,25 @@ void get_partition_function(const int inuc, [[maybe_unused]] const tf_t& tfactor
97134

98135
}
99136

137+
138+
// a version of get_parition_function where we have not cached the
139+
// index into the arrays
140+
141+
AMREX_GPU_HOST_DEVICE AMREX_INLINE
142+
void get_partition_function(const int inuc,
143+
[[maybe_unused]] const tf_t& tfactors,
144+
amrex::Real& pf, amrex::Real& dpf_dT) {
145+
146+
// create a dummy cache. This will initialize the indices
147+
// to -1 and we will force a search for the correct index
148+
// when we do the interpolation.
149+
150+
part_fun::pf_cache_t pf_cache;
151+
152+
get_partition_function(inuc, tfactors, pf_cache, pf, dpf_dT);
153+
}
154+
155+
100156
AMREX_GPU_HOST_DEVICE AMREX_INLINE
101157
void get_partition_function_cached(const int inuc, const tf_t& tfactors,
102158
part_fun::pf_cache_t& pf_cache,
@@ -107,7 +163,7 @@ void get_partition_function_cached(const int inuc, const tf_t& tfactors,
107163
pf = pf_cache.data(inuc, 1);
108164
dpf_dT = pf_cache.data(inuc, 2);
109165
} else {
110-
get_partition_function(inuc, tfactors, pf, dpf_dT);
166+
get_partition_function(inuc, tfactors, pf_cache, pf, dpf_dT);
111167
pf_cache.data(inuc, 1) = pf;
112168
pf_cache.data(inuc, 2) = dpf_dT;
113169
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pynucastro version: 2.8.0
1+
pynucastro version: 2.8.0-6-g7d01fa58a

networks/CNO_extras/table_rates.H

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ struct table_t
4545
// we add a 7th index, k_index_dlogr_dlogt used for computing the derivative
4646
// of Log(rate) with respect of Log(temperature) by using the table
4747
// values. It isn't an index into the table but into the 'entries'
48-
// array. Is important to mention that although we compute dlogr/dlogT is
48+
// array. Is important to mention that although we compute dlogr/dlogT as
4949
// the computed quantity in 'entries', we pursue ultimately
5050
// dr/dt as the final desired quantity to be computed for this index.
5151

5252
const int k_index_dlogr_dlogt = 7;
53-
const int add_vars = 1; // 1 Additional Var in entries
53+
constexpr int add_vars = 1; // 1 Additional Var in entries
5454

5555

5656
namespace rate_tables
@@ -184,16 +184,14 @@ evaluate_linear_2d(const amrex::Real fip1jp1, const amrex::Real fip1j, const amr
184184
template<typename R, typename T, typename D>
185185
AMREX_INLINE AMREX_GPU_HOST_DEVICE
186186
amrex::Real
187-
evaluate_vars(const table_t& table_meta, const R& log_rhoy_table, const T& log_temp_table, const D& data,
188-
const amrex::Real log_rhoy, const amrex::Real log_temp, const int component)
187+
evaluate_vars(const int irhoy_lo, const int jtemp_lo,
188+
const R& log_rhoy_table, const T& log_temp_table, const D& data,
189+
const amrex::Real log_rhoy, const amrex::Real log_temp, const int component)
189190
{
190191
// This function evaluates the 2-D interpolator, for several pairs of rho_ye and temperature.
191192

192-
int jtemp_lo = vector_index_lu(table_meta.ntemp, log_temp_table, log_temp);
193-
int jtemp_hi = jtemp_lo + 1;
194-
195-
int irhoy_lo = vector_index_lu(table_meta.nrhoy, log_rhoy_table, log_rhoy);
196193
int irhoy_hi = irhoy_lo + 1;
194+
int jtemp_hi = jtemp_lo + 1;
197195

198196
amrex::Real rhoy_lo = log_rhoy_table(irhoy_lo);
199197
amrex::Real rhoy_hi = log_rhoy_table(irhoy_hi);
@@ -216,15 +214,13 @@ evaluate_vars(const table_t& table_meta, const R& log_rhoy_table, const T& log_t
216214
template<typename R, typename T, typename D>
217215
AMREX_INLINE AMREX_GPU_HOST_DEVICE
218216
amrex::Real
219-
evaluate_dr_dtemp(const table_t& table_meta, const R& log_rhoy_table, const T& log_temp_table, const D& data,
217+
evaluate_dr_dtemp(const int irhoy_lo, const int jtemp_lo,
218+
const table_t& table_meta, const R& log_rhoy_table, const T& log_temp_table, const D& data,
220219
const amrex::Real log_rhoy, const amrex::Real log_temp)
221220
{
222221
// The main objective of this function is compute dlogr_dlogt.
223222

224-
const int irhoy_lo = vector_index_lu(table_meta.nrhoy, log_rhoy_table, log_rhoy);
225223
const int irhoy_hi = irhoy_lo + 1;
226-
227-
const int jtemp_lo = vector_index_lu(table_meta.ntemp, log_temp_table, log_temp);
228224
const int jtemp_hi = jtemp_lo + 1;
229225

230226
amrex::Real dlogr_dlogt;
@@ -361,16 +357,29 @@ evaluate_dr_dtemp(const table_t& table_meta, const R& log_rhoy_table, const T& l
361357
template <typename R, typename T, typename D>
362358
AMREX_INLINE AMREX_GPU_HOST_DEVICE
363359
void
364-
get_entries(const table_t& table_meta, const R& log_rhoy_table, const T& log_temp_table, const D& data,
365-
const amrex::Real log_rhoy, const amrex::Real log_temp, amrex::Array1D<amrex::Real, 1, num_vars+1>& entries)
360+
get_entries(const int irhoy_lo, const int jtemp_lo,
361+
const table_t& table_meta, const R& log_rhoy_table, const T& log_temp_table, const D& data,
362+
const amrex::Real log_rhoy, const amrex::Real log_temp, amrex::Array1D<amrex::Real, 1, num_vars+add_vars>& entries)
366363
{
367-
for (int ivar = 1; ivar <= num_vars; ivar++) {
368-
entries(ivar) = evaluate_vars(table_meta, log_rhoy_table, log_temp_table, data,
369-
log_rhoy, log_temp, ivar);
370-
}
371364

372-
entries(k_index_dlogr_dlogt) = evaluate_dr_dtemp(table_meta, log_rhoy_table, log_temp_table, data,
373-
log_rhoy, log_temp);
365+
// only interpolate the quantities we currently use
366+
367+
entries(jtab_rate) = evaluate_vars(irhoy_lo, jtemp_lo,
368+
log_rhoy_table, log_temp_table, data,
369+
log_rhoy, log_temp, jtab_rate);
370+
371+
entries(jtab_nuloss) = evaluate_vars(irhoy_lo, jtemp_lo,
372+
log_rhoy_table, log_temp_table, data,
373+
log_rhoy, log_temp, jtab_nuloss);
374+
375+
entries(jtab_gamma) = evaluate_vars(irhoy_lo, jtemp_lo,
376+
log_rhoy_table, log_temp_table, data,
377+
log_rhoy, log_temp, jtab_gamma);
378+
379+
entries(k_index_dlogr_dlogt) =
380+
evaluate_dr_dtemp(irhoy_lo, jtemp_lo,
381+
table_meta, log_rhoy_table, log_temp_table, data,
382+
log_rhoy, log_temp);
374383
}
375384

376385
template <typename R, typename T, typename D>
@@ -381,14 +390,21 @@ tabular_evaluate(const table_t& table_meta,
381390
const amrex::Real rhoy, const amrex::Real temp,
382391
amrex::Real& rate, amrex::Real& drate_dt, amrex::Real& edot_nu, amrex::Real& edot_gamma)
383392
{
384-
amrex::Array1D<amrex::Real, 1, num_vars+1> entries;
393+
amrex::Array1D<amrex::Real, 1, num_vars+add_vars> entries;
385394

386395
// Get the table entries at this rhoy, temp
387396

388397
const amrex::Real log_rhoy = std::log10(rhoy);
389398
const amrex::Real log_temp = std::log10(temp);
390399

391-
get_entries(table_meta, log_rhoy_table, log_temp_table, data,
400+
// get the index into the table -- all components are
401+
// stored with the same indices
402+
403+
int irhoy_lo = vector_index_lu(table_meta.nrhoy, log_rhoy_table, log_rhoy);
404+
int jtemp_lo = vector_index_lu(table_meta.ntemp, log_temp_table, log_temp);
405+
406+
get_entries(irhoy_lo, jtemp_lo,
407+
table_meta, log_rhoy_table, log_temp_table, data,
392408
log_rhoy, log_temp, entries);
393409

394410
// Fill outputs: rate, d(rate)/d(temperature), and

networks/ECSN/ECSN.png

112 Bytes
Loading

networks/ECSN/partition_functions.H

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,22 @@ namespace part_fun {
1515

1616

1717

18-
// interpolation routine
18+
// index locator
1919

2020
template <typename T>
2121
AMREX_GPU_HOST_DEVICE AMREX_INLINE
22-
void interpolate_pf(const amrex::Real t9, const T& temp_array, const T& pf_array,
23-
amrex::Real& pf, amrex::Real& dpf_dT) {
22+
int
23+
index_pf(const amrex::Real t9, const T& temp_array) {
2424

2525
int left = temp_array.lo();
2626
int right = temp_array.hi();
2727

28+
int idx = -1;
29+
2830
if (t9 >= temp_array(left) && t9 < temp_array(right)) {
2931

30-
// find the largest temperature element <= t9 using a binary search
32+
// find the largest temperature element <= t9 using a
33+
// binary search
3134

3235
while (left < right) {
3336
int mid = (left + right) / 2;
@@ -38,11 +41,37 @@ namespace part_fun {
3841
}
3942
}
4043

41-
const int idx = right - 1;
44+
idx = right - 1;
45+
}
46+
47+
return idx;
48+
}
49+
50+
// interpolation routine
51+
52+
template <typename T>
53+
AMREX_GPU_HOST_DEVICE AMREX_INLINE
54+
void interpolate_pf(const amrex::Real t9, int idx,
55+
const T& temp_array, const T& pf_array,
56+
amrex::Real& pf, amrex::Real& dpf_dT) {
57+
58+
// if the index is -1, we are either outside of the bounds or
59+
// we never computed it. try recomputing here
60+
if (idx == -1) {
61+
idx = index_pf(t9, temp_array);
62+
}
63+
64+
// if the index is still -1, then we are out-of-bounds, so
65+
// just skip the interpolation
4266

43-
// now we have temp_array[idx] <= t9 < temp_array[idx+1]
67+
if (idx != -1) {
4468

45-
// construct the slope -- this is (log10(pf_{i+1}) - log10(pf_i)) / (T_{i+1} - T_i)
69+
// we have idx such that:
70+
// temp_array[idx] <= t9 < temp_array[idx+1]
71+
AMREX_ASSERT(t9 >= temp_array(idx) && t9 < temp_array(idx+1));
72+
73+
// construct the slope -- this is
74+
// (log10(pf_{i+1}) - log10(pf_i)) / (T_{i+1} - T_i)
4675

4776
amrex::Real slope = (pf_array(idx+1) - pf_array(idx)) /
4877
(temp_array(idx+1) - temp_array(idx));
@@ -67,6 +96,8 @@ namespace part_fun {
6796

6897
}
6998

99+
100+
70101
struct pf_cache_t {
71102
// Store the coefficient and derivative adjacent in memory, as they're
72103
// always accessed at the same time.
@@ -77,12 +108,18 @@ namespace part_fun {
77108

78109
}
79110

80-
// main interface
111+
// get the partition function for nucleus inuc. Here pf_cache
112+
// should already contain the index into the temp / pf arrays
81113

82114
AMREX_GPU_HOST_DEVICE AMREX_INLINE
83-
void get_partition_function(const int inuc, [[maybe_unused]] const tf_t& tfactors,
115+
void get_partition_function(const int inuc,
116+
[[maybe_unused]] const tf_t& tfactors,
117+
part_fun::pf_cache_t& pf_cache,
84118
amrex::Real& pf, amrex::Real& dpf_dT) {
85119

120+
pf = 1.0_rt;
121+
dpf_dT = 0.0_rt;
122+
86123
// inuc is the 1-based index for the species
87124

88125
switch (inuc) {
@@ -97,6 +134,25 @@ void get_partition_function(const int inuc, [[maybe_unused]] const tf_t& tfactor
97134

98135
}
99136

137+
138+
// a version of get_parition_function where we have not cached the
139+
// index into the arrays
140+
141+
AMREX_GPU_HOST_DEVICE AMREX_INLINE
142+
void get_partition_function(const int inuc,
143+
[[maybe_unused]] const tf_t& tfactors,
144+
amrex::Real& pf, amrex::Real& dpf_dT) {
145+
146+
// create a dummy cache. This will initialize the indices
147+
// to -1 and we will force a search for the correct index
148+
// when we do the interpolation.
149+
150+
part_fun::pf_cache_t pf_cache;
151+
152+
get_partition_function(inuc, tfactors, pf_cache, pf, dpf_dT);
153+
}
154+
155+
100156
AMREX_GPU_HOST_DEVICE AMREX_INLINE
101157
void get_partition_function_cached(const int inuc, const tf_t& tfactors,
102158
part_fun::pf_cache_t& pf_cache,
@@ -107,7 +163,7 @@ void get_partition_function_cached(const int inuc, const tf_t& tfactors,
107163
pf = pf_cache.data(inuc, 1);
108164
dpf_dT = pf_cache.data(inuc, 2);
109165
} else {
110-
get_partition_function(inuc, tfactors, pf, dpf_dT);
166+
get_partition_function(inuc, tfactors, pf_cache, pf, dpf_dT);
111167
pf_cache.data(inuc, 1) = pf;
112168
pf_cache.data(inuc, 2) = dpf_dT;
113169
}

networks/ECSN/pynucastro-info.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pynucastro version: 2.8.0
1+
pynucastro version: 2.8.0-6-g7d01fa58a

0 commit comments

Comments
 (0)