00001 #include "Cambridge2CorrelationFunction.h"
00002 #include <iomanip>
00003 #include "QMCInput.h"
00004
00005 void Cambridge2CorrelationFunction::initializeParameters(
00006 Array1D<int> & BeginningIndexOfParameterType,
00007 Array1D<double> &Parameters,
00008 Array1D<int> & BeginningIndexOfConstantType,
00009 Array1D<double> & Constants)
00010 {
00011 active = true;
00012 if( Constants.dim1() < 2 )
00013 {
00014 cerr << "ERROR: Cambridge 2 particle Jastrow needs two constants, gamma and C." << endl
00015 << " You requested " << Constants.dim1() << " constant parameters." << endl;
00016 exit(0);
00017 }
00018
00019 g = Constants(0);
00020 C = (int)(Constants(1));
00021
00022 if( C < 2 )
00023 {
00024
00025
00026
00027
00028 cerr << "ERROR: Cambridge 2 particle Jastrow requires C = 2 or C = 3, "
00029 << "but you set C = " << C << endl;
00030 }
00031
00032 if( BeginningIndexOfParameterType.dim1() != 2 || Parameters.dim1() < 2)
00033 {
00034 cerr << "ERROR: Cambridge 2 particle Jastrow needs two parameter types, L and alpha," << endl
00035 << " including at least one alpha." << endl
00036 << " You requested " << Parameters.dim1() << " parameters"
00037 << " and " << BeginningIndexOfParameterType.dim1() << " parameter types." << endl;
00038 exit(0);
00039 }
00040
00041 L = Parameters(0);
00042 optimizeL = globalInput.flags.optimize_L;
00043
00044
00045
00046
00047
00048 if(Constants.dim1() >= 3)
00049 optimizeL = (int)(Constants(2)) == 1 ? true : false;
00050 if(Constants.dim1() >= 4)
00051 f = Constants(3);
00052 else
00053 {
00054 f = 1.0;
00055 }
00056 fL = f * L;
00057
00058 if( L <= 0.0 || fL > 100.0)
00059 {
00060
00061
00062
00063
00064
00065
00066
00067 if(globalInput.flags.a_diag < 0.0)
00068 {
00069
00070 active = false;
00071 } else {
00072 cerr << "Error: You can not have L = " << L << " in Cambridge 2 particle Jastrows!\n";
00073 cerr << *this;
00074 exit(0);
00075 }
00076 }
00077
00078 int N = Parameters.dim1() - 1;
00079 Array1D<double> a(N+1);
00080
00081 alpha_0 = Parameters(1);
00082
00083
00084 alpha_1 = g / pow( -1.0 , C ) / ( fL ) + alpha_0 * C;
00085
00086 d_a1_dL = -g / pow( -1.0 , C ) / ( fL * L );
00087
00088 a(0) = alpha_0;
00089 a(1) = alpha_1;
00090 for(int ai=2; ai<=N; ai++)
00091 a(ai) = Parameters(ai);
00092 alpha.initialize(a);
00093 }
00094
00095 bool Cambridge2CorrelationFunction::isSingular()
00096 {
00097 return L <= 0.0;
00098 }
00099
00100 Array1D<Complex> Cambridge2CorrelationFunction::getPoles()
00101 {
00102 Array1D<Complex> temp;
00103 return temp;
00104 }
00105
00106 void Cambridge2CorrelationFunction::evaluate( double _r )
00107 {
00108 r = _r;
00109 FunctionValue = 0.0;
00110 dFunctionValue = 0.0;
00111 d2FunctionValue = 0.0;
00112 if(!active) return;
00113
00114 d = fL * r - 1.0;
00115
00116
00117 if( d > 0.0 )
00118 return;
00119
00120
00121 alpha.evaluate(fL * r);
00122 P = alpha.getFunctionValue();
00123 dP_r = fL * alpha.getFirstDerivativeValue();
00124 dP_rr = fL * fL * alpha.getSecondDerivativeValue();
00125
00126 dpc = pow(d, C);
00127 dpc_r = C * fL * dpc / d;
00128 dpc_rr = (C - 1.0) * fL * dpc_r / d;
00129
00130 if(globalInput.flags.calculate_Derivatives == 1)
00131 {
00132 dP_L = f * r * alpha.getFirstDerivativeValue();
00133 dP_Lr = dP_L / r + f * fL * r * alpha.getSecondDerivativeValue();
00134 dP_Lrr = 2.0 * f * fL * alpha.getSecondDerivativeValue() +
00135 r * f * fL * fL * alpha.getThirdDerivativeValue();
00136
00137 dpc_L = dpc_r * r / L;
00138 dpc_Lr = dpc_L / d * (C * fL - 1.0 / r);
00139 dpc_Lrr = dpc_rr / d * (C * f * r - 2.0 / L);
00140 }
00141
00142
00143 FunctionValue = dpc * P;
00144
00145
00146 dFunctionValue = dpc_r * P + dpc * dP_r;
00147
00148 d2FunctionValue =
00149 dpc_rr * P +
00150 dpc_r * dP_r * 2.0 +
00151 dpc * dP_rr;
00152 }
00153
00154 double Cambridge2CorrelationFunction::getFunctionValue()
00155 {
00156 return FunctionValue;
00157 }
00158
00159 double Cambridge2CorrelationFunction::getFunctionValue(double r)
00160 {
00161 if(!active) return 0.0;
00162
00163 d = fL * r - 1.0;
00164
00165
00166 if( d > 0.0 )
00167 return 0.0;
00168
00169
00170 alpha.evaluate(fL * r);
00171 P = alpha.getFunctionValue();
00172 dpc = pow(d, C);
00173
00174 return dpc * P;
00175 }
00176
00177 double Cambridge2CorrelationFunction::get_p_a(int ai)
00178 {
00179 double p_a = 0.0;
00180 if( d > 0.0 || !active) return 0.0;
00181
00182 switch(ai)
00183 {
00184
00185 case 0:
00186 if(optimizeL)
00187 {
00188 p_a = dpc * d_a1_dL * fL * r;
00189 p_a += dpc * dP_L;
00190 p_a += dpc_L * P;
00191 } else {
00192 p_a = 0.0;
00193 }
00194 break;
00195
00196
00197 case 1:
00198 p_a = dpc * (1.0 + C * fL * r);
00199 break;
00200
00201
00202 default:
00203 p_a = dpc * alpha.get_p_a(ai);
00204 break;
00205 }
00206 return p_a;
00207 }
00208
00209 double Cambridge2CorrelationFunction::getFirstDerivativeValue()
00210 {
00211 return dFunctionValue;
00212 }
00213
00214 double Cambridge2CorrelationFunction::get_p2_xa(int ai)
00215 {
00216 double p2_xa = 0.0;
00217 if( d > 0.0 || !active) return 0.0;
00218
00219 switch(ai)
00220 {
00221
00222 case 0:
00223 if(optimizeL)
00224 {
00225 p2_xa = fL * d_a1_dL * ( dpc + dpc_r * r);
00226 p2_xa += dpc * dP_Lr;
00227 p2_xa += dpc_L * dP_r;
00228 p2_xa += dpc_r * dP_L;
00229 p2_xa += dpc_Lr * P;
00230 } else {
00231 p2_xa = 0.0;
00232 }
00233 break;
00234
00235
00236 case 1:
00237 p2_xa = dpc_r * (1.0 + C * fL * r);
00238 p2_xa += dpc * C * fL;
00239 break;
00240
00241
00242 default:
00243 p2_xa = dpc_r * alpha.get_p_a(ai);
00244 p2_xa += dpc * alpha.get_p2_xa(ai) * fL;
00245 break;
00246 }
00247 return p2_xa;
00248 }
00249
00250 double Cambridge2CorrelationFunction::getSecondDerivativeValue()
00251 {
00252 return d2FunctionValue;
00253 }
00254
00255 double Cambridge2CorrelationFunction::get_p3_xxa(int ai)
00256 {
00257 double p3_xxa = 0.0;
00258 if( d > 0.0 || !active ) return 0.0;
00259
00260 switch(ai)
00261 {
00262
00263 case 0:
00264 if(optimizeL)
00265 {
00266 p3_xxa = dpc_Lrr * P;
00267 p3_xxa += dpc_rr * dP_L;
00268 p3_xxa += dpc_Lr * dP_r * 2.0;
00269 p3_xxa += dpc_r * dP_Lr * 2.0;
00270 p3_xxa += dpc_L * dP_rr;
00271 p3_xxa += dpc * dP_Lrr;
00272 p3_xxa += (2.0 * dpc_r + r * dpc_rr) * d_a1_dL * fL;
00273 } else {
00274 p3_xxa = 0.0;
00275 }
00276 break;
00277
00278
00279 case 1:
00280 p3_xxa = dpc_rr * (1.0 + C * fL * r);
00281 p3_xxa += dpc_r * 2.0 * C * fL;
00282 break;
00283
00284
00285 default:
00286 p3_xxa = dpc_rr * alpha.get_p_a(ai);
00287 p3_xxa += dpc_r * alpha.get_p2_xa(ai) * 2.0 * fL;
00288 p3_xxa += dpc * alpha.get_p3_xxa(ai) * fL * fL;
00289 break;
00290 }
00291 return p3_xxa;
00292 }
00293
00294 Array1D<double> Cambridge2CorrelationFunction::getNumeratorCoeffs()
00295 {
00296 return alpha.getCoefficients();
00297 }
00298
00299 Array1D<double> Cambridge2CorrelationFunction::getDenominatorCoeffs()
00300 {
00301 return alpha.getCoefficients();
00302 }
00303
00304 void Cambridge2CorrelationFunction::print(ostream& strm)
00305 {
00306
00307
00308
00309
00310
00311
00312
00313 }
00314
00315 ostream& operator <<(ostream& strm, Cambridge2CorrelationFunction &rhs)
00316 {
00317 strm.unsetf(ios::scientific);
00318 strm << "Cambridge 2 particle jastrow parameters:" << endl
00319 << " g = " << rhs.g
00320 << " C = " << rhs.C;
00321 if(fabs(rhs.f-1.0) > 1e-10)
00322 strm << " f = " << rhs.f;
00323 strm << " L = " << rhs.L;
00324 if(rhs.optimizeL)
00325 strm << " (optimized)" << endl;
00326 else
00327 strm << " (not optimized)" << endl;
00328
00329 bool extraPrec = false;
00330
00331 int coWidth, coPrec;
00332 if(extraPrec)
00333 {
00334 coPrec = 15;
00335 coWidth = 20;
00336 } else {
00337 coPrec = 7;
00338 coWidth = 10;
00339 }
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351 strm.unsetf(ios::scientific);
00352 strm.precision(coPrec);
00353 strm << "x = r / " << (1.0 / rhs.fL) << endl;
00354 strm << "(x - 1)^" << rhs.C << " (";
00355 rhs.alpha.print(strm);
00356 strm << ")" << endl;
00357 return strm;
00358 }
00359