78 if (!centre->needsForceUpdate() || !
pot->supportsBatchEvaluation() ||
79 !oneSidedProduct(
params)) {
85 const auto pos = firstProbe(*centre, direction, mobile,
86 params.main_options().finiteDifference);
90 auto probe = std::make_unique<Matter>(*centre);
91 probe->setPositions(*pos);
92 Matter *
const both[] = {centre.get(), probe.get()};
98 const VectorXi &mobileIn) {
102 std::unique_ptr<Matter> probe = std::move(
probe_);
104 lowestEv.resize(matter->numberOfAtoms(), 3);
108 const int size = 3 *
static_cast<int>(mobile.size());
114 const long maxIters = std::max(1L,
params.lanczos_options().max_iterations);
115 MatrixXd T(size, maxIters), Q(size, maxIters);
119 double alpha, beta = r.norm();
124 double ew = 0, ewOld = 0, ewAbsRelErr;
125 const double dr =
params.main_options().finiteDifference;
131 VectorXd evEst, evT, evOldEst;
133 auto tmpMatter = std::make_unique<Matter>(*matter);
134 const long forceCallsStart = tmpMatter->getForceCalls();
135 const AtomMatrix pos0 = matter->getPositions();
136 const VectorXd force0 =
mobileForces(tmpMatter.get(), mobile);
138 auto applyH = [&](
const VectorXd &v) -> VectorXd {
139 auto at = [&](
double scale) -> VectorXd {
143 tmpMatter->setPositions(pos);
146 if (probe && !probe->needsForceUpdate() &&
147 probe->getPositions() == tmpMatter->getPositions()) {
159 for (
int i = 0; i < size; i++) {
163 u = applyH(Q.col(i));
168 r = u - beta * Q.col(i - 1);
170 alpha = Q.col(i).dot(r);
171 r = r - alpha * Q.col(i);
182 const bool krylovClosed = beta <= 1e-10 * std::fabs(alpha);
185 Eigen::SelfAdjointEigenSolver<MatrixXd> es(T.block(0, 0, i + 1, i + 1));
186 ew = es.eigenvalues()(0);
187 evT = es.eigenvectors().col(0);
189 std::fabs(ewOld), 1.0);
192 evEst = Q.block(0, 0, size, i + 1) * evT;
193 eonc::safemath::safe_normalize_inplace(evEst);
199 "[ILanczos] {:9s} {:9s} {:10s} {:14s} {:9.4f} "
200 "{:10.6f} {:7.3f} {:5} n_mobile={}",
201 "----",
"----",
"----",
"----", ew, ewAbsRelErr,
204 QUILL_LOG_ERROR(
log,
"[ILanczos] ERROR: linear dependence");
207 if (ewAbsRelErr <
params.lanczos_options().tolerance) {
208 QUILL_LOG_INFO(
log,
"[ILanczos] Tolerance reached: {}",
209 params.lanczos_options().tolerance);
218 QUILL_LOG_ERROR(
log,
"[ILanczos] ERROR: linear dependence");
223 double Cnew = u.dot(Q.col(i));
225 std::fabs(Cprev), 1.0);
226 if (ewAbsRelErr <=
params.lanczos_options().tolerance) {
229 QUILL_LOG_INFO(
log,
"[ILanczos] Tolerance reached: {}",
230 params.lanczos_options().tolerance);
236 if (i >=
params.lanczos_options().max_iterations - 1) {
237 QUILL_LOG_ERROR(
log,
"[ILanczos] Max iterations");
243 totalForceCalls = tmpMatter->getForceCalls() - forceCallsStart + probeCalls;
246 if (evEst.size() == size) {
void evaluateTogether(Potential &pot, std::span< Matter *const > systems, bool threads, std::span< const long > owners)
Evaluates every system that needs a force update.