| 120 | } |
| 121 | |
| 122 | double SteadyStateSystem::timeStep(int nsteps, double dt, double* x, double* r, int loglevel) |
| 123 | { |
| 124 | // set the Jacobian age parameter to the transient value |
| 125 | newton().setOptions(m_ts_jac_age); |
| 126 | |
| 127 | int n = 0; |
| 128 | int successiveFailures = 0; |
| 129 | |
| 130 | // Only output this if nothing else under this function call will be output |
| 131 | if (loglevel == 1) { |
| 132 | writelog("\n============================"); |
| 133 | writelog("\n{:<5s} {:<11s} {:<7s}\n", "step", "dt (s)", "log(ss)"); |
| 134 | writelog("============================"); |
| 135 | } |
| 136 | while (n < nsteps) { |
| 137 | if (loglevel == 1) { // At level 1, output concise information |
| 138 | double ss = ssnorm(x, r); |
| 139 | writelog("\n{:<5d} {:<6.4e} {:>7.4f}", n, dt, log10(ss)); |
| 140 | } else if (loglevel > 1) { |
| 141 | double ss = ssnorm(x, r); |
| 142 | writelog("\nTimestep ({}) dt= {:<11.4e} log(ss)= {:<7.4f}", n, dt, log10(ss)); |
| 143 | } |
| 144 | |
| 145 | // set up for time stepping with stepsize dt |
| 146 | initTimeInteg(dt,x); |
| 147 | |
| 148 | int j0 = m_jac->nEvals(); // Store the current number of Jacobian evaluations |
| 149 | |
| 150 | // solve the transient problem |
| 151 | int status = newton().solve(x, r, *this, loglevel); |
| 152 | |
| 153 | // successful time step. Copy the new solution in r to |
| 154 | // the current solution in x. |
| 155 | if (status >= 0) { |
| 156 | if (loglevel > 1) { |
| 157 | writelog("\nTimestep ({}) succeeded", n); |
| 158 | } |
| 159 | successiveFailures = 0; |
| 160 | m_nsteps++; |
| 161 | n += 1; |
| 162 | copy(r, r + m_size, x); |
| 163 | // No Jacobian evaluations were performed, so a larger timestep can be used |
| 164 | if (m_jac->nEvals() == j0) { |
| 165 | dt *= 1.5; |
| 166 | } |
| 167 | if (m_time_step_callback) { |
| 168 | m_time_step_callback->eval(dt); |
| 169 | } |
| 170 | dt = std::min(dt, m_tmax); |
| 171 | if (m_nsteps >= m_nsteps_max) { |
| 172 | throw CanteraError("OneDim::timeStep", |
| 173 | "Took maximum number of timesteps allowed ({}) without " |
| 174 | "reaching steady-state solution.", m_nsteps_max); |
| 175 | } |
| 176 | } else { |
| 177 | // No solution could be found with this time step. |
| 178 | // Decrease the stepsize and try again. |
| 179 | successiveFailures++; |
nothing calls this directly
no test coverage detected