1#ifndef SPECTRALDENSITY_H
2#define SPECTRALDENSITY_H
32 int b =
pow(kr, p.power) * p.bins;
75 std::vector<double> k_avg;
76 std::vector<size_t> bin_count;
86 if (lattice.size(d) > 2 * par.bins)
87 par.bins = lattice.size(d) / 2;
89 par.binwidth = par.max / par.bins;
98 par.binwidth = par.max / par.bins;
106 par.binwidth = par.max / par.bins;
119 par.bins =
ceil(par.max / par.binwidth);
120 par.max = par.binwidth * par.bins;
129 k_binning &binwidth(
double w) {
132 par.bins =
ceil(par.max / w);
133 par.max = par.binwidth * par.bins;
134 par.bins_set =
false;
166 template <
typename T>
169 binning_timer.start();
171 if (k_avg.size() != par.bins)
180 int b = sd_get_k_bin(X.coordinates(), par);
181 if (b >= 0 && b < par.bins) {
186 binning_timer.stop();
193 template <
typename T>
196 using float_t = hila::arithmetic_type<T>;
197 constexpr int n_float =
sizeof(T) /
sizeof(float_t);
199 binning_timer.start();
201 if (k_avg.size() != par.bins)
210 int b = sd_get_k_bin(X.coordinates(), par);
211 if (b >= 0 && b < par.bins) {
213 for (
int i = 0; i < n_float; i++) {
221 binning_timer.stop();
231 template <typename T, std::enable_if_t<hila::contains_complex<T>::value,
int> = 0>
242 template <typename T, std::enable_if_t<!hila::contains_complex<T>::value,
int> = 0>
247 if constexpr (
sizeof(T) %
sizeof(
Complex<hila::arithmetic_type<T>>) == 0) {
251 constexpr int nc =
sizeof(T) /
sizeof(cmplx_t);
257 constexpr int nc =
sizeof(T) /
sizeof(cmplx_t) + 1;
264 for (
int i = 0; i <
sizeof(T) /
sizeof(hila::arithmetic_type<T>); i++) {
266 hila::set_number_in_var(cfield[X], i, a);
280 k_avg.resize(par.bins);
281 bin_count.resize(par.bins);
290 double kr = X.coordinates().convert_to_k().norm();
291 int b = sd_get_k_bin(X.coordinates(), par);
293 if (b >= 0 && b < par.bins) {
299 for (
int i = 0; i < par.bins; i++) {
300 bin_count[i] =
count[i];
301 k_avg[i] = s[i] /
count[i];
309 if (k_avg.size() == 0) {
313 if (i >= 0 && i < par.bins)
323 if (bin_count.size() == 0) {
327 if (i >= 0 && i < par.bins)
338 return pow(((
double)i) / par.bins, 1.0 / par.power) * par.max;
341 double bin_max(
int i) {
Array< n, m, T > ceil(Array< n, m, T > a)
Ceiling.
Array< n, m, T > pow(Array< n, m, T > a, int b)
Power.
Vector< 4, double > convert_to_k() const
Convert momentum space CoordinateVector to wave number k, where -pi/2 < k_i <= pi_2 Utility function ...
The field class implements the standard methods for accessing Fields. Hilapp replaces the parity acce...
ReductionVector & allreduce(bool b=true)
allreduce(bool) turns allreduce on or off. By default on.
std::vector< double > spectraldensity(const Field< T > &f)
void sd_calculate_bin_info()
k_binning & k_max(double km)
Max value of k.
k_binning & exact_bins(int e)
Bin exactly this many bins.
std::vector< T > bin_k_field(const Field< T > &f)
Generic k-space field binner routine - returns field element type vector.
double k(int i)
Get the average k-value of bin i.
k_binning & power(double p)
Bin quantity k^p.
k_binning & bins(int n)
Set number of bins in histogram.
long count(int i)
get the count of points within bin i
std::vector< double > bin_k_field_squarenorm(const Field< T > &f)
sum up the square norm of all elements
#define foralldir(d)
Macro to loop over (all) Direction(s)
constexpr Parity ALL
bit pattern: 011
void FFT_field(const Field< T > &input, Field< T > &result, const CoordinateVector &directions, fft_direction fftdir=fft_direction::forward)
Implement hila::swap for gauge fields.
hila::arithmetic_type< T > get_number_in_var(const T &var, int i)
sd_k_bin_parameters holds the parameters to define binning.