10#include <unsupported/Eigen/CXX11/Tensor>
22 const Eigen::array<Eigen::Index,dim>
d;
24 explicit Diff(
const Eigen::array<Eigen::Index,dim>& d_,
25 const Eigen::Matrix<double,dim,dim>& A,
26 const Eigen::array<Eigen::Index,dim>& n_) :
30 for(
const auto& order :
d)
36 typename std::enable_if<dm==1,void>::type
39 Eigen::TensorMap<const Eigen::Tensor<double,dm>> xReal(x_in,
n);
40 const Eigen::Tensor<dcomplex,dm> x=xReal.template cast<dcomplex>();
41 Eigen::TensorMap<Eigen::Tensor<double,dm>> y(y_out,
n);
45 for(
const auto& order :
d)
47 totalOrder= totalOrder + order;
49 if (totalOrder == 0) {
55 Eigen::Tensor<dcomplex,dm> xhat(
n);
59 Eigen::Tensor<dcomplex,dm> d2fhat(
n);
63 for (
int i = 0; i <
n[0]; ++i) {
66 for (
int k= 0; k<dim; ++k) {
67 if (
d[k] == 0)
continue;
68 else if (
d[k] % 2 == 0)
69 r << (i <=
n[0] / 2 ? i : i -
n[0]);
71 r << (i ==
n[0] / 2 ? 0 : -
n[0] * (i / (
n[0] / 2)) + i);
72 factor = factor * std::pow(-2.0 * std::numbers::pi *
77 d2fhat(i)= xhat(i) * factor;
81 Eigen::Tensor<dcomplex,dm> Lf(
n);
88 typename std::enable_if<dm==2,void>::type
91 Eigen::TensorMap<const Eigen::Tensor<double,2>> xReal(x_in,
n);
92 const Eigen::Tensor<dcomplex,2> x=xReal.cast<
dcomplex>();
93 Eigen::TensorMap<Eigen::Tensor<double,2>> y(y_out,
n);
97 for(
const auto& order :
d)
99 totalOrder= totalOrder + order;
101 if (totalOrder == 0) {
107 Eigen::Tensor<dcomplex,2> xhat(
n);
111 Eigen::Tensor<dcomplex,2> d2fhat(
n);
115 for (
int i = 0; i <
n[0]; ++i) {
116 for (
int j = 0; j <
n[1]; ++j) {
119 for (
int k= 0; k<dim; ++k) {
120 if (
d[k] == 0)
continue;
121 else if (
d[k] % 2 == 0)
122 r << (i <=
n[0] / 2 ? i : i -
n[0]),
123 (j <=
n[1] / 2 ? j : j -
n[1]);
125 r << (i ==
n[0] / 2 ? 0 : -
n[0] * (i / (
n[0] / 2)) + i),
126 (j ==
n[1] / 2 ? 0 : -
n[1] * (j / (
n[1] / 2)) + j);
127 factor = factor * std::pow(-2.0 * std::numbers::pi *
132 d2fhat(i,j)= xhat(i,j) * factor;
137 Eigen::Tensor<dcomplex,2> Lf(
n);
144 typename std::enable_if<dm==3,void>::type
147 Eigen::TensorMap<const Eigen::Tensor<double,dm>> xReal(x_in,
n);
148 const Eigen::Tensor<dcomplex,dm> x=xReal.template cast<dcomplex>();
149 Eigen::TensorMap<Eigen::Tensor<double,dm>> y(y_out,
n);
153 for(
const auto& order :
d)
155 totalOrder= totalOrder + order;
157 if (totalOrder == 0) {
163 Eigen::Tensor<dcomplex,dm> xhat(
n);
167 Eigen::Tensor<dcomplex,dm> d2fhat(
n);
171 for (
int i = 0; i <
n[0]; ++i) {
172 for (
int j = 0; j <
n[1]; ++j) {
173 for (
int k = 0; k <
n[2]; ++k) {
176 for (
int l = 0; l < dm; ++l) {
177 if (
d[l] == 0)
continue;
178 else if (
d[l] % 2 == 0)
179 r << (i <=
n[0] / 2 ? i : i -
n[0]),
180 (j <=
n[1] / 2 ? j : j -
n[1]),
181 (k <=
n[2] / 2 ? k : k -
n[2]);
183 r << (i ==
n[0] / 2 ? 0 : -
n[0] * (i / (
n[0] / 2)) + i),
184 (j ==
n[1] / 2 ? 0 : -
n[1] * (j / (
n[1] / 2)) + j),
185 (k ==
n[2] / 2 ? 0 : -
n[2] * (k / (
n[2] / 2)) + k);
186 factor = factor * std::pow(-2.0 * std::numbers::pi *
191 d2fhat(i,j,k) = xhat(i,j,k) * factor;
197 Eigen::Tensor<dcomplex,dm> Lf(
n);
static void ifft(const Eigen::Tensor< dcomplex, 3 > &in, Eigen::Tensor< dcomplex, 3 > &out)
static void fft(const Eigen::Tensor< dcomplex, 3 > &in, Eigen::Tensor< dcomplex, 3 > &out)
std::enable_if< dm==1, void >::type perform_op(const double *x_in, double *y_out) const
std::enable_if< dm==2, void >::type perform_op(const double *x_in, double *y_out) const
const Eigen::array< Eigen::Index, dim > d
std::complex< double > dcomplex
Diff(const Eigen::array< Eigen::Index, dim > &d_, const Eigen::Matrix< double, dim, dim > &A, const Eigen::array< Eigen::Index, dim > &n_)
std::enable_if< dm==3, void >::type perform_op(const double *x_in, double *y_out) const
const Eigen::array< Eigen::Index, dim > n
VectorDimD cartesian() const