double calc_E(const gsl_vector *x, void *par) { Timer t; // Get the helpers opthelper_t *p=(opthelper_t *) par; // Get the atomic positions std::vector<atom_t> atoms=get_atoms(x,*p); // print_xyz(atoms); // Construct basis set BasisSet basis; construct_basis(basis,atoms,p->baslib,p->set); // Perform the electronic structure calculation enum calcd mode=run_calc(basis,p->set,false); // Solution checkpoint Checkpoint solchk(p->set.get_string("SaveChk"),false); // Current energy is energy_t en; solchk.read(en); if(mode==FULLCALC) { ERROR_INFO(); throw std::runtime_error("Should have not computed forces for energy.\n"); } else if(mode==ECALC) printf("Computed energy % .8f in %s.\n",en.E,t.elapsed().c_str()); else printf("Found energy % .8f in checkpoint file.\n",en.E); fflush(stdout); return en.E; }
void calc_Ef(const gsl_vector *x, void *par, double *E, gsl_vector *g) { Timer t; // Get the helpers opthelper_t *p=(opthelper_t *) par; // Get the atomic positions std::vector<atom_t> atoms=get_atoms(x,*p); // print_xyz(atoms); // Construct basis set BasisSet basis; construct_basis(basis,atoms,p->baslib,p->set); // Perform the electronic structure calculation enum calcd mode=run_calc(basis,p->set,true); // Solution checkpoint Checkpoint solchk(p->set.get_string("SaveChk"),false); // Energy energy_t en; solchk.read(en); *E=en.E; // Force arma::vec f; solchk.read("Force",f); // Set components for(size_t i=0;i<p->dofidx.size();i++) { size_t j=p->dofidx[i]; gsl_vector_set(g,3*i ,-f(3*j)); gsl_vector_set(g,3*i+1,-f(3*j+1)); gsl_vector_set(g,3*i+2,-f(3*j+2)); } double frms, fmax; get_forces(g,fmax,frms); if(mode==ECALC) { ERROR_INFO(); throw std::runtime_error("Should have not computed just the energy for forces.\n"); } else if(mode==FULLCALC) printf("Computed energy % .8f and forces (max = %.3e, rms = %.3e) in %s.\n",en.E,fmax,frms,t.elapsed().c_str()); else if(mode==FORCECALC) printf("Found energy % .8f in checkpoint file and calculated forces (max = %.3e, rms = %.3e) in %s.\n",en.E,fmax,frms,t.elapsed().c_str()); else if(mode==NOCALC) printf("Found energy and forces in checkpoint file.\n"); fflush(stdout); }
PetscErrorCode cHamiltonianMatrix::fock(){ int spin_flag; spin_flag = 1; basis1 = gsl_matrix_alloc(N,dim); construct_basis(basis1, spin_flag); spin_flag = 2; basis2 = gsl_matrix_alloc(N2,dim2); construct_basis(basis2, spin_flag); // if (rank == 0){ // only root CPU prints the result to screen. // for (int i = 0; i < N; ++i) { // for (int j = 0; j < dim; ++j) { // cout << gsl_matrix_get(basis1,i,j) << '\t'; // } // cout << "EOL" << endl; // } // for (int i = 0; i < N2; ++i) { // for (int j = 0; j < dim2; ++j) { // cout << gsl_matrix_get(basis2,i,j) << '\t'; // } // cout << "EOL" << endl; // } // } return ierr; }