Skip to content

Commit

Permalink
Added spectrum computation to NcHIPertEM and updated notebook.
Browse files Browse the repository at this point in the history
  • Loading branch information
vitenti committed Apr 22, 2024
1 parent fc63c39 commit 8afd590
Show file tree
Hide file tree
Showing 4 changed files with 434 additions and 1,922 deletions.
2,282 changes: 363 additions & 1,919 deletions notebooks/primordial_perturbations/vexp_bounce.ipynb

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions numcosmo/perturbations/nc_hipert_adiab.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@
#include <glib.h>
#include <glib-object.h>
#include <numcosmo/build_cfg.h>
#include <numcosmo/math/ncm_ode_spline.h>
#include <numcosmo/math/ncm_powspec_spline2d.h>
#include <numcosmo/nc_hicosmo.h>
#include <numcosmo/math/ncm_csq1d.h>
#include <numcosmo/math/ncm_powspec_spline2d.h>

G_BEGIN_DECLS

Expand Down
68 changes: 67 additions & 1 deletion numcosmo/perturbations/nc_hipert_em.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#endif /* HAVE_CONFIG_H */
#include "build_cfg.h"

#include "math/ncm_spline_cubic_notaknot.h"
#include "math/ncm_spline2d_bicubic.h"
#include "perturbations/nc_hipert_em.h"

#ifndef NUMCOSMO_GIR_SCAN
Expand Down Expand Up @@ -441,3 +441,69 @@ nc_hipert_em_eval_PE_PB (NcHIPertEM *pem, NcmModel *model, const gdouble tau, gd
*PB = unit * unit * gsl_pow_4 (x) * gsl_pow_5 (k) * J11 / fact;
}

/**
* nc_hipert_em_prepare_spectrum:
* @pem: a #NcHIPertEM
* @model: a #NcmModel
* @k_array: (element-type gdouble): a #GArray with the wave numbers
* @tau_array: (element-type gdouble): a #GArray with the times
* @ps_E: (out callee-allocates) (transfer full): the electric field power spectrum
* @ps_B: (out callee-allocates) (transfer full): the magnetic field power spectrum
*
* Prepares the electric and magnetic field power spectra in units of Gauss squared
* $G_\mathrm{s}^2$.
*
*/
void
nc_hipert_em_prepare_spectrum (NcHIPertEM *pem, NcmModel *model, GArray *k_array, GArray *tau_array, NcmPowspecSpline2d **ps_E, NcmPowspecSpline2d **ps_B)

Check warning on line 458 in numcosmo/perturbations/nc_hipert_em.c

View check run for this annotation

Codecov / codecov/patch

numcosmo/perturbations/nc_hipert_em.c#L458

Added line #L458 was not covered by tests
{
NcmCSQ1D *csq1d = NCM_CSQ1D (pem);
NcmMatrix *ps_m_E = ncm_matrix_new (k_array->len, tau_array->len);
NcmMatrix *ps_m_B = ncm_matrix_new (k_array->len, tau_array->len);
NcmVector *lnk_vec = ncm_vector_new (k_array->len);
NcmSpline2d *ps_s_E, *ps_s_B;
guint i;

Check warning on line 465 in numcosmo/perturbations/nc_hipert_em.c

View check run for this annotation

Codecov / codecov/patch

numcosmo/perturbations/nc_hipert_em.c#L460-L465

Added lines #L460 - L465 were not covered by tests

for (i = 0; i < k_array->len; i++)

Check warning on line 467 in numcosmo/perturbations/nc_hipert_em.c

View check run for this annotation

Codecov / codecov/patch

numcosmo/perturbations/nc_hipert_em.c#L467

Added line #L467 was not covered by tests
{
NcmCSQ1DState state;
const gdouble k = g_array_index (k_array, gdouble, i);
guint j;

Check warning on line 471 in numcosmo/perturbations/nc_hipert_em.c

View check run for this annotation

Codecov / codecov/patch

numcosmo/perturbations/nc_hipert_em.c#L469-L471

Added lines #L469 - L471 were not covered by tests

nc_hipert_em_set_k (pem, k);
ncm_vector_set (lnk_vec, i, log (k));
ncm_csq1d_prepare (csq1d, model);

Check warning on line 475 in numcosmo/perturbations/nc_hipert_em.c

View check run for this annotation

Codecov / codecov/patch

numcosmo/perturbations/nc_hipert_em.c#L473-L475

Added lines #L473 - L475 were not covered by tests

for (j = 0; j < tau_array->len; j++)

Check warning on line 477 in numcosmo/perturbations/nc_hipert_em.c

View check run for this annotation

Codecov / codecov/patch

numcosmo/perturbations/nc_hipert_em.c#L477

Added line #L477 was not covered by tests
{
const gdouble tau = g_array_index (tau_array, gdouble, j);
gdouble ps_E_k_tau, ps_B_k_tau;

Check warning on line 480 in numcosmo/perturbations/nc_hipert_em.c

View check run for this annotation

Codecov / codecov/patch

numcosmo/perturbations/nc_hipert_em.c#L479-L480

Added lines #L479 - L480 were not covered by tests

nc_hipert_em_eval_PE_PB (pem, model, tau, &ps_E_k_tau, &ps_B_k_tau);

Check warning on line 482 in numcosmo/perturbations/nc_hipert_em.c

View check run for this annotation

Codecov / codecov/patch

numcosmo/perturbations/nc_hipert_em.c#L482

Added line #L482 was not covered by tests

ncm_matrix_set (ps_m_E, i, j, log (ps_E_k_tau));
ncm_matrix_set (ps_m_B, i, j, log (ps_B_k_tau));

Check warning on line 485 in numcosmo/perturbations/nc_hipert_em.c

View check run for this annotation

Codecov / codecov/patch

numcosmo/perturbations/nc_hipert_em.c#L484-L485

Added lines #L484 - L485 were not covered by tests
}
}

{
NcmVector *tau_vec = ncm_vector_new_array (tau_array);

Check warning on line 490 in numcosmo/perturbations/nc_hipert_em.c

View check run for this annotation

Codecov / codecov/patch

numcosmo/perturbations/nc_hipert_em.c#L490

Added line #L490 was not covered by tests

ps_s_E = ncm_spline2d_bicubic_notaknot_new ();
ps_s_B = ncm_spline2d_bicubic_notaknot_new ();

Check warning on line 493 in numcosmo/perturbations/nc_hipert_em.c

View check run for this annotation

Codecov / codecov/patch

numcosmo/perturbations/nc_hipert_em.c#L492-L493

Added lines #L492 - L493 were not covered by tests

ncm_spline2d_set (ps_s_E, tau_vec, lnk_vec, ps_m_E, TRUE);
ncm_spline2d_set (ps_s_B, tau_vec, lnk_vec, ps_m_B, TRUE);

Check warning on line 496 in numcosmo/perturbations/nc_hipert_em.c

View check run for this annotation

Codecov / codecov/patch

numcosmo/perturbations/nc_hipert_em.c#L495-L496

Added lines #L495 - L496 were not covered by tests

*ps_E = ncm_powspec_spline2d_new (ps_s_E);
*ps_B = ncm_powspec_spline2d_new (ps_s_B);

Check warning on line 499 in numcosmo/perturbations/nc_hipert_em.c

View check run for this annotation

Codecov / codecov/patch

numcosmo/perturbations/nc_hipert_em.c#L498-L499

Added lines #L498 - L499 were not covered by tests

ncm_matrix_free (ps_m_E);
ncm_matrix_free (ps_m_B);
ncm_vector_free (tau_vec);
ncm_vector_free (lnk_vec);
ncm_spline2d_free (ps_s_E);
ncm_spline2d_free (ps_s_B);

Check warning on line 506 in numcosmo/perturbations/nc_hipert_em.c

View check run for this annotation

Codecov / codecov/patch

numcosmo/perturbations/nc_hipert_em.c#L501-L506

Added lines #L501 - L506 were not covered by tests
}
}

3 changes: 3 additions & 0 deletions numcosmo/perturbations/nc_hipert_em.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <numcosmo/math/ncm_ode_spline.h>
#include <numcosmo/nc_hicosmo.h>
#include <numcosmo/math/ncm_csq1d.h>
#include <numcosmo/math/ncm_powspec_spline2d.h>

G_BEGIN_DECLS

Expand Down Expand Up @@ -93,6 +94,8 @@ gdouble nc_hipert_em_get_k (NcHIPertEM *pem);

void nc_hipert_em_eval_PE_PB (NcHIPertEM *pem, NcmModel *model, const gdouble tau, gdouble *PE, gdouble *PB);

void nc_hipert_em_prepare_spectrum (NcHIPertEM *pem, NcmModel *model, GArray *k_array, GArray *tau_array, NcmPowspecSpline2d **ps_E, NcmPowspecSpline2d **ps_B);

G_END_DECLS

#endif /* _NC_HIPERT_EM_H_ */
Expand Down

0 comments on commit 8afd590

Please sign in to comment.