WaveBlocksND
inhomogeneous_inner_product.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <cmath>
4 #include <functional>
5 #include <iostream>
6 #include <tuple>
7 #include <vector>
8 
9 #include <Eigen/Core>
10 #include <Eigen/Dense>
11 #include <unsupported/Eigen/MatrixFunctions>
12 
13 #include "../types.hpp"
14 #include "../wavepackets/hawp_commons.hpp"
15 
16 
17 namespace waveblocks {
18  namespace innerproducts {
19  using wavepackets::AbstractScalarHaWp;
20 
29  template<dim_t D, class MultiIndex, class QR>
31  {
32  public:
41  using CDiagonalXX = Eigen::DiagonalMatrix<complex_t, Eigen::Dynamic>;
42  using NodeMatrix = typename QR::NodeMatrix;
43  using WeightVector = typename QR::WeightVector;
44  using op_t = std::function<CMatrix1X(CMatrixDX,RMatrixD1)>;
45 
60  static CMatrixXX build_matrix(const AbstractScalarHaWp<D, MultiIndex>& pacbra,
61  const AbstractScalarHaWp<D, MultiIndex>& packet,
62  const op_t& op=default_op) {
63  const dim_t n_nodes = QR::number_nodes();
64  const complex_t S_bra = pacbra.parameters().S();
65  const complex_t S_ket = packet.parameters().S();
66  NodeMatrix nodes;
67  WeightVector weights;
68  std::tie(nodes, weights) = QR::nodes_and_weights();
69 
70  // Mix parameters and compute affine transformation
71  std::pair<RMatrixD1, RMatrixDD> PImix = pacbra.parameters().mix(packet.parameters());
72  const RMatrixD1& q0 = std::get<0>(PImix);
73  const RMatrixDD& Qs = std::get<1>(PImix);
74 
75  // Transform nodes
76  const CMatrixDX transformed_nodes = q0.template cast<complex_t>().replicate(1, n_nodes) + packet.eps() * (Qs.template cast<complex_t>() * nodes);
77 
78  // Apply operator
79  const CMatrix1X values = op(transformed_nodes, q0);
80 
81  // Prefactor
82  const CMatrix1X factor =
83  std::conj(pacbra.prefactor()) * packet.prefactor() * Qs.determinant() *
84  std::pow(packet.eps(), D) * weights.array() * values.array();
85 
86  // Evaluate basis
87  const CMatrixXX basisr = pacbra.evaluate_basis(transformed_nodes);
88  const CMatrixXX basisc = packet.evaluate_basis(transformed_nodes);
89 
90  // Build matrix
91  const CDiagonalXX Dfactor(factor);
92  const CMatrixXX result = basisr.matrix().conjugate() * Dfactor * basisc.matrix().transpose();
93 
94  // Global phase
95  const complex_t phase = std::exp(complex_t(0,1) * (S_ket - std::conj(S_bra)) / std::pow(packet.eps(),2));
96  return phase * result;
97  }
98 
105  static complex_t quadrature(const AbstractScalarHaWp<D, MultiIndex>& pacbra,
106  const AbstractScalarHaWp<D, MultiIndex>& packet,
107  const op_t& op=default_op) {
108  const auto M = build_matrix(pacbra, packet, op);
109  // Quadrature with wavepacket coefficients, c^H M c.
110  return pacbra.coefficients().adjoint() * M * packet.coefficients();
111  }
112 
113  private:
114  static CMatrix1X default_op(const CMatrixDX& nodes, const RMatrixD1& pos)
115  {
116  (void)pos;
117  return CMatrix1X::Ones(1, nodes.cols());
118  }
119  };
120  }
121 }
Definition: coefficients_file_parser.cpp:10
Eigen::DiagonalMatrix< complex_t, Eigen::Dynamic > CDiagonalXX
Definition: inhomogeneous_inner_product.hpp:41
RMatrix< D, D > RMatrixDD
Definition: inhomogeneous_inner_product.hpp:39
Eigen::Matrix< real_t, R, C > RMatrix
Definition: types.hpp:22
std::complex< real_t > complex_t
Definition: types.hpp:15
CMatrix< Eigen::Dynamic, Eigen::Dynamic > CMatrixXX
Definition: inhomogeneous_inner_product.hpp:33
typename QR::NodeMatrix NodeMatrix
Definition: inhomogeneous_inner_product.hpp:42
static CMatrixXX build_matrix(const AbstractScalarHaWp< D, MultiIndex > &pacbra, const AbstractScalarHaWp< D, MultiIndex > &packet, const op_t &op=default_op)
Calculate the matrix of the inner product.
Definition: inhomogeneous_inner_product.hpp:60
CMatrix< D, 1 > CMatrixD1
Definition: inhomogeneous_inner_product.hpp:36
CMatrix< 1, Eigen::Dynamic > CMatrix1X
Definition: inhomogeneous_inner_product.hpp:34
Class providing inhomogeneous inner product calculation of scalar wavepackets.
Definition: inhomogeneous_inner_product.hpp:30
CMatrix< D, D > CMatrixDD
Definition: inhomogeneous_inner_product.hpp:37
std::function< CMatrix1X(CMatrixDX, RMatrixD1)> op_t
Definition: inhomogeneous_inner_product.hpp:44
CMatrix< Eigen::Dynamic, 1 > CMatrixX1
Definition: inhomogeneous_inner_product.hpp:35
static CMatrix1X default_op(const CMatrixDX &nodes, const RMatrixD1 &pos)
Definition: inhomogeneous_inner_product.hpp:114
RMatrix< D, 1 > RMatrixD1
Definition: inhomogeneous_inner_product.hpp:40
Eigen::Matrix< complex_t, R, C > CMatrix
Definition: types.hpp:19
CMatrix< D, Eigen::Dynamic > CMatrixDX
Definition: inhomogeneous_inner_product.hpp:38
typename QR::WeightVector WeightVector
Definition: inhomogeneous_inner_product.hpp:43
int dim_t
Definition: types.hpp:16
static complex_t quadrature(const AbstractScalarHaWp< D, MultiIndex > &pacbra, const AbstractScalarHaWp< D, MultiIndex > &packet, const op_t &op=default_op)
Perform quadrature.
Definition: inhomogeneous_inner_product.hpp:105