std::chrono::duration<double> cphf(calculation_data &data){ std::chrono::duration<double> elapsed_seconds(0); auto start = std::chrono::steady_clock::now(); int sz = (data.n_paired/2)*(data.n_baseset-data.n_paired/2); std::function<int(int,int)> idx = [&](int i,int a){ return (data.n_baseset-data.n_paired/2)*i + (a-data.n_paired/2); }; // build A + B matrix for singlet hermitian_matrix AB = data.A_singlet + data.B_singlet; hermitian_matrix inv_AB = AB.inverse(); // build theta matrix matrix theta_x(sz,1); matrix theta_y(sz,1); matrix theta_z(sz,1); for(int i=0;i<data.n_paired/2;i++){ for(int a=data.n_paired/2;a<data.n_baseset;a++){ int ia = idx(i,a); theta_x(ia,0) = data.mo_dipole_x(i,a); theta_y(ia,0) = data.mo_dipole_y(i,a); theta_z(ia,0) = data.mo_dipole_z(i,a); } } // solve (A+B)C=Theta matrix Cx = inv_AB * theta_x; matrix Cy = inv_AB * theta_y; matrix Cz = inv_AB * theta_z; // calculate the polarizability matrix *Cs[3] = { &Cx,&Cy,&Cz }; matrix *thetas[3] = { &theta_x,&theta_y,&theta_z }; for(int xyz1=0;xyz1<3;xyz1++) for(int xyz2=0;xyz2<3;xyz2++) data.polarizability[xyz1][xyz2] = 0; for(int i=0;i<data.n_paired/2;i++){ for(int a=data.n_paired/2;a<data.n_baseset;a++){ int ia = idx(i,a); for(int xyz1=0;xyz1<3;xyz1++) for(int xyz2=0;xyz2<3;xyz2++) data.polarizability[xyz1][xyz2] += 4 * (*thetas[xyz1])(ia,0) * (*Cs[xyz2])(ia,0); } } auto end = std::chrono::steady_clock::now(); elapsed_seconds = std::chrono::duration_cast<std::chrono::duration<double>>(end-start); return elapsed_seconds; }
void HAZRD3(void){ int smode; if(H->mode==0 && H->only1!=1) O->N = H->N-1; else O->N = H->N; DCEOBJ(&O->typf); O->itrcnt = 0; H->nfncts = 0; O->gradtl = -ONE; O->stptol = -ONE; O->maxstp = -ONE; O->fdigit = -1; O->prtcod = 2; setoptim(); if(C->errorno==1) HAZ3TRM(9900); else if(C->errorno==2) HAZ3TRM(9910); STPNOTE(); if(!(H->angrad || H->anhess)) RESTOR(H->x0,O->N,H->nm1dx,C->theta); if(C->errorno==1) HAZ3TRM(9900); else if(C->errorno==2) HAZ3TRM(9910); nrow = ceil((H->N+ONE)/7); if(prnt==1) { OPTHDR(); theta_x(); OPTPRTX(); } while(O->itrcnt<O->itrlmt && O->iret==0 && C->errorno==0 && O->trmcod==0) { optim(); if(C->errorno) { OPTNOTE(); if(C->errorno==1) HAZ3TRM(9900); else if(C->errorno==2) HAZ3TRM(9910); } if(prnt==1) { theta_x(); OPTPRTX(); } } if(!(H->angrad || H->anhess)) { RESTOR(H->xplus,O->N,H->nm1dx,C->theta); if(C->errorno==1) HAZ3TRM(9900); else if(C->errorno==2) HAZ3TRM(9910); } O->iret++; smode = H->mode; H->mode = 2; constp(); H->mode = smode; if(C->errorno==1) HAZ3TRM(9900); else if(C->errorno==2) HAZ3TRM(9910); OPTNOTE(); switch(O->iret) { case 2: HAZ3TRM(9110); break; case 3: hzfxpc("Initial estimate appears to be a critical",41,9); hzfxpc(" point. It is possible, however, that it",41,0); hzfxpc(" is a maximizer or a saddle point.",34,0); hzfskp(1); RETRY_T(); break; case 4: hzfxpc("The scaled distance between the last two",40,9); hzfxpc(" estimates of the parameters is less than ",42,0); hzfxpf(O->stptol,16,99,0); hzfskp(1); hzfxpc("The current set of parameter estimates",38,9); hzfxpc(" may be a minimizer. It is also possible",41,0); hzfxpc(" that the optimization code",27,0); hzfskp(1); hzfxpc("is making slow progress and is not near",39,9); hzfxpc(" a minimum.",11,0); hzfskp(1); RETRY_T(); break; case 5: hzfxpc("The last step attempted failed to find a",40,9); hzfxpc(" point better than the last estimate. ",38,0); hzfxpc(" Either the current estimates",29,0); hzfskp(1); hzfxpc("are a minimizer and no more accuracy is",39,9); hzfxpc(" possible or insufficient accuracy is",37,0); hzfxpc(" possible in the gradient calculations",38,0); hzfskp(1); hzfxpc("due to machine precision.",25,9); hzfskp(1); RETRY_T(); break; case 6: hzfxpc("Maximum iterations of ",22,9); hzfxpi(O->itrlmt,5,0); hzfxpc("reached no convergence.",23,-1); hzfskp(1); break; case 7: hzfxpc("Five consecutive steps of length, ",34,9); hzfxpf(O->maxstp,22,99,0); hzfxpc(" have been taken. Either the objective",39,0); hzfxpc(" function is unbounded below or has a",37,0); hzfxpc(" finite asymptote in some direction.",36,0); hzfskp(1); hzfxpc("It is also possible that the value used",39,9); hzfxpc(" is too small.",14,0); hzfskp(1); RETRY_T(); break; case 8: if(H->retry!=0) HAZ3TRM(9136); hzfxpc("Problem is so ill-conditioned that a",36,9); hzfxpc(" reasonable direction of search cannot",38,0); hzfxpc(" be calculated",14,0); hzfskp(1); hzfxpc("given the current limit for the condition",41,9); hzfxpc(" code.",6,0); hzfskp(1); RETRY_T(); } hzfpag(2); }