00001 #include "Umrigar2CorrelationFunction.h"
00002 #include <sstream>
00003
00004 void Umrigar2CorrelationFunction::initializeParameters(
00005 Array1D<int> & BeginningIndexOfParameterType,
00006 Array1D<double> &Parameters,
00007 Array1D<int> & BeginningIndexOfConstantType,
00008 Array1D<double> & Constants)
00009 {
00010 if( Constants.dim1() != 1 )
00011 {
00012 cerr << "ERROR: Umrigar correlation function entered "
00013 << "without a constant for the cusp condition!" << endl;
00014 exit(0);
00015 }
00016
00017 if( BeginningIndexOfParameterType.dim1() != 2 )
00018 {
00019 cerr << "ERROR: Umrigar correlation function entered with an incorrect "
00020 << "number of parameter types!" << endl;
00021 exit(0);
00022 }
00023
00024
00025 g = Parameters(0);
00026
00027 b = Parameters(1);
00028
00029 k = Parameters(2);
00030
00038 a = 1.0;
00039 B = a * b * b;
00040 dB = 2.0 * a * b;
00041
00042
00043
00044
00045
00046
00047 optimizeG = false;
00048 if(Constants(0) == 1)
00049 optimizeG = true;
00050 }
00051
00052 void Umrigar2CorrelationFunction::evaluate( double _r )
00053 {
00054 r = _r;
00055
00056 if(isSingular()){
00057 FunctionValue = 0.0;
00058 dFunctionValue = 0.0;
00059 d2FunctionValue = -1e10;
00060 return;
00061 }
00062
00063 dU_dr = exp(-k * r);
00064 dU_drr = -1.0 * dU_dr * k;
00065 U = (1.0 - dU_dr) / k;
00066
00067 dU_dkr = -1.0 * r * dU_dr;
00068 dU_dk = -1.0 * (dU_dkr + U) / k;
00069 dU_dkrr = dU_dr * ( k * r - 1.0 );
00070
00071 den = (1.0 + B * U);
00072 iden = 1.0 / den;
00073 iden2 = iden * iden;
00074
00075 FunctionValue = g * U * iden;
00076 dFunctionValue = g * dU_dr * iden2;
00077 d2FunctionValue = dFunctionValue * ( dU_drr / dU_dr - 2.0 * B * dU_dr * iden);
00078
00079 if(isnan(d2FunctionValue)){
00080 printf("k %20.10e B %20.10e r %20.10e U %20.10e dU_dr %20.10e dU_drr %20.10e\n",
00081 k,B,r,U,dU_dr,dU_drr);
00082 }
00083 }
00084
00085 double Umrigar2CorrelationFunction::get_p_a(int ai)
00086 {
00087 double p_a = 0.0;
00088 switch(ai)
00089 {
00090
00091 case 0:
00092 if(optimizeG)
00093 p_a = U * iden;
00094 else
00095 p_a = 0.0;
00096 break;
00097
00098
00099 case 1:
00100 p_a = -1.0 * dB * U * U * iden2;
00101 p_a *= g;
00102 break;
00103
00104
00105 case 2:
00106 p_a = dU_dk * iden2;
00107 p_a *= g;
00108 break;
00109
00110
00111 default:
00112 clog << "Error: Umrigar Jastrow function doesn't use parameter"
00113 << " index = " << ai << endl;
00114 break;
00115 }
00116
00117 return p_a;
00118 }
00119
00120 double Umrigar2CorrelationFunction::get_p2_xa(int ai)
00121 {
00122 double p2_xa = 0.0;
00123 switch(ai)
00124 {
00125
00126 case 0:
00127 if(optimizeG)
00128 p2_xa = dU_dr * iden2;
00129 else
00130 p2_xa = 0.0;
00131 break;
00132
00133
00134 case 1:
00135 p2_xa = -2.0 * dB * U * dU_dr * iden2 * iden;
00136 p2_xa *= g;
00137 break;
00138
00139
00140 case 2:
00141 p2_xa = -2.0 * B * dU_dk * dU_dr;
00142 p2_xa += den * dU_dkr;
00143 p2_xa *= iden2 * iden;
00144 p2_xa *= g;
00145 break;
00146
00147
00148 default:
00149 clog << "Error: Umrigar Jastrow function doesn't use parameter"
00150 << " index = " << ai << endl;
00151 break;
00152 }
00153
00154 return p2_xa;
00155 }
00156
00157 double Umrigar2CorrelationFunction::get_p3_xxa(int ai)
00158 {
00159 double p3_xxa = 0.0;
00160 switch(ai)
00161 {
00162
00163 case 0:
00164 if(optimizeG)
00165 {
00166 p3_xxa = -2.0 * B * dU_dr * dU_dr;
00167 p3_xxa += den * dU_drr;
00168 p3_xxa *= iden2 * iden;
00169 }
00170 else
00171 p3_xxa = 0.0;
00172 break;
00173
00174
00175 case 1:
00176 p3_xxa = (1.0 - 2.0 * B * U) * dU_dr * dU_dr;
00177 p3_xxa += U * den * dU_drr;
00178 p3_xxa *= -2.0 * iden2 * iden2;
00179 p3_xxa *= g * dB;
00180 break;
00181
00182
00183 case 2:
00184
00185
00186
00187
00188
00189
00190
00191
00192 p3_xxa = 3.0 * B * dU_dr * dU_dr - den * dU_drr;
00193 p3_xxa *= 2.0 * B * dU_dk;
00194 p3_xxa += den * ( den * dU_dkrr - 4.0 * B * dU_dr * dU_dkr);
00195 p3_xxa *= iden2 * iden2;
00196 p3_xxa *= g;
00197 break;
00198
00199
00200 default:
00201 clog << "Error: Umrigar Jastrow function doesn't use parameter"
00202 << " index = " << ai << endl;
00203 break;
00204 }
00205 return p3_xxa;
00206 }
00207
00208 void Umrigar2CorrelationFunction::print(ostream& strm)
00209 {
00210 strm << "Umrigar Jastrow parameters:" << endl;
00211 strm << " g = " << g;
00212 if(optimizeG)
00213 strm << " (optimized)" << endl;
00214 else
00215 strm << " (not optimized)" << endl;
00216 strm << " b = " << b << endl;
00217 strm << " B = " << B << endl;
00218 strm << " k = " << k << endl;
00219
00220 stringstream Uterm;
00221 Uterm << " (1.0 - Exp[ -" << k << " r]) / " << k;
00222 strm << " (" << g << Uterm.str() << ")/(1.0 + " << B << Uterm.str() << ")" << endl;
00223 }
00224
00225 bool Umrigar2CorrelationFunction::isSingular()
00226 {
00227 return k <= 0.0 || fabs(B) < 1e-50;
00228 }