oILAB
Loading...
Searching...
No Matches
FunctionImplementation.h
Go to the documentation of this file.
1//
2// Created by Nikhil Chandra Admal on 5/30/24.
3//
4
5#ifndef OILAB_FUNCTIONIMPLEMENTATION_H
6#define OILAB_FUNCTIONIMPLEMENTATION_H
7
8#include <iostream>
9#include <numbers>
10
11namespace oILAB {
12template <typename Derived, typename Scalar>
14 : derivedFunction(static_cast<const Derived &>(*this)),
15 domainSize(_domainSize) {}
16
17template <typename Derived, typename Scalar>
19 const Eigen::Vector<double, Eigen::Dynamic> &vec) const {
20 return derivedFunction(vec);
21 }
22
23 /*
24 template<typename Derived, typename Scalar>
25 template<int dim>
26 LatticeFunction<typename Function<Derived,Scalar>::dcomplex,dim>
27 Function<Derived,Scalar>::fft(const std::array<Eigen::Index,dim>& n, const Eigen::Matrix<double,Eigen::Dynamic,dim>& basisVectors) const
28 {
29 // Initialize a zero periodic function and its fft
30 LatticeFunction<dcomplex,dim> pfhat(n,basisVectors);
31 PeriodicFunction<std::complex<double>,dim> pf_complex(pfhat.ifft());
32 PeriodicFunction<double,dim> pf(pf_complex.values.dimensions(),pf_complex.unitCell);
33 pf.values= pf_complex.values.real();
34
35 Eigen::Vector<double, Eigen::Dynamic> factor, inversePlaneDistances;
36 inversePlaneDistances = basisVectors.colwise().norm();
37 factor = (2.0 * domainSize * inversePlaneDistances).array().ceil();
38 //std::cout << "Scaling the lattice by factors = " << factor.transpose() << std::endl;
39 Eigen::Matrix<double, Eigen::Dynamic, dim> scaledUnitCell= pf.unitCell.array().rowwise() * factor.array().transpose();
40
41 Eigen::array<Eigen::Index, dim> nRefined = n;
42 for (int i = 0; i < dim; i++) {
43 nRefined[i] = factor(i) * n[i];
44 }
45
46 // pkf - periodic kernel function
47 PeriodicFunction<double,dim> pfRefined(nRefined, scaledUnitCell, *this);
48 LatticeFunction<dcomplex, dim> pfhatRefined(pfRefined.fft());
49
51 // LatticeFunction<dcomplex,dim> temp(nRefined, pfhatRefined.basisVectors);
52 // Eigen::Vector<double, Eigen::Dynamic> center = pfRefined.unitCell.rowwise().sum()/2;
53 // Exponential exp_function(center);
54 // LatticeFunction<dcomplex, dim> exp_factor(nRefined, pfhatRefined.basisVectors, exp_function);
55 // temp.values = exp_factor.values * pfhatRefined.values;
56 // pfhatRefined.values = temp.values;
57
58 Eigen::array<Eigen::DenseIndex, dim> strides;
59 strides.fill(1);
60 for (int i = 0; i < dim; i++)
61 strides[i] = factor(i);
62
63 pfhat.values = pfhatRefined.values.stride(strides);
64
65 return pfhat;
66
67 }
68 */
69
70 /* ******************************************** */
71
72 Exponential::Exponential(const Eigen::Vector<double,Eigen::Dynamic>& _x) : x(_x){}
73 std::complex<double> Exponential::operator()(const Eigen::Vector<double,Eigen::Dynamic>& vec) const
74 {
75 return exp(2*std::numbers::pi*std::complex<double>(0,1)*vec.dot(x));
76 }
77
78 /* ******************************************** */
79 template<typename T, typename Scalar>
80 Shift<T,Scalar>::Shift(const Eigen::Vector<double,Eigen::Dynamic>& t,
81 const Function<T,Scalar>& fun):
82 Function<Shift<T,Scalar>,Scalar>(fun.domainSize),
83 t(t),fun(fun)
84 {}
85 template<typename T, typename Scalar>
86 Scalar Shift<T,Scalar>::operator()(const Eigen::Vector<double,Eigen::Dynamic>& y) const
87 {
88 //return fun(y+t);
89 return fun(t-y);
90 }
91 } // namespace oILAB
92#endif
std::complex< double > operator()(const Eigen::Vector< double, Eigen::Dynamic > &vec) const
const Eigen::Vector< double, Eigen::Dynamic > & x
Definition Function.h:43
Exponential(const Eigen::Vector< double, Eigen::Dynamic > &_x)
Scalar operator()(const Eigen::Vector< double, Eigen::Dynamic > &vec) const
Function(double _domainSize=std::numeric_limits< double >::infinity())
Scalar operator()(const Eigen::Vector< double, Eigen::Dynamic > &y) const
Shift(const Eigen::Vector< double, Eigen::Dynamic > &t, const Function< T, Scalar > &fun)