Skip to content

Commit 2359fab

Browse files
authored
fix RKC integration with SDC (#1497)
1 parent 695b711 commit 2359fab

File tree

2 files changed

+42
-22
lines changed

2 files changed

+42
-22
lines changed

integration/RKC/actual_integrator_sdc.H

+37-20
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ using namespace integrator_rp;
1616

1717
template <typename BurnT>
1818
AMREX_GPU_HOST_DEVICE AMREX_INLINE
19-
void actual_integrator (BurnT& state, Real dt)
19+
void actual_integrator (BurnT& state, amrex::Real dt, bool is_retry=false)
2020
{
2121
constexpr int int_neqs = integrator_neqs<BurnT>();
2222

@@ -38,46 +38,63 @@ void actual_integrator (BurnT& state, Real dt)
3838
// Save the initial composition and temperature for our later diagnostics.
3939

4040
#ifndef AMREX_USE_GPU
41-
Real xn_in[NumSpec];
41+
amrex::Real xn_in[NumSpec];
4242
for (int n = 0; n < NumSpec; ++n) {
4343
xn_in[n] = state.y[SFS+n] / state.y[SRHO];
4444
}
4545
// we are assuming that the temperature was valid on input
46-
Real T_in = state.T;
46+
amrex::Real T_in = state.T;
4747
#ifdef AUX_THERMO
48-
Real aux_in[NumAux];
48+
amrex::Real aux_in[NumAux];
4949
for (int n = 0; n < NumAux; ++n) {
5050
aux_in[n] = state.y[SFX+n] / state.y[SRHO];
5151
}
5252
#endif
53-
Real rhoe_in = state.y[SEINT];
53+
amrex::Real rhoe_in = state.y[SEINT];
5454
#endif
5555

5656

5757
// Set the tolerances.
5858

59-
Real sdc_tol_fac = std::pow(sdc_burn_tol_factor, state.num_sdc_iters - state.sdc_iter - 1);
59+
amrex::Real sdc_tol_fac = std::pow(sdc_burn_tol_factor, state.num_sdc_iters - state.sdc_iter - 1);
6060

6161
// we use 1-based indexing inside of RKC, so we need to shift the
6262
// indices SRHO, SFS, etc by 1
6363

64-
Real sdc_min_density = amrex::min(state.rho, state.rho_orig + state.ydot_a[SRHO] * dt);
64+
amrex::Real sdc_min_density = amrex::min(state.rho, state.rho_orig + state.ydot_a[SRHO] * dt);
6565

66-
rkc_state.atol_enuc = sdc_min_density * atol_enuc * sdc_tol_fac;
67-
rkc_state.rtol_enuc = rtol_enuc * sdc_tol_fac;
66+
if (!is_retry) {
67+
68+
rkc_state.atol_enuc = sdc_min_density * atol_enuc * sdc_tol_fac;
69+
rkc_state.rtol_enuc = rtol_enuc * sdc_tol_fac;
70+
71+
// Note: we define the input atol for species to refer only to the
72+
// mass fraction part, and we multiply by a representative density
73+
// so that atol becomes an absolutely tolerance on (rho X)
74+
75+
rkc_state.atol_spec = sdc_min_density * atol_spec * sdc_tol_fac;
76+
rkc_state.rtol_spec = rtol_spec * sdc_tol_fac;
77+
78+
} else {
79+
80+
rkc_state.atol_enuc = sdc_min_density * retry_atol_enuc * sdc_tol_fac;
81+
rkc_state.rtol_enuc = retry_rtol_enuc * sdc_tol_fac;
82+
83+
// Note: we define the input atol for species to refer only to the
84+
// mass fraction part, and we multiply by a representative density
85+
// so that atol becomes an absolutely tolerance on (rho X)
86+
87+
rkc_state.atol_spec = sdc_min_density * retry_atol_spec * sdc_tol_fac;
88+
rkc_state.rtol_spec = retry_rtol_spec * sdc_tol_fac;
89+
90+
}
6891

6992
if (scale_system) {
7093
// the absolute tol for energy needs to reflect the scaled
7194
// energy the integrator sees
7295
rkc_state.atol_enuc /= state.e_scale;
7396
}
7497

75-
// Note: we define the input atol for species to refer only to the
76-
// mass fraction part, and we multiply by a representative density
77-
// so that atol becomes an absolutely tolerance on (rho X)
78-
79-
rkc_state.atol_spec = sdc_min_density * atol_spec * sdc_tol_fac;
80-
rkc_state.rtol_spec = rtol_spec * sdc_tol_fac;
8198

8299
// Call the integration routine.
83100

@@ -98,7 +115,7 @@ void actual_integrator (BurnT& state, Real dt)
98115
// we only evolved (rho e), not (rho E), so we need to update the
99116
// total energy now to ensure we are conservative
100117

101-
Real rho_Sdot = 0.0_rt;
118+
amrex::Real rho_Sdot = 0.0_rt;
102119
if (state.time > 0) {
103120
rho_Sdot = (state.y[SEINT] - state.rhoe_orig) / state.time - state.ydot_a[SEINT];
104121
}
@@ -164,14 +181,14 @@ void actual_integrator (BurnT& state, Real dt)
164181
std::cout << "temp start = " << std::setprecision(16) << T_in << std::endl;
165182
std::cout << "rhoe start = " << std::setprecision(16) << rhoe_in << std::endl;
166183
std::cout << "xn start = ";
167-
for (int n = 0; n < NumSpec; ++n) {
168-
std::cout << std::setprecision(16) << xn_in[n] << " ";
184+
for (auto X : xn_in) {
185+
std::cout << std::setprecision(16) << X << " ";
169186
}
170187
std::cout << std::endl;
171188
#ifdef AUX_THERMO
172189
std::cout << "aux start = ";
173-
for (int n = 0; n < NumAux; ++n) {
174-
std::cout << std::setprecision(16) << aux_in[n] << " ";
190+
for (auto aux : aux_in) {
191+
std::cout << std::setprecision(16) << aux << " ";
175192
}
176193
std::cout << std::endl;
177194
#endif

integration/utils/circle_theorem.H

+5-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
#ifdef STRANG
66
#include <integrator_type_strang.H>
77
#include <integrator_rhs_strang.H>
8-
#endif
9-
#ifdef SDC
8+
#else
109
#include <integrator_type_sdc.H>
1110
#include <integrator_rhs_sdc.H>
1211
#endif
@@ -23,7 +22,11 @@ void circle_theorem_sprad(const amrex::Real time, BurnT& state, T& int_state, am
2322
if (integrator_rp::jacobian == 1) {
2423
jac(time, state, int_state, jac_array);
2524
} else {
25+
#ifdef STRANG
2626
integrator_to_burn(int_state, state);
27+
#else
28+
int_to_burn(time, int_state, state);
29+
#endif
2730
jac_info_t jac_info;
2831
jac_info.h = 0.0_rt;
2932
numerical_jac(state, jac_info, jac_array);

0 commit comments

Comments
 (0)