oILAB
Loading...
Searching...
No Matches
PeriodicFunction.h
Go to the documentation of this file.
1//
2// Created by Nikhil Chandra Admal on 7/4/23.
3//
4
5#ifndef OILAB_PERIODICFUNCTION_H
6#define OILAB_PERIODICFUNCTION_H
7
8#include "Eigen/Dense"
9#include "unsupported/Eigen/CXX11/Tensor"
10#include <iomanip>
11
12namespace gbLAB {
13
14 template<typename Scalar, int dim>
15 class LatticeFunction;
16
17 template<typename Derived, typename Scalar>
18 class Function;
19
20 template<typename Scalar, int dim>
22 public:
23 using dcomplex= std::complex<double>;
24 const Eigen::Matrix<double,Eigen::Dynamic,dim> unitCell;
25 Eigen::Tensor<Scalar,dim> values;
26
27 // Construct a zero periodic function
28 explicit PeriodicFunction(const Eigen::array<Eigen::Index,dim>& n,
29 const Eigen::Matrix<double,Eigen::Dynamic,dim>& _unitCell);
30
31 // generates a periodic function from a function centered at the center of a lattice
32 template<typename T, typename = T, typename=T, int dm=dim, typename = std::enable_if_t<dm==1>>
33 PeriodicFunction(const Eigen::array<Eigen::Index,dim>& n,
34 const Eigen::Matrix<double,Eigen::Dynamic,dim>& _unitCell,
35 const Function<T,Scalar>& fun);
36
37 template<typename T, typename = T, int dm=dim, typename = std::enable_if_t<dm==2>>
38 PeriodicFunction(const Eigen::array<Eigen::Index,dim>& n,
39 const Eigen::Matrix<double,Eigen::Dynamic,dim>& _unitCell,
40 const Function<T,Scalar>& fun);
41
42 template<typename T, int dm=dim, typename = std::enable_if_t<dm==3>>
43 PeriodicFunction(const Eigen::array<Eigen::Index,dim>& n,
44 const Eigen::Matrix<double,Eigen::Dynamic,dim>& _unitCell,
45 const Function<T,Scalar>& fun);
46
48
49 double dot(const PeriodicFunction<Scalar,dim>& other) const;
50
51 template <typename T>
53 };
54
55 template<typename Scalar, int dim, typename = std::enable_if_t<dim==2>>
56 std::basic_ostream<char>& operator<<(std::basic_ostream<char>& s, const PeriodicFunction<Scalar, dim>& fun)
57 {
58 auto n = fun.values.dimensions();
59 assert(n.size() == dim);
60 s << n[0]*n[1] << std::endl;
61 s << std::endl;
62 for (int i = 0; i < n[0]; i++) {
63 for (int j = 0; j < n[1]; j++) {
64 Eigen::Vector<double, Eigen::Dynamic> x = i * fun.unitCell.col(0) / n[0] +
65 j * fun.unitCell.col(1) / n[1];
66 const Eigen::IOFormat fmt(15, 0, " ", "", " ", "", "", "");
67 s << x.transpose().format(fmt) << std::setw(25) << std::setprecision(15) << fun.values(i, j)
68 << std::endl;
69 }
70 }
71 return s;
72 }
73
74 template<typename Scalar, int dim, typename T, typename = std::enable_if_t<dim==3>>
75 std::basic_ostream<char>& operator<<(std::basic_ostream<char>& s, const PeriodicFunction<Scalar, dim>& fun)
76 {
77 auto n = fun.values.dimensions();
78 assert(n.size() == dim);
79 s << n[0]*n[1]*n[2] << std::endl;
80 s << std::endl;
81 for (int i = 0; i < n[0]; i++) {
82 for (int j = 0; j < n[1]; j++) {
83 for (int k = 0; k < n[2]; k++) {
84 Eigen::Vector<double, Eigen::Dynamic> x = i * fun.unitCell.col(0) / n[0] +
85 j * fun.unitCell.col(1) / n[1] +
86 k * fun.unitCell.col(2) / n[2];
87 const Eigen::IOFormat fmt(15, 0, " ", " ", " ", "", "", "");
88 s << x.transpose().format(fmt) << std::setw(25) << std::setprecision(15) << fun.values(i,j,k)
89 << std::endl;
90 }
91 }
92 }
93 return s;
94 }
95
96}
98
99#endif //OILAB_PERIODICFUNCTION_H
PeriodicFunction< Scalar, dim > kernelConvolution(const Function< T, Scalar > &kernel)
LatticeFunction< dcomplex, dim > fft() const
Eigen::Tensor< Scalar, dim > values
const Eigen::Matrix< double, Eigen::Dynamic, dim > unitCell
double dot(const PeriodicFunction< Scalar, dim > &other) const
std::complex< double > dcomplex
basic_ostream< char > & operator<<(basic_ostream< char > &s, const LatticeDirection< dim > &m)