// // ******************************************************************** // * License and Disclaimer * // * * // * The Geant4 software is copyright of the Copyright Holders of * // * the Geant4 Collaboration. It is provided under the terms and * // * conditions of the Geant4 Software License, included in the file * // * LICENSE and available at http://cern.ch/geant4/license . These * // * include a list of copyright holders. * // * * // * Neither the authors of this software system, nor their employing * // * institutes,nor the agencies providing financial support for this * // * work make any representation or warranty, express or implied, * // * regarding this software system or assume any liability for its * // * use. Please see the license in the file LICENSE and URL above * // * for the full disclaimer and the limitation of liability. * // * * // * This code implementation is the result of the scientific and * // * technical work of the GEANT4 collaboration. * // * By using, copying, modifying or distributing the software (or * // * any work based on the software) you agree to acknowledge its * // * use in resulting scientific publications, and indicate your * // * acceptance of all terms of the Geant4 Software license. * // ******************************************************************** // #include "G4AdjointCSMatrix.hh" #include "G4AdjointInterpolator.hh" G4AdjointInterpolator* G4AdjointInterpolator::theInstance = 0; /////////////////////////////////////////////////////// // G4AdjointInterpolator* G4AdjointInterpolator::GetAdjointInterpolator() { if(theInstance == 0) { static G4AdjointInterpolator interpolator; theInstance = &interpolator; } return theInstance; } /////////////////////////////////////////////////////// // G4AdjointInterpolator* G4AdjointInterpolator::GetInstance() { if(theInstance == 0) { static G4AdjointInterpolator interpolator; theInstance = &interpolator; } return theInstance; } /////////////////////////////////////////////////////// // G4AdjointInterpolator::G4AdjointInterpolator() {; } /////////////////////////////////////////////////////// // G4AdjointInterpolator::~G4AdjointInterpolator() {; } /////////////////////////////////////////////////////// // G4double G4AdjointInterpolator::LinearInterpolation(G4double& x,G4double& x1,G4double& x2,G4double& y1,G4double& y2) { G4double res = y1+ (x-x1)*(y2-y1)/(x2-x1); //G4cout<<"Linear "<& x_vec,size_t , size_t ) //only valid if x_vec is monotically increasing { //most rapid nethod could be used probably //It is important to put std::vector& such that the vector itself is used and not a copy size_t ndim = x_vec.size(); size_t ind1 = 0; size_t ind2 = ndim - 1; /* if (ind_max >= ind_min){ ind1=ind_min; ind2=ind_max; } */ if (ndim >1) { if (x_vec[0] < x_vec[1] ) { //increasing do { size_t midBin = (ind1 + ind2)/2; if (x < x_vec[midBin]) ind2 = midBin; else ind1 = midBin; } while (ind2 - ind1 > 1); } else { do { size_t midBin = (ind1 + ind2)/2; if (x < x_vec[midBin]) ind1 = midBin; else ind2 = midBin; } while (ind2 - ind1 > 1); } } return ind1; } /////////////////////////////////////////////////////// // size_t G4AdjointInterpolator::FindPositionForLogVector(G4double& log_x,std::vector& log_x_vec) //only valid if x_vec is monotically increasing { //most rapid nethod could be used probably //It is important to put std::vector& such that the vector itself is used and not a copy if (log_x_vec.size()>3){ size_t ind=0; G4double log_x1=log_x_vec[1]; G4double d_log =log_x_vec[2]-log_x1; G4double dind=(log_x-log_x1)/d_log +1.; if (dind <1.) ind=0; else if (dind >= double(log_x_vec.size())-2.) ind =log_x_vec.size()-2; else ind =size_t(dind); return ind; } else return FindPosition(log_x, log_x_vec); } /////////////////////////////////////////////////////// // G4double G4AdjointInterpolator::Interpolate(G4double& x,std::vector& x_vec,std::vector& y_vec,G4String InterPolMethod) { size_t i=FindPosition(x,x_vec); //G4cout<& x_vec,std::vector& y_vec, std::vector& index_vec,G4double x0, G4double dx) //only linear interpolation possible { size_t ind=0; if (x>x0) ind=int((x-x0)/dx); if (ind >= index_vec.size()-1) ind= index_vec.size()-2; size_t ind1 = index_vec[ind]; size_t ind2 = index_vec[ind+1]; if (ind1 >ind2) { size_t ind11=ind1; ind1=ind2; ind2=ind11; } ind=FindPosition(x,x_vec,ind1,ind2); return Interpolation( x,x_vec[ind],x_vec[ind+1],y_vec[ind],y_vec[ind+1],"Lin"); } /////////////////////////////////////////////////////// // G4double G4AdjointInterpolator::InterpolateForLogVector(G4double& log_x,std::vector& log_x_vec,std::vector& log_y_vec) { //size_t i=0; size_t i=FindPositionForLogVector(log_x,log_x_vec); /*G4cout<<"In interpolate "<