MP-Gadget  5.0.1.dev1-76bc7d4726-dirty
Classes | Typedefs | Functions
powerspectrum.h File Reference
#include <stddef.h>
#include <stdint.h>
#include <gsl/gsl_interp.h>
Include dependency graph for powerspectrum.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _powerspectrum
 

Typedefs

typedef struct _powerspectrum Power
 

Functions

void powerspectrum_alloc (Power *ps, const int nbins, const int nthreads, const int MassiveNuLinResp, const double BoxSize_in_cm)
 
void powerspectrum_zero (Power *ps)
 
void powerspectrum_free (Power *ps)
 
void powerspectrum_sum (Power *ps)
 
void powerspectrum_save (Power *ps, const char *OutputDir, const char *filename, const double Time, const double D1)
 

Typedef Documentation

◆ Power

typedef struct _powerspectrum Power

Function Documentation

◆ powerspectrum_alloc()

void powerspectrum_alloc ( Power ps,
const int  nbins,
const int  nthreads,
const int  MassiveNuLinResp,
const double  BoxSize_in_cm 
)

Definition at line 16 of file powerspectrum.c.

17 {
18  ps->size = nbins;
19  const int nalloc = nbins*nthreads;
20  ps->nalloc = nalloc;
21  ps->kk = (double *) mymalloc("Powerspectrum", sizeof(double) * 2*nalloc);
22  ps->Power = ps->kk + nalloc;
23  ps->BoxSize_in_MPC = BoxSize_in_cm / CM_PER_MPC;
24  ps->logknu = NULL;
25  if(MassiveNuLinResp) {
26  /*These arrays are stored separately to make interpolation more accurate*/
27  ps->logknu = (double *) mymalloc("PowerNu", sizeof(double) * 2*nbins);
28  ps->delta_nu_ratio = ps-> logknu + nbins;
29  }
30  ps->Nmodes = (int64_t *) mymalloc("Powermodes", sizeof(int64_t) * nalloc);
32 }
#define mymalloc(name, size)
Definition: mymalloc.h:15
#define CM_PER_MPC
Definition: physconst.h:20
void powerspectrum_zero(Power *ps)
Definition: powerspectrum.c:35
double * logknu
Definition: powerspectrum.h:20
double * delta_nu_ratio
Definition: powerspectrum.h:21
double * Power
Definition: powerspectrum.h:10
double BoxSize_in_MPC
Definition: powerspectrum.h:17
int64_t * Nmodes
Definition: powerspectrum.h:11

References _powerspectrum::BoxSize_in_MPC, CM_PER_MPC, _powerspectrum::delta_nu_ratio, _powerspectrum::kk, _powerspectrum::logknu, mymalloc, _powerspectrum::nalloc, _powerspectrum::Nmodes, _powerspectrum::Power, powerspectrum_zero(), and _powerspectrum::size.

Referenced by _prepare(), glass_evolve(), and test_total_powerspectrum().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ powerspectrum_free()

void powerspectrum_free ( Power ps)

Definition at line 44 of file powerspectrum.c.

45 {
46  myfree(ps->Nmodes);
47  if(ps->logknu)
48  myfree(ps->logknu);
49  myfree(ps->kk);
50 }
#define myfree(x)
Definition: mymalloc.h:19

References _powerspectrum::kk, _powerspectrum::logknu, myfree, and _powerspectrum::Nmodes.

Referenced by glass_evolve(), and gravpm_force().

Here is the caller graph for this function:

◆ powerspectrum_save()

void powerspectrum_save ( Power ps,
const char *  OutputDir,
const char *  filename,
const double  Time,
const double  D1 
)

Definition at line 92 of file powerspectrum.c.

93 {
94  int i;
95  int ThisTask;
96  MPI_Comm_rank(MPI_COMM_WORLD, &ThisTask);
97  if(ThisTask != 0)
98  return;
99  char * fname = fastpm_strdup_printf("%s/%s-%0.4f.txt", OutputDir, filename, Time);
100  /* Avoid -0.0000.txt at high z*/
101  if(Time <= 1e-4) {
102  myfree(fname);
103  fname = fastpm_strdup_printf("%s/%s-%0.4e.txt", OutputDir, filename, Time);
104  }
105  message(1, "Writing Power Spectrum to %s\n", fname);
106  FILE * fp = fopen(fname, "w");
107  if(!fp)
108  message(1, "Could not open %s for writing\n", fname);
109  else {
110  fprintf(fp, "# in Mpc/h Units \n");
111  fprintf(fp, "# D1 = %g \n", D1);
112  fprintf(fp, "# k P N P(z=0)\n");
113  for(i = 0; i < ps->nonzero; i ++) {
114  fprintf(fp, "%g %g %ld %g\n", ps->kk[i], ps->Power[i], ps->Nmodes[i],
115  ps->Power[i] / (D1 * D1));
116  }
117  fclose(fp);
118  }
119  myfree(fname);
120 }
void message(int where, const char *fmt,...)
Definition: endrun.c:175
char * fastpm_strdup_printf(const char *fmt,...)
Definition: string.c:41
int ThisTask
Definition: test_exchange.c:23

References fastpm_strdup_printf(), _powerspectrum::kk, message(), myfree, _powerspectrum::Nmodes, _powerspectrum::nonzero, _powerspectrum::Power, and ThisTask.

Referenced by glass_evolve(), and gravpm_force().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ powerspectrum_sum()

void powerspectrum_sum ( Power ps)

Definition at line 54 of file powerspectrum.c.

55 {
56  /*Sum power spectrum thread-local storage*/
57  int i,j;
58  for(i = 0; i < ps->size; i ++) {
59  for(j = 1; j < ps->nalloc/ps->size; j++) {
60  ps->Power[i] += ps->Power[i+ ps->size*j];
61  ps->kk[i] += ps->kk[i+ ps->size*j];
62  ps->Nmodes[i] += ps->Nmodes[i +ps->size*j];
63  }
64  }
65 
66  /*Now sum power spectrum MPI storage*/
67  MPI_Allreduce(MPI_IN_PLACE, &(ps->Norm), 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
68  MPI_Allreduce(MPI_IN_PLACE, ps->kk, ps->size, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
69  MPI_Allreduce(MPI_IN_PLACE, ps->Power, ps->size, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
70  MPI_Allreduce(MPI_IN_PLACE, ps->Nmodes, ps->size, MPI_INT64, MPI_SUM, MPI_COMM_WORLD);
71 
72  int nk_nz = 0;
73  /*Now fix power spectrum units and remove zero entries.*/
74  for(i = 0; i < ps->size; i ++) {
75  if(ps->Nmodes[i] == 0) continue;
76  ps->Power[i] /= ps->Nmodes[i];
77  ps->Power[i] /= ps->Norm;
78  ps->kk[i] /= ps->Nmodes[i];
79  /* Mpc/h units */
80  ps->kk[i] *= 2 * M_PI / (ps->BoxSize_in_MPC);
81  ps->Power[i] *= pow(ps->BoxSize_in_MPC , 3.0);
82  /*Move the power spectrum earlier, removing zero modes*/
83  ps->Power[nk_nz] = ps->Power[i];
84  ps->kk[nk_nz] = ps->kk[i];
85  ps->Nmodes[nk_nz] = ps->Nmodes[i];
86  nk_nz++;
87  }
88  ps->nonzero = nk_nz;
89 }
#define MPI_INT64
Definition: system.h:12

References _powerspectrum::BoxSize_in_MPC, _powerspectrum::kk, MPI_INT64, _powerspectrum::nalloc, _powerspectrum::Nmodes, _powerspectrum::nonzero, _powerspectrum::Norm, _powerspectrum::Power, and _powerspectrum::size.

Referenced by compute_neutrino_power(), glass_force(), gravpm_force(), and test_total_powerspectrum().

Here is the caller graph for this function:

◆ powerspectrum_zero()

void powerspectrum_zero ( Power ps)

Definition at line 35 of file powerspectrum.c.

36 {
37  memset(ps->kk, 0, sizeof(double) * ps->nalloc);
38  memset(ps->Power, 0, sizeof(double) * ps->nalloc);
39  memset(ps->Nmodes, 0, sizeof(int64_t) * ps->nalloc);
40  ps->Norm = 0;
41 }

References _powerspectrum::kk, _powerspectrum::nalloc, _powerspectrum::Nmodes, _powerspectrum::Norm, and _powerspectrum::Power.

Referenced by compute_neutrino_power(), glass_force(), powerspectrum_alloc(), and test_total_powerspectrum().

Here is the caller graph for this function: