Triumvirate C++ API 0.5.0
Three-point clustering measurements in large-scale structure analyses.
Loading...
Searching...
No Matches
field.hpp
Go to the documentation of this file.
1// Copyright (C) [GPLv3 Licence]
2//
3// This file is part of the Triumvirate program. See the COPYRIGHT
4// and LICENCE files at the top-level directory of this distribution
5// for details of copyright and licensing.
6//
7// This program is free software: you can redistribute it and/or modify it
8// under the terms of the GNU General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15// See the GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program. If not, see <https://www.gnu.org/licenses/>.
19
37#ifndef TRIUMVIRATE_INCLUDE_FIELD_HPP_INCLUDED_
38#define TRIUMVIRATE_INCLUDE_FIELD_HPP_INCLUDED_
39
40#include <fftw3.h>
41
42#include <chrono>
43#include <cmath>
44#include <complex>
45#include <functional>
46#include <vector>
47
48#include "arrayops.hpp"
49#include "monitor.hpp"
50#include "parameters.hpp"
51#include "maths.hpp"
52#include "dataobjs.hpp"
53#include "io.hpp"
54#include "particles.hpp"
55
56namespace trvm = trv::maths;
57
58namespace trv {
59
60// ***********************************************************************
61// Mesh field
62// ***********************************************************************
63
68class MeshField {
69 public:
71 std::string name;
72 fftw_complex* field;
73 double dr[3];
74 double dk[3];
75 double vol;
76 double vol_cell;
77
78 // ---------------------------------------------------------------------
79 // Life cycle
80 // ---------------------------------------------------------------------
81
90 explicit MeshField(
92 bool plan_ini = true,
93 const std::string& name = "mesh-field"
94 );
95
107 explicit MeshField(
109 fftw_plan& transform, fftw_plan& inv_transform,
110 const std::string& name = "mesh-field"
111 );
112
116 ~MeshField();
117
124 void reset_density_field();
125
126 // ---------------------------------------------------------------------
127 // Operators & reserved methods
128 // ---------------------------------------------------------------------
129
136 const fftw_complex& operator[](long long gid);
137
138 // ---------------------------------------------------------------------
139 // Mesh assignment
140 // ---------------------------------------------------------------------
141
149 ParticleCatalogue& particles, fftw_complex* weights
150 );
151
152 // ---------------------------------------------------------------------
153 // Field computations
154 // ---------------------------------------------------------------------
155
167
185 ParticleCatalogue& particles
186 );
187
221 ParticleCatalogue& particles_data, ParticleCatalogue& particles_rand,
222 LineOfSight* los_data, LineOfSight* los_rand,
223 double alpha, int ell, int m
224 );
225
239 ParticleCatalogue& particles, LineOfSight* los,
240 double alpha, int ell, int m
241 );
242
275 ParticleCatalogue& particles_data, ParticleCatalogue& particles_rand,
276 LineOfSight* los_data, LineOfSight* los_rand,
277 double alpha, int ell, int m
278 );
279
293 ParticleCatalogue& particles, LineOfSight* los,
294 double alpha, int ell, int m
295 );
296
297 // ---------------------------------------------------------------------
298 // Field transforms
299 // ---------------------------------------------------------------------
300
309 void fourier_transform();
310
315
316 // ---------------------------------------------------------------------
317 // Field operations
318 // ---------------------------------------------------------------------
319
327
333
334 // ---------------------------------------------------------------------
335 // One-point statistics
336 // ---------------------------------------------------------------------
337
362 MeshField& field_fourier, std::vector< std::complex<double> >& ylm,
363 double k_band, double dk_band,
364 double& k_eff, int& nmodes
365 );
366
388 MeshField& field_fourier,
389 std::vector< std::complex<double> >& ylm,
391 double r
392 );
393
394 // ---------------------------------------------------------------------
395 // Misc
396 // ---------------------------------------------------------------------
397
409 double calc_grid_based_powlaw_norm(ParticleCatalogue& particles, int order);
410
411 private:
413 std::vector<double> window;
415 int window_assign_order = -1;
416
418 fftw_complex* field_s = nullptr;
419
421 fftw_plan transform;
423 fftw_plan transform_s;
425 fftw_plan inv_transform;
426
427 bool plan_ini = false;
428 bool plan_ext = false;
429
430 friend class FieldStats;
431
432 // ---------------------------------------------------------------------
433 // Mesh grid properties
434 // ---------------------------------------------------------------------
435
442 long long ret_grid_index(int i, int j, int k);
443
449 void shift_grid_indices_fourier(int& i, int& j, int& k);
450
457 void get_grid_pos_vector(int i, int j, int k, double rvec[3]);
458
465 void get_grid_wavevector(int i, int j, int k, double kvec[3]);
466
467 // ---------------------------------------------------------------------
468 // Mesh assignment
469 // ---------------------------------------------------------------------
470
478 void assign_weighted_field_to_mesh_ngp(
479 ParticleCatalogue& particles, fftw_complex* weight
480 );
481
489 void assign_weighted_field_to_mesh_cic(
490 ParticleCatalogue& particles, fftw_complex* weight
491 );
492
500 void assign_weighted_field_to_mesh_tsc(
501 ParticleCatalogue& particles, fftw_complex* weight
502 );
503
511 void assign_weighted_field_to_mesh_pcs(
512 ParticleCatalogue& particles, fftw_complex* weight
513 );
514
524 double calc_assignment_window_in_fourier(int i, int j, int k, int order = 0);
525
534 void compute_assignment_window_in_fourier(int order = 0);
535};
536
537
538// ***********************************************************************
539// Field statistics
540// ***********************************************************************
541
551 public:
552 std::vector<int> nmodes;
553 std::vector<int> npairs;
554 std::vector<double> k;
555 std::vector<double> r;
557 std::vector< std::complex<double> > sn;
559 std::vector< std::complex<double> > pk;
561 std::vector< std::complex<double> > xi;
562
563 // ---------------------------------------------------------------------
564 // Life cycle
565 // ---------------------------------------------------------------------
566
574 explicit FieldStats(trv::ParameterSet& params, bool plan_ini = true);
575
579 ~FieldStats();
580
584 void reset_stats();
585
586 // ---------------------------------------------------------------------
587 // Binned statistics
588 // ---------------------------------------------------------------------
589
621 MeshField& field_a, MeshField& field_b, std::complex<double> shotnoise_amp,
622 int ell, int m, trv::Binning& kbinning
623 );
624
643 MeshField& field_a, MeshField& field_b, std::complex<double> shotnoise_amp,
644 int ell, int m, trv::Binning& rbinning
645 );
646
680 MeshField& field_a, MeshField& field_b,
681 std::vector< std::complex<double> >& ylm_a,
682 std::vector< std::complex<double> >& ylm_b,
683 std::complex<double> shotnoise_amp,
684 trv::Binning& rbinning
685 );
686
725 MeshField& field_a, MeshField& field_b,
726 std::vector< std::complex<double> >& ylm_a,
727 std::vector< std::complex<double> >& ylm_b,
730 std::complex<double> shotnoise_amp,
731 double k_a, double k_b
732 );
733
741 trv::Binning& binning, const std::string& save_file
742 );
743
744 private:
745 trv::ParameterSet params;
746 double dr[3];
747 double dk[3];
748 double vol;
749 double vol_cell;
750
752 fftw_complex* twopt_3d = nullptr;
754 fftw_plan inv_transform;
756 bool plan_ini = false;
757
759 std::vector<double> alias_sn;
761 bool alias_ini = false;
762
763 // ---------------------------------------------------------------------
764 // Utilities
765 // ---------------------------------------------------------------------
766
774 bool if_fields_compatible(MeshField& field_a, MeshField& field_b);
775
781 void resize_stats(int num_bins);
782
791 long long ret_grid_index(int i, int j, int k);
792
800 void shift_grid_indices_fourier(int& i, int& j, int& k);
801
802 // ---------------------------------------------------------------------
803 // Sampling corrections
804 // ---------------------------------------------------------------------
805
817 std::function<double(int, int, int)> ret_calc_shotnoise_aliasing();
818
826 void get_shotnoise_aliasing_sin2(
827 int i, int j, int k, double& cx2, double& cy2, double& cz2
828 );
829
837 double calc_shotnoise_aliasing_ngp(int i, int j, int k);
838
846 double calc_shotnoise_aliasing_cic(int i, int j, int k);
847
855 double calc_shotnoise_aliasing_tsc(int i, int j, int k);
856
864 double calc_shotnoise_aliasing_pcs(int i, int j, int k);
865
870 void compute_shotnoise_aliasing();
871};
872
873} // namespace trv
874
875#endif // !TRIUMVIRATE_INCLUDE_FIELD_HPP_INCLUDED_
Array operations.
Isotropic coordinate binning.
Definition dataobjs.hpp:56
Field (pseudo-two-point) statistics.
Definition field.hpp:550
std::vector< std::complex< double > > sn
shot-noise power in bins
Definition field.hpp:557
void reset_stats()
Reset two-point statistics.
Definition field.cpp:1821
std::vector< std::complex< double > > pk
pseudo power spectrum in bins
Definition field.hpp:559
std::vector< double > r
Definition field.hpp:555
void compute_uncoupled_shotnoise_for_3pcf(MeshField &field_a, MeshField &field_b, std::vector< std::complex< double > > &ylm_a, std::vector< std::complex< double > > &ylm_b, std::complex< double > shotnoise_amp, trv::Binning &rbinning)
Compute binned uncoupled three-point correlation function shot noise.
Definition field.cpp:2495
std::complex< double > compute_uncoupled_shotnoise_for_bispec_per_bin(MeshField &field_a, MeshField &field_b, std::vector< std::complex< double > > &ylm_a, std::vector< std::complex< double > > &ylm_b, trvm::SphericalBesselCalculator &sj_a, trvm::SphericalBesselCalculator &sj_b, std::complex< double > shotnoise_amp, double k_a, double k_b)
Compute unbinned uncoupled bispectrum shot noise on the FFT mesh grid.
Definition field.cpp:2721
~FieldStats()
Destruct two-point statistics.
Definition field.cpp:1805
std::vector< int > nmodes
number of wavevector modes in bins
Definition field.hpp:552
FieldStats(trv::ParameterSet &params, bool plan_ini=true)
Construct pseudo two-point statistics.
Definition field.cpp:1763
std::vector< double > k
average wavenumber in bins
Definition field.hpp:554
std::vector< std::complex< double > > xi
pseudo two-point correlation function in bins
Definition field.hpp:561
std::vector< int > npairs
number of separation pairs in bins
Definition field.hpp:553
void compute_ylm_wgtd_2pt_stats_in_fourier(MeshField &field_a, MeshField &field_b, std::complex< double > shotnoise_amp, int ell, int m, trv::Binning &kbinning)
Compute binned two-point statistics in Fourier space.
Definition field.cpp:2084
trv::BinnedVectors record_binned_vectors(trv::Binning &binning, const std::string &save_file)
Record binned vectors given a binning scheme.
Definition field.cpp:1890
void compute_ylm_wgtd_2pt_stats_in_config(MeshField &field_a, MeshField &field_b, std::complex< double > shotnoise_amp, int ell, int m, trv::Binning &rbinning)
Compute binned two-point statistics in configuration space.
Definition field.cpp:2279
Discretely sampled field on a mesh grid from particle catalogues.
Definition field.hpp:68
trv::ParameterSet params
parameter set
Definition field.hpp:70
void inv_fourier_transform()
Inverse Fourier transform the (FFT-transformed) field.
Definition field.cpp:1448
void inv_fourier_transform_sjl_ylm_wgtd_field(MeshField &field_fourier, std::vector< std::complex< double > > &ylm, trvm::SphericalBesselCalculator &sjl, double r)
Inverse Fourier transform a field weighted by the spherical Bessel function and reduced spherical ha...
Definition field.cpp:1627
std::string name
field name
Definition field.hpp:71
void assign_weighted_field_to_mesh(ParticleCatalogue &particles, fftw_complex *weights)
Assign a weighted field to a mesh by interpolation scheme.
Definition field.cpp:427
double calc_grid_based_powlaw_norm(ParticleCatalogue &particles, int order)
Definition field.cpp:1702
void reset_density_field()
(Re-)initialise the complex field (and its shadow) on mesh.
Definition field.cpp:358
void inv_fourier_transform_ylm_wgtd_field_band_limited(MeshField &field_fourier, std::vector< std::complex< double > > &ylm, double k_band, double dk_band, double &k_eff, int &nmodes)
Inverse Fourier transform a field weighted by the reduced spherical harmonics restricted to a wavenu...
Definition field.cpp:1544
double dr[3]
grid size in each dimension
Definition field.hpp:73
void fourier_transform()
Fourier transform the field.
Definition field.cpp:1365
void compute_ylm_wgtd_field(ParticleCatalogue &particles_data, ParticleCatalogue &particles_rand, LineOfSight *los_data, LineOfSight *los_rand, double alpha, int ell, int m)
Compute the weighted field (fluctuations) further weighted by the reduced spherical harmonics.
Definition field.cpp:1106
void compute_unweighted_field(ParticleCatalogue &particles)
Compute the unweighted field.
Definition field.cpp:1066
void apply_wide_angle_pow_law_kernel()
Apply wide-angle correction kernel in configuration space.
Definition field.cpp:1479
void compute_ylm_wgtd_quad_field(ParticleCatalogue &particles_data, ParticleCatalogue &particles_rand, LineOfSight *los_data, LineOfSight *los_rand, double alpha, int ell, int m)
Compute the quadratic weighted field (fluctuations) further weighted by the reduced spherical harmoni...
Definition field.cpp:1229
fftw_complex * field
complex field on mesh
Definition field.hpp:72
MeshField(trv::ParameterSet &params, bool plan_ini=true, const std::string &name="mesh-field")
Construct the mesh field.
Definition field.cpp:42
void compute_unweighted_field_fluctuations_insitu(ParticleCatalogue &particles)
Compute the unweighted field fluctuations.
Definition field.cpp:1089
double dk[3]
fundamental wavenumber in each dimension
Definition field.hpp:74
double vol
mesh volume
Definition field.hpp:75
~MeshField()
Destruct the mesh field.
Definition field.cpp:329
double vol_cell
mesh grid cell volume
Definition field.hpp:76
void apply_assignment_compensation()
Apply compensation needed after Fourier transform for assignment schemes.
Definition field.cpp:1516
const fftw_complex & operator[](long long gid)
Return mesh field grid cell value.
Definition field.cpp:382
Parameter set.
Particle catalogue.
Definition particles.hpp:68
Interpolated spherical Bessel function of the first kind.
Definition maths.hpp:258
Clustering measurement data objects.
I/O support including custom exceptions and utility functions.
Mathematical calculations.
Provide tracking of program resources and exceptions.
Program parameter configuration.
Particle containers with I/O methods and operations.
Binned vectors.
Definition dataobjs.hpp:164
Line-of-sight vector.
Definition dataobjs.hpp:184