Loading...
Searching...
No Matches
gpr::quantum::ringbath Namespace Reference

Classes

struct  Kernel
struct  Sensitivity

Typedefs

using Matrix = Eigen::MatrixXd
using Vector = Eigen::VectorXd

Enumerations

enum class  Potential { Frozen , Relaxed }

Functions

Vector matsubaraShifts (Eigen::Index beads, double betaN, double hbar=1)
Kernel boundKernel (Potential potential, const Matrix &C, const Matrix &Q, const Matrix &AQ, double alpha, const Vector &shifts)
double modeWeight (Eigen::Index k, Eigen::Index separation, Eigen::Index beads)
void requireBlocks (const std::vector< Matrix > &blocks, Eigen::Index beads)
Matrix ringMatrix (const std::vector< Matrix > &blocks, Eigen::Index beads)
std::vector< Matrix > projectRing (const Matrix &W, Eigen::Index beads, Eigen::Index d)
Matrix positiveRoot (const Matrix &D)
double nuclearNorm (const Matrix &M)
Sensitivity logRateSensitivity (const ratepost::Ring &ring, const ratepost::Weights &w, const Kernel &kernel)

Typedef Documentation

◆ Matrix

using gpr::quantum::ringbath::Matrix = Eigen::MatrixXd

Definition at line 39 of file RingBathKernel.h.

◆ Vector

using gpr::quantum::ringbath::Vector = Eigen::VectorXd

Definition at line 40 of file RingBathKernel.h.

Enumeration Type Documentation

◆ Potential

Enumerator
Frozen 
Relaxed 

Definition at line 42 of file RingBathKernel.h.

Function Documentation

◆ boundKernel()

Kernel gpr::quantum::ringbath::boundKernel ( Potential potential,
const Matrix & C,
const Matrix & Q,
const Matrix & AQ,
double alpha,
const Vector & shifts )
inline

Definition at line 76 of file RingBathKernel.h.

78{
79 if (shifts.size() < 2 || !shifts.allFinite() || shifts(0) != 0 ||
80 (shifts.array() < 0).any())
81 throw std::invalid_argument(
82 "Matsubara shifts from matsubaraShifts required");
83 if (!(alpha > 0))
84 throw std::invalid_argument(
85 "A positive environment spectral bound is required at the centroid "
86 "shift");
87 Kernel kernel;
88 kernel.potential = potential;
89 const auto r = C.cols();
90 const auto zero = bathresponse::boundResponse(C, Q, AQ, alpha, 0.);
91 for (Eigen::Index k = 0; k < shifts.size(); ++k) {
92 const auto shifted =
93 k == 0 ? zero
94 : bathresponse::boundResponse(C, Q, AQ, alpha, shifts(k));
95 if (potential == Potential::Frozen) {
96 kernel.lower.push_back(-shifted.upper);
97 kernel.upper.push_back(-shifted.lower);
98 } else if (k == 0) {
99 kernel.lower.push_back(Matrix::Zero(r, r));
100 kernel.upper.push_back(Matrix::Zero(r, r));
101 } else {
102 kernel.lower.push_back(zero.lower - shifted.upper);
103 kernel.upper.push_back(zero.upper - shifted.lower);
104 }
105 }
106 return kernel;
107}
Bounds boundResponse(const Matrix &B, const Matrix &Q, const Matrix &AQ, double alpha, double shift)
std::vector< Matrix > upper
std::vector< Matrix > lower

◆ logRateSensitivity()

Sensitivity gpr::quantum::ringbath::logRateSensitivity ( const ratepost::Ring & ring,
const ratepost::Weights & w,
const Kernel & kernel )
inline

Definition at line 211 of file RingBathKernel.h.

214{
215 const auto N = static_cast<Eigen::Index>(ring.beads.size());
216 requireBlocks(kernel.lower, N);
217 requireBlocks(kernel.upper, N);
218 const Eigen::Index d = kernel.lower.front().rows();
219 if (N < 4 || ring.beads.front().size() != d ||
220 w.pseudoInverse.rows() != N * d)
221 throw std::invalid_argument(
222 "Kernel, ring and weights dimensions must match");
223 const bool hasReactant = ring.reactantHessian.size() != 0;
224 if (kernel.potential == Potential::Frozen && !hasReactant)
225 throw std::invalid_argument(
226 "A frozen environment kernel needs the reactant as reference");
227 const Vector reference = hasReactant ? ring.reactant : Vector::Zero(d);
228 Vector x(N * d), wg(N * d);
229 const Eigen::Index sites = hasReactant ? N + 1 : N;
230 if (w.channels.size() != sites * (d + 1))
231 throw std::invalid_argument("Weights do not match the ring");
232 for (Eigen::Index j = 0; j < N; ++j) {
233 x.segment(j * d, d) = ring.beads[j] - reference;
234 for (Eigen::Index c = 0; c < d; ++c)
235 wg(j * d + c) = w.channels(ratepost::siteChannel(sites, j, c));
236 }
237 Sensitivity result;
238 Matrix W = -.5 * ring.betaN * x * x.transpose() +
239 .5 * (wg * x.transpose() + x * wg.transpose()) -
240 .5 * w.pseudoInverse;
241 if (hasReactant) {
242 Eigen::LLT<Matrix> reactant(ring.reactantHessian);
243 if (reactant.info() != Eigen::Success)
244 throw std::domain_error("A positive reactant ring is required");
245 W += .5 * reactant.solve(Matrix::Identity(N * d, N * d));
246 }
247 result.ringWeight = .5 * (W + W.transpose());
248 result.modeWeights = projectRing(result.ringWeight, N, d);
249 for (std::size_t k = 0; k < kernel.lower.size(); ++k) {
250 const Matrix root = positiveRoot(kernel.upper[k] - kernel.lower[k]);
251 result.halfWidth +=
252 .5 * nuclearNorm(root * result.modeWeights[k] * root);
253 }
254 result.actionLower = .5 * x.dot(ringMatrix(kernel.lower, N) * x);
255 result.actionUpper = .5 * x.dot(ringMatrix(kernel.upper, N) * x);
256 return result;
257}
@ x
Definition Enums.h:28
Eigen::Index siteChannel(Eigen::Index sites, Eigen::Index site, Eigen::Index component)
std::vector< Matrix > projectRing(const Matrix &W, Eigen::Index beads, Eigen::Index d)
double nuclearNorm(const Matrix &M)
Matrix positiveRoot(const Matrix &D)
Eigen::MatrixXd Matrix
void requireBlocks(const std::vector< Matrix > &blocks, Eigen::Index beads)
Eigen::VectorXd Vector
Matrix ringMatrix(const std::vector< Matrix > &blocks, Eigen::Index beads)
Eigen::MatrixXd Matrix

◆ matsubaraShifts()

Vector gpr::quantum::ringbath::matsubaraShifts ( Eigen::Index beads,
double betaN,
double hbar = 1 )
inline

Definition at line 45 of file RingBathKernel.h.

46{
47 if (beads < 2 || !(betaN > 0) || !(hbar > 0) || !std::isfinite(betaN) ||
48 !std::isfinite(hbar))
49 throw std::invalid_argument(
50 "At least two beads and positive beta_N and hbar required");
51 Vector shifts(beads / 2 + 1);
52 for (Eigen::Index k = 0; k < shifts.size(); ++k) {
53 const double s =
54 2 * std::sin(std::numbers::pi * k / beads) / (betaN * hbar);
55 shifts(k) = s * s;
56 }
57 return shifts;
58}

◆ modeWeight()

double gpr::quantum::ringbath::modeWeight ( Eigen::Index k,
Eigen::Index separation,
Eigen::Index beads )
inline

Definition at line 110 of file RingBathKernel.h.

112{
113 const double c = std::cos(2 * std::numbers::pi *
114 static_cast<double>(k * separation) / beads);
115 return (k == 0 || 2 * k == beads ? 1. : 2.) * c / beads;
116}

◆ nuclearNorm()

double gpr::quantum::ringbath::nuclearNorm ( const Matrix & M)
inline

Definition at line 188 of file RingBathKernel.h.

189{
190 Eigen::SelfAdjointEigenSolver<Matrix> s(.5 * (M + M.transpose()),
191 Eigen::EigenvaluesOnly);
192 if (s.info() != Eigen::Success)
193 throw std::runtime_error("Nuclear norm spectrum failed");
194 return s.eigenvalues().cwiseAbs().sum();
195}

◆ positiveRoot()

Matrix gpr::quantum::ringbath::positiveRoot ( const Matrix & D)
inline

Definition at line 174 of file RingBathKernel.h.

175{
176 Eigen::SelfAdjointEigenSolver<Matrix> s(.5 * (D + D.transpose()));
177 if (s.info() != Eigen::Success)
178 throw std::runtime_error("Kernel width spectrum failed");
179 const double tolerance =
180 1e-12 * std::max(1., s.eigenvalues().cwiseAbs().maxCoeff());
181 if (s.eigenvalues().minCoeff() < -tolerance)
182 throw std::domain_error("Kernel bounds are not ordered");
183 return s.eigenvectors() *
184 s.eigenvalues().cwiseMax(0.).cwiseSqrt().asDiagonal() *
185 s.eigenvectors().transpose();
186}

◆ projectRing()

std::vector< Matrix > gpr::quantum::ringbath::projectRing ( const Matrix & W,
Eigen::Index beads,
Eigen::Index d )
inline

Definition at line 149 of file RingBathKernel.h.

151{
152 if (beads < 2 || d < 1 || W.rows() != beads * d || W.cols() != beads * d ||
153 !W.allFinite())
154 throw std::invalid_argument("Ring matrix of matching size required");
155 std::vector<Matrix> projected(beads / 2 + 1, Matrix::Zero(d, d));
156 for (Eigen::Index j = 0; j < beads; ++j)
157 for (Eigen::Index l = 0; l < beads; ++l)
158 for (std::size_t k = 0; k < projected.size(); ++k)
159 projected[k] += modeWeight(static_cast<Eigen::Index>(k),
160 (j - l + beads) % beads, beads) *
161 W.block(l * d, j * d, d, d);
162 for (auto& p: projected)
163 p = (.5 * (p + p.transpose())).eval();
164 return projected;
165}
double modeWeight(Eigen::Index k, Eigen::Index separation, Eigen::Index beads)

◆ requireBlocks()

void gpr::quantum::ringbath::requireBlocks ( const std::vector< Matrix > & blocks,
Eigen::Index beads )
inline

Definition at line 118 of file RingBathKernel.h.

119{
120 if (beads < 2 || blocks.size() != static_cast<std::size_t>(beads / 2 + 1))
121 throw std::invalid_argument(
122 "One kernel block per Matsubara frequency k = 0..N/2 required");
123 for (const auto& b: blocks)
124 if (b.rows() != blocks.front().rows() || b.cols() != b.rows() ||
125 !b.allFinite() || b.rows() == 0)
126 throw std::invalid_argument(
127 "Finite square kernel blocks of one size required");
128}

◆ ringMatrix()

Matrix gpr::quantum::ringbath::ringMatrix ( const std::vector< Matrix > & blocks,
Eigen::Index beads )
inline

Definition at line 132 of file RingBathKernel.h.

133{
134 requireBlocks(blocks, beads);
135 const Eigen::Index d = blocks.front().rows();
136 Matrix K = Matrix::Zero(beads * d, beads * d);
137 for (Eigen::Index j = 0; j < beads; ++j)
138 for (Eigen::Index l = 0; l < beads; ++l)
139 for (std::size_t k = 0; k < blocks.size(); ++k)
140 K.block(j * d, l * d, d, d) +=
141 modeWeight(static_cast<Eigen::Index>(k),
142 (j - l + beads) % beads, beads) *
143 .5 * (blocks[k] + blocks[k].transpose());
144 return K;
145}