Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4BulirschStoer.hh
Go to the documentation of this file.
1// ********************************************************************
2// * License and Disclaimer *
3// * *
4// * The Geant4 software is copyright of the Copyright Holders of *
5// * the Geant4 Collaboration. It is provided under the terms and *
6// * conditions of the Geant4 Software License, included in the file *
7// * LICENSE and available at http://cern.ch/geant4/license . These *
8// * include a list of copyright holders. *
9// * *
10// * Neither the authors of this software system, nor their employing *
11// * institutes,nor the agencies providing financial support for this *
12// * work make any representation or warranty, express or implied, *
13// * regarding this software system or assume any liability for its *
14// * use. Please see the license in the file LICENSE and URL above *
15// * for the full disclaimer and the limitation of liability. *
16// * *
17// * This code implementation is the result of the scientific and *
18// * technical work of the GEANT4 collaboration. *
19// * By using, copying, modifying or distributing the software (or *
20// * any work based on the software) you agree to acknowledge its *
21// * use in resulting scientific publications, and indicate your *
22// * acceptance of all terms of the Geant4 Software license. *
23// ********************************************************************
24//
25// G4BulirschStoer
26//
27// Class description:
28//
29// The Bulirsch-Stoer is a controlled driver that adjusts both step size
30// and order of the method. The algorithm uses the modified midpoint and
31// a polynomial extrapolation computes the solution.
32
33// Author: Dmitry Sorokin (CERN, Google Summer of Code 2016), 13.02.2018
34// Supervision: John Apostolakis (CERN)
35// --------------------------------------------------------------------
36#ifndef G4BULIRSCH_STOER_HH
37#define G4BULIRSCH_STOER_HH
38
39#include "G4ModifiedMidpoint.hh"
40
41#include "G4FieldTrack.hh"
42
43/**
44 * @brief G4BulirschStoer is a controlled driver that adjusts both step size
45 * and order of the method. The algorithm uses the modified midpoint and
46 * a polynomial extrapolation computes the solution.
47 */
48
50{
51 public:
52
53 enum class step_result { success, fail };
54
55 /**
56 * Constructor for G4BulirschStoer.
57 * @param[in] equation Pointer to the provided equation of motion.
58 * @param[in] nvar The number of integration variables.
59 * @param[in] eps_rel Relative tolerance.
60 * @param[in] max_dt Maximum allowed time step.
61 */
63 G4double eps_rel, G4double max_dt = DBL_MAX);
64
65 /**
66 * Default Destructor.
67 */
68 ~G4BulirschStoer() = default;
69
70 /**
71 * Modifiers.
72 */
73 inline void set_max_dt(G4double max_dt);
74 inline void set_max_relative_error(G4double eps_rel);
75
76 /**
77 * Stepper method.
78 * @param[in] in Initial position.
79 * @param[in] dxdt dxdt for mid-point calculation.
80 * @param[out] t The updated step.
81 * @param[out] out Updated position.
82 * @param[in,out] dt Step size.
83 * @returns success if step is not rejected.
84 */
85 step_result try_step(const G4double in[], const G4double dxdt[],
86 G4double& t, G4double out[], G4double& dt);
87
88 /**
89 * Resets the internal state of the stepper.
90 */
91 void reset();
92
93 /**
94 * Setter and getter for the equation of motion.
95 */
98
99 /**
100 * Returns the number of integration variables.
101 */
103
104 private:
105
106 /**
107 * Polynomial extrapolation.
108 */
109 void extrapolate(std::size_t k, G4double xest[]);
110
111 /**
112 * Calculates the optimal step size for a given error and stage number.
113 */
114 G4double calc_h_opt(G4double h, G4double error, std::size_t k) const;
115
116 /**
117 * Calculates the optimal stage number.
118 */
119 G4bool set_k_opt(std::size_t k, G4double& dt);
120
121 /**
122 * Utilities.
123 */
124 G4bool in_convergence_window(G4int k) const;
125 G4bool should_reject(G4double error, G4int k) const;
126
127 private:
128
129 /** Maximum number of stages. */
130 const static G4int m_k_max = 8;
131
132 /** Number of vars to be integrated. */
133 G4int fnvar;
134
135 /** Relative tolerance. */
136 G4double m_eps_rel;
137
138 /** Modified midpoint algorithm. */
139 G4ModifiedMidpoint m_midpoint;
140
141 /** Flags for step. */
142 G4bool m_last_step_rejected{false};
143 G4bool m_first{true};
144
145 /** Last step size. */
146 G4double m_dt_last{0.0};
147
148 /** Max allowed time step. */
149 G4double m_max_dt;
150
151 /** Crude estimate of optimal order. */
152 G4int m_current_k_opt;
153
154 /** Error estimate. */
156
157 /** Stores the successive interval counts. */
158 G4int m_interval_sequence[m_k_max+1];
159
160 /** Extrapolation coeffs (Neville's algorithm). */
161 G4double m_coeff[m_k_max+1][m_k_max];
162
163 /** Costs for interval count. */
164 G4int m_cost[m_k_max+1];
165
166 /** Sequence of states for extrapolation. */
167 G4double m_table[m_k_max][G4FieldTrack::ncompSVEC];
168
169 /** Optimal step size. */
170 G4double h_opt[m_k_max+1];
171
172 /** Work per unit step. */
173 G4double work[m_k_max+1];
174};
175
176#include "G4BulirschStoer.icc"
177
178#endif
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
void SetEquationOfMotion(G4EquationOfMotion *equation)
G4EquationOfMotion * GetEquationOfMotion() const
~G4BulirschStoer()=default
void set_max_dt(G4double max_dt)
G4BulirschStoer(G4EquationOfMotion *equation, G4int nvar, G4double eps_rel, G4double max_dt=DBL_MAX)
G4int GetNumberOfVariables() const
step_result try_step(const G4double in[], const G4double dxdt[], G4double &t, G4double out[], G4double &dt)
void set_max_relative_error(G4double eps_rel)
G4EquationOfMotion is the abstract base class for the right hand size of the equation of motion of a ...
G4ModifiedMidpoint implements a midpoint method adapted from Boost odeint.
#define DBL_MAX
Definition templates.hh:62