|
| 1 | +#ifndef actual_integrator_H |
| 2 | +#define actual_integrator_H |
| 3 | + |
| 4 | +#include <iomanip> |
| 5 | + |
| 6 | +#include <be_type.H> |
| 7 | +#include <be_integrator.H> |
| 8 | +#include <extern_parameters.H> |
| 9 | + |
| 10 | +AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE |
| 11 | +void actual_integrator (burn_t& state, const Real dt) |
| 12 | +{ |
| 13 | + |
| 14 | + be_t be; |
| 15 | + |
| 16 | + // set the Jacobian type |
| 17 | + be.jacobian_type = jacobian; |
| 18 | + |
| 19 | + // Start off by assuming a successful burn. |
| 20 | + |
| 21 | + state.success = true; |
| 22 | + |
| 23 | + // Initialize the integration time. |
| 24 | + |
| 25 | + be.t = 0.0; |
| 26 | + be.tout = dt; |
| 27 | + |
| 28 | + // Fill in the initial integration state. |
| 29 | + |
| 30 | + burn_to_int(state, be); |
| 31 | + |
| 32 | + // Save the initial composition and temperature for our later diagnostics. |
| 33 | + |
| 34 | +#ifndef AMREX_USE_GPU |
| 35 | + Real xn_in[NumSpec]; |
| 36 | + for (int n = 0; n < NumSpec; ++n) { |
| 37 | + xn_in[n] = state.y[SFS+n] / state.y[SRHO]; |
| 38 | + } |
| 39 | + // we are assuming that the temperature was valid on input |
| 40 | + Real T_in = state.T; |
| 41 | +#ifdef AUX_THERMO |
| 42 | + Real aux_in[NumAux]; |
| 43 | + for (int n = 0; n < NumAux; ++n) { |
| 44 | + aux_in[n] = state.y[SFX+n] / state.y[SRHO]; |
| 45 | + } |
| 46 | +#endif |
| 47 | + Real rhoe_in = state.y[SEINT]; |
| 48 | +#endif |
| 49 | + |
| 50 | + |
| 51 | + // Set the tolerances. |
| 52 | + |
| 53 | + Real sdc_tol_fac = std::pow(sdc_burn_tol_factor, state.num_sdc_iters - state.sdc_iter - 1); |
| 54 | + |
| 55 | + // we use 1-based indexing inside of BackwardEuler, so we need to shift the |
| 56 | + // indices SRHO, SFS, etc by 1 |
| 57 | + |
| 58 | + Real sdc_min_density = amrex::min(state.rho, state.rho_orig + state.ydot_a[SRHO] * dt); |
| 59 | + |
| 60 | + be.atol_enuc = sdc_min_density * atol_enuc * sdc_tol_fac; |
| 61 | + be.rtol_enuc = rtol_enuc * sdc_tol_fac; |
| 62 | + |
| 63 | + // Note: we define the input atol for species to refer only to the |
| 64 | + // mass fraction part, and we multiply by a representative density |
| 65 | + // so that atol becomes an absolutely tolerance on (rho X) |
| 66 | + |
| 67 | + be.atol_spec = sdc_min_density * atol_spec * sdc_tol_fac; |
| 68 | + be.rtol_spec = rtol_spec * sdc_tol_fac; |
| 69 | + |
| 70 | + // Call the integration routine. |
| 71 | + |
| 72 | + int istate = be_integrator(state, be); |
| 73 | + |
| 74 | + // Get the number of RHS and Jacobian evaluations. |
| 75 | + |
| 76 | + state.n_rhs = be.n_rhs; |
| 77 | + state.n_jac = be.n_jac; |
| 78 | + state.n_step = be.n_step; |
| 79 | + |
| 80 | + // Copy the integration data back to the burn state. |
| 81 | + // This will also update the aux state from X if we are using NSE |
| 82 | + |
| 83 | + int_to_burn(be.t, be, state); |
| 84 | + |
| 85 | + // we only evolved (rho e), not (rho E), so we need to update the |
| 86 | + // total energy now to ensure we are conservative |
| 87 | + |
| 88 | + Real rho_Sdot = 0.0_rt; |
| 89 | + if (state.time > 0) { |
| 90 | + rho_Sdot = (be.y(SEINT+1) - state.rhoe_orig) / state.time - state.ydot_a[SEINT]; |
| 91 | + } |
| 92 | + |
| 93 | + state.y[SEDEN] += state.time * (state.ydot_a[SEDEN] + rho_Sdot); |
| 94 | + |
| 95 | + // also momentum |
| 96 | + |
| 97 | + state.y[SMX] += state.time * state.ydot_a[SMX]; |
| 98 | + state.y[SMY] += state.time * state.ydot_a[SMY]; |
| 99 | + state.y[SMZ] += state.time * state.ydot_a[SMZ]; |
| 100 | + |
| 101 | + // normalize the abundances on exit. We'll assume that the driver |
| 102 | + // calling this is making use of the conserved state (state.y[]), |
| 103 | + // so that is what will be normalized. |
| 104 | + |
| 105 | + normalize_abundances_sdc_burn(state); |
| 106 | + |
| 107 | + if (istate < 0) { |
| 108 | + state.success = false; |
| 109 | + } |
| 110 | + |
| 111 | + |
| 112 | +#ifndef AMREX_USE_GPU |
| 113 | + if (burner_verbose) { |
| 114 | + // Print out some integration statistics, if desired. |
| 115 | + std::cout << "integration summary: " << std::endl; |
| 116 | + std::cout << "dens: " << state.rho << " temp: " << state.T << std::endl; |
| 117 | + std::cout << "energy released: " << state.e << std::endl; |
| 118 | + std::cout << "number of steps taken: " << state.n_step << std::endl; |
| 119 | + std::cout << "number of f evaluations: " << state.n_rhs << std::endl; |
| 120 | + } |
| 121 | +#endif |
| 122 | + |
| 123 | + // If we failed, print out the current state of the integration. |
| 124 | + |
| 125 | + if (!state.success) { |
| 126 | +#ifndef AMREX_USE_GPU |
| 127 | + std::cout << Font::Bold << FGColor::Red << "[ERROR] integration failed in net" << ResetDisplay << std::endl; |
| 128 | + std::cout << "istate = " << istate << std::endl; |
| 129 | + std::cout << "zone = (" << state.i << ", " << state.j << ", " << state.k << ")" << std::endl; |
| 130 | + std::cout << "time = " << be.t << std::endl; |
| 131 | + std::cout << "dt = " << std::setprecision(16) << dt << std::endl; |
| 132 | + std::cout << "dens start = " << std::setprecision(16) << state.rho_orig << std::endl; |
| 133 | + std::cout << "temp start = " << std::setprecision(16) << T_in << std::endl; |
| 134 | + std::cout << "rhoe start = " << std::setprecision(16) << rhoe_in << std::endl; |
| 135 | + std::cout << "xn start = "; |
| 136 | + for (int n = 0; n < NumSpec; ++n) { |
| 137 | + std::cout << std::setprecision(16) << xn_in[n] << " "; |
| 138 | + } |
| 139 | + std::cout << std::endl; |
| 140 | +#ifdef AUX_THERMO |
| 141 | + std::cout << "aux start = "; |
| 142 | + for (int n = 0; n < NumAux; ++n) { |
| 143 | + std::cout << std::setprecision(16) << aux_in[n] << " "; |
| 144 | + } |
| 145 | + std::cout << std::endl; |
| 146 | +#endif |
| 147 | + std::cout << "dens current = " << std::setprecision(16) << state.rho << std::endl; |
| 148 | + std::cout << "temp current = " << std::setprecision(16) << state.T << std::endl; |
| 149 | + std::cout << "xn current = "; |
| 150 | + for (int n = 0; n < NumSpec; ++n) { |
| 151 | + std::cout << std::setprecision(16) << state.xn[n] << " "; |
| 152 | + } |
| 153 | + std::cout << std::endl; |
| 154 | +#ifdef AUX_THERMO |
| 155 | + std::cout << "aux current = "; |
| 156 | + for (int n = 0; n < NumAux; ++n) { |
| 157 | + std::cout << std::setprecision(16) << state.aux[n] << " "; |
| 158 | + } |
| 159 | + std::cout << std::endl; |
| 160 | +#endif |
| 161 | + std::cout << "A(rho) = " << std::setprecision(16) << state.ydot_a[SRHO] << std::endl; |
| 162 | + std::cout << "A(rho e) = " << std::setprecision(16) << state.ydot_a[SEINT] << std::endl; |
| 163 | + std::cout << "A(rho X_k) = "; |
| 164 | + for (int n = 0; n < NumSpec; n++) { |
| 165 | + std::cout << std::setprecision(16) << state.ydot_a[SFS+n] << " "; |
| 166 | + } |
| 167 | + std::cout << std::endl; |
| 168 | +#ifdef AUX_THERMO |
| 169 | + std::cout << "A(rho aux_k) = "; |
| 170 | + for (int n = 0; n < NumAux; n++) { |
| 171 | + std::cout << std::setprecision(16) << state.ydot_a[SFX+n] << " "; |
| 172 | + } |
| 173 | + std::cout << std::endl; |
| 174 | +#endif |
| 175 | +#endif |
| 176 | + } |
| 177 | + |
| 178 | + |
| 179 | +} |
| 180 | + |
| 181 | +#endif |
0 commit comments