48G4AdjointInterpolator::G4AdjointInterpolator() {}
58 G4double res = y1 + (x - x1) * (y2 - y1) / (x2 - x1);
66 if(y1 <= 0. || y2 <= 0. || x1 <= 0.)
68 G4double B = std::log(y2 / y1) / std::log(x2 / x1);
78 G4double B = (std::log(y2) - std::log(y1)) / (x2 - x1);
90 if(InterPolMethod ==
"Log")
94 else if(InterPolMethod ==
"Lin")
98 else if(InterPolMethod ==
"Exp")
105 ed <<
"The interpolation method that you invoked does not exist!\n";
106 G4Exception(
"G4AdjointInterpolator::Interpolation",
"adoint001",
115 std::vector<G4double>& x_vec,
size_t,
120 size_t ndim = x_vec.size();
122 size_t ind2 = ndim - 1;
126 if(x_vec[0] < x_vec[1])
130 size_t midBin = (ind1 + ind2) / 2;
131 if(x < x_vec[midBin])
135 }
while(ind2 - ind1 > 1);
141 size_t midBin = (ind1 + ind2) / 2;
142 if(x < x_vec[midBin])
146 }
while(ind2 - ind1 > 1);
156 G4double& log_x, std::vector<G4double>& log_x_vec)
164 std::vector<G4double>& x_vec,
165 std::vector<G4double>& y_vec,
169 return Interpolation(x, x_vec[i], x_vec[i + 1], y_vec[i], y_vec[i + 1],
175 G4double& x, std::vector<G4double>& x_vec, std::vector<G4double>& y_vec,
176 std::vector<size_t>& index_vec,
G4double 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];
193 return Interpolation(x, x_vec[ind], x_vec[ind + 1], y_vec[ind],
194 y_vec[ind + 1],
"Lin");
199 G4double& log_x, std::vector<G4double>& log_x_vec,
200 std::vector<G4double>& log_y_vec)
205 log_y_vec[i], log_y_vec[i + 1]);
G4double B(G4double temperature)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
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 ExponentialInterpolation(G4double &x, G4double &x1, G4double &x2, G4double &y1, G4double &y2)
G4double Interpolate(G4double &x, std::vector< G4double > &x_vec, std::vector< G4double > &y_vec, G4String InterPolMethod="Log")
static G4AdjointInterpolator * GetInstance()
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)
static G4AdjointInterpolator * GetAdjointInterpolator()
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 LogarithmicInterpolation(G4double &x, G4double &x1, G4double &x2, G4double &y1, G4double &y2)
G4double InterpolateForLogVector(G4double &x, std::vector< G4double > &x_vec, std::vector< G4double > &y_vec)