00001 // QMcBeaver 00002 // 00003 // Constructed by 00004 // 00005 // Michael Todd Feldmann 00006 // and 00007 // David Randall "Chip" Kent IV 00008 // 00009 // Copyright 2000. All rights reserved. 00010 // 00011 // drkent@users.sourceforge.net mtfeldmann@users.sourceforge.net 00012 00013 #include "FixedCuspPadeCorrelationFunction.h" 00014 00015 void FixedCuspPadeCorrelationFunction::initializeParameters( 00016 Array1D<int> & BeginningIndexOfParameterType, 00017 Array1D<double> &Parameters, 00018 Array1D<int> & BeginningIndexOfConstantType, 00019 Array1D<double> & Constants) 00020 { 00021 if( Constants.dim1() < 1 ) 00022 { 00023 cerr << "ERROR: Fixed Cusp Pade correlation function entered " 00024 << "without a constant for the cusp condition!" << endl; 00025 exit(0); 00026 } 00027 else if( Constants.dim1() > 1 ) 00028 { 00029 cerr << "ERROR: Fixed Cusp Pade correlation function entered " 00030 << "with more than one constant!" << endl; 00031 exit(0); 00032 } 00033 00034 if( BeginningIndexOfParameterType.dim1() != 2 ) 00035 { 00036 cerr << "ERROR: Pade correlation function entered with an incorrect " 00037 << "number of parameter types!" << endl; 00038 exit(0); 00039 } 00040 00041 Array1D<double> numeratorParameters(BeginningIndexOfParameterType(1)+2); 00042 00043 numeratorParameters(0) = 0.0; 00044 numeratorParameters(1) = Constants(0); 00045 for(int i=0; i<numeratorParameters.dim1()-2; i++) 00046 { 00047 numeratorParameters(i+2) = Parameters(i); 00048 } 00049 00050 Numerator.initialize(numeratorParameters); 00051 00052 Array1D<double> denominatorParameters(Parameters.dim1()- 00053 numeratorParameters.dim1()+3); 00054 00055 denominatorParameters(0) = 1.0; 00056 00057 for(int i=0; i<denominatorParameters.dim1()-1; i++) 00058 { 00059 denominatorParameters(i+1) = 00060 Parameters(i+BeginningIndexOfParameterType(1)); 00061 } 00062 00063 Denominator.initialize(denominatorParameters); 00064 } 00065 00066 bool FixedCuspPadeCorrelationFunction::isSingular() 00067 { 00068 return Denominator.hasNonNegativeZeroes(); 00069 } 00070 00071 Array1D<Complex> FixedCuspPadeCorrelationFunction::getPoles() 00072 { 00073 return Denominator.getRoots(); 00074 } 00075 00076 void FixedCuspPadeCorrelationFunction::evaluate( double r ) 00077 { 00078 // p = a/b 00079 // p' = a'/b - a b'/b^2 00080 // p'' = a"/b - 2 a' b'/b^2 + 2a (b')^2 /b^3 -a b"/b^2 00081 00082 Numerator.evaluate(r); 00083 double a = Numerator.getFunctionValue(); 00084 double ap = Numerator.getFirstDerivativeValue(); 00085 double app = Numerator.getSecondDerivativeValue(); 00086 00087 Denominator.evaluate(r); 00088 double b = Denominator.getFunctionValue(); 00089 double bp = Denominator.getFirstDerivativeValue(); 00090 double bpp = Denominator.getSecondDerivativeValue(); 00091 00092 double aDIVb = a/b; 00093 double bpDIVb = bp/b; 00094 double apDIVb = ap/b; 00095 00096 FunctionValue = aDIVb; 00097 dFunctionValue = apDIVb - bpDIVb*aDIVb; 00098 d2FunctionValue = (app - bpp*aDIVb)/b - 2*bpDIVb*dFunctionValue; 00099 } 00100 00101 double FixedCuspPadeCorrelationFunction::getFunctionValue() 00102 { 00103 return FunctionValue; 00104 } 00105 00106 double FixedCuspPadeCorrelationFunction::getFunctionValue(double r) 00107 { 00108 return Numerator.getFunctionValue(r) / Denominator.getFunctionValue(r); 00109 } 00110 00111 double FixedCuspPadeCorrelationFunction::get_p_a(int ai) 00112 { 00113 if(ai < Numerator.getNumberCoefficients() - 2) 00114 { 00115 //The parameter is in the numerator. The first 00116 //two terms in the numerator are not optimizable, so the first 00117 //one is at 2. 00118 ai += 2; 00119 return Numerator.get_p_a(ai) / Denominator.getFunctionValue(); 00120 return 0.0; 00121 } 00122 00123 //The parameter is in the denominator, where first optimizable 00124 //parameter has index 1. 00125 ai -= (Numerator.getNumberCoefficients() - 2) -1; 00126 00127 double t = -FunctionValue/Denominator.getFunctionValue(); 00128 return t * Denominator.get_p_a(ai); 00129 } 00130 00131 double FixedCuspPadeCorrelationFunction::getFirstDerivativeValue() 00132 { 00133 return dFunctionValue; 00134 } 00135 00136 double FixedCuspPadeCorrelationFunction::get_p2_xa(int ai) 00137 { 00138 double div = Denominator.getFunctionValue(); 00139 double div2 = div*div; 00140 double p_x = Denominator.getFirstDerivativeValue(); 00141 00142 if(ai < Numerator.getNumberCoefficients() - 2) 00143 { 00144 ai += 2; 00145 double t = div * Numerator.get_p2_xa(ai); 00146 t -= Numerator.get_p_a(ai) * p_x; 00147 return t / div2; 00148 } 00149 00150 ai -= (Numerator.getNumberCoefficients() - 2) -1; 00151 00152 double p_a = Denominator.get_p_a(ai); 00153 double p2_xa = Denominator.get_p2_xa(ai); 00154 00155 double t1 = 2.0 * p_a * p_x / div; 00156 double t2 = -1.0 * p2_xa; 00157 double sum = (t1 + t2) * Numerator.getFunctionValue(); 00158 00159 double t3 = -1.0 * p_a; 00160 sum += t3 * Numerator.getFirstDerivativeValue(); 00161 00162 return sum/div2; 00163 } 00164 00165 double FixedCuspPadeCorrelationFunction::getSecondDerivativeValue() 00166 { 00167 return d2FunctionValue; 00168 } 00169 00170 double FixedCuspPadeCorrelationFunction::get_p3_xxa(int ai) 00171 { 00172 double div = Denominator.getFunctionValue(); 00173 double div2 = div*div; 00174 double p_x = Denominator.getFirstDerivativeValue(); 00175 double p2_xx = Denominator.getSecondDerivativeValue(); 00176 00177 if(ai < Numerator.getNumberCoefficients() - 2) 00178 { 00179 ai += 2; 00180 double t = 2.0 * p_x * p_x * Numerator.get_p_a(ai); 00181 t -= div * p2_xx * Numerator.get_p_a(ai); 00182 t -= 2.0 * div * p_x * Numerator.get_p2_xa(ai); 00183 t += div2 * Numerator.get_p3_xxa(ai); 00184 return t/(div2 * div); 00185 } 00186 00187 ai -= (Numerator.getNumberCoefficients() - 2) -1; 00188 double p_a = Denominator.get_p_a(ai); 00189 double p2_xa = Denominator.get_p2_xa(ai); 00190 double p3_xxa = Denominator.get_p3_xxa(ai); 00191 /* 00192 There are 7 terms. First, we'll handle the 4 terms where the numerator 00193 doesn't have any derivatives. 00194 */ 00195 00196 double t1 = -6.0 * p_a * p_x * p_x / div2; 00197 double t2 = 4.0 * p_x * p2_xa / div; 00198 double t3 = 2.0 * p_a * p2_xx / div; 00199 double t4 = -1.0 * p3_xxa; 00200 double sum = (t1 + t2 + t3 + t4) * Numerator.getFunctionValue(); 00201 00202 //Now the 2 terms with the first derivative of the numerator 00203 double t5 = -2.0 * p2_xa; 00204 double t6 = 4.0 * p_a * p_x / div; 00205 sum += (t5 + t6) * Numerator.getFirstDerivativeValue(); 00206 00207 //Lastly, the term with the secton derivative of the numerator 00208 double t7 = -1.0 * p_a; 00209 sum += t7 * Numerator.getSecondDerivativeValue(); 00210 00211 return sum/div2; 00212 } 00213 00214 Array1D<double> FixedCuspPadeCorrelationFunction::getNumeratorCoeffs() 00215 { 00216 return Numerator.getCoefficients(); 00217 } 00218 00219 Array1D<double> FixedCuspPadeCorrelationFunction::getDenominatorCoeffs() 00220 { 00221 return Denominator.getCoefficients(); 00222 } 00223 00224 void FixedCuspPadeCorrelationFunction::print(ostream& strm) 00225 { 00226 strm << "Fixed Cusp Pade Jastrow parameters:" << endl; 00227 strm << "("; 00228 Numerator.print(strm); 00229 strm << ")/" << endl; 00230 00231 strm << "("; 00232 Denominator.print(strm); 00233 strm << ")" << endl; 00234 } 00235 00236