86{
87 if(m_max_dt < dt)
88 {
89
90
91 dt = m_max_dt;
93 }
94
95 if (dt != m_dt_last)
96 {
98 }
99
101
103
104
105
106 for(
G4int k = 0; k <= m_current_k_opt+1; ++k)
107 {
108
109
110 m_midpoint.
SetSteps(m_interval_sequence[k]);
111 if(k == 0)
112 {
113 m_midpoint.
DoStep(in, dxdt, out, dt);
114
115 }
116 else
117 {
118 m_midpoint.
DoStep(in, dxdt, m_table[k-1], dt);
119 extrapolate(k, out);
120
121 for (
G4int i = 0; i < fnvar; ++i)
122 {
123 m_err[i] = out[i] - m_table[0][i];
124 }
127 h_opt[k] = calc_h_opt(dt, error, k);
128 work[k] =
static_cast<G4double>(m_cost[k]) / h_opt[k];
129
130 if( (k == m_current_k_opt-1) || m_first)
131 {
132 if(error < 1.0)
133 {
134
135 reject = false;
136 if( (work[k] < KFAC2 * work[k-1]) || (m_current_k_opt <= 2) )
137 {
138
139 m_current_k_opt = std::min(m_k_max - 1 , std::max(2 , k + 1));
140 new_h = h_opt[k];
141 new_h *=
static_cast<G4double>(m_cost[k + 1])
143 }
144 else
145 {
146 m_current_k_opt = std::min(m_k_max - 1, std::max(2, k));
147 new_h = h_opt[k];
148 }
149 break;
150 }
151 else if(should_reject(error , k) && !m_first)
152 {
153 reject = true;
154 new_h = h_opt[k];
155 break;
156 }
157 }
158 if(k == m_current_k_opt)
159 {
160 if(error < 1.0)
161 {
162
163 reject = false;
164 if(work[k-1] < KFAC2 * work[k])
165 {
166 m_current_k_opt = std::max( 2 , m_current_k_opt-1 );
167 new_h = h_opt[m_current_k_opt];
168 }
169 else if( (work[k] < KFAC2 * work[k-1]) && !m_last_step_rejected )
170 {
171 m_current_k_opt = std::min(m_k_max - 1, m_current_k_opt + 1);
172 new_h = h_opt[k];
173 new_h *=
static_cast<G4double>(m_cost[m_current_k_opt])
175 }
176 else
177 {
178 new_h = h_opt[m_current_k_opt];
179 }
180 break;
181 }
182 else if(should_reject(error, k))
183 {
184 reject = true;
185 new_h = h_opt[m_current_k_opt];
186 break;
187 }
188 }
189 if(k == m_current_k_opt + 1)
190 {
191 if(error < 1.0)
192 {
193 reject = false;
194 if(work[k-2] < KFAC2 * work[k-1])
195 {
196 m_current_k_opt = std::max(2, m_current_k_opt - 1);
197 }
198 if((work[k] < KFAC2 * work[m_current_k_opt]) && !m_last_step_rejected)
199 {
200 m_current_k_opt = std::min(m_k_max - 1 , k);
201 }
202 new_h = h_opt[m_current_k_opt];
203 }
204 else
205 {
206 reject = true;
207 new_h = h_opt[m_current_k_opt];
208 }
209 break;
210 }
211 }
212 }
213
214 if(!reject)
215 {
216 t += dt;
217 }
218
219 if(!m_last_step_rejected || new_h < dt)
220 {
221
222 new_h = std::min(m_max_dt, new_h);
223 m_dt_last = new_h;
224 dt = new_h;
225 }
226
227 m_last_step_rejected = reject;
228 m_first = false;
229
231}
void SetSteps(G4int steps)
void DoStep(const G4double yIn[], const G4double dydxIn[], G4double yOut[], G4double hstep) const
G4double relativeError(const G4double y[], const G4double yerr[], G4double hstep, G4double errorTolerance)