WaveBlocksND
hawp_gradient_evaluator.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <array>
4 
5 #include <Eigen/Core>
6 
7 #include "hawp_paramset.hpp"
8 #include "shapes/shape_enum.hpp"
9 
10 
11 namespace waveblocks {
12  namespace wavepackets {
21  template<dim_t D, class MultiIndex>
23  {
24  public:
34  const HaWpParamSet<D>* parameters,
35  const ShapeEnum<D,MultiIndex>* base_enum,
36  const ShapeEnum<D,MultiIndex>* grad_enum)
37  : eps_(eps)
38  , parameters_(parameters)
39  , base_enum_(base_enum)
40  , grad_enum_(grad_enum)
41  { }
42 
52  std::array<Coefficients, std::size_t(D) > apply(const Coefficients& base_coeffs) const
53  {
54  RMatrix<D,1> const& p = parameters_->p();
55  CMatrix<D,D> const& P = parameters_->P();
56 
57  Eigen::Matrix<complex_t,D,D> Pbar = P.conjugate();
58 
59  std::array<Coefficients, std::size_t(D) > grad_coeffs;
60  for (dim_t d = 0; d < D; d++) {
61  grad_coeffs[d] = Coefficients(grad_enum_->n_entries());
62  }
63 
64  //iterate over each slice [i = index of current slice]
65  for (int i = 0; i < grad_enum_->n_slices(); i++) {
66  //loop over all multi-indices within current slice [j = position of multi-index within current slice]
67  #pragma omp parallel for
68  for (std::size_t j = 0; j < grad_enum_->slice(i).size(); j++) {
69  MultiIndex curr_index = grad_enum_->slice(i)[j];
70 
71  //central node
72  complex_t cc(0,0);
73  std::size_t curr_ordinal = 0;
74  bool central_node_exists = false;
75 
76  if ( (central_node_exists = base_enum_->slice(i).try_find(curr_index, curr_ordinal)) ) {
77 
78  curr_ordinal += base_enum_->slice(i).offset();
79 
80  cc = base_coeffs[curr_ordinal];
81  }
82 
83  //backward neighbours
84  Eigen::Matrix<complex_t,D,1> cb;
85  for (dim_t d = 0; d < D; d++) {
86  if (curr_index[d] != 0) {
87  MultiIndex prev_index = curr_index; prev_index[d] -= 1;
88 
89  std::size_t prev_ordinal = 0;
90 
91  if (base_enum_->slice(i-1).try_find(prev_index, prev_ordinal)) {
92 
93  prev_ordinal += base_enum_->slice(i-1).offset();
94 
95  cb[d] = base_coeffs[prev_ordinal] * std::sqrt(real_t(curr_index[d]));
96  }
97  }
98  }
99 
100  //forward neighbours
101  Eigen::Matrix<complex_t,D,1> cf;
102  if (central_node_exists && i+1 < base_enum_->n_slices()) {
103  for (dim_t d = 0; d < D; d++) {
104  MultiIndex next_index = curr_index; next_index[d] += 1;
105 
106  std::size_t next_ordinal = 0;
107 
108  if (base_enum_->slice(i+1).try_find(next_index, next_ordinal)) {
109 
110  next_ordinal += base_enum_->slice(i+1).offset();
111 
112  cf[d] = base_coeffs[next_ordinal] * std::sqrt(real_t(curr_index[d]+1));
113  }
114  }
115  }
116 
117  Eigen::Matrix<complex_t,D,1> Pcc = p*cc;
118  Eigen::Matrix<complex_t,D,1> Pcf = Pbar*cf;
119  Eigen::Matrix<complex_t,D,1> Pcb = P*cb;
120 
121  Eigen::Matrix<complex_t,D,1> bgrad = (Pcf + Pcb)*eps_/std::sqrt(real_t(2)) + Pcc;
122 
123  for (dim_t d = 0; d < D; d++) {
124  grad_coeffs[d][grad_enum_->slice(i).offset() + j] = bgrad(d,0);
125  }
126  }
127  }
128 
129  return grad_coeffs;
130  }
131 
132  private:
134 
136 
140  const ShapeEnum<D,MultiIndex>* base_enum_;
141 
145  const ShapeEnum<D,MultiIndex>* grad_enum_;
146  };
147  }
148 }
Definition: coefficients_file_parser.cpp:10
function p(by, bw, bv)
Definition: jquery.js:23
real_t eps_
Definition: hawp_gradient_evaluator.hpp:133
Eigen::Matrix< real_t, R, C > RMatrix
Definition: types.hpp:22
Eigen::Matrix< complex_t, Eigen::Dynamic, 1 > Coefficients
Definition: types.hpp:33
std::complex< real_t > complex_t
Definition: types.hpp:15
double real_t
Definition: types.hpp:14
HaWpGradientEvaluator(real_t eps, const HaWpParamSet< D > *parameters, const ShapeEnum< D, MultiIndex > *base_enum, const ShapeEnum< D, MultiIndex > *grad_enum)
Initialisation.
Definition: hawp_gradient_evaluator.hpp:33
std::array< Coefficients, std::size_t(D) > apply(const Coefficients &base_coeffs) const
Computes the coefficients of the gradient wavepacket.
Definition: hawp_gradient_evaluator.hpp:52
This class represents the Hagedorn parameter set .
Definition: hawp_paramset.hpp:24
const ShapeEnum< D, MultiIndex > * base_enum_
enumeration of basic shape
Definition: hawp_gradient_evaluator.hpp:140
const HaWpParamSet< D > * parameters_
Definition: hawp_gradient_evaluator.hpp:135
Eigen::Matrix< complex_t, R, C > CMatrix
Definition: types.hpp:19
const ShapeEnum< D, MultiIndex > * grad_enum_
enumeration of extended shape
Definition: hawp_gradient_evaluator.hpp:145
int dim_t
Definition: types.hpp:16
This class constructs the coefficients of the Hagedorn gradient wavepacket applied to an arbitrary s...
Definition: hawp_gradient_evaluator.hpp:22