ampsci
High-precision calculations for one- and two-valence atomic systems
SpinorMatrix.hpp
1#pragma once
2#include "LinAlg/Matrix.hpp"
3#include "Maths/Grid.hpp"
4#include "Maths/Interpolator.hpp"
5#include "RadialMatrix.hpp"
6#include "Wavefunction/DiracSpinor.hpp"
7#include <cassert>
8#include <iostream>
9#include <type_traits>
10
11namespace MBPT {
12
13/*! Defines SpinorMatrix, Radial Dirac Spinor matrix. Designed to store
14 Greens-function like operators: |Fa><Fb| (where Fa, Fb are radial Dirac
15 spinors), as a radial matrix. The matrix is stored on a sub-grid (between r0
16 and rmax), with a specified stride.
17
18@details
19
20SpinorMatrix is a 2*2 matrix in spinor space {ff, fg, gf, gg} - the g blocks are
21small and are optional. Each block is an N*N radial matrix, where N is a subset
22of the number of points along the full radial grid. May store doubles or complex
23doubles.
24
25 SpinorMatrix = {ff fg}
26 {gf gg}
27 SpinorMatrix * F = {ff fg} * (f)
28 {gf gg} (g)
29 = (ff(r,r')*f(r') + fg(r,r')*g(r'))
30 (gf(r,r')*f(r') + gg(r,r')*g(r'))
31
32Note: Careful to distinguish SpinorMatrix multiplication/integration:
33 G1 * G2 = Int G1(ra,rb)*G2(rb,rc)
34 = Sum_j G1(i,j)*G2(j,k)
35
36G1.drj() * G2 = Int G1(ra,rb)*G2(rb,rc)*dr_b
37 = Sum_j G1(i,j)*G2(j,k)*drdu_j*du
38 = G1 * G2.dri()
39
40While almost always symmetric, this doesn't assume that.
41*/
42template <typename T>
44
45 std::size_t m_i0, m_stride;
46 std::size_t m_size;
47 std::size_t m_g_size;
48 LinAlg::Matrix<T> m_ff, m_fg, m_gf, m_gg;
49 bool m_incl_g;
50 std::shared_ptr<const Grid> m_rgrid; // "full" grid
51 std::vector<double> sub_r{}; // sub grid
52
53public:
54 //============================================================================
55
56 SpinorMatrix(std::size_t i0, std::size_t stride, std::size_t size,
57 bool incl_g, std::shared_ptr<const Grid> rgrid)
58 : m_i0(i0),
59 m_stride(stride),
60 m_size(size),
61 m_g_size(incl_g ? size : 0),
62 m_ff(m_size),
63 m_fg(m_g_size),
64 m_gf(m_g_size),
65 m_gg(m_g_size),
66 m_incl_g(incl_g),
67 m_rgrid(rgrid) {
68 //------------------
69 // create vector of r on sub-grid, used to interpolate values onto full
70 const auto &r = m_rgrid->r();
71 sub_r.reserve(m_size);
72 assert(m_i0 + m_stride * m_size <= r.size());
73 for (std::size_t i = 0; i < m_size; ++i) {
74 sub_r.push_back(r[index_to_fullgrid(i)]);
75 }
76 assert(m_i0 + m_stride * m_size <= r.size());
77 assert(sub_r[1] == r[index_to_fullgrid(1)]);
78 assert(sub_r[m_size - 1] == r[index_to_fullgrid(m_size - 1)]);
79 //------------------
80 }
81
82 //============================================================================
83 //! direct access to matrix elements
84 T &ff(std::size_t i, std::size_t j) { return m_ff(i, j); }
85 T &fg(std::size_t i, std::size_t j) { return m_fg(i, j); }
86 T &gf(std::size_t i, std::size_t j) { return m_gf(i, j); }
87 T &gg(std::size_t i, std::size_t j) { return m_gg(i, j); }
88 const T ff(std::size_t i, std::size_t j) const { return m_ff(i, j); }
89 const T fg(std::size_t i, std::size_t j) const { return m_fg(i, j); }
90 const T gf(std::size_t i, std::size_t j) const { return m_gf(i, j); }
91 const T gg(std::size_t i, std::size_t j) const { return m_gg(i, j); }
92
93 //! direct access to matrix's
94 const LinAlg::Matrix<T> &ff() const { return m_ff; }
95 const LinAlg::Matrix<T> &fg() const { return m_fg; }
96 const LinAlg::Matrix<T> &gf() const { return m_gf; }
97 const LinAlg::Matrix<T> &gg() const { return m_gg; }
98 LinAlg::Matrix<T> &ff() { return m_ff; }
99 LinAlg::Matrix<T> &fg() { return m_fg; }
100 LinAlg::Matrix<T> &gf() { return m_gf; }
101 LinAlg::Matrix<T> &gg() { return m_gg; }
102
103 LinAlg::Matrix<T> &sp(std::size_t mu, std::size_t nu) {
104 assert(mu < 2 && nu < 2);
105 if (mu == 0 && nu == 0)
106 return m_ff;
107 if (mu == 0 && nu == 1)
108 return m_fg;
109 if (mu == 1 && nu == 0)
110 return m_gf;
111 if (mu == 1 && nu == 1)
112 return m_gg;
113 assert(false);
114 }
115
116 const LinAlg::Matrix<T> &sp(std::size_t mu, std::size_t nu) const {
117 assert(mu < 2 && nu < 2);
118 if (mu == 0 && nu == 0)
119 return m_ff;
120 if (mu == 0 && nu == 1)
121 return m_fg;
122 if (mu == 1 && nu == 0)
123 return m_gf;
124 if (mu == 1 && nu == 1)
125 return m_gg;
126 assert(false);
127 }
128
129 std::size_t size() const { return m_size; }
130 std::size_t g_size() const { return m_g_size; }
131 bool includes_g() const { return m_g_size == m_size; };
132 std::size_t i0() const { return m_i0; }
133 std::size_t stride() const { return m_stride; }
134
135 //============================================================================
136 //! Sets all matrix elements to zero
137 void zero() {
138 m_ff.zero();
139 m_fg.zero();
140 m_gf.zero();
141 m_gg.zero();
142 }
143
144 //============================================================================
145 //! Kills g parts of spinor matrix, in place!
147 m_g_size = 0;
148 m_incl_g = false;
149 m_fg.resize(0, 0);
150 m_gf.resize(0, 0);
151 m_gg.resize(0, 0);
152 return *this;
153 }
154
155 //! Creates g parts of spinor matrix - will have value 0
157 m_g_size = m_size;
158 m_incl_g = true;
159 m_fg.resize(m_size, m_size);
160 m_gf.resize(m_size, m_size);
161 m_gg.resize(m_size, m_size);
162 return *this;
163 }
164
165 //============================================================================
166 //! Matrix adition +,-
168 m_ff += rhs.m_ff;
169 m_fg += rhs.m_fg;
170 m_gf += rhs.m_gf;
171 m_gg += rhs.m_gg;
172 return *this;
173 }
174 //! Matrix adition +,-
176 m_ff -= rhs.m_ff;
177 m_fg -= rhs.m_fg;
178 m_gf -= rhs.m_gf;
179 m_gg -= rhs.m_gg;
180 return *this;
181 }
182 //! Scalar multiplication
184 m_ff *= x;
185 m_fg *= x;
186 m_gf *= x;
187 m_gg *= x;
188 return *this;
189 }
190
191 //! Matrix adition +,-
192 [[nodiscard]] friend SpinorMatrix<T> operator+(SpinorMatrix<T> lhs,
193 const SpinorMatrix<T> &rhs) {
194 return (lhs += rhs);
195 }
196 //! Matrix adition +,-
197 [[nodiscard]] friend SpinorMatrix<T> operator-(SpinorMatrix<T> lhs,
198 const SpinorMatrix<T> &rhs) {
199 return (lhs -= rhs);
200 }
201 //! Scalar multiplication
202 [[nodiscard]] friend SpinorMatrix<T> operator*(const T x,
203 SpinorMatrix<T> rhs) {
204 return (rhs *= x);
205 }
206
207 //! Adition of identity: Matrix<T> += T : T assumed to be *Identity!
209 m_ff += aI;
210 m_gg += aI;
211 return *this;
212 }
213 //! Adition of identity: Matrix<T> -= T : T assumed to be *Identity!
215 m_ff -= aI;
216 m_gg -= aI;
217 return *this;
218 }
219
220 //! Adition of identity: Matrix<T> + T : T assumed to be *Identity!
221 [[nodiscard]] friend SpinorMatrix<T> operator+(SpinorMatrix<T> M, T aI) {
222 return (M += aI);
223 }
224 //! Adition of identity: Matrix<T> - T : T assumed to be *Identity!
225 [[nodiscard]] friend SpinorMatrix<T> operator-(SpinorMatrix<T> M, T aI) {
226 return (M -= aI);
227 }
228
229 //============================================================================
230
231 //! Matrix multplication: \f$ C=A\times B \equiv C_{ij} = \sum_k A_{ik}\,B_{kj}. \f$
232 //! Note: integration measure not automatically included: call .drj() first to include it!
233 [[nodiscard]] friend SpinorMatrix<T> operator*(const SpinorMatrix<T> &a,
234 const SpinorMatrix<T> &b) {
235
236 SpinorMatrix<T> out(a.m_i0, a.m_stride, a.m_size, a.m_incl_g, a.m_rgrid);
237
238 // FF = FF*FF + FG*GF
239 // FG = FF*FG + FG*GG
240 // GF = GF*FF + GG*GF
241 // GG = GF*FG + GG*GG
242 out.ff() = a.ff() * b.ff();
243 if (a.m_incl_g && b.m_incl_g) {
244 out.ff() += a.fg() * b.gf();
245 out.fg() = a.ff() * b.fg() + a.fg() * b.gg();
246 out.gf() = a.gf() * b.ff() + a.gg() * b.gf();
247 out.gg() = a.gf() * b.fg() + a.gg() * b.gg();
248 }
249 return out;
250 }
251
252 //============================================================================
253 //! Multiply elements (in place): Gij -> Gij*Bij
255 m_ff.mult_elements_by(rhs.ff());
256 if (this->m_incl_g) {
257 // && rhs.m_incl_g
258 // I WANT an error if matrices not identical!?
259 m_fg.mult_elements_by(rhs.fg());
260 m_gf.mult_elements_by(rhs.gf());
261 m_gg.mult_elements_by(rhs.gg());
262 }
263 return *this;
264 }
265 //! Multiply elements (new matrix): Gij = Aij*Bij
266 [[deprecated]] [[nodiscard]] friend SpinorMatrix<T>
268 lhs.mult_elements_by(rhs);
269 return lhs;
270 }
271
272 //============================================================================
273 //! Multiply elements (in place): Gij -> Gij*Bij
275 m_ff.mult_elements_by(rhs.Rmatrix());
276 if (this->m_incl_g) {
277 m_fg.mult_elements_by(rhs.Rmatrix());
278 m_gf.mult_elements_by(rhs.Rmatrix());
279 m_gg.mult_elements_by(rhs.Rmatrix());
280 }
281 return *this;
282 }
283
284 //! Multiply elements (new matrix): Gij = Aij*Bij
285 [[nodiscard]] friend SpinorMatrix<T>
287 lhs.mult_elements_by(rhs);
288 return lhs;
289 }
290
291 //! Multiply elements (new matrix): Gij = Aij*Bij
292 [[nodiscard]] friend SpinorMatrix<T> mult_elements(const RadialMatrix<T> &rhs,
293 SpinorMatrix<T> lhs) {
294 lhs.mult_elements_by(rhs);
295 return lhs;
296 }
297
298 //============================================================================
299
300 //! Returns conjugate of matrix
301 [[nodiscard]] SpinorMatrix<T> conj() const {
302 auto out = *this;
303 out.ff().conj_in_place();
304 out.fg().conj_in_place();
305 out.gf().conj_in_place();
306 out.gg().conj_in_place();
307 return out;
308 }
309 //! Returns real part of complex matrix (changes type; returns a real
310 //! matrix)
311 [[nodiscard]] SpinorMatrix<double> real() const {
312 SpinorMatrix<double> out(m_i0, m_stride, m_size, m_incl_g, m_rgrid);
313 out.ff() = m_ff.real();
314 out.fg() = m_fg.real();
315 out.gf() = m_gf.real();
316 out.gg() = m_gg.real();
317 return out;
318 }
319 //! Returns imag part of complex matrix (changes type; returns a real matrix)
320 [[nodiscard]] SpinorMatrix<double> imag() const {
321 SpinorMatrix<double> out(m_i0, m_stride, m_size, m_incl_g, m_rgrid);
322 out.ff() = m_ff.imag();
323 out.fg() = m_fg.imag();
324 out.gf() = m_gf.imag();
325 out.gg() = m_gg.imag();
326 return out;
327 }
328 //! Converts a real to complex matrix (changes type; returns a complex
329 //! matrix)
331 SpinorMatrix<std::complex<double>> out(m_i0, m_stride, m_size, m_incl_g,
332 m_rgrid);
333 out.ff() = m_ff.complex();
334 out.fg() = m_fg.complex();
335 out.gf() = m_gf.complex();
336 out.gg() = m_gg.complex();
337 return out;
338 }
339
340 //============================================================================
341 //! Inversion (in place)
343 m_ff.invert_in_place();
344 if (m_incl_g) {
345 const auto &ai = m_ff; // already inverted
346 const auto &b = m_fg;
347 const auto &c = m_gf;
348 const auto &d = m_gg;
349 const auto cai = c * ai;
350 const auto dmcaib = (d - cai * b).invert_in_place();
351 const auto aib_dmcaib = ai * b * dmcaib;
352 m_ff += aib_dmcaib * cai;
353 m_fg = -1.0 * aib_dmcaib;
354 m_gf = -1.0 * dmcaib * cai;
355 m_gg = dmcaib;
356 }
357 return *this;
358 }
359 //! Returns inverse of matrix; original matrix unchanged
360 [[nodiscard]] SpinorMatrix<T> inverse() const {
361 auto out = *this; //
362 return out.invert_in_place();
363 }
364
365 //============================================================================
366 //! Multiplies by drj: Q_ij -> Q_ij*dr_j, in place
368 const auto dus = m_rgrid->du() * double(m_stride);
369 for (auto i = 0ul; i < m_size; ++i) {
370 for (auto j = 0ul; j < m_size; ++j) {
371 const auto sj = index_to_fullgrid(j);
372 const auto dr = m_rgrid->drdu(sj) * dus;
373 m_ff[i][j] *= dr;
374 }
375 }
376 if (m_incl_g) {
377 for (auto i = 0ul; i < m_size; ++i) {
378 for (auto j = 0ul; j < m_size; ++j) {
379 const auto sj = index_to_fullgrid(j);
380 const auto dr = m_rgrid->drdu(sj) * dus;
381 m_fg[i][j] *= dr;
382 m_gf[i][j] *= dr;
383 m_gg[i][j] *= dr;
384 }
385 }
386 }
387 return *this;
388 }
389 //! Multiplies by dri: Q_ij -> Q_ij*dr_i, in place
391 const auto dus = m_rgrid->du() * double(m_stride);
392 for (auto i = 0ul; i < m_size; ++i) {
393 const auto si = index_to_fullgrid(i);
394 const auto dr = m_rgrid->drdu(si) * dus;
395 for (auto j = 0ul; j < m_size; ++j) {
396 m_ff[i][j] *= dr;
397 }
398 }
399 if (m_incl_g) {
400 for (auto i = 0ul; i < m_size; ++i) {
401 const auto si = index_to_fullgrid(i);
402 const auto dr = m_rgrid->drdu(si) * dus;
403 for (auto j = 0ul; j < m_size; ++j) {
404 m_fg[i][j] *= dr;
405 m_gf[i][j] *= dr;
406 m_gg[i][j] *= dr;
407 }
408 }
409 }
410 return *this;
411 }
412 //! Multiplies by drj: Q_ij -> Q_ij*dr_j. Returns new matrix (orig unchanged)
414 auto out = *this;
415 return out.drj_in_place();
416 }
417 //! Multiplies by dri: Q_ij -> Q_ij*dr_i. Returns new matrix (orig unchanged)
419 auto out = *this;
420 return out.dri_in_place();
421 }
422
423 //! returns dr at position along sub grid
424 double dr(std::size_t sub_index) const {
425 const auto full_index = index_to_fullgrid(sub_index);
426 return m_rgrid->drdu(full_index) * m_rgrid->du() * double(m_stride);
427 }
428
429 //============================================================================
430 //! Converts an index on the sub-grid to the full grid.
431 std::size_t index_to_fullgrid(std::size_t i) const {
432 return m_i0 + i * m_stride;
433 }
434
435 //============================================================================
436 //! Adds k*|ket><bra| to matrix (used for building Green's functions)
437 void add(const DiracSpinor &ket, const DiracSpinor &bra, T k = T(1.0)) {
438 // Adds (k)*|ket><bra| to G matrix
439 // G_ij = f * Q_i * W_j
440 // Q = Q(1) = ket, W = W(2) = bra
441 // Takes sub-grid into account; ket,bra are on full grid, G on sub-grid
442 for (auto i = 0ul; i < m_size; ++i) {
443 const auto si = index_to_fullgrid(i);
444 for (auto j = 0ul; j < m_size; ++j) {
445 const auto sj = index_to_fullgrid(j);
446 m_ff[i][j] += k * ket.f(si) * bra.f(sj);
447 }
448 }
449
450 if (m_incl_g) {
451 for (auto i = 0ul; i < m_size; ++i) {
452 const auto si = index_to_fullgrid(i);
453 for (auto j = 0ul; j < m_size; ++j) {
454 const auto sj = index_to_fullgrid(j);
455 // XXX Double check fg/gf right way!
456 m_fg[i][j] += k * ket.f(si) * bra.g(sj);
457 m_gf[i][j] += k * ket.g(si) * bra.f(sj); // symmetric, transpose?
458 m_gg[i][j] += k * ket.g(si) * bra.g(sj);
459 }
460 }
461 }
462 }
463
464 //============================================================================
465 //! Action of SpinorMatrix operator on DiracSpinor. Inludes Integration:
466 //! G*F = Int[G(r,r')*F(r') dr'] = sum_j G_ij*F_j*drdu_j*du
468
469 const auto &r = Fn.grid().r();
470 // const auto &drdu = Fn.grid().drdu();
471 // const double s_du = double(m_stride) * Fn.grid().du();
472
473 // include dr?? No, not by default?
474 std::vector<double> f(m_size), g;
475 for (auto i = 0ul; i < m_size; ++i) {
476 for (auto j = 0ul; j < m_size; ++j) {
477 const auto j_f = index_to_fullgrid(j);
478 f[i] += m_ff(i, j) * Fn.f(j_f); // * drdu[j_f] * s_du;
479 }
480 }
481 if (m_incl_g) {
482 g.resize(m_size);
483 for (auto i = 0ul; i < m_size; ++i) {
484 for (auto j = 0ul; j < m_size; ++j) {
485 const auto j_f = index_to_fullgrid(j);
486 f[i] += m_fg(i, j) * Fn.g(j_f); // * drdu[j_f] * s_du;
487 g[i] += (m_gf(i, j) * Fn.f(j_f) + m_gg(i, j) * Fn.g(j_f)); // *
488 // drdu[j_f] * s_du;
489 }
490 }
491 }
492
493 DiracSpinor out = Fn * 0.0;
494 // Interpolate from sub-grid to full grid
495 out.f() = Interpolator::interpolate(sub_r, f, r);
496 if (m_incl_g) {
497 out.g() = Interpolator::interpolate(sub_r, g, r);
498 }
499 return out;
500 }
501
502 //============================================================================
503 // For testing only:
504 friend std::ostream &operator<<(std::ostream &os, const SpinorMatrix<T> &a) {
505 os << "FF:\n";
506 os << a.m_ff;
507 if (a.m_incl_g) {
508 os << "FG:\n";
509 os << a.m_fg;
510 os << "GF:\n";
511 os << a.m_gf;
512 os << "GG:\n";
513 os << a.m_gg;
514 }
515 return os;
516 }
517};
518
519//! Checks if two matrix's are equal (to within parts in 10^12)
520template <typename T>
521bool equal(const SpinorMatrix<T> &lhs, const SpinorMatrix<T> &rhs) {
522 return equal(lhs.ff(), rhs.ff()) && equal(lhs.fg(), rhs.fg()) &&
523 equal(lhs.gf(), rhs.gf()) && equal(lhs.gg(), rhs.gg());
524}
525
526//! returns maximum element (by abs)
527template <typename T>
528double max_element(const SpinorMatrix<T> &a) {
529 double xff = 0.0, xfg = 0.0, xgf = 0.0, xgg = 0.0;
530 for (auto i = 0ul; i < a.size(); ++i) {
531 for (auto j = 0ul; j < a.size(); ++j) {
532 if (std::abs(a.ff(i, j)) > xff)
533 xff = std::abs(a.ff(i, j));
534 if (a.g_size() != 0) {
535 if (std::abs(a.fg(i, j)) > xfg)
536 xfg = std::abs(a.fg(i, j));
537 if (std::abs(a.gf(i, j)) > xgf)
538 xgf = std::abs(a.gf(i, j));
539 if (std::abs(a.gg(i, j)) > xgg)
540 xgg = std::abs(a.gg(i, j));
541 }
542 }
543 }
544 return std::max({xff, xfg, xgf, xgg});
545}
546
547//! returns maximum difference (abs) between two matrixs
548template <typename T>
549double max_delta(const SpinorMatrix<T> &a, const SpinorMatrix<T> &b) {
550 double xff = 0.0, xfg = 0.0, xgf = 0.0, xgg = 0.0;
551 for (auto i = 0ul; i < a.size(); ++i) {
552 for (auto j = 0ul; j < a.size(); ++j) {
553 if (std::abs(a.ff(i, j) - b.ff(i, j)) > xff)
554 xff = std::abs(a.ff(i, j) - b.ff(i, j));
555 if (a.g_size() != 0) {
556 if (std::abs(a.fg(i, j) - b.fg(i, j)) > xfg)
557 xfg = std::abs(a.fg(i, j) - b.fg(i, j));
558 if (std::abs(a.gf(i, j) - b.gf(i, j)) > xgf)
559 xgf = std::abs(a.gf(i, j) - b.gf(i, j));
560 if (std::abs(a.gg(i, j) - b.gg(i, j)) > xgg)
561 xgg = std::abs(a.gg(i, j) - b.gg(i, j));
562 }
563 }
564 }
565 return std::max({xff, xfg, xgf, xgg});
566}
567
568//! returns maximum relative diference [aij-bij/(aij+bij)] (abs) between two
569//! matrices
570template <typename T>
571double max_epsilon(const SpinorMatrix<T> &a, const SpinorMatrix<T> &b) {
572 double xff = 0.0, xfg = 0.0, xgf = 0.0, xgg = 0.0;
573 for (auto i = 0ul; i < a.size(); ++i) {
574 for (auto j = 0ul; j < a.size(); ++j) {
575 const auto eps_ff =
576 std::abs((a.ff(i, j) - b.ff(i, j)) / (a.ff(i, j) + b.ff(i, j)));
577 if (eps_ff > xff)
578 xff = eps_ff;
579 if (a.g_size() != 0) {
580 const auto eps_fg =
581 std::abs((a.fg(i, j) - b.fg(i, j)) / (a.fg(i, j) + b.fg(i, j)));
582 const auto eps_gf =
583 std::abs((a.gf(i, j) - b.gf(i, j)) / (a.gf(i, j) + b.gf(i, j)));
584 const auto eps_gg =
585 std::abs((a.gg(i, j) - b.gg(i, j)) / (a.gg(i, j) + b.gg(i, j)));
586 if (eps_ff > xfg)
587 xfg = eps_fg;
588 if (eps_gf > xgf)
589 xgf = eps_gf;
590 if (eps_gg > xgg)
591 xgg = eps_gg;
592 }
593 }
594 }
595 return std::max({xff, xfg, xgf, xgg});
596}
597
598//==============================================================================
599using GMatrix = SpinorMatrix<double>;
600using ComplexGMatrix = SpinorMatrix<std::complex<double>>;
601using ComplexDouble = std::complex<double>;
602
603} // namespace MBPT
Stores radial Dirac spinor: F_nk = (f, g)
Definition DiracSpinor.hpp:41
const std::vector< double > & f() const
Upper (large) radial component function, f.
Definition DiracSpinor.hpp:125
const Grid & grid() const
Resturns a const reference to the radial grid.
Definition DiracSpinor.hpp:115
const std::vector< double > & g() const
Lower (small) radial component function, g.
Definition DiracSpinor.hpp:132
const std::vector< double > & r() const
Grid points, r.
Definition Grid.hpp:75
Matrix class; row-major.
Definition Matrix.hpp:35
Matrix< T > & invert_in_place()
Inverts the matrix, in place. Uses GSL; via LU decomposition. Only works for double/complex<double>.
Definition Matrix.ipp:77
auto complex() const
Converts a real to complex matrix (changes type; returns a complex matrix)
Definition Matrix.ipp:205
auto imag() const
Returns imag part of complex matrix (changes type; returns a real matrix)
Definition Matrix.ipp:194
Matrix< T > & zero()
Sets all elements to zero, in place.
Definition Matrix.ipp:154
Matrix< T > & mult_elements_by(const Matrix< T > &a)
Muplitplies all the elements by those of matrix a, in place: M_ij *= a_ij.
Definition Matrix.ipp:270
auto real() const
Returns real part of complex matrix (changes type; returns a real matrix)
Definition Matrix.ipp:183
void resize(std::size_t rows, std::size_t cols)
Resizes matrix to new dimension; all values reset to default.
Definition Matrix.hpp:92
Definition RadialMatrix.hpp:27
const LinAlg::Matrix< T > & Rmatrix() const
direct access to radial matrix
Definition RadialMatrix.hpp:69
Definition SpinorMatrix.hpp:43
void add(const DiracSpinor &ket, const DiracSpinor &bra, T k=T(1.0))
Adds k*|ket><bra| to matrix (used for building Green's functions)
Definition SpinorMatrix.hpp:437
SpinorMatrix< T > & operator-=(T aI)
Adition of identity: Matrix<T> -= T : T assumed to be *Identity!
Definition SpinorMatrix.hpp:214
friend SpinorMatrix< T > mult_elements(SpinorMatrix< T > lhs, const SpinorMatrix< T > &rhs)
Multiply elements (new matrix): Gij = Aij*Bij.
Definition SpinorMatrix.hpp:267
SpinorMatrix< std::complex< double > > complex() const
Converts a real to complex matrix (changes type; returns a complex matrix)
Definition SpinorMatrix.hpp:330
SpinorMatrix< T > & create_g()
Creates g parts of spinor matrix - will have value 0.
Definition SpinorMatrix.hpp:156
T & ff(std::size_t i, std::size_t j)
direct access to matrix elements
Definition SpinorMatrix.hpp:84
friend SpinorMatrix< T > operator+(SpinorMatrix< T > M, T aI)
Adition of identity: Matrix<T> + T : T assumed to be *Identity!
Definition SpinorMatrix.hpp:221
SpinorMatrix< T > drj() const
Multiplies by drj: Q_ij -> Q_ij*dr_j. Returns new matrix (orig unchanged)
Definition SpinorMatrix.hpp:413
SpinorMatrix< T > & drj_in_place()
Multiplies by drj: Q_ij -> Q_ij*dr_j, in place.
Definition SpinorMatrix.hpp:367
SpinorMatrix< T > & operator*=(const T x)
Scalar multiplication.
Definition SpinorMatrix.hpp:183
SpinorMatrix< T > & dri_in_place()
Multiplies by dri: Q_ij -> Q_ij*dr_i, in place.
Definition SpinorMatrix.hpp:390
friend SpinorMatrix< T > mult_elements(SpinorMatrix< T > lhs, const RadialMatrix< T > &rhs)
Multiply elements (new matrix): Gij = Aij*Bij.
Definition SpinorMatrix.hpp:286
const LinAlg::Matrix< T > & ff() const
direct access to matrix's
Definition SpinorMatrix.hpp:94
friend SpinorMatrix< T > operator*(const T x, SpinorMatrix< T > rhs)
Scalar multiplication.
Definition SpinorMatrix.hpp:202
SpinorMatrix< T > & operator-=(const SpinorMatrix< T > &rhs)
Matrix adition +,-.
Definition SpinorMatrix.hpp:175
SpinorMatrix< T > & operator+=(T aI)
Adition of identity: Matrix<T> += T : T assumed to be *Identity!
Definition SpinorMatrix.hpp:208
SpinorMatrix< double > imag() const
Returns imag part of complex matrix (changes type; returns a real matrix)
Definition SpinorMatrix.hpp:320
void zero()
Sets all matrix elements to zero.
Definition SpinorMatrix.hpp:137
SpinorMatrix< T > dri() const
Multiplies by dri: Q_ij -> Q_ij*dr_i. Returns new matrix (orig unchanged)
Definition SpinorMatrix.hpp:418
SpinorMatrix< T > & mult_elements_by(const SpinorMatrix< T > &rhs)
Multiply elements (in place): Gij -> Gij*Bij.
Definition SpinorMatrix.hpp:254
DiracSpinor operator*(const DiracSpinor &Fn) const
Action of SpinorMatrix operator on DiracSpinor. Inludes Integration: G*F = Int[G(r,...
Definition SpinorMatrix.hpp:467
SpinorMatrix< T > & drop_g()
Kills g parts of spinor matrix, in place!
Definition SpinorMatrix.hpp:146
SpinorMatrix< T > & operator+=(const SpinorMatrix< T > &rhs)
Matrix adition +,-.
Definition SpinorMatrix.hpp:167
SpinorMatrix< T > & invert_in_place()
Inversion (in place)
Definition SpinorMatrix.hpp:342
friend SpinorMatrix< T > mult_elements(const RadialMatrix< T > &rhs, SpinorMatrix< T > lhs)
Multiply elements (new matrix): Gij = Aij*Bij.
Definition SpinorMatrix.hpp:292
std::size_t index_to_fullgrid(std::size_t i) const
Converts an index on the sub-grid to the full grid.
Definition SpinorMatrix.hpp:431
friend SpinorMatrix< T > operator-(SpinorMatrix< T > M, T aI)
Adition of identity: Matrix<T> - T : T assumed to be *Identity!
Definition SpinorMatrix.hpp:225
double dr(std::size_t sub_index) const
returns dr at position along sub grid
Definition SpinorMatrix.hpp:424
friend SpinorMatrix< T > operator*(const SpinorMatrix< T > &a, const SpinorMatrix< T > &b)
Matrix multplication: Note: integration measure not automatically included: call ....
Definition SpinorMatrix.hpp:233
SpinorMatrix< double > real() const
Returns real part of complex matrix (changes type; returns a real matrix)
Definition SpinorMatrix.hpp:311
friend SpinorMatrix< T > operator+(SpinorMatrix< T > lhs, const SpinorMatrix< T > &rhs)
Matrix adition +,-.
Definition SpinorMatrix.hpp:192
SpinorMatrix< T > inverse() const
Returns inverse of matrix; original matrix unchanged.
Definition SpinorMatrix.hpp:360
SpinorMatrix< T > & mult_elements_by(const RadialMatrix< T > &rhs)
Multiply elements (in place): Gij -> Gij*Bij.
Definition SpinorMatrix.hpp:274
SpinorMatrix< T > conj() const
Returns conjugate of matrix.
Definition SpinorMatrix.hpp:301
friend SpinorMatrix< T > operator-(SpinorMatrix< T > lhs, const SpinorMatrix< T > &rhs)
Matrix adition +,-.
Definition SpinorMatrix.hpp:197
std::vector< double > interpolate(const std::vector< double > &x_in, const std::vector< double > &y_in, const std::vector< double > &x_out, Method method=Method::cspline)
Performs interpolation using GSL (GNU Scientific Library)
Definition Interpolator.hpp:162
Many-body perturbation theory.
Definition CI_Integrals.hpp:9
double max_element(const RadialMatrix< T > &a)
returns maximum element (by abs)
Definition RadialMatrix.hpp:287
bool equal(const RadialMatrix< T > &lhs, const RadialMatrix< T > &rhs)
Checks if two matrix's are equal (to within parts in 10^12)
Definition RadialMatrix.hpp:281
double max_delta(const RadialMatrix< T > &a, const RadialMatrix< T > &b)
returns maximum difference (abs) between two matrixs
Definition RadialMatrix.hpp:301
double max_epsilon(const RadialMatrix< T > &a, const RadialMatrix< T > &b)
returns maximum relative diference [aij-bij/(aij+bij)] (abs) between two matrices
Definition RadialMatrix.hpp:316