7 #include "../math/pi.hpp" 8 #include "../math/kahan_sum.hpp" 16 namespace wavepackets {
17 using shapes::ShapeEnum;
18 using shapes::ShapeSlice;
40 template<dim_t D,
class MultiIndex,
int N>
95 const ShapeEnum<D,MultiIndex>* enumeration,
98 , parameters_(parameters)
99 , enumeration_(enumeration)
107 dx_ = x.colwise() - q.template cast<complex_t>();
109 Qh_Qinvt_ = Q.adjoint()*Qinv_.transpose();
110 Qinv_dx_ = Qinv_*
dx_;
115 for (
dim_t d = 0; d < D; d++)
116 limit = std::max(limit, enumeration_->limit(d) );
118 sqrt_.resize(limit+2);
120 for (
int i = 0; i <= limit+1; i++)
121 sqrt_[i] = std::sqrt(
real_t(i) );
137 CArray1N pr1 = ( dx_.array() * P_Qinv_dx.array() ).colwise().sum();
138 CArray1N pr2 = ( p.transpose()*
dx_ ).array();
140 CArray1N e =
complex_t(0.0, 1.0)/(eps_*
eps_) * (0.5*pr1 + pr2);
142 return e.exp() / std::pow(math::pi<real_t>()*eps_*eps_, D/4.0);
171 auto & prev_enum = enumeration_->slice(islice-1);
172 auto & curr_enum = enumeration_->slice(islice);
173 auto & next_enum = enumeration_->slice(islice+1);
175 assert ((
int)prev_enum.size() == prev_basis.rows());
176 assert ((
int)curr_enum.size() == curr_basis.rows());
187 for (std::size_t j = 0; j < next_enum.size(); j++) {
188 std::array<int,D> next_index = next_enum[j];
191 for (
dim_t d = 0; d < D; d++) {
192 if (next_index[d] != 0) {
202 std::array<int,D> curr_index = next_index;
203 curr_index[axis] -= 1;
204 std::size_t curr_ordinal = curr_enum.find(curr_index);
206 assert(curr_ordinal < curr_enum.size());
208 pr1 = curr_basis.row(curr_ordinal) * Qinv_dx_.row(axis).array() * std::sqrt(2.0)/
eps_ ;
212 std::array< std::size_t,D > prev_ordinals = prev_enum.find_backward_neighbours(curr_index);
216 for (
dim_t d = 0; d < D; d++) {
217 if (curr_index[d] != 0) {
218 pr2 += prev_basis.row(prev_ordinals[d]) *
Qh_Qinvt_(axis,d) * sqrt_[ curr_index[d] ];
224 next_basis.row(j) = (pr1 - pr2) / sqrt_[ 1+curr_index[axis] ];
249 complete_basis.block(0, 0, 1, npts_) = next_basis =
seed();
251 for (
int islice = 0; islice < enumeration_->n_slices(); islice++) {
252 prev_basis = std::move(curr_basis);
253 curr_basis = std::move(next_basis);
255 next_basis =
step(islice, prev_basis, curr_basis);
257 std::size_t offset = enumeration_->slice(islice+1).offset();
261 complete_basis.block(offset, 0, next_basis.rows(),
npts_) = next_basis;
264 return complete_basis;
291 psi += next_basis.row(0)*coefficients[0];
293 for (
int islice = 0; islice < enumeration_->n_slices(); islice++) {
294 prev_basis = std::move(curr_basis);
295 curr_basis = std::move(next_basis);
297 next_basis =
step(islice, prev_basis, curr_basis);
299 std::size_t offset = enumeration_->slice(islice+1).offset();
301 for (
long j = 0; j < next_basis.rows(); j++) {
307 psi += next_basis.row(j)*cj;
331 std::size_t n_components)
const 334 std::vector< math::KahanSum< CArray<1,N> > > psi(n_components);
342 for (std::size_t n = 0; n < n_components; n++) {
344 psi[n] += subset_coeffs[n][0]*next_basis.row(0).matrix();
347 for (
int islice = 0; islice < enumeration_->n_slices(); islice++) {
348 prev_basis = std::move(curr_basis);
349 curr_basis = std::move(next_basis);
351 next_basis =
step(islice, prev_basis, curr_basis);
353 ShapeSlice<D,MultiIndex>
const& superset_slice = enumeration_->slice(islice+1);
366 std::vector<std::size_t> seek(n_components);
367 for (
long j = 0; j < next_basis.rows(); j++) {
368 for (std::size_t n = 0; n < n_components; n++) {
369 ShapeSlice<D,MultiIndex>
const& subset_slice = subset_enums[n]->slice(islice+1);
371 if (seek[n] < subset_slice.size() && subset_slice[seek[n]] == superset_slice[j]) {
372 complex_t cj = subset_coeffs[n][subset_slice.offset() + seek[n]];
374 psi[n] += next_basis.row(j)*cj;
383 for (std::size_t n = 0; n < n_components; n++) {
384 result.row(n) = psi[n]();
405 std::vector< math::KahanSum< CArray<1,N> > > psi(n_components);
413 for (std::size_t n = 0; n < n_components; n++) {
415 psi[n] += coefficients[n][0]*next_basis.row(0);
418 for (
int islice = 0; islice < enumeration_->n_slices(); islice++) {
419 prev_basis = std::move(curr_basis);
420 curr_basis = std::move(next_basis);
422 next_basis =
step(islice, prev_basis, curr_basis);
424 ShapeSlice<D,MultiIndex>
const& slice = enumeration_->slice(islice+1);
427 for (
long j = 0; j < next_basis.rows(); j++) {
428 for (std::size_t n = 0; n < n_components; n++) {
429 complex_t cj = coefficients[n][slice.offset() + j];
431 psi[n] += next_basis.row(j)*cj;
437 for (std::size_t n = 0; n < n_components; n++) {
438 result.row(n) = psi[n]();
RMatrix< D, 1 > const & p() const
Get the parameter .
Definition: hawp_paramset.hpp:102
Definition: coefficients_file_parser.cpp:10
const HaWpParamSet< D > * parameters_
Definition: hawp_evaluator.hpp:51
function p(by, bw, bv)
Definition: jquery.js:23
Eigen::Matrix< complex_t, D, D > CMatrixDD
Definition: hawp_evaluator.hpp:44
Eigen::Matrix< real_t, R, C > RMatrix
Definition: types.hpp:22
real_t eps_
Definition: hawp_evaluator.hpp:50
Eigen::Matrix< complex_t, Eigen::Dynamic, 1 > Coefficients
Definition: types.hpp:33
const ShapeEnum< D, MultiIndex > * enumeration_
Definition: hawp_evaluator.hpp:52
CMatrix< D, D > const & Q() const
Get the parameter .
Definition: hawp_paramset.hpp:105
std::complex< real_t > complex_t
Definition: types.hpp:15
double real_t
Definition: types.hpp:14
HaWpBasisVector< N > all() const
Evaluates all basis functions.
Definition: hawp_evaluator.hpp:238
CArray< Eigen::Dynamic, N > vector_reduce(ShapeEnum< D, MultiIndex > **subset_enums, complex_t const **subset_coeffs, std::size_t n_components) const
Efficiently evaluates a vectorial wavepacket with shared Hagedorn parameter set, but different basis ...
Definition: hawp_evaluator.hpp:329
Evaluates a wavepacket slice by slice.
Definition: hawp_evaluator.hpp:41
HaWpEvaluator(real_t eps, const HaWpParamSet< D > *parameters, const ShapeEnum< D, MultiIndex > *enumeration, const CMatrixDN &x)
Definition: hawp_evaluator.hpp:93
The Kahan's algorithm achieves O(1) error growth for summing N numbers.
Definition: kahan_sum.hpp:18
int npts_
Definition: hawp_evaluator.hpp:57
This class represents the Hagedorn parameter set .
Definition: hawp_paramset.hpp:24
CMatrixDN dx_
Definition: hawp_evaluator.hpp:62
Eigen::Matrix< complex_t, D, N > CMatrixDN
Definition: hawp_evaluator.hpp:46
CArray< Eigen::Dynamic, N > HaWpBasisVector
Definition: types.hpp:31
CMatrixDD Qinv_
Definition: hawp_evaluator.hpp:67
CMatrixDN Qinv_dx_
Definition: hawp_evaluator.hpp:77
CMatrix< D, D > const & P() const
Get the parameter .
Definition: hawp_paramset.hpp:108
Eigen::Matrix< real_t, D, N > RMatrixDN
Definition: hawp_evaluator.hpp:47
RMatrix< D, 1 > const & q() const
Get the parameter .
Definition: hawp_paramset.hpp:99
CArray1N seed() const
Evaluates basis function on node (ground-state).
Definition: hawp_evaluator.hpp:130
std::vector< real_t > sqrt_
Definition: hawp_evaluator.hpp:82
Eigen::Matrix< complex_t, R, C > CMatrix
Definition: types.hpp:19
Eigen::Array< complex_t, 1, N > CArray1N
Definition: hawp_evaluator.hpp:45
CArray< Eigen::Dynamic, N > vector_reduce(complex_t const **coefficients, std::size_t n_components) const
Efficiently evaluates a vectorial wavepacket with shared Hagedorn parameter set and shared basis shap...
Definition: hawp_evaluator.hpp:402
CMatrixDD Qh_Qinvt_
Definition: hawp_evaluator.hpp:72
CArray< 1, N > reduce(const Coefficients &coefficients) const
Evaluates wavepacket in a memory efficient manner.
Definition: hawp_evaluator.hpp:280
int dim_t
Definition: types.hpp:16
HaWpBasisVector< N > step(std::size_t islice, const HaWpBasisVector< N > &prev_basis, const HaWpBasisVector< N > &curr_basis) const
Having basis function values on previous and current slice, this member function computes basis funct...
Definition: hawp_evaluator.hpp:167
Eigen::Array< complex_t, R, C > CArray
Definition: types.hpp:25