00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "QMCHartreeFock.h"
00010
00011
00012 int QMCHartreeFock::numelecs;
00013 int QMCHartreeFock::numalphas;
00014 int QMCHartreeFock::numbetas;
00015 int QMCHartreeFock::sample;
00016 int QMCHartreeFock::maxsamples;
00017 int QMCHartreeFock::numsamples;
00018
00019
00020 Array2D<double> QMCHartreeFock::elec_x;
00021 Array2D<double> QMCHartreeFock::elec_y;
00022 Array2D<double> QMCHartreeFock::elec_z;
00023 Array2D<double> QMCHartreeFock::elec_weight;
00024
00025 QMCHartreeFock::QMCHartreeFock()
00026 {
00027 }
00028
00029 QMCHartreeFock::~QMCHartreeFock()
00030 {
00031 elec_x.deallocate();
00032 elec_y.deallocate();
00033 elec_z.deallocate();
00034 elec_weight.deallocate();
00035 }
00036
00037 void QMCHartreeFock::Initialize(QMCInput* IN)
00038 {
00039 PsiPotential.Initialize(IN);
00040
00041 numalphas = IN->WF.getNumberElectrons(true);
00042 numbetas = IN->WF.getNumberElectrons(false);
00043 numelecs = numalphas + numbetas;
00044 maxsamples = IN->flags.hf_num_average;
00045 sample = 0;
00046 numsamples = 0;
00047
00048
00049 elec_x.allocate(numelecs, maxsamples);
00050 elec_y.allocate(numelecs, maxsamples);
00051 elec_z.allocate(numelecs, maxsamples);
00052 elec_weight.allocate(numelecs, maxsamples);
00053 }
00054
00055 void QMCHartreeFock::AddElectron(int elec, double weight, double x, double y,
00056 double z)
00057 {
00058
00059 elec_x(elec, sample) = x;
00060 elec_y(elec, sample) = y;
00061 elec_z(elec, sample) = z;
00062 elec_weight(elec, sample) = weight;
00063 }
00064
00065 void QMCHartreeFock::IncrementSample()
00066 {
00067
00068 sample++;
00069 if (sample >= maxsamples) sample = 0;
00070 numsamples++;
00071 if (numsamples >= maxsamples) numsamples = maxsamples;
00072 }
00073
00074 double QMCHartreeFock::GetVEff(int elec, double x, double y, double z)
00075 {
00076
00077
00078 double dx, dy, dz, r;
00079 double sum1, sum2, sumV;
00080
00081 sum1 = 0;
00082 sumV = 0;
00083
00084 int noweights = 0;
00085 for (int i = 0; i < numelecs; i++)
00086 {
00087 if (i != elec)
00088 {
00089 sum2 = 0;
00090 double weights = 0;
00091 for (int j = 0; j < numsamples; j++)
00092 {
00093 dx = x - elec_x(i, j);
00094 dy = y - elec_y(i, j);
00095 dz = z - elec_z(i, j);
00096 r = sqrt(dx * dx + dy * dy + dz * dz);
00097 sum2 += elec_weight(i, j) / r;
00098 weights += elec_weight(i, j);
00099 }
00100 sum1 += sum2 / weights;
00101 if (weights == 0) noweights = 1;
00102
00103
00104 sumV += (i < numalphas) ? PsiPotential.GetPoten(i, 0, x, y, z) : PsiPotential.GetPoten(i - numalphas, 1, x, y, z);
00105 }
00106 }
00107
00108
00109
00110
00111 double V_mixed = sum1 / 2.0;
00112 double V_trial = sumV / 2.0;
00113 double V_pure = 2 * V_mixed - V_trial;
00114 if (noweights) V_pure = V_trial;
00115 if (numsamples == 0) return V_trial; else return V_pure;
00116 }