Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4TSimpleRunge.hh
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// G4TSimpleRunge
27//
28// Class description:
29//
30// Templated version of G4SimpleRunge.
31// Adapted from G4G4TSimpleRunge class.
32
33// Author: Josh Xie (CERN, Google Summer of Code 2014), June 2014
34// Supervisors: Sandro Wenzel, John Apostolakis (CERN)
35// --------------------------------------------------------------------
36#ifndef G4TSimpleRunge_HH
37#define G4TSimpleRunge_HH
38
39#include <cassert>
40#include "G4TMagErrorStepper.hh"
41#include "G4ThreeVector.hh"
42
43/**
44 * @brief G4TSimpleRunge is a templated version of G4SimpleRunge.
45 */
46
47template <class T_Equation, int N>
49 : public G4TMagErrorStepper<G4TSimpleRunge<T_Equation, N>, T_Equation, N>
50{
51 public:
52
53 static constexpr double IntegratorCorrection = 1. / ((1 << 2) - 1);
54
55 G4TSimpleRunge(T_Equation* EqRhs, G4int numberOfVariables = 6)
56 : G4TMagErrorStepper<G4TSimpleRunge<T_Equation, N>, T_Equation, N>(
57 EqRhs, numberOfVariables)
58 , fNumberOfVariables(numberOfVariables)
59 , fEquation_Rhs(EqRhs)
60
61 {
62 // default GetNumberOfStateVariables() == 12
63 assert(this->GetNumberOfStateVariables() <= 12);
64 }
65
66 ~G4TSimpleRunge() = default;
67
68 inline void RightHandSide(G4double y[],
69 G4double dydx[])
70 {
71 fEquation_Rhs->T_Equation::RightHandSide(y, dydx);
72 }
73
74 inline void DumbStepper(const G4double yIn[],
75 const G4double dydx[],
76 G4double h, G4double yOut[]) // override final
77 {
78 // Initialise time to t0, needed when it is not updated by the integration.
79 yTemp[7] = yOut[7] = yIn[7]; // Better to set it to NaN; // TODO
80
81 for(G4int i = 0; i < N; ++i)
82 {
83 yTemp[i] = yIn[i] + 0.5 * h * dydx[i];
84 }
85
86 this->RightHandSide(yTemp, dydxTemp);
87
88 for(G4int i = 0; i < N; ++i)
89 {
90 yOut[i] = yIn[i] + h * (dydxTemp[i]);
91 }
92 }
93
94 inline G4int IntegratorOrder() const { return 2; }
95
96 private:
97
98 G4int fNumberOfVariables;
99 G4double dydxTemp[N > 12 ? N : 12];
100 G4double yTemp[N > 12 ? N : 12];
101
102 T_Equation* fEquation_Rhs;
103 // scratch space
104};
105
106#endif
double G4double
Definition G4Types.hh:83
int G4int
Definition G4Types.hh:85
G4int GetNumberOfStateVariables() const
G4TMagErrorStepper(T_Equation *EqRhs, G4int numberOfVariables, G4int numStateVariables=12)
static constexpr double IntegratorCorrection
G4int IntegratorOrder() const
void DumbStepper(const G4double yIn[], const G4double dydx[], G4double h, G4double yOut[])
~G4TSimpleRunge()=default
G4TSimpleRunge(T_Equation *EqRhs, G4int numberOfVariables=6)
void RightHandSide(G4double y[], G4double dydx[])
#define N
Definition crc32.c:57