Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4ModifiedMidpoint.cc
이 파일의 문서화 페이지로 가기
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 //
26 // $Id: $
27 //
28 // G4ModifiedMidpoint implementation
29 // Based on modified_midpoint.hpp from boost
30 //
31 // Author: Dmitry Sorokin - GSoC 2016
32 //
34 
35 #include "G4ModifiedMidpoint.hh"
36 
38  G4int nvar, G4int steps )
39  : fEquation(equation), fnvar(nvar), fsteps(steps)
40 {
41  if (nvar <= 0)
42  {
43  G4Exception("G4ModifiedMidpoint::G4ModifiedMidpoint()",
44  "GeomField0002", FatalException,
45  "Invalid number of variables; must be greater than zero!");
46  }
47 }
48 
49 void G4ModifiedMidpoint::DoStep( const G4double yIn[], const G4double dydyIn[],
50  G4double yOut[], G4double hstep) const
51 {
56 
57  const G4double h = hstep / fsteps;
58  const G4double h2 = 2 * h;
59 
60  // y1 = yIn + h * dydx
61  for (G4int i = 0; i < fnvar; ++i)
62  {
63  y1[i] = yIn[i] + h * dydyIn[i];
64  }
65 
66  fEquation->RightHandSide(y1, dydx);
67 
68  copy(y0, yIn);
69 
70  // general step
71  // yTemp = y1; y1 = y0 + h2 * dydx; y0 = yTemp
72  for (G4int i = 1; i < fsteps; ++i)
73  {
74  copy(yTemp, y1);
75  for (G4int j = 0; j < fnvar; ++j)
76  {
77  y1[j] = y0[j] + h2 * dydx[j];
78  }
79  copy(y0, yTemp);
80 
81  fEquation->RightHandSide(y1, dydx);
82  }
83 
84  // last step
85  // yOut = 0.5 * (y0 + y1 + h * dydx)
86  for (G4int i = 0; i < fnvar; ++i)
87  {
88  yOut[i] = 0.5 * (y0[i] + y1[i] + h * dydx[i]);
89  }
90 }
91 
92 void G4ModifiedMidpoint::DoStep( const G4double yIn[], const G4double dydxIn[],
93  G4double yOut[], G4double hstep, G4double yMid[],
94  G4double derivs[][G4FieldTrack::ncompSVEC]) const
95 {
99 
100  const G4double h = hstep / fsteps;
101  const G4double h2 = 2 * h;
102 
103  // y0 = yIn
104  copy(y0, yIn);
105 
106  // y1 = y0 + h * dydx
107  for (G4int i = 0; i < fnvar; ++i)
108  {
109  y1[i] = y0[i] + h * dydxIn[i];
110  }
111 
112  // result of first step already gives approximation
113  // at the center of the interval
114  if(fsteps == 2)
115  {
116  copy(yMid, y1);
117  }
118 
119  fEquation->RightHandSide(y1, derivs[0]);
120 
121  // general step
122  // yTemp = y1; y1 = y0 + h2 * dydx; y0 = yTemp
123  for (G4int i = 1; i < fsteps; ++i)
124  {
125  copy(yTemp, y1);
126  for (G4int j = 0; j < fnvar; ++j)
127  {
128  y1[j] = y0[j] + h2 * derivs[i-1][j];
129  }
130  copy(y0, yTemp);
131 
132  // save approximation at the center of the interval
133  if(i == fsteps / 2 - 1 )
134  {
135  copy(yMid, y1);
136  }
137 
138  fEquation->RightHandSide(y1, derivs[i]);
139  }
140 
141  // last step
142  // yOut = 0.5 * (y0 + y1 + h * dydx)
143  for (G4int i = 0; i < fnvar; ++i)
144  {
145  yOut[i] = 0.5 * (y0[i] + y1[i] + h * derivs[fsteps-1][i]);
146  }
147 }
148 
149 void G4ModifiedMidpoint::copy(G4double dst[], const G4double src[]) const
150 {
151  std::memcpy(dst, src, sizeof(G4double) * fnvar);
152 }
Float_t y1[n_points_granero]
Definition: compare.C:5
G4EquationOfMotion * fEquation
double G4double
Definition: G4Types.hh:76
void DoStep(const G4double yIn[], const G4double dydxIn[], G4double yOut[], G4double hstep) const
TH1F * h2
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
int G4int
Definition: G4Types.hh:78
void copy(G4double dst[], const G4double src[]) const
void RightHandSide(const G4double y[], G4double dydx[]) const
G4ModifiedMidpoint(G4EquationOfMotion *equation, G4int nvar=6, G4int steps=2)