Skip to content

Commit 5e1de1e

Browse files
committed
add a normalization only after successful VODE step
1 parent 4fdcf27 commit 5e1de1e

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

integration/VODE/vode_dvstep.H

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,18 @@ int dvstep (BurnT& state, DvodeT& vstate)
223223

224224
#ifdef SDC
225225
if (vstate.y(SEINT+1) < 0.0_rt) {
226+
#ifdef MICROPHYSICS_DEBUG
227+
std::cout << "rejecting due to rho e" << std::endl;
228+
#endif
226229
valid_update = false;
227230
}
228231

229232
amrex::Real rho_current = state.rho_orig + vstate.tn * state.ydot_a[SRHO];
230233

231234
if (rho_current < 0.0_rt) {
235+
#ifdef MICROPHYSICS_DEBUG
236+
std::cout << "rejecting due to rho" << std::endl;
237+
#endif
232238
valid_update = false;
233239
}
234240
#endif
@@ -294,11 +300,17 @@ int dvstep (BurnT& state, DvodeT& vstate)
294300
}
295301

296302
if (vstate.y(SFS+i) < -species_failure_tolerance * rho_current) {
303+
#ifdef MICROPHYSICS_DEBUG
304+
std::cout << "rejecting step due to negative species " << i << std::endl;
305+
#endif
297306
valid_update = false;
298307
break;
299308
}
300309

301310
if (vstate.y(SFS+i) > (1.0_rt + species_failure_tolerance) * rho_current) {
311+
#ifdef MICROPHYSICS_DEBUG
312+
std::cout << "rejecting step due to large species " << i << std::endl;
313+
#endif
302314
valid_update = false;
303315
break;
304316
}
@@ -313,6 +325,19 @@ int dvstep (BurnT& state, DvodeT& vstate)
313325
DSM = ACNRM / vstate.tq(2);
314326
if (DSM <= 1.0_rt && valid_update) {
315327

328+
#ifdef SDC
329+
// do normalization if desired
330+
amrex::Real rhoX_sum{};
331+
for (int n = 1; n <= NumSpec; ++n) {
332+
vstate.y(SFS+n) = amrex::Clamp(vstate.y(SFS+n), 0.0, rho_current);
333+
rhoX_sum += vstate.y(SFS+n);
334+
}
335+
336+
amrex::Real fac = rho_current / rhoX_sum;
337+
for (int n = 1; n <= NumSpec; ++n) {
338+
vstate.y(SFS+n) *= fac;
339+
}
340+
#endif
316341
// After a successful step, update the yh and TAU arrays and decrement
317342
// NQWAIT. If NQWAIT is then 1 and NQ .lt. MAXORD, then ACOR is saved
318343
// for use in a possible order increase on the next step.

integration/integrator_setup_sdc.H

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ struct state_backup_t {
1919
amrex::Real T_in{};
2020
amrex::Real rhoe_in{};
2121
#ifndef AMREX_USE_GPU
22-
amrex::Real xn_in[NumSpec]{};
22+
amrex::Real rhoxn_in[NumSpec]{};
2323
#ifdef AUX_THERMO
24-
amrex::Real aux_in[NumAux]{};
24+
amrex::Real rhoaux_in[NumAux]{};
2525
#endif
2626
#endif
2727
};
@@ -115,11 +115,11 @@ state_backup_t integrator_backup (const BurnT& state) {
115115

116116
#ifndef AMREX_USE_GPU
117117
for (int n = 0; n < NumSpec; ++n) {
118-
state_save.xn_in[n] = state.y[SFS+n] / state.y[SRHO];
118+
state_save.rhoxn_in[n] = state.y[SFS+n];
119119
}
120120
#ifdef AUX_THERMO
121121
for (int n = 0; n < NumAux; ++n) {
122-
state_save.aux_in[n] = state.y[SFX+n] / state.y[SRHO];
122+
state_save.rhoaux_in[n] = state.y[SFX+n];
123123
}
124124
#endif
125125
#endif
@@ -223,14 +223,14 @@ void integrator_cleanup (IntegratorT& int_state, BurnT& state,
223223
std::cout << "dens start = " << std::setprecision(OUTDIGITS) << state.rho_orig << std::endl;
224224
std::cout << "temp start = " << std::setprecision(OUTDIGITS) << state_save.T_in << std::endl;
225225
std::cout << "rhoe start = " << std::setprecision(OUTDIGITS) << state_save.rhoe_in << std::endl;
226-
std::cout << "xn start = ";
227-
for (const auto X : state_save.xn_in) {
226+
std::cout << "rho xn start = ";
227+
for (const auto X : state_save.rhoxn_in) {
228228
std::cout << std::setprecision(OUTDIGITS) << X << " ";
229229
}
230230
std::cout << std::endl;
231231
#ifdef AUX_THERMO
232-
std::cout << "aux start = ";
233-
for (const auto aux : state_save.aux_in) {
232+
std::cout << "rho aux start = ";
233+
for (const auto aux : state_save.rhoaux_in) {
234234
std::cout << std::setprecision(OUTDIGITS) << aux << " ";
235235
}
236236
std::cout << std::endl;

0 commit comments

Comments
 (0)