1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
static const int nx = 8;
static const int ny = 4;
static const int nz = 6;
int main(){
Eigen::Tensor<double, 3> uFun((nz+1),nx,ny);//tensor(row,col,matrix)
uFun.setZero();
for(int x = 0; x< nx; x++){
for(int y = 0; y< ny; y++){
for(int z = 0; z< nz+1; z++){
uFun(z,x,y) = //define function u same as MATLAB
}
}
}
//define matrix and copy the tensor into it
//map tensor to matrix
Eigen::MatrixXd dummy((nz+1),nx); //to match tensor slices
dummy.setZero();
Eigen::Tensor<double, 2> Tensor2D((nz+1),nx); //tensor(row,col,matrix)
Tensor2D.setZero();
Tensor2D = uFun.slice(std::array{0, 0, 3}, std::array{nz + 1, nx, 1}).reshape(std::array{nz + 1, nx}) ;
dummy = static_cast<MatrixType<double>>(Eigen::Map<const MatrixType<double>>(Tensor2D.data(), (nz+1), nx));
Eigen::MatrixXcd tempOut1((nz+1),nx);
//uh1= fft(u,[],1);
for (int k=0; k< dummy.cols(); k++){
tempOut1.col(k) = fft.fwd(dummy.col(k));
}
//uh2= fft(u,[],2);
Eigen::MatrixXcd tempOut((nz+1),nx);
Eigen::VectorXcd row(nx);
for (int k=0; k< (dummy.rows()); k++){
fft.fwd(row, dummy.row(k));
tempOut.row(k) = row;
}
}
|