Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4AdjointInterpolator Class Reference

#include <G4AdjointInterpolator.hh>

Public Member Functions

 ~G4AdjointInterpolator ()
 
G4double LinearInterpolation (G4double &x, G4double &x1, G4double &x2, G4double &y1, G4double &y2)
 
G4double LogarithmicInterpolation (G4double &x, G4double &x1, G4double &x2, G4double &y1, G4double &y2)
 
G4double ExponentialInterpolation (G4double &x, G4double &x1, G4double &x2, G4double &y1, G4double &y2)
 
G4double Interpolation (G4double &x, G4double &x1, G4double &x2, G4double &y1, G4double &y2, G4String InterPolMethod="Log")
 
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)
 
G4double Interpolate (G4double &x, std::vector< G4double > &x_vec, std::vector< G4double > &y_vec, G4String InterPolMethod="Log")
 
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 InterpolateForLogVector (G4double &x, std::vector< G4double > &x_vec, std::vector< G4double > &y_vec)
 

Static Public Member Functions

static G4AdjointInterpolatorGetAdjointInterpolator ()
 
static G4AdjointInterpolatorGetInstance ()
 

Detailed Description

Definition at line 53 of file G4AdjointInterpolator.hh.

Constructor & Destructor Documentation

G4AdjointInterpolator::~G4AdjointInterpolator ( )

Definition at line 58 of file G4AdjointInterpolator.cc.

59 {
60 }

Member Function Documentation

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

Definition at line 86 of file G4AdjointInterpolator.cc.

87 {
88  G4double B=(std::log(y2)-std::log(y1));
89  B=B/(x2-x1);
90  G4double A=y1*std::exp(-B*x1);
91  G4double res=A*std::exp(B*x);
92  return res;
93 }
double B(double temperature)
double A(double temperature)
double G4double
Definition: G4Types.hh:76

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 116 of file G4AdjointInterpolator.cc.

117 {
118  //most rapid nethod could be used probably
119  //It is important to put std::vector<G4double>& such that the vector itself is used and not a copy
120 
121 
122  size_t ndim = x_vec.size();
123  size_t ind1 = 0;
124  size_t ind2 = ndim - 1;
125  /* if (ind_max >= ind_min){
126  ind1=ind_min;
127  ind2=ind_max;
128 
129 
130  }
131  */
132 
133 
134  if (ndim >1) {
135 
136  if (x_vec[0] < x_vec[1] ) { //increasing
137  do {
138  size_t midBin = (ind1 + ind2)/2;
139  if (x < x_vec[midBin])
140  ind2 = midBin;
141  else
142  ind1 = midBin;
143  // Loop checking, 07-Aug-2015, Vladimir Ivanchenko
144  } while (ind2 - ind1 > 1);
145  }
146  else {
147  do {
148  size_t midBin = (ind1 + ind2)/2;
149  if (x < x_vec[midBin])
150  ind1 = midBin;
151  else
152  ind2 = midBin;
153  // Loop checking, 07-Aug-2015, Vladimir Ivanchenko
154  } while (ind2 - ind1 > 1);
155  }
156 
157  }
158 
159  return ind1;
160 }

Here is the caller graph for this function:

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

Definition at line 164 of file G4AdjointInterpolator.cc.

165 {
166  //most rapid nethod could be used probably
167  //It is important to put std::vector<G4double>& such that the vector itself is used and not a copy
168  return FindPosition(log_x, log_x_vec);
169  /*
170  if (log_x_vec.size()>3){
171  size_t ind=0;
172  G4double log_x1=log_x_vec[1];
173  G4double d_log =log_x_vec[2]-log_x1;
174  G4double dind=(log_x-log_x1)/d_log +1.;
175  if (dind <1.) ind=0;
176  else if (dind >= double(log_x_vec.size())-2.) ind =log_x_vec.size()-2;
177  else ind =size_t(dind);
178  return ind;
179 
180  }
181  else return FindPosition(log_x, log_x_vec);
182  */
183 
184 
185 }
size_t FindPosition(G4double &x, std::vector< G4double > &x_vec, size_t ind_min=0, size_t ind_max=0)

Here is the call graph for this function:

Here is the caller graph for this function:

G4AdjointInterpolator * G4AdjointInterpolator::GetAdjointInterpolator ( )
static

Definition at line 34 of file G4AdjointInterpolator.cc.

35 {
36  return GetInstance();
37 }
static G4AdjointInterpolator * GetInstance()

Here is the call graph for this function:

G4AdjointInterpolator * G4AdjointInterpolator::GetInstance ( )
static

Definition at line 41 of file G4AdjointInterpolator.cc.

42 {
43  if(!theInstance)
44  {
45  theInstance = new G4AdjointInterpolator;
46  }
47  return theInstance;
48 }

Here is the caller graph for this function:

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

Definition at line 189 of file G4AdjointInterpolator.cc.

190 {
191  size_t i=FindPosition(x,x_vec);
192  //G4cout<<i<<G4endl;
193  //G4cout<<x<<G4endl;
194  //G4cout<<x_vec[i]<<G4endl;
195  return Interpolation( x,x_vec[i],x_vec[i+1],y_vec[i],y_vec[i+1],InterPolMethod);
196 }
G4double Interpolation(G4double &x, G4double &x1, G4double &x2, G4double &y1, G4double &y2, G4String InterPolMethod="Log")
size_t FindPosition(G4double &x, std::vector< G4double > &x_vec, size_t ind_min=0, size_t ind_max=0)

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 220 of file G4AdjointInterpolator.cc.

221 {
222  //size_t i=0;
223  size_t i=FindPositionForLogVector(log_x,log_x_vec);
224  /*G4cout<<"In interpolate "<<G4endl;
225  G4cout<<i<<G4endl;
226  G4cout<<log_x<<G4endl;
227  G4cout<<log_x_vec[i]<<G4endl;
228  G4cout<<log_x_vec[i+1]<<G4endl;
229  G4cout<<log_y_vec[i]<<G4endl;
230  G4cout<<log_y_vec[i+1]<<G4endl;*/
231 
232  G4double log_y=LinearInterpolation(log_x,log_x_vec[i],log_x_vec[i+1],log_y_vec[i],log_y_vec[i+1]);
233  return log_y;
234 }
size_t FindPositionForLogVector(G4double &x, std::vector< G4double > &x_vec)
G4double LinearInterpolation(G4double &x, G4double &x1, G4double &x2, G4double &y1, G4double &y2)
double G4double
Definition: G4Types.hh:76

Here is the call graph for this function:

Here is the caller graph for this function:

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 200 of file G4AdjointInterpolator.cc.

202 {
203  size_t ind=0;
204  if (x>x0) ind=int((x-x0)/dx);
205  if (ind >= index_vec.size()-1) ind= index_vec.size()-2;
206  size_t ind1 = index_vec[ind];
207  size_t ind2 = index_vec[ind+1];
208  if (ind1 >ind2) {
209  size_t ind11=ind1;
210  ind1=ind2;
211  ind2=ind11;
212 
213  }
214  ind=FindPosition(x,x_vec,ind1,ind2);
215  return Interpolation( x,x_vec[ind],x_vec[ind+1],y_vec[ind],y_vec[ind+1],"Lin");
216 }
G4double Interpolation(G4double &x, G4double &x1, G4double &x2, G4double &y1, G4double &y2, G4String InterPolMethod="Log")
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
size_t FindPosition(G4double &x, std::vector< G4double > &x_vec, size_t ind_min=0, size_t ind_max=0)

Here is the call graph for this function:

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

Definition at line 97 of file G4AdjointInterpolator.cc.

98 {
99  if (InterPolMethod == "Log" ){
100  return LogarithmicInterpolation(x,x1,x2,y1,y2);
101  }
102  else if (InterPolMethod == "Lin" ){
103  return LinearInterpolation(x,x1,x2,y1,y2);
104  }
105  else if (InterPolMethod == "Exp" ){
106  return ExponentialInterpolation(x,x1,x2,y1,y2);
107  }
108  else {
109  //G4cout<<"The interpolation method that you invoked does not exist!"<<G4endl;
110  return -1111111111.;
111  }
112 }
G4double LogarithmicInterpolation(G4double &x, G4double &x1, G4double &x2, G4double &y1, G4double &y2)
G4double LinearInterpolation(G4double &x, G4double &x1, G4double &x2, G4double &y1, G4double &y2)
G4double ExponentialInterpolation(G4double &x, G4double &x1, G4double &x2, G4double &y1, G4double &y2)

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 64 of file G4AdjointInterpolator.cc.

65 {
66  G4double res = y1+ (x-x1)*(y2-y1)/(x2-x1);
67  //G4cout<<"Linear "<<res<<G4endl;
68  return res;
69 }
double G4double
Definition: G4Types.hh:76

Here is the caller graph for this function:

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

Definition at line 73 of file G4AdjointInterpolator.cc.

74 {
75  if (y1<=0 || y2<=0 || x1<=0) return LinearInterpolation(x,x1,x2,y1,y2);
76  G4double B=std::log(y2/y1)/std::log(x2/x1);
77  //G4cout<<"x1,x2,y1,y2 "<<x1<<'\t'<<x2<<'\t'<<y1<<'\t'<<y2<<'\t'<<G4endl;
78  G4double A=y1/std::pow(x1,B);
79  G4double res=A*std::pow(x,B);
80  // G4cout<<"Log "<<res<<G4endl;
81  return res;
82 }
double B(double temperature)
double A(double temperature)
G4double LinearInterpolation(G4double &x, G4double &x1, G4double &x2, G4double &y1, G4double &y2)
double G4double
Definition: G4Types.hh:76

Here is the call graph for this function:

Here is the caller graph for this function:


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