74 std::vector<double> times,
75 const std::vector<HarmonicPointCurvature>& updates,
76 const M& normal, M modes = {},
77 double unresolvedTolerance = 1e-12,
78 std::vector<M> modalGreen = {})
79 : omega_(
std::move(frequencies)),
80 modes_(
std::move(modes)),
81 times_(
std::move(times)),
83 modalGreen_(
std::move(modalGreen))
85 const auto d = omega_.size(),
86 n =
static_cast<Eigen::Index
>(times_.size());
88 d > 0 && n > 0 && omega_.allFinite() &&
89 (omega_.array() > 0).all() && period_ > 0 &&
90 std::isfinite(period_) && std::isfinite(unresolvedTolerance) &&
91 unresolvedTolerance >= 0,
92 "Positive finite harmonic frequencies and thermal period required");
93 require(n <= std::numeric_limits<Eigen::Index>::max() / d,
94 "Nodal dimension exceeds range");
96 codimension_ = normal.cols();
97 require(codimension_ <= dimension_ && normal.rows() == dimension_ &&
99 "Matching finite nodal constraint columns required");
101 require((normal.transpose() * normal -
102 M::Identity(codimension_, codimension_))
104 "Nodal constraints must be jointly orthonormal");
105 require(!modes_.size() ||
106 (modes_.rows() == d && modes_.cols() == d &&
107 modes_.allFinite() &&
108 (modes_.transpose() * modes_ - M::Identity(d, d)).norm() <=
110 "Orthonormal harmonic normal modes required");
111 for (Eigen::Index j = 0; j < n; ++j)
112 require(std::isfinite(times_[j]) && times_[j] >= 0 &&
113 times_[j] < period_ &&
114 (!j || times_[j] > times_[j - 1]),
115 "Distinct increasing imaginary times inside one period "
117 require(green(0).allFinite(),
118 "Harmonic reference response exceeds numerical range");
119 require(modalGreen_.empty() ||
120 modalGreen_.size() ==
static_cast<std::size_t
>(d),
121 "One nodal reference Green matrix per harmonic mode required");
122 for (
auto& matrix: modalGreen_) {
123 require(matrix.rows() == n && matrix.cols() == n &&
124 matrix.allFinite() &&
125 (matrix - matrix.transpose()).norm() <=
126 1e-12 * std::max(1., matrix.norm()),
127 "Matching finite symmetric modal Green matrices required");
128 matrix = (.5 * matrix + .5 * matrix.transpose()).eval();
129 const Eigen::LDLT<M> factor(matrix);
130 require(factor.info() == Eigen::Success &&
131 (factor.vectorD().array() > 0).all(),
132 "Modal reference Green matrix must be positive");
134 std::vector<V> columns;
135 std::vector<double> signs;
136 Eigen::Index negativeSigns = 0;
137 for (
const auto& update: updates) {
138 require(update.node < times_.size() &&
139 update.direction.size() == d &&
140 update.direction.allFinite() &&
141 std::isfinite(update.strength),
142 "Finite matching point curvature required");
143 if (update.strength == 0)
continue;
144 require(update.direction.squaredNorm() > 0,
145 "A nonzero point curvature needs a resolved direction");
146 V column = modes_.size() ? V(modes_.transpose() * update.direction)
148 column *= std::sqrt(std::abs(update.strength));
149 require(column.allFinite(),
150 "Point curvature exceeds the harmonic coordinate range");
151 nodes_.push_back(update.node);
152 columns.push_back(std::move(column));
153 signs.push_back(update.strength < 0 ? -1. : 1.);
154 negativeSigns += update.strength < 0;
156 const auto r =
static_cast<Eigen::Index
>(columns.size()),
157 size = r + codimension_;
158 signs_ = Eigen::Map<const V>(signs.data(), r);
159 directions_.resize(d, r);
160 for (Eigen::Index j = 0; j < r; ++j)
161 directions_.col(j) = columns[j];
162 for (Eigen::Index j = 0; j < n; ++j) {
165 M block = codimension_ == 0 ? M(d, 0) : normal.middleRows(j * d, d);
166 if (modes_.size() && codimension_)
167 block = (modes_.transpose() * block).eval();
168 normals_.push_back(std::move(block));
170 M small = M::Zero(size, size);
171 V rowScales = V::Ones(size);
172 for (Eigen::Index i = 0; i < r; ++i) {
173 for (Eigen::Index j = 0; j < r; ++j)
175 (directions_.col(i).array() * directions_.col(j).array() *
176 greenNodes(nodes_[i], nodes_[j]).array())
178 rowScales[i] += small(i, i);
179 small(i, i) += signs[i];
180 for (Eigen::Index j = 0; j < n && codimension_; ++j)
181 small.block(i, r, 1, codimension_).noalias() +=
182 (directions_.col(i).array() *
183 greenNodes(nodes_[i], j).array())
189 small.bottomLeftCorner(codimension_, r) =
190 small.topRightCorner(r, codimension_).transpose();
191 for (Eigen::Index i = 0; i < n; ++i)
192 for (Eigen::Index j = 0; j < n; ++j)
193 small.bottomRightCorner(codimension_, codimension_)
194 .noalias() += normals_[i].transpose() *
195 greenNodes(i, j).asDiagonal() *
198 require(small.allFinite(),
"Reduced harmonic response is nonfinite");
199 small = (.5 * small + .5 * small.transpose()).eval();
200 for (Eigen::Index j = 0; j < codimension_; ++j)
201 rowScales[r + j] = small(r + j, r + j);
202 require(rowScales.allFinite() && (rowScales.array() > 0).all(),
203 "Resolved positive reference Gram diagonals required");
204 Eigen::Index negativeSmall = 0, zeroSmall = 0;
206 V scales = V::Ones(size);
207 for (Eigen::Index j = 0; j < size; ++j) {
210 scales[j] = 1 / std::sqrt(rowScales[j]);
211 logRatio_ -= 2 * std::log(scales[j]);
213 small = (scales.asDiagonal() * small).eval();
214 small = (small * scales.asDiagonal()).eval();
215 Eigen::SelfAdjointEigenSolver<M> spectrum(small);
216 if (spectrum.info() != Eigen::Success ||
217 !spectrum.eigenvalues().allFinite())
218 throw std::runtime_error(
219 "Reduced harmonic response eigensolve fails");
220 smallVectors_ = scales.asDiagonal() * spectrum.eigenvectors();
221 smallValues_ = spectrum.eigenvalues();
223 std::max(1., smallValues_.cwiseAbs().maxCoeff());
224 for (
double value: smallValues_) {
225 if (std::abs(value) <= unresolvedTolerance * scale)
228 negativeSmall += value < 0;
229 logRatio_ += std::log(std::abs(value));
233 smallVectors_.resize(0, 0);
234 smallValues_.resize(0);
237 inertia_.negative = negativeSigns - negativeSmall - zeroSmall;
238 inertia_.unresolved = zeroSmall;
240 dimension_ - codimension_ - inertia_.negative - zeroSmall;
241 if (inertia_.negative < 0 || inertia_.positive < 0)
242 throw std::runtime_error(
243 "Reduced harmonic inertia exceeds the nodal subspace");
270 inertia_.negative == 1 && inertia_.unresolved == 0,
271 "A Gaussian saddle section needs one resolved unstable direction");
272 const auto d = omega_.size(),
273 n =
static_cast<Eigen::Index
>(times_.size());
274 const auto r = directions_.cols(), k = codimension_;
275 M gram = M::Zero(r, r), cross = M::Zero(r, k),
276 constraint = M::Zero(k, k);
277 for (Eigen::Index i = 0; i < r; ++i) {
278 for (Eigen::Index j = 0; j < r; ++j)
280 (directions_.col(i).array() * directions_.col(j).array() *
281 greenNodes(nodes_[i], nodes_[j]).array())
283 for (Eigen::Index j = 0; j < n && k; ++j)
284 cross.row(i).noalias() += (directions_.col(i).array() *
285 greenNodes(nodes_[i], j).array())
290 M projected = M::Zero(r, r);
292 for (Eigen::Index i = 0; i < n; ++i)
293 for (Eigen::Index j = 0; j < n; ++j)
294 constraint.noalias() += normals_[i].transpose() *
295 greenNodes(i, j).asDiagonal() *
297 const Eigen::LDLT<M> factor(constraint);
298 require(factor.info() == Eigen::Success &&
299 (factor.vectorD().array() > 0).all(),
300 "Saddle-section reference constraint Gram matrix must be "
302 projected = cross * factor.solve(cross.transpose());
304 M restricted = gram - projected;
305 restricted = (.5 * restricted + .5 * restricted.transpose()).eval();
306 const Eigen::SelfAdjointEigenSolver<M> eig(restricted);
307 require(eig.info() == Eigen::Success,
308 "Saddle-section reference Gram spectrum is unresolved");
309 const double threshold = 64 * std::numeric_limits<double>::epsilon() *
310 (gram.norm() + projected.norm());
311 require(eig.eigenvalues().minCoeff() >= -threshold,
312 "Saddle-section reference Gram matrix is indefinite");
313 const auto count = (eig.eigenvalues().array() > threshold).count();
314 require(count > 0,
"Saddle section has no resolved update direction");
315 const M basis = eig.eigenvectors().rightCols(count);
316 const V roots = eig.eigenvalues().tail(count).array().sqrt();
317 const M reduced = M::Identity(count, count) +
318 roots.asDiagonal() * basis.transpose() *
319 signs_.asDiagonal() * basis * roots.asDiagonal();
320 const Eigen::SelfAdjointEigenSolver<M> unstable(reduced);
321 require(unstable.info() == Eigen::Success &&
322 unstable.eigenvalues()[0] < 0 &&
323 (count == 1 || unstable.eigenvalues()[1] > 0),
324 "Saddle section has no unique negative reference direction");
325 const V coefficients =
327 (unstable.eigenvectors().col(0).array() / roots.array()).matrix();
328 const V normalWeights =
329 coefficients + signs_.asDiagonal() * (restricted * coefficients);
330 V normal = V::Zero(dimension_);
331 for (Eigen::Index j = 0; j < r; ++j)
332 normal.segment(nodes_[j] * d, d) +=
333 directions_.col(j) * normalWeights[j];
334 V component = V::Zero(k);
335 for (Eigen::Index j = 0; j < n && k; ++j)
336 component += normals_[j].transpose() * normal.segment(j * d, d);
337 for (Eigen::Index j = 0; j < n && k; ++j)
338 normal.segment(j * d, d) -= normals_[j] * component;
339 require(normal.allFinite() && normal.norm() > 0,
340 "Saddle-section normal is unresolved");
341 normal /= normal.norm();
343 for (Eigen::Index j = 0; j < n; ++j)
344 normal.segment(j * d, d) =
345 (modes_ * normal.segment(j * d, d)).eval();