ALPSCore reference
grid.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1998-2018 ALPS Collaboration. See COPYRIGHT.TXT
3  * All rights reserved. Use is subject to license terms. See LICENSE.TXT
4  * For use in publications, see ACKNOWLEDGE.TXT
5  */
6 
7 #ifndef ALPSCORE_GRID_HPP
8 #define ALPSCORE_GRID_HPP
9 
10 #include <complex>
11 #include <cmath>
12 #include <vector>
13 
14 namespace alps {
15  namespace gf {
17  namespace grid{
18 
21  private:
23  double emin_;
25  double emax_;
27  int n_;
28  public:
29  linear_real_frequency_grid(double emin, double emax, int n) : emin_(emin), emax_(emax), n_(n){};
30  void compute_points(std::vector<double> &points) const {
31  points.resize(n_);
32  double step = (emax_ - emin_)/double(n_-1);
33  for(int i = 0; i<n_; i++) {
34  points[i] = emin_ + step*i;
35  }
36  }
37  };
38 
41  private:
43  double t_min_;
45  double t_max_;
47  double c_;
49  int nfreq_;
50  public:
51  logarithmic_real_frequency_grid(double tmin, double tmax, double c, int n): t_min_(tmin), t_max_(tmax), c_(c), nfreq_(n) {
52  if (tmin <= 0.0)
53  throw std::invalid_argument("the parameter tmin must be greater than 0");
54  if (tmax<tmin)
55  throw std::invalid_argument("the parameter tmax must be greater than tmin");
56  };
57  logarithmic_real_frequency_grid(double tmin, double tmax, int n): t_min_(tmin), t_max_(tmax), c_(0), nfreq_(n) {
58  if (tmin <= 0.0)
59  throw std::invalid_argument("the parameter tmin must be greater than 0");
60  if (tmax<tmin)
61  throw std::invalid_argument("the parameter tmax must be greater than tmin");
62  };
63  void compute_points(std::vector<double> &points) const {
64  points.resize(nfreq_);
65  double scale = std::log(t_max_ / t_min_) / ((float) ((nfreq_ / 2 - 1)));
66  points[nfreq_ / 2] = c_;
67  for (int i = 0; i < nfreq_ / 2; ++i) {
68  // check boundaries for an even # of frequencies
69  if(i<nfreq_/2 - 1)
70  points[nfreq_ / 2 + i + 1] = c_ + t_min_ * std::exp(((float) (i)) * scale);
71  points[nfreq_ / 2 - i - 1] = c_ - t_min_ * std::exp(((float) (i)) * scale);
72  }
73  // if we have an odd # of frequencies, this catches the last element
74  if (nfreq_ % 2 != 0)
75  points[nfreq_ / 2 + nfreq_ / 2] = c_ + t_min_ * std::exp(((float) (nfreq_/2 - 1)) * scale);
76  }
77  };
78 
81  private:
83  int nfreq_;
84  double spread_;
85  public:
86  quadratic_real_frequency_grid(double spread, int n): nfreq_(n) {
87  if (spread < 1)
88  throw std::invalid_argument("the parameter spread must be greater than 1");
89  spread_ = spread;
90  }
91  void compute_points(std::vector<double> & points) const {
92  points.resize(nfreq_);
93  std::vector<double> temp(nfreq_);
94  double t = 0;
95  for (int i = 0; i < nfreq_; ++i) {
96  double a = double(i) / (nfreq_ - 1);
97  double factor = 4 * (spread_ - 1) * (a * a - a) + spread_;
98  factor /= double(nfreq_ - 1) / (3. * (nfreq_ - 2))
99  * ((nfreq_ - 1) * (2 + spread_) - 4 + spread_);
100  double delta_t = factor;
101  t += delta_t;
102  temp[i] = t;
103  }
104  points[nfreq_/2] = 0.;
105  for (int i = 1; i <= nfreq_/2; ++i) {
106  if(i<nfreq_/2)
107  points[i + nfreq_ / 2] = temp[i - 1] / temp[nfreq_ / 2 - 1];
108  points[nfreq_ / 2 - i] = -temp[i - 1] / temp[nfreq_ / 2 - 1];
109  }
110  //if we have an odd # of frequencies, this catches the last element
111  if (nfreq_ % 2 != 0)
112  points[nfreq_ / 2 + nfreq_ / 2] = temp[nfreq_/2 - 1] / temp[nfreq_ / 2 - 1];
113  }
114  };
115  }
116  }
117 }
118 
119 #endif //ALPSCORE_GRID_HPP
void compute_points(std::vector< double > &points) const
Definition: grid.hpp:91
boost::array< T, N > log(boost::array< T, N > arg)
quadratic_real_frequency_grid(double spread, int n)
Definition: grid.hpp:86
Linear grid in real frequency.
Definition: grid.hpp:20
Logarithmic grid in real frequency.
Definition: grid.hpp:40
boost::array< T, N > exp(boost::array< T, N > arg)
Quadratic grid in real frequency.
Definition: grid.hpp:80
linear_real_frequency_grid(double emin, double emax, int n)
Definition: grid.hpp:29
void compute_points(std::vector< double > &points) const
Definition: grid.hpp:30
logarithmic_real_frequency_grid(double tmin, double tmax, double c, int n)
Definition: grid.hpp:51
void compute_points(std::vector< double > &points) const
Definition: grid.hpp:63
logarithmic_real_frequency_grid(double tmin, double tmax, int n)
Definition: grid.hpp:57