Grid 0.7.0
PowerSpectrum.h
Go to the documentation of this file.
1#pragma once
2namespace Grid {
3
4class Band
5{
7public:
8 Band(RealD _lo,RealD _hi)
9 {
10 lo=_lo;
11 hi=_hi;
12 }
14 if ( x>lo && x<hi ){
15 return 1.0;
16 } else {
17 return 0.0;
18 }
19 }
20};
21
23{
24 public:
25
26 template<typename T> static RealD normalise(T& v)
27 {
28 RealD nn = norm2(v);
29 nn = sqrt(nn);
30 v = v * (1.0/nn);
31 return nn;
32 }
33
34 std::vector<RealD> ranges;
35 std::vector<int> order;
36
37 PowerSpectrum( std::vector<RealD> &bins, std::vector<int> &_order ) : ranges(bins), order(_order) { };
38
39 template<class Field>
40 RealD operator()(LinearOperatorBase<Field> &HermOp, const Field &src)
41 {
42 GridBase *grid = src.Grid();
43 int N=ranges.size();
44 RealD hi = ranges[N-1];
45
46 RealD lo_band = 0.0;
47 RealD hi_band;
48 RealD nn=norm2(src);
49 RealD ss=0.0;
50
51 Field tmp = src;
52
53 for(int b=0;b<N;b++){
54 hi_band = ranges[b];
55 Band Notch(lo_band,hi_band);
56
57 Chebyshev<Field> polynomial;
58 polynomial.Init(0.0,hi,order[b],Notch);
59 polynomial.JacksonSmooth();
60
61 polynomial(HermOp,src,tmp) ;
62
63 RealD p=norm2(tmp);
64 ss=ss+p;
65 std::cout << GridLogMessage << " PowerSpectrum Band["<<lo_band<<","<<hi_band<<"] power "<<norm2(tmp)/nn<<std::endl;
66
67 lo_band=hi_band;
68 }
69 std::cout << GridLogMessage << " PowerSpectrum total power "<<ss/nn<<std::endl;
70 std::cout << GridLogMessage << " PowerSpectrum total power (unnormalised) "<<nn<<std::endl;
71
72 return 0;
73 };
74};
75
76}
accelerator_inline Grid_simd< S, V > sqrt(const Grid_simd< S, V > &r)
RealD norm2(const Lattice< vobj > &arg)
GridLogger GridLogMessage(1, "Message", GridLogColours, "NORMAL")
double RealD
Definition Simd.h:61
void JacksonSmooth(void)
Definition Chebyshev.h:156
void Init(RealD _lo, RealD _hi, int _order)
Definition Chebyshev.h:86
RealD operator()(RealD x)
Band(RealD _lo, RealD _hi)
std::vector< int > order
std::vector< RealD > ranges
PowerSpectrum(std::vector< RealD > &bins, std::vector< int > &_order)
static RealD normalise(T &v)
RealD operator()(LinearOperatorBase< Field > &HermOp, const Field &src)