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