49 : fnvar(nvar), m_eps_rel(eps_rel), m_midpoint(equation,nvar), m_max_dt(max_dt)
53 for(
G4int i = 0; i < m_k_max + 1; ++i)
55 m_interval_sequence[i] = 2 * (i + 1);
58 m_cost[i] = m_interval_sequence[i];
62 m_cost[i] = m_cost[i-1] + m_interval_sequence[i];
64 for(
G4int k = 0; k < i; ++k)
67 /
static_cast<G4double>(m_interval_sequence[k]);
68 m_coeff[i][k] = 1.0 / (r * r - 1.0);
105 for(
G4int k = 0; k <= m_current_k_opt+1; ++k)
109 m_midpoint.SetSteps(m_interval_sequence[k]);
112 m_midpoint.DoStep(in, dxdt, out, dt);
117 m_midpoint.DoStep(in, dxdt, m_table[k-1], dt);
120 for (
G4int i = 0; i < fnvar; ++i)
122 m_err[i] = out[i] - m_table[0][i];
126 h_opt[k] = calc_h_opt(dt, error, k);
127 work[k] =
static_cast<G4double>(m_cost[k]) / h_opt[k];
129 if( (k == m_current_k_opt-1) || m_first)
135 if( (work[k] < KFAC2 * work[k-1]) || (m_current_k_opt <= 2) )
138 m_current_k_opt = std::min(m_k_max - 1 , std::max(2 , k + 1));
140 new_h *=
static_cast<G4double>(m_cost[k + 1])
145 m_current_k_opt = std::min(m_k_max - 1, std::max(2, k));
150 if(should_reject(error , k) && !m_first)
157 if(k == m_current_k_opt)
163 if(work[k-1] < KFAC2 * work[k])
165 m_current_k_opt = std::max( 2 , m_current_k_opt-1 );
166 new_h = h_opt[m_current_k_opt];
168 else if( (work[k] < KFAC2 * work[k-1]) && !m_last_step_rejected )
170 m_current_k_opt = std::min(m_k_max - 1, m_current_k_opt + 1);
172 new_h *=
static_cast<G4double>(m_cost[m_current_k_opt])
177 new_h = h_opt[m_current_k_opt];
181 if(should_reject(error, k))
184 new_h = h_opt[m_current_k_opt];
188 if(k == m_current_k_opt + 1)
193 if(work[k-2] < KFAC2 * work[k-1])
195 m_current_k_opt = std::max(2, m_current_k_opt - 1);
197 if((work[k] < KFAC2 * work[m_current_k_opt]) && !m_last_step_rejected)
199 m_current_k_opt = std::min(m_k_max - 1 , k);
201 new_h = h_opt[m_current_k_opt];
206 new_h = h_opt[m_current_k_opt];
218 if(!m_last_step_rejected || new_h < dt)
221 new_h = std::min(m_max_dt, new_h);
226 m_last_step_rejected = reject;