double EwaldgpuForce::tune_rcut(double accuracy, double precision, double alpha, double V, double q_sqr, int N) { double rcut_low=0.0; double rcut_high=0.5 * std::max(box_l[0],std::max(box_l[1],box_l[2])); double rcut_guess; double fkt_low; double fkt_high; double fkt_guess; // Find rcut with given K in k-space error estimate via bisection fkt_low = error_estimate_r(q_sqr, N, rcut_low, V, alpha, accuracy); fkt_high = error_estimate_r(q_sqr, N, rcut_high, V, alpha, accuracy); if (fkt_low*fkt_high > 0.0) { return -1; // Value unusable } do { rcut_guess = 0.5 *(rcut_low + rcut_high); fkt_guess = error_estimate_r(q_sqr, N, rcut_guess, V, alpha, accuracy); if (fkt_low*fkt_guess < 0.0) rcut_high = rcut_guess; else rcut_low = rcut_guess; } while (fabs(rcut_low-rcut_high) > precision); return 0.5 *(rcut_low + rcut_high); }
double EwaldgpuForce::tune_rcut(double accuracy, double precision, double alpha, double V, double q_sqr, int N) { double rcut_low=std::numeric_limits<double>::epsilon(); /* Limit maximal cutoff to 10000 particles in rcut sphere. */ double rcut_high=std::min(std::min(box_l[0],std::min(box_l[1],box_l[2])), pow((3000.0*V)/(4.0*3.14159*N), 1.0/3.0)); double rcut_guess; double fkt_low; double fkt_high; double fkt_guess; // Find rcut with given K in k-space error estimate via bisection fkt_low = error_estimate_r(q_sqr, N, rcut_low, V, alpha, accuracy); fkt_high = error_estimate_r(q_sqr, N, rcut_high, V, alpha, accuracy); if (fkt_low*fkt_high > 0.0) { return -1; // Value unusable } do { rcut_guess = 0.5 *(rcut_low + rcut_high); fkt_guess = error_estimate_r(q_sqr, N, rcut_guess, V, alpha, accuracy); if (fkt_low*fkt_guess < 0.0) rcut_high = rcut_guess; else rcut_low = rcut_guess; } while (fabs(rcut_low-rcut_high) > precision); return 0.5 *(rcut_low + rcut_high); }