void System::quantumForce(mat r, mat &qforce, double wf) { int N = Wavefunction->getNumberOfParticles(); int M = Wavefunction->getNumberOfDimensions(); double wf_minus, wf_plus; mat r_plus, r_minus; r_plus = mat(N,M); r_minus = mat(N,M); r_plus = r_minus = r; double h = 1e-5; // compute the first derivative int i, j; for (i=0; i<N; i++) { for (j=0; j<M; j++) { r_plus(i,j) = r(i,j) + h; r_minus(i,j) = r(i,j) - h; wf_plus = Wavefunction->evaluateWavefunction(r_plus); wf_minus = Wavefunction->evaluateWavefunction(r_minus); qforce(i,j) = (wf_plus-wf_minus); r_minus(i,j) = r_plus(i,j) = r(i,j); } } qforce = qforce*2.0/(wf*2*h); }
mat Wavefunction::q_force() { mat q_f = zeros(n_particles, dim); //#if NUMERICAL #if 0 double h = 0.05; mat r_plus = zeros(n_particles, dim); mat r_minus = zeros(n_particles, dim); // Initiating r_plus and r_minus. r_plus = r_new; r_minus = r_new; // Calculating the Quantum Force numerically. for (int i = 0; i < n_particles; i++) { for (int j = 0; j < dim; j++) { r_plus(i, j) += h; r_minus(i, j) -= h; q_f(i, j) = 2 * (evaluate(r_plus) - evaluate(r_minus)) / (2 * h * evaluate(r_new)); r_plus(i, j) = r_new(i, j); r_minus(i, j) = r_new(i, j); } } #else rowvec gradient_slater; rowvec gradient_jastrow; double R = slater->get_ratio(); for (int i = 0; i < n_particles; i++) { // Finding the Orbitals' gradient. slater->compute_gradient(i); gradient_slater = slater->get_gradient(); // Finding the Jastrow's gradient. jas->compute_gradient(r_new, i); gradient_jastrow = jas->get_gradient(); q_f.row(i) = 2 * (gradient_jastrow + gradient_slater)/R; } #endif return q_f; }
/******************************************************************* * * NAME : evaluate( double* r) * * DESCRIPTION : In progress. * */ double QD_kinetic::evaluate(mat r) { #if NUMERICAL // the step length and its squared inverse for the second derivative double h = 0.001; double wfminus, wfplus, wfold, e_kinetic; mat r_plus; mat r_minus; wfold = wf->get_wf_old(); r_plus = zeros<mat > (n_particles, dim); r_minus = zeros<mat > (n_particles, dim); r_plus = r_minus = r; // compute the kinetic energy e_kinetic = 0; for (int i = 0; i < n_particles; i++) { for (int j = 0; j < dim; j++) { r_plus(i, j) = r(i, j) + h; r_minus(i, j) = r(i, j) - h; wfminus = wf->evaluate(r_minus); wfplus = wf->evaluate(r_plus); e_kinetic += (wfplus - 2 * wfold + wfminus); r_plus(i, j) = r(i, j); r_minus(i, j) = r(i, j); } } // include electron mass and hbar squared and divide by wave function e_kinetic = -0.5 * e_kinetic / (h * h) / wfold; return e_kinetic; #else // Analytic solution with the Jastrow factor. double e_kin = 0; e_kin += wf->get_laplacian(); e_kin = -0.5 * e_kin; return e_kin; #endif // Analytic solution without the Jastrow fasctor. #if 0 double alpha, r_sq, derivative; alpha = wf->getAlpha(); derivative = 0; for (int i = 0; i < n_particles; i++) { r_sq = 0; for (int j = 0; j < dim; j++) { r_sq += r(i, j) * r(i, j); } derivative += -2 * w * alpha + (w * w) * (alpha * alpha) * r_sq; } return -0.5 * derivative; #endif }