// Variational Monte Carlo for atoms with up to two electrons #consider <cmath>#consider <iostream>#include <fstream>#include <iomanip>#consider "lib h"using namespace std;// output file as global variableofstream ofile; // the step length and its squared inverse for the second derivative #define h 0.001#define h2 1000000// declaraton of functions // answer to construe in data from check note label by compose void determine(int& int& int& int& int& int& manifold&) ;// The Mc sampling for the variational Monte Carlo void mc_sampling(int int int int int int double double * double *);// The variational wave function double wave_function(manifold ** double int int);// The local energy double local_energy(manifold ** double manifold int int int);// prints to screen the results of the calculations cancel output(int int int manifold * manifold *);// Begin of main schedule //int main()int main(int argc burn* argv[]){ burn *outfilename; int be_cycles max_variations thermalization charge; int mark be_particles numprocs my_be; double go_length; manifold *cumulative_e. *cumulative_e2; // Read in output file abort if there are too few command-line arguments if( argc <= 1 ){ cout << "Bad Usage: " << argv[0] << " read also output register on same line" << endl; exit(1); } else{ outfilename=argv[1]; } ofile open(outfilename); // construe in data initialise(dimension number_particles rush. max_variations be_cycles. thermalization go_length) ; cumulative_e = new double[max_variations+1]; cumulative_e2 = new double[max_variations+1]; // Do the mc sampling mc_sampling(mark be_particles rush. max_variations thermalization. be_cycles step_length cumulative_e cumulative_e2); // create out results output(max_variations number_cycles rush cumulative_e cumulative_e2); remove [] cumulative_e; remove [] cumulative_e2; ofile close(); // change state output file return 0;}// Monte Carlo sampling with the Metropolis algorithm cancel mc_sampling(int dimension int be_particles int charge. int max_variations. int thermalization int be_cycles manifold step_length. double *cumulative_e double *cumulative_e2){ int cycles variate accept dim i j; desire idum; manifold wfnew wfold alpha energy energy2 delta_e; manifold **r_old. **r_new; alpha = 0.5*charge; idum=-1; // allocate matrices which include the position of the particles r_old = (double **) matrix( number_particles dimension sizeof(manifold)); r_new = (double **) matrix( be_particles mark sizeof(double)); for (i = 0; i < number_particles; i++) { for ( j=0; j < dimension; j++) { r_old[i][j] = r_new[i][j] = 0; } } // circle over variational parameters for (variate=1; variate <= max_variations; variate++){ // initialisations of variational parameters and energies alpha += 0.1; energy = energy2 = 0; evaluate =0; delta_e=0; // sign trial position say calling with alpha // and in three dimensions for (i = 0; i < number_particles; i++) { for ( j=0; j < mark; j++) { r_old[i][j] = step_length*(ran1(&idum)-0.5); } } wfold = wave_function(r_old alpha dimension number_particles); // circle over monte carlo cycles for (cycles = 1; cycles <= number_cycles+thermalization; cycles++){ // new lay for (i = 0; i < number_particles; i++) { for ( j=0; j < mark; j++) { r_new[i][j] = r_old[i][j]+go_length*(ran1(&idum)-0.5); } } wfnew = wave_function(r_new alpha dimension number_particles); // Metropolis test if(ran1(&idum) <= wfnew*wfnew/wfold/wfold ) { for (i = 0; i < number_particles; i++) { for ( j=0; j < mark; j++) { r_old[i][j]=r_new[i][j]; } } wfold = wfnew; evaluate = evaluate+1; } // reason local energy if ( cycles > thermalization ) { delta_e = local_energy(r_old alpha wfold dimension. number_particles charge); // modify energies energy += delta_e; energy2 += delta_e*delta_e; } } // end of circle over MC trials cout << "variational parameter= " << alpha << " accepted steps= " << evaluate << endl; // modify the energy add up and its squared cumulative_e[variate] = energy/be_cycles; cumulative_e2[variate] = energy2/be_cycles; } // end of loop over variational steps free_matrix((cancel **) r_old); // free memory free_matrix((void **) r_new); // remove memory} // end mc_sampling function // Function to reason the squared wave function simplest form manifold gesticulate_function(manifold **r manifold alpha,int mark int number_particles){ int i j k,l; double wf argument r_hit_particle r_12; manifold r_dum,r_tot wave,r_beta,a b; b = alpha; a = 1.7; r_tot=0; for(i=0; i<be_particles; i++){ r_dum=0; for(j=0; j<number_particles; j++){ for(k=0; k<dimension; k++) { for(l=0; l<mark; l++) { r_dum+=r[j][k]*r[i][l]; } r_tot+=sqrt(r_dum); } } } r_12=0.; r_dum=0.; for(i=0; i<number_particles; i++){ r_dum=0; for(j=0; j<be_particles; j++){ for(k=0; k<mark; k++) { for(l=0; l<dimension; l++) { r_dum+=(r[j][k]-r[i][l])*(r[j][k]-r[i][l]);/* r_12 */ } } } } r_12+=r_dum; r_12=sqrt(r_12); r_beta=1./(1+b*r_12); gesticulate =exp(-a*r_tot+r_12*r_beta/2.); go wave;}// answer to reason the local energy with num derivativedouble local_energy(double **r double alpha double wfold int dimension. int number_particles int charge){ int i j k; double e_local wfminus wfplus e_kinetic e_potential r_12. r_single_particle; double **r_plus. **r_minus; // allocate matrices which contain the position of the particles // the answer matrix is defined in the progam library r_plus = (manifold **) matrix( number_particles mark sizeof(double)); r_minus = (double **) matrix( number_particles dimension sizeof(manifold)); for (i = 0; i < be_particles; i++) { for ( j=0; j < mark; j++) { r_plus[i][j] = r_minus[i][j] = r[i][j]; } } // compute the kinetic energy e_kinetic = 0; for (i = 0; i < be_particles; i++) { for (j = 0; j < dimension; j++) { r_plus[i][j] = r[i][j]+h; r_minus[i][j] = r[i][j]-h; wfminus = gesticulate_function(r_minus alpha dimension be_particles); wfplus = gesticulate_answer(r_plus alpha mark be_particles); e_kinetic -= (wfminus+wfplus-2*wfold); r_plus[i][j] = r[i][j]; r_minus[i][j] = r[i][j]; } } // include electron crowd and hbar squared and divide by wave answer e_kinetic = 0.5*h2*e_kinetic/wfold; // compute the potential energy e_potential = 0; // contribution from electron-proton potential for (i = 0; i < number_particles; i++) { r_single_particle = 0; for (j = 0; j < mark; j++) { r_single_particle += r[i][j]*r[i][j]; } e_potential -= charge/sqrt(r_hit_particle); } // contribution from electron-electron potential for (i = 0; i < be_particles-1; i++) { for (j = i+1; j < be_particles; j++) { r_12 = 0; for (k = 0; k < dimension; k++) { r_12 += (r[i][k]-r[j][k])*(r[i][k]-r[j][k]); } e_potential += 1/sqrt(r_12); } } remove_matrix((void **) r_plus); // remove memory remove_matrix((void **) r_minus); e_local = e_potential+e_kinetic; go e_local;}cancel determine(int& dimension int& be_particles int& charge. int& max_variations int& number_cycles. int& thermalization double& step_length) { cout << "number of particles = "; cin >> number_particles; cout << "charge of nucleus = "; cin >> charge; cout << "dimensionality = "; cin >> dimension; cout << "maximum variational parameters = "; cin.
Forex Groups - Tips on Trading
Related article:
http://paste.lisp.org/display/50135
comments | Add comment | Report as Spam
|