Geant4-11
Public Member Functions | Private Member Functions | Private Attributes
G4ModifiedMidpoint Class Reference

#include <G4ModifiedMidpoint.hh>

Public Member Functions

void DoStep (const G4double yIn[], const G4double dydxIn[], G4double yOut[], G4double hstep) const
 
void DoStep (const G4double yIn[], const G4double dydxIn[], G4double yOut[], G4double hstep, G4double yMid[], G4double derivs[][G4FieldTrack::ncompSVEC]) const
 
 G4ModifiedMidpoint (G4EquationOfMotion *equation, G4int nvar=6, G4int steps=2)
 
G4EquationOfMotionGetEquationOfMotion ()
 
G4int GetNumberOfVariables () const
 
G4int GetSteps () const
 
void SetEquationOfMotion (G4EquationOfMotion *equation)
 
void SetSteps (G4int steps)
 
 ~G4ModifiedMidpoint ()=default
 

Private Member Functions

void copy (G4double dst[], const G4double src[]) const
 

Private Attributes

G4EquationOfMotionfEquation = nullptr
 
G4int fnvar = 0
 
G4int fsteps = 0
 

Detailed Description

Definition at line 41 of file G4ModifiedMidpoint.hh.

Constructor & Destructor Documentation

◆ G4ModifiedMidpoint()

G4ModifiedMidpoint::G4ModifiedMidpoint ( G4EquationOfMotion equation,
G4int  nvar = 6,
G4int  steps = 2 
)

Definition at line 36 of file G4ModifiedMidpoint.cc.

38 : fEquation(equation), fnvar(nvar), fsteps(steps)
39{
40 if (nvar <= 0)
41 {
42 G4Exception("G4ModifiedMidpoint::G4ModifiedMidpoint()",
43 "GeomField0002", FatalException,
44 "Invalid number of variables; must be greater than zero!");
45 }
46}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
G4EquationOfMotion * fEquation

References FatalException, and G4Exception().

◆ ~G4ModifiedMidpoint()

G4ModifiedMidpoint::~G4ModifiedMidpoint ( )
default

Member Function Documentation

◆ copy()

void G4ModifiedMidpoint::copy ( G4double  dst[],
const G4double  src[] 
) const
private

Definition at line 157 of file G4ModifiedMidpoint.cc.

158{
159 std::memcpy(dst, src, sizeof(G4double) * fnvar);
160}
double G4double
Definition: G4Types.hh:83

References fnvar.

Referenced by DoStep().

◆ DoStep() [1/2]

void G4ModifiedMidpoint::DoStep ( const G4double  yIn[],
const G4double  dydxIn[],
G4double  yOut[],
G4double  hstep 
) const

Definition at line 48 of file G4ModifiedMidpoint.cc.

50{
54 setValue(yIn, Value1D::LabTime, y0, y1, yTemp, yOut);
55
57
58 const G4double h = hstep / fsteps;
59 const G4double h2 = 2 * h;
60
61 // y1 = yIn + h * dydx
62 //
63 for (G4int i = 0; i < fnvar; ++i)
64 {
65 y1[i] = yIn[i] + h * dydyIn[i];
66 }
67
68 fEquation->RightHandSide(y1, dydx);
69
70 copy(y0, yIn);
71
72 // general step
73 // yTemp = y1; y1 = y0 + h2 * dydx; y0 = yTemp
74 //
75 for (G4int i = 1; i < fsteps; ++i)
76 {
77 copy(yTemp, y1);
78 for (G4int j = 0; j < fnvar; ++j)
79 {
80 y1[j] = y0[j] + h2 * dydx[j];
81 }
82 copy(y0, yTemp);
83
84 fEquation->RightHandSide(y1, dydx);
85 }
86
87 // last step
88 // yOut = 0.5 * (y0 + y1 + h * dydx)
89 //
90 for (G4int i = 0; i < fnvar; ++i)
91 {
92 yOut[i] = 0.5 * (y0[i] + y1[i] + h * dydx[i]);
93 }
94}
int G4int
Definition: G4Types.hh:85
void RightHandSide(const G4double y[], G4double dydx[]) const
void copy(G4double dst[], const G4double src[]) const
void setValue(const SourceArray &src, Value1D value, TargetArray &trg)

References copy(), fEquation, fnvar, fsteps, G4FieldTrack::ncompSVEC, G4EquationOfMotion::RightHandSide(), and field_utils::setValue().

Referenced by G4BulirschStoer::try_step().

◆ DoStep() [2/2]

void G4ModifiedMidpoint::DoStep ( const G4double  yIn[],
const G4double  dydxIn[],
G4double  yOut[],
G4double  hstep,
G4double  yMid[],
G4double  derivs[][G4FieldTrack::ncompSVEC] 
) const

Definition at line 96 of file G4ModifiedMidpoint.cc.

99{
103 setValue(yIn, Value1D::LabTime, y0, y1, yTemp, yMid, yOut);
104
105 const G4double h = hstep / fsteps;
106 const G4double h2 = 2 * h;
107
108 // y0 = yIn
109 copy(y0, yIn);
110
111 // y1 = y0 + h * dydx
112 for (G4int i = 0; i < fnvar; ++i)
113 {
114 y1[i] = y0[i] + h * dydxIn[i];
115 }
116
117 // result of first step already gives approximation
118 // at the center of the interval
119 //
120 if(fsteps == 2)
121 {
122 copy(yMid, y1);
123 }
124
125 fEquation->RightHandSide(y1, derivs[0]);
126
127 // general step
128 // yTemp = y1; y1 = y0 + h2 * dydx; y0 = yTemp
129 //
130 for (G4int i = 1; i < fsteps; ++i)
131 {
132 copy(yTemp, y1);
133 for (G4int j = 0; j < fnvar; ++j)
134 {
135 y1[j] = y0[j] + h2 * derivs[i-1][j];
136 }
137 copy(y0, yTemp);
138
139 // save approximation at the center of the interval
140 if(i == fsteps / 2 - 1 )
141 {
142 copy(yMid, y1);
143 }
144
145 fEquation->RightHandSide(y1, derivs[i]);
146 }
147
148 // last step
149 // yOut = 0.5 * (y0 + y1 + h * dydx)
150 //
151 for (G4int i = 0; i < fnvar; ++i)
152 {
153 yOut[i] = 0.5 * (y0[i] + y1[i] + h * derivs[fsteps-1][i]);
154 }
155}

References copy(), fEquation, fnvar, fsteps, G4FieldTrack::ncompSVEC, G4EquationOfMotion::RightHandSide(), and field_utils::setValue().

◆ GetEquationOfMotion()

G4EquationOfMotion * G4ModifiedMidpoint::GetEquationOfMotion ( )
inline

◆ GetNumberOfVariables()

G4int G4ModifiedMidpoint::GetNumberOfVariables ( ) const
inline

◆ GetSteps()

G4int G4ModifiedMidpoint::GetSteps ( ) const
inline

◆ SetEquationOfMotion()

void G4ModifiedMidpoint::SetEquationOfMotion ( G4EquationOfMotion equation)
inline

◆ SetSteps()

void G4ModifiedMidpoint::SetSteps ( G4int  steps)
inline

Field Documentation

◆ fEquation

G4EquationOfMotion* G4ModifiedMidpoint::fEquation = nullptr
private

Definition at line 70 of file G4ModifiedMidpoint.hh.

Referenced by DoStep().

◆ fnvar

G4int G4ModifiedMidpoint::fnvar = 0
private

Definition at line 71 of file G4ModifiedMidpoint.hh.

Referenced by copy(), and DoStep().

◆ fsteps

G4int G4ModifiedMidpoint::fsteps = 0
private

Definition at line 72 of file G4ModifiedMidpoint.hh.

Referenced by DoStep().


The documentation for this class was generated from the following files: