Geant4-11
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Attributes
G4AdjointInterpolator Class Reference

#include <G4AdjointInterpolator.hh>

Public Member Functions

G4double ExponentialInterpolation (G4double &x, G4double &x1, G4double &x2, G4double &y1, G4double &y2)
 
size_t FindPosition (G4double &x, std::vector< G4double > &x_vec, size_t ind_min=0, size_t ind_max=0)
 
size_t FindPositionForLogVector (G4double &x, std::vector< G4double > &x_vec)
 
 G4AdjointInterpolator (G4AdjointInterpolator &)=delete
 
G4double Interpolate (G4double &x, std::vector< G4double > &x_vec, std::vector< G4double > &y_vec, G4String InterPolMethod="Log")
 
G4double InterpolateForLogVector (G4double &x, std::vector< G4double > &x_vec, std::vector< G4double > &y_vec)
 
G4double InterpolateWithIndexVector (G4double &x, std::vector< G4double > &x_vec, std::vector< G4double > &y_vec, std::vector< size_t > &index_vec, G4double x0, G4double dx)
 
G4double Interpolation (G4double &x, G4double &x1, G4double &x2, G4double &y1, G4double &y2, G4String InterPolMethod="Log")
 
G4double LinearInterpolation (G4double &x, G4double &x1, G4double &x2, G4double &y1, G4double &y2)
 
G4double LogarithmicInterpolation (G4double &x, G4double &x1, G4double &x2, G4double &y1, G4double &y2)
 
G4AdjointInterpolatoroperator= (const G4AdjointInterpolator &right)=delete
 
 ~G4AdjointInterpolator ()
 

Static Public Member Functions

static G4AdjointInterpolatorGetAdjointInterpolator ()
 
static G4AdjointInterpolatorGetInstance ()
 

Private Member Functions

 G4AdjointInterpolator ()
 

Static Private Attributes

static G4ThreadLocal G4AdjointInterpolatorfInstance = nullptr
 

Detailed Description

Definition at line 41 of file G4AdjointInterpolator.hh.

Constructor & Destructor Documentation

◆ ~G4AdjointInterpolator()

G4AdjointInterpolator::~G4AdjointInterpolator ( )

Definition at line 51 of file G4AdjointInterpolator.cc.

51{}

◆ G4AdjointInterpolator() [1/2]

G4AdjointInterpolator::G4AdjointInterpolator ( G4AdjointInterpolator )
delete

◆ G4AdjointInterpolator() [2/2]

G4AdjointInterpolator::G4AdjointInterpolator ( )
private

Definition at line 48 of file G4AdjointInterpolator.cc.

48{}

Referenced by GetInstance().

Member Function Documentation

◆ ExponentialInterpolation()

G4double G4AdjointInterpolator::ExponentialInterpolation ( G4double x,
G4double x1,
G4double x2,
G4double y1,
G4double y2 
)

Definition at line 75 of file G4AdjointInterpolator.cc.

77{
78 G4double B = (std::log(y2) - std::log(y1)) / (x2 - x1);
79 G4double A = y1 * std::exp(-B * x1);
80 G4double res = A * std::exp(B * x);
81 return res;
82}
G4double B(G4double temperature)
double G4double
Definition: G4Types.hh:83
const G4double A[17]

References A, and B().

Referenced by Interpolation().

◆ FindPosition()

size_t G4AdjointInterpolator::FindPosition ( G4double x,
std::vector< G4double > &  x_vec,
size_t  ind_min = 0,
size_t  ind_max = 0 
)

Definition at line 114 of file G4AdjointInterpolator.cc.

117{
118 // most rapid method could be used probably
119
120 size_t ndim = x_vec.size();
121 size_t ind1 = 0;
122 size_t ind2 = ndim - 1;
123
124 if(ndim > 1)
125 {
126 if(x_vec[0] < x_vec[1])
127 { // increasing
128 do
129 {
130 size_t midBin = (ind1 + ind2) / 2;
131 if(x < x_vec[midBin])
132 ind2 = midBin;
133 else
134 ind1 = midBin;
135 } while(ind2 - ind1 > 1);
136 }
137 else
138 {
139 do
140 {
141 size_t midBin = (ind1 + ind2) / 2;
142 if(x < x_vec[midBin])
143 ind1 = midBin;
144 else
145 ind2 = midBin;
146 } while(ind2 - ind1 > 1);
147 }
148 }
149
150 return ind1;
151}

Referenced by G4AdjointCSMatrix::AddData(), FindPositionForLogVector(), Interpolate(), and InterpolateWithIndexVector().

◆ FindPositionForLogVector()

size_t G4AdjointInterpolator::FindPositionForLogVector ( G4double x,
std::vector< G4double > &  x_vec 
)

Definition at line 155 of file G4AdjointInterpolator.cc.

157{
158 // most rapid method could be used probably
159 return FindPosition(log_x, log_x_vec);
160}
size_t FindPosition(G4double &x, std::vector< G4double > &x_vec, size_t ind_min=0, size_t ind_max=0)

References FindPosition().

Referenced by G4AdjointCSManager::ComputeAdjointCS(), InterpolateForLogVector(), and G4VEmAdjointModel::SampleAdjSecEnergyFromCSMatrix().

◆ GetAdjointInterpolator()

G4AdjointInterpolator * G4AdjointInterpolator::GetAdjointInterpolator ( )
static

Definition at line 32 of file G4AdjointInterpolator.cc.

33{
34 return GetInstance();
35}
static G4AdjointInterpolator * GetInstance()

References GetInstance().

◆ GetInstance()

G4AdjointInterpolator * G4AdjointInterpolator::GetInstance ( )
static

◆ Interpolate()

G4double G4AdjointInterpolator::Interpolate ( G4double x,
std::vector< G4double > &  x_vec,
std::vector< G4double > &  y_vec,
G4String  InterPolMethod = "Log" 
)

Definition at line 163 of file G4AdjointInterpolator.cc.

167{
168 size_t i = FindPosition(x, x_vec);
169 return Interpolation(x, x_vec[i], x_vec[i + 1], y_vec[i], y_vec[i + 1],
170 InterPolMethod);
171}
G4double Interpolation(G4double &x, G4double &x1, G4double &x2, G4double &y1, G4double &y2, G4String InterPolMethod="Log")

References FindPosition(), and Interpolation().

Referenced by G4VEmAdjointModel::SampleAdjSecEnergyFromCSMatrix().

◆ InterpolateForLogVector()

G4double G4AdjointInterpolator::InterpolateForLogVector ( G4double x,
std::vector< G4double > &  x_vec,
std::vector< G4double > &  y_vec 
)

Definition at line 198 of file G4AdjointInterpolator.cc.

201{
202 size_t i = FindPositionForLogVector(log_x, log_x_vec);
203
204 G4double log_y = LinearInterpolation(log_x, log_x_vec[i], log_x_vec[i + 1],
205 log_y_vec[i], log_y_vec[i + 1]);
206 return log_y;
207}
G4double LinearInterpolation(G4double &x, G4double &x1, G4double &x2, G4double &y1, G4double &y2)
size_t FindPositionForLogVector(G4double &x, std::vector< G4double > &x_vec)

References FindPositionForLogVector(), and LinearInterpolation().

Referenced by G4AdjointCSManager::ComputeAdjointCS(), and G4VEmAdjointModel::SampleAdjSecEnergyFromCSMatrix().

◆ InterpolateWithIndexVector()

G4double G4AdjointInterpolator::InterpolateWithIndexVector ( G4double x,
std::vector< G4double > &  x_vec,
std::vector< G4double > &  y_vec,
std::vector< size_t > &  index_vec,
G4double  x0,
G4double  dx 
)

Definition at line 174 of file G4AdjointInterpolator.cc.

178{
179 size_t ind = 0;
180 if(x > x0)
181 ind = int((x - x0) / dx);
182 if(ind >= index_vec.size() - 1)
183 ind = index_vec.size() - 2;
184 size_t ind1 = index_vec[ind];
185 size_t ind2 = index_vec[ind + 1];
186 if(ind1 > ind2)
187 {
188 size_t ind11 = ind1;
189 ind1 = ind2;
190 ind2 = ind11;
191 }
192 ind = FindPosition(x, x_vec, ind1, ind2);
193 return Interpolation(x, x_vec[ind], x_vec[ind + 1], y_vec[ind],
194 y_vec[ind + 1], "Lin");
195}

References FindPosition(), and Interpolation().

◆ Interpolation()

G4double G4AdjointInterpolator::Interpolation ( G4double x,
G4double x1,
G4double x2,
G4double y1,
G4double y2,
G4String  InterPolMethod = "Log" 
)

Definition at line 85 of file G4AdjointInterpolator.cc.

89{
90 if(InterPolMethod == "Log")
91 {
92 return LogarithmicInterpolation(x, x1, x2, y1, y2);
93 }
94 else if(InterPolMethod == "Lin")
95 {
96 return LinearInterpolation(x, x1, x2, y1, y2);
97 }
98 else if(InterPolMethod == "Exp")
99 {
100 return ExponentialInterpolation(x, x1, x2, y1, y2);
101 }
102 else
103 {
105 ed << "The interpolation method that you invoked does not exist!\n";
106 G4Exception("G4AdjointInterpolator::Interpolation", "adoint001",
107 FatalException, ed);
108 return 0.;
109 }
110}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
G4double ExponentialInterpolation(G4double &x, G4double &x1, G4double &x2, G4double &y1, G4double &y2)
G4double LogarithmicInterpolation(G4double &x, G4double &x1, G4double &x2, G4double &y1, G4double &y2)

References ExponentialInterpolation(), FatalException, G4Exception(), LinearInterpolation(), and LogarithmicInterpolation().

Referenced by Interpolate(), and InterpolateWithIndexVector().

◆ LinearInterpolation()

G4double G4AdjointInterpolator::LinearInterpolation ( G4double x,
G4double x1,
G4double x2,
G4double y1,
G4double y2 
)

Definition at line 54 of file G4AdjointInterpolator.cc.

57{
58 G4double res = y1 + (x - x1) * (y2 - y1) / (x2 - x1);
59 return res;
60}

Referenced by G4AdjointCSManager::ComputeAdjointCS(), InterpolateForLogVector(), Interpolation(), LogarithmicInterpolation(), and G4VEmAdjointModel::SampleAdjSecEnergyFromCSMatrix().

◆ LogarithmicInterpolation()

G4double G4AdjointInterpolator::LogarithmicInterpolation ( G4double x,
G4double x1,
G4double x2,
G4double y1,
G4double y2 
)

Definition at line 63 of file G4AdjointInterpolator.cc.

65{
66 if(y1 <= 0. || y2 <= 0. || x1 <= 0.)
67 return LinearInterpolation(x, x1, x2, y1, y2);
68 G4double B = std::log(y2 / y1) / std::log(x2 / x1);
69 G4double A = y1 / std::pow(x1, B);
70 G4double res = A * std::pow(x, B);
71 return res;
72}

References A, B(), and LinearInterpolation().

Referenced by Interpolation().

◆ operator=()

G4AdjointInterpolator & G4AdjointInterpolator::operator= ( const G4AdjointInterpolator right)
delete

Field Documentation

◆ fInstance

G4ThreadLocal G4AdjointInterpolator * G4AdjointInterpolator::fInstance = nullptr
staticprivate

Definition at line 87 of file G4AdjointInterpolator.hh.

Referenced by GetInstance().


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