From fc63c39356ad82245d666b211060fe240402779d Mon Sep 17 00:00:00 2001 From: Sandro Dias Pinto Vitenti Date: Sun, 21 Apr 2024 23:43:53 -0300 Subject: [PATCH] NcHIPert Reformulation (#95) * Removed old singularity code from CSQ1D. Working version of vexp_bounce.ipynb. * Removing old singularity interface (deprecated). * Updated perturbations to use CSQ1D instead of the old and deprecated HOAA. * Simplified CSQ1D interface. Now the subclasses are responsible for any extra parameter of the system. * Redesigned CSQ1D to better organize the output in terms of different parametrizations and frames. * Updated nc_de_cont, vacuum_study.ipynb and test_py_csq1d.py to use the new design. * Updated stubs. * New method to compute the state at a time and frame. * Updated vacuum_study_adiabatic. * Updated vacuum_study. * Updated unit testing. * Added tests for non adiabatic vacuum and its propagation using ODE and the propagator. * More tests for NcmCSQ1D and NcmCSQ1DState. * Cleaning notebooks. * Added electromagnetic constants to NcmC. Added unit testing. * New NcHIPertEM for free electromagnetic field computation. * Improved interface for perturbation objects (work in progress). * Updated vexp_bounce.ipynb to use the new interface. * Updating primordial_perturbations/magnetic_dust_bounce.ipynb. --------- Co-authored-by: EFrion Co-authored-by: Eduardo Barroso --- docs/numcosmo-docs.sgml | 18 +- examples/example_exp_potential.py | 188 -- examples/example_zeta_exp_potential.py | 150 +- meson.build | 9 + meson_options.txt | 12 + .../bounce_vector.ipynb | 112 +- .../magnetic_dust_bounce.ipynb | 126 +- .../single_fluid_qb.ipynb | 420 +++ .../vacuum_study.ipynb | 463 ++-- .../vacuum_study_adiabatic.ipynb | 149 +- .../vexp_bounce.ipynb | 2432 +++++++++++++++-- numcosmo/data/nc_data_planck_lkl.c | 2 +- numcosmo/data/nc_data_snia_cov.c | 32 +- numcosmo/math/ncm_c.c | 16 + numcosmo/math/ncm_c.h | 14 + numcosmo/math/ncm_cfg.c | 22 +- numcosmo/math/ncm_csq1d.c | 2169 ++++++++++----- numcosmo/math/ncm_csq1d.h | 260 +- numcosmo/math/ncm_fftlog.c | 90 + numcosmo/math/ncm_fftlog.h | 3 + numcosmo/math/ncm_powspec.c | 18 +- numcosmo/math/ncm_powspec_filter.c | 45 + numcosmo/math/ncm_powspec_spline2d.c | 359 +++ numcosmo/math/ncm_powspec_spline2d.h | 55 + numcosmo/math/ncm_util.c | 19 +- numcosmo/meson.build | 12 +- numcosmo/model/nc_hicosmo_Vexp.c | 1877 +++++++------ numcosmo/model/nc_hicosmo_Vexp.h | 53 +- numcosmo/model/nc_hicosmo_qgrw.c | 17 +- numcosmo/model/nc_hicosmo_qgw.c | 450 +++ numcosmo/model/nc_hicosmo_qgw.h | 115 + numcosmo/nc_de_cont.c | 139 +- numcosmo/nc_de_cont.h | 34 +- numcosmo/nc_powspec_ml.h | 19 +- numcosmo/nc_powspec_ml_fix_spline.c | 259 -- numcosmo/nc_powspec_ml_fix_spline.h | 73 - numcosmo/nc_powspec_ml_spline.c | 274 ++ numcosmo/nc_powspec_ml_spline.h | 50 + numcosmo/numcosmo-math.h | 5 +- numcosmo/numcosmo.h | 28 +- numcosmo/perturbations/nc_hipert_adiab.c | 810 +++++- numcosmo/perturbations/nc_hipert_adiab.h | 174 +- numcosmo/perturbations/nc_hipert_em.c | 443 +++ numcosmo/perturbations/nc_hipert_em.h | 99 + numcosmo/perturbations/nc_hipert_gw.c | 378 ++- numcosmo/perturbations/nc_hipert_gw.h | 174 +- numcosmo_py/datasets/no_perturbations.py | 9 +- numcosmo_py/experiments/planck18.py | 4 - numcosmo_py/nc.pyi | 570 +++- numcosmo_py/ncm.pyi | 393 ++- numcosmo_py/plotting/tools.py | 9 +- tests/meson.build | 43 +- tests/test_nc_hicosmo_qgw.c | 91 + tests/test_ncm_fftlog.c | 79 +- tests/test_ncm_generic.c | 147 + tests/test_py_constants.py | 6 +- tests/test_py_csq1d.py | 514 +++- tests/test_py_data_rosenbrock.py | 2 - tests/test_py_data_snia_cov.py | 63 + tests/test_py_de_cont.py | 136 + tests/test_py_hicosmo_Vexp.py | 306 +++ tests/test_py_hipert_adiab.py | 763 ++++++ tests/test_py_hipert_em.py | 262 ++ tests/test_py_hipert_gw.py | 207 ++ tests/test_py_numcosmo_app.py | 1 + tests/test_py_ode_spline.py | 19 +- tests/test_py_powspec_ml_spline.py | 198 ++ tests/test_py_powspec_spline2d.py | 199 ++ 68 files changed, 12412 insertions(+), 4275 deletions(-) delete mode 100755 examples/example_exp_potential.py create mode 100644 notebooks/primordial_perturbations/single_fluid_qb.ipynb create mode 100644 numcosmo/math/ncm_powspec_spline2d.c create mode 100644 numcosmo/math/ncm_powspec_spline2d.h create mode 100644 numcosmo/model/nc_hicosmo_qgw.c create mode 100644 numcosmo/model/nc_hicosmo_qgw.h delete mode 100644 numcosmo/nc_powspec_ml_fix_spline.c delete mode 100644 numcosmo/nc_powspec_ml_fix_spline.h create mode 100644 numcosmo/nc_powspec_ml_spline.c create mode 100644 numcosmo/nc_powspec_ml_spline.h create mode 100644 numcosmo/perturbations/nc_hipert_em.c create mode 100644 numcosmo/perturbations/nc_hipert_em.h create mode 100644 tests/test_nc_hicosmo_qgw.c create mode 100644 tests/test_py_data_snia_cov.py create mode 100644 tests/test_py_de_cont.py create mode 100644 tests/test_py_hicosmo_Vexp.py create mode 100644 tests/test_py_hipert_adiab.py create mode 100644 tests/test_py_hipert_em.py create mode 100644 tests/test_py_hipert_gw.py create mode 100644 tests/test_py_powspec_ml_spline.py create mode 100644 tests/test_py_powspec_spline2d.py diff --git a/docs/numcosmo-docs.sgml b/docs/numcosmo-docs.sgml index a904aa35b..0724d7b3c 100644 --- a/docs/numcosmo-docs.sgml +++ b/docs/numcosmo-docs.sgml @@ -77,9 +77,10 @@
Power spectrum functions + - +
Harmonic Oscillator @@ -271,14 +272,15 @@ Perturbations - - - - - + + + + + +
Gravitational theories @@ -320,9 +322,9 @@
Matter Power Spectrum - - + +
diff --git a/examples/example_exp_potential.py b/examples/example_exp_potential.py deleted file mode 100755 index 09a25920a..000000000 --- a/examples/example_exp_potential.py +++ /dev/null @@ -1,188 +0,0 @@ -#!/usr/bin/env python -# -# example_exp_potential.py -# -# Mon May 22 16:00:00 2023 -# Copyright 2023 Sandro Dias Pinto Vitenti -# -# -# example_exp_potential.py -# Copyright (C) 2023 Sandro Dias Pinto Vitenti -# -# numcosmo is free software: you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by the -# Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# numcosmo is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program. If not, see . - -"""Example using exponential potential cosmology.""" - -import math -import numpy as np -import matplotlib.pyplot as plt - -from numcosmo_py import Nc, Ncm - - -# -# Initializing the library objects, this must be called before -# any other library function. -# -Ncm.cfg_init() - - -def test_Vexp() -> None: - """Example using exponential potential cosmology.""" - - # - # New homogeneous and isotropic cosmological model: NcHICosmoVexp - # - cosmo1 = Nc.HICosmoVexp() - cosmo2 = Nc.HICosmoVexp() - - cosmo1.props.alphab = +1.0e-1 - cosmo1.props.sigmaphi = +8.0e-1 - cosmo1.props.dphi = +5.0e-1 - # cosmo1.props.xb = 4.8e37 - cosmo1.props.xb = 1.0e37 - cosmo1.props.OmegaL = 1.0e0 - cosmo1.props.Omegac = 1.0 - cosmo1.props.H0 = 67.8 - - cosmo2.props.alphab = +1.0e-1 - cosmo2.props.sigmaphi = +8.0e-1 - cosmo2.props.dphi = +5.0e-1 - # cosmo2.props.xb = 4.8e37 - cosmo2.props.xb = 1.0e37 - cosmo2.props.OmegaL = 1.0e0 - cosmo2.props.Omegac = 1.0 - cosmo2.props.H0 = 67.8 - - tau_min = max(cosmo1.tau_min(), cosmo1.tau_xc(1.0e-5)) - tau_max = min(cosmo1.tau_max(), -cosmo1.tau_xc(1.0e-5)) - k = 1.0e0 - xb = cosmo1.xbe() - - print(f"# tau interval: ({tau_min: 22.15g}, {tau_max: 22.15g})") - - Nn = 100000 - LS = 1.0e-30 - tau_a = np.concatenate( - ( - np.geomspace(tau_min, -LS, int(Nn / 2)), - np.geomspace(LS, tau_max, int(Nn / 2)), - ), - axis=0, - ) - - alpha_a = [] - - nu1_a = [] - mnu1_a = [] - mnu_gw1_a = [] - dlnmnu1_a = [] - dlnmnu_gw1_a = [] - Eaa01_a = [] - x1_a = [] - y1_a = [] - - nu2_a = [] - mnu2_a = [] - mnu_gw2_a = [] - dlnmnu2_a = [] - dlnmnu_gw2_a = [] - Eaa02_a = [] - x2_a = [] - y2_a = [] - - for tau in tau_a: - nu1, dlnmnu1 = cosmo1.eval_system(tau, k) - mnu1 = cosmo1.eval_mnu(tau, k) - mnu_gw1 = Nc.HIPertIGW.eval_mnu(cosmo1, tau, k) - - nu2, dlnmnu2 = cosmo2.eval_system(tau, k) - mnu2 = cosmo2.eval_mnu(tau, k) - mnu_gw2 = Nc.HIPertIGW.eval_mnu(cosmo2, tau, k) - - _nu_gw1, dlnmnu_gw1 = Nc.HIPertIGW.eval_system(cosmo1, tau, k) - _nu_gw2, dlnmnu_gw2 = Nc.HIPertIGW.eval_system(cosmo2, tau, k) - - Eaa01 = k * tau / nu1 - Eaa02 = k * tau / nu2 - - (x1, y1) = cosmo1.x_y(tau) - (x2, y2) = cosmo2.x_y(tau) - - alpha = 0 - if tau > 0.0: - alpha = 0.5 * tau * tau / math.log(10.0) - else: - alpha = -0.5 * tau * tau / math.log(10.0) - - alpha_a.append(alpha) - - nu1_a.append(nu1) - mnu1_a.append(nu1 / mnu1) - mnu_gw1_a.append(nu1 / mnu_gw1) - - dlnmnu1_a.append(math.fabs(k * dlnmnu1 / nu1)) - dlnmnu_gw1_a.append(math.fabs(k * dlnmnu_gw1 / nu1)) - Eaa01_a.append(math.fabs(Eaa01) * math.exp(-0.5 * tau * tau) * xb) - - x1_a.append(x1) - y1_a.append(y1) - - nu2_a.append(nu2) - mnu2_a.append(nu2 / mnu2) - mnu_gw2_a.append(nu2 / mnu_gw2) - - dlnmnu2_a.append(math.fabs(k * dlnmnu2 / nu2)) - dlnmnu_gw2_a.append(math.fabs(k * dlnmnu_gw2 / nu2)) - Eaa02_a.append(math.fabs(Eaa02) * math.exp(-0.5 * tau * tau) * xb) - - x2_a.append(x2) - y2_a.append(y2) - - mylw = 1 - - print( - f"# tau classical: ({cosmo1.tau_qt_c(): 22.15g}, {cosmo1.tau_qt_e(): 22.15g})" - ) - - # plt.plot (alpha_a, np.array (x1_a)**(-2), lw=mylw, label = r'$x^{-2}_1$') - # plt.plot (alpha_a, np.array (x2_a)**(-2), lw=mylw, label = r'$x^{-2}_2$') - # plt.plot (alpha_a, nu_a, lw=mylw, label = r'$\nu$') - # plt.plot (alpha_a, mnu1_a, lw=mylw, label = r'$m_1\nu_1$') - # plt.plot (alpha_a, mnu2_a, lw=mylw, label = r'$m_2\nu_2$') - # plt.plot (alpha_a, mnu_gw_a, lw=mylw, label = r'$m_\mathrm{gw}\nu_\mathrm{gw}$') - plt.plot(alpha_a, dlnmnu1_a, lw=mylw, label=r"$\mathrm{d}\ln(m\nu)/\mathrm{d}\tau$") - # plt.plot (alpha_a, dlnmnu_gw1_a, lw=mylw, - # label = r'$\mathrm{d}\ln(m\nu)_\mathrm{gw}/\mathrm{d}\tau$') - plt.plot(alpha_a, dlnmnu2_a, lw=mylw, label=r"$\mathrm{d}\ln(m\nu)/\mathrm{d}\tau$") - # plt.plot (alpha_a, dlnmnu_gw2_a, lw=mylw, - # label = r'$\mathrm{d}\ln(m\nu)_\mathrm{gw}/\mathrm{d}\tau$') - plt.plot(alpha_a, Eaa01_a, lw=mylw, label=r"$E_1$") - plt.plot(alpha_a, Eaa02_a, lw=mylw, label=r"$E_2$") - - plt.grid(b=True, which="both", linestyle=":", color="0.75", linewidth=0.5) - plt.legend(loc="best") - - # plt.xscale('symlog', linthreshx=1.0e-1) - # plt.xscale('log', linthreshx=1.0e-5) - plt.yscale("log", subsy=[2, 4, 6, 8]) - # plt.yscale('symlog', linthreshy=1.0e-2, linscaley = 1.0, subsy = [2]) - # plt.ylim (1.0e-10, 1.0e12) - - plt.show() - plt.clf() - - -if __name__ == "__main__": - test_Vexp() diff --git a/examples/example_zeta_exp_potential.py b/examples/example_zeta_exp_potential.py index 5b565a80c..c9400a22e 100755 --- a/examples/example_zeta_exp_potential.py +++ b/examples/example_zeta_exp_potential.py @@ -55,16 +55,16 @@ def test_zeta_exp_potential(new_config: bool = True) -> None: Vexp.props.Omegac = 1.0 Vexp.props.H0 = 67.8 else: - Vexp.props.alphab = +1.0e-20 - Vexp.props.sigmaphi = +8.0e-1 - Vexp.props.dphi = +5.0e-1 - Vexp.props.xb = 2.0e38 + Vexp.props.alphab = +8.3163e-2 + Vexp.props.sigmaphi = +9.0 + Vexp.props.dphi = -9.0e-4 + Vexp.props.xb = 2.0e36 Vexp.props.OmegaL = 1.0 Vexp.props.Omegac = 1.0 Vexp.props.H0 = 67.8 - k = 1.0e0 - tc = Vexp.tau_xe(1.0e15) + k = 0.05 + tc = +Vexp.tau_xe(1.0e15) reltol = 1.0e-14 adiab.set_ti(Vexp.tau_min()) @@ -84,21 +84,28 @@ def test_zeta_exp_potential(new_config: bool = True) -> None: # exit () print("# Preparing ADIAB") + found, adiab_ti = adiab.find_adiab_time_limit(Vexp, -20.0, -1.0e-2, 1.0e-6) + assert found, "Cannot find initial time" + adiab.set_init_cond_adiab(Vexp, adiab_ti) adiab.prepare(Vexp) # exit () print("# Preparing GW") + found, gw_ti = gw.find_adiab_time_limit(Vexp, -20.0, -1.0e-2, 1.0e-8) + assert found, "Cannot find initial time" + gw.set_init_cond_adiab(Vexp, gw_ti) gw.prepare(Vexp) # (t0, t1) = adiab.get_t0_t1 (Vexp) - (t0, t1) = gw.get_t0_t1(Vexp) + t0 = gw.get_ti() + t1 = gw.get_tf() print(f"# BACKG (t0, t1) = ({Vexp.tau_min(): 21.15e}, {Vexp.tau_max(): 21.15e})") print(f"# ADIAB (t0, t1) = ({t0: 21.15e}, {t1: 21.15e})") - (Delta_zeta_c, _Delta_Pzeta_c) = adiab.eval_Delta(Vexp, tc) - (Delta_h_c, _Delta_Ph_c) = gw.eval_Delta(Vexp, tc) + (Delta_zeta_c, _Delta_Pzeta_c) = adiab.eval_powspec_at(Vexp, tc) + (Delta_h_c, _Delta_Ph_c) = gw.eval_powspec_at(Vexp, tc) print(f"# Time of x_e = 10^15: tau_c = {tc: 21.15f}") print(f"# Power spectrum at tau_c: PS_ADIAB = {Delta_zeta_c: 21.15e}") @@ -106,124 +113,21 @@ def test_zeta_exp_potential(new_config: bool = True) -> None: print( f"# Power spectrum at tau_c: r = {2.0 * Delta_h_c / Delta_zeta_c: 21.15e}" ) + + tau_a = np.linspace(-5.0, t1, 100000) + Delta_zeta = np.array([adiab.eval_powspec_at(Vexp, t) for t in tau_a]) + Delta_h = np.array([gw.eval_powspec_at(Vexp, t) for t in tau_a]) + mylw = 1.0 - t_a = np.linspace(t0, t1, 100000) - alpha_a = [] + + plt.plot(tau_a, np.abs(Delta_zeta[:,0]), lw=mylw, label=r"$\Delta_{\zeta}a$") + plt.plot(tau_a, Delta_h[:,0], lw=mylw, label=r"$\Delta_h$") - Delta_zeta = [] - # Delta_Pzeta = [] - - Delta_h = [] - # Delta_Ph = [] - - zeta_a_a = [] - zeta_b_a = [] - Pzeta_a_a = [] - Pzeta_b_a = [] - - h_a_a = [] - h_b_a = [] - Ph_a_a = [] - Ph_b_a = [] - - nu_a = [] - m_a = [] - mnu_a = [] - dlnmnu_a = [] - - epsilon_a = [] - gamma_a = [] - sin_thetab_a = [] - cos_thetab_a = [] - - for t in t_a: - (Delta_zeta_v, _Delta_Pzeta_v) = adiab.eval_Delta(Vexp, t) - (Delta_h_v, _Delta_Ph_v) = gw.eval_Delta(Vexp, t) - - (zeta_a_v, zeta_b_v, Pzeta_a_v, Pzeta_b_v) = adiab.eval_QV(Vexp, t) - (h_a_v, h_b_v, Ph_a_v, Ph_b_v) = gw.eval_QV(Vexp, t) - - (epsilon_v, gamma_v, sin_thetab_v, cos_thetab_v) = gw.eval_AA(Vexp, t) - - epsilon_a.append(epsilon_v) - gamma_a.append(gamma_v) - sin_thetab_a.append(sin_thetab_v) - cos_thetab_a.append(cos_thetab_v) - - nu_adiab = adiab.eval_nu(Vexp, t, k) - mnu_adiab = adiab.eval_mnu(Vexp, t, k) - m_adiab = mnu_adiab / nu_adiab - dlnmnu_adiab = math.fabs(adiab.eval_dlnmnu(Vexp, t, k)) - - alpha = 0 - if t > 0.0: - alpha = +0.5 * t**2 / math.log(10.0) - else: - alpha = -0.5 * t**2 / math.log(10.0) - - alpha_a.append(alpha) - - nu_a.append(nu_adiab) - m_a.append(m_adiab) - mnu_a.append(mnu_adiab) - dlnmnu_a.append(dlnmnu_adiab) - - Delta_zeta.append(Delta_zeta_v) - Delta_h.append(Delta_h_v) - - zeta_a_a.append(zeta_a_v) - zeta_b_a.append(zeta_b_v) - - Pzeta_a_a.append(Pzeta_a_v) - Pzeta_b_a.append(Pzeta_b_v) - - h_a_a.append(h_a_v) - h_b_a.append(h_b_v) - - Ph_a_a.append(Ph_a_v) - Ph_b_a.append(Ph_b_v) - - mylw = 1 - - h_a_npa = np.array(h_a_a) - h_b_npa = np.array(h_b_a) - - # Ph_a_npa = np.array(Ph_a_a) - # Ph_b_npa = np.array(Ph_b_a) - - zeta_a_npa = np.array(zeta_a_a) - zeta_b_npa = np.array(zeta_b_a) - - # Pzeta_a_npa = np.array(Pzeta_a_a) - # Pzeta_b_npa = np.array(Pzeta_b_a) - - # plt.plot (alpha_a, Delta_zeta, lw=mylw, label = r'$\Delta_{\zeta}$') - # plt.plot (alpha_a, Delta_h, lw=mylw, label = r'$\Delta_{h}$') - - plt.plot(alpha_a, zeta_a_npa, lw=mylw, label=r"$\tilde{\zeta}^a$") - plt.plot(alpha_a, zeta_b_npa, lw=mylw, label=r"$\tilde{\zeta}^b$") - plt.plot(alpha_a, h_a_npa, lw=mylw, label=r"$\tilde{h}^a$") - plt.plot(alpha_a, h_b_npa, lw=mylw, label=r"$\tilde{h}^b$") - - # plt.plot (alpha_a, epsilon_a, lw=mylw, label = r'$\epsilon$') - # plt.plot (alpha_a, gamma_a, lw=mylw, label = r'$\gamma$') - # plt.plot (alpha_a, sin_thetab_a, lw=mylw, label = r'$\sin(\theta_b)$') - # plt.plot (alpha_a, cos_thetab_a, lw=mylw, label = r'$\cos(\theta_b)$') - - # plt.plot (alpha_a, nu_a, lw=mylw, label = r'$\nu_h$') - # plt.plot (alpha_a, m_a, lw=mylw, label = r'$m_h$') - # plt.plot (alpha_a, mnu_a, lw=mylw, label = r'$m_h\nu_h$') - # plt.plot (alpha_a, 1.0 / (np.array (mnu_a)), lw=mylw, label = r'$(m_h\nu_h)^{-1}$') - # plt.plot (alpha_a, dlnmnu_a, lw=mylw, label = r'$d\ln(m_h\nu_h)$') - - # plt.plot (alpha_a, (Ph_a_a * h_b_a), lw=mylw, label = r't_1') - # plt.plot (alpha_a, (Ph_b_a * h_a_a), lw=mylw, label = r't_2') - - plt.grid(b=True, which="both", linestyle=":", color="0.75", linewidth=0.5) + plt.grid(which="both", linestyle=":", color="0.75", linewidth=0.5) plt.legend(loc="upper left") # plt.xscale('symlog', linthreshx=1.0e-5) - plt.yscale("symlog", linthreshy=1.0e23) + plt.yscale("log") # plt.yscale('log', linthreshy=1.0e-20) plt.show() @@ -231,4 +135,4 @@ def test_zeta_exp_potential(new_config: bool = True) -> None: if __name__ == "__main__": - test_zeta_exp_potential() + test_zeta_exp_potential(new_config = False) diff --git a/meson.build b/meson.build index 127ce3b8f..4931c64b8 100644 --- a/meson.build +++ b/meson.build @@ -400,6 +400,9 @@ if get_option('mpi').auto() or get_option('mpi').enabled() # MPICH is not found by the mpi dependency, so we need to check for it manually if (not mpi_fortran_dep.found()) mpi_fortran_dep = dependency('mpichf90', required: false) + if mpi_fortran_dep.found() + numcosmo_conf.set('HAVE_MPIF90', true) + endif endif if get_option('mpi').enabled() and not mpi_c_dep.found() @@ -448,6 +451,9 @@ omp_fortran = dependency( language: 'fortran', required: false, ) +if omp_fortran.found() + numcosmo_conf.set('HAVE_FORTRAN_OPENMP', true) +endif ####################################################################################### # Checking for GObject instrospection: @@ -497,6 +503,9 @@ glib_dep = dependency('glib-2.0', version: glib_req) gobject_dep = dependency('gobject-2.0', version: glib_req) gio_dep = dependency('gio-2.0', version: glib_req) +# Using structured logging if available +# add_global_arguments('-DG_LOG_USE_STRUCTURED', language: 'c') + ####################################################################################### # Checking for GSL: ####################################################################################### diff --git a/meson_options.txt b/meson_options.txt index 2bdc21283..2abfaeec8 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -138,3 +138,15 @@ option( value: 'auto', description: 'Enable MPI support', ) + + +####################################################################################### +# pytest tap plugin +####################################################################################### + +option( + 'pytest_tap', + type: 'boolean', + value: true, + description: 'Enable pytest tap plugin', +) diff --git a/notebooks/primordial_perturbations/bounce_vector.ipynb b/notebooks/primordial_perturbations/bounce_vector.ipynb index 178983690..5627db843 100644 --- a/notebooks/primordial_perturbations/bounce_vector.ipynb +++ b/notebooks/primordial_perturbations/bounce_vector.ipynb @@ -75,22 +75,13 @@ "metadata": {}, "outputs": [], "source": [ - "try:\n", - " import gi\n", - "\n", - " gi.require_version(\"NumCosmo\", \"1.0\")\n", - " gi.require_version(\"NumCosmoMath\", \"1.0\")\n", - "except:\n", - " pass\n", - "\n", "import sys\n", "import math\n", - "import matplotlib as mpl\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "\n", - "from gi.repository import NumCosmo as Nc\n", - "from gi.repository import NumCosmoMath as Ncm\n", + "from numcosmo_py import Ncm\n", + "from numcosmo_py.plotting.tools import set_rc_params_article, latex_float\n", "\n", "%matplotlib inline" ] @@ -108,41 +99,7 @@ "metadata": {}, "outputs": [], "source": [ - "fig_width_pt = 246.0 * 2.0 # Get this from LaTeX using \\showthe\\columnwidth\n", - "inches_per_pt = 1.0 / 72.27 # Convert pt to inch\n", - "golden_mean = (math.sqrt(5) - 1.0) / 2.0 # Aesthetic ratio\n", - "fig_width = fig_width_pt * inches_per_pt # width in inches\n", - "fig_height = fig_width * golden_mean # height in inches\n", - "fig_size = [fig_width, fig_height]\n", - "\n", - "params = {\n", - " \"axes.labelsize\": 10,\n", - " \"font.size\": 10,\n", - " \"legend.fontsize\": 8,\n", - " \"xtick.labelsize\": 8,\n", - " \"ytick.labelsize\": 8,\n", - " \"text.usetex\": True,\n", - " \"figure.figsize\": fig_size,\n", - "}\n", - "\n", - "mpl.rcParams.update(params)\n", - "\n", - "\n", - "def latex_float(f):\n", - " float_str = \"{0:.2g}\".format(f)\n", - " if \"e\" in float_str:\n", - " base, exponent = float_str.split(\"e\")\n", - " if base == 1.0:\n", - " if exponent == 0.0:\n", - " return r\"1\"\n", - " else:\n", - " return r\"10^{{{1}}}\".format(int(exponent))\n", - " elif exponent == 0.0:\n", - " return r\"{0}\".format(base)\n", - " else:\n", - " return r\"{0} \\times 10^{{{1}}}\".format(base, int(exponent))\n", - " else:\n", - " return float_str" + "set_rc_params_article(ncol=2)" ] }, { @@ -192,6 +149,12 @@ " self.etab = 1.0 / (xb * math.sqrt(Omega_r))\n", " self.lp_RH = 1.0 / (Ncm.C.hubble_radius_hm1_planck() / h)\n", "\n", + " def set_k(self, k):\n", + " self.k = k\n", + "\n", + " def get_k(self):\n", + " return self.k\n", + "\n", " def y_eta(self, eta):\n", " eta2 = eta * eta\n", " etab2 = self.etab**2\n", @@ -220,16 +183,20 @@ "\n", " return yp_xb / y_xb\n", "\n", - " def do_eval_xi(self, model, eta, k):\n", + " def do_eval_xi(self, model, eta):\n", + " k = self.k\n", " return 2.0 * math.log(self.y_eta(eta)) + math.log(self.b * k)\n", "\n", - " def do_eval_nu(self, model, eta, k):\n", + " def do_eval_nu(self, model, eta):\n", + " k = self.k\n", " return self.b * k\n", "\n", - " def do_eval_F1(self, model, eta, k):\n", + " def do_eval_F1(self, model, eta):\n", + " k = self.k\n", " return 2.0 * self.H_eta(eta) / (2.0 * self.b * k)\n", "\n", - " def do_eval_F2(self, model, eta, k):\n", + " def do_eval_F2(self, model, eta):\n", + " k = self.k\n", " eta2 = eta**2\n", " etab2 = self.etab**2\n", " s1 = math.sqrt(1.0 + eta2 / etab2)\n", @@ -253,6 +220,12 @@ "outputs": [], "source": [ "csq1d = PyCSQ1DVecPert(b=1.0e-3, xb=5.0e29)\n", + "csq1d.set_ti(-1.0e6)\n", + "csq1d.set_vacuum_max_time(-1.0e-25)\n", + "csq1d.set_vacuum_reltol(1.0e-7)\n", + "csq1d.set_initial_condition_type(Ncm.CSQ1DInitialStateType.ADIABATIC4)\n", + "\n", + "state = Ncm.CSQ1DState()\n", "\n", "ki = 1.0e0\n", "kf = 1.0e9\n", @@ -277,23 +250,17 @@ "fig = plt.figure(dpi=120)\n", "\n", "max_etaf = -1.0e300\n", - "min_etai = +1.0e300\n", "\n", "for k in k_a:\n", " csq1d.set_k(k)\n", " csq1d.set_reltol(1.0e-12)\n", - " csq1d.set_save_evol(True)\n", "\n", - " (Found1, etai) = csq1d.find_adiab_time_limit(None, -1.0e15, -1.0e-25, 1.0e-7)\n", " (Found2, etafa) = csq1d.find_adiab_time_limit(None, +1.0e-25, +1.0e15, 1.0e0)\n", " etaf = etafa * 20\n", "\n", - " csq1d.set_ti(etai)\n", " csq1d.set_tf(etaf)\n", - " csq1d.set_init_cond_adiab(None, etai)\n", " csq1d.prepare()\n", "\n", - " min_etai = min(etai, min_etai)\n", " max_etaf = max(etaf, max_etaf)\n", "\n", " eta_a, eta_s = csq1d.get_time_array()\n", @@ -304,7 +271,8 @@ " eta_a = np.array(eta_a)\n", "\n", " for eta in eta_a:\n", - " (J11, J12, J22) = csq1d.get_J_at(None, eta)\n", + " csq1d.eval_at(None, eta, state)\n", + " (J11, J12, J22) = state.get_J()\n", "\n", " f = 16.0 * math.pi * csq1d.lp_RH**2\n", "\n", @@ -330,7 +298,7 @@ " label=r\"$\\vert\\Pi_h\\vert_{k_s = 10^{%0.2g}}$\" % math.log10(k),\n", " )\n", "\n", - "etac_a = np.geomspace(min_etai, -eta_s, 1000)\n", + "etac_a = np.geomspace(csq1d.get_ti(), -eta_s, 1000)\n", "etae_a = np.geomspace(eta_s, max_etaf, 1000)\n", "eta_a = np.concatenate((etac_a, etae_a))\n", "a_a = np.array([csq1d.y_eta(eta) for eta in eta_a])\n", @@ -338,7 +306,7 @@ "\n", "plt.plot(eta_a, a_a, lw=mylw, label=r\"$a(\\eta)$\")\n", "\n", - "plt.grid(b=True, which=\"both\", linestyle=\":\", color=\"0.75\", linewidth=0.5)\n", + "plt.grid(which=\"both\", linestyle=\":\", color=\"0.75\", linewidth=0.5)\n", "leg = plt.legend(loc=\"best\", ncol=2)\n", "plt.xscale(\"symlog\", linthresh=1.0e-30, linscale=4.0)\n", "plt.yscale(\"log\")\n", @@ -370,7 +338,6 @@ "fig = plt.figure(dpi=120)\n", "\n", "max_etaf = -1.0e300\n", - "min_etai = +1.0e300\n", "\n", "for k in k_a:\n", " csq1d.set_k(k)\n", @@ -378,16 +345,12 @@ " csq1d.set_save_evol(True)\n", " print(\"Computing k = %g\" % k)\n", "\n", - " (Found1, etai) = csq1d.find_adiab_time_limit(None, -1.0e15, -1.0e-25, 1.0e-7)\n", " (Found2, etafa) = csq1d.find_adiab_time_limit(None, +1.0e-25, +1.0e15, 1.0e0)\n", " etaf = etafa * 100\n", "\n", - " min_etai = min(etai, min_etai)\n", " max_etaf = max(etaf, max_etaf)\n", "\n", - " csq1d.set_ti(etai)\n", " csq1d.set_tf(etaf)\n", - " csq1d.set_init_cond_adiab(None, etai)\n", " csq1d.prepare()\n", "\n", " eta_a, eta_s = csq1d.get_time_array()\n", @@ -396,7 +359,8 @@ " eta_a = np.array(eta_a)\n", "\n", " for eta in eta_a:\n", - " (J11, J12, J22) = csq1d.get_J_at(None, eta)\n", + " csq1d.eval_at(None, eta, state)\n", + " (J11, J12, J22) = state.get_J()\n", " y = csq1d.y_eta(eta)\n", " f = 8.0 * csq1d.lp_RH**2 / math.pi\n", "\n", @@ -407,11 +371,12 @@ "\n", " plt.plot(eta_a, Php_a, lw=mylw, label=r\"$P_{v,k = 10^{%0.2g}}$\" % math.log10(k))\n", " eta = 0.0\n", - " (J11, J12, J22) = csq1d.get_J_at(None, eta)\n", + " csq1d.eval_at(None, eta, state)\n", + " (J11, J12, J22) = state.get_J()\n", " y = csq1d.y_eta(eta)\n", " f = 8.0 * csq1d.lp_RH**2 / math.pi\n", "\n", - "etac_a = np.geomspace(min_etai, -eta_s, 1000)\n", + "etac_a = np.geomspace(csq1d.get_ti(), -eta_s, 1000)\n", "etae_a = np.geomspace(eta_s, max_etaf, 1000)\n", "eta_a = np.concatenate((etac_a, etae_a))\n", "a_a = np.array([csq1d.y_eta(eta) for eta in eta_a])\n", @@ -429,7 +394,7 @@ " c=\"gray\",\n", ")\n", "\n", - "plt.grid(b=True, which=\"both\", linestyle=\":\", color=\"0.75\", linewidth=0.5)\n", + "plt.grid(which=\"both\", linestyle=\":\", color=\"0.75\", linewidth=0.5)\n", "leg = plt.legend(loc=\"best\", ncol=2)\n", "plt.xscale(\"symlog\", linthresh=1.0e-30, linscale=4.0)\n", "plt.yscale(\"log\")\n", @@ -459,14 +424,11 @@ " csq1d.set_save_evol(True)\n", " print(\"Computing k = %g\" % k)\n", "\n", - " (Found1, etai) = csq1d.find_adiab_time_limit(None, -1.0e15, -1.0e-25, 1.0e-7)\n", - "\n", - " csq1d.set_ti(etai)\n", " csq1d.set_tf(etaf)\n", - " csq1d.set_init_cond_adiab(None, etai)\n", " csq1d.prepare()\n", "\n", - " (J11, J12, J22) = csq1d.get_J_at(None, etaf)\n", + " csq1d.eval_at(None, etaf, state)\n", + " (J11, J12, J22) = state.get_J()\n", " y = csq1d.y_eta(etaf)\n", " f = 8.0 * k * csq1d.lp_RH**2 / math.pi\n", " Php_a.append(f * 0.5 * J22 / y**4)\n", @@ -476,7 +438,7 @@ "\n", "plt.plot(k_a, Php_a, lw=mylw, label=r\"$P_{h^\\prime}(%s)$\" % latex_float(etaf))\n", "\n", - "plt.grid(b=True, which=\"both\", linestyle=\":\", color=\"0.75\", linewidth=0.5)\n", + "plt.grid(which=\"both\", linestyle=\":\", color=\"0.75\", linewidth=0.5)\n", "leg = plt.legend(loc=\"best\")\n", "\n", "plt.xscale(\"log\")\n", @@ -511,5 +473,5 @@ } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 } diff --git a/notebooks/primordial_perturbations/magnetic_dust_bounce.ipynb b/notebooks/primordial_perturbations/magnetic_dust_bounce.ipynb index f57d7778c..dc2619bca 100644 --- a/notebooks/primordial_perturbations/magnetic_dust_bounce.ipynb +++ b/notebooks/primordial_perturbations/magnetic_dust_bounce.ipynb @@ -61,8 +61,9 @@ "\\end{equation}\n", "for the mode $k$. It is convenient to rewrite $F$ as\n", "\\begin{equation}\n", - "F = \\frac{1}{4}\\left\\{1+c_*^2\\frac{\\left(t/t_b\\right)^2+3}{\\left[\\left(t/t_b\\right)^2+1\\right]^2}\\right\\}, \\qquad c_* \\equiv \\frac{2}{\\sqrt3}\\frac{l_*}{t_b}.\n", + "F = \\frac{1}{4}\\left\\{1+c_*^2\\frac{\\left(t/t_b\\right)^2+3}{\\left[\\left(t/t_b\\right)^2+1\\right]^2}\\right\\}, \\qquad c_* \\equiv \\frac{2}{\\sqrt{3}}\\frac{l_*}{t_b}.\n", "\\end{equation}\n", + "where $t_b$ is defined above.\n", "\n", "\n", "## Loading NumCosmo\n", @@ -76,28 +77,20 @@ "metadata": {}, "outputs": [], "source": [ - "try:\n", - " import gi\n", - "\n", - " gi.require_version(\"NumCosmo\", \"1.0\")\n", - " gi.require_version(\"NumCosmoMath\", \"1.0\")\n", - "except:\n", - " pass\n", - "\n", "import sys\n", "import math\n", - "import matplotlib\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", - "from gi.repository import NumCosmo as Nc\n", - "from gi.repository import NumCosmoMath as Ncm" + "\n", + "from numcosmo_py import Ncm\n", + "from numcosmo_py.plotting.tools import set_rc_params_article, latex_float" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "# A helper function to write latex formatted numbers" + "# Latex definition" ] }, { @@ -106,16 +99,7 @@ "metadata": {}, "outputs": [], "source": [ - "def latex_float(f):\n", - " float_str = \"{0:.2g}\".format(f)\n", - " if \"e\" in float_str:\n", - " base, exponent = float_str.split(\"e\")\n", - " if base == 1.0:\n", - " return r\"10^{{{1}}}\".format(int(exponent))\n", - " else:\n", - " return r\"{0} \\times 10^{{{1}}}\".format(base, int(exponent))\n", - " else:\n", - " return float_str" + "set_rc_params_article(ncol=2)" ] }, { @@ -153,7 +137,7 @@ "outputs": [], "source": [ "class PyCSQ1DMagDust(Ncm.CSQ1D):\n", - " def __init__(self, Omega_m=0.3, xb=1.0e25, cc=1.0, h=0.7, a_ns=1.0e-12):\n", + " def __init__(self, Omega_m=0.3, xb=1.0e25, cc=1.0e-50, h=0.7, a_ns=1.0e-12):\n", " Ncm.CSQ1D.__init__(self)\n", "\n", " self.h = h\n", @@ -163,6 +147,13 @@ " self.cc = cc\n", " self.RH = Ncm.C.c() / (1.0e5 * h) # Hubble radius in units of Mpc\n", " self.a_ns = a_ns\n", + " self.k = 1.0\n", + "\n", + " def set_k(self, k):\n", + " self.k = k\n", + "\n", + " def get_k(self):\n", + " return self.k\n", "\n", " # Scale factor over scale factor today\n", " def y_t(self, t):\n", @@ -206,19 +197,23 @@ " self.cc = math.sqrt(f) * w ** (3.0 / 2.0) / math.sqrt(1.0 + 2.0 / w**3)\n", " return self.cc\n", "\n", - " def do_eval_xi(self, model, t, k):\n", + " def do_eval_xi(self, model, t):\n", + " k = self.k\n", " return math.log(k) + math.log(self.F_t(t))\n", "\n", - " def do_eval_nu(self, model, t, k):\n", + " def do_eval_nu(self, model, t):\n", + " k = self.k\n", " return k / self.y_t(t)\n", "\n", - " def do_eval_nu2(self, model, t, k):\n", + " def do_eval_nu2(self, model, t):\n", + " k = self.k\n", " return (k / self.y_t(t)) ** 2\n", "\n", - " def do_eval_m(self, model, t, k):\n", + " def do_eval_m(self, model, t):\n", " return self.y_t(t) * self.F_t(t)\n", "\n", - " def do_eval_F1(self, model, t, k):\n", + " def do_eval_F1(self, model, t):\n", + " k = self.k\n", " cc = self.cc\n", " cc2 = cc**2\n", " tbar = t / self.tb\n", @@ -231,19 +226,18 @@ " T2 = tbar2 + 1.0\n", " T3 = T2**2\n", " T4 = cc2 * (tbar2 + 3.0)\n", - " return (T1 / (T2 * (T3 + T4) * self.tb)) / (\n", - " 2.0 * self.do_eval_nu(model, t, k)\n", - " )\n", + " return (T1 / (T2 * (T3 + T4) * self.tb)) / (2.0 * self.do_eval_nu(model, t))\n", " else:\n", " T1 = -2.0 * cc2 * tbar * (1.0 + 5.0 / tbar2)\n", " T2 = 1.0 + 1.0 / tbar2\n", " T3 = T2**2\n", " T4 = cc2 * (1.0 + 3.0 / tbar2)\n", " return (T1 / (T2 * (T3 + T4 / tbar2) * tbar4 * self.tb)) / (\n", - " 2.0 * self.do_eval_nu(model, t, k)\n", + " 2.0 * self.do_eval_nu(model, t)\n", " )\n", "\n", - " def do_eval_F2(self, model, t, k):\n", + " def do_eval_F2(self, model, t):\n", + " k = self.k\n", " cc = self.cc\n", " cc2 = cc**2\n", " tbar = t / self.tb\n", @@ -258,7 +252,7 @@ " T4 = -15.0 + 7.0 * tbar2 * (8.0 + tbar2)\n", " T5 = (T3 + cc2 * (3.0 + tbar2)) ** 2\n", " return (T1 * (T2 + T3 * T4) / (T3 * T5)) / (\n", - " 2.0 * self.do_eval_nu(model, t, k)\n", + " 2.0 * self.do_eval_nu(model, t)\n", " ) ** 2\n", " else:\n", " T1 = (2.0 / 3.0) * cc2 / self.tb**2\n", @@ -267,15 +261,17 @@ " T4 = -15.0 / tbar4 + 7.0 * (8.0 / tbar2 + 1.0)\n", " T5 = (T3 + cc2 * (3.0 / tbar4 + 1.0 / tbar2)) ** 2\n", " return (T1 * (T2 / tbar2 + T3 * T4) / (T3 * T5 * tbar4)) / (\n", - " 2.0 * self.do_eval_nu(model, t, k)\n", + " 2.0 * self.do_eval_nu(model, t)\n", " ) ** 2\n", "\n", " def do_prepare(self, model):\n", " pass\n", "\n", " def eval_PB_PE(self, t, c_A2=0.0, c_PiA2=0.0):\n", + " state = Ncm.CSQ1DState()\n", " if (c_A2 == 0.0) or (c_PiA2 == 0.0):\n", - " (J11, J12, J22) = self.get_J_at(None, t)\n", + " self.eval_at(None, t, state)\n", + " (J11, J12, J22) = state.get_J()\n", " A2 = 0.5 * J11 if c_A2 == 0.0 else c_A2\n", " PiA2 = 0.5 * J22 if c_PiA2 == 0.0 else c_PiA2\n", " F = self.F_t(t)\n", @@ -283,7 +279,7 @@ " k = self.get_k()\n", " y = self.y_t(t)\n", " RH = self.RH\n", - " m = self.eval_m(None, t, k)\n", + " m = self.eval_m(None, t)\n", " PE = PiA2 * (k / y) ** 3 / (2.0 * math.pi**2 * RH**4 * m)\n", " PB = m * A2 * (k / y) ** 5 / (2.0 * math.pi**2 * RH**4)\n", "\n", @@ -297,6 +293,12 @@ "outputs": [], "source": [ "csq1d = PyCSQ1DMagDust(cc=1.0e20, xb=1.0e30)\n", + "csq1d.set_initial_condition_type(Ncm.CSQ1DInitialStateType.ADIABATIC4)\n", + "csq1d.set_ti(-1.0e6)\n", + "csq1d.set_vacuum_max_time(-1.0e-25)\n", + "csq1d.set_vacuum_reltol(1.0e-3)\n", + "\n", + "state = Ncm.CSQ1DState()\n", "\n", "print(\"c = % 22.15g\" % csq1d.set_max_c(1.0e-2))\n", "csq1d.cc = 1.0e0\n", @@ -312,9 +314,8 @@ "kf = 4.0e3\n", "k_a = np.geomspace(ki, kf, 3)\n", "\n", - "csq1d.set_k(kf)\n", + "csq1d.set_k(ki)\n", "(Found2, tf) = csq1d.find_adiab_time_limit(None, +1.0e-25, +1.0e15, 1.0e0)\n", - "\n", "print(Found2, tf)" ] }, @@ -324,10 +325,9 @@ "metadata": {}, "outputs": [], "source": [ - "plt.figure(figsize=(14, 7))\n", + "plt.figure()\n", "\n", "max_tf = -1.0e300\n", - "min_ti = +1.0e300\n", "\n", "colors = [\"r\", \"g\", \"b\"]\n", "i = 0\n", @@ -337,20 +337,11 @@ " csq1d.set_reltol(1.0e-12)\n", " csq1d.set_save_evol(True)\n", "\n", - " # print (csq1d.eval_adiab_at (None, -5))\n", - "\n", - " (Found1, ti) = csq1d.find_adiab_time_limit(None, -1.0e15, -1.0e-25, 1.0e-3)\n", - " # print (Found1, ti)\n", - "\n", - " (Found2, tfa) = csq1d.find_adiab_time_limit(None, +1.0e-25, +1.0e15, 1.0e0)\n", + " (_, tfa) = csq1d.find_adiab_time_limit(None, +1.0e-25, +1.0e15, 1.0e0)\n", " tf = tfa * 20\n", - "\n", - " min_ti = min(ti, min_ti)\n", " max_tf = max(tf, max_tf)\n", "\n", - " csq1d.set_ti(ti)\n", " csq1d.set_tf(tf)\n", - " csq1d.set_init_cond_adiab(None, ti)\n", " csq1d.prepare()\n", "\n", " t_a, t_s = csq1d.get_time_array()\n", @@ -361,7 +352,8 @@ " t_a = np.array(t_a)\n", "\n", " for t in t_a:\n", - " (J11, J12, J22) = csq1d.get_J_at(None, t)\n", + " csq1d.eval_at(None, t, state)\n", + " (J11, J12, J22) = state.get_J()\n", " Abs_phi2_a.append(0.5 * J11)\n", " Abs_Pphi2_a.append(0.5 * J22)\n", "\n", @@ -394,7 +386,7 @@ "\n", " i = i + 1\n", "\n", - "tc_a = np.geomspace(min_ti, -t_s, 1000)\n", + "tc_a = np.geomspace(csq1d.get_ti(), -t_s, 1000)\n", "te_a = np.geomspace(t_s, max_tf, 1000)\n", "t_a = np.concatenate((tc_a, te_a))\n", "\n", @@ -428,7 +420,7 @@ "metadata": {}, "outputs": [], "source": [ - "plt.figure(figsize=(14, 7))\n", + "plt.figure()\n", "\n", "max_tf = -1.0e300\n", "min_ti = +1.0e300\n", @@ -441,20 +433,12 @@ " csq1d.set_reltol(1.0e-12)\n", " csq1d.set_save_evol(True)\n", "\n", - " # print (csq1d.eval_adiab_at (None, -5))\n", - "\n", - " (Found1, ti) = csq1d.find_adiab_time_limit(None, -1.0e15, -1.0e-25, 1.0e-3)\n", - " # print (Found1, ti)\n", - "\n", " (Found2, tfa) = csq1d.find_adiab_time_limit(None, +1.0e-25, +1.0e15, 1.0e0)\n", " tf = tfa * 20\n", "\n", - " min_ti = min(ti, min_ti)\n", " max_tf = max(tf, max_tf)\n", "\n", - " csq1d.set_ti(ti)\n", " csq1d.set_tf(tf)\n", - " csq1d.set_init_cond_adiab(None, ti)\n", " csq1d.prepare()\n", "\n", " t_a, t_s = csq1d.get_time_array()\n", @@ -495,7 +479,7 @@ " else:\n", " i = i + 1\n", "\n", - "tc_a = np.geomspace(min_ti, -t_s, 1000)\n", + "tc_a = np.geomspace(csq1d.get_ti(), -t_s, 1000)\n", "te_a = np.geomspace(t_s, max_tf, 1000)\n", "t_a = np.concatenate((tc_a, te_a))\n", "\n", @@ -503,7 +487,7 @@ "# plt.plot (t_a, [csq1d.Omega_m_t (t) for t in t_a], lw=mylw, label = r'$\\rho_m$')\n", "# plt.axhline (y = 1.0)\n", "\n", - "# plt.grid (b=True, which='both', linestyle=':', color='0.75', linewidth=0.5)\n", + "plt.grid(which=\"both\", linestyle=\":\", color=\"0.75\", linewidth=0.5)\n", "leg = plt.legend(loc=\"best\", ncol=2, fontsize=13)\n", "plt.xscale(\"symlog\", linthresh=t_s)\n", "plt.yscale(\"log\")\n", @@ -529,7 +513,7 @@ "metadata": {}, "outputs": [], "source": [ - "fig = plt.figure(figsize=(16, 8))\n", + "fig = plt.figure()\n", "ax = fig.add_subplot(111)\n", "\n", "k_a = np.geomspace(ki, kf, 10)\n", @@ -546,20 +530,20 @@ " csq1d.set_reltol(1.0e-12)\n", " csq1d.set_save_evol(True)\n", "\n", - " (Found1, ti) = csq1d.find_adiab_time_limit(None, -1.0e15, -1.0e-25, 1.0e-3)\n", " (Found2, tfa) = csq1d.find_adiab_time_limit(None, +1.0e-25, +1.0e15, 1.0e0)\n", " tf = tfa * 20\n", "\n", - " csq1d.set_ti(ti)\n", " csq1d.set_tf(tf)\n", - " csq1d.set_init_cond_adiab(None, ti)\n", " csq1d.prepare()\n", "\n", " t_a, t_s = csq1d.get_time_array()\n", " t_a = np.array(t_a)\n", " t_ra = t_a > tfa\n", "\n", - " JM = np.array([np.array(csq1d.get_J_at(None, t)) * conv_g2 for t in t_a[t_ra]])\n", + " state = Ncm.CSQ1DState()\n", + " JM = np.array(\n", + " [np.array(csq1d.eval_at(None, t, state).get_J()) * conv_g2 for t in t_a[t_ra]]\n", + " )\n", " phiAmp = 0.5 * max(JM[:, 0])\n", " PphiAmp = 0.5 * max(JM[:, 2])\n", "\n", @@ -668,5 +652,5 @@ } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 } diff --git a/notebooks/primordial_perturbations/single_fluid_qb.ipynb b/notebooks/primordial_perturbations/single_fluid_qb.ipynb new file mode 100644 index 000000000..43252a178 --- /dev/null +++ b/notebooks/primordial_perturbations/single_fluid_qb.ipynb @@ -0,0 +1,420 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "a5537045-5ff7-4a4f-9ae0-3f71a250f6f7", + "metadata": {}, + "outputs": [], + "source": [ + "from numcosmo_py import Ncm, Nc\n", + "import sys\n", + "import math\n", + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "\n", + "from scipy.special import erfc\n", + "\n", + "from numcosmo_py.plotting.tools import set_rc_params_article, latex_float" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c51de52a-3e9f-41d0-abbf-42273e752ca6", + "metadata": {}, + "outputs": [], + "source": [ + "__name__ = \"NcContext\"\n", + "\n", + "Ncm.cfg_init()\n", + "Ncm.cfg_set_log_handler(lambda msg: sys.stdout.write(msg) and sys.stdout.flush())" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "99c566ef-a694-4756-bb1f-47f19aaed50c", + "metadata": {}, + "outputs": [], + "source": [ + "set_rc_params_article(ncol=2)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "18a16757-a85b-4b0e-a7e4-7ce5e08501e0", + "metadata": {}, + "outputs": [], + "source": [ + "qgw = Nc.HICosmoQGW.new()\n", + "adiab = Nc.HIPertAdiab.new()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6c8eee25-27f7-4ad2-a62d-a2a19226f48c", + "metadata": {}, + "outputs": [], + "source": [ + "qgw.props.xb = 1.0e35\n", + "qgw.props.w = 1.0e-18" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d4b4bf8d-50b2-40c8-8532-59a3712daefb", + "metadata": {}, + "outputs": [], + "source": [ + "adiab.set_k(1.0e-1)\n", + "adiab.set_ti(-300.0)\n", + "adiab.set_tf(-1.0)\n", + "adiab.set_reltol(1.0e-11)\n", + "adiab.set_initial_condition_type(Ncm.CSQ1DInitialStateType.ADIABATIC4)\n", + "adiab.set_vacuum_max_time(-1.0e-15)\n", + "adiab.set_vacuum_reltol(1.0e-7)\n", + "\n", + "Found, tAD = adiab.find_adiab_time_limit(\n", + " qgw, adiab.get_ti(), adiab.get_vacuum_max_time(), adiab.get_vacuum_reltol()\n", + ")\n", + "\n", + "print(f\"Found: {Found}, tAD: {tAD}\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "804cf6e5-dfc7-4286-ac78-a5c9152b2763", + "metadata": {}, + "outputs": [], + "source": [ + "adiab.prepare(qgw)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e530eb26-a982-4535-8648-9d94ddf04dc5", + "metadata": {}, + "outputs": [], + "source": [ + "ta, ts = adiab.get_time_array()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fb7981b8-3870-4bca-b603-7e0ce02e4280", + "metadata": {}, + "outputs": [], + "source": [ + "Pzeta = [adiab.eval_powspec_zeta_at(qgw, t) for t in ta]\n", + "PPsi = [adiab.eval_powspec_Psi_at(qgw, t) for t in ta]\n", + "Pdrho = [adiab.eval_powspec_drho_at(qgw, t) for t in ta]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "555ba73a-ec5a-4dfa-9ab7-8ddc46af0df5", + "metadata": {}, + "outputs": [], + "source": [ + "fig = plt.figure()\n", + "\n", + "plt.plot(ta, Pzeta, label=\"$P_\\zeta$\")\n", + "plt.plot(ta, PPsi, label=\"$P_\\Psi$\")\n", + "plt.plot(ta, Pdrho, label=r\"$P_{\\delta_\\rho}$\")\n", + "\n", + "plt.hlines(2.0e-9, xmin=min(ta), xmax=max(ta))\n", + "plt.yscale(\"log\")\n", + "\n", + "plt.grid()\n", + "plt.legend()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "867871b9-1ecc-4635-8b20-909bd92bc1b3", + "metadata": {}, + "outputs": [], + "source": [ + "adiab.eval_cosmic_time(qgw, -170)\n", + "pass" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3edb486c-a1a6-4156-9cc9-92dde501ec5b", + "metadata": {}, + "outputs": [], + "source": [ + "for k in np.geomspace(1.0e2, 1.0e17, 10):\n", + " adiab.set_k(k)\n", + " tau_min = -qgw.eval_tau_jeans(k)\n", + " tau_max = -qgw.eval_tau_hubble(k)\n", + " tau_l_a = np.linspace(tau_min, tau_max, 100)\n", + "\n", + " plt.plot(\n", + " tau_l_a,\n", + " [adiab.eval_delta_critial(qgw, tau) for tau in tau_l_a],\n", + " label=rf\"$k={latex_float(k)}$\",\n", + " )\n", + "\n", + "plt.yscale(\"log\")\n", + "plt.legend()\n", + "pass" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "23da41ab-e85b-4b9e-acea-85cf9f4c3f2f", + "metadata": {}, + "outputs": [], + "source": [ + "fig = plt.figure()\n", + "\n", + "ka = np.geomspace(1.0e4, 2.0e17, 1000)\n", + "tau_jeans_a = [-qgw.eval_tau_jeans(k) for k in ka]\n", + "tau_hubble_a = [-qgw.eval_tau_hubble(k) for k in ka]\n", + "tau_a = np.linspace(min(tau_jeans_a), max(tau_hubble_a), 120)\n", + "\n", + "plt.plot(ka, tau_jeans_a, label=rf\"$\\tau_\\mathrm{{Jeans}}$\")\n", + "plt.plot(ka, tau_hubble_a, label=rf\"$\\tau_\\mathrm{{Hubble}}$\")\n", + "\n", + "plt.xscale(\"log\")\n", + "\n", + "plt.grid()\n", + "plt.legend()\n", + "pass" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2f5d6059-ceb5-4a2a-8017-f11f42e84869", + "metadata": {}, + "outputs": [], + "source": [ + "ka = np.geomspace(1.0e2, 1.0e20, 1000)\n", + "tau_a = np.linspace(-120.0, -10.0, 500)\n", + "adiab.prepare_spectrum(qgw, ka, tau_a)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b2493ebe-d0ba-4295-873d-3ddf5ed74837", + "metadata": {}, + "outputs": [], + "source": [ + "ka = np.geomspace(1.0e2, 1.0e21, 1000)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2f3ea952-2793-4aee-bb8b-222bd4ce3d18", + "metadata": {}, + "outputs": [], + "source": [ + "Pzetak = adiab.eval_powspec_zeta(qgw)\n", + "# Pzetak.set_kmax(1.0e21)\n", + "PPsik = adiab.eval_powspec_Psi(qgw)\n", + "# PPsik.set_kmax(1.0e21)\n", + "Pdrhok = adiab.eval_powspec_drho(qgw)\n", + "# Pdrhok.set_kmax(1.0e21)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "31a64851-bf8a-4fc5-b6ae-8acf86933147", + "metadata": {}, + "outputs": [], + "source": [ + "fig = plt.figure()\n", + "\n", + "k = 1.0e15\n", + "\n", + "ymin = 1.0e300\n", + "ymax = 1.0e-300\n", + "\n", + "tau = -qgw.eval_tau_jeans(k)\n", + "\n", + "Ps = [k**3 * 0.5 / np.pi**2 * Pzetak.eval(None, tau, k) for tau in tau_a]\n", + "plt.plot(tau_a, Ps, label=f\"$P_\\zeta({latex_float(tau)})$\")\n", + "\n", + "ymin = np.min(np.concatenate((Ps, [ymin])))\n", + "ymax = np.max(np.concatenate((Ps, [ymax])))\n", + "\n", + "Ps = [k**3 * 0.5 / np.pi**2 * PPsik.eval(None, tau, k) for tau in tau_a]\n", + "plt.plot(tau_a, Ps, label=f\"$P_\\Psi({latex_float(tau)})$\")\n", + "\n", + "ymin = np.min(np.concatenate((Ps, [ymin])))\n", + "ymax = np.max(np.concatenate((Ps, [ymax])))\n", + "\n", + "Ps = [k**3 * 0.5 / np.pi**2 * Pdrhok.eval(None, tau, k) for tau in tau_a]\n", + "plt.plot(tau_a, Ps, label=f\"$P_\\Psi({latex_float(tau)})$\")\n", + "\n", + "ymin = np.min(np.concatenate((Ps, [ymin])))\n", + "ymax = np.max(np.concatenate((Ps, [ymax])))\n", + "\n", + "plt.vlines([-qgw.eval_tau_jeans(k), -qgw.eval_tau_hubble(k)], ymin=ymin, ymax=ymax)\n", + "\n", + "plt.yscale(\"log\")\n", + "\n", + "pass" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e21d385e", + "metadata": {}, + "outputs": [], + "source": [ + "fig = plt.figure()\n", + "\n", + "ka = np.geomspace(1.0e2, 1.0e21, 1000)\n", + "\n", + "tau_plot_a = tau_a[::40]\n", + "for tau in tau_plot_a:\n", + " Ps = [k**3 * 0.5 / np.pi**2 * Pzetak.eval(None, tau, k) for k in ka]\n", + " plt.plot(ka, Ps, label=f\"$P_\\zeta({latex_float(tau)})$\")\n", + "\n", + "plt.xscale(\"log\")\n", + "plt.yscale(\"log\")\n", + "plt.legend()\n", + "pass" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "229e071d-ccf7-491b-927b-9d9fac4a136a", + "metadata": {}, + "outputs": [], + "source": [ + "fig = plt.figure()\n", + "\n", + "for tau in tau_plot_a:\n", + " plt.plot(\n", + " ka,\n", + " [k**3 * 0.5 / np.pi**2 * PPsik.eval(None, tau, k) for k in ka],\n", + " label=rf\"$P_\\Psi({latex_float(tau)})$\",\n", + " )\n", + "\n", + "plt.xscale(\"log\")\n", + "plt.yscale(\"log\")\n", + "plt.legend()\n", + "pass" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ca049064-099c-40d8-a36a-f827252c681d", + "metadata": {}, + "outputs": [], + "source": [ + "fig = plt.figure()\n", + "\n", + "for tau in tau_plot_a:\n", + " plt.plot(\n", + " ka,\n", + " [k**3 * 0.5 / np.pi**2 * Pdrhok.eval(None, tau, k) for k in ka],\n", + " label=rf\"$P_{{\\delta_\\rho}}({latex_float(tau)})$\",\n", + " )\n", + "\n", + "plt.xscale(\"log\")\n", + "plt.yscale(\"log\")\n", + "plt.legend()\n", + "plt.grid()\n", + "pass" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "15dbfa20", + "metadata": {}, + "outputs": [], + "source": [ + "def compute_sigma_at_jeans(kJ):\n", + " # Compute the time at which the wave-number k enters the Jeans scale\n", + " tau_k_jeans = -qgw.eval_tau_jeans(kJ)\n", + " # Compute the Hubble scale at that time\n", + " kH = np.abs(qgw.eval_hubble(tau_k_jeans) / qgw.eval_x(tau_k_jeans))\n", + " # Create a range of wave-numbers from the Jeans scale to the Hubble scale\n", + " ka = np.geomspace(kH, kJ, 50)\n", + " # Create a range of times from the time the wave-number k enters the Jeans scale to\n", + " # the time it enters the Hubble scale\n", + " tau_a = np.linspace(tau_k_jeans - 1.0e-1, tau_k_jeans + 1.0e-1, 6)\n", + " # Prepare the spectrum for the range of wave-numbers and times\n", + " adiab.prepare_spectrum(qgw, ka, tau_a)\n", + " # Evaluate the power spectrum of the energy density perturbation at the time\n", + " # the wave-number kJ enters the Jeans scale.\n", + " Pdrhok = adiab.eval_powspec_drho(qgw)\n", + " # Evaluate the variance of the energy density perturbation at the time\n", + " # the wave-number kJ enters the Jeans scale.\n", + " sigma_drho = Pdrhok.sigma_tophat_R(qgw, 1.0e-4, tau_k_jeans, 1.0 / kJ)\n", + "\n", + " # Compute the critial delta for\n", + " adiab.set_k(kJ)\n", + " delta_c = adiab.eval_delta_critial(qgw, tau_k_jeans)\n", + "\n", + " return delta_c, sigma_drho" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "033d8a20", + "metadata": {}, + "outputs": [], + "source": [ + "fig = plt.figure()\n", + "\n", + "ka = np.geomspace(1.0e10, 1.0e15, 10)\n", + "sigma_delta = np.array([compute_sigma_at_jeans(k) for k in ka])\n", + "\n", + "plt.plot(1.0 / ka, sigma_delta[:, 1], label=r\"$\\sigma(\\tau_J, \\lambda_J)$\")\n", + "plt.plot(1.0 / ka, sigma_delta[:, 0], label=r\"$\\delta_c(\\tau_J)$\")\n", + "\n", + "plt.xscale(\"log\")\n", + "plt.yscale(\"log\")\n", + "plt.xlabel(\"$\\lambda$\")\n", + "plt.legend()\n", + "pass" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/notebooks/primordial_perturbations/vacuum_study.ipynb b/notebooks/primordial_perturbations/vacuum_study.ipynb index c33498bc9..d1ca06726 100644 --- a/notebooks/primordial_perturbations/vacuum_study.ipynb +++ b/notebooks/primordial_perturbations/vacuum_study.ipynb @@ -41,28 +41,14 @@ "metadata": {}, "outputs": [], "source": [ - "try:\n", - " import gi\n", - "\n", - " gi.require_version(\"NumCosmo\", \"1.0\")\n", - " gi.require_version(\"NumCosmoMath\", \"1.0\")\n", - "except:\n", - " pass\n", - "\n", "import sys\n", "import math\n", - "import matplotlib as mpl\n", "import matplotlib.pyplot as plt\n", - "import matplotlib.gridspec as gridspec\n", - "import matplotlib.animation as animation\n", "import matplotlib.cm as cm\n", - "from mpl_toolkits.mplot3d import Axes3D\n", "import numpy as np\n", "\n", - "from IPython.display import HTML\n", - "\n", - "from gi.repository import NumCosmo as Nc\n", - "from gi.repository import NumCosmoMath as Ncm\n", + "from numcosmo_py import Ncm, Nc\n", + "from numcosmo_py.plotting.tools import set_rc_params_article, latex_float\n", "\n", "%matplotlib inline" ] @@ -80,42 +66,7 @@ "metadata": {}, "outputs": [], "source": [ - "fig_width_pt = 246.0 * 2.0 # Get this from LaTeX using \\showthe\\columnwidth\n", - "inches_per_pt = 1.0 / 72.27 # Convert pt to inch\n", - "golden_mean = (math.sqrt(5) - 1.0) / 2.0 # Aesthetic ratio\n", - "fig_width = fig_width_pt * inches_per_pt # width in inches\n", - "fig_height = fig_width * golden_mean # height in inches\n", - "fig_size = [fig_width, fig_height]\n", - "\n", - "params = {\n", - " \"axes.labelsize\": 10,\n", - " \"font.size\": 10,\n", - " \"legend.fontsize\": 8,\n", - " \"xtick.labelsize\": 8,\n", - " \"ytick.labelsize\": 8,\n", - " \"text.usetex\": True,\n", - " \"figure.figsize\": fig_size,\n", - " \"animation.embed_limit\": 2**128,\n", - "}\n", - "\n", - "mpl.rcParams.update(params)\n", - "\n", - "\n", - "def latex_float(f):\n", - " float_str = \"{0:.1e}\".format(f)\n", - " if \"e\" in float_str:\n", - " base, exponent = float_str.split(\"e\")\n", - " if base == 1.0:\n", - " if exponent == 0.0:\n", - " return r\"1\"\n", - " else:\n", - " return r\"10^{{{1}}}\".format(int(exponent))\n", - " elif exponent == 0.0:\n", - " return r\"{0}\".format(base)\n", - " else:\n", - " return r\"{0} \\times 10^{{{1}}}\".format(base, int(exponent))\n", - " else:\n", - " return float_str" + "set_rc_params_article(ncol=2)" ] }, { @@ -175,6 +126,19 @@ "colors = cm.copper(np.linspace(0, 1, len(r_a)))" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "state_prop0 = Ncm.CSQ1DState.new()\n", + "state_prop0.set_up(Ncm.CSQ1DFrame.NONADIAB1, 0.0, 0.0, 0.0)\n", + "\n", + "state_prop = Ncm.CSQ1DState.new()\n", + "state_nonadiab = Ncm.CSQ1DState.new()" + ] + }, { "cell_type": "code", "execution_count": null, @@ -191,72 +155,58 @@ "fig, ax = plt.subplots(dpi=120)\n", "axin1 = ax.inset_axes([0.09, 0.5, 0.42, 0.42])\n", "\n", - "frame = 0\n", - "\n", - "x0_a = []\n", - "lny0_a = []\n", - "xV_a = []\n", - "lnyV_a = []\n", + "frame = Ncm.CSQ1DFrame.ORIG\n", "\n", - "chiV0 = 0.0\n", - "UpV0 = 0.0\n", - "\n", - "gammaV = UpV0 - 0.5 * math.log1p(chiV0 * chiV0)\n", - "alphaV = math.asinh(chiV0)\n", + "evol_prop = []\n", + "evol_nonadiab = []\n", "\n", "for t in t_a:\n", - " (chi, Up) = csq1d.evolve_prop_vector_chi_Up(None, t, frame, chiV0, UpV0)\n", - " (chiV, UpV) = csq1d.eval_nonadiab_at(None, 0, t)\n", + " csq1d.evolve_prop_vector(None, state_prop0, frame, t, state_prop)\n", + " csq1d.compute_nonadiab(None, t, state_nonadiab)\n", "\n", - " x0_a.append(chi)\n", - " lny0_a.append(math.sinh(-Up) + 0.5 * math.exp(-Up) * chi**2)\n", + " csq1d.change_frame(None, state_nonadiab, frame)\n", "\n", - " xV_a.append(chiV)\n", - " lnyV_a.append(math.sinh(-UpV) + 0.5 * math.exp(-UpV) * chiV**2)\n", + " evol_prop.append(state_prop.get_minkowski())\n", + " evol_nonadiab.append(state_nonadiab.get_minkowski())\n", "\n", - "x0_a = np.array(x0_a)\n", - "lny0_a = np.array(lny0_a)\n", + "evol_prop = np.array(evol_prop)\n", + "evol_nonadiab = np.array(evol_nonadiab)\n", "\n", "for r, c in zip(r_a, colors):\n", " for theta in theta_a:\n", - " x_a = []\n", - " lny_a = []\n", - "\n", - " alpha0, gamma0 = csq1d.alpha_gamma_circle(None, alphaV, gammaV, r, theta)\n", - "\n", - " chi0 = math.sinh(alpha0)\n", - " Up0 = gamma0 + 0.5 * math.log1p(chi0 * chi0)\n", + " evol_circle = []\n", + " state_prop0_circle = state_prop0.get_circle(r, theta)\n", "\n", " for t in t_a:\n", - " (chi, Up) = csq1d.evolve_prop_vector_chi_Up(None, t, frame, chi0, Up0)\n", - " # x_a.append (chi / math.exp (Up))\n", - " # lny_a.append (-Up)\n", - " gamma = Up - 0.5 * math.log1p(chi * chi)\n", - " x_a.append(chi)\n", - " lny_a.append(-math.sqrt(1.0 + chi * chi) * math.sinh(gamma))\n", - "\n", - " x_a = np.array(x_a)\n", - " lny_a = np.array(lny_a)\n", + " csq1d.evolve_prop_vector(None, state_prop0_circle, frame, t, state_prop)\n", + " evol_circle.append(state_prop.get_minkowski())\n", + " evol_circle = np.array(evol_circle)\n", "\n", " if theta == 0:\n", - " plt.plot(x_a, lny_a, lw=mylw, color=c, label=r\"$r=%s$\" % (latex_float(r)))\n", + " plt.plot(\n", + " evol_circle[:, 0],\n", + " evol_circle[:, 1],\n", + " lw=mylw,\n", + " color=c,\n", + " label=r\"$r=%s$\" % (latex_float(r)),\n", + " )\n", " else:\n", - " plt.plot(x_a, lny_a, lw=mylw, color=c)\n", + " plt.plot(evol_circle[:, 0], evol_circle[:, 1], lw=mylw, color=c)\n", "\n", - " axin1.plot(x_a, lny_a, lw=mylw, color=c)\n", + " axin1.plot(evol_circle[:, 0], evol_circle[:, 1], lw=mylw, color=c)\n", "\n", - "plt.plot(xV_a, lnyV_a, \"k--\", lw=mylw, label=r\"$V_2$\", alpha=1.0)\n", - "plt.plot(x0_a, lny0_a, \"r-\", lw=mylw, label=r\"$M$\", alpha=0.6)\n", + "plt.plot(\n", + " evol_nonadiab[:, 0], evol_nonadiab[:, 1], \"k--\", lw=mylw, label=r\"$V_2$\", alpha=1.0\n", + ")\n", + "plt.plot(evol_prop[:, 0], evol_prop[:, 1], \"r-\", lw=mylw, label=r\"$M$\", alpha=0.6)\n", "\n", - "axin1.plot(x0_a, lny0_a, \"r-\", lw=mylw, label=r\"$M$\", alpha=1.0)\n", - "axin1.plot(xV_a, lnyV_a, \"k--\", lw=mylw, label=r\"$V_2$\", alpha=0.6)\n", + "axin1.plot(evol_prop[:, 0], evol_prop[:, 1], \"r-\", lw=mylw, label=r\"$M$\", alpha=1.0)\n", + "axin1.plot(\n", + " evol_nonadiab[:, 0], evol_nonadiab[:, 1], \"k--\", lw=mylw, label=r\"$V_2$\", alpha=0.6\n", + ")\n", "\n", - "plt.grid(b=True, which=\"both\", linestyle=\":\", color=\"0.75\", linewidth=0.5)\n", + "plt.grid(which=\"both\", linestyle=\":\", color=\"0.75\", linewidth=0.5)\n", "leg = plt.legend(loc=\"best\", ncol=2)\n", - "# plt.xscale(\"symlog\", linthresh=1.0e-1)\n", - "# plt.yscale(\"symlog\", linthresh=1.0e-1)\n", - "# plt.xscale(\"log\")\n", - "# plt.yscale(\"log\")\n", "\n", "axin1.set_xlim(17.812, 17.822)\n", "axin1.set_ylim(158.6, 158.8)\n", @@ -270,7 +220,8 @@ "fig.tight_layout()\n", "\n", "plt.savefig(\"nonadiab_vacuum_f0.pdf\")\n", - "plt.show" + "plt.show\n", + "pass" ] }, { @@ -290,93 +241,79 @@ "\n", "axin1 = ax.inset_axes([0.09, 0.7, 0.25, 0.25])\n", "\n", - "frame = 1\n", - "\n", - "x0_a = []\n", - "lny0_a = []\n", - "xV_a = []\n", - "lnyV_a = []\n", + "frame = Ncm.CSQ1DFrame.NONADIAB1\n", "\n", - "chiV0 = 0.0\n", - "UpV0 = 0.0\n", - "\n", - "gammaV = UpV0 - 0.5 * math.log1p(chiV0 * chiV0)\n", - "alphaV = math.asinh(chiV0)\n", + "evol_prop = []\n", + "evol_nonadiab = []\n", "\n", "for t in t_a:\n", - " (chi, Up) = csq1d.evolve_prop_vector_chi_Up(None, t, frame, chiV0, UpV0)\n", - " (chiV, UpV) = csq1d.eval_nonadiab_at(None, frame, t)\n", + " csq1d.evolve_prop_vector(None, state_prop0, frame, t, state_prop)\n", + " csq1d.compute_nonadiab(None, t, state_nonadiab)\n", "\n", - " x0_a.append(chi)\n", - " lny0_a.append(math.sinh(-Up) + 0.5 * math.exp(-Up) * chi**2)\n", + " csq1d.change_frame(None, state_nonadiab, frame)\n", "\n", - " xV_a.append(chiV)\n", - " lnyV_a.append(math.sinh(-UpV) + 0.5 * math.exp(-UpV) * chiV**2)\n", + " evol_prop.append(state_prop.get_minkowski())\n", + " evol_nonadiab.append(state_nonadiab.get_minkowski())\n", "\n", - "x0_a = np.array(x0_a)\n", - "lny0_a = np.array(lny0_a)\n", + "evol_prop = np.array(evol_prop)\n", + "evol_nonadiab = np.array(evol_nonadiab)\n", "\n", "l = 0.0\n", "\n", "for r, c in zip(r_a, colors):\n", " for theta in theta_a:\n", - " x_a = []\n", - " lny_a = []\n", - "\n", - " alpha0, gamma0 = csq1d.alpha_gamma_circle(None, alphaV, gammaV, r, theta)\n", - "\n", - " chi0 = math.sinh(alpha0)\n", - " Up0 = gamma0 + 0.5 * math.log1p(chi0 * chi0)\n", + " evol_circle = []\n", + " state_prop0_circle = state_prop0.get_circle(r, theta)\n", "\n", " for t in t_a:\n", - " (chi, Up) = csq1d.evolve_prop_vector_chi_Up(None, t, frame, chi0, Up0)\n", - "\n", - " gamma = Up - 0.5 * math.log1p(chi * chi)\n", - " x_a.append(chi)\n", - " lny_a.append(-math.sqrt(1.0 + chi * chi) * math.sinh(gamma))\n", - "\n", - " mx = x_a[0]\n", - " mlny = lny_a[0]\n", - " r0 = math.hypot(mx, mlny)\n", + " csq1d.evolve_prop_vector(None, state_prop0_circle, frame, t, state_prop)\n", + " evol_circle.append(state_prop.get_minkowski())\n", + " evol_circle = np.array(evol_circle)\n", "\n", - " nx = mx / r0\n", - " nlny = mlny / r0\n", - "\n", - " x_a = np.array(x_a) - mx + nx * 1.0e-4 * (1.0 + l)\n", - " lny_a = np.array(lny_a) - mlny + nlny * 1.0e-4 * (1.0 + l)\n", - "\n", - " x_a = np.array(x_a)\n", - " lny_a = np.array(lny_a)\n", + " origin = evol_circle[0]\n", + " r0 = math.hypot(*origin)\n", + " origin_r = origin / r0\n", + " evol_circle = evol_circle - origin + origin_r * 1.0e-4 * (1.0 + l)\n", "\n", " if theta == 0:\n", - " plt.plot(x_a, lny_a, lw=mylw, color=c, label=r\"$r=%s$\" % (latex_float(r)))\n", + " plt.plot(\n", + " evol_circle[:, 0],\n", + " evol_circle[:, 1],\n", + " lw=mylw,\n", + " color=c,\n", + " label=r\"$r=%s$\" % (latex_float(r)),\n", + " )\n", " else:\n", - " plt.plot(x_a, lny_a, lw=mylw, color=c)\n", + " plt.plot(evol_circle[:, 0], evol_circle[:, 1], lw=mylw, color=c)\n", "\n", - " axin1.plot(x_a, lny_a, lw=mylw, color=c)\n", + " axin1.plot(evol_circle[:, 0], evol_circle[:, 1], lw=mylw, color=c)\n", "\n", " l = l + 1.0\n", "\n", - "\n", - "print(\n", - " csq1d.eval_int_qmnu2(None, tf, k),\n", - " csq1d.eval_int_mnu2(None, tf, k),\n", - " csq1d.eval_int_q2mnu2(None, tf, k),\n", - " (x0_a[-1] - xV_a[-1]) / x0_a[-1],\n", - " (lny0_a[-1] - lnyV_a[-1]) / lny0_a[-1],\n", + "plt.plot(\n", + " evol_nonadiab[:, 0],\n", + " evol_nonadiab[:, 1],\n", + " \"k--\",\n", + " lw=mylw,\n", + " label=r\"$V_2^{(1)}$\",\n", + " alpha=1.0,\n", + ")\n", + "plt.plot(evol_prop[:, 0], evol_prop[:, 1], \"r-\", lw=mylw, label=r\"$M^{(1)}$\", alpha=0.6)\n", + "\n", + "axin1.plot(\n", + " evol_nonadiab[:, 0],\n", + " evol_nonadiab[:, 1],\n", + " \"k--\",\n", + " lw=mylw,\n", + " label=r\"$V_2^{(1)}$\",\n", + " alpha=1.0,\n", + ")\n", + "axin1.plot(\n", + " evol_prop[:, 0], evol_prop[:, 1], \"r-\", lw=mylw, label=r\"$M^{(1)}$\", alpha=0.6\n", ")\n", "\n", - "plt.plot(xV_a, lnyV_a, \"k--\", lw=mylw, label=r\"$V_2^{(1)}$\", alpha=1.0)\n", - "plt.plot(x0_a, lny0_a, \"r-\", lw=mylw, label=r\"$M^{(1)}$\", alpha=0.6)\n", - "\n", - "axin1.plot(xV_a, lnyV_a, \"k--\", lw=mylw, label=r\"$V_2^{(1)}$\", alpha=1.0)\n", - "axin1.plot(x0_a, lny0_a, \"r-\", lw=mylw, label=r\"$M^{(1)}$\", alpha=0.6)\n", - "\n", - "\n", - "plt.grid(b=True, which=\"both\", linestyle=\":\", color=\"0.75\", linewidth=0.5)\n", + "plt.grid(which=\"both\", linestyle=\":\", color=\"0.75\", linewidth=0.5)\n", "leg = plt.legend(loc=\"best\", ncol=2)\n", - "# plt.xscale(\"symlog\", linscale=6.0e-1, linthresh=1.0e-2)\n", - "# plt.yscale(\"symlog\", linscale=6.0e-1, linthresh=1.0e-2)\n", "\n", "axin1.set_xlim(-0.2e-6, +7.5e-6)\n", "axin1.set_ylim(-25.0e-5, +1.0e-5)\n", @@ -389,7 +326,8 @@ "fig.tight_layout()\n", "\n", "plt.savefig(\"nonadiab_vacuum_f1.pdf\")\n", - "plt.show" + "plt.show\n", + "pass" ] }, { @@ -407,89 +345,67 @@ "\n", "fig = plt.figure(dpi=120)\n", "\n", - "frame = 2\n", - "\n", - "x0_a = []\n", - "lny0_a = []\n", - "xV_a = []\n", - "lnyV_a = []\n", - "\n", - "chiV0 = 0.0\n", - "UpV0 = 0.0\n", + "frame = Ncm.CSQ1DFrame.NONADIAB2\n", "\n", - "gammaV = UpV0 - 0.5 * math.log1p(chiV0 * chiV0)\n", - "alphaV = math.asinh(chiV0)\n", + "evol_prop = []\n", + "evol_nonadiab = []\n", "\n", "for t in t_a:\n", - " (chi, Up) = csq1d.evolve_prop_vector_chi_Up(None, t, frame, chiV0, UpV0)\n", - " (chiV, UpV) = csq1d.eval_nonadiab_at(None, frame, t)\n", + " csq1d.evolve_prop_vector(None, state_prop0, frame, t, state_prop)\n", + " csq1d.compute_nonadiab(None, t, state_nonadiab)\n", "\n", - " x0_a.append(chi)\n", - " lny0_a.append(math.sinh(-Up) + 0.5 * math.exp(-Up) * chi**2)\n", + " csq1d.change_frame(None, state_nonadiab, frame)\n", "\n", - " xV_a.append(chiV)\n", - " lnyV_a.append(math.sinh(-UpV) + 0.5 * math.exp(-UpV) * chiV**2)\n", + " evol_prop.append(state_prop.get_minkowski())\n", + " evol_nonadiab.append(state_nonadiab.get_minkowski())\n", "\n", - "x0_a = np.array(x0_a)\n", - "lny0_a = np.array(lny0_a)\n", + "evol_prop = np.array(evol_prop)\n", + "evol_nonadiab = np.array(evol_nonadiab)\n", "\n", "l = 0.0\n", "for r, c in zip(r_a, colors):\n", " for theta in theta_a:\n", - " x_a = []\n", - " lny_a = []\n", - "\n", - " alpha0, gamma0 = csq1d.alpha_gamma_circle(None, alphaV, gammaV, r, theta)\n", - "\n", - " chi0 = math.sinh(alpha0)\n", - " Up0 = gamma0 + 0.5 * math.log1p(chi0 * chi0)\n", + " evol_circle = []\n", + " state_prop0_circle = state_prop0.get_circle(r, theta)\n", "\n", " for t in t_a:\n", - " (chi, Up) = csq1d.evolve_prop_vector_chi_Up(None, t, frame, chi0, Up0)\n", - "\n", - " gamma = Up - 0.5 * math.log1p(chi * chi)\n", - " x_a.append(chi)\n", - " lny_a.append(-math.sqrt(1.0 + chi * chi) * math.sinh(gamma))\n", + " csq1d.evolve_prop_vector(None, state_prop0_circle, frame, t, state_prop)\n", + " evol_circle.append(state_prop.get_minkowski())\n", + " evol_circle = np.array(evol_circle)\n", "\n", - " mx = x_a[0]\n", - " mlny = lny_a[0]\n", - " r0 = math.hypot(mx, mlny)\n", - "\n", - " nx = mx / r0\n", - " nlny = mlny / r0\n", - "\n", - " rho_a = np.hypot(x_a, lny_a) * 1.0e-9\n", - " phi_a = np.arctan2(lny_a, x_a)\n", - "\n", - " # x_a = rho_a * np.cos (phi_a)\n", - " # lny_a = rho_a * np.sin (phi_a)\n", + " origin = evol_circle[0]\n", + " r0 = math.hypot(*origin)\n", + " origin_r = origin / r0\n", "\n", " fr = 1.0e-7 * (1.0 + l / 2.0)\n", - " x_a = np.array(x_a) - mx + nx * fr\n", - " lny_a = np.array(lny_a) - mlny + nlny * fr\n", + " evol_circle = evol_circle - origin + origin_r * fr\n", "\n", " if theta == 0:\n", - " plt.plot(x_a, lny_a, lw=mylw, color=c, label=r\"$r=%s$\" % (latex_float(r)))\n", + " plt.plot(\n", + " evol_circle[:, 0],\n", + " evol_circle[:, 1],\n", + " lw=mylw,\n", + " color=c,\n", + " label=r\"$r=%s$\" % (latex_float(r)),\n", + " )\n", " else:\n", - " plt.plot(x_a, lny_a, lw=mylw, color=c)\n", + " plt.plot(evol_circle[:, 0], evol_circle[:, 1], color=c)\n", "\n", " l = l + 1.0\n", "\n", - "\n", - "print(\n", - " csq1d.eval_int_qmnu2(None, tf, k),\n", - " csq1d.eval_int_mnu2(None, tf, k),\n", - " csq1d.eval_int_q2mnu2(None, tf, k),\n", - " (x0_a[-1] - xV_a[-1]),\n", - " (lny0_a[-1] - lnyV_a[-1]),\n", - ")\n", - "\n", "plt.plot(\n", - " xV_a, lnyV_a, \"o\", color=\"k\", lw=mylw, label=r\"$V_2^{(2)}$\", alpha=1.0, markersize=1\n", + " evol_nonadiab[:, 0],\n", + " evol_nonadiab[:, 1],\n", + " \"o\",\n", + " color=\"k\",\n", + " lw=mylw,\n", + " label=r\"$V_2^{(2)}$\",\n", + " alpha=1.0,\n", + " markersize=1,\n", ")\n", - "plt.plot(x0_a, lny0_a, \"r-\", lw=mylw, label=r\"$M^{(2)}$\", alpha=0.6)\n", + "plt.plot(evol_prop[:, 0], evol_prop[:, 1], \"r-\", lw=mylw, label=r\"$M^{(2)}$\", alpha=0.6)\n", "\n", - "plt.grid(b=True, which=\"both\", linestyle=\":\", color=\"0.75\", linewidth=0.5)\n", + "plt.grid(which=\"both\", linestyle=\":\", color=\"0.75\", linewidth=0.5)\n", "leg = plt.legend(loc=\"upper left\", ncol=2)\n", "# plt.xscale(\"symlog\", linscale=6.0e-1, linthresh=1.0e-6)\n", "# plt.yscale(\"symlog\", linscale=6.0e-1, linthresh=1.0e-6)\n", @@ -501,7 +417,8 @@ "fig.tight_layout()\n", "\n", "plt.savefig(\"nonadiab_vacuum_f2.pdf\")\n", - "plt.show" + "plt.show\n", + "pass" ] }, { @@ -520,81 +437,58 @@ "fig = plt.figure(dpi=120)\n", "gs = fig.add_gridspec(1, 2)\n", "(ax1, ax2) = gs.subplots()\n", - "fig.suptitle(\"Sharing x per column, y per row\")\n", - "\n", - "frame = 0\n", "\n", - "x0_a = []\n", - "lny0_a = []\n", - "xV_a = []\n", - "lnyV_a = []\n", + "frame = Ncm.CSQ1DFrame.ORIG\n", "\n", - "chiV0 = 0.0\n", - "UpV0 = 0.0\n", - "\n", - "gammaV = UpV0 - 0.5 * math.log1p(chiV0 * chiV0)\n", - "alphaV = math.asinh(chiV0)\n", + "evol_prop = []\n", + "evol_nonadiab = []\n", "\n", "for t in t_a:\n", - " (chi, Up) = csq1d.evolve_prop_vector_chi_Up(None, t, frame, chiV0, UpV0)\n", - " (chiV, UpV) = csq1d.eval_nonadiab_at(None, 0, t)\n", + " csq1d.evolve_prop_vector(None, state_prop0, frame, t, state_prop)\n", + " csq1d.compute_nonadiab(None, t, state_nonadiab)\n", "\n", - " x0_a.append(chi)\n", - " lny0_a.append(math.sinh(-Up) + 0.5 * math.exp(-Up) * chi)\n", + " csq1d.change_frame(None, state_nonadiab, frame)\n", "\n", - " xV_a.append(chiV)\n", - " lnyV_a.append(math.sinh(-UpV) + 0.5 * math.exp(-UpV) * chiV)\n", + " evol_prop.append(state_prop.get_minkowski())\n", + " evol_nonadiab.append(state_nonadiab.get_minkowski())\n", "\n", - "x0_a = np.array(x0_a)\n", - "lny0_a = np.array(lny0_a)\n", + "evol_prop = np.array(evol_prop)\n", + "evol_nonadiab = np.array(evol_nonadiab)\n", "\n", "for r in np.geomspace(1.0e-4, 1.0e1, 10):\n", " for theta in theta_a[0:1]:\n", - " x_a = []\n", - " lny_a = []\n", - "\n", - " alpha0, gamma0 = csq1d.alpha_gamma_circle(None, alphaV, gammaV, r, theta)\n", - "\n", - " chi0 = math.sinh(alpha0)\n", - " Up0 = gamma0 + 0.5 * math.log1p(chi0 * chi0)\n", + " evol_circle = []\n", + " state_prop0_circle = state_prop0.get_circle(r, theta)\n", "\n", " for t in t_a:\n", - " (chi, Up) = csq1d.evolve_prop_vector_chi_Up(None, t, frame, chi0, Up0)\n", - " # x_a.append (chi / math.exp (Up))\n", - " # lny_a.append (-Up)\n", - " gamma = Up - 0.5 * math.log1p(chi * chi)\n", - " x_a.append(chi)\n", - " lny_a.append(-math.sqrt(1.0 + chi * chi) * math.sinh(gamma))\n", + " csq1d.evolve_prop_vector(None, state_prop0_circle, frame, t, state_prop)\n", + " evol_circle.append(state_prop.get_minkowski())\n", + " evol_circle = np.array(evol_circle)\n", "\n", - " x_a = np.array(x_a)\n", - " lny_a = np.array(lny_a)\n", - "\n", - " rho_a = np.hypot(x_a, lny_a)\n", - " phi_a = np.arctan2(lny_a, x_a)\n", + " rho_a = np.hypot(*np.hsplit(evol_circle, 2))\n", + " phi_a = np.arctan2(*np.hsplit(evol_circle[:, [1, 0]], 2))\n", "\n", " ax1.plot(t_a, rho_a, lw=mylw)\n", " ax2.plot(t_a, phi_a - phi_a[0], lw=mylw)\n", "\n", - "rho0_a = np.hypot(x0_a, lny0_a)\n", - "phi0_a = np.arctan2(lny0_a, x0_a)\n", + "rho0_a = np.hypot(*np.hsplit(evol_prop, 2))\n", + "phi0_a = np.arctan2(*np.hsplit(evol_prop[:, [1, 0]], 2))\n", "\n", - "rhoV_a = np.hypot(xV_a, lnyV_a)\n", - "phiV_a = np.arctan2(lnyV_a, xV_a)\n", + "rhoV_a = np.hypot(*np.hsplit(evol_nonadiab, 2))\n", + "phiV_a = np.arctan2(*np.hsplit(evol_nonadiab[:, [1, 0]], 2))\n", "\n", - "# ax1.plot (t_a, rho0_a, 'k-', lw=mylw, label = r'$M(t)$')\n", - "# ax2.plot (t_a, phi0_a-phi0_a[0], 'k-', lw=mylw, label = r'$M(t)$')\n", + "ax1.plot(t_a, rho0_a, \"k-\", lw=mylw, label=r\"$M(t)$\")\n", + "ax2.plot(t_a, phi0_a - phi0_a[0], \"k-\", lw=mylw, label=r\"$M(t)$\")\n", "\n", - "# ax1.plot (t_a, rhoV_a, 'k-', lw=mylw, label = r'$V(t)$')\n", - "# ax2.plot (t_a, phiV_a-phiV_a[0], 'k-', lw=mylw, label = r'$V(t)$')\n", + "ax1.plot(t_a, rhoV_a, \"k-\", lw=mylw, label=r\"$V(t)$\")\n", + "ax2.plot(t_a, phiV_a - phiV_a[0], \"k-\", lw=mylw, label=r\"$V(t)$\")\n", "\n", - "# ax1.grid (b=True, which='both', linestyle=':', color='0.75', linewidth=0.5)\n", - "# ax2.grid (b=True, which='both', linestyle=':', color='0.75', linewidth=0.5)\n", + "ax1.grid(which=\"both\", linestyle=\":\", color=\"0.75\", linewidth=0.5)\n", + "ax2.grid(which=\"both\", linestyle=\":\", color=\"0.75\", linewidth=0.5)\n", "leg = ax1.legend(loc=\"best\", ncol=2)\n", - "# ax1.set_xscale(\"log\")\n", + "ax1.set_xscale(\"log\")\n", "ax1.set_yscale(\"log\")\n", - "\n", - "# ax2.set_xscale(\"log\")\n", - "# ax2.set_yscale(\"symlog\")\n", + "ax2.set_xscale(\"log\")\n", "\n", "ax1.set_xlabel(\"$t$\")\n", "ax1.set_ylabel(\"$r$\")\n", @@ -606,7 +500,8 @@ "fig.tight_layout()\n", "\n", "plt.savefig(\"nonadiab_vacuum_f0_xy.pdf\")\n", - "plt.show" + "plt.show\n", + "pass" ] }, { @@ -616,23 +511,27 @@ "outputs": [], "source": [ "csq1d = Nc.DECont(Omegaw=0.3, OmegaL=0.7, w=1.0e-3, cs2=1.0e-3)\n", + "csq1d.set_initial_condition_type(Ncm.CSQ1DInitialStateType.AD_HOC)\n", "# csq1d.set_reltol (1.0e-11)\n", "\n", + "frame = Ncm.CSQ1DFrame.ORIG\n", + "final_state = Ncm.CSQ1DState.new()\n", + "\n", "\n", "def compute_J(k):\n", " csq1d.set_k(k)\n", " csq1d.prepare_prop(None, 0.0, 1.0e-30, 1.0e1)\n", "\n", - " (chi, Up) = csq1d.evolve_prop_vector_chi_Up(None, tf, frame, chiV, UpV)\n", - " csq1d.set_init_cond(Ncm.CSQ1DEvolState.UP, tf, chi, Up)\n", + " csq1d.evolve_prop_vector(None, state_prop0, frame, tf, state_prop)\n", + " csq1d.set_init_cond(None, Ncm.CSQ1DEvolState.UP, state_prop)\n", " csq1d.set_tf(1.0e10)\n", " csq1d.prepare()\n", "\n", " t_a, t_s = csq1d.get_time_array()\n", "\n", - " J = csq1d.get_J_at(None, t_a[-1])\n", + " csq1d.eval_at(None, t_a[-1], final_state)\n", "\n", - " return J" + " return final_state.get_J()" ] }, { @@ -831,5 +730,5 @@ } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 } diff --git a/notebooks/primordial_perturbations/vacuum_study_adiabatic.ipynb b/notebooks/primordial_perturbations/vacuum_study_adiabatic.ipynb index 77194def9..580289611 100644 --- a/notebooks/primordial_perturbations/vacuum_study_adiabatic.ipynb +++ b/notebooks/primordial_perturbations/vacuum_study_adiabatic.ipynb @@ -41,28 +41,14 @@ "metadata": {}, "outputs": [], "source": [ - "try:\n", - " import gi\n", - "\n", - " gi.require_version(\"NumCosmo\", \"1.0\")\n", - " gi.require_version(\"NumCosmoMath\", \"1.0\")\n", - "except:\n", - " pass\n", - "\n", "import sys\n", "import math\n", - "import matplotlib as mpl\n", "import matplotlib.pyplot as plt\n", - "import matplotlib.gridspec as gridspec\n", - "import matplotlib.animation as animation\n", - "from mpl_toolkits.mplot3d import Axes3D\n", "import matplotlib.cm as cm\n", "import numpy as np\n", "\n", - "from IPython.display import HTML\n", - "\n", - "from gi.repository import NumCosmo as Nc\n", - "from gi.repository import NumCosmoMath as Ncm\n", + "from numcosmo_py import Ncm, Nc\n", + "from numcosmo_py.plotting.tools import set_rc_params_article, latex_float\n", "\n", "%matplotlib inline" ] @@ -80,42 +66,7 @@ "metadata": {}, "outputs": [], "source": [ - "fig_width_pt = 246.0 * 2.0 # Get this from LaTeX using \\showthe\\columnwidth\n", - "inches_per_pt = 1.0 / 72.27 # Convert pt to inch\n", - "golden_mean = (math.sqrt(5) - 1.0) / 2.0 # Aesthetic ratio\n", - "fig_width = fig_width_pt * inches_per_pt # width in inches\n", - "fig_height = fig_width * golden_mean # height in inches\n", - "fig_size = [fig_width, fig_height]\n", - "\n", - "params = {\n", - " \"axes.labelsize\": 10,\n", - " \"font.size\": 10,\n", - " \"legend.fontsize\": 8,\n", - " \"xtick.labelsize\": 8,\n", - " \"ytick.labelsize\": 8,\n", - " \"text.usetex\": True,\n", - " \"figure.figsize\": fig_size,\n", - " \"animation.embed_limit\": 2**128,\n", - "}\n", - "\n", - "mpl.rcParams.update(params)\n", - "\n", - "\n", - "def latex_float(f):\n", - " float_str = \"{0:.2g}\".format(f)\n", - " if \"e\" in float_str:\n", - " base, exponent = float_str.split(\"e\")\n", - " if base == 1.0:\n", - " if exponent == 0.0:\n", - " return r\"1\"\n", - " else:\n", - " return r\"10^{{{1}}}\".format(int(exponent))\n", - " elif exponent == 0.0:\n", - " return r\"{0}\".format(base)\n", - " else:\n", - " return r\"{0} \\times 10^{{{1}}}\".format(base, int(exponent))\n", - " else:\n", - " return float_str" + "set_rc_params_article(ncol=2)" ] }, { @@ -153,9 +104,11 @@ "outputs": [], "source": [ "csq1d = Nc.DECont(Omegaw=1.0, OmegaL=0.0, w=1.0e-6, cs2=1.0e-6)\n", + "state0 = Ncm.CSQ1DState.new()\n", + "state = Ncm.CSQ1DState.new()\n", "\n", "ti = 1.0e-10\n", - "tf = 5.0e-3\n", + "tf = 5.0e-2\n", "\n", "ki = 1.0e0\n", "kf = 1.0e2\n", @@ -165,15 +118,13 @@ "\n", "Found, tAD = csq1d.find_adiab_time_limit(None, ti, tf, 1.0e-5)\n", "\n", - "alpha0, dgamma0, _, _ = csq1d.eval_adiab_at(None, tAD)\n", - "xi0 = csq1d.eval_xi(None, tAD, csq1d.get_k())\n", - "gamma0 = xi0 + dgamma0\n", + "csq1d.compute_adiab(None, tAD, state0)\n", "\n", "Found, tfAD = csq1d.find_adiab_time_limit(None, ti, 1.0e1, 1.0e-1)\n", "if Found:\n", " tf = tfAD\n", "\n", - "print(ti, tAD, tf)\n", + "print(ti, tAD, tf, Found)\n", "\n", "mylw = 1.0\n", "\n", @@ -189,34 +140,34 @@ "metadata": {}, "outputs": [], "source": [ - "fig = plt.figure(dpi=120)\n", + "fig = plt.figure()\n", + "\n", + "frame = Ncm.CSQ1DFrame.ORIG\n", "\n", "for r, c in zip(r_a, colors):\n", " for theta in theta_a:\n", " if r == 0 and theta > 0.0:\n", " continue\n", "\n", - " alpha, dgamma = csq1d.alpha_gamma_circle(None, alpha0, dgamma0, r, theta)\n", - "\n", - " csq1d.set_init_cond(Ncm.CSQ1DEvolState.ADIABATIC, tAD, alpha, dgamma)\n", + " state0_circle = state0.get_circle(r, theta)\n", + " csq1d.set_init_cond(None, Ncm.CSQ1DEvolState.ADIABATIC, state0_circle)\n", " csq1d.set_tf(tf)\n", " csq1d.prepare()\n", "\n", " t_a, tmax = csq1d.get_time_array()\n", - " mx1x2 = np.array([csq1d.get_minkowski_frame(None, 0, t) for t in t_a])\n", + " mx1x2 = np.array(\n", + " [csq1d.eval_at_frame(None, frame, t, state).get_minkowski() for t in t_a]\n", + " )\n", "\n", " if r == 0.0:\n", " plt.plot(\n", " mx1x2[:, 0], mx1x2[:, 1], lw=mylw, color=\"r\", alpha=0.6, label=r\"$M$\"\n", " )\n", "\n", - " Valphadgamma = zip(\n", - " t_a, np.array([csq1d.eval_adiab_at(None, t) for t in t_a])\n", - " )\n", " Vx1x2 = np.array(\n", " [\n", - " csq1d.alpha_dgamma_to_minkowski_frame(None, 0, t, alpha, dgamma)\n", - " for t, (alpha, dgamma, _, _) in Valphadgamma\n", + " csq1d.compute_adiab_frame(None, frame, t, state)[0].get_minkowski()\n", + " for t in t_a\n", " ]\n", " )\n", "\n", @@ -232,7 +183,7 @@ " plt.plot(mx1x2[:, 0], mx1x2[:, 1], lw=mylw, color=c)\n", "\n", "\n", - "plt.grid(b=True, which=\"both\", linestyle=\":\", color=\"0.75\", linewidth=0.5)\n", + "plt.grid(which=\"both\", linestyle=\":\", color=\"0.75\", linewidth=0.5)\n", "leg = plt.legend(loc=\"best\", ncol=2)\n", "\n", "plt.xscale(\"symlog\", linthresh=1.0e-15)\n", @@ -245,21 +196,24 @@ "plt.savefig(\"adiab_vacuum_f0.pdf\")\n", "plt.show()\n", "\n", - "fig = plt.figure(dpi=120)\n", + "fig = plt.figure()\n", + "\n", + "frame = Ncm.CSQ1DFrame.ADIAB1\n", "\n", "for r, c in zip(r_a, colors):\n", " for theta in theta_a:\n", " if r == 0.0 and theta > 0.0:\n", " continue\n", "\n", - " alpha, dgamma = csq1d.alpha_gamma_circle(None, alpha0, dgamma0, r, theta)\n", - "\n", - " csq1d.set_init_cond(Ncm.CSQ1DEvolState.ADIABATIC, tAD, alpha, dgamma)\n", + " state0_circle = state0.get_circle(r, theta)\n", + " csq1d.set_init_cond(None, Ncm.CSQ1DEvolState.ADIABATIC, state0_circle)\n", " csq1d.set_tf(tf)\n", " csq1d.prepare()\n", "\n", " t_a, tmax = csq1d.get_time_array()\n", - " mx1x2 = np.array([csq1d.get_minkowski_frame(None, 1, t) for t in t_a])\n", + " mx1x2 = np.array(\n", + " [csq1d.eval_at_frame(None, frame, t, state).get_minkowski() for t in t_a]\n", + " )\n", "\n", " if r == 0.0:\n", " plt.plot(\n", @@ -271,13 +225,10 @@ " label=r\"$M^{(1)}$\",\n", " )\n", "\n", - " Valphadgamma = zip(\n", - " t_a, np.array([csq1d.eval_adiab_at(None, t) for t in t_a])\n", - " )\n", " Vx1x2 = np.array(\n", " [\n", - " csq1d.alpha_dgamma_to_minkowski_frame(None, 1, t, alpha, dgamma)\n", - " for t, (alpha, dgamma, _, _) in Valphadgamma\n", + " csq1d.compute_adiab_frame(None, frame, t, state)[0].get_minkowski()\n", + " for t in t_a\n", " ]\n", " )\n", "\n", @@ -291,13 +242,17 @@ " )\n", " elif theta == 0.0:\n", " plt.plot(\n", - " mx1x2[:, 0], mx1x2[:, 1], lw=mylw, color=c, label=r\"$r$=%.2f\" % (r)\n", + " mx1x2[:, 0],\n", + " mx1x2[:, 1],\n", + " lw=mylw,\n", + " color=c,\n", + " label=rf\"$r={latex_float(r)}$\",\n", " )\n", " else:\n", " plt.plot(mx1x2[:, 0], mx1x2[:, 1], lw=mylw, color=c)\n", "\n", "\n", - "plt.grid(b=True, which=\"both\", linestyle=\":\", color=\"0.75\", linewidth=0.5)\n", + "plt.grid(which=\"both\", linestyle=\":\", color=\"0.75\", linewidth=0.5)\n", "leg = plt.legend(loc=\"best\", ncol=2)\n", "\n", "plt.xlabel(\"$x^1$\")\n", @@ -307,21 +262,24 @@ "plt.savefig(\"adiab_vacuum_f1.pdf\")\n", "plt.show()\n", "\n", - "fig = plt.figure(dpi=120)\n", + "fig = plt.figure()\n", + "\n", + "frame = Ncm.CSQ1DFrame.ADIAB2\n", "\n", "for r, c in zip(r_a, colors):\n", " for theta in theta_a:\n", " if r == 0 and theta > 0.0:\n", " continue\n", "\n", - " alpha, dgamma = csq1d.alpha_gamma_circle(None, alpha0, dgamma0, r, theta)\n", - "\n", - " csq1d.set_init_cond(Ncm.CSQ1DEvolState.ADIABATIC, tAD, alpha, dgamma)\n", + " state0_circle = state0.get_circle(r, theta)\n", + " csq1d.set_init_cond(None, Ncm.CSQ1DEvolState.ADIABATIC, state0_circle)\n", " csq1d.set_tf(tf)\n", " csq1d.prepare()\n", "\n", " t_a, tmax = csq1d.get_time_array()\n", - " mx1x2 = np.array([csq1d.get_minkowski_frame(None, 2, t) for t in t_a])\n", + " mx1x2 = np.array(\n", + " [csq1d.eval_at_frame(None, frame, t, state).get_minkowski() for t in t_a]\n", + " )\n", "\n", " if r == 0.0:\n", " plt.plot(\n", @@ -333,13 +291,10 @@ " label=r\"$M^{(2)}$\",\n", " )\n", "\n", - " Valphadgamma = zip(\n", - " t_a, np.array([csq1d.eval_adiab_at(None, t) for t in t_a])\n", - " )\n", " Vx1x2 = np.array(\n", " [\n", - " csq1d.alpha_dgamma_to_minkowski_frame(None, 2, t, alpha, dgamma)\n", - " for t, (alpha, dgamma, _, _) in Valphadgamma\n", + " csq1d.compute_adiab_frame(None, frame, t, state)[0].get_minkowski()\n", + " for t in t_a\n", " ]\n", " )\n", "\n", @@ -354,12 +309,16 @@ "\n", " elif theta == 0.0:\n", " plt.plot(\n", - " mx1x2[:, 0], mx1x2[:, 1], lw=mylw, color=c, label=r\"$r$=%.2f\" % (r)\n", + " mx1x2[:, 0],\n", + " mx1x2[:, 1],\n", + " lw=mylw,\n", + " color=c,\n", + " label=rf\"$r={latex_float(r)}$\",\n", " )\n", " else:\n", " plt.plot(mx1x2[:, 0], mx1x2[:, 1], lw=mylw, color=c)\n", "\n", - "plt.grid(b=True, which=\"both\", linestyle=\":\", color=\"0.75\", linewidth=0.5)\n", + "plt.grid(which=\"both\", linestyle=\":\", color=\"0.75\", linewidth=0.5)\n", "leg = plt.legend(loc=\"best\", ncol=2)\n", "\n", "plt.xlabel(\"$x^1$\")\n", @@ -388,7 +347,7 @@ "\n", " t_a, t_s = csq1d.get_time_array()\n", "\n", - " J = csq1d.get_J_at(None, t_a[-1])\n", + " J = csq1d.eval_at(None, t_a[-1], state).get_J()\n", "\n", " return J" ] @@ -413,7 +372,7 @@ "metadata": {}, "outputs": [], "source": [ - "fig = plt.figure(dpi=120)\n", + "fig = plt.figure()\n", "\n", "plt.plot(k_a, (k_a**3) * J_a[:, 0], lw=mylw, c=\"k\", label=r\"$J_{00}$\")\n", "\n", @@ -460,5 +419,5 @@ } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 } diff --git a/notebooks/primordial_perturbations/vexp_bounce.ipynb b/notebooks/primordial_perturbations/vexp_bounce.ipynb index 974e343d5..2f790d1fb 100644 --- a/notebooks/primordial_perturbations/vexp_bounce.ipynb +++ b/notebooks/primordial_perturbations/vexp_bounce.ipynb @@ -55,7 +55,7 @@ "\\begin{equation}\n", "F\\equiv \\frac{1}{4}+B e^{-\\frac{\\phi^2}{\\beta^2}}.\n", "\\end{equation}\n", - "\n", + "The coupling is controlled by the parameters $B$ and $\\beta$.\n", "\n", "## Loading NumCosmo\n", "\n", @@ -69,14 +69,62 @@ "metadata": {}, "outputs": [], "source": [ - "from numcosmo_py import Nc\n", - "from numcosmo_py import Ncm\n", - "\n", "import sys\n", - "import math\n", - "import matplotlib\n", "import matplotlib.pyplot as plt\n", - "import numpy as np" + "import numpy as np\n", + "from matplotlib.pyplot import cm\n", + "\n", + "from numcosmo_py import Ncm, Nc\n", + "from numcosmo_py.plotting.tools import set_rc_params_article, latex_float" + ] + }, + { + "cell_type": "markdown", + "id": "d088def3", + "metadata": {}, + "source": [ + "# Initializing the library" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7968aadd", + "metadata": {}, + "outputs": [], + "source": [ + "__name__ = \"NcContext\"\n", + "\n", + "Ncm.cfg_init()\n", + "Ncm.cfg_set_log_handler(lambda msg: sys.stdout.write(msg) and sys.stdout.flush())" + ] + }, + { + "cell_type": "markdown", + "id": "a809c869", + "metadata": {}, + "source": [ + "# Latex definition" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "039b5406", + "metadata": {}, + "outputs": [], + "source": [ + "set_rc_params_article(ncol=2)" + ] + }, + { + "cell_type": "markdown", + "id": "67bcf96e", + "metadata": {}, + "source": [ + "# Model initialization\n", + "\n", + "Creating a new background Vexp model" ] }, { @@ -86,20 +134,46 @@ "metadata": {}, "outputs": [], "source": [ - "Vexp = Nc.HICosmoVexp.new()\n", - "Vexp.props.alphab = 8.3163e-2\n", - "Vexp.props.sigmaphi = 9.0\n", - "Vexp.props.dphi = -9.0e-4\n", - "Vexp.props.xb = 2.0e36\n", - "Vexp.props.OmegaL = 1.0\n", - "Vexp.props.Omegac = 1.0\n", - "Vexp.props.H0 = 67.8\n", + "Vexp_none = Nc.HICosmoVexp.new()\n", + "Vexp_none.set_em_coupling(Nc.HICosmoVexpEMCoupling.NONE)\n", + "\n", + "Vexp_cauchy = Nc.HICosmoVexp.new()\n", + "Vexp_cauchy.set_em_coupling(Nc.HICosmoVexpEMCoupling.CAUCHY)\n", + "\n", + "Vexp_gauss = Nc.HICosmoVexp.new()\n", + "Vexp_gauss.set_em_coupling(Nc.HICosmoVexpEMCoupling.GAUSS)\n", + "\n", + "current_set = {\n", + " \"alphab\": 7.4847e-3, # Alpha (# of e-fold\\s) at the bounce\n", + " \"sigmaphi\": 100.0, # Width of the Gaussian solution for the WdW equation\n", + " \"xb\": 2.0e36, # Inverse of the scale factor at the bounce (Initial condition)\n", + " \"dphi\": -9.0e-4, # Deviation of the Gaussian solution for the WdW equation\n", + " \"OmegaL\": 1.0, # H²(a when w=-1)/H²(a0). Basically gives the DE-dominated phase\n", + " \"Omegac\": 1.0, # Omega_d???\n", + " \"H0\": 67.8, # Hubble parameter today given by CMB observations\n", + " \"Bem\": -1.0 / 4.0 + 1.0e-12, # Amplitude of the EM gaussian coupling\n", + " \"betaem\": 3.6e-1, # Width of the EM gaussian coupling\n", + "}\n", + "\n", + "Vexp_none.set_properties(**current_set)\n", + "Vexp_cauchy.set_properties(**current_set)\n", + "Vexp_gauss.set_properties(**current_set)\n", + "\n", + "tc = Vexp_none.tau_xe(\n", + " 1.0e15\n", + ") # Initial tau in expansion phase??? tau para quando a expansão é 10^15\n", + "reltol = 1.0e-14 # Relative tolerance for solving differential equations" + ] + }, + { + "cell_type": "markdown", + "id": "0266f16d", + "metadata": {}, + "source": [ + "# Model integrated time\n", "\n", - "tc = Vexp.tau_xe(1.0e15)\n", - "reltol = 1.0e-14\n", - "B = 1.0e-58\n", - "beta = 0.08\n", - "k = 1.0" + "Getting the time intervals for the computed model in terms of $\\alpha \\equiv \\ln(a/a_0)$ and $\\alpha = \\alpha_b + \\frac{\\tau^2}{2}$.\n", + "\n" ] }, { @@ -109,29 +183,72 @@ "metadata": {}, "outputs": [], "source": [ - "tau_min = Vexp.tau_min()\n", - "tau_max = Vexp.tau_max()\n", - "tau_qt_c = Vexp.tau_qt_c()\n", - "tau_qt_e = Vexp.tau_qt_e()\n", + "tau_min = Vexp_none.tau_min() # Get initial time\n", + "tau_max = Vexp_none.tau_max() # Get final time\n", + "tau_qt_c = Vexp_none.tau_qt_c() # Get initial time of the quantum phase\n", + "tau_qt_e = Vexp_none.tau_qt_e() # Get final time of the quantum phase\n", "npoints = 5000\n", "\n", "tau_a = np.linspace(tau_min, tau_max, npoints)\n", "tau_q_a = np.linspace(tau_qt_c, tau_qt_e, npoints)\n", "\n", - "print(f\"Vexp model prepared in the interval ({tau_min},{tau_max})\")\n", - "print(f\"Vexp quantum dominated interval ({tau_qt_c},{tau_qt_e})\")" + "print(f\"Vexp model prepared in the interval ({tau_min}, {tau_max})\")\n", + "print(f\"Vexp quantum dominated interval ({tau_qt_c}, {tau_qt_e})\")" + ] + }, + { + "cell_type": "markdown", + "id": "3c633661-3b73-4bf6-883d-fcc39d45838b", + "metadata": {}, + "source": [ + "Computing background functions" ] }, { "cell_type": "code", "execution_count": null, - "id": "076f80d0", + "id": "25b11fe3-543a-4254-901a-bdffb0408cc4", "metadata": {}, "outputs": [], "source": [ - "plt.figure(figsize=(14, 7))\n", + "alpha_a = [Vexp_none.alpha(tau) for tau in tau_a]\n", + "phi_a = np.array([Vexp_none.phi(tau) for tau in tau_a])\n", + "deta_s = Ncm.SplineCubicNotaknot.new()\n", + "deta_s.set_array(tau_a, [Vexp_none.eval_nu(tau, 1.0) for tau in tau_a], True)\n", + "rescale = Vexp_none.RH_planck() / np.exp(Vexp_none.alpha_0e())\n", + "eta_a = [\n", + " (\n", + " -deta_s.eval_integ(tau, 0.0) * rescale\n", + " if tau < 1.0\n", + " else deta_s.eval_integ(0.0, tau) * rescale\n", + " )\n", + " for tau in tau_a\n", + "]\n", + "RS_a = np.array(\n", + " [Vexp_none.Ricci_scale(tau) for tau in tau_a]\n", + ") # Hubble scale goes to 0 at the bounce, but not the Ricci scalar\n", + "nu_a = np.array([Vexp_none.eval_nu(tau, 1.0) for tau in tau_a])\n", + "x_y_a = np.array([Vexp_none.x_y(tau) for tau in tau_a])" + ] + }, + { + "cell_type": "markdown", + "id": "e88d0550", + "metadata": {}, + "source": [ + "# Consistence check\n", "\n", - "alpha_a = [Vexp.alpha(tau) for tau in tau_a]\n", + "Plotting $\\alpha(\\tau) - \\alpha_b$." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "076f80d0", + "metadata": {}, + "outputs": [], + "source": [ + "plt.figure()\n", "\n", "plt.plot(tau_a, alpha_a, label=r\"$\\alpha$\")\n", "\n", @@ -143,6 +260,16 @@ "pass" ] }, + { + "cell_type": "markdown", + "id": "30583ff4", + "metadata": {}, + "source": [ + "# Plotting scale factor as a function of tau.\n", + "\n", + "$a(\\tau)$" + ] + }, { "cell_type": "code", "execution_count": null, @@ -150,11 +277,12 @@ "metadata": {}, "outputs": [], "source": [ - "plt.figure(figsize=(14, 7))\n", + "plt.figure()\n", "\n", - "alpha_a = [Vexp.alpha(tau) for tau in tau_a]\n", + "print(Vexp_none.alpha_0e()) # alpha_0 na expansão\n", + "print(Vexp_none.tau_xe(1.0))\n", "\n", - "plt.plot(tau_a, np.exp(alpha_a) / Vexp.props.xb, label=r\"$a$\")\n", + "plt.plot(tau_a, np.exp(alpha_a) / Vexp_none.props.xb, label=r\"$a$\")\n", "\n", "plt.grid(visible=True, which=\"both\", linestyle=\":\", color=\"0.75\", linewidth=0.5)\n", "leg = plt.legend(loc=\"best\", ncol=2, fontsize=13)\n", @@ -165,6 +293,16 @@ "pass" ] }, + { + "cell_type": "markdown", + "id": "11ffc7cb", + "metadata": {}, + "source": [ + "# Plotting the scalar field as a function of tau.\n", + "\n", + "$\\phi(\\tau)$" + ] + }, { "cell_type": "code", "execution_count": null, @@ -172,9 +310,7 @@ "metadata": {}, "outputs": [], "source": [ - "plt.figure(figsize=(14, 7))\n", - "\n", - "phi_a = [Vexp.phi(tau) for tau in tau_a]\n", + "plt.figure()\n", "\n", "plt.plot(tau_a, phi_a, label=r\"$\\phi$\")\n", "\n", @@ -188,14 +324,40 @@ { "cell_type": "code", "execution_count": null, - "id": "1ef41aa3", + "id": "6165b7a9-60eb-46cd-9cdd-8388d2ad2fa0", "metadata": {}, "outputs": [], "source": [ - "plt.figure(figsize=(14, 7))\n", + "plt.figure()\n", + "\n", + "plt.plot(eta_a, phi_a, label=r\"$\\phi$\")\n", + "\n", + "plt.grid(visible=True, which=\"both\", linestyle=\":\", color=\"0.75\", linewidth=0.5)\n", + "leg = plt.legend(loc=\"best\", ncol=2, fontsize=13)\n", + "\n", + "plt.xscale(\"symlog\", linthresh=1.0e-1)\n", + "plt.xlabel(r\"$\\eta$\")\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "id": "33a74f85", + "metadata": {}, + "source": [ + "# Ploting Ricci scalar and mode frequency.\n", "\n", - "RS_a = [Vexp.Ricci_scale(tau) for tau in tau_a]\n", - "nu_a = [Vexp.eval_nu(tau, k) for tau in tau_a]\n", + "$R(\\tau)$ and $\\nu(\\tau)$" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1ef41aa3", + "metadata": {}, + "outputs": [], + "source": [ + "plt.figure()\n", "\n", "plt.plot(tau_a, RS_a, label=r\"$R_s$\")\n", "plt.plot(tau_a, nu_a, label=r\"$\\nu$\")\n", @@ -209,6 +371,16 @@ "plt.show()" ] }, + { + "cell_type": "markdown", + "id": "dcdcb840", + "metadata": {}, + "source": [ + "# Plotting background field variables\n", + "\n", + "$x(\\tau)$, $y(\\tau)$ and $\\sqrt{x^2 + y^2}$." + ] + }, { "cell_type": "code", "execution_count": null, @@ -216,9 +388,7 @@ "metadata": {}, "outputs": [], "source": [ - "plt.figure(figsize=(14, 7))\n", - "\n", - "x_y_a = np.array([Vexp.x_y(tau) for tau in tau_a])\n", + "plt.figure()\n", "\n", "plt.plot(tau_a, x_y_a[:, 0], label=\"$x$\")\n", "plt.plot(tau_a, x_y_a[:, 1], label=\"$y$\")\n", @@ -230,9 +400,39 @@ "plt.xlabel(r\"$\\tau$\")\n", "plt.yscale(\"symlog\")\n", "\n", + "plt.show()\n", + "\n", + "# Close-up on the Friedmann constraint in the quantum regime\n", + "plt.figure()\n", + "\n", + "plt.plot(\n", + " tau_a,\n", + " np.sqrt(x_y_a[:, 0] * x_y_a[:, 0] + x_y_a[:, 1] * x_y_a[:, 1]),\n", + " label=\"$x^2+y^2$\",\n", + ")\n", + "plt.plot(\n", + " tau_a,\n", + " np.hypot(x_y_a[:, 0], x_y_a[:, 1]),\n", + " label=\"$\\sqrt{x^2+y^2}$\",\n", + " linestyle=\"dashed\",\n", + ")\n", + "\n", + "plt.xlim(-0.25, 0.25)\n", + "plt.yscale(\"symlog\")\n", + "\n", "plt.show()" ] }, + { + "cell_type": "markdown", + "id": "566ed5a5", + "metadata": {}, + "source": [ + "# Plotting magnetic field background quantities \n", + "\n", + "$\\phi(\\tau)$, $f(\\phi(\\tau)) = e^{-\\phi^2/\\beta^2}$ and the equation of state $w$." + ] + }, { "cell_type": "code", "execution_count": null, @@ -240,300 +440,2146 @@ "metadata": {}, "outputs": [], "source": [ - "# plt.figure (figsize=(14, 7))\n", - "\n", - "# x_y_a = np.array ([Vexp.x_y (tau) for tau in tau_a])\n", + "plt.figure()\n", "\n", - "# plt.plot (tau_a, 2.0 * x_y_a[:,0]**2-1.0, label='$w = 2x^2-1$')\n", + "plt.plot(tau_a, phi_a, label=\"$\\phi$\")\n", + "# plt.plot (tau_a, np.exp (-(phi_a / beta)**2), label=r'$f(\\phi)$')\n", + "plt.plot(tau_a, 2.0 * x_y_a[:, 0] ** 2 - 1.0, label=\"$w = 2x^2-1$\")\n", "\n", - "# plt.grid (visible=True, which='both', linestyle=':', color='0.75', linewidth=0.5)\n", - "# leg = plt.legend (loc=\"best\", ncol = 2, fontsize=13)\n", + "plt.grid(visible=True, which=\"both\", linestyle=\":\", color=\"0.75\", linewidth=0.5)\n", + "leg = plt.legend(loc=\"best\", ncol=2, fontsize=13)\n", "\n", - "# plt.xlabel (r\"$\\tau$\")\n", + "plt.xlabel(r\"$\\tau$\")\n", "# plt.yscale('symlog')\n", - "# plt.ylim(-1.1, 1.1)\n", + "plt.xlim(-2.0, tau_qt_e)\n", + "plt.ylim(-1.1, 1.1)\n", "\n", - "# plt.show()\n", + "plt.show()\n", "\n", - "plt.figure(figsize=(14, 7))\n", + "###\n", + "### Equation of state\n", + "###\n", "\n", - "x_y_a = np.array([Vexp.x_y(tau) for tau in tau_q_a])\n", - "phi_q_a = [Vexp.phi(tau) for tau in tau_q_a]\n", - "phi_q_a = np.array(phi_q_a)\n", + "plt.figure()\n", "\n", - "plt.plot(tau_q_a, phi_q_a, label=\"$\\phi$\")\n", - "plt.plot(tau_q_a, np.exp(-((phi_q_a / 0.08) ** 2)), label=r\"$f(\\phi)$\")\n", - "plt.plot(tau_q_a, 2.0 * x_y_a[:, 0] ** 2 - 1.0, label=\"$w = 2x^2-1$\")\n", + "plt.plot(tau_a, 2.0 * x_y_a[:, 0] ** 2 - 1.0, label=\"$w = 2x^2-1$\")\n", "\n", "plt.grid(visible=True, which=\"both\", linestyle=\":\", color=\"0.75\", linewidth=0.5)\n", "leg = plt.legend(loc=\"best\", ncol=2, fontsize=13)\n", - "\n", + "plt.xlim(-0.025, 0.025)\n", "plt.xlabel(r\"$\\tau$\")\n", - "# plt.yscale('symlog')\n", - "plt.xlim(tau_qt_c, tau_qt_e)\n", - "plt.ylim(-2.1, 2.1)\n", "\n", "plt.show()" ] }, + { + "cell_type": "markdown", + "id": "3fd4824a", + "metadata": {}, + "source": [ + "# Defines the electromagnetic field model\n", + "\n", + "This model use the Complex Structure Quantization method CSQ1D." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b97f932b-65fa-4639-96c4-bdc8db63bb61", + "metadata": {}, + "outputs": [], + "source": [ + "tau_f = 10.0\n", + "\n", + "pem_none = Nc.HIPertEM.new()\n", + "pem_none.set_initial_condition_type(Ncm.CSQ1DInitialStateType.ADIABATIC2)\n", + "pem_none.set_abstol(\n", + " 1.0e-200\n", + ") # The vacuum is a fixed point at zero, we need an absolute tolerance to evolve the system\n", + "pem_none.set_k(1.0e3)\n", + "pem_none.set_ti(Vexp_none.tau_min())\n", + "pem_none.set_tf(tau_f) # We do not want to evolve through the singularity\n", + "pem_none.set_vacuum_max_time(-12.0)\n", + "pem_none.set_vacuum_reltol(1.0e-8)\n", + "\n", + "\n", + "pem_cauchy = Nc.HIPertEM.new()\n", + "pem_cauchy.set_k(1.0e3)\n", + "pem_cauchy.set_initial_condition_type(Ncm.CSQ1DInitialStateType.ADIABATIC4)\n", + "pem_cauchy.set_ti(Vexp_cauchy.tau_min())\n", + "pem_cauchy.set_tf(tau_f) # We do not want to evolve through the singularity\n", + "pem_cauchy.set_vacuum_max_time(-1.0e-1)\n", + "pem_cauchy.set_vacuum_reltol(1.0e-8)\n", + "\n", + "\n", + "pem_gauss = Nc.HIPertEM.new()\n", + "pem_gauss.set_initial_condition_type(Ncm.CSQ1DInitialStateType.ADIABATIC2)\n", + "pem_gauss.set_k(1.0e3)\n", + "pem_gauss.set_ti(Vexp_gauss.tau_min())\n", + "pem_gauss.set_tf(tau_f) # We do not want to evolve through the singularity\n", + "pem_gauss.set_vacuum_max_time(-1.0e-1)\n", + "pem_gauss.set_vacuum_reltol(1.0e-8)" + ] + }, + { + "cell_type": "markdown", + "id": "50bf1a78", + "metadata": {}, + "source": [ + "# Setting up models\n", + "\n", + "Setting up all models, including the benchmark with no coupling." + ] + }, + { + "cell_type": "markdown", + "id": "2eb3f807", + "metadata": {}, + "source": [ + "# Finding starting point as the end of the adiabatic phase\n", + "\n", + "Setting limit for the adiabatic phase with $10^{-9}$." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "15557cb5", + "metadata": {}, + "outputs": [], + "source": [ + "print(f\"Searching for WKB scale in ({tau_min}, {tau_qt_c})\")\n", + "\n", + "(Found_tau_i_none, tau_i_none) = pem_none.find_adiab_time_limit(\n", + " Vexp_none, tau_min, -12.0, 1.0e-9\n", + ")\n", + "(Found_tau_i_cauchy, tau_i_cauchy) = pem_cauchy.find_adiab_time_limit(\n", + " Vexp_cauchy, tau_min, -1.0e-5, 1.0e-9\n", + ")\n", + "(Found_tau_i_gauss, tau_i_gauss) = pem_gauss.find_adiab_time_limit(\n", + " Vexp_gauss, tau_min, -1.0e-5, 1.0e-9\n", + ")" + ] + }, + { + "cell_type": "markdown", + "id": "cc51f921", + "metadata": {}, + "source": [ + "# Checking if the search for the starting time was successful " + ] + }, { "cell_type": "code", "execution_count": null, - "id": "41770867", + "id": "4f5bf439", "metadata": {}, "outputs": [], "source": [ - "class PyCSQ1DMagScalarField(Ncm.CSQ1D):\n", - " def __init__(self, B, beta):\n", - " Ncm.CSQ1D.__init__(self)\n", - " self.B = B\n", - " self.beta = beta\n", + "print(\n", + " f\"Found ({Found_tau_i_none }) WKB scale for no-potential at {tau_i_none:7.3f}\"\n", + ")\n", + "print(\n", + " f\"Found ({Found_tau_i_cauchy}) WKB scale for cauchy-potential at {tau_i_cauchy:7.3f} (B = {Vexp_gauss.props.Bem:.2e}, beta = {Vexp_gauss.props.betaem})\"\n", + ")\n", + "print(\n", + " f\"Found ({Found_tau_i_gauss }) WKB scale for gauss-potential at {tau_i_gauss:7.3f} (B = {Vexp_gauss.props.Bem:.2e}, beta = {Vexp_gauss.props.betaem})\"\n", + ")\n", + "\n", + "print(pem_none.eval_F1(Vexp_none, tau_i_none))\n", + "print(pem_none.eval_F2(Vexp_none, tau_i_none))\n", + "print(pem_cauchy.eval_F1(Vexp_cauchy, tau_i_cauchy))\n", + "print(pem_cauchy.eval_F2(Vexp_cauchy, tau_i_cauchy))\n", + "print(pem_gauss.eval_F1(Vexp_gauss, tau_i_gauss))\n", + "print(pem_gauss.eval_F2(Vexp_gauss, tau_i_gauss))\n", + "\n", + "state_none = Ncm.CSQ1DState.new()\n", + "state_cauchy = Ncm.CSQ1DState.new()\n", + "state_gauss = Ncm.CSQ1DState.new()\n", + "\n", + "print(pem_none.compute_adiab(Vexp_none, tau_i_none, state_none)[0].get_ag())\n", + "print(pem_cauchy.compute_adiab(Vexp_cauchy, tau_i_cauchy, state_cauchy)[0].get_ag())\n", + "print(pem_gauss.compute_adiab(Vexp_gauss, tau_i_gauss, state_gauss)[0].get_ag())" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "46d519a9", + "metadata": {}, + "outputs": [], + "source": [ + "plt.figure()\n", "\n", - " def do_eval_xi(self, model, t, k):\n", - " return model.eval_xi(t, k, self.B, self.beta)\n", + "tau_ad_a = np.linspace(-2.35, -1.0, 100)\n", + "tau_ad_a = tau_a\n", "\n", - " def do_eval_nu(self, model, t, k):\n", - " return model.eval_nu(t, k)\n", "\n", - " def do_eval_nu2(self, model, t, k):\n", - " return model.eval_nu(t, k) ** 2\n", + "F1_a_cauchy = np.abs([pem_cauchy.eval_F1(Vexp_cauchy, tau) for tau in tau_ad_a])\n", + "F2_a_cauchy = np.abs([pem_cauchy.eval_F2(Vexp_cauchy, tau) for tau in tau_ad_a])\n", "\n", - " def do_eval_m(self, model, t, k):\n", - " return model.eval_m(t, self.B, self.beta)\n", + "F1_a_gauss = np.abs([pem_gauss.eval_F1(Vexp_gauss, tau) for tau in tau_ad_a])\n", + "F2_a_gauss = np.abs([pem_gauss.eval_F2(Vexp_gauss, tau) for tau in tau_ad_a])\n", "\n", - " def do_eval_F1(self, model, t, k):\n", - " return model.eval_F1(t, k, self.B, self.beta)\n", + "plt.plot(tau_ad_a, F1_a_cauchy, label=r\"cauchy $|F_1|$\")\n", + "plt.plot(tau_ad_a, F1_a_gauss, label=r\"gauss $|F_1|$\")\n", "\n", - " def do_prepare(self, model):\n", - " pass\n", + "plt.plot(tau_ad_a, F2_a_cauchy, label=r\"cauchy $|F_2|$\")\n", + "plt.plot(tau_ad_a, F2_a_gauss, label=r\"gauss $|F_2|$\")\n", "\n", - " def eval_PB_PE(self, model, t):\n", - " J11, _, J22 = self.get_J_at(model, t)\n", - " A2 = 0.5 * J11\n", - " PiA2 = 0.5 * J22\n", + "plt.grid(visible=True, which=\"both\", linestyle=\":\", color=\"0.75\", linewidth=0.5)\n", + "leg = plt.legend(loc=\"best\", ncol=2, fontsize=13)\n", "\n", - " alpha = model.alpha(t)\n", - " y = np.exp(alpha) / model.props.xb\n", - " RH = model.RH_Mpc()\n", - " k = self.get_k()\n", - " m = model.eval_m(t, self.B, self.beta)\n", - " PE = PiA2 * (k / y) ** 3 / (2.0 * math.pi**2 * RH**4 * m)\n", - " PB = m * A2 * (k / y) ** 5 / (2.0 * math.pi**2 * RH**4)\n", + "plt.ylim(1.0e-20, None)\n", + "plt.xlabel(r\"$\\tau$\")\n", + "plt.yscale(\"log\")\n", "\n", - " return PB, PE, J11, J22" + "plt.show()" ] }, { "cell_type": "code", "execution_count": null, - "id": "fc63790d", + "id": "1603d89c", "metadata": {}, "outputs": [], "source": [ - "k = 1.0e0\n", - "B0 = 1.0e-50\n", - "beta0 = 3.0e0\n", - "B1 = 1.0e30\n", - "beta1 = 3.0e0\n", + "pem_none.prepare(Vexp_none)\n", + "pem_cauchy.prepare(Vexp_cauchy)\n", + "pem_gauss.prepare(Vexp_gauss)\n", "\n", - "csq1d0 = PyCSQ1DMagScalarField(B0, beta0)\n", - "csq1d0.set_k(k)\n", - "csq1d1 = PyCSQ1DMagScalarField(B1, beta1)\n", - "csq1d1.set_k(k)" + "tau_evol_a_none, tau_s_none = pem_none.get_time_array()\n", + "tau_evol_a_none = np.array(tau_evol_a_none)\n", + "\n", + "tau_evol_a_cauchy, tau_s_gauss = pem_cauchy.get_time_array()\n", + "tau_evol_a_cauchy = np.array(tau_evol_a_cauchy)\n", + "\n", + "tau_evol_a_gauss, tau_s_gauss = pem_gauss.get_time_array()\n", + "tau_evol_a_gauss = np.array(tau_evol_a_gauss)" ] }, { "cell_type": "code", "execution_count": null, - "id": "15557cb5", + "id": "4d27899c", "metadata": {}, "outputs": [], "source": [ - "print(f\"Searching for WKB scale in ({tau_min}, {tau_qt_c})\")\n", - "# (Found2, tf) = csq1d.find_adiab_time_limit (Vexp, tau_min, tau_qt_c, 1.0e0)" + "PB_a_none = []\n", + "PE_a_none = []\n", + "J11_a_none = []\n", + "J22_a_none = []\n", + "\n", + "PB_a_cauchy = []\n", + "PE_a_cauchy = []\n", + "J11_a_cauchy = []\n", + "J22_a_cauchy = []\n", + "\n", + "PB_a_gauss = []\n", + "PE_a_gauss = []\n", + "J11_a_gauss = []\n", + "J22_a_gauss = []\n", + "\n", + "for tau in tau_evol_a_none:\n", + " PE, PB = pem_none.eval_PE_PB(Vexp_none, tau)\n", + " J11, _, J22 = pem_none.eval_at(Vexp_none, tau, state_none).get_J()\n", + " PE_a_none.append(PE)\n", + " PB_a_none.append(PB)\n", + " J11_a_none.append(J11)\n", + " J22_a_none.append(J22)\n", + "\n", + "for tau in tau_evol_a_cauchy:\n", + " PE, PB = pem_cauchy.eval_PE_PB(Vexp_cauchy, tau)\n", + " J11, _, J22 = pem_cauchy.eval_at(Vexp_cauchy, tau, state_cauchy).get_J()\n", + " PE_a_cauchy.append(PE)\n", + " PB_a_cauchy.append(PB)\n", + " J11_a_cauchy.append(J11)\n", + " J22_a_cauchy.append(J22)\n", + "\n", + "for tau in tau_evol_a_gauss:\n", + " PE, PB = pem_gauss.eval_PE_PB(Vexp_gauss, tau)\n", + " J11, _, J22 = pem_gauss.eval_at(Vexp_gauss, tau, state_gauss).get_J()\n", + " PE_a_gauss.append(PE)\n", + " PB_a_gauss.append(PB)\n", + " J11_a_gauss.append(J11)\n", + " J22_a_gauss.append(J22)\n", + "\n", + "PB_a_none = np.array(PB_a_none)\n", + "PE_a_none = np.array(PE_a_none)\n", + "J11_a_none = np.array(J11_a_none)\n", + "J22_a_none = np.array(J22_a_none)\n", + "\n", + "PB_a_cauchy = np.array(PB_a_cauchy)\n", + "PE_a_cauchy = np.array(PE_a_cauchy)\n", + "J11_a_cauchy = np.array(J11_a_cauchy)\n", + "J22_a_cauchy = np.array(J22_a_cauchy)\n", + "\n", + "PB_a_gauss = np.array(PB_a_gauss)\n", + "PE_a_gauss = np.array(PE_a_gauss)\n", + "J11_a_gauss = np.array(J11_a_gauss)\n", + "J22_a_gauss = np.array(J22_a_gauss)" ] }, { "cell_type": "code", "execution_count": null, - "id": "4f5bf439", + "id": "3b581dae", "metadata": {}, "outputs": [], "source": [ - "from scipy.optimize import minimize\n", + "mylw = 1\n", "\n", - "tau_i0 = -12.0e0\n", - "tau_i1 = -14.0e0\n", - "tau_f = 10.0\n", + "plt.figure()\n", + "\n", + "plt.plot(\n", + " tau_evol_a_none,\n", + " J22_a_none,\n", + " lw=mylw,\n", + " label=f\"no-pot $J_{{22}}(k_s = {pem_none.get_k()})$\",\n", + ")\n", + "plt.plot(\n", + " tau_evol_a_gauss,\n", + " J22_a_gauss,\n", + " lw=mylw,\n", + " label=f\"gauss $J_{{22}}(k_s = {pem_gauss.get_k()})$\",\n", + ")\n", + "\n", + "leg = plt.legend(loc=\"best\", ncol=2, fontsize=13)\n", + "plt.yscale(\"log\")\n", + "plt.show()\n", + "\n", + "plt.figure()\n", + "\n", + "plt.plot(\n", + " tau_evol_a_cauchy,\n", + " J22_a_cauchy,\n", + " lw=mylw,\n", + " label=f\"cauchy $J_{{22}}(k_s = {pem_cauchy.get_k()})$\",\n", + ")\n", + "\n", + "leg = plt.legend(loc=\"best\", ncol=2, fontsize=13)\n", + "plt.yscale(\"log\")\n", + "plt.show()\n", + "\n", + "# Loop over k (TO FIX: same J for k=1 and k=4.000)\n", + "\n", + "# plt.figure (figsize=(16, 8))\n", + "\n", + "# mylw = 1\n", "\n", - "print(csq1d0.eval_F1(Vexp, tau_i0, k))\n", - "print(csq1d1.eval_F1(Vexp, tau_i1, k))\n", + "# for k in k_a:\n", "\n", - "print(csq1d0.eval_adiab_at(Vexp, tau_i0))\n", - "print(csq1d1.eval_adiab_at(Vexp, tau_i1))" + "# plt.plot (tau_evol_a0, J22_a0, lw=mylw, label = f'$J^0_{{22}}(k_s = %s)$'% latex_float (k))\n", + "# plt.plot (tau_evol_a1, J22_a1, lw=mylw, label = f'$J^1_{{22}}(k_s = %s)$'% latex_float (k))\n", + "\n", + "# leg = plt.legend (loc=\"best\", ncol = 2, fontsize=13)\n", + "# plt.yscale(\"log\")" ] }, { "cell_type": "code", "execution_count": null, - "id": "46d519a9", + "id": "c01f786b", "metadata": {}, "outputs": [], "source": [ - "plt.figure(figsize=(14, 7))\n", + "plt.figure()\n", + "\n", + "plt.plot(\n", + " tau_evol_a_none,\n", + " J11_a_none,\n", + " lw=mylw,\n", + " label=f\"no-pot $J_{{11}}(k_s = {pem_none.get_k()})$\",\n", + ")\n", + "plt.plot(\n", + " tau_evol_a_gauss,\n", + " J11_a_gauss,\n", + " lw=mylw,\n", + " label=f\"gauss $J_{{11}}(k_s = {pem_gauss.get_k()})$\",\n", + ")\n", + "\n", + "leg = plt.legend(loc=\"best\", ncol=2, fontsize=13)\n", + "plt.yscale(\"log\")\n", + "plt.show()\n", + "\n", + "plt.figure()\n", + "\n", + "plt.plot(\n", + " tau_evol_a_cauchy,\n", + " J11_a_cauchy,\n", + " lw=mylw,\n", + " label=f\"cauchy $J_{{11}}(k_s = {pem_cauchy.get_k()})$\",\n", + ")\n", + "\n", + "leg = plt.legend(loc=\"best\", ncol=2, fontsize=13)\n", + "plt.yscale(\"log\")\n", + "plt.show()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "594d9532", + "metadata": {}, + "outputs": [], + "source": [ + "plt.figure()\n", + "\n", + "plt.plot(\n", + " tau_evol_a_none,\n", + " PB_a_none,\n", + " lw=mylw,\n", + " label=f\"no-pot $P_{{B}}(k_s = {pem_none.get_k()})$\",\n", + ")\n", + "plt.plot(\n", + " tau_evol_a_gauss,\n", + " PB_a_gauss,\n", + " lw=mylw,\n", + " label=f\"gauss $P_{{B}}(k_s = {pem_gauss.get_k()})$\",\n", + ")\n", + "plt.plot(\n", + " tau_evol_a_cauchy,\n", + " PB_a_cauchy,\n", + " lw=mylw,\n", + " label=f\"cauchy $P_{{B}}(k_s = {pem_cauchy.get_k()})$\",\n", + ")\n", + "\n", + "leg = plt.legend(loc=\"best\", ncol=2, fontsize=13)\n", + "plt.yscale(\"log\")\n", + "# plt.xlim(8.0, None)\n", + "# plt.ylim(1.0e-60,None)\n", + "plt.show()\n", + "\n", + "plt.figure()\n", + "\n", + "plt.plot(\n", + " tau_evol_a_none,\n", + " PE_a_none,\n", + " lw=mylw,\n", + " label=f\"no-pot $P_{{E}}(k_s = {pem_none.get_k()})$\",\n", + ")\n", + "plt.plot(\n", + " tau_evol_a_gauss,\n", + " PE_a_gauss,\n", + " lw=mylw,\n", + " label=f\"gauss $P_{{E}}(k_s = {pem_gauss.get_k()})$\",\n", + ")\n", + "plt.plot(\n", + " tau_evol_a_cauchy,\n", + " PE_a_cauchy,\n", + " lw=mylw,\n", + " label=f\"cauchy $P_{{E}}(k_s = {pem_cauchy.get_k()})$\",\n", + ")\n", + "\n", + "leg = plt.legend(loc=\"best\", ncol=2, fontsize=13)\n", + "plt.yscale(\"log\")\n", + "# plt.xlim(-5.0,5.0)\n", + "# plt.ylim(1.0e-85, None)\n", + "\n", + "plt.show()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a03afde0-cfe3-4d2d-b3f9-f805bf20d966", + "metadata": {}, + "outputs": [], + "source": [ + "plt.figure()\n", + "\n", + "plt.plot(\n", + " tau_evol_a_none,\n", + " PB_a_none,\n", + " lw=mylw,\n", + " label=f\"no-pot $P_{{B}}(k_s = {pem_none.get_k()})$\",\n", + ")\n", + "# plt.plot(tau_evol_a_gauss, PB_a_gauss, lw=mylw, label=f\"gauss $P_{{B}}(k_s = {pem_gauss.get_k()})$\")\n", + "# plt.plot(tau_evol_a_cauchy, PB_a_cauchy, lw=mylw, label=f\"cauchy $P_{{B}}(k_s = {pem_cauchy.get_k()})$\")\n", + "plt.plot(\n", + " tau_evol_a_none,\n", + " PE_a_none,\n", + " lw=mylw,\n", + " label=f\"no-pot $P_{{E}}(k_s = {pem_none.get_k()})$\",\n", + ")\n", + "# plt.plot(tau_evol_a_gauss, PE_a_gauss, lw=mylw, label=f\"gauss $P_{{E}}(k_s = {pem_gauss.get_k()})$\")\n", + "# plt.plot(tau_evol_a_cauchy, PE_a_cauchy, lw=mylw, label=f\"cauchy $P_{{E}}(k_s = {pem_cauchy.get_k()})$\")\n", + "\n", + "leg = plt.legend(loc=\"best\", ncol=2, fontsize=13)\n", + "plt.yscale(\"log\")\n", + "# plt.xlim(-5.0,5.0)\n", + "# plt.ylim(1.0e-125, None)\n", + "\n", + "plt.show()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "86c4839c", + "metadata": {}, + "outputs": [], + "source": [ + "###\n", + "### Loop over k\n", + "###\n", "\n", "tau_ad_a = np.linspace(-1.35, -1.0, 100)\n", - "tau_ad_a = tau_a\n", "\n", - "F1_a0 = np.array([csq1d0.eval_F1(Vexp, tau, k) for tau in tau_ad_a])\n", - "F2_a0 = np.array([csq1d0.eval_F2(Vexp, tau, k) for tau in tau_ad_a])\n", - "nu_a0 = np.array([csq1d0.eval_nu(Vexp, tau, k) for tau in tau_ad_a])\n", + "ki = 1.0\n", + "kf = 4.0e3\n", + "k_a = np.geomspace(ki, kf, 3)\n", "\n", - "F1_a1 = np.array([csq1d1.eval_F1(Vexp, tau, k) for tau in tau_ad_a])\n", - "F2_a1 = np.array([csq1d1.eval_F2(Vexp, tau, k) for tau in tau_ad_a])\n", - "nu_a1 = np.array([csq1d1.eval_nu(Vexp, tau, k) for tau in tau_ad_a])\n", + "B0 = 1.0e-50\n", + "beta0 = 8.0e-1\n", + "B1 = 1.0e50\n", + "beta1 = 8.0e-1\n", + "\n", + "\n", + "csq1d_nopot = PyCSQ1DMagCauchy(B0, beta0)\n", + "csq1d_gauss = PyCSQ1DMagGauss(B1, beta1)\n", + "csq1d_cauchy = PyCSQ1DMagCauchy(B1, beta1)\n", + "\n", + "\n", + "# Define map colours for easier visualisation\n", + "# Maps are defined there: https://matplotlib.org/stable/tutorials/colors/colormaps.html\n", + "# colormapF1a_nopot = plt.get_cmap('Blues')\n", + "# colorsF1a_nopot = iter(colormapF1a_nopot(np.linspace(0,1,len(k_a))))\n", + "# colormapF1a_gauss = plt.get_cmap('Greens')\n", + "# colorsF1a_gauss = iter(colormapF1a_gauss(np.linspace(0,1,len(k_a))))\n", + "# colormapF1a_cauchy = plt.get_cmap('Reds')\n", + "# colorsF1a_cauchy = iter(colormapF1a_cauchy(np.linspace(0,1,len(k_a))))\n", + "\n", + "# colormapF2a_nopot = plt.get_cmap('Dark2')\n", + "# colorsF2a_nopot = iter(colormapF2a_nopot(np.linspace(0,1,len(k_a))))\n", + "# colormapF2a_gauss = plt.get_cmap('Dark2')\n", + "# colorsF2a_gauss = iter(colormapF2a_gauss(np.linspace(0,1,len(k_a))))\n", + "# colormapF2a_cauchy = plt.get_cmap('Dark2')\n", + "# colorsF2a_cauchy = iter(colormapF2a_cauchy(np.linspace(0,1,len(k_a))))\n", + "\n", + "\n", + "color_nopot = iter(\n", + " cm.Reds(np.linspace(1 / 2, 1, len(k_a)))\n", + ") # Go from 1/2 to 1 to display colours not too bright\n", + "color_gauss = iter(cm.Blues(np.linspace(1 / 2, 1, len(k_a))))\n", + "color_cauchy = iter(cm.Greens(np.linspace(1 / 2, 1, len(k_a))))\n", + "\n", + "plt.figure(figsize=(16, 8))\n", + "\n", + "\n", + "###\n", + "### TO DO: fix the overlapping ticks on the y-axis\n", + "###\n", + "\n", + "# First loop for F1\n", + "for k in k_a:\n", + " csq1d_nopot.set_k(k)\n", + " csq1d_gauss.set_k(k)\n", + " csq1d_cauchy.set_k(k)\n", + "\n", + " print(f\"Searching for WKB scale in ({tau_min}, {tau_qt_c})\")\n", + "\n", + " (Found_tau_i_nopot, tau_i_nopot) = csq1d_nopot.find_adiab_time_limit(\n", + " Vexp, tau_min, -1.0e-2, 1.0e-9\n", + " )\n", + " (Found_tau_i_gauss, tau_i_gauss) = csq1d_gauss.find_adiab_time_limit(\n", + " Vexp, tau_min, -1.0e-2, 1.0e-9\n", + " )\n", + " (Found_tau_i_cauchy, tau_i_cauchy) = csq1d_cauchy.find_adiab_time_limit(\n", + " Vexp, tau_min, -1.0e-2, 1.0e-9\n", + " )\n", + "\n", + " print(csq1d_nopot.eval_F1(Vexp, tau_i_nopot, k))\n", + " print(csq1d_gauss.eval_F1(Vexp, tau_i_gauss, k))\n", + " print(csq1d_cauchy.eval_F1(Vexp, tau_i_cauchy, k))\n", + "\n", + " print(csq1d_nopot.eval_adiab_at(Vexp, tau_i_nopot))\n", + " print(csq1d_gauss.eval_adiab_at(Vexp, tau_i_gauss))\n", + " print(csq1d_cauchy.eval_adiab_at(Vexp, tau_i_cauchy))\n", + "\n", + " F1_a_nopot = np.array([csq1d_nopot.eval_F1(Vexp, tau, k) for tau in tau_ad_a])\n", + " # F2_a_nopot = np.array ([csq1d_nopot.eval_F2 (Vexp, tau, k) for tau in tau_ad_a])\n", + " nu_a_nopot = np.array([csq1d_nopot.eval_nu(Vexp, tau, k) for tau in tau_ad_a])\n", + "\n", + " F1_a_gauss = np.array([csq1d_gauss.eval_F1(Vexp, tau, k) for tau in tau_ad_a])\n", + " # F2_a_gauss = np.array ([csq1d_gauss.eval_F2 (Vexp, tau, k) for tau in tau_ad_a])\n", + " nu_a_gauss = np.array([csq1d_gauss.eval_nu(Vexp, tau, k) for tau in tau_ad_a])\n", + "\n", + " F1_a_cauchy = np.array([csq1d_cauchy.eval_F1(Vexp, tau, k) for tau in tau_ad_a])\n", + " # F2_a_cauchy = np.array ([csq1d_cauchy.eval_F2 (Vexp, tau, k) for tau in tau_ad_a])\n", + " nu_a_cauchy = np.array([csq1d_cauchy.eval_nu(Vexp, tau, k) for tau in tau_ad_a])\n", + "\n", + " c_nopot = next(color_nopot)\n", + " c_gauss = next(color_gauss)\n", + " c_cauchy = next(color_cauchy)\n", + "\n", + " plt.plot(\n", + " tau_ad_a,\n", + " F1_a_nopot,\n", + " label=r\"$F^{nopot}_1$ (k = $%s$)\" % latex_float(k),\n", + " c=c_nopot,\n", + " ) # color=next(colorsF1a_nopot))\n", + " plt.plot(\n", + " tau_ad_a,\n", + " F1_a_gauss,\n", + " label=r\"$F^{gauss}_1$ (k = $%s$)\" % latex_float(k),\n", + " c=c_gauss,\n", + " ) # color=next(colorsF1a_gauss))\n", + " plt.plot(\n", + " tau_ad_a,\n", + " F1_a_cauchy,\n", + " label=r\"$F^{cauchy}_1$ (k = $%s$)\" % latex_float(k),\n", + " c=c_cauchy,\n", + " ) # color=next(colorsF1a_cauchy))\n", + " # plt.plot (tau_ad_a, F2_a_nopot, label=r\"$F^{nopot}_2$ (k = $%s$)\"% latex_float (k),c=c1)#color=next(colorsF2a_nopot))\n", + " # plt.plot (tau_ad_a, F2_a_gauss, label=r\"$F^{gauss}_2$ (k = $%s$)\"% latex_float (k),c=c2)#color=next(colorsF2a_gauss))\n", + " # plt.plot (tau_ad_a, F2_a_cauchy, label=r\"$F^{cauchy}_2$ (k = $%s$)\"% latex_float (k),c=c3)#color=next(colorsF2a_cauchy))\n", "\n", - "plt.plot(tau_ad_a, F1_a0, label=r\"$F^0_1$\")\n", - "plt.plot(tau_ad_a, F1_a1, label=r\"$F^1_1$\")\n", - "# plt.plot (tau_ad_a, F2_a, label=r\"$F_2$\")\n", "\n", "plt.grid(visible=True, which=\"both\", linestyle=\":\", color=\"0.75\", linewidth=0.5)\n", - "leg = plt.legend(loc=\"best\", ncol=2, fontsize=13)\n", + "leg = plt.legend(loc=\"best\", ncol=2, fontsize=16)\n", "\n", "plt.xlabel(r\"$\\tau$\")\n", "plt.xscale(\"symlog\")\n", - "plt.yscale(\"symlog\")\n", + "plt.yscale(\"symlog\", linthresh=1.0e-10)\n", + "\n", + "# Erase overlapping ticks labels\n", + "ticks_F1 = plt.yticks()[0]\n", + "ticks_F1[2] = 0\n", + "ticks_F1[4] = 0\n", + "plt.yticks(ticks_F1)\n", + "\n", + "plt.savefig(plotpath + \"plotF1_\" + current_set + \".pdf\")\n", + "\n", + "plt.show()\n", + "\n", + "\n", + "# Reinitialise the color map\n", + "color_nopot = iter(cm.Reds(np.linspace(1 / 2, 1, len(k_a))))\n", + "color_gauss = iter(cm.Blues(np.linspace(1 / 2, 1, len(k_a))))\n", + "color_cauchy = iter(cm.Greens(np.linspace(1 / 2, 1, len(k_a))))\n", + "\n", + "plt.figure(figsize=(16, 8))\n", + "\n", + "# Second loop for F2\n", + "for k in k_a:\n", + " csq1d_nopot.set_k(k)\n", + " csq1d_gauss.set_k(k)\n", + " csq1d_cauchy.set_k(k)\n", + "\n", + " print(f\"Searching for WKB scale in ({tau_min}, {tau_qt_c})\")\n", + "\n", + " (Found_tau_i_nopot, tau_i_nopot) = csq1d_nopot.find_adiab_time_limit(\n", + " Vexp, tau_min, -1.0e-2, 1.0e-9\n", + " )\n", + " (Found_tau_i_gauss, tau_i_gauss) = csq1d_gauss.find_adiab_time_limit(\n", + " Vexp, tau_min, -1.0e-2, 1.0e-9\n", + " )\n", + " (Found_tau_i_cauchy, tau_i_cauchy) = csq1d_cauchy.find_adiab_time_limit(\n", + " Vexp, tau_min, -1.0e-2, 1.0e-9\n", + " )\n", + "\n", + " print(csq1d_nopot.eval_F1(Vexp, tau_i_nopot, k))\n", + " print(csq1d_gauss.eval_F1(Vexp, tau_i_gauss, k))\n", + " print(csq1d_cauchy.eval_F1(Vexp, tau_i_cauchy, k))\n", + "\n", + " print(csq1d_nopot.eval_adiab_at(Vexp, tau_i_nopot))\n", + " print(csq1d_gauss.eval_adiab_at(Vexp, tau_i_gauss))\n", + " print(csq1d_cauchy.eval_adiab_at(Vexp, tau_i_cauchy))\n", + "\n", + " # F1_a_nopot = np.array ([csq1d_nopot.eval_F1 (Vexp, tau, k) for tau in tau_ad_a])\n", + " F2_a_nopot = np.array([csq1d_nopot.eval_F2(Vexp, tau, k) for tau in tau_ad_a])\n", + " nu_a_nopot = np.array([csq1d_nopot.eval_nu(Vexp, tau, k) for tau in tau_ad_a])\n", + "\n", + " # F1_a_gauss = np.array ([csq1d_gauss.eval_F1 (Vexp, tau, k) for tau in tau_ad_a])\n", + " F2_a_gauss = np.array([csq1d_gauss.eval_F2(Vexp, tau, k) for tau in tau_ad_a])\n", + " nu_a_gauss = np.array([csq1d_gauss.eval_nu(Vexp, tau, k) for tau in tau_ad_a])\n", + "\n", + " # F1_a_cauchy = np.array ([csq1d_cauchy.eval_F1 (Vexp, tau, k) for tau in tau_ad_a])\n", + " F2_a_cauchy = np.array([csq1d_cauchy.eval_F2(Vexp, tau, k) for tau in tau_ad_a])\n", + " nu_a_cauchy = np.array([csq1d_cauchy.eval_nu(Vexp, tau, k) for tau in tau_ad_a])\n", + "\n", + " c_nopot = next(color_nopot)\n", + " c_gauss = next(color_gauss)\n", + " c_cauchy = next(color_cauchy)\n", + "\n", + " # plt.plot (tau_ad_a, F1_a_nopot, label=r\"$F^{nopot}_1$ (k = $%s$)\"% latex_float (k),c=c1)#color=next(colorsF1a_nopot))\n", + " # plt.plot (tau_ad_a, F1_a_gauss, label=r\"$F^{gauss}_1$ (k = $%s$)\"% latex_float (k),c=c2)#color=next(colorsF1a_gauss))\n", + " # plt.plot (tau_ad_a, F1_a_cauchy, label=r\"$F^{cauchy}_1$ (k = $%s$)\"% latex_float (k),c=c3)#color=next(colorsF1a_cauchy))\n", + " plt.plot(\n", + " tau_ad_a,\n", + " F2_a_nopot,\n", + " label=r\"$F^{nopot}_2$ (k = $%s$)\" % latex_float(k),\n", + " c=c_nopot,\n", + " ) # color=next(colorsF2a_nopot))\n", + " plt.plot(\n", + " tau_ad_a,\n", + " F2_a_gauss,\n", + " label=r\"$F^{gauss}_2$ (k = $%s$)\" % latex_float(k),\n", + " c=c_gauss,\n", + " ) # color=next(colorsF2a_gauss))\n", + " plt.plot(\n", + " tau_ad_a,\n", + " F2_a_cauchy,\n", + " label=r\"$F^{cauchy}_2$ (k = $%s$)\" % latex_float(k),\n", + " c=c_cauchy,\n", + " ) # color=next(colorsF2a_cauchy))\n", + "\n", + "plt.grid(visible=True, which=\"both\", linestyle=\":\", color=\"0.75\", linewidth=0.5)\n", + "leg = plt.legend(loc=\"best\", ncol=2, fontsize=16)\n", + "\n", + "plt.xlabel(r\"$\\tau$\")\n", + "plt.xscale(\"symlog\")\n", + "plt.yscale(\"symlog\", linthresh=1.0e-10)\n", + "\n", + "# Erase overlapping ticks labels\n", + "ticks_F2 = plt.yticks()[0]\n", + "ticks_F2[7] = 0\n", + "ticks_F2[9] = 0\n", + "plt.yticks(ticks_F2)\n", + "\n", + "plt.savefig(plotpath + \"plotF2_\" + current_set + \".pdf\")\n", "\n", "plt.show()" ] }, { - "cell_type": "markdown", - "id": "6da0d3d9", + "cell_type": "code", + "execution_count": null, + "id": "82a8f6fd", "metadata": {}, + "outputs": [], "source": [ - "tau_i = -0.94\n", - "tau_f = 5.0\n", - "print(csq1d0.eval_adiab_at (Vexp, tau_i))\n", - "print(csq1d1.eval_adiab_at (Vexp, tau_i))" + "ki = 1.0\n", + "kf = 4.0e3\n", + "k_a = np.geomspace(ki, kf, 3)\n", + "\n", + "tau_f = 10.0\n", + "\n", + "B0 = 1.0e-50\n", + "beta0 = 8.0e-1\n", + "B1 = 1.0e50\n", + "beta1 = 8.0e-1\n", + "\n", + "\n", + "csq1d_nopot = PyCSQ1DMagCauchy(B0, beta0)\n", + "csq1d_gauss = PyCSQ1DMagGauss(B1, beta1)\n", + "csq1d_cauchy = PyCSQ1DMagCauchy(B1, beta1)\n", + "\n", + "# Define map colours for easier visualisation\n", + "# Maps are defined there: https://matplotlib.org/stable/tutorials/colors/colormaps.html\n", + "# colormapF1a0= plt.get_cmap('Accent')\n", + "# colorsF1a0 = iter(colormapF1a0(np.linspace(0,1,10)))\n", + "# colormapF1a1= plt.get_cmap('Accent')\n", + "# colorsF1a1 = iter(colormapF1a1(np.linspace(0,1,10)))\n", + "# colormapF2a0= plt.get_cmap('Dark2')\n", + "# colorsF2a0 = iter(colormapF2a0(np.linspace(0,1,10)))\n", + "# colormapF2a1= plt.get_cmap('Dark2')\n", + "# colorsF2a1 = iter(colormapF2a1(np.linspace(0,1,10)))\n", + "\n", + "\n", + "color_nopot = iter(\n", + " cm.Reds(np.linspace(1 / 2, 1, len(k_a)))\n", + ") # Go from 1/2 to 1 to display colours not too bright\n", + "color_gauss = iter(cm.Blues(np.linspace(1 / 2, 1, len(k_a))))\n", + "color_cauchy = iter(cm.Greens(np.linspace(1 / 2, 1, len(k_a))))\n", + "\n", + "tau_ad_a = np.linspace(-1.35, -1.0, 100)\n", + "tau_ad_a = tau_a\n", + "\n", + "plt.figure(figsize=(14, 7))\n", + "\n", + "mylw = 1\n", + "\n", + "for k in k_a:\n", + " csq1d_nopot.set_k(k)\n", + " csq1d_gauss.set_k(k)\n", + " csq1d_cauchy.set_k(k)\n", + "\n", + " print(f\"Searching for WKB scale in ({tau_min}, {tau_qt_c})\")\n", + "\n", + " (Found_tau_i_nopot, tau_i_nopot) = csq1d_nopot.find_adiab_time_limit(\n", + " Vexp, tau_min, -1.0e-2, 1.0e-9\n", + " )\n", + " (Found_tau_i_gauss, tau_i_gauss) = csq1d_gauss.find_adiab_time_limit(\n", + " Vexp, tau_min, -1.0e-2, 1.0e-9\n", + " )\n", + " (Found_tau_i_cauchy, tau_i_cauchy) = csq1d_cauchy.find_adiab_time_limit(\n", + " Vexp, tau_min, -1.0e-2, 1.0e-9\n", + " )\n", + "\n", + " print(csq1d_nopot.eval_F1(Vexp, tau_i_nopot, k))\n", + " print(csq1d_gauss.eval_F1(Vexp, tau_i_gauss, k))\n", + " print(csq1d_cauchy.eval_F1(Vexp, tau_i_cauchy, k))\n", + "\n", + " print(csq1d_nopot.eval_adiab_at(Vexp, tau_i_nopot))\n", + " print(csq1d_gauss.eval_adiab_at(Vexp, tau_i_gauss))\n", + " print(csq1d_cauchy.eval_adiab_at(Vexp, tau_i_cauchy))\n", + "\n", + " F1_a_nopot = np.array([csq1d_nopot.eval_F1(Vexp, tau, k) for tau in tau_ad_a])\n", + " F2_a_nopot = np.array([csq1d_nopot.eval_F2(Vexp, tau, k) for tau in tau_ad_a])\n", + " nu_a_nopot = np.array([csq1d_nopot.eval_nu(Vexp, tau, k) for tau in tau_ad_a])\n", + "\n", + " F1_a_gauss = np.array([csq1d_gauss.eval_F1(Vexp, tau, k) for tau in tau_ad_a])\n", + " F2_a_gauss = np.array([csq1d_gauss.eval_F2(Vexp, tau, k) for tau in tau_ad_a])\n", + " nu_a_gauss = np.array([csq1d_gauss.eval_nu(Vexp, tau, k) for tau in tau_ad_a])\n", + "\n", + " F1_a_cauchy = np.array([csq1d_cauchy.eval_F1(Vexp, tau, k) for tau in tau_ad_a])\n", + " F2_a_cauchy = np.array([csq1d_cauchy.eval_F2(Vexp, tau, k) for tau in tau_ad_a])\n", + " nu_a_cauchy = np.array([csq1d_cauchy.eval_nu(Vexp, tau, k) for tau in tau_ad_a])\n", + "\n", + " csq1d_nopot.set_init_cond_adiab(Vexp, tau_i_nopot)\n", + " csq1d_gauss.set_init_cond_adiab(Vexp, tau_i_gauss)\n", + " csq1d_cauchy.set_init_cond_adiab(Vexp, tau_i_cauchy)\n", + "\n", + " csq1d_nopot.set_ti(tau_i_nopot)\n", + " csq1d_nopot.set_tf(tau_f)\n", + " csq1d_nopot.prepare(Vexp)\n", + "\n", + " csq1d_gauss.set_ti(tau_i_gauss)\n", + " csq1d_gauss.set_tf(tau_f)\n", + " csq1d_gauss.prepare(Vexp)\n", + "\n", + " csq1d_cauchy.set_ti(tau_i_cauchy)\n", + " csq1d_cauchy.set_tf(tau_f)\n", + " csq1d_cauchy.prepare(Vexp)\n", + "\n", + " tau_evol_a_nopot, tau_s_nopot = csq1d_nopot.get_time_array()\n", + " tau_evol_a_nopot = np.array(tau_evol_a_nopot)\n", + "\n", + " tau_evol_a_gauss, tau_s_gauss = csq1d_gauss.get_time_array()\n", + " tau_evol_a_gauss = np.array(tau_evol_a_gauss)\n", + "\n", + " tau_evol_a_cauchy, tau_s_cauchy = csq1d_cauchy.get_time_array()\n", + " tau_evol_a_cauchy = np.array(tau_evol_a_cauchy)\n", + "\n", + " PB_a_nopot = []\n", + " PE_a_nopot = []\n", + " J11_a_nopot = []\n", + " J22_a_nopot = []\n", + "\n", + " PB_a_gauss = []\n", + " PE_a_gauss = []\n", + " J11_a_gauss = []\n", + " J22_a_gauss = []\n", + "\n", + " PB_a_cauchy = []\n", + " PE_a_cauchy = []\n", + " J11_a_cauchy = []\n", + " J22_a_cauchy = []\n", + "\n", + " for tau in tau_evol_a_nopot:\n", + " PB, PE, J11, J22 = csq1d_nopot.eval_PB_PE(Vexp, tau)\n", + " PB_a_nopot.append(PB)\n", + " PE_a_nopot.append(PE)\n", + " J11_a_nopot.append(J11)\n", + " J22_a_nopot.append(J22)\n", + "\n", + " for tau in tau_evol_a_gauss:\n", + " PB, PE, J11, J22 = csq1d_gauss.eval_PB_PE(Vexp, tau)\n", + " # PB_a_gauss.append(PB)\n", + " # PE_a_gauss.append(PE)\n", + " # J11_a_gauss.append(J11)\n", + " J22_a_gauss.append(J22)\n", + "\n", + " for tau in tau_evol_a_cauchy:\n", + " PB, PE, J11, J22 = csq1d_cauchy.eval_PB_PE(Vexp, tau)\n", + " # PB_a_cauchy.append(PB)\n", + " # PE_a_cauchy.append(PE)\n", + " # J11_a_cauchy.append(J11)\n", + " J22_a_cauchy.append(J22)\n", + "\n", + " # PB_a_nopot = np.array(PB_a_nopot)\n", + " # PE_a_nopot = np.array(PE_a_nopot)\n", + " # J11_a_nopot = np.array(J11_a_nopot)\n", + " J22_a_nopot = np.array(J22_a_nopot)\n", + "\n", + " # PB_a_gauss = np.array(PB_a_gauss)\n", + " # PE_a_gauss = np.array(PE_a_gauss)\n", + " # J11_a_gauss = np.array(J11_a_gauss)\n", + " J22_a_gauss = np.array(J22_a_gauss)\n", + "\n", + " # PB_a_cauchy = np.array(PB_a_cauchy)\n", + " # PE_a_cauchy = np.array(PE_a_cauchy)\n", + " # J11_a_cauchy = np.array(J11_a_cauchy)\n", + " J22_a_cauchy = np.array(J22_a_cauchy)\n", + "\n", + " c_nopot = next(color_nopot)\n", + " c_gauss = next(color_gauss)\n", + " c_cauchy = next(color_cauchy)\n", + "\n", + " plt.plot(\n", + " tau_evol_a_nopot,\n", + " J22_a_nopot,\n", + " c=c_nopot,\n", + " lw=mylw,\n", + " label=f\"$J^{{nopot}}_{{22}}$ (k = $%s$)\" % latex_float(k),\n", + " )\n", + " plt.plot(\n", + " tau_evol_a_gauss,\n", + " J22_a_gauss,\n", + " c=c_gauss,\n", + " lw=mylw,\n", + " label=f\"$J^{{gauss}}_{{22}}$ (k = $%s$)\" % latex_float(k),\n", + " )\n", + " plt.plot(\n", + " tau_evol_a_cauchy,\n", + " J22_a_cauchy,\n", + " c=c_cauchy,\n", + " lw=mylw,\n", + " label=f\"$J^{{cauchy}}_{{22}}$ (k = $%s$)\" % latex_float(k),\n", + " )\n", + "\n", + "\n", + "leg = plt.legend(loc=\"center left\", ncol=2, fontsize=16)\n", + "plt.yscale(\"log\")\n", + "plt.xlabel(r\"$\\tau$\")\n", + "\n", + "plt.savefig(plotpath + \"plotJ22_\" + current_set + \".pdf\")\n", + "\n", + "plt.show()" ] }, { "cell_type": "code", "execution_count": null, - "id": "825f9b1d", + "id": "c8225ea8", "metadata": {}, "outputs": [], "source": [ - "csq1d0.set_init_cond_adiab(Vexp, tau_i0)\n", - "csq1d1.set_init_cond_adiab(Vexp, tau_i1)" + "ki = 1.0\n", + "kf = 4.0e3\n", + "k_a = np.geomspace(ki, kf, 3)\n", + "\n", + "B0 = 1.0e-50\n", + "beta0 = 8.0e-1\n", + "B1 = 1.0e50\n", + "beta1 = 8.0e-1\n", + "\n", + "csq1d_nopot = PyCSQ1DMagCauchy(B0, beta0)\n", + "csq1d_gauss = PyCSQ1DMagGauss(B1, beta1)\n", + "csq1d_cauchy = PyCSQ1DMagCauchy(B1, beta1)\n", + "\n", + "# Define map colours for easier visualisation\n", + "# Maps are defined there: https://matplotlib.org/stable/tutorials/colors/colormaps.html\n", + "# colormapF1a0= plt.get_cmap('Accent')\n", + "# colorsF1a0 = iter(colormapF1a0(np.linspace(0,1,10)))\n", + "# colormapF1a1= plt.get_cmap('Accent')\n", + "# colorsF1a1 = iter(colormapF1a1(np.linspace(0,1,10)))\n", + "# colormapF2a0= plt.get_cmap('Dark2')\n", + "# colorsF2a0 = iter(colormapF2a0(np.linspace(0,1,10)))\n", + "# colormapF2a1= plt.get_cmap('Dark2')\n", + "# colorsF2a1 = iter(colormapF2a1(np.linspace(0,1,10)))\n", + "\n", + "\n", + "color_nopot = iter(\n", + " cm.Reds(np.linspace(1 / 2, 1, len(k_a)))\n", + ") # Go from 1/2 to 1 to display colours not too bright\n", + "color_gauss = iter(cm.Blues(np.linspace(1 / 2, 1, len(k_a))))\n", + "color_cauchy = iter(cm.Greens(np.linspace(1 / 2, 1, len(k_a))))\n", + "\n", + "tau_ad_a = np.linspace(-1.35, -1.0, 100)\n", + "tau_ad_a = tau_a\n", + "\n", + "plt.figure(figsize=(14, 7))\n", + "\n", + "mylw = 1\n", + "\n", + "for k in k_a:\n", + " csq1d_nopot.set_k(k)\n", + " csq1d_gauss.set_k(k)\n", + " csq1d_cauchy.set_k(k)\n", + "\n", + " print(f\"Searching for WKB scale in ({tau_min}, {tau_qt_c})\")\n", + "\n", + " (Found_tau_i_nopot, tau_i_nopot) = csq1d_nopot.find_adiab_time_limit(\n", + " Vexp, tau_min, -1.0e-2, 1.0e-9\n", + " )\n", + " (Found_tau_i_gauss, tau_i_gauss) = csq1d_gauss.find_adiab_time_limit(\n", + " Vexp, tau_min, -1.0e-2, 1.0e-9\n", + " )\n", + " (Found_tau_i_cauchy, tau_i_cauchy) = csq1d_cauchy.find_adiab_time_limit(\n", + " Vexp, tau_min, -1.0e-2, 1.0e-9\n", + " )\n", + "\n", + " print(csq1d_nopot.eval_F1(Vexp, tau_i_nopot, k))\n", + " print(csq1d_gauss.eval_F1(Vexp, tau_i_gauss, k))\n", + " print(csq1d_cauchy.eval_F1(Vexp, tau_i_cauchy, k))\n", + "\n", + " print(csq1d_nopot.eval_adiab_at(Vexp, tau_i_nopot))\n", + " print(csq1d_gauss.eval_adiab_at(Vexp, tau_i_gauss))\n", + " print(csq1d_cauchy.eval_adiab_at(Vexp, tau_i_cauchy))\n", + "\n", + " F1_a_nopot = np.array([csq1d_nopot.eval_F1(Vexp, tau, k) for tau in tau_ad_a])\n", + " F2_a_nopot = np.array([csq1d_nopot.eval_F2(Vexp, tau, k) for tau in tau_ad_a])\n", + " nu_a_nopot = np.array([csq1d_nopot.eval_nu(Vexp, tau, k) for tau in tau_ad_a])\n", + "\n", + " F1_a_gauss = np.array([csq1d_gauss.eval_F1(Vexp, tau, k) for tau in tau_ad_a])\n", + " F2_a_gauss = np.array([csq1d_gauss.eval_F2(Vexp, tau, k) for tau in tau_ad_a])\n", + " nu_a_gauss = np.array([csq1d_gauss.eval_nu(Vexp, tau, k) for tau in tau_ad_a])\n", + "\n", + " F1_a_cauchy = np.array([csq1d_cauchy.eval_F1(Vexp, tau, k) for tau in tau_ad_a])\n", + " F2_a_cauchy = np.array([csq1d_cauchy.eval_F2(Vexp, tau, k) for tau in tau_ad_a])\n", + " nu_a_cauchy = np.array([csq1d_cauchy.eval_nu(Vexp, tau, k) for tau in tau_ad_a])\n", + "\n", + " csq1d_nopot.set_init_cond_adiab(Vexp, tau_i_nopot)\n", + " csq1d_gauss.set_init_cond_adiab(Vexp, tau_i_gauss)\n", + " csq1d_cauchy.set_init_cond_adiab(Vexp, tau_i_cauchy)\n", + "\n", + " csq1d_nopot.set_ti(tau_i_nopot)\n", + " csq1d_nopot.set_tf(tau_f)\n", + " csq1d_nopot.prepare(Vexp)\n", + "\n", + " csq1d_gauss.set_ti(tau_i_gauss)\n", + " csq1d_gauss.set_tf(tau_f)\n", + " csq1d_gauss.prepare(Vexp)\n", + "\n", + " csq1d_cauchy.set_ti(tau_i_cauchy)\n", + " csq1d_cauchy.set_tf(tau_f)\n", + " csq1d_cauchy.prepare(Vexp)\n", + "\n", + " tau_evol_a_nopot, tau_s_nopot = csq1d_nopot.get_time_array()\n", + " tau_evol_a_nopot = np.array(tau_evol_a_nopot)\n", + "\n", + " tau_evol_a_gauss, tau_s_gauss = csq1d_gauss.get_time_array()\n", + " tau_evol_a_gauss = np.array(tau_evol_a_gauss)\n", + "\n", + " tau_evol_a_cauchy, tau_s_cauchy = csq1d_cauchy.get_time_array()\n", + " tau_evol_a_cauchy = np.array(tau_evol_a_cauchy)\n", + "\n", + " # PB_a_nopot = []\n", + " # PE_a_nopot = []\n", + " J11_a_nopot = []\n", + " # J22_a_nopot = []\n", + "\n", + " # PB_a_gauss = []\n", + " # PE_a_gauss = []\n", + " J11_a_gauss = []\n", + " # J22_a_gauss = []\n", + "\n", + " # PB_a_cauchy = []\n", + " # PE_a_cauchy = []\n", + " J11_a_cauchy = []\n", + " # J22_a_cauchy = []\n", + "\n", + " for tau in tau_evol_a_nopot:\n", + " PB, PE, J11, J22 = csq1d_nopot.eval_PB_PE(Vexp, tau)\n", + " # PB_a_nopot.append(PB)\n", + " # PE_a_nopot.append(PE)\n", + " J11_a_nopot.append(J11)\n", + " # J22_a_nopot.append(J22)\n", + "\n", + " for tau in tau_evol_a_gauss:\n", + " PB, PE, J11, J22 = csq1d_gauss.eval_PB_PE(Vexp, tau)\n", + " # PB_a_gauss.append(PB)\n", + " # PE_a_gauss.append(PE)\n", + " J11_a_gauss.append(J11)\n", + " # J22_a_gauss.append(J22)\n", + "\n", + " for tau in tau_evol_a_cauchy:\n", + " PB, PE, J11, J22 = csq1d_cauchy.eval_PB_PE(Vexp, tau)\n", + " # PB_a_cauchy.append(PB)\n", + " # PE_a_cauchy.append(PE)\n", + " J11_a_cauchy.append(J11)\n", + " # J22_a_cauchy.append(J22)\n", + "\n", + " # PB_a_nopot = np.array(PB_a_nopot)\n", + " # PE_a_nopot = np.array(PE_a_nopot)\n", + " J11_a_nopot = np.array(J11_a_nopot)\n", + " # J22_a_nopot = np.array(J22_a_nopot)\n", + "\n", + " # PB_a_gauss = np.array(PB_a_gauss)\n", + " # PE_a_gauss = np.array(PE_a_gauss)\n", + " J11_a_gauss = np.array(J11_a_gauss)\n", + " # J22_a_gauss = np.array(J22_a_gauss)\n", + "\n", + " # PB_a_cauchy = np.array(PB_a_cauchy)\n", + " # PE_a_cauchy = np.array(PE_a_cauchy)\n", + " J11_a_cauchy = np.array(J11_a_cauchy)\n", + " # J22_a_cauchy = np.array(J22_a_cauchy)\n", + "\n", + " c_nopot = next(color_nopot)\n", + " c_gauss = next(color_gauss)\n", + " c_cauchy = next(color_cauchy)\n", + "\n", + " plt.plot(\n", + " tau_evol_a_nopot,\n", + " J11_a_nopot,\n", + " c=c_nopot,\n", + " lw=mylw,\n", + " label=f\"$J^{{nopot}}_{{11}}$ (k = $%s$)\" % latex_float(k),\n", + " )\n", + " plt.plot(\n", + " tau_evol_a_gauss,\n", + " J11_a_gauss,\n", + " c=c_gauss,\n", + " lw=mylw,\n", + " label=f\"$J^{{gauss}}_{{11}}$ (k = $%s$)\" % latex_float(k),\n", + " )\n", + " plt.plot(\n", + " tau_evol_a_cauchy,\n", + " J11_a_cauchy,\n", + " c=c_cauchy,\n", + " lw=mylw,\n", + " label=f\"$J^{{cauchy}}_{{11}}$ (k = $%s$)\" % latex_float(k),\n", + " )\n", + "\n", + "leg = plt.legend(loc=\"center left\", ncol=2, fontsize=16)\n", + "plt.yscale(\"log\")\n", + "plt.xlabel(r\"$\\tau$\")\n", + "\n", + "plt.savefig(plotpath + \"plotJ11_\" + current_set + \".pdf\")\n", + "\n", + "plt.show()" ] }, { "cell_type": "code", "execution_count": null, - "id": "1603d89c", + "id": "b02fb044", "metadata": {}, "outputs": [], "source": [ - "csq1d0.set_ti(tau_i0)\n", - "csq1d0.set_tf(tau_f)\n", - "csq1d0.prepare(Vexp)\n", + "tau_f = 10.0\n", + "\n", + "ki = 1.0\n", + "kf = 4.0e3\n", + "k_a = np.geomspace(ki, kf, 3)\n", + "\n", + "B0 = 1.0e-50\n", + "beta0 = 8.0e-1\n", + "B1 = 1.0e50\n", + "beta1 = 8.0e-1\n", + "\n", + "csq1d_nopot = PyCSQ1DMagCauchy(B0, beta0)\n", + "csq1d_gauss = PyCSQ1DMagGauss(B1, beta1)\n", + "csq1d_cauchy = PyCSQ1DMagCauchy(B1, beta1)\n", + "\n", + "# Define map colours for easier visualisation\n", + "# Maps are defined at https://matplotlib.org/stable/tutorials/colors/colormaps.html\n", + "# colormapB0= plt.get_cmap('viridis')\n", + "# colorsB0 = iter(colormapB0(np.linspace(0,1,len(k_a))))\n", + "\n", + "# colormapB1= plt.get_cmap('viridis')\n", + "# colorsB1 = iter(colormapB1(np.linspace(1,2,len(k_a))))\n", + "\n", + "# colormapE0= plt.get_cmap('viridis')\n", + "# colorsE0 = iter(colormapE0(np.linspace(0,1,len(k_a))))\n", + "\n", + "# colormapE1= plt.get_cmap('viridis')\n", + "# colorsE1 = iter(colormapE1(np.linspace(1,2,len(k_a))))\n", + "\n", + "# colors = plt.cm.coolwarm(np.linspace(0, 1, len(k_a)))\n", + "\n", + "\n", + "color_nopot = iter(\n", + " cm.Reds(np.linspace(1 / 2, 1, len(k_a)))\n", + ") # Go from 1/2 to 1 to display colours not too bright\n", + "color_gauss = iter(cm.Blues(np.linspace(1 / 2, 1, len(k_a))))\n", + "color_cauchy = iter(cm.Greens(np.linspace(1 / 2, 1, len(k_a))))\n", + "\n", + "tau_ad_a = np.linspace(-1.35, -1.0, 100)\n", + "tau_ad_a = tau_a\n", + "\n", + "fig = plt.figure(figsize=(14, 7))\n", + "\n", + "mylw = 1\n", "\n", - "csq1d1.set_ti(tau_i1)\n", - "csq1d1.set_tf(tau_f)\n", - "csq1d1.prepare(Vexp)\n", + "for ik, k in enumerate(k_a):\n", + " csq1d_nopot.set_k(k)\n", + " csq1d_gauss.set_k(k)\n", + " csq1d_cauchy.set_k(k)\n", + "\n", + " print(f\"Searching for WKB scale in ({tau_min}, {tau_qt_c})\")\n", + "\n", + " (Found_tau_i_nopot, tau_i_nopot) = csq1d_nopot.find_adiab_time_limit(\n", + " Vexp, tau_min, -1.0e-2, 1.0e-9\n", + " )\n", + " (Found_tau_i_gauss, tau_i_gauss) = csq1d_gauss.find_adiab_time_limit(\n", + " Vexp, tau_min, -1.0e-2, 1.0e-9\n", + " )\n", + " (Found_tau_i_cauchy, tau_i_cauchy) = csq1d_cauchy.find_adiab_time_limit(\n", + " Vexp, tau_min, -1.0e-2, 1.0e-9\n", + " )\n", + "\n", + " print(csq1d_nopot.eval_F1(Vexp, tau_i_nopot, k))\n", + " print(csq1d_gauss.eval_F1(Vexp, tau_i_gauss, k))\n", + " print(csq1d_cauchy.eval_F1(Vexp, tau_i_cauchy, k))\n", + "\n", + " print(csq1d_nopot.eval_adiab_at(Vexp, tau_i_nopot))\n", + " print(csq1d_gauss.eval_adiab_at(Vexp, tau_i_gauss))\n", + " print(csq1d_cauchy.eval_adiab_at(Vexp, tau_i_cauchy))\n", + "\n", + " F1_a_nopot = np.array([csq1d_nopot.eval_F1(Vexp, tau, k) for tau in tau_ad_a])\n", + " F2_a_nopot = np.array([csq1d_nopot.eval_F2(Vexp, tau, k) for tau in tau_ad_a])\n", + " nu_a_nopot = np.array([csq1d_nopot.eval_nu(Vexp, tau, k) for tau in tau_ad_a])\n", + "\n", + " F1_a_gauss = np.array([csq1d_gauss.eval_F1(Vexp, tau, k) for tau in tau_ad_a])\n", + " F2_a_gauss = np.array([csq1d_gauss.eval_F2(Vexp, tau, k) for tau in tau_ad_a])\n", + " nu_a_gauss = np.array([csq1d_gauss.eval_nu(Vexp, tau, k) for tau in tau_ad_a])\n", + "\n", + " F1_a_cauchy = np.array([csq1d_cauchy.eval_F1(Vexp, tau, k) for tau in tau_ad_a])\n", + " F2_a_cauchy = np.array([csq1d_cauchy.eval_F2(Vexp, tau, k) for tau in tau_ad_a])\n", + " nu_a_cauchy = np.array([csq1d_cauchy.eval_nu(Vexp, tau, k) for tau in tau_ad_a])\n", + "\n", + " csq1d_nopot.set_init_cond_adiab(Vexp, tau_i_nopot)\n", + " csq1d_gauss.set_init_cond_adiab(Vexp, tau_i_gauss)\n", + " csq1d_cauchy.set_init_cond_adiab(Vexp, tau_i_cauchy)\n", + "\n", + " csq1d_nopot.set_ti(tau_i_nopot)\n", + " csq1d_nopot.set_tf(tau_f)\n", + " csq1d_nopot.prepare(Vexp)\n", + "\n", + " csq1d_gauss.set_ti(tau_i_gauss)\n", + " csq1d_gauss.set_tf(tau_f)\n", + " csq1d_gauss.prepare(Vexp)\n", + "\n", + " csq1d_cauchy.set_ti(tau_i_cauchy)\n", + " csq1d_cauchy.set_tf(tau_f)\n", + " csq1d_cauchy.prepare(Vexp)\n", + "\n", + " tau_evol_a_nopot, tau_s_nopot = csq1d_nopot.get_time_array()\n", + " tau_evol_a_nopot = np.array(tau_evol_a_nopot)\n", + "\n", + " tau_evol_a_gauss, tau_s_gauss = csq1d_gauss.get_time_array()\n", + " tau_evol_a_gauss = np.array(tau_evol_a_gauss)\n", + "\n", + " tau_evol_a_cauchy, tau_s_cauchy = csq1d_cauchy.get_time_array()\n", + " tau_evol_a_cauchy = np.array(tau_evol_a_cauchy)\n", + "\n", + " PB_a_nopot = []\n", + " # PE_a_nopot = []\n", + " # J11_a_nopot = []\n", + " # J22_a_nopot = []\n", + "\n", + " PB_a_gauss = []\n", + " # PE_a_gauss = []\n", + " # J11_a_gauss = []\n", + " # J22_a_gauss = []\n", + "\n", + " PB_a_cauchy = []\n", + " # PE_a_cauchy = []\n", + " # J11_a_cauchy = []\n", + " # J22_a_cauchy = []\n", + "\n", + " for tau in tau_evol_a_nopot:\n", + " PB, PE, J11, J22 = csq1d_nopot.eval_PB_PE(Vexp, tau)\n", + " PB_a_nopot.append(PB)\n", + " # PE_a_nopot.append(PE)\n", + " # J11_a_nopot.append(J11)\n", + " # J22_a_nopot.append(J22)\n", + "\n", + " for tau in tau_evol_a_gauss:\n", + " PB, PE, J11, J22 = csq1d_gauss.eval_PB_PE(Vexp, tau)\n", + " PB_a_gauss.append(PB)\n", + " # PE_a_gauss.append(PE)\n", + " # J11_a_gauss.append(J11)\n", + " # J22_a_gauss.append(J22)\n", + "\n", + " for tau in tau_evol_a_cauchy:\n", + " PB, PE, J11, J22 = csq1d_cauchy.eval_PB_PE(Vexp, tau)\n", + " PB_a_cauchy.append(PB)\n", + " # PE_a_cauchy.append(PE)\n", + " # J11_a_cauchy.append(J11)\n", + " # J22_a_cauchy.append(J22)\n", + "\n", + " PB_a_nopot = np.array(PB_a_nopot)\n", + " # PE_a_nopot = np.array(PE_a_nopot)\n", + " # J11_a_nopot = np.array(J11_a_nopot)\n", + " # J22_a_nopot = np.array(J22_a_nopot)\n", + "\n", + " PB_a_gauss = np.array(PB_a_gauss)\n", + " # PE_a_gauss = np.array(PE_a_gauss)\n", + " # J11_a_gauss = np.array(J11_a_gauss)\n", + " # J22_a_gauss = np.array(J22_a_gauss)\n", + "\n", + " PB_a_cauchy = np.array(PB_a_cauchy)\n", + " # PE_a_cauchy = np.array(PE_a_cauchy)\n", + " # J11_a_cauchy = np.array(J11_a_cauchy)\n", + " # J22_a_cauchy = np.array(J22_a_cauchy)\n", + "\n", + " c_nopot = next(color_nopot)\n", + " c_gauss = next(color_gauss)\n", + " c_cauchy = next(color_cauchy)\n", + "\n", + " plt.plot(\n", + " tau_evol_a_nopot,\n", + " PB_a_nopot,\n", + " c=c_nopot,\n", + " lw=mylw,\n", + " label=f\"$P_{{B^{{nopot}}}}$ (k = $%s$)\" % latex_float(k),\n", + " )\n", + " plt.plot(\n", + " tau_evol_a_gauss,\n", + " PB_a_gauss,\n", + " c=c_gauss,\n", + " lw=mylw,\n", + " label=f\"$P_{{B^{{gauss}}}}$ (k = $%s$)\" % latex_float(k),\n", + " )\n", + " plt.plot(\n", + " tau_evol_a_cauchy,\n", + " PB_a_cauchy,\n", + " c=c_cauchy,\n", + " lw=mylw,\n", + " label=f\"$P_{{B^{{cauchy}}}}$ (k = $%s$)\" % latex_float(k),\n", + " )\n", + "\n", + "# plt.plot (tau_evol_a_nopot, PE_a_nopot, c=c_nopot, lw=mylw, label = f'$P_{{E^{{nopot}}}}$ (k = $%s$)'% latex_float (k))\n", + "# plt.plot (tau_evol_a_gauss, PE_a_gauss, c=c_gauss, lw=mylw, label = f'$P^{{E^{{gauss}}}}$ (k = $%s$)'% latex_float (k))\n", + "# plt.plot (tau_evol_a_cauchy, PE_a_cauchy, c=c_cauchy, lw=mylw, label = f'$P^{{E^{{cauchy}}}}$ (k = $%s$)'% latex_float (k))\n", "\n", - "tau_evol_a0, tau_s0 = csq1d0.get_time_array()\n", - "tau_evol_a0 = np.array(tau_evol_a0)\n", "\n", - "tau_evol_a1, tau_s1 = csq1d1.get_time_array()\n", - "tau_evol_a1 = np.array(tau_evol_a1)" + "plt.xlabel(r\"$\\tau$\")\n", + "plt.yscale(\"log\")\n", + "leg = plt.legend(loc=\"best\", ncol=2, fontsize=16)\n", + "\n", + "plt.savefig(plotpath + \"plotPB_\" + current_set + \".pdf\")\n", + "\n", + "plt.show()" ] }, { "cell_type": "code", "execution_count": null, - "id": "4d27899c", + "id": "36a8ed98", "metadata": {}, "outputs": [], "source": [ - "PB_a0 = []\n", - "PE_a0 = []\n", - "J11_a0 = []\n", - "J22_a0 = []\n", + "tau_f = 10.0\n", + "\n", + "ki = 1.0\n", + "kf = 4.0e3\n", + "k_a = np.geomspace(ki, kf, 3)\n", + "\n", + "B0 = 1.0e-50\n", + "beta0 = 8.0e-1\n", + "B1 = 1.0e50\n", + "beta1 = 8.0e-1\n", + "\n", + "csq1d_nopot = PyCSQ1DMagCauchy(B0, beta0)\n", + "csq1d_gauss = PyCSQ1DMagGauss(B1, beta1)\n", + "csq1d_cauchy = PyCSQ1DMagCauchy(B1, beta1)\n", + "\n", + "# Define map colours for easier visualisation\n", + "# Maps are defined at https://matplotlib.org/stable/tutorials/colors/colormaps.html\n", + "# colormapB0= plt.get_cmap('viridis')\n", + "# colorsB0 = iter(colormapB0(np.linspace(0,1,len(k_a))))\n", + "\n", + "# colormapB1= plt.get_cmap('viridis')\n", + "# colorsB1 = iter(colormapB1(np.linspace(1,2,len(k_a))))\n", + "\n", + "# colormapE0= plt.get_cmap('viridis')\n", + "# colorsE0 = iter(colormapE0(np.linspace(0,1,len(k_a))))\n", "\n", - "PB_a1 = []\n", - "PE_a1 = []\n", - "J11_a1 = []\n", - "J22_a1 = []\n", + "# colormapE1= plt.get_cmap('viridis')\n", + "# colorsE1 = iter(colormapE1(np.linspace(1,2,len(k_a))))\n", "\n", - "for tau in tau_evol_a0:\n", - " PB, PE, J11, J22 = csq1d0.eval_PB_PE(Vexp, tau)\n", - " PB_a0.append(PB)\n", - " PE_a0.append(PE)\n", - " J11_a0.append(J11)\n", - " J22_a0.append(J22)\n", + "# colors = plt.cm.coolwarm(np.linspace(0, 1, len(k_a)))\n", "\n", - "for tau in tau_evol_a1:\n", - " PB, PE, J11, J22 = csq1d1.eval_PB_PE(Vexp, tau)\n", - " PB_a1.append(PB)\n", - " PE_a1.append(PE)\n", - " J11_a1.append(J11)\n", - " J22_a1.append(J22)\n", "\n", - "PB_a0 = np.array(PB_a0)\n", - "PE_a0 = np.array(PE_a0)\n", - "J11_a0 = np.array(J11_a0)\n", - "J22_a0 = np.array(J22_a0)\n", + "color_nopot = iter(\n", + " cm.Reds(np.linspace(1 / 2, 1, len(k_a)))\n", + ") # Go from 1/2 to 1 to display colours not too bright\n", + "color_gauss = iter(cm.Blues(np.linspace(1 / 2, 1, len(k_a))))\n", + "color_cauchy = iter(cm.Greens(np.linspace(1 / 2, 1, len(k_a))))\n", "\n", - "PB_a1 = np.array(PB_a1)\n", - "PE_a1 = np.array(PE_a1)\n", - "J11_a1 = np.array(J11_a1)\n", - "J22_a1 = np.array(J22_a1)" + "tau_ad_a = np.linspace(-1.35, -1.0, 100)\n", + "tau_ad_a = tau_a\n", + "\n", + "fig = plt.figure(figsize=(14, 7))\n", + "\n", + "mylw = 1\n", + "\n", + "for ik, k in enumerate(k_a):\n", + " csq1d_nopot.set_k(k)\n", + " csq1d_gauss.set_k(k)\n", + " csq1d_cauchy.set_k(k)\n", + "\n", + " print(f\"Searching for WKB scale in ({tau_min}, {tau_qt_c})\")\n", + "\n", + " (Found_tau_i_nopot, tau_i_nopot) = csq1d_nopot.find_adiab_time_limit(\n", + " Vexp, tau_min, -1.0e-2, 1.0e-9\n", + " )\n", + " (Found_tau_i_gauss, tau_i_gauss) = csq1d_gauss.find_adiab_time_limit(\n", + " Vexp, tau_min, -1.0e-2, 1.0e-9\n", + " )\n", + " (Found_tau_i_cauchy, tau_i_cauchy) = csq1d_cauchy.find_adiab_time_limit(\n", + " Vexp, tau_min, -1.0e-2, 1.0e-9\n", + " )\n", + "\n", + " print(csq1d_nopot.eval_F1(Vexp, tau_i_nopot, k))\n", + " print(csq1d_gauss.eval_F1(Vexp, tau_i_gauss, k))\n", + " print(csq1d_cauchy.eval_F1(Vexp, tau_i_cauchy, k))\n", + "\n", + " print(csq1d_nopot.eval_adiab_at(Vexp, tau_i_nopot))\n", + " print(csq1d_gauss.eval_adiab_at(Vexp, tau_i_gauss))\n", + " print(csq1d_cauchy.eval_adiab_at(Vexp, tau_i_cauchy))\n", + "\n", + " F1_a_nopot = np.array([csq1d_nopot.eval_F1(Vexp, tau, k) for tau in tau_ad_a])\n", + " F2_a_nopot = np.array([csq1d_nopot.eval_F2(Vexp, tau, k) for tau in tau_ad_a])\n", + " nu_a_nopot = np.array([csq1d_nopot.eval_nu(Vexp, tau, k) for tau in tau_ad_a])\n", + "\n", + " F1_a_gauss = np.array([csq1d_gauss.eval_F1(Vexp, tau, k) for tau in tau_ad_a])\n", + " F2_a_gauss = np.array([csq1d_gauss.eval_F2(Vexp, tau, k) for tau in tau_ad_a])\n", + " nu_a_gauss = np.array([csq1d_gauss.eval_nu(Vexp, tau, k) for tau in tau_ad_a])\n", + "\n", + " F1_a_cauchy = np.array([csq1d_cauchy.eval_F1(Vexp, tau, k) for tau in tau_ad_a])\n", + " F2_a_cauchy = np.array([csq1d_cauchy.eval_F2(Vexp, tau, k) for tau in tau_ad_a])\n", + " nu_a_cauchy = np.array([csq1d_cauchy.eval_nu(Vexp, tau, k) for tau in tau_ad_a])\n", + "\n", + " csq1d_nopot.set_init_cond_adiab(Vexp, tau_i_nopot)\n", + " csq1d_gauss.set_init_cond_adiab(Vexp, tau_i_gauss)\n", + " csq1d_cauchy.set_init_cond_adiab(Vexp, tau_i_cauchy)\n", + "\n", + " csq1d_nopot.set_ti(tau_i_nopot)\n", + " csq1d_nopot.set_tf(tau_f)\n", + " csq1d_nopot.prepare(Vexp)\n", + "\n", + " csq1d_gauss.set_ti(tau_i_gauss)\n", + " csq1d_gauss.set_tf(tau_f)\n", + " csq1d_gauss.prepare(Vexp)\n", + "\n", + " csq1d_cauchy.set_ti(tau_i_cauchy)\n", + " csq1d_cauchy.set_tf(tau_f)\n", + " csq1d_cauchy.prepare(Vexp)\n", + "\n", + " tau_evol_a_nopot, tau_s_nopot = csq1d_nopot.get_time_array()\n", + " tau_evol_a_nopot = np.array(tau_evol_a_nopot)\n", + "\n", + " tau_evol_a_gauss, tau_s_gauss = csq1d_gauss.get_time_array()\n", + " tau_evol_a_gauss = np.array(tau_evol_a_gauss)\n", + "\n", + " tau_evol_a_cauchy, tau_s_cauchy = csq1d_cauchy.get_time_array()\n", + " tau_evol_a_cauchy = np.array(tau_evol_a_cauchy)\n", + "\n", + " # PB_a_nopot = []\n", + " PE_a_nopot = []\n", + " # J11_a_nopot = []\n", + " # J22_a_nopot = []\n", + "\n", + " # PB_a_gauss = []\n", + " PE_a_gauss = []\n", + " # J11_a_gauss = []\n", + " # J22_a_gauss = []\n", + "\n", + " # PB_a_cauchy = []\n", + " PE_a_cauchy = []\n", + " # J11_a_cauchy = []\n", + " # J22_a_cauchy = []\n", + "\n", + " for tau in tau_evol_a_nopot:\n", + " PB, PE, J11, J22 = csq1d_nopot.eval_PB_PE(Vexp, tau)\n", + " # PB_a_nopot.append(PB)\n", + " PE_a_nopot.append(PE)\n", + " # J11_a_nopot.append(J11)\n", + " # J22_a_nopot.append(J22)\n", + "\n", + " for tau in tau_evol_a_gauss:\n", + " PB, PE, J11, J22 = csq1d_gauss.eval_PB_PE(Vexp, tau)\n", + " # PB_a_gauss.append(PB)\n", + " PE_a_gauss.append(PE)\n", + " # J11_a_gauss.append(J11)\n", + " # J22_a_gauss.append(J22)\n", + "\n", + " for tau in tau_evol_a_cauchy:\n", + " PB, PE, J11, J22 = csq1d_cauchy.eval_PB_PE(Vexp, tau)\n", + " # PB_a_cauchy.append(PB)\n", + " PE_a_cauchy.append(PE)\n", + " # J11_a_cauchy.append(J11)\n", + " # J22_a_cauchy.append(J22)\n", + "\n", + " # PB_a_nopot = np.array(PB_a_nopot)\n", + " PE_a_nopot = np.array(PE_a_nopot)\n", + " # J11_a_nopot = np.array(J11_a_nopot)\n", + " # J22_a_nopot = np.array(J22_a_nopot)\n", + "\n", + " # PB_a_gauss = np.array(PB_a_gauss)\n", + " PE_a_gauss = np.array(PE_a_gauss)\n", + " # J11_a_gauss = np.array(J11_a_gauss)\n", + " # J22_a_gauss = np.array(J22_a_gauss)\n", + "\n", + " # PB_a_cauchy = np.array(PB_a_cauchy)\n", + " PE_a_cauchy = np.array(PE_a_cauchy)\n", + " # J11_a_cauchy = np.array(J11_a_cauchy)\n", + " # J22_a_cauchy = np.array(J22_a_cauchy)\n", + "\n", + " c_nopot = next(color_nopot)\n", + " c_gauss = next(color_gauss)\n", + " c_cauchy = next(color_cauchy)\n", + "\n", + " # plt.plot (tau_evol_a_nopot, PB_a_nopot, c=c_nopot, lw=mylw, label = f'$P_{{B^{{nopot}}}}$ (k = $%s$)'% latex_float (k))\n", + " # plt.plot (tau_evol_a_gauss, PB_a_gauss, c=c_gauss, lw=mylw, label = f'$P^{{B^{{gauss}}}}$ (k = $%s$)'% latex_float (k))\n", + " # plt.plot (tau_evol_a_cauchy, PB_a_cauchy, c=c_cauchy, lw=mylw, label = f'$P^{{B^{{cauchy}}}}$ (k = $%s$)'% latex_float (k))\n", + "\n", + " plt.plot(\n", + " tau_evol_a_nopot,\n", + " PE_a_nopot,\n", + " c=c_nopot,\n", + " lw=mylw,\n", + " label=f\"$P_{{E^{{nopot}}}}$ (k = $%s$)\" % latex_float(k),\n", + " )\n", + " plt.plot(\n", + " tau_evol_a_gauss,\n", + " PE_a_gauss,\n", + " c=c_gauss,\n", + " lw=mylw,\n", + " label=f\"$P_{{E^{{gauss}}}}$ (k = $%s$)\" % latex_float(k),\n", + " )\n", + " plt.plot(\n", + " tau_evol_a_cauchy,\n", + " PE_a_cauchy,\n", + " c=c_cauchy,\n", + " lw=mylw,\n", + " label=f\"$P_{{E^{{cauchy}}}}$ (k = $%s$)\" % latex_float(k),\n", + " )\n", + "\n", + "\n", + "plt.xlabel(r\"$\\tau$\")\n", + "plt.yscale(\"log\")\n", + "leg = plt.legend(loc=\"best\", ncol=2, fontsize=16)\n", + "plt.savefig(plotpath + \"plotPE_\" + current_set + \".pdf\")\n", + "\n", + "plt.show()" ] }, { "cell_type": "code", "execution_count": null, - "id": "c01f786b", + "id": "f80645af", "metadata": {}, "outputs": [], "source": [ - "mylw = 1\n", + "tau_f = 10.0\n", + "\n", + "ki = 1.0\n", + "kf = 4.0e3\n", + "k_a = np.geomspace(ki, kf, 3)\n", + "\n", + "B1 = 1.0e10\n", + "beta1 = 8.0e-1\n", + "\n", + "B2 = 1.0e20\n", + "beta2 = 8.0e-1\n", + "\n", + "csq1d2 = PyCSQ1DMagScalarField(B2, beta2)\n", + "csq1d1 = PyCSQ1DMagScalarField(B1, beta1)\n", + "\n", + "# Define map colours for easier visualisation\n", + "# Maps are defined at https://matplotlib.org/stable/tutorials/colors/colormaps.html\n", + "# colormapB0= plt.get_cmap('viridis')\n", + "# colorsB0 = iter(colormapB0(np.linspace(0,1,len(k_a))))\n", + "\n", + "# colormapB1= plt.get_cmap('viridis')\n", + "# colorsB1 = iter(colormapB1(np.linspace(1,2,len(k_a))))\n", + "\n", + "# colormapE0= plt.get_cmap('viridis')\n", + "# colorsE0 = iter(colormapE0(np.linspace(0,1,len(k_a))))\n", + "\n", + "# colormapE1= plt.get_cmap('viridis')\n", + "# colorsE1 = iter(colormapE1(np.linspace(1,2,len(k_a))))\n", + "\n", + "colors = plt.cm.coolwarm(np.linspace(0, 1, len(k_a)))\n", + "\n", + "\n", + "tau_ad_a = np.linspace(-1.35, -1.0, 100)\n", + "tau_ad_a = tau_a\n", + "\n", + "fig = plt.figure(figsize=(14, 7))\n", "\n", - "plt.plot(tau_evol_a0, J11_a0, lw=mylw, label=f\"$J^0_{{11}}(k_s = {k})$\")\n", - "plt.plot(tau_evol_a1, J11_a1, lw=mylw, label=f\"$J^1_{{11}}(k_s = {k})$\")\n", + "mylw = 1\n", "\n", - "plt.plot(tau_evol_a0, J22_a0, lw=mylw, label=f\"$J^0_{{22}}(k_s = {k})$\")\n", - "plt.plot(tau_evol_a1, J22_a1, lw=mylw, label=f\"$J^1_{{22}}(k_s = {k})$\")\n", + "for ik, k in enumerate(k_a[:2]):\n", + " csq1d2.set_k(k)\n", + " csq1d1.set_k(k)\n", + "\n", + " print(f\"Searching for WKB scale in ({tau_min}, {tau_qt_c})\")\n", + "\n", + " (Found_tau_i2, tau_i2) = csq1d2.find_adiab_time_limit(\n", + " Vexp, tau_min, -1.0e-2, 1.0e-9\n", + " )\n", + " (Found_tau_i1, tau_i1) = csq1d1.find_adiab_time_limit(\n", + " Vexp, tau_min, -1.0e-2, 1.0e-9\n", + " )\n", + "\n", + " print(csq1d2.eval_F1(Vexp, tau_i2, k))\n", + " print(csq1d1.eval_F1(Vexp, tau_i1, k))\n", + "\n", + " print(csq1d2.eval_adiab_at(Vexp, tau_i2))\n", + " print(csq1d1.eval_adiab_at(Vexp, tau_i1))\n", + "\n", + " F1_a2 = np.array([csq1d2.eval_F1(Vexp, tau, k) for tau in tau_ad_a])\n", + " F2_a2 = np.array([csq1d2.eval_F2(Vexp, tau, k) for tau in tau_ad_a])\n", + " nu_a2 = np.array([csq1d2.eval_nu(Vexp, tau, k) for tau in tau_ad_a])\n", + "\n", + " F1_a1 = np.array([csq1d1.eval_F1(Vexp, tau, k) for tau in tau_ad_a])\n", + " F2_a1 = np.array([csq1d1.eval_F2(Vexp, tau, k) for tau in tau_ad_a])\n", + " nu_a1 = np.array([csq1d1.eval_nu(Vexp, tau, k) for tau in tau_ad_a])\n", + "\n", + " csq1d2.set_init_cond_adiab(Vexp, tau_i2)\n", + " csq1d1.set_init_cond_adiab(Vexp, tau_i1)\n", + "\n", + " csq1d2.set_ti(tau_i2)\n", + " csq1d2.set_tf(tau_f)\n", + " csq1d2.prepare(Vexp)\n", + "\n", + " csq1d1.set_ti(tau_i1)\n", + " csq1d1.set_tf(tau_f)\n", + " csq1d1.prepare(Vexp)\n", + "\n", + " tau_evol_a2, tau_s2 = csq1d2.get_time_array()\n", + " tau_evol_a2 = np.array(tau_evol_a2)\n", + "\n", + " tau_evol_a1, tau_s1 = csq1d1.get_time_array()\n", + " tau_evol_a1 = np.array(tau_evol_a1)\n", + "\n", + " PB_a2 = []\n", + " PE_a2 = []\n", + " J11_a2 = []\n", + " J22_a2 = []\n", + "\n", + " PB_a1 = []\n", + " PE_a1 = []\n", + " J11_a1 = []\n", + " J22_a1 = []\n", + "\n", + " for tau in tau_evol_a2:\n", + " PB, PE, J11, J22 = csq1d2.eval_PB_PE(Vexp, tau)\n", + " PB_a2.append(PB)\n", + " PE_a2.append(PE)\n", + " J11_a2.append(J11)\n", + " J22_a2.append(J22)\n", + "\n", + " for tau in tau_evol_a1:\n", + " PB, PE, J11, J22 = csq1d1.eval_PB_PE(Vexp, tau)\n", + " PB_a1.append(PB)\n", + " PE_a1.append(PE)\n", + " J11_a1.append(J11)\n", + " J22_a1.append(J22)\n", + "\n", + " PB_a2 = np.array(PB_a2)\n", + " PE_a2 = np.array(PE_a2)\n", + " J11_a2 = np.array(J11_a2)\n", + " J22_a2 = np.array(J22_a2)\n", + "\n", + " PB_a1 = np.array(PB_a1)\n", + " PE_a1 = np.array(PE_a1)\n", + " J11_a1 = np.array(J11_a1)\n", + " J22_a1 = np.array(J22_a1)\n", + "\n", + " plt.plot(\n", + " tau_evol_a2,\n", + " PB_a2,\n", + " lw=mylw,\n", + " label=f\"$P_{{B^2}}(k_s = {int(k)})$\",\n", + " color=colors[ik],\n", + " )\n", + " plt.plot(\n", + " tau_evol_a1,\n", + " PB_a1,\n", + " lw=mylw,\n", + " linestyle=\"dashed\",\n", + " label=f\"$P_{{B^1}}(k_s = {int(k)})$\",\n", + " color=colors[ik],\n", + " )\n", + "\n", + " # plt.plot (tau_evol_a2, PE_a2, lw=mylw, linestyle='dotted', label = f'$P_{{E^2}}(k_s = {int(k)})$',color=colors[ik])\n", + " # plt.plot (tau_evol_a1, PE_a1, lw=mylw, linestyle='dashdot', label = f'$P_{{E^1}}(k_s = {int(k)})$',color=colors[ik])\n", + "\n", + "\n", + "# plt.plot (tau_evol_a0, PB_a0, lw=mylw, label = f'$P_{{B^0}}(k_s = {int(k)})$',color=next(colorsB0))\n", + "# plt.plot (tau_evol_a1, PB_a1, lw=mylw, label = f'$P_{{B^1}}(k_s = {int(k)})$',color=next(colorsB1))\n", + "\n", + "# plt.plot (tau_evol_a0, PE_a0, lw=mylw, linestyle='--', label = f'$P_{{E^0}}(k_s = {int(k)})$',color=next(colorsE0))\n", + "# plt.plot (tau_evol_a1, PE_a1, lw=mylw, linestyle='--', label = f'$P_{{E^1}}(k_s = {int(k)})$',color=next(colorsE1))\n", "\n", "leg = plt.legend(loc=\"best\", ncol=2, fontsize=13)\n", + "plt.grid()\n", "plt.yscale(\"log\")\n", - "# plt.xlim(None,-15.0)\n", - "# plt.ylim(1.0e-260,1.0e-90)" + "plt.xlim(-5.0, 5.0)\n", + "plt.ylim(1.0e-38, None)\n", + "plt.show()\n", + "fig.savefig(\"PE_PB_testbeta2.pdf\")" ] }, { "cell_type": "code", "execution_count": null, - "id": "594d9532", + "id": "158dd92e", "metadata": {}, "outputs": [], "source": [ + "### Magnetic power spectrum\n", + "\n", + "tau_f = 10.0\n", + "\n", + "ki = 1.0\n", + "kf = 4.0e3\n", + "k_a = np.geomspace(ki, kf, 2)\n", + "\n", + "B0 = 1.0e-50\n", + "beta0 = 8.0e-1\n", + "B1 = 1.0e50\n", + "beta1 = 8.0e3\n", + "\n", + "csq1d_nopot = PyCSQ1DMagCauchy(B0, beta0)\n", + "csq1d_gauss = PyCSQ1DMagGauss(B1, beta1)\n", + "csq1d_cauchy = PyCSQ1DMagCauchy(B1, beta1)\n", + "\n", + "color_nopot = iter(\n", + " cm.Reds(np.linspace(1 / 2, 1, len(k_a)))\n", + ") # Go from 1/2 to 1 to display colours not too bright\n", + "color_gauss = iter(cm.Blues(np.linspace(1 / 2, 1, len(k_a))))\n", + "color_cauchy = iter(cm.Greens(np.linspace(1 / 2, 1, len(k_a))))\n", + "\n", + "tau_ad_a = np.linspace(-1.35, -1.0, 100)\n", + "tau_ad_a = tau_a\n", + "\n", + "fig = plt.figure(figsize=(14, 7))\n", + "ax = fig.add_subplot(111)\n", + "\n", "mylw = 1\n", "\n", - "plt.plot(tau_evol_a0, PB_a0, lw=mylw, label=f\"$P_{{B^0}}(k_s = {k})$\")\n", - "plt.plot(tau_evol_a1, PB_a1, lw=mylw, label=f\"$P_{{B^1}}(k_s = {k})$\")\n", + "PB_a_nopot = []\n", + "# PE_a_nopot = []\n", + "# J11_a_nopot = []\n", + "# J22_a_nopot = []\n", "\n", - "plt.plot(tau_evol_a0, PE_a0, lw=mylw, label=f\"$P_{{E^0}}(k_s = {k})$\")\n", - "plt.plot(tau_evol_a1, PE_a1, lw=mylw, label=f\"$P_{{E^1}}(k_s = {k})$\")\n", + "PB_a_gauss = []\n", + "# PE_a_gauss = []\n", + "# J11_a_gauss = []\n", + "# J22_a_gauss = []\n", + "\n", + "PB_a_cauchy = []\n", + "# PE_a_cauchy = []\n", + "# J11_a_cauchy = []\n", + "# J22_a_cauchy = []\n", + "\n", + "for ik, k in enumerate(k_a):\n", + " csq1d_nopot.set_k(k)\n", + " csq1d_gauss.set_k(k)\n", + " csq1d_cauchy.set_k(k)\n", + "\n", + " print(f\"Searching for WKB scale in ({tau_min}, {tau_qt_c})\")\n", + "\n", + " (Found_tau_i_nopot, tau_i_nopot) = csq1d_nopot.find_adiab_time_limit(\n", + " Vexp, tau_min, -1.0e-2, 1.0e-9\n", + " )\n", + " (Found_tau_i_gauss, tau_i_gauss) = csq1d_gauss.find_adiab_time_limit(\n", + " Vexp, tau_min, -1.0e-2, 1.0e-9\n", + " )\n", + " (Found_tau_i_cauchy, tau_i_cauchy) = csq1d_cauchy.find_adiab_time_limit(\n", + " Vexp, tau_min, -1.0e-2, 1.0e-9\n", + " )\n", + "\n", + " print(csq1d_nopot.eval_F1(Vexp, tau_i_nopot, k))\n", + " print(csq1d_gauss.eval_F1(Vexp, tau_i_gauss, k))\n", + " print(csq1d_cauchy.eval_F1(Vexp, tau_i_cauchy, k))\n", + "\n", + " print(csq1d_nopot.eval_adiab_at(Vexp, tau_i_nopot))\n", + " print(csq1d_gauss.eval_adiab_at(Vexp, tau_i_gauss))\n", + " print(csq1d_cauchy.eval_adiab_at(Vexp, tau_i_cauchy))\n", + "\n", + " F1_a_nopot = np.array([csq1d_nopot.eval_F1(Vexp, tau, k) for tau in tau_ad_a])\n", + " F2_a_nopot = np.array([csq1d_nopot.eval_F2(Vexp, tau, k) for tau in tau_ad_a])\n", + " nu_a_nopot = np.array([csq1d_nopot.eval_nu(Vexp, tau, k) for tau in tau_ad_a])\n", + "\n", + " F1_a_gauss = np.array([csq1d_gauss.eval_F1(Vexp, tau, k) for tau in tau_ad_a])\n", + " F2_a_gauss = np.array([csq1d_gauss.eval_F2(Vexp, tau, k) for tau in tau_ad_a])\n", + " nu_a_gauss = np.array([csq1d_gauss.eval_nu(Vexp, tau, k) for tau in tau_ad_a])\n", + "\n", + " F1_a_cauchy = np.array([csq1d_cauchy.eval_F1(Vexp, tau, k) for tau in tau_ad_a])\n", + " F2_a_cauchy = np.array([csq1d_cauchy.eval_F2(Vexp, tau, k) for tau in tau_ad_a])\n", + " nu_a_cauchy = np.array([csq1d_cauchy.eval_nu(Vexp, tau, k) for tau in tau_ad_a])\n", + "\n", + " csq1d_nopot.set_init_cond_adiab(Vexp, tau_i_nopot)\n", + " csq1d_gauss.set_init_cond_adiab(Vexp, tau_i_gauss)\n", + " csq1d_cauchy.set_init_cond_adiab(Vexp, tau_i_cauchy)\n", + "\n", + " tau_f = Vexp.tau_xe(1.0)\n", + " csq1d_nopot.set_ti(tau_i_nopot)\n", + " csq1d_nopot.set_tf(tau_f)\n", + " csq1d_nopot.prepare(Vexp)\n", + "\n", + " csq1d_gauss.set_ti(tau_i_gauss)\n", + " csq1d_gauss.set_tf(tau_f)\n", + " csq1d_gauss.prepare(Vexp)\n", + "\n", + " csq1d_cauchy.set_ti(tau_i_cauchy)\n", + " csq1d_cauchy.set_tf(tau_f)\n", + " csq1d_cauchy.prepare(Vexp)\n", + "\n", + " tau_evol_a_nopot, tau_s_nopot = csq1d_nopot.get_time_array()\n", + " tau_evol_a_nopot = np.array(tau_evol_a_nopot)\n", + "\n", + " tau_evol_a_gauss, tau_s_gauss = csq1d_gauss.get_time_array()\n", + " tau_evol_a_gauss = np.array(tau_evol_a_gauss)\n", + "\n", + " tau_evol_a_cauchy, tau_s_cauchy = csq1d_cauchy.get_time_array()\n", + " tau_evol_a_cauchy = np.array(tau_evol_a_cauchy)\n", + "\n", + " PB, PE, J11, J22 = csq1d_nopot.eval_PB_PE(Vexp, Vexp.tau_xe(1.0))\n", + " PB_a_nopot.append(PB)\n", + " # PE_a_nopot.append(PE)\n", + "\n", + " PB, PE, J11, J22 = csq1d_gauss.eval_PB_PE(Vexp, Vexp.tau_xe(1.0))\n", + " PB_a_gauss.append(PB)\n", + " # PE_a_gauss.append(PE)\n", + "\n", + " PB, PE, J11, J22 = csq1d_cauchy.eval_PB_PE(Vexp, Vexp.tau_xe(1.0))\n", + " PB_a_cauchy.append(PB)\n", + "# PE_a_cauchy.append(PE)\n", + "\n", + "\n", + "PB_a_nopot = np.array(PB_a_nopot)\n", + "# PE_a_nopot = np.array(PE_a_nopot)\n", + "\n", + "PB_a_gauss = np.array(PB_a_gauss)\n", + "# PE_a_gauss = np.array(PE_a_gauss)\n", + "\n", + "PB_a_cauchy = np.array(PB_a_cauchy)\n", + "\n", + "plt.plot(\n", + " k_a,\n", + " np.sqrt(PB_a_nopot * csq1d_nopot.RH**6) * 1.0e9,\n", + " lw=mylw,\n", + " label=f\"$B^{{nopot}}$\",\n", + ")\n", + "plt.plot(\n", + " k_a,\n", + " np.sqrt(PB_a_gauss * csq1d_gauss.RH**6) * 1.0e9,\n", + " lw=mylw,\n", + " label=f\"$B^{{gauss}}$\",\n", + ")\n", + "plt.plot(\n", + " k_a,\n", + " np.sqrt(PB_a_cauchy * csq1d_cauchy.RH**6) * 1.0e9,\n", + " lw=mylw,\n", + " label=f\"$B^{{cauchy}}$\",\n", + ")\n", + "\n", + "# plt.plot (tau_evol_a_nopot, PE_a_nopot, c=c_nopot, lw=mylw, label = f'$P_{{E^{{nopot}}}}$ (k = $%s$)'% latex_float (k))\n", + "# plt.plot (tau_evol_a_gauss, PE_a_gauss, c=c_gauss, lw=mylw, label = f'$P^{{E^{{gauss}}}}$ (k = $%s$)'% latex_float (k))\n", + "# plt.plot (tau_evol_a_cauchy, PE_a_cauchy, c=c_cauchy, lw=mylw, label = f'$P^{{E^{{cauchy}}}}$ (k = $%s$)'% latex_float (k))\n", + "\n", + "\n", + "# Spectral indices: magnetic = nB, electric = nE\n", + "# nE = math.log (PE_a_nopot[-1] / PE_a_nopot[0]) / math.log (k_a[-1] / k_a[0])\n", + "nB_nopot = math.log(PB_a_nopot[-1] / PB_a_nopot[0]) / math.log(k_a[-1] / k_a[0])\n", + "print(\"Magnetic spectral index no_pot: \", nB_nopot)\n", + "nB_gauss = math.log(PB_a_gauss[-1] / PB_a_gauss[0]) / math.log(k_a[-1] / k_a[0])\n", + "print(\"Magnetic spectral index gauss: \", nB_gauss)\n", + "nB_cauchy = math.log(PB_a_cauchy[-1] / PB_a_cauchy[0]) / math.log(k_a[-1] / k_a[0])\n", + "print(\"Magnetic spectral index cauchy: \", nB_cauchy)\n", + "\n", + "plt.xlabel(\"$k R_H$\", fontsize=16)\n", + "plt.ylabel(\"$B_{\\lambda} (nG)$\", fontsize=16)\n", + "plt.yscale(\"log\")\n", + "plt.xscale(\"log\")\n", + "plt.grid(b=True, which=\"both\", linestyle=\":\", color=\"0.5\", linewidth=0.5)\n", + "leg = plt.legend(loc=\"best\", fontsize=16)\n", + "\n", + "\n", + "# Top x-axis\n", + "def forward(x):\n", + " return [csq1d_nopot.RH / xi if xi > 0.0 else 1.0e30 for xi in x]\n", + "\n", + "\n", + "def inverse(x):\n", + " return [csq1d_nopot.RH / xi if xi > 0.0 else 1.0e30 for xi in x]\n", + "\n", + "\n", + "ax2 = ax.secondary_xaxis(\"top\", functions=(forward, inverse))\n", + "ax2.set_xlabel(\"$\\lambda (Mpc)$\")\n", + "\n", + "# Observational limits\n", + "\n", + "# print(ax.get_ylim(),math.log10(ax.get_ylim()[1]),math.log10(ax.get_ylim()[0]))\n", + "y_center = 10 ** (\n", + " (math.log10(ax.get_ylim()[1]) + math.log10(ax.get_ylim()[0])) / 2.0\n", + ") # Get center of y-axis\n", + "plt.axvline(1.0, color=\"green\") # Draw vertical line for Hubble radius\n", + "plt.text(\n", + " 1.05,\n", + " y_center,\n", + " \"Hubble radius\",\n", + " color=\"green\",\n", + " rotation=90,\n", + " verticalalignment=\"center\",\n", + ") # Add text\n", + "\n", + "# print(np.sqrt(PB_a_nopot[-1]*csq1d_nopot.RH**6)*1.0e9,np.sqrt(PB_a_gauss[-1]*csq1d_gauss.RH**6)*1.0e9,np.sqrt(PB_a_cauchy[-1]*csq1d_cauchy.RH**6)*1.0e9)\n", + "\n", + "# Check if y range reaches observational bounds before drawing the thresholds\n", + "# First check is for CMB, second for dynamo. If CMB is reached, it also draws the dynamo threshold\n", + "if (\n", + " (np.sqrt(PB_a_nopot[-1] * csq1d_nopot.RH**6) * 1.0e9 > 0.9)\n", + " or (np.sqrt(PB_a_gauss[-1] * csq1d_gauss.RH**6) * 1.0e9 > 0.9)\n", + " or (np.sqrt(PB_a_cauchy[-1] * csq1d_cauchy.RH**6) * 1.0e9 > 0.9)\n", + "):\n", + " x_center = 10 ** (\n", + " (math.log10(ax.get_xlim()[1]) + math.log10(ax.get_xlim()[0])) / 2.0\n", + " ) # Get center of x-axis\n", + "\n", + " plt.axhline(1.0, color=\"red\") # Draw horizontal line for CMB threshold\n", + " plt.text(\n", + " x_center,\n", + " 5.0e-3,\n", + " \"CMB limit $(1 nG)$\",\n", + " color=\"red\",\n", + " horizontalalignment=\"center\",\n", + " ) # Add text\n", + "\n", + " plt.axhline(1.0e-12, color=\"blue\") # Draw horizontal line for dynamo threshold\n", + " plt.text(\n", + " x_center,\n", + " 5.0e-12,\n", + " \"Dynamo threshold $(10^{-12} nG)$\",\n", + " color=\"blue\",\n", + " horizontalalignment=\"center\",\n", + " ) # Add text\n", + "elif (\n", + " (np.sqrt(PB_a_nopot[-1] * csq1d_nopot.RH**6) * 1.0e9 > 0.9e-13)\n", + " or (np.sqrt(PB_a_gauss[-1] * csq1d_gauss.RH**6) * 1.0e9 > 0.9e-13)\n", + " or (np.sqrt(PB_a_cauchy[-1] * csq1d_cauchy.RH**6) * 1.0e9 > 0.9e-13)\n", + "):\n", + " x_center = 10 ** (\n", + " (math.log10(ax.get_xlim()[1]) + math.log10(ax.get_xlim()[0])) / 2.0\n", + " ) # Get center of x-axis\n", + "\n", + " plt.axhline(1.0e-12, color=\"blue\") # Draw horizontal line for dynamo threshold\n", + " plt.text(\n", + " x_center,\n", + " 2.0e-12,\n", + " \"Dynamo threshold\",\n", + " color=\"blue\",\n", + " horizontalalignment=\"center\",\n", + " ) # Add text\n", + "\n", + "plt.savefig(\n", + " plotpath + \"plotB_\" + current_set + \"_\" + str(B1) + \"_\" + str(beta1) + \".pdf\"\n", + ")\n", "\n", - "leg = plt.legend(loc=\"best\", ncol=2, fontsize=13)\n", + "plt.show()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e10cb0d5", + "metadata": {}, + "outputs": [], + "source": [ + "### Backreaction\n", + "\n", + "\n", + "tau_f = 10.0\n", + "\n", + "ki = 1.0\n", + "# kf = ki\n", + "kf = 4.0e3\n", + "k_a = np.geomspace(ki, kf, 3)\n", + "\n", + "B0 = 1.0e-50\n", + "beta0 = 8.0e-1\n", + "B1 = 1.0e50\n", + "beta1 = 8.0e-1\n", + "\n", + "\n", + "csq1d_nopot = PyCSQ1DMagCauchy(B0, beta0)\n", + "csq1d_gauss = PyCSQ1DMagGauss(B1, beta1)\n", + "csq1d_cauchy = PyCSQ1DMagCauchy(B1, beta1)\n", + "\n", + "color_nopot = iter(\n", + " cm.Reds(np.linspace(1 / 2, 1, len(k_a)))\n", + ") # Go from 1/2 to 1 to display colours not too bright\n", + "color_gauss = iter(cm.Blues(np.linspace(1 / 2, 1, len(k_a))))\n", + "color_cauchy = iter(cm.Greens(np.linspace(1 / 2, 1, len(k_a))))\n", + "\n", + "tau_ad_a = np.linspace(-1.35, -1.0, 100)\n", + "tau_ad_a = tau_a\n", + "\n", + "fig = plt.figure(figsize=(14, 7))\n", + "\n", + "\n", + "# EM field energy density\n", + "\n", + "mylw = 1\n", + "\n", + "for ik, k in enumerate(k_a):\n", + " csq1d_nopot.set_k(k)\n", + " csq1d_gauss.set_k(k)\n", + " csq1d_cauchy.set_k(k)\n", + "\n", + " print(f\"Searching for WKB scale in ({tau_min}, {tau_qt_c})\")\n", + "\n", + " (Found_tau_i_nopot, tau_i_nopot) = csq1d_nopot.find_adiab_time_limit(\n", + " Vexp, tau_min, -1.0e-2, 1.0e-9\n", + " )\n", + " (Found_tau_i_gauss, tau_i_gauss) = csq1d_gauss.find_adiab_time_limit(\n", + " Vexp, tau_min, -1.0e-2, 1.0e-9\n", + " )\n", + " (Found_tau_i_cauchy, tau_i_cauchy) = csq1d_cauchy.find_adiab_time_limit(\n", + " Vexp, tau_min, -1.0e-2, 1.0e-9\n", + " )\n", + "\n", + " print(csq1d_nopot.eval_F1(Vexp, tau_i_nopot, k))\n", + " print(csq1d_gauss.eval_F1(Vexp, tau_i_gauss, k))\n", + " print(csq1d_cauchy.eval_F1(Vexp, tau_i_cauchy, k))\n", + "\n", + " print(csq1d_nopot.eval_adiab_at(Vexp, tau_i_nopot))\n", + " print(csq1d_gauss.eval_adiab_at(Vexp, tau_i_gauss))\n", + " print(csq1d_cauchy.eval_adiab_at(Vexp, tau_i_cauchy))\n", + "\n", + " F1_a_nopot = np.array([csq1d_nopot.eval_F1(Vexp, tau, k) for tau in tau_ad_a])\n", + " F2_a_nopot = np.array([csq1d_nopot.eval_F2(Vexp, tau, k) for tau in tau_ad_a])\n", + " nu_a_nopot = np.array([csq1d_nopot.eval_nu(Vexp, tau, k) for tau in tau_ad_a])\n", + "\n", + " F1_a_gauss = np.array([csq1d_gauss.eval_F1(Vexp, tau, k) for tau in tau_ad_a])\n", + " F2_a_gauss = np.array([csq1d_gauss.eval_F2(Vexp, tau, k) for tau in tau_ad_a])\n", + " nu_a_gauss = np.array([csq1d_gauss.eval_nu(Vexp, tau, k) for tau in tau_ad_a])\n", + "\n", + " F1_a_cauchy = np.array([csq1d_cauchy.eval_F1(Vexp, tau, k) for tau in tau_ad_a])\n", + " F2_a_cauchy = np.array([csq1d_cauchy.eval_F2(Vexp, tau, k) for tau in tau_ad_a])\n", + " nu_a_cauchy = np.array([csq1d_cauchy.eval_nu(Vexp, tau, k) for tau in tau_ad_a])\n", + "\n", + " csq1d_nopot.set_init_cond_adiab(Vexp, tau_i_nopot)\n", + " csq1d_gauss.set_init_cond_adiab(Vexp, tau_i_gauss)\n", + " csq1d_cauchy.set_init_cond_adiab(Vexp, tau_i_cauchy)\n", + "\n", + " csq1d_nopot.set_ti(tau_i_nopot)\n", + " csq1d_nopot.set_tf(tau_f)\n", + " csq1d_nopot.prepare(Vexp)\n", + "\n", + " csq1d_gauss.set_ti(tau_i_gauss)\n", + " csq1d_gauss.set_tf(tau_f)\n", + " csq1d_gauss.prepare(Vexp)\n", + "\n", + " csq1d_cauchy.set_ti(tau_i_cauchy)\n", + " csq1d_cauchy.set_tf(tau_f)\n", + " csq1d_cauchy.prepare(Vexp)\n", + "\n", + " tau_evol_a_nopot, tau_s_nopot = csq1d_nopot.get_time_array()\n", + " tau_evol_a_nopot = np.array(tau_evol_a_nopot)\n", + "\n", + " tau_evol_a_gauss, tau_s_gauss = csq1d_gauss.get_time_array()\n", + " tau_evol_a_gauss = np.array(tau_evol_a_gauss)\n", + "\n", + " tau_evol_a_cauchy, tau_s_cauchy = csq1d_cauchy.get_time_array()\n", + " tau_evol_a_cauchy = np.array(tau_evol_a_cauchy)\n", + "\n", + " rho_phi_a = []\n", + "\n", + " PB_a_nopot = []\n", + " PE_a_nopot = []\n", + " sf_a_nopot = []\n", + "\n", + " PB_a_gauss = []\n", + " PE_a_gauss = []\n", + " sf_a_gauss = []\n", + "\n", + " PB_a_cauchy = []\n", + " PE_a_cauchy = []\n", + " sf_a_cauchy = []\n", + "\n", + " for tau in tau_evol_a_nopot:\n", + " # Scale factor in terms of tau\n", + " alpha_a_nopot = Vexp.alpha(tau)\n", + " sf_a_nopot.append(np.exp(alpha_a_nopot) / Vexp.props.xb)\n", + " # Scalar field energy density. x and y are defined as (x,y) -> (kappa/sqrt(6))*(x,y)\n", + " # rho_phi = H^2 (x^2+y^2) / 2\n", + "\n", + " rho_phi_a.append(\n", + " (\n", + " (Vexp.x_y(tau)[0] ** 2 + Vexp.x_y(tau)[1] ** 2)\n", + " / 2.0\n", + " / (csq1d_nopot.RH * csq1d_nopot.RH)\n", + " )\n", + " )\n", + "\n", + " PB, PE, J11, J22 = csq1d_nopot.eval_PB_PE(Vexp, tau)\n", + " PB_a_nopot.append(PB)\n", + " PE_a_nopot.append(PE)\n", + "\n", + " for tau in tau_evol_a_gauss:\n", + " # Scale factor in terms of tau\n", + " alpha_a_gauss = Vexp.alpha(tau)\n", + " sf_a_gauss.append(np.exp(alpha_a_gauss) / Vexp.props.xb)\n", + " # Power spectra\n", + " PB, PE, J11, J22 = csq1d_gauss.eval_PB_PE(Vexp, tau)\n", + " PB_a_gauss.append(PB)\n", + " PE_a_gauss.append(PE)\n", + "\n", + " for tau in tau_evol_a_cauchy:\n", + " # Scale factor in terms of tau\n", + " alpha_a_cauchy = Vexp.alpha(tau)\n", + " sf_a_cauchy.append(np.exp(alpha_a_cauchy) / Vexp.props.xb)\n", + " # Power spectra\n", + " PB, PE, J11, J22 = csq1d_cauchy.eval_PB_PE(Vexp, tau)\n", + " PB_a_cauchy.append(PB)\n", + " PE_a_cauchy.append(PE)\n", + "\n", + " PB_a_nopot = np.array(PB_a_nopot)\n", + " PE_a_nopot = np.array(PE_a_nopot)\n", + " sf_a_nopot = np.array(sf_a_nopot)\n", + "\n", + " rho_phi_a = np.array(rho_phi_a)\n", + "\n", + " PB_a_gauss = np.array(PB_a_gauss)\n", + " PE_a_gauss = np.array(PE_a_gauss)\n", + " sf_a_gauss = np.array(sf_a_gauss)\n", + "\n", + " PB_a_cauchy = np.array(PB_a_cauchy)\n", + " PE_a_cauchy = np.array(PE_a_cauchy)\n", + " sf_a_cauchy = np.array(sf_a_cauchy)\n", + "\n", + " c_nopot = next(color_nopot)\n", + " c_gauss = next(color_gauss)\n", + " c_cauchy = next(color_cauchy)\n", + "\n", + " # Scalar field\n", + " plt.plot(tau_evol_a_nopot, rho_phi_a, c=\"red\", lw=mylw, label=r\"$\\rho_{{\\phi}}$\")\n", + "\n", + " # EM\n", + " plt.plot(\n", + " tau_evol_a_nopot,\n", + " ((PB_a_nopot + PE_a_nopot)[-1]) * sf_a_nopot[-1] ** 4 / sf_a_nopot**4,\n", + " c=c_nopot,\n", + " lw=mylw,\n", + " label=r\"$\\rho_r^{{nopot}}$ (k = $%s$)\" % latex_float(k),\n", + " )\n", + " plt.plot(\n", + " tau_evol_a_gauss,\n", + " ((PB_a_gauss + PE_a_gauss)[-1]) * sf_a_gauss[-1] ** 4 / sf_a_gauss**4,\n", + " c=c_gauss,\n", + " lw=mylw,\n", + " label=r\"$\\rho_{{r}}^{{gauss}}$ (k = $%s$)\" % latex_float(k),\n", + " )\n", + " plt.plot(\n", + " tau_evol_a_cauchy,\n", + " ((PB_a_cauchy + PE_a_cauchy)[-1]) * sf_a_cauchy[-1] ** 4 / sf_a_cauchy**4,\n", + " c=c_cauchy,\n", + " lw=mylw,\n", + " label=r\"$\\rho_{{r}}^{{cauchy}}$ (k = $%s$)\" % latex_float(k),\n", + " )\n", + "\n", + "\n", + "plt.xlabel(r\"$\\tau$\")\n", "plt.yscale(\"log\")\n", - "# plt.xlim(-19.0,-17.0)\n", - "# plt.ylim(1.0e-260,1.0e-90)" + "leg = plt.legend(loc=\"best\", ncol=2, fontsize=16)\n", + "# plt.xlim(-1.0,1.0)\n", + "# plt.ylim(10e-58,1)\n", + "plt.savefig(plotpath + \"plotrho_\" + current_set + \".pdf\")\n", + "\n", + "plt.show()" ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0689de74", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { diff --git a/numcosmo/data/nc_data_planck_lkl.c b/numcosmo/data/nc_data_planck_lkl.c index 0b4bf4157..da98a94d9 100644 --- a/numcosmo/data/nc_data_planck_lkl.c +++ b/numcosmo/data/nc_data_planck_lkl.c @@ -973,7 +973,7 @@ void nc_data_planck_lkl_download_baseline (const gchar *dir) { const gchar *file = "COM_Likelihood_Data-baseline_R3.00.tar.gz"; - const gchar *url_str = "http://pla.esac.esa.int/pla/aio/product-action?COSMOLOGY.FILE_ID=COM_Likelihood_Data-baseline_R3.00.tar.gz"; + const gchar *url_str = "https://github.com/NumCosmo/NumCosmo/releases/download/datafile-release-v1.0.0/COM_Likelihood_Data-baseline_R3.00.tar.gz"; gchar *full_filename = g_build_filename (dir, file, NULL); GError *error = NULL; gint prog = 0; diff --git a/numcosmo/data/nc_data_snia_cov.c b/numcosmo/data/nc_data_snia_cov.c index 32b915773..42416e33e 100644 --- a/numcosmo/data/nc_data_snia_cov.c +++ b/numcosmo/data/nc_data_snia_cov.c @@ -1097,8 +1097,6 @@ nc_data_snia_cov_new_full (const gchar *filename, gboolean use_norma) if (self->cat_version == 0) { - printf ("AQUI\n"); - fflush (stdout); nc_data_snia_cov_load_V0 (snia_cov, fptr); } else if (self->cat_version == 1) @@ -3721,19 +3719,6 @@ nc_data_snia_cov_get_catalog_by_id (NcDataSNIAId id) } } -void -_nc_data_snia_copy_prog (goffset current_num_bytes, goffset total_num_bytes, gpointer user_data) -{ - gint *old_prog = (gint *) user_data; - gint prog = (100 * current_num_bytes) / total_num_bytes; - - if (prog > *old_prog) - { - ncm_message ("# % 3d%%\r", prog); - *old_prog = prog; - } -} - /** * nc_data_snia_cov_get_fits: * @filename: Catalog fits filename @@ -3747,7 +3732,7 @@ gchar * nc_data_snia_cov_get_fits (const gchar *filename, gboolean check_size) { gchar *full_filename = ncm_cfg_get_fullpath (filename); - gchar *url_str = g_strdup_printf ("https://github.com/NumCosmo/NumCosmo/releases/download/v"PACKAGE_VERSION "/%s", filename); + gchar *url_str = g_strdup_printf ("https://github.com/NumCosmo/NumCosmo/releases/download/datafile-release-v1.0.0/%s", filename); GFile *local = g_file_new_for_path (full_filename); GFile *remote = g_file_new_for_uri (url_str); GError *error = NULL; @@ -3787,14 +3772,17 @@ nc_data_snia_cov_get_fits (const gchar *filename, gboolean check_size) if (download) { + const gchar *dir = ncm_cfg_get_fullpath_base (); + gchar *cmd[] = { "wget", "-O", full_filename, url_str, NULL }; + ncm_message ("# Downloading file [%s]...\n", url_str); - if (!g_file_copy (remote, local, G_FILE_COPY_OVERWRITE, NULL, - &_nc_data_snia_copy_prog, &prog, &error)) - g_error ("nc_data_snia_cov_get_fits: cannot get fits file from %s: %s." - " To use this catalog, download the file from the url and copy " - "to ~/.numcosmo directory.", - url_str, error->message); + if (!g_spawn_sync (dir, cmd, NULL, + G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL, NULL, &error)) + g_error ("nc_data_snia_cov_get_fits: cannot download file: %s. Error: %s. " + "Please download the file manually from %s and extract it to %s.", + filename, error->message, + url_str, dir); } g_free (url_str); diff --git a/numcosmo/math/ncm_c.c b/numcosmo/math/ncm_c.c index ba317af3b..f97aa6ea3 100644 --- a/numcosmo/math/ncm_c.c +++ b/numcosmo/math/ncm_c.c @@ -288,6 +288,14 @@ ncm_c_class_init (NcmCClass *klass) * Returns: Stefan Boltzmann constant $\sigma_\mathrm{SB} = 5.670374419 \times 10^{-8} \,\left[\mathrm{W}\,\mathrm{m}^{-2}\,\mathrm{K}^{-4}\right]$. */ +/** + * ncm_c_magnetic_constant: + * + * Using CODATA values, see [description][NcmC.description]. + * + * Returns: Magnetic constant $\mu_0 = 1.25663706212 \times 10^{-6} \,\left[\mathrm{N}\,\mathrm{A}^{-2}\right]$. + */ + /** * ncm_c_mass_atomic: * @@ -412,6 +420,14 @@ ncm_c_class_init (NcmCClass *klass) * Returns: The square of the fine struct constant $\alpha^2$. */ +/** + * ncm_c_electric_constant: + * + * Derived from CODATA values, see [description][NcmC.description]. + * + * Returns: Electric constant $\varepsilon_0 = 1 / (\mu_0 c^2) \,\left[\mathrm{F}\,\mathrm{m}^{-1}\right]$. + */ + /** * ncm_c_AR: * diff --git a/numcosmo/math/ncm_c.h b/numcosmo/math/ncm_c.h index 6df3f71b6..4590103d6 100644 --- a/numcosmo/math/ncm_c.h +++ b/numcosmo/math/ncm_c.h @@ -80,6 +80,7 @@ NCM_INLINE gdouble ncm_c_G (void) G_GNUC_CONST; NCM_INLINE gdouble ncm_c_planck_length (void) G_GNUC_CONST; NCM_INLINE gdouble ncm_c_thomson_cs (void) G_GNUC_CONST; NCM_INLINE gdouble ncm_c_stefan_boltzmann (void) G_GNUC_CONST; +NCM_INLINE gdouble ncm_c_magnetic_constant (void) G_GNUC_CONST; NCM_INLINE gdouble ncm_c_mass_atomic (void) G_GNUC_CONST; NCM_INLINE gdouble ncm_c_mass_e (void) G_GNUC_CONST; NCM_INLINE gdouble ncm_c_mass_p (void) G_GNUC_CONST; @@ -100,6 +101,7 @@ NCM_INLINE gdouble ncm_c_lightyear_pc (void) G_GNUC_CONST; NCM_INLINE gdouble ncm_c_Glightyear_Mpc (void) G_GNUC_CONST; NCM_INLINE gdouble ncm_c_hc (void) G_GNUC_CONST; NCM_INLINE gdouble ncm_c_fine_struct_square (void) G_GNUC_CONST; +NCM_INLINE gdouble ncm_c_electric_constant (void) G_GNUC_CONST; NCM_INLINE gdouble ncm_c_AR (void) G_GNUC_CONST; NCM_INLINE gdouble ncm_c_c2 (void) G_GNUC_CONST; NCM_INLINE gdouble ncm_c_planck_length2 (void) G_GNUC_CONST; @@ -548,6 +550,12 @@ ncm_c_stefan_boltzmann (void) return 5.670374419e-8; } +NCM_INLINE gdouble +ncm_c_magnetic_constant (void) +{ + return 1.25663706212e-6; +} + NCM_INLINE gdouble ncm_c_mass_atomic (void) { @@ -642,6 +650,12 @@ ncm_c_fine_struct_square (void) return ncm_c_fine_struct () * ncm_c_fine_struct (); } +NCM_INLINE gdouble +ncm_c_electric_constant (void) +{ + return 1.0 / (ncm_c_magnetic_constant () * ncm_c_c () * ncm_c_c ()); +} + NCM_INLINE gdouble ncm_c_AR (void) { diff --git a/numcosmo/math/ncm_cfg.c b/numcosmo/math/ncm_cfg.c index b230f47f7..c2e813b81 100644 --- a/numcosmo/math/ncm_cfg.c +++ b/numcosmo/math/ncm_cfg.c @@ -57,10 +57,11 @@ #include "math/ncm_spline2d_spline.h" #include "math/ncm_integral1d.h" #include "math/ncm_integral_nd.h" -#include "math/ncm_powspec.h" +#include "math/ncm_powspec_corr3d.h" #include "math/ncm_powspec_filter.h" #include "math/ncm_powspec_sphere_proj.h" -#include "math/ncm_powspec_corr3d.h" +#include "math/ncm_powspec_spline2d.h" +#include "math/ncm_powspec.h" #include "math/ncm_model.h" #include "math/ncm_model_ctrl.h" #include "math/ncm_model_builder.h" @@ -101,6 +102,7 @@ #include "model/nc_hicosmo_de_cpl.h" #include "model/nc_hicosmo_de_jbp.h" #include "model/nc_hicosmo_qgrw.h" +#include "model/nc_hicosmo_qgw.h" #include "model/nc_hicosmo_Vexp.h" #include "model/nc_hicosmo_de_reparam_ok.h" #include "model/nc_hicosmo_de_reparam_cmb.h" @@ -170,11 +172,12 @@ #include "nc_recomb_seager.h" #include "nc_hireion.h" #include "nc_hireion_camb.h" -#include "nc_powspec_ml.h" -#include "nc_powspec_ml_transfer.h" #include "nc_powspec_ml_cbe.h" -#include "nc_powspec_mnl.h" +#include "nc_powspec_ml_spline.h" +#include "nc_powspec_ml_transfer.h" +#include "nc_powspec_ml.h" #include "nc_powspec_mnl_halofit.h" +#include "nc_powspec_mnl.h" #include "nc_snia_dist_cov.h" #include "nc_planck_fi.h" #include "nc_planck_fi_cor_tt.h" @@ -295,7 +298,7 @@ _ncm_cfg_log_error (const gchar *log_domain, GLogLevelFlags log_level, const gch /* print out all the frames to stderr */ for (i = 0; i < size; i++) { - fprintf (_log_stream_err, "# (%s): %s-BACKTRACEA:[%02zd] %s\n", pname, log_domain, i, trace[i]); + fprintf (_log_stream_err, "# (%s): %s-BACKTRACE:[%02zd] %s\n", pname, log_domain, i, trace[i]); } g_free (trace); @@ -310,8 +313,6 @@ _ncm_cfg_log_error (const gchar *log_domain, GLogLevelFlags log_level, const gch abort (); } -void clencurt_gen (int M); - #ifdef HAVE_OPENBLAS_SET_NUM_THREADS void goto_set_num_threads (gint); void openblas_set_num_threads (gint); @@ -547,6 +548,7 @@ ncm_cfg_init_full_ptr (gint *argc, gchar ***argv) ncm_cfg_register_obj (NCM_TYPE_INTEGRAL_ND); ncm_cfg_register_obj (NCM_TYPE_POWSPEC); + ncm_cfg_register_obj (NCM_TYPE_POWSPEC_SPLINE2D); ncm_cfg_register_obj (NCM_TYPE_POWSPEC_FILTER); ncm_cfg_register_obj (NCM_TYPE_POWSPEC_SPHERE_PROJ); ncm_cfg_register_obj (NCM_TYPE_POWSPEC_CORR3D); @@ -608,6 +610,7 @@ ncm_cfg_init_full_ptr (gint *argc, gchar ***argv) ncm_cfg_register_obj (NC_TYPE_HICOSMO_DE_CPL); ncm_cfg_register_obj (NC_TYPE_HICOSMO_DE_JBP); ncm_cfg_register_obj (NC_TYPE_HICOSMO_QGRW); + ncm_cfg_register_obj (NC_TYPE_HICOSMO_QGW); ncm_cfg_register_obj (NC_TYPE_HICOSMO_VEXP); ncm_cfg_register_obj (NC_TYPE_HICOSMO_DE_REPARAM_OK); @@ -710,6 +713,7 @@ ncm_cfg_init_full_ptr (gint *argc, gchar ***argv) ncm_cfg_register_obj (NC_TYPE_HIREION_CAMB); ncm_cfg_register_obj (NC_TYPE_POWSPEC_ML); + ncm_cfg_register_obj (NC_TYPE_POWSPEC_ML_SPLINE); ncm_cfg_register_obj (NC_TYPE_POWSPEC_ML_TRANSFER); ncm_cfg_register_obj (NC_TYPE_POWSPEC_ML_CBE); @@ -1165,7 +1169,7 @@ ncm_cfg_set_log_handler (NcmCfgLoggerFunc logger) container.logger = logger; - _log_msg_id = g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_DEBUG, _ncm_cfg_log_message_logger, &container); + _log_msg_id = g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, _ncm_cfg_log_message_logger, &container); } /** diff --git a/numcosmo/math/ncm_csq1d.c b/numcosmo/math/ncm_csq1d.c index f674699da..96b2f3f1d 100644 --- a/numcosmo/math/ncm_csq1d.c +++ b/numcosmo/math/ncm_csq1d.c @@ -61,6 +61,7 @@ #include "math/ncm_c.h" #include "math/ncm_integrate.h" #include "math/ncm_memory_pool.h" +#include "ncm_enum_types.h" #ifndef NUMCOSMO_GIR_SCAN #include @@ -98,7 +99,6 @@ typedef struct _NcmCSQ1DPrivate { gdouble reltol; gdouble abstol; - gdouble k; gdouble ti; gdouble tf; gdouble t; @@ -107,7 +107,6 @@ typedef struct _NcmCSQ1DPrivate gdouble adiab_threshold; gdouble prop_threshold; gboolean save_evol; - gboolean max_order_2; NcmModelCtrl *ctrl; gpointer cvode; gpointer cvode_Up; @@ -133,9 +132,16 @@ typedef struct _NcmCSQ1DPrivate SUNLinearSolver LS_Prop; NcmSpline *alpha_s; NcmSpline *dgamma_s; + NcmSpline *gamma_s; NcmDiff *diff; NcmSpline *R[4]; gdouble tf_Prop; + gdouble ti_Prop; + NcmCSQ1DState *cur_state; + NcmCSQ1DInitialStateType initial_condition_type; + gdouble vacuum_reltol; + gdouble vacuum_max_time; + gdouble vacuum_final_time; } NcmCSQ1DPrivate; enum @@ -143,15 +149,17 @@ enum PROP_0, PROP_RELTOL, PROP_ABSTOL, - PROP_K, PROP_TI, PROP_TF, PROP_ADIAB_THRESHOLD, PROP_PROP_THRESHOLD, PROP_SAVE_EVOL, - PROP_MAX_ORDER_2, + PROP_VACUUM_TYPE, + PROP_VACUUM_RELTOL, + PROP_VACUUM_MAX_TIME, }; +G_DEFINE_BOXED_TYPE (NcmCSQ1DState, ncm_csq1d_state, ncm_csq1d_state_copy, ncm_csq1d_state_free) G_DEFINE_TYPE_WITH_PRIVATE (NcmCSQ1D, ncm_csq1d, G_TYPE_OBJECT) static void @@ -161,7 +169,6 @@ ncm_csq1d_init (NcmCSQ1D *csq1d) self->reltol = 0.0; self->abstol = 0.0; - self->k = 0.0; self->ti = 0.0; self->tf = 0.0; self->init_cond_set = FALSE; @@ -169,7 +176,6 @@ ncm_csq1d_init (NcmCSQ1D *csq1d) self->adiab_threshold = 0.0; self->prop_threshold = 0.0; self->save_evol = FALSE; - self->max_order_2 = FALSE; self->ctrl = ncm_model_ctrl_new (NULL); self->cvode = NULL; @@ -214,6 +220,7 @@ ncm_csq1d_init (NcmCSQ1D *csq1d) self->alpha_s = ncm_spline_cubic_notaknot_new (); self->dgamma_s = ncm_spline_cubic_notaknot_new (); + self->gamma_s = ncm_spline_cubic_notaknot_new (); { gint i; @@ -222,8 +229,15 @@ ncm_csq1d_init (NcmCSQ1D *csq1d) self->R[i] = ncm_spline_cubic_notaknot_new (); } self->tf_Prop = 0.0; + self->ti_Prop = 0.0; - self->diff = ncm_diff_new (); + self->diff = ncm_diff_new (); + self->cur_state = ncm_csq1d_state_new (); + + self->initial_condition_type = NCM_CSQ1D_INITIAL_CONDITION_TYPE_LENGTH; + self->vacuum_reltol = 0.0; + self->vacuum_max_time = 0.0; + self->vacuum_final_time = 0.0; } static void @@ -235,6 +249,7 @@ _ncm_csq1d_dispose (GObject *object) ncm_model_ctrl_clear (&self->ctrl); ncm_spline_clear (&self->alpha_s); ncm_spline_clear (&self->dgamma_s); + ncm_spline_clear (&self->gamma_s); { gint i; @@ -335,6 +350,8 @@ _ncm_csq1d_finalize (GObject *object) NCM_CVODE_CHECK (&flag, "SUNLinSolFree", 1, ); } + ncm_csq1d_state_free (self->cur_state); + /* Chain up : end */ G_OBJECT_CLASS (ncm_csq1d_parent_class)->finalize (object); } @@ -354,9 +371,6 @@ _ncm_csq1d_set_property (GObject *object, guint prop_id, const GValue *value, GP case PROP_ABSTOL: ncm_csq1d_set_abstol (csq1d, g_value_get_double (value)); break; - case PROP_K: - ncm_csq1d_set_k (csq1d, g_value_get_double (value)); - break; case PROP_TI: ncm_csq1d_set_ti (csq1d, g_value_get_double (value)); break; @@ -372,8 +386,14 @@ _ncm_csq1d_set_property (GObject *object, guint prop_id, const GValue *value, GP case PROP_SAVE_EVOL: ncm_csq1d_set_save_evol (csq1d, g_value_get_boolean (value)); break; - case PROP_MAX_ORDER_2: - ncm_csq1d_set_max_order_2 (csq1d, g_value_get_boolean (value)); + case PROP_VACUUM_TYPE: + ncm_csq1d_set_initial_condition_type (csq1d, g_value_get_enum (value)); + break; + case PROP_VACUUM_RELTOL: + ncm_csq1d_set_vacuum_reltol (csq1d, g_value_get_double (value)); + break; + case PROP_VACUUM_MAX_TIME: + ncm_csq1d_set_vacuum_max_time (csq1d, g_value_get_double (value)); break; default: /* LCOV_EXCL_LINE */ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); /* LCOV_EXCL_LINE */ @@ -396,9 +416,6 @@ _ncm_csq1d_get_property (GObject *object, guint prop_id, GValue *value, GParamSp case PROP_ABSTOL: g_value_set_double (value, ncm_csq1d_get_abstol (csq1d)); break; - case PROP_K: - g_value_set_double (value, ncm_csq1d_get_k (csq1d)); - break; case PROP_TI: g_value_set_double (value, ncm_csq1d_get_ti (csq1d)); break; @@ -414,8 +431,14 @@ _ncm_csq1d_get_property (GObject *object, guint prop_id, GValue *value, GParamSp case PROP_SAVE_EVOL: g_value_set_boolean (value, ncm_csq1d_get_save_evol (csq1d)); break; - case PROP_MAX_ORDER_2: - g_value_set_boolean (value, ncm_csq1d_get_max_order_2 (csq1d)); + case PROP_VACUUM_TYPE: + g_value_set_enum (value, ncm_csq1d_get_initial_condition_type (csq1d)); + break; + case PROP_VACUUM_RELTOL: + g_value_set_double (value, ncm_csq1d_get_vacuum_reltol (csq1d)); + break; + case PROP_VACUUM_MAX_TIME: + g_value_set_double (value, ncm_csq1d_get_vacuum_max_time (csq1d)); break; default: /* LCOV_EXCL_LINE */ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); /* LCOV_EXCL_LINE */ @@ -423,20 +446,16 @@ _ncm_csq1d_get_property (GObject *object, guint prop_id, GValue *value, GParamSp } } -static gdouble _ncm_csq1d_eval_xi (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); -static gdouble _ncm_csq1d_eval_dxi (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); -static gdouble _ncm_csq1d_eval_nu (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); -static gdouble _ncm_csq1d_eval_nu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); -static gdouble _ncm_csq1d_eval_m (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); -static gdouble _ncm_csq1d_eval_int_1_m (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); -static gdouble _ncm_csq1d_eval_int_mnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); -static gdouble _ncm_csq1d_eval_int_qmnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); -static gdouble _ncm_csq1d_eval_int_q2mnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); -static gdouble _ncm_csq1d_eval_dm (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); -static gdouble _ncm_csq1d_eval_F1 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); -static gdouble _ncm_csq1d_eval_F2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); -static gdouble _ncm_csq1d_eval_FN (NcmCSQ1D *csq1d, NcmModel *model, const gint n, const gdouble t, const gdouble k); -static gdouble _ncm_csq1d_eval_powspec_factor (NcmCSQ1D *csq1d, NcmModel *model, const gdouble k); +static gdouble _ncm_csq1d_eval_xi (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); +static gdouble _ncm_csq1d_eval_nu (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); +static gdouble _ncm_csq1d_eval_nu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); +static gdouble _ncm_csq1d_eval_m (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); +static gdouble _ncm_csq1d_eval_int_1_m (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); +static gdouble _ncm_csq1d_eval_int_mnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); +static gdouble _ncm_csq1d_eval_int_qmnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); +static gdouble _ncm_csq1d_eval_int_q2mnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); +static gdouble _ncm_csq1d_eval_F1 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); +static gdouble _ncm_csq1d_eval_F2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); static void ncm_csq1d_class_init (NcmCSQ1DClass *klass) @@ -462,13 +481,6 @@ ncm_csq1d_class_init (NcmCSQ1DClass *klass) "Absolute tolerance tolerance", 0.0, G_MAXDOUBLE, 0.0, G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB)); - g_object_class_install_property (object_class, - PROP_K, - g_param_spec_double ("k", - NULL, - "Mode k", - 0.0, G_MAXDOUBLE, 1.0, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB)); g_object_class_install_property (object_class, PROP_TI, g_param_spec_double ("ti", @@ -488,7 +500,7 @@ ncm_csq1d_class_init (NcmCSQ1DClass *klass) g_param_spec_double ("adiab-threshold", NULL, "The adiabatic threshold", - 0.0, G_MAXDOUBLE, 1.0e-1, + 0.0, G_MAXDOUBLE, 1.0e0, G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB)); g_object_class_install_property (object_class, PROP_PROP_THRESHOLD, @@ -505,31 +517,44 @@ ncm_csq1d_class_init (NcmCSQ1DClass *klass) TRUE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB)); g_object_class_install_property (object_class, - PROP_MAX_ORDER_2, - g_param_spec_boolean ("max-order-2", - NULL, - "Whether to always truncate at order 2", - FALSE, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB)); + PROP_VACUUM_TYPE, + g_param_spec_enum ("vacuum-type", + NULL, + "The vacuum type", + NCM_TYPE_CSQ1D_INITIAL_CONDITION_TYPE, + NCM_CSQ1D_INITIAL_CONDITION_TYPE_AD_HOC, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB)); + + g_object_class_install_property (object_class, + PROP_VACUUM_RELTOL, + g_param_spec_double ("vacuum-reltol", + NULL, + "The vacuum relative tolerance", + DBL_EPSILON, 1.0, 1.0e-5, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB)); + + g_object_class_install_property (object_class, + PROP_VACUUM_MAX_TIME, + g_param_spec_double ("vacuum-max-time", + NULL, + "The vacuum maximum time", + -G_MAXDOUBLE, G_MAXDOUBLE, 1.0, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB)); - klass->eval_xi = &_ncm_csq1d_eval_xi; - klass->eval_dxi = &_ncm_csq1d_eval_dxi; - klass->eval_nu = &_ncm_csq1d_eval_nu; - klass->eval_nu2 = &_ncm_csq1d_eval_nu2; - klass->eval_m = &_ncm_csq1d_eval_m; - klass->eval_int_1_m = &_ncm_csq1d_eval_int_1_m; - klass->eval_int_mnu2 = &_ncm_csq1d_eval_int_mnu2; - klass->eval_int_qmnu2 = &_ncm_csq1d_eval_int_qmnu2; - klass->eval_int_q2mnu2 = &_ncm_csq1d_eval_int_q2mnu2; - klass->eval_dm = &_ncm_csq1d_eval_dm; - klass->eval_F1 = &_ncm_csq1d_eval_F1; - klass->eval_F2 = &_ncm_csq1d_eval_F2; - klass->eval_FN = &_ncm_csq1d_eval_FN; - klass->eval_powspec_factor = &_ncm_csq1d_eval_powspec_factor; + klass->eval_xi = &_ncm_csq1d_eval_xi; + klass->eval_nu = &_ncm_csq1d_eval_nu; + klass->eval_nu2 = &_ncm_csq1d_eval_nu2; + klass->eval_m = &_ncm_csq1d_eval_m; + klass->eval_int_1_m = &_ncm_csq1d_eval_int_1_m; + klass->eval_int_mnu2 = &_ncm_csq1d_eval_int_mnu2; + klass->eval_int_qmnu2 = &_ncm_csq1d_eval_int_qmnu2; + klass->eval_int_q2mnu2 = &_ncm_csq1d_eval_int_q2mnu2; + klass->eval_F1 = &_ncm_csq1d_eval_F1; + klass->eval_F2 = &_ncm_csq1d_eval_F2; } static gdouble -_ncm_csq1d_eval_xi (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k) +_ncm_csq1d_eval_xi (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) { g_error ("_ncm_csq1d_eval_xi: not implemented."); @@ -537,13 +562,7 @@ _ncm_csq1d_eval_xi (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdo } static gdouble -_ncm_csq1d_eval_dxi (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k) -{ - return NCM_CSQ1D_GET_CLASS (csq1d)->eval_F1 (csq1d, model, t, k) * 2.0 * NCM_CSQ1D_GET_CLASS (csq1d)->eval_nu (csq1d, model, t, k); -} - -static gdouble -_ncm_csq1d_eval_nu (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k) +_ncm_csq1d_eval_nu (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) { g_error ("_ncm_csq1d_eval_nu: not implemented."); @@ -551,19 +570,19 @@ _ncm_csq1d_eval_nu (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdo } static gdouble -_ncm_csq1d_eval_nu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k) +_ncm_csq1d_eval_nu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) { - return gsl_pow_2 (NCM_CSQ1D_GET_CLASS (csq1d)->eval_nu (csq1d, model, t, k)); + return gsl_pow_2 (NCM_CSQ1D_GET_CLASS (csq1d)->eval_nu (csq1d, model, t)); } static gdouble -_ncm_csq1d_eval_m (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k) +_ncm_csq1d_eval_m (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) { - return exp (NCM_CSQ1D_GET_CLASS (csq1d)->eval_xi (csq1d, model, t, k)) / NCM_CSQ1D_GET_CLASS (csq1d)->eval_nu (csq1d, model, t, k); + return exp (NCM_CSQ1D_GET_CLASS (csq1d)->eval_xi (csq1d, model, t)) / NCM_CSQ1D_GET_CLASS (csq1d)->eval_nu (csq1d, model, t); } static gdouble -_ncm_csq1d_eval_int_1_m (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k) +_ncm_csq1d_eval_int_1_m (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) { g_error ("_ncm_csq1d_eval_int_1_m: not implemented."); @@ -571,7 +590,7 @@ _ncm_csq1d_eval_int_1_m (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, cons } static gdouble -_ncm_csq1d_eval_int_mnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k) +_ncm_csq1d_eval_int_mnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) { g_error ("_ncm_csq1d_eval_int_mnu2: not implemented."); @@ -579,7 +598,7 @@ _ncm_csq1d_eval_int_mnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, con } static gdouble -_ncm_csq1d_eval_int_qmnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k) +_ncm_csq1d_eval_int_qmnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) { g_error ("_ncm_csq1d_eval_int_qmnu2: not implemented."); @@ -587,7 +606,7 @@ _ncm_csq1d_eval_int_qmnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, co } static gdouble -_ncm_csq1d_eval_int_q2mnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k) +_ncm_csq1d_eval_int_q2mnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) { g_error ("_ncm_csq1d_eval_int_q2mnu2: not implemented."); @@ -595,15 +614,7 @@ _ncm_csq1d_eval_int_q2mnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, c } static gdouble -_ncm_csq1d_eval_dm (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k) -{ - g_error ("_ncm_csq1d_eval_dm: not implemented."); - - return 0.0; -} - -static gdouble -_ncm_csq1d_eval_F1 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k) +_ncm_csq1d_eval_F1 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) { g_error ("_ncm_csq1d_eval_F1: not implemented."); @@ -621,11 +632,11 @@ typedef struct _NcmCSQ1DWS static gdouble _ncm_csq1d_F1_func (const gdouble t, gpointer user_data); static gdouble -_ncm_csq1d_eval_F2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k) +_ncm_csq1d_eval_F2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) { NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); NcmCSQ1DWS ws = {csq1d, model, 0.0, 0.0}; - const gdouble nu = ncm_csq1d_eval_nu (csq1d, model, t, self->k); + const gdouble nu = ncm_csq1d_eval_nu (csq1d, model, t); const gdouble twonu = 2.0 * nu; gdouble err; @@ -633,22 +644,374 @@ _ncm_csq1d_eval_F2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdo return ncm_diff_rc_d1_1_to_1 (self->diff, t, &_ncm_csq1d_F1_func, &ws, &err) / twonu; } -static gdouble -_ncm_csq1d_eval_FN (NcmCSQ1D *csq1d, NcmModel *model, const gint n, const gdouble t, const gdouble k) +/* State related functions */ + +/** + * ncm_csq1d_state_new: + * + * Creates a new and uninitialized #NcmCSQ1DState. + * + * Returns: (transfer full): a new #NcmCSQ1DState. + */ +NcmCSQ1DState * +ncm_csq1d_state_new (void) { - g_error ("_ncm_csq1d_eval_FN: not implemented."); + return g_slice_new0 (NcmCSQ1DState); +} - return 0.0; +/** + * ncm_csq1d_state_copy: + * @state: a #NcmCSQ1DState + * + * Creates a copy of @state. + * + * Returns: (transfer full): a new #NcmCSQ1DState with the same contents as @state. + */ +NcmCSQ1DState * +ncm_csq1d_state_copy (NcmCSQ1DState *state) +{ + return g_slice_dup (NcmCSQ1DState, state); +} + +/** + * ncm_csq1d_state_free: + * @state: a #NcmCSQ1DState + * + * Frees @state. + * + */ +void +ncm_csq1d_state_free (NcmCSQ1DState *state) +{ + g_slice_free (NcmCSQ1DState, state); +} + +/** + * ncm_csq1d_state_set_ag: + * @state: a #NcmCSQ1DState + * @frame: the frame of @state + * @t: the time of @state + * @alpha: the alpha of @state + * @gamma: the gamma of @state + * + * Sets the state using the $(\alpha, \gamma)$ parametrization. + * + */ +void +ncm_csq1d_state_set_ag (NcmCSQ1DState *state, const NcmCSQ1DFrame frame, const gdouble t, const gdouble alpha, const gdouble gamma) +{ + state->frame = frame; + state->t = t; + state->alpha = alpha; + state->gamma = gamma; +} + +/** + * ncm_csq1d_state_set_up: + * @state: a #NcmCSQ1DState + * @frame: the frame of @state + * @t: the time of @state + * @chi: the chi of @state + * @Up: the Up of @state + * + * Sets the state using the $(\chi, U_+)$ parametrization. + * + */ +void +ncm_csq1d_state_set_up (NcmCSQ1DState *state, const NcmCSQ1DFrame frame, const gdouble t, const gdouble chi, const gdouble Up) +{ + state->frame = frame; + state->t = t; + state->alpha = asinh (chi); + state->gamma = Up - gsl_sf_lncosh (state->alpha); +} + +/** + * ncm_csq1d_state_set_um: + * @state: a #NcmCSQ1DState + * @frame: the frame of @state + * @t: the time of @state + * @chi: the chi of @state + * @Um: the Um of @state + * + * Sets the state using the $(\chi, U_-)$ parametrization. + * + */ +void +ncm_csq1d_state_set_um (NcmCSQ1DState *state, const NcmCSQ1DFrame frame, const gdouble t, const gdouble chi, const gdouble Um) +{ + state->frame = frame; + state->t = t; + state->alpha = asinh (chi); + state->gamma = -Um + gsl_sf_lncosh (state->alpha); +} + +/** + * ncm_csq1d_state_get_time: + * @state: a #NcmCSQ1DState + * + * Returns: the time of @state. + */ +gdouble +ncm_csq1d_state_get_time (NcmCSQ1DState *state) +{ + return state->t; +} + +/** + * ncm_csq1d_state_get_frame: + * @state: a #NcmCSQ1DState + * + * Returns: the frame of @state. + */ +NcmCSQ1DFrame +ncm_csq1d_state_get_frame (NcmCSQ1DState *state) +{ + return state->frame; +} + +/** + * ncm_csq1d_state_get_ag: + * @state: a #NcmCSQ1DState + * @alpha: (out): the alpha of @state + * @gamma: (out): the gamma of @state + * + * Computes the $(\alpha, \gamma)$ parametrization of @state. + * + */ +void +ncm_csq1d_state_get_ag (NcmCSQ1DState *state, gdouble *alpha, gdouble *gamma) +{ + *alpha = state->alpha; + *gamma = state->gamma; +} + +/** + * ncm_csq1d_state_get_up: + * @state: a #NcmCSQ1DState + * @chi: (out): the chi of @state + * @Up: (out): the Up of @state + * + * Computes the $(\chi, U_+)$ parametrization of @state. + * + */ +void +ncm_csq1d_state_get_up (NcmCSQ1DState *state, gdouble *chi, gdouble *Up) +{ + *chi = sinh (state->alpha); + *Up = state->gamma + gsl_sf_lncosh (state->alpha); +} + +/** + * ncm_csq1d_state_get_um: + * @state: a #NcmCSQ1DState + * @chi: (out): the chi of @state + * @Um: (out): the Um of @state + * + * Computes the $(\chi, U_-)$ parametrization of @state. + * + */ +void +ncm_csq1d_state_get_um (NcmCSQ1DState *state, gdouble *chi, gdouble *Um) +{ + *chi = sinh (state->alpha); + *Um = -state->gamma + gsl_sf_lncosh (state->alpha); +} + +/** + * ncm_csq1d_state_get_J: + * @state: a #NcmCSQ1DState + * @J11: (out): the J11 of @state + * @J12: (out): the J12 of @state + * @J22: (out): the J22 of @state + * + * Computes the covariant metric of @state. + * + */ +void +ncm_csq1d_state_get_J (NcmCSQ1DState *state, gdouble *J11, gdouble *J12, gdouble *J22) +{ + const gdouble alpha = state->alpha; + const gdouble gamma = state->gamma; + + *J11 = cosh (alpha) * exp (-gamma); + *J22 = cosh (alpha) * exp (+gamma); + *J12 = -sinh (alpha); +} + +/** + * ncm_csq1d_state_get_phi_Pphi: + * @state: a #NcmCSQ1DState + * @phi: (out caller-allocates) (array fixed-size=2): the $\phi$ of @state + * @Pphi: (out caller-allocates) (array fixed-size=2): the $P_\phi$ of @state + * + * Computes the $(\phi, P_\phi)$ parametrization of @state. + * + */ +void +ncm_csq1d_state_get_phi_Pphi (NcmCSQ1DState *state, gdouble *phi, gdouble *Pphi) +{ + const gdouble alpha = state->alpha; + const gdouble gamma = state->gamma; + const gdouble exp_gamma_p_alpha_2 = exp (0.5 * (gamma + alpha)); + const gdouble exp_gamma_m_alpha_2 = exp (0.5 * (gamma - alpha)); + + phi[0] = +0.5 / exp_gamma_m_alpha_2; + phi[1] = -0.5 / exp_gamma_p_alpha_2; + + Pphi[0] = -0.5 * exp_gamma_p_alpha_2; + Pphi[1] = -0.5 * exp_gamma_m_alpha_2; +} + +/** + * ncm_csq1d_state_get_poincare_half_plane: + * @state: a #NcmCSQ1DState + * @x: (out): the $x$ of @state + * @lny: (out): the $\ln y$ of @state + * + * Computes the Poincaré half-plane parametrization of @state. + * + */ +void +ncm_csq1d_state_get_poincare_half_plane (NcmCSQ1DState *state, gdouble *x, gdouble *lny) +{ + const gdouble alpha = state->alpha; + const gdouble gamma = state->gamma; + + *x = exp (-gamma) * tanh (alpha); + *lny = -gamma - gsl_sf_lncosh (alpha); +} + +/** + * ncm_csq1d_state_get_poincare_disc: + * @state: a #NcmCSQ1DState + * @x: (out): the $x$ of @state + * @y: (out): the $y$ of @state + * + * Computes the Poincaré disc parametrization of @state. + * + */ +void +ncm_csq1d_state_get_poincare_disc (NcmCSQ1DState *state, gdouble *x, gdouble *y) +{ + const gdouble alpha = state->alpha; + const gdouble gamma = state->gamma; + + *x = +tanh (alpha) / (1.0 / cosh (alpha) + cosh (gamma)); + *y = -tanh (gamma) / (1.0 / (cosh (alpha) * cosh (gamma)) + 1.0); +} + +/** + * ncm_csq1d_state_get_minkowski: + * @state: a #NcmCSQ1DState + * @x1: (out): the $x_1$ of @state + * @x2: (out): the $x_2$ of @state + * + * Computes the Minkowski parametrization of @state. + * + */ +void +ncm_csq1d_state_get_minkowski (NcmCSQ1DState *state, gdouble *x1, gdouble *x2) +{ + const gdouble alpha = state->alpha; + const gdouble gamma = state->gamma; + + *x1 = +sinh (alpha); + *x2 = -cosh (alpha) * sinh (gamma); } static gdouble -_ncm_csq1d_eval_powspec_factor (NcmCSQ1D *csq1d, NcmModel *model, const gdouble k) +_arcsinh_exp_x (const gdouble x) { - g_error ("_ncm_csq1d_eval_powspec_factor: not implemented."); + return x + log1p (sqrt (1.0 + exp (-2.0 * x))); +} - return 0.0; +static gdouble +_arccosh_exp_x (const gdouble x) +{ + return x + log1p (sqrt (1.0 - exp (-2.0 * x))); +} + +/** + * ncm_csq1d_state_get_circle: + * @state: a #NcmCSQ1DState + * @r: radius + * @theta: angle + * @cstate: (out caller-allocates): the new state + * + * Computes the complex structure matrix parameters for a circle + * around the point @state with radius $r$ and angle + * $\theta$ and stores the result in @cstate. + * + */ +void +ncm_csq1d_state_get_circle (NcmCSQ1DState *state, const gdouble r, const gdouble theta, NcmCSQ1DState *cstate) +{ + const gdouble alpha = state->alpha; + const gdouble gamma = state->gamma; + const gdouble ct = cos (theta); + const gdouble st = sin (theta); + const gdouble tr = tanh (r); + const gdouble ca = cosh (alpha); + const gdouble ta = tanh (alpha); + const gdouble lncr = gsl_sf_lncosh (r); + const gdouble lnca = gsl_sf_lncosh (alpha); + const gdouble f = (ta + ct * tr); + const gdouble absf = fabs (f); + const gdouble ln_absf = log (absf); + const gdouble signf = GSL_SIGN (f); + const gdouble t1 = signf * _arcsinh_exp_x (lncr + lnca + ln_absf); + const gdouble t2 = -(2.0 * st * tr / (ca * (1.0 + tr * ct * ta) + tr * st)); + + ncm_csq1d_state_set_ag (cstate, state->frame, state->t, t1, gamma + 0.5 * log1p (t2)); +} + +/** + * ncm_csq1d_state_compute_distance: + * @state: a #NcmCSQ1DState + * @state1: a #NcmCSQ1DState + * + * Computes the distance between @state and @state1. + * + * Returns: the distance between @state and @state1. + */ +gdouble +ncm_csq1d_state_compute_distance (NcmCSQ1DState *state, NcmCSQ1DState *state1) +{ + const gdouble dgamma01 = state->gamma - state1->gamma; + + g_assert (state->frame == state1->frame); + g_assert (state->t == state1->t); + + if ((fabs (state->alpha) > 1.0) || (fabs (state1->alpha) > 1.0) || (fabs (dgamma01) > 1.0)) + { + const gdouble lncoshalpha0 = gsl_sf_lncosh (state->alpha); + const gdouble lncoshalpha1 = gsl_sf_lncosh (state1->alpha); + const gdouble lncoshdgamma = gsl_sf_lncosh (dgamma01); + const gdouble tanhalpha0 = tanh (state->alpha); + const gdouble tanhalpha1 = tanh (state1->alpha); + const gdouble f = log1p (-tanhalpha0 * tanhalpha1 * exp (-lncoshdgamma)); + + return _arccosh_exp_x (lncoshalpha0 + lncoshalpha1 + lncoshdgamma + f); + } + else + { + const gdouble a = gsl_sf_lncosh (state->alpha + state1->alpha); + const gdouble b = gsl_sf_lncosh (state->alpha - state1->alpha); + const gdouble c = gsl_sf_lncosh (dgamma01); + const gdouble expm1a = expm1 (a); + const gdouble expm1b = expm1 (b); + const gdouble expm1apc = expm1 (a + c); + const gdouble expm1bpc = expm1 (b + c); + const gdouble M12_m1 = 0.5 * (expm1apc + expm1bpc + expm1b - expm1a); + const gdouble dist = asinh (sqrt (M12_m1 * (2.0 + M12_m1))); + + return dist; + } } +/* CSQ1D methods */ + /** * ncm_csq1d_ref: * @csq1d: a #NcmCSQ1D @@ -702,7 +1065,11 @@ ncm_csq1d_set_reltol (NcmCSQ1D *csq1d, const gdouble reltol) { NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); - self->reltol = reltol; + if (self->reltol != reltol) + { + self->reltol = reltol; + ncm_model_ctrl_force_update (self->ctrl); + } } /** @@ -718,23 +1085,11 @@ ncm_csq1d_set_abstol (NcmCSQ1D *csq1d, const gdouble abstol) { NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); - self->abstol = abstol; -} - -/** - * ncm_csq1d_set_k: - * @csq1d: a #NcmCSQ1D - * @k: mode $k$ - * - * Sets the mode $k$ to @k. - * - */ -void -ncm_csq1d_set_k (NcmCSQ1D *csq1d, const gdouble k) -{ - NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); - - self->k = k; + if (self->abstol != abstol) + { + self->abstol = abstol; + ncm_model_ctrl_force_update (self->ctrl); + } } /** @@ -754,6 +1109,7 @@ ncm_csq1d_set_ti (NcmCSQ1D *csq1d, const gdouble ti) { self->ti = ti; self->init_cond_set = FALSE; + ncm_model_ctrl_force_update (self->ctrl); } } @@ -770,7 +1126,11 @@ ncm_csq1d_set_tf (NcmCSQ1D *csq1d, const gdouble tf) { NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); - self->tf = tf; + if (self->tf != tf) + { + self->tf = tf; + ncm_model_ctrl_force_update (self->ctrl); + } } /** @@ -786,7 +1146,11 @@ ncm_csq1d_set_adiab_threshold (NcmCSQ1D *csq1d, const gdouble adiab_threshold) { NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); - self->adiab_threshold = adiab_threshold; + if (self->adiab_threshold != adiab_threshold) + { + ncm_model_ctrl_force_update (self->ctrl); + self->adiab_threshold = adiab_threshold; + } } /** @@ -826,66 +1190,46 @@ ncm_csq1d_set_save_evol (NcmCSQ1D *csq1d, gboolean save_evol) } } -/** - * ncm_csq1d_set_max_order_2: - * @csq1d: a #NcmCSQ1D - * @truncate: whether to truncate the adiabatic series at order 2 - * - * If true truncates the adiabatic series at order 2. - * - */ -void -ncm_csq1d_set_max_order_2 (NcmCSQ1D *csq1d, gboolean truncate) -{ - NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); - - if (self->max_order_2 != truncate) - { - ncm_model_ctrl_force_update (self->ctrl); - self->max_order_2 = truncate; - } -} - /** * ncm_csq1d_set_init_cond: * @csq1d: a #NcmCSQ1D - * @state: a #NcmCSQ1DEvolState - * @ti: initial time $t_i$ - * @x: $\alpha$ or $\chi$ depending on the @state - * @y: $\delta\gamma$, $U_+$ or $U_-$ depending on the @state + * @model: (allow-none): a #NcmModel + * @evol_state: a #NcmCSQ1DEvolState + * @initial_state: a #NcmCSQ1DState * - * Sets the values of the initial conditions at $t_i$. - * This method also updates the value of $t_i$. + * Sets the values of the initial conditions to @initial_state. + * Depending on the value of @evol_state, the initial conditions + * are set in the adiabatic frame 1 if @evol_state is #NCM_CSQ1D_EVOL_STATE_ADIABATIC, + * or in the original frame when using the $U_+$ or $U_-$ parametrization. * */ void -ncm_csq1d_set_init_cond (NcmCSQ1D *csq1d, NcmCSQ1DEvolState state, const gdouble ti, const gdouble x, const gdouble y) +ncm_csq1d_set_init_cond (NcmCSQ1D *csq1d, NcmModel *model, NcmCSQ1DEvolState evol_state, NcmCSQ1DState *initial_state) { NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); - switch (state) + switch (evol_state) { case NCM_CSQ1D_EVOL_STATE_ADIABATIC: - NV_Ith_S (self->y, 0) = x; - NV_Ith_S (self->y, 1) = y; + ncm_csq1d_change_frame (csq1d, model, initial_state, NCM_CSQ1D_FRAME_ADIAB1); + ncm_csq1d_state_get_ag (initial_state, &NV_Ith_S (self->y, 0), &NV_Ith_S (self->y, 1)); break; case NCM_CSQ1D_EVOL_STATE_UP: - NV_Ith_S (self->y_Up, 0) = x; - NV_Ith_S (self->y_Up, 1) = y; + ncm_csq1d_change_frame (csq1d, model, initial_state, NCM_CSQ1D_FRAME_ORIG); + ncm_csq1d_state_get_up (initial_state, &NV_Ith_S (self->y_Up, 0), &NV_Ith_S (self->y_Up, 1)); break; case NCM_CSQ1D_EVOL_STATE_UM: - NV_Ith_S (self->y_Um, 0) = x; - NV_Ith_S (self->y_Um, 1) = y; + ncm_csq1d_change_frame (csq1d, model, initial_state, NCM_CSQ1D_FRAME_ORIG); + ncm_csq1d_state_get_um (initial_state, &NV_Ith_S (self->y_Um, 0), &NV_Ith_S (self->y_Um, 1)); break; default: - g_error ("ncm_csq1d_set_init_cond: state %d not supported", state); + g_error ("ncm_csq1d_set_init_cond: state %d not supported", evol_state); break; } - self->t = ti; - self->state = state; + self->t = ncm_csq1d_state_get_time (initial_state); + self->state = evol_state; - ncm_csq1d_set_ti (csq1d, ti); self->init_cond_set = TRUE; } @@ -903,57 +1247,109 @@ void ncm_csq1d_set_init_cond_adiab (NcmCSQ1D *csq1d, NcmModel *model, const gdouble ti) { NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); - gdouble alpha, dgamma; + NcmCSQ1DState *state = ncm_csq1d_compute_adiab (csq1d, model, ti, self->cur_state, NULL, NULL); - ncm_csq1d_eval_adiab_at (csq1d, model, ti, &alpha, &dgamma, NULL, NULL); + g_assert (state->frame == NCM_CSQ1D_FRAME_ADIAB1); - if ((fabs (dgamma) > self->adiab_threshold) || (fabs (alpha) > self->adiab_threshold)) + if ((fabs (state->gamma) > self->adiab_threshold) || (fabs (state->alpha) > self->adiab_threshold)) g_error ("ncm_csq1d_set_init_cond_adiab: time ti == % 22.15g is not a valid adiabatic time alpha, dgamma == (% 22.15g, % 22.15g)", - ti, alpha, dgamma); + ti, state->alpha, state->gamma); else - ncm_csq1d_set_init_cond (csq1d, NCM_CSQ1D_EVOL_STATE_ADIABATIC, ti, alpha, dgamma); + ncm_csq1d_set_init_cond (csq1d, model, NCM_CSQ1D_EVOL_STATE_ADIABATIC, state); } /** - * ncm_csq1d_get_reltol: + * ncm_csq1d_set_initial_condition_type: * @csq1d: a #NcmCSQ1D + * @initial_condition_type: the vacuum type + * + * Sets the initial condition type to @initial_condition_type. The initial condition + * type is used to determine the initial state state when preparing the object using + * ncm_csq1d_prepare(). * - * Returns: the relative tolerance. */ -gdouble -ncm_csq1d_get_reltol (NcmCSQ1D *csq1d) +void +ncm_csq1d_set_initial_condition_type (NcmCSQ1D *csq1d, NcmCSQ1DInitialStateType initial_condition_type) { NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); - return self->reltol; + if (self->initial_condition_type != initial_condition_type) + { + ncm_model_ctrl_force_update (self->ctrl); + self->initial_condition_type = initial_condition_type; + } } /** - * ncm_csq1d_get_abstol: + * ncm_csq1d_set_vacuum_reltol: * @csq1d: a #NcmCSQ1D + * @vacuum_reltol: relative tolerance + * + * Sets the relative tolerance for the vacuum definition. This tolerance + * is used to determine the vacuum state when preparing the object using + * ncm_csq1d_prepare(). * - * Returns: the absolute tolerance to @abstol. */ -gdouble -ncm_csq1d_get_abstol (NcmCSQ1D *csq1d) +void +ncm_csq1d_set_vacuum_reltol (NcmCSQ1D *csq1d, const gdouble vacuum_reltol) { NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); - return self->abstol; -} + if (self->vacuum_reltol != vacuum_reltol) + { + ncm_model_ctrl_force_update (self->ctrl); + self->vacuum_reltol = vacuum_reltol; + } +} + +/** + * ncm_csq1d_set_vacuum_max_time: + * @csq1d: a #NcmCSQ1D + * @vacuum_max_time: maximum time + * + * Sets the maximum time for the vacuum search. This time is used + * to determine the vacuum state when preparing the object using + * ncm_csq1d_prepare(). + * + */ +void +ncm_csq1d_set_vacuum_max_time (NcmCSQ1D *csq1d, const gdouble vacuum_max_time) +{ + NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); + + if (self->vacuum_max_time != vacuum_max_time) + { + ncm_model_ctrl_force_update (self->ctrl); + self->vacuum_max_time = vacuum_max_time; + } +} + +/** + * ncm_csq1d_get_reltol: + * @csq1d: a #NcmCSQ1D + * + * Returns: the relative tolerance. + */ +gdouble +ncm_csq1d_get_reltol (NcmCSQ1D *csq1d) +{ + NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); + + return self->reltol; +} /** - * ncm_csq1d_get_k: + * ncm_csq1d_get_abstol: * @csq1d: a #NcmCSQ1D * - * Returns: the mode $k$. + * Returns: the absolute tolerance to @abstol. */ gdouble -ncm_csq1d_get_k (NcmCSQ1D *csq1d) +ncm_csq1d_get_abstol (NcmCSQ1D *csq1d) { NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); - return self->k; + return self->abstol; } /** @@ -1027,17 +1423,45 @@ ncm_csq1d_get_save_evol (NcmCSQ1D *csq1d) } /** - * ncm_csq1d_get_max_order_2: + * ncm_csq1d_get_initial_condition_type: * @csq1d: a #NcmCSQ1D * - * Returns: whether the maximum order of the adiabatic series is 2. + * Returns: the initial condition type. */ -gboolean -ncm_csq1d_get_max_order_2 (NcmCSQ1D *csq1d) +NcmCSQ1DInitialStateType +ncm_csq1d_get_initial_condition_type (NcmCSQ1D *csq1d) +{ + NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); + + return self->initial_condition_type; +} + +/** + * ncm_csq1d_get_vacuum_reltol: + * @csq1d: a #NcmCSQ1D + * + * Returns: the relative tolerance for the vacuum definition. + */ +gdouble +ncm_csq1d_get_vacuum_reltol (NcmCSQ1D *csq1d) +{ + NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); + + return self->vacuum_reltol; +} + +/** + * ncm_csq1d_get_vacuum_max_time: + * @csq1d: a #NcmCSQ1D + * + * Returns: the maximum time for the vacuum search. + */ +gdouble +ncm_csq1d_get_vacuum_max_time (NcmCSQ1D *csq1d) { NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); - return self->max_order_2; + return self->vacuum_max_time; } static gint _ncm_csq1d_f (realtype t, N_Vector y, N_Vector ydot, gpointer f_data); @@ -1204,8 +1628,8 @@ _ncm_csq1d_f (realtype t, N_Vector y, N_Vector ydot, gpointer f_data) const gdouble alpha = NV_Ith_S (y, 0); const gdouble dgamma = NV_Ith_S (y, 1); - const gdouble nu = ncm_csq1d_eval_nu (ws->csq1d, ws->model, t, self->k); - const gdouble F1 = ncm_csq1d_eval_F1 (ws->csq1d, ws->model, t, self->k); + const gdouble nu = ncm_csq1d_eval_nu (ws->csq1d, ws->model, t); + const gdouble F1 = ncm_csq1d_eval_F1 (ws->csq1d, ws->model, t); const gdouble twonu = 2.0 * nu; NV_Ith_S (ydot, 0) = -twonu *sinh (dgamma); @@ -1224,8 +1648,8 @@ _ncm_csq1d_f_Up (realtype t, N_Vector y_Up, N_Vector ydot, gpointer f_data) const gdouble chi = NV_Ith_S (y_Up, 0); const gdouble Up = NV_Ith_S (y_Up, 1); - const gdouble m = ncm_csq1d_eval_m (ws->csq1d, ws->model, t, self->k); - const gdouble nu2 = ncm_csq1d_eval_nu2 (ws->csq1d, ws->model, t, self->k); + const gdouble m = ncm_csq1d_eval_m (ws->csq1d, ws->model, t); + const gdouble nu2 = ncm_csq1d_eval_nu2 (ws->csq1d, ws->model, t); const gdouble exp_Up = exp (Up); const gdouble ch2_alpha = 1.0 + chi * chi; @@ -1244,8 +1668,8 @@ _ncm_csq1d_f_Um (realtype t, N_Vector y, N_Vector ydot, gpointer f_data) const gdouble chi = NV_Ith_S (y, 0); const gdouble Um = NV_Ith_S (y, 1); - const gdouble m = ncm_csq1d_eval_m (ws->csq1d, ws->model, t, self->k); - const gdouble nu2 = ncm_csq1d_eval_nu2 (ws->csq1d, ws->model, t, self->k); + const gdouble m = ncm_csq1d_eval_m (ws->csq1d, ws->model, t); + const gdouble nu2 = ncm_csq1d_eval_nu2 (ws->csq1d, ws->model, t); const gdouble exp_Um = exp (Um); const gdouble ch2_alpha = 1.0 + chi * chi; @@ -1264,7 +1688,7 @@ _ncm_csq1d_J (realtype t, N_Vector y, N_Vector fy, SUNMatrix J, gpointer jac_dat const gdouble alpha = NV_Ith_S (y, 0); const gdouble dgamma = NV_Ith_S (y, 1); - const gdouble nu = ncm_csq1d_eval_nu (ws->csq1d, ws->model, t, self->k); + const gdouble nu = ncm_csq1d_eval_nu (ws->csq1d, ws->model, t); const gdouble twonu = 2.0 * nu; /* - twonu * sinh (dgamma); */ @@ -1288,8 +1712,8 @@ _ncm_csq1d_J_Up (realtype t, N_Vector y_Up, N_Vector fy, SUNMatrix J, gpointer j const gdouble chi = NV_Ith_S (y_Up, 0); const gdouble Up = NV_Ith_S (y_Up, 1); - const gdouble nu2 = ncm_csq1d_eval_nu2 (ws->csq1d, ws->model, t, self->k); - const gdouble m = ncm_csq1d_eval_m (ws->csq1d, ws->model, t, self->k); + const gdouble nu2 = ncm_csq1d_eval_nu2 (ws->csq1d, ws->model, t); + const gdouble m = ncm_csq1d_eval_m (ws->csq1d, ws->model, t); const gdouble exp_Up = exp (Up); const gdouble ch2_alpha = 1.0 + chi * chi; @@ -1313,8 +1737,8 @@ _ncm_csq1d_J_Um (realtype t, N_Vector y, N_Vector fy, SUNMatrix J, gpointer jac_ const gdouble chi = NV_Ith_S (y, 0); const gdouble Um = NV_Ith_S (y, 1); - const gdouble m = ncm_csq1d_eval_m (ws->csq1d, ws->model, t, self->k); - const gdouble nu2 = ncm_csq1d_eval_nu2 (ws->csq1d, ws->model, t, self->k); + const gdouble m = ncm_csq1d_eval_m (ws->csq1d, ws->model, t); + const gdouble nu2 = ncm_csq1d_eval_nu2 (ws->csq1d, ws->model, t); const gdouble exp_Um = exp (Um); const gdouble ch2_alpha = 1.0 + chi * chi; @@ -1334,25 +1758,14 @@ _ncm_csq1d_J_Um (realtype t, N_Vector y, N_Vector fy, SUNMatrix J, gpointer jac_ * @csq1d: a #NcmCSQ1D * @model: (allow-none): a #NcmModel * @t: time $t$ - * @k: mode $k$ * * Returns: $\xi$ */ -/** - * ncm_csq1d_eval_dxi: (virtual eval_dxi) - * @csq1d: a #NcmCSQ1D - * @model: (allow-none): a #NcmModel - * @t: time $t$ - * @k: mode $k$ - * - * Returns: $\mathrm{d}\xi/\mathrm{d}t$ - */ /** * ncm_csq1d_eval_nu: (virtual eval_nu) * @csq1d: a #NcmCSQ1D * @model: (allow-none): a #NcmModel * @t: time $t$ - * @k: mode $k$ * * Returns: $\nu$ */ @@ -1361,7 +1774,6 @@ _ncm_csq1d_J_Um (realtype t, N_Vector y, N_Vector fy, SUNMatrix J, gpointer jac_ * @csq1d: a #NcmCSQ1D * @model: (allow-none): a #NcmModel * @t: time $t$ - * @k: mode $k$ * * Returns: $\nu^2$ */ @@ -1370,7 +1782,6 @@ _ncm_csq1d_J_Um (realtype t, N_Vector y, N_Vector fy, SUNMatrix J, gpointer jac_ * @csq1d: a #NcmCSQ1D * @model: (allow-none): a #NcmModel * @t: time $t$ - * @k: mode $k$ * * Returns: $m$ */ @@ -1379,7 +1790,6 @@ _ncm_csq1d_J_Um (realtype t, N_Vector y, N_Vector fy, SUNMatrix J, gpointer jac_ * @csq1d: a #NcmCSQ1D * @model: (allow-none): a #NcmModel * @t: time $t$ - * @k: mode $k$ * * Returns: $\int 1/m \mathrm{d}t$. */ @@ -1388,7 +1798,6 @@ _ncm_csq1d_J_Um (realtype t, N_Vector y, N_Vector fy, SUNMatrix J, gpointer jac_ * @csq1d: a #NcmCSQ1D * @model: (allow-none): a #NcmModel * @t: time $t$ - * @k: mode $k$ * * Returns: $\int m\nu^2 \mathrm{d}t$. */ @@ -1397,7 +1806,6 @@ _ncm_csq1d_J_Um (realtype t, N_Vector y, N_Vector fy, SUNMatrix J, gpointer jac_ * @csq1d: a #NcmCSQ1D * @model: (allow-none): a #NcmModel * @t: time $t$ - * @k: mode $k$ * * Returns: $\int \left(\int 1/m \mathrm{d}t\right) m\nu^2 \mathrm{d}t$. */ @@ -1406,25 +1814,14 @@ _ncm_csq1d_J_Um (realtype t, N_Vector y, N_Vector fy, SUNMatrix J, gpointer jac_ * @csq1d: a #NcmCSQ1D * @model: (allow-none): a #NcmModel * @t: time $t$ - * @k: mode $k$ * * Returns: $\int \left(\int 1/m \mathrm{d}t\right)^2 m\nu^2 \mathrm{d}t$. */ -/** - * ncm_csq1d_eval_dm: (virtual eval_dm) - * @csq1d: a #NcmCSQ1D - * @model: (allow-none): a #NcmModel - * @t: time $t$ - * @k: mode $k$ - * - * Returns: $\mathrm{d}m/\mathrm{d}t$ - */ /** * ncm_csq1d_eval_F1: (virtual eval_F1) * @csq1d: a #NcmCSQ1D * @model: (allow-none): a #NcmModel * @t: time $t$ - * @k: mode $k$ * * Returns: $F_1$ */ @@ -1433,31 +1830,12 @@ _ncm_csq1d_J_Um (realtype t, N_Vector y, N_Vector fy, SUNMatrix J, gpointer jac_ * @csq1d: a #NcmCSQ1D * @model: (allow-none): a #NcmModel * @t: time $t$ - * @k: mode $k$ * * Returns: $F_2$ */ -/** - * ncm_csq1d_eval_FN: (virtual eval_FN) - * @csq1d: a #NcmCSQ1D - * @model: (allow-none): a #NcmModel - * @n: order $n$ - * @t: time $t$ - * @k: mode $k$ - * - * Returns: $F_n$ - */ -/** - * ncm_csq1d_eval_powspec_factor: (virtual eval_powspec_factor) - * @csq1d: a #NcmCSQ1D - * @model: (allow-none): a #NcmModel - * @k: mode $k$ - * - * Returns: $F_n$ - */ static NcmCSQ1DEvolStop -_ncm_csq1d_evol_adiabatic (NcmCSQ1D *csq1d, NcmModel *model, GArray *asinh_t_a, GArray *alpha_a, GArray *dgamma_a) +_ncm_csq1d_evol_adiabatic (NcmCSQ1D *csq1d, NcmModel *model, GArray *asinh_t_a, GArray *alpha_a, GArray *dgamma_a, GArray *gamma_a) { NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); NcmCSQ1DEvolStop reason = NCM_CSQ1D_EVOL_STOP_ERROR; @@ -1484,7 +1862,7 @@ _ncm_csq1d_evol_adiabatic (NcmCSQ1D *csq1d, NcmModel *model, GArray *asinh_t_a, if (PRINT_EVOL) { - const gdouble xi = ncm_csq1d_eval_xi (csq1d, model, self->t, self->k); + const gdouble xi = ncm_csq1d_eval_xi (csq1d, model, self->t); const gdouble gamma = dgamma + xi; const gdouble chi = sinh (alpha); const gdouble lnch_alpha = gsl_sf_lncosh (alpha); @@ -1498,9 +1876,13 @@ _ncm_csq1d_evol_adiabatic (NcmCSQ1D *csq1d, NcmModel *model, GArray *asinh_t_a, if ((fabs ((asinh_t - last_asinh_t) / last_asinh_t) > 1.0e-5) || is_finished) { + const gdouble xi = ncm_csq1d_eval_xi (csq1d, model, self->t); + const gdouble gamma = dgamma + xi; + g_array_append_val (asinh_t_a, asinh_t); g_array_append_val (alpha_a, alpha); g_array_append_val (dgamma_a, dgamma); + g_array_append_val (gamma_a, gamma); last_asinh_t = asinh_t; } @@ -1510,7 +1892,7 @@ _ncm_csq1d_evol_adiabatic (NcmCSQ1D *csq1d, NcmModel *model, GArray *asinh_t_a, break; } - if ((fabs (dgamma) > self->adiab_threshold) || (fabs (alpha) > self->adiab_threshold)) + if ((fabs (dgamma) > self->adiab_threshold) && (fabs (alpha) > self->adiab_threshold)) { if (dgamma > 0.0) reason = NCM_CSQ1D_EVOL_STOP_UP_START; @@ -1525,14 +1907,11 @@ _ncm_csq1d_evol_adiabatic (NcmCSQ1D *csq1d, NcmModel *model, GArray *asinh_t_a, } static NcmCSQ1DEvolStop -_ncm_csq1d_evol_Up (NcmCSQ1D *csq1d, NcmCSQ1DWS *ws, NcmModel *model, GArray *asinh_t_a, GArray *alpha_a, GArray *dgamma_a) +_ncm_csq1d_evol_Up (NcmCSQ1D *csq1d, NcmCSQ1DWS *ws, NcmModel *model, GArray *asinh_t_a, GArray *alpha_a, GArray *dgamma_a, GArray *gamma_a) { NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); NcmCSQ1DEvolStop reason = NCM_CSQ1D_EVOL_STOP_ERROR; gdouble last_asinh_t = asinh (self->t); - GArray *t_a = g_array_new (FALSE, FALSE, sizeof (gdouble)); - GArray *exp_Up_a = g_array_new (FALSE, FALSE, sizeof (gdouble)); - GArray *chim_t_a = g_array_new (FALSE, FALSE, sizeof (gdouble)); gint flag; g_assert (self->state == NCM_CSQ1D_EVOL_STATE_UP); @@ -1550,8 +1929,8 @@ _ncm_csq1d_evol_Up (NcmCSQ1D *csq1d, NcmCSQ1DWS *ws, NcmModel *model, GArray *as NCM_CVODE_CHECK (&flag, "CVode[_ncm_csq1d_evol_Up]", 1, NCM_CSQ1D_EVOL_STOP_ERROR); asinh_t = asinh (self->t); - xi = ncm_csq1d_eval_xi (csq1d, model, self->t, self->k); - m = ncm_csq1d_eval_m (csq1d, model, self->t, self->k); + xi = ncm_csq1d_eval_xi (csq1d, model, self->t); + m = ncm_csq1d_eval_m (csq1d, model, self->t); chi = NV_Ith_S (self->y_Up, 0); Up = NV_Ith_S (self->y_Up, 1); chim = m * chi; @@ -1576,13 +1955,10 @@ _ncm_csq1d_evol_Up (NcmCSQ1D *csq1d, NcmCSQ1DWS *ws, NcmModel *model, GArray *as g_array_append_val (asinh_t_a, asinh_t); g_array_append_val (alpha_a, alpha); g_array_append_val (dgamma_a, dgamma); + g_array_append_val (gamma_a, gamma); last_asinh_t = asinh_t; } - g_array_append_val (t_a, self->t); - g_array_append_val (exp_Up_a, exp_Up); - g_array_append_val (chim_t_a, chim_t); - if (is_finished) { reason = NCM_CSQ1D_EVOL_STOP_FINISHED; @@ -1602,15 +1978,11 @@ _ncm_csq1d_evol_Up (NcmCSQ1D *csq1d, NcmCSQ1DWS *ws, NcmModel *model, GArray *as } } - g_array_unref (t_a); - g_array_unref (exp_Up_a); - g_array_unref (chim_t_a); - return reason; } static NcmCSQ1DEvolStop -_ncm_csq1d_evol_Um (NcmCSQ1D *csq1d, NcmModel *model, GArray *asinh_t_a, GArray *alpha_a, GArray *dgamma_a) +_ncm_csq1d_evol_Um (NcmCSQ1D *csq1d, NcmModel *model, GArray *asinh_t_a, GArray *alpha_a, GArray *dgamma_a, GArray *gamma_a) { NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); NcmCSQ1DEvolStop reason = NCM_CSQ1D_EVOL_STOP_ERROR; @@ -1632,7 +2004,7 @@ _ncm_csq1d_evol_Um (NcmCSQ1D *csq1d, NcmModel *model, GArray *asinh_t_a, GArray NCM_CVODE_CHECK (&flag, "CVode[_ncm_csq1d_evol_Um]", 1, NCM_CSQ1D_EVOL_STOP_ERROR); asinh_t = asinh (self->t); - xi = ncm_csq1d_eval_xi (csq1d, model, self->t, self->k); + xi = ncm_csq1d_eval_xi (csq1d, model, self->t); chi = NV_Ith_S (self->y_Um, 0); Um = NV_Ith_S (self->y_Um, 1); gamma = -Um + 0.5 * log1p (chi * chi); @@ -1654,6 +2026,7 @@ _ncm_csq1d_evol_Um (NcmCSQ1D *csq1d, NcmModel *model, GArray *asinh_t_a, GArray g_array_append_val (asinh_t_a, asinh_t); g_array_append_val (alpha_a, alpha); g_array_append_val (dgamma_a, dgamma); + g_array_append_val (gamma_a, gamma); last_asinh_t = asinh_t; } @@ -1680,7 +2053,7 @@ _ncm_csq1d_evol_Um (NcmCSQ1D *csq1d, NcmModel *model, GArray *asinh_t_a, GArray } static void -_ncm_csq1d_evol_save (NcmCSQ1D *csq1d, NcmModel *model, NcmCSQ1DWS *ws, GArray *asinh_t_a, GArray *alpha_a, GArray *dgamma_a) +_ncm_csq1d_evol_save (NcmCSQ1D *csq1d, NcmModel *model, NcmCSQ1DWS *ws, GArray *asinh_t_a, GArray *alpha_a, GArray *dgamma_a, GArray *gamma_a) { NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); NcmCSQ1DEvolStop stop; @@ -1693,19 +2066,19 @@ _ncm_csq1d_evol_save (NcmCSQ1D *csq1d, NcmModel *model, NcmCSQ1DWS *ws, GArray * case NCM_CSQ1D_EVOL_STATE_ADIABATIC: { _ncm_csq1d_prepare_integrator (csq1d, ws); - stop = _ncm_csq1d_evol_adiabatic (csq1d, model, asinh_t_a, alpha_a, dgamma_a); + stop = _ncm_csq1d_evol_adiabatic (csq1d, model, asinh_t_a, alpha_a, dgamma_a, gamma_a); break; } case NCM_CSQ1D_EVOL_STATE_UP: { _ncm_csq1d_prepare_integrator_Up (csq1d, ws); - stop = _ncm_csq1d_evol_Up (csq1d, ws, model, asinh_t_a, alpha_a, dgamma_a); + stop = _ncm_csq1d_evol_Up (csq1d, ws, model, asinh_t_a, alpha_a, dgamma_a, gamma_a); break; } case NCM_CSQ1D_EVOL_STATE_UM: { _ncm_csq1d_prepare_integrator_Um (csq1d, ws); - stop = _ncm_csq1d_evol_Um (csq1d, model, asinh_t_a, alpha_a, dgamma_a); + stop = _ncm_csq1d_evol_Um (csq1d, model, asinh_t_a, alpha_a, dgamma_a, gamma_a); break; } default: @@ -1723,7 +2096,7 @@ _ncm_csq1d_evol_save (NcmCSQ1D *csq1d, NcmModel *model, NcmCSQ1DWS *ws, GArray * { const gdouble alpha = NV_Ith_S (self->y, 0); const gdouble dgamma = NV_Ith_S (self->y, 1); - const gdouble xi = ncm_csq1d_eval_xi (csq1d, model, self->t, self->k); + const gdouble xi = ncm_csq1d_eval_xi (csq1d, model, self->t); const gdouble gamma = xi + dgamma; const gdouble Up = +gamma + gsl_sf_lncosh (alpha); @@ -1747,7 +2120,7 @@ _ncm_csq1d_evol_save (NcmCSQ1D *csq1d, NcmModel *model, NcmCSQ1DWS *ws, GArray * } self->state = NCM_CSQ1D_EVOL_STATE_UP; - _ncm_csq1d_evol_save (csq1d, model, ws, asinh_t_a, alpha_a, dgamma_a); + _ncm_csq1d_evol_save (csq1d, model, ws, asinh_t_a, alpha_a, dgamma_a, gamma_a); break; } case NCM_CSQ1D_EVOL_STOP_UM_START: @@ -1758,7 +2131,7 @@ _ncm_csq1d_evol_save (NcmCSQ1D *csq1d, NcmModel *model, NcmCSQ1DWS *ws, GArray * { const gdouble alpha = NV_Ith_S (self->y, 0); const gdouble dgamma = NV_Ith_S (self->y, 1); - const gdouble xi = ncm_csq1d_eval_xi (csq1d, model, self->t, self->k); + const gdouble xi = ncm_csq1d_eval_xi (csq1d, model, self->t); const gdouble gamma = xi + dgamma; const gdouble Um = -gamma + gsl_sf_lncosh (alpha); @@ -1782,7 +2155,7 @@ _ncm_csq1d_evol_save (NcmCSQ1D *csq1d, NcmModel *model, NcmCSQ1DWS *ws, GArray * } self->state = NCM_CSQ1D_EVOL_STATE_UM; - _ncm_csq1d_evol_save (csq1d, model, ws, asinh_t_a, alpha_a, dgamma_a); + _ncm_csq1d_evol_save (csq1d, model, ws, asinh_t_a, alpha_a, dgamma_a, gamma_a); break; } case NCM_CSQ1D_EVOL_STOP_ADIABATIC_START: @@ -1793,7 +2166,7 @@ _ncm_csq1d_evol_save (NcmCSQ1D *csq1d, NcmModel *model, NcmCSQ1DWS *ws, GArray * { const gdouble chi = NV_Ith_S (self->y_Up, 0); const gdouble Up = NV_Ith_S (self->y_Up, 1); - const gdouble xi = ncm_csq1d_eval_xi (csq1d, model, self->t, self->k); + const gdouble xi = ncm_csq1d_eval_xi (csq1d, model, self->t); const gdouble gamma = Up - 0.5 * log1p (chi * chi); const gdouble dgamma = gamma - xi; @@ -1805,7 +2178,7 @@ _ncm_csq1d_evol_save (NcmCSQ1D *csq1d, NcmModel *model, NcmCSQ1DWS *ws, GArray * { const gdouble chi = NV_Ith_S (self->y_Um, 0); const gdouble Um = NV_Ith_S (self->y_Um, 1); - const gdouble xi = ncm_csq1d_eval_xi (csq1d, model, self->t, self->k); + const gdouble xi = ncm_csq1d_eval_xi (csq1d, model, self->t); const gdouble gamma = -Um + 0.5 * log1p (chi * chi); const gdouble dgamma = gamma - xi; @@ -1819,7 +2192,7 @@ _ncm_csq1d_evol_save (NcmCSQ1D *csq1d, NcmModel *model, NcmCSQ1DWS *ws, GArray * } self->state = NCM_CSQ1D_EVOL_STATE_ADIABATIC; - _ncm_csq1d_evol_save (csq1d, model, ws, asinh_t_a, alpha_a, dgamma_a); + _ncm_csq1d_evol_save (csq1d, model, ws, asinh_t_a, alpha_a, dgamma_a, gamma_a); break; } case NCM_CSQ1D_EVOL_STOP_FINISHED: @@ -1832,16 +2205,8 @@ _ncm_csq1d_evol_save (NcmCSQ1D *csq1d, NcmModel *model, NcmCSQ1DWS *ws, GArray * } } -/** - * ncm_csq1d_prepare: (virtual prepare) - * @csq1d: a #NcmCSQ1D - * @model: (allow-none): a #NcmModel - * - * Prepares the object using @model. - * - */ -void -ncm_csq1d_prepare (NcmCSQ1D *csq1d, NcmModel *model) +static void +_ncm_csq1d_prepare_splines (NcmCSQ1D *csq1d, NcmModel *model) { NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); NcmCSQ1DWS ws = {csq1d, model, 0.0, 0.0}; @@ -1857,15 +2222,18 @@ ncm_csq1d_prepare (NcmCSQ1D *csq1d, NcmModel *model) GArray *asinh_t_a = g_array_sized_new (FALSE, FALSE, sizeof (gdouble), 1000); GArray *alpha_a = g_array_sized_new (FALSE, FALSE, sizeof (gdouble), 1000); GArray *dgamma_a = g_array_sized_new (FALSE, FALSE, sizeof (gdouble), 1000); + GArray *gamma_a = g_array_sized_new (FALSE, FALSE, sizeof (gdouble), 1000); - _ncm_csq1d_evol_save (csq1d, model, &ws, asinh_t_a, alpha_a, dgamma_a); + _ncm_csq1d_evol_save (csq1d, model, &ws, asinh_t_a, alpha_a, dgamma_a, gamma_a); ncm_spline_set_array (self->alpha_s, asinh_t_a, alpha_a, TRUE); ncm_spline_set_array (self->dgamma_s, asinh_t_a, dgamma_a, TRUE); + ncm_spline_set_array (self->gamma_s, asinh_t_a, gamma_a, TRUE); g_array_unref (asinh_t_a); g_array_unref (alpha_a); g_array_unref (dgamma_a); + g_array_unref (gamma_a); } else { @@ -1873,6 +2241,83 @@ ncm_csq1d_prepare (NcmCSQ1D *csq1d, NcmModel *model) } } +static gboolean +_ncm_csq1d_prepare_adiab (NcmCSQ1D *csq1d, NcmModel *model) +{ + NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); + + if (!ncm_csq1d_find_adiab_time_limit (csq1d, model, self->ti, self->vacuum_max_time, self->vacuum_reltol, &self->vacuum_final_time)) + { + return FALSE; + } + else + { + NcmCSQ1DState state; + gdouble zeta_k_tau, alpha_reltol, dgamma_reltol; + + /* If the final time is greater than the vacuum time, we need to compute the numerical solution + * from the vacuum time to the final time. Otherwise, we just need to compute the adiabatic + * solution from the initial time to the final time. + */ + if (self->tf > self->vacuum_final_time) + { + ncm_csq1d_compute_adiab (csq1d, model, self->vacuum_final_time, &state, &alpha_reltol, &dgamma_reltol); + ncm_csq1d_set_init_cond_adiab (csq1d, model, self->vacuum_final_time); + _ncm_csq1d_prepare_splines (csq1d, model); + } + } + + return TRUE; +} + +/** + * ncm_csq1d_prepare: (virtual prepare) + * @csq1d: a #NcmCSQ1D + * @model: (allow-none): a #NcmModel + * + * Prepares the object using @model. It integrates the system from the initial time to + * the final time. If the #NcmCSQ1DInitialStateType is set to + * #NCM_CSQ1D_INITIAL_CONDITION_TYPE_AD_HOC, the initial conditions must be set using + * ncm_csq1d_set_init_cond(). Otherwise, the initial conditions are automatically set + * using the chosen method. See ncm_csq1d_set_initial_condition_type(). + * + * The initial conditions based on the vacuum are controlled by the parameters + * ncm_csq1d_set_vacuum_reltol() and ncm_csq1d_set_vacuum_max_time(). + * + */ +void +ncm_csq1d_prepare (NcmCSQ1D *csq1d, NcmModel *model) +{ + NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); + gboolean success = FALSE; + + switch (self->initial_condition_type) + { + case NCM_CSQ1D_INITIAL_CONDITION_TYPE_AD_HOC: + + if (!self->init_cond_set) + g_error ("ncm_csq1d_prepare: initial conditions must be set " + "using ncm_csq1d_set_init_cond()."); + + _ncm_csq1d_prepare_splines (csq1d, model); + break; + case NCM_CSQ1D_INITIAL_CONDITION_TYPE_ADIABATIC2: + case NCM_CSQ1D_INITIAL_CONDITION_TYPE_ADIABATIC4: + success = _ncm_csq1d_prepare_adiab (csq1d, model); + + if (!success) + g_error ("ncm_csq1d_prepare: could not find adiabatic time limit."); + + break; + case NCM_CSQ1D_INITIAL_CONDITION_TYPE_NONADIABATIC2: + g_error ("ncm_csq1d_prepare: not implemented."); + break; + default: + g_error ("ncm_csq1d_prepare: invalid initial condition type."); + break; + } +} + /** * ncm_csq1d_get_time_array: * @csq1d: a #NcmCSQ1D @@ -1935,7 +2380,9 @@ _ncm_csq1d_find_adiab_time_limit_f (gdouble t, gpointer params) * @ti: (out): adiabatic time limit $t_i$ * * Computes the time upper limit $t_i \in [t_0, t_1]$ where the adiabatic - * approximation is satisfied up to @reltol. + * approximation is satisfied up to @reltol. If both times are adiabatic, the + * time closer to the adiabatic limit is chosen. If both times are non-adiabatic, + * the function returns %FALSE. * * Returns: whether the time limit was found. */ @@ -1965,15 +2412,29 @@ ncm_csq1d_find_adiab_time_limit (NcmCSQ1D *csq1d, NcmModel *model, gdouble t0, g adiab0 = ((fabs (alpha_reltol0) < reltol) && (fabs (dgamma_reltol0) < reltol)); adiab1 = ((fabs (alpha_reltol1) < reltol) && (fabs (dgamma_reltol1) < reltol)); - if ((adiab0 && adiab1) || (!adiab0 && !adiab1)) + if (!adiab0 && !adiab1) /* Both times are non-adiabatic */ { if (PRINT_EVOL) - g_warning ("# Impossible to find the adiabatic limit: \n\tt0 % 22.15g % 22.15g % 22.15g % 22.15g % 22.15g\n\tt1 % 22.15g % 22.15g % 22.15g % 22.15g % 22.15g\n", + g_warning ("# Impossible to find the adiabatic limit: \n" + "\tt0 % 22.15g % 22.15g % 22.15g % 22.15g % 22.15g\n" + "\tt1 % 22.15g % 22.15g % 22.15g % 22.15g % 22.15g\n", t0, alpha0, alpha_reltol0, dgamma0, dgamma_reltol0, t1, alpha1, alpha_reltol1, dgamma1, dgamma_reltol1); return FALSE; } + else if (adiab0 && adiab1) /* Both times are adiabatic, below reltol */ + { + if (PRINT_EVOL) + printf ("# Both times are adiabatic: \n" + "\tt0 % 22.15g % 22.15g % 22.15g % 22.15g % 22.15g\n" + "\tt1 % 22.15g % 22.15g % 22.15g % 22.15g % 22.15g\n", + t0, alpha0, alpha_reltol0, dgamma0, dgamma_reltol0, + t1, alpha1, alpha_reltol1, dgamma1, dgamma_reltol1); + + /* We choose the time that is closer to the adiabatic limit */ + ti[0] = t1; + } else { NcmCSQ1DWS ws = {csq1d, model, reltol, 0.0}; @@ -2019,7 +2480,7 @@ _ncm_csq1d_F1_func (const gdouble t, gpointer user_data) { NcmCSQ1DWS *ws = (NcmCSQ1DWS *) user_data; NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (ws->csq1d); - const gdouble F1 = ncm_csq1d_eval_F1 (ws->csq1d, ws->model, t, self->k); + const gdouble F1 = ncm_csq1d_eval_F1 (ws->csq1d, ws->model, t); return F1; } @@ -2029,7 +2490,7 @@ _ncm_csq1d_F2_func (const gdouble t, gpointer user_data) { NcmCSQ1DWS *ws = (NcmCSQ1DWS *) user_data; NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (ws->csq1d); - const gdouble F2 = ncm_csq1d_eval_F2 (ws->csq1d, ws->model, t, self->k); + const gdouble F2 = ncm_csq1d_eval_F2 (ws->csq1d, ws->model, t); return F2; } @@ -2039,7 +2500,7 @@ _ncm_csq1d_lnnu_func (const gdouble t, gpointer user_data) { NcmCSQ1DWS *ws = (NcmCSQ1DWS *) user_data; NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (ws->csq1d); - const gdouble nu = ncm_csq1d_eval_nu (ws->csq1d, ws->model, t, self->k); + const gdouble nu = ncm_csq1d_eval_nu (ws->csq1d, ws->model, t); return log (nu); } @@ -2076,6 +2537,7 @@ ncm_csq1d_find_adiab_max (NcmCSQ1D *csq1d, NcmModel *model, gdouble t0, gdouble gdouble atm = (at0 + at1) * 0.5; const guint linsearch = 100; guint iter = 0; + gdouble abs_sum = 0.0; gint status; gsl_function F; gint ret; @@ -2092,6 +2554,8 @@ ncm_csq1d_find_adiab_max (NcmCSQ1D *csq1d, NcmModel *model, gdouble t0, gdouble const gdouble at = at0 + (at1 - at0) * i / (linsearch - 1); const gdouble test0 = GSL_FN_EVAL (&F, at); + abs_sum += test0; + if (test0 < test) { test = test0; @@ -2100,6 +2564,15 @@ ncm_csq1d_find_adiab_max (NcmCSQ1D *csq1d, NcmModel *model, gdouble t0, gdouble } } + if (abs_sum == 0.0) + { + F1_min[0] = 0.0; + t_Bl[0] = t0; + t_Bu[0] = t1; + + return t1; + } + /* Testing for minimum on the edge */ if (ncm_cmp (atm, atl, 1.0e-15, 0.0) == 0) { @@ -2137,7 +2610,7 @@ ncm_csq1d_find_adiab_max (NcmCSQ1D *csq1d, NcmModel *model, gdouble t0, gdouble } gsl_min_fminimizer_free (fmin); - ws.F1_min = ncm_csq1d_eval_F1 (csq1d, model, sinh (atm), self->k); + ws.F1_min = ncm_csq1d_eval_F1 (csq1d, model, sinh (atm)); { const gsl_root_fsolver_type *T; @@ -2184,7 +2657,7 @@ ncm_csq1d_find_adiab_max (NcmCSQ1D *csq1d, NcmModel *model, gdouble t0, gdouble { const gdouble tm = sinh (atm); - F1_min[0] = ncm_csq1d_eval_F1 (csq1d, model, tm, self->k); + F1_min[0] = ncm_csq1d_eval_F1 (csq1d, model, tm); t_Bl[0] = sinh (t_Bl[0]); t_Bu[0] = sinh (t_Bu[0]); @@ -2197,7 +2670,7 @@ _ncm_csq1d_abs_F1_asinht (gdouble at, gpointer user_data) { NcmCSQ1DWS *ws = (NcmCSQ1DWS *) user_data; NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (ws->csq1d); - const gdouble F1 = ncm_csq1d_eval_F1 (ws->csq1d, ws->model, sinh (at), self->k); + const gdouble F1 = ncm_csq1d_eval_F1 (ws->csq1d, ws->model, sinh (at)); return fabs (F1); } @@ -2207,34 +2680,40 @@ _ncm_csq1d_ln_abs_F1_eps_asinht (gdouble at, gpointer user_data) { NcmCSQ1DWS *ws = (NcmCSQ1DWS *) user_data; NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (ws->csq1d); - const gdouble F1 = ncm_csq1d_eval_F1 (ws->csq1d, ws->model, sinh (at), self->k); + const gdouble F1 = ncm_csq1d_eval_F1 (ws->csq1d, ws->model, sinh (at)); return fabs ((F1 - ws->F1_min) / ws->reltol) - 1.0; } -/** - * ncm_csq1d_eval_adiab_at: - * @csq1d: a #NcmCSQ1D - * @model: (allow-none): a #NcmModel - * @t: time $t$ - * @alpha: (out): value of $\alpha(t)$ - * @dgamma: (out): value of $\Delta\gamma(t)$ - * @alpha_reltol: (out) (allow-none): estimated error on $\alpha(t)$ - * @dgamma_reltol: (out) (allow-none): estimated error on $\Delta\gamma(t)$ - * - * Computes the value of the adiabatic approximation of the variables $\alpha$ and $\Delta\gamma$ at $t$. - * - */ -void -ncm_csq1d_eval_adiab_at (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, gdouble *alpha, gdouble *dgamma, gdouble *alpha_reltol, gdouble *dgamma_reltol) +static void +_ncm_csq1d_compute_adiab2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, NcmCSQ1DState *state, gdouble *alpha_reltol, gdouble *dgamma_reltol) +{ + NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); + const gdouble F1 = ncm_csq1d_eval_F1 (csq1d, model, t); + const gdouble F2 = ncm_csq1d_eval_F2 (csq1d, model, t); + + state->frame = NCM_CSQ1D_FRAME_ADIAB1; + state->t = t; + state->alpha = +F1; + state->gamma = -F2; + + if (alpha_reltol != NULL) + alpha_reltol[0] = fabs (F1); + + if (dgamma_reltol != NULL) + dgamma_reltol[0] = fabs (F2); +} + +static void +_ncm_csq1d_compute_adiab4 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, NcmCSQ1DState *state, gdouble *alpha_reltol, gdouble *dgamma_reltol) { NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); NcmCSQ1DWS ws = {csq1d, model, 0.0, 0.0}; - const gdouble F1 = ncm_csq1d_eval_F1 (csq1d, model, t, self->k); - const gdouble F2 = ncm_csq1d_eval_F2 (csq1d, model, t, self->k); + const gdouble F1 = ncm_csq1d_eval_F1 (csq1d, model, t); + const gdouble F2 = ncm_csq1d_eval_F2 (csq1d, model, t); const gdouble F1_2 = F1 * F1; const gdouble F1_3 = F1_2 * F1; - const gdouble nu = ncm_csq1d_eval_nu (csq1d, model, t, self->k); + const gdouble nu = ncm_csq1d_eval_nu (csq1d, model, t); const gdouble twonu = 2.0 * nu; gdouble err, F3, d2F2, dlnnu, F4, alpha_reltol0, dgamma_reltol0; @@ -2243,14 +2722,10 @@ ncm_csq1d_eval_adiab_at (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, gdou dlnnu = ncm_diff_rc_d1_1_to_1 (self->diff, t, &_ncm_csq1d_lnnu_func, &ws, &err); F4 = d2F2 / gsl_pow_2 (twonu) - dlnnu * F3 / twonu; - if (self->max_order_2) - { - alpha_reltol0 = fabs (F1); - dgamma_reltol0 = fabs (F2); - alpha[0] = +F1; - dgamma[0] = -F2; - } - else if ((fabs (F3) > fabs (F2)) || (fabs (F4) > fabs (F3))) + state->frame = NCM_CSQ1D_FRAME_ADIAB1; + state->t = t; + + if ((fabs (F3) > fabs (F2)) || (fabs (F4) > fabs (F3))) { g_warning ("WKB series with |F3| > |F2| or |F4| > |F3|, " "|F3/F2| = % 22.15g and |F4/F3| = % 22.15g " @@ -2259,8 +2734,8 @@ ncm_csq1d_eval_adiab_at (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, gdou alpha_reltol0 = fabs (F1); dgamma_reltol0 = fabs (F2); - alpha[0] = +F1; - dgamma[0] = -F2; + state->alpha = +F1; + state->gamma = -F2; } else if ((F1 == 0.0) || (F2 == 0.0)) { @@ -2269,15 +2744,15 @@ ncm_csq1d_eval_adiab_at (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, gdou alpha_reltol0 = 0.0; dgamma_reltol0 = 0.0; - alpha[0] = F1; - dgamma[0] = -F2; + state->alpha = +F1; + state->gamma = -F2; } else { alpha_reltol0 = gsl_pow_2 ((F1_3 / 3.0 - F3) / F1); dgamma_reltol0 = gsl_pow_2 ((F4 - F1_2 * F2) / F2); - alpha[0] = +F1 + F1_3 / 3.0 - F3; - dgamma[0] = -(1.0 + F1_2) * F2 + F4; + state->alpha = +F1 + F1_3 / 3.0 - F3; + state->gamma = -(1.0 + F1_2) * F2 + F4; } if (alpha_reltol != NULL) @@ -2288,203 +2763,288 @@ ncm_csq1d_eval_adiab_at (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, gdou } static void -_ncm_csq1d_eval_adiab_at_no_test (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, gdouble *alpha, gdouble *dgamma, gdouble *alpha_reltol, gdouble *dgamma_reltol) -{ - NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); - NcmCSQ1DWS ws = {csq1d, model, 0.0, 0.0}; - const gdouble F1 = ncm_csq1d_eval_F1 (csq1d, model, t, self->k); - const gdouble F2 = ncm_csq1d_eval_F2 (csq1d, model, t, self->k); - const gdouble F1_2 = F1 * F1; - const gdouble F1_3 = F1_2 * F1; - const gdouble nu = ncm_csq1d_eval_nu (csq1d, model, t, self->k); - const gdouble twonu = 2.0 * nu; - gdouble err, F3, d2F2, dlnnu, F4, alpha_reltol0, dgamma_reltol0; - - if (self->max_order_2) - { - alpha_reltol0 = fabs (F1); - dgamma_reltol0 = fabs (F2); - alpha[0] = +F1; - dgamma[0] = -F2; - } - else - { - F3 = ncm_diff_rc_d1_1_to_1 (self->diff, t, &_ncm_csq1d_F2_func, &ws, &err) / twonu; - d2F2 = ncm_diff_rc_d2_1_to_1 (self->diff, t, &_ncm_csq1d_F2_func, &ws, &err); - dlnnu = ncm_diff_rc_d1_1_to_1 (self->diff, t, &_ncm_csq1d_lnnu_func, &ws, &err); - F4 = d2F2 / gsl_pow_2 (twonu) - dlnnu * F3 / twonu; - - alpha_reltol0 = gsl_pow_2 ((F1_3 / 3.0 - F3) / F1); - dgamma_reltol0 = gsl_pow_2 ((F4 - F1_2 * F2) / F2); - alpha[0] = +F1 + F1_3 / 3.0 - F3; - dgamma[0] = -(1.0 + F1_2) * F2 + F4; - } - - if (alpha_reltol != NULL) - alpha_reltol[0] = alpha_reltol0; - - if (dgamma_reltol != NULL) - dgamma_reltol[0] = dgamma_reltol0; -} - -/** - * ncm_csq1d_eval_nonadiab_at: - * @csq1d: a #NcmCSQ1D - * @model: (allow-none): a #NcmModel - * @nonadiab_frame: frame - * @t: time $t$ - * @chi: (out): value of $\chi(t)$ - * @Up: (out): value of $U_+$ - * - * Computes the value of the non-adiabatic VDC order order two - * in the variables $\chi$ and $U$ at $t$. The VDC can be computed - * at different frames by choosing @nonadiab_frame. - * - */ -void -ncm_csq1d_eval_nonadiab_at (NcmCSQ1D *csq1d, NcmModel *model, guint nonadiab_frame, const gdouble t, gdouble *chi, gdouble *Up) +_ncm_csq1d_compute_adiab (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, NcmCSQ1DState *state, gdouble *alpha_reltol, gdouble *dgamma_reltol) { NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); - const gdouble q0 = ncm_csq1d_eval_int_1_m (csq1d, model, t, self->k); - const gdouble q1 = ncm_csq1d_eval_int_q2mnu2 (csq1d, model, t, self->k); - const gdouble p1 = ncm_csq1d_eval_int_qmnu2 (csq1d, model, t, self->k); - const gdouble r1 = 0.5 * ncm_csq1d_eval_int_mnu2 (csq1d, model, t, self->k); - switch (nonadiab_frame) + switch (self->initial_condition_type) { - case 0: - chi[0] = (2.0 * p1 - 1.0) * (q0 + q1) + 2.0 * r1; - Up[0] = -2.0 * p1; + case NCM_CSQ1D_INITIAL_CONDITION_TYPE_ADIABATIC2: + _ncm_csq1d_compute_adiab2 (csq1d, model, t, state, alpha_reltol, dgamma_reltol); break; - case 1: - chi[0] = +2.0 * r1; - Up[0] = -2.0 * p1; + case NCM_CSQ1D_INITIAL_CONDITION_TYPE_ADIABATIC4: + _ncm_csq1d_compute_adiab4 (csq1d, model, t, state, alpha_reltol, dgamma_reltol); break; - case 2: - chi[0] = 0.0; - Up[0] = 0.0; + default: + _ncm_csq1d_compute_adiab4 (csq1d, model, t, state, alpha_reltol, dgamma_reltol); break; } } /** - * ncm_csq1d_eval_at: + * ncm_csq1d_compute_adiab: * @csq1d: a #NcmCSQ1D + * @model: (allow-none): a #NcmModel * @t: time $t$ - * @alpha: (out): value of $\alpha(t)$ - * @dgamma: (out): value of $\Delta\gamma(t)$ + * @state: a #NcmCSQ1DState to store the result + * @alpha_reltol: (out) (allow-none): estimated error on $\alpha(t)$ + * @dgamma_reltol: (out) (allow-none): estimated error on $\Delta\gamma(t)$ * - * Computes the value of the variables $\alpha$ and $\Delta\gamma$ at $t$. + * Computes the value of the adiabatic approximation of the variables $\alpha$ and $\Delta\gamma$ at $t$. + * This method computes the adiabatic approximation using the adiabatic series up to the order 2 or 4, + * depending on the value of the property max-order-2. The result is stored in the state object in the + * frame NCM_CSQ1D_FRAME_ADIAB1. Use ncm_csq1d_change_frame() to change the frame. * + * Returns: (transfer none): the @state object with the result. */ -void -ncm_csq1d_eval_at (NcmCSQ1D *csq1d, const gdouble t, gdouble *alpha, gdouble *dgamma) +NcmCSQ1DState * +ncm_csq1d_compute_adiab (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, NcmCSQ1DState *state, gdouble *alpha_reltol, gdouble *dgamma_reltol) { - NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); - const gdouble a_t = asinh (t); + _ncm_csq1d_compute_adiab (csq1d, model, t, state, alpha_reltol, dgamma_reltol); - alpha[0] = ncm_spline_eval (self->alpha_s, a_t); - dgamma[0] = ncm_spline_eval (self->dgamma_s, a_t); + return state; } /** - * ncm_csq1d_alpha_dgamma_to_phi_Pphi: + * ncm_csq1d_compute_adiab_frame: * @csq1d: a #NcmCSQ1D * @model: (allow-none): a #NcmModel + * @frame: the frame to change * @t: time $t$ - * @alpha: value of $\alpha(t)$ - * @dgamma: value of $\Delta\gamma(t)$ - * @phi: (out caller-allocates) (array fixed-size=2): real and imaginary parts of $\phi$, i.e., $[\mathrm{Re}(\phi), \mathrm{Im}(\phi)]$ - * @Pphi: (out caller-allocates) (array fixed-size=2): real and imaginary parts of $\Pi_\phi$, i.e., $[\mathrm{Re}(\Pi_\phi), \mathrm{Im}(\Pi_\phi)]$ + * @state: a #NcmCSQ1DState to store the result + * @alpha_reltol: (out) (allow-none): estimated error on $\alpha(t)$ + * @dgamma_reltol: (out) (allow-none): estimated error on $\Delta\gamma(t)$ * - * Computes the value of the variables $\alpha$ and $\Delta\gamma$ at $t$. + * As ncm_csq1d_compute_adiab(), but changes the frame of the result to @frame. * + * Returns: (transfer none): the @state object with the result. */ -void -ncm_csq1d_alpha_dgamma_to_phi_Pphi (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble alpha, const gdouble dgamma, gdouble *phi, gdouble *Pphi) +NcmCSQ1DState * +ncm_csq1d_compute_adiab_frame (NcmCSQ1D *csq1d, NcmModel *model, const NcmCSQ1DFrame frame, const gdouble t, NcmCSQ1DState *state, gdouble *alpha_reltol, gdouble *dgamma_reltol) { - NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); - const gdouble gamma = ncm_csq1d_eval_xi (csq1d, model, t, self->k) + dgamma; - const gdouble exp_gamma_p_alpha_2 = exp (0.5 * (gamma + alpha)); - const gdouble exp_gamma_m_alpha_2 = exp (0.5 * (gamma - alpha)); - - phi[0] = +0.5 / exp_gamma_m_alpha_2; - phi[1] = -0.5 / exp_gamma_p_alpha_2; + _ncm_csq1d_compute_adiab (csq1d, model, t, state, alpha_reltol, dgamma_reltol); + ncm_csq1d_change_frame (csq1d, model, state, frame); - Pphi[0] = -0.5 * exp_gamma_p_alpha_2; - Pphi[1] = -0.5 * exp_gamma_m_alpha_2; + return state; } -/** - * ncm_csq1d_get_J_at: - * @csq1d: a #NcmCSQ1D - * @model: (allow-none): a #NcmModel - * @t: time $t$ - * @J11: (out): $J_{11}$ - * @J12: (out): $J_{12}$ - * @J22: (out): $J_{22}$ - * - * Computes the complex structure matrix. - * - */ -void -ncm_csq1d_get_J_at (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, gdouble *J11, gdouble *J12, gdouble *J22) +static void +_ncm_csq1d_eval_adiab2_at_no_test (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, gdouble *alpha, gdouble *dgamma, gdouble *alpha_reltol, gdouble *dgamma_reltol) { NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); - const gdouble a_t = asinh (t); + const gdouble F1 = ncm_csq1d_eval_F1 (csq1d, model, t); + const gdouble F2 = ncm_csq1d_eval_F2 (csq1d, model, t); - const gdouble alpha = ncm_spline_eval (self->alpha_s, a_t); - const gdouble dgamma = ncm_spline_eval (self->dgamma_s, a_t); - const gdouble gamma = ncm_csq1d_eval_xi (csq1d, model, t, self->k) + dgamma; + alpha[0] = +F1; + dgamma[0] = -F2; + + if (alpha_reltol != NULL) + alpha_reltol[0] = fabs (F1); - J11[0] = cosh (alpha) * exp (-gamma); - J22[0] = cosh (alpha) * exp (+gamma); - J12[0] = -sinh (alpha); + if (dgamma_reltol != NULL) + dgamma_reltol[0] = fabs (F2); } -/** - * ncm_csq1d_get_H_poincare_hp: - * @csq1d: a #NcmCSQ1D - * @model: (allow-none): a #NcmModel - * @t: time $t$ - * @x: (out): $x$ - * @lny: (out): $\ln(y)$ - * - * Computes the complex structure matrix. - * - */ -void -ncm_csq1d_get_H_poincare_hp (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, gdouble *x, gdouble *lny) +static void +_ncm_csq1d_eval_adiab4_at_no_test (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, gdouble *alpha, gdouble *dgamma, gdouble *alpha_reltol, gdouble *dgamma_reltol) { NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); + NcmCSQ1DWS ws = {csq1d, model, 0.0, 0.0}; + const gdouble F1 = ncm_csq1d_eval_F1 (csq1d, model, t); + const gdouble F2 = ncm_csq1d_eval_F2 (csq1d, model, t); + const gdouble F1_2 = F1 * F1; + const gdouble F1_3 = F1_2 * F1; + const gdouble nu = ncm_csq1d_eval_nu (csq1d, model, t); + const gdouble twonu = 2.0 * nu; + gdouble err, F3, d2F2, dlnnu, F4, alpha_reltol0, dgamma_reltol0; - x[0] = 0.0; - lny[0] = -ncm_csq1d_eval_xi (csq1d, model, t, self->k); -} + F3 = ncm_diff_rc_d1_1_to_1 (self->diff, t, &_ncm_csq1d_F2_func, &ws, &err) / twonu; + d2F2 = ncm_diff_rc_d2_1_to_1 (self->diff, t, &_ncm_csq1d_F2_func, &ws, &err); + dlnnu = ncm_diff_rc_d1_1_to_1 (self->diff, t, &_ncm_csq1d_lnnu_func, &ws, &err); + F4 = d2F2 / gsl_pow_2 (twonu) - dlnnu * F3 / twonu; + + if (F1 != 0.0) + alpha_reltol0 = gsl_pow_2 ((F1_3 / 3.0 - F3) / F1); + else + alpha_reltol0 = gsl_pow_2 (F1_3 / 3.0 - F3); + + if (F2 != 0.0) + dgamma_reltol0 = gsl_pow_2 ((F4 - F1_2 * F2) / F2); + else + dgamma_reltol0 = gsl_pow_2 (F4 - F1_2 * F2); + + alpha[0] = +F1 + F1_3 / 3.0 - F3; + dgamma[0] = -(1.0 + F1_2) * F2 + F4; + + if (alpha_reltol != NULL) + alpha_reltol[0] = alpha_reltol0; + + if (dgamma_reltol != NULL) + dgamma_reltol[0] = dgamma_reltol0; +} + +static void +_ncm_csq1d_eval_adiab_at_no_test (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, gdouble *alpha, gdouble *dgamma, gdouble *alpha_reltol, gdouble *dgamma_reltol) +{ + NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); + + switch (self->initial_condition_type) + { + case NCM_CSQ1D_INITIAL_CONDITION_TYPE_ADIABATIC2: + _ncm_csq1d_eval_adiab2_at_no_test (csq1d, model, t, alpha, dgamma, alpha_reltol, dgamma_reltol); + break; + case NCM_CSQ1D_INITIAL_CONDITION_TYPE_ADIABATIC4: + _ncm_csq1d_eval_adiab4_at_no_test (csq1d, model, t, alpha, dgamma, alpha_reltol, dgamma_reltol); + break; + default: + _ncm_csq1d_eval_adiab4_at_no_test (csq1d, model, t, alpha, dgamma, alpha_reltol, dgamma_reltol); + break; + } +} + +static void +_ncm_csq1d_compute_nonadiab (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, NcmCSQ1DState *state) +{ + NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); + const gdouble p1 = ncm_csq1d_eval_int_qmnu2 (csq1d, model, t); + const gdouble r1 = 0.5 * ncm_csq1d_eval_int_mnu2 (csq1d, model, t); + + ncm_csq1d_state_set_up (state, NCM_CSQ1D_FRAME_NONADIAB1, t, +2.0 * r1, -2.0 * p1); +} + +/* OLD IMPLEMENTATION + * const gdouble q0 = ncm_csq1d_eval_int_1_m (csq1d, model, t); + * const gdouble q1 = ncm_csq1d_eval_int_q2mnu2 (csq1d, model, t); + * const gdouble p1 = ncm_csq1d_eval_int_qmnu2 (csq1d, model, t); + * const gdouble r1 = 0.5 * ncm_csq1d_eval_int_mnu2 (csq1d, model, t); + * + * switch (frame) + * { + * case NCM_CSQ1D_FRAME_ORIG: + * chi[0] = (2.0 * p1 - 1.0) * (q0 + q1) + 2.0 * r1; + * Up[0] = -2.0 * p1; + * break; + * case NCM_CSQ1D_FRAME_NONADIAB1: + * chi[0] = +2.0 * r1; + * Up[0] = -2.0 * p1; + * break; + * case NCM_CSQ1D_FRAME_NONADIAB2: + * chi[0] = 0.0; + * Up[0] = 0.0; + * break; + * default: + * g_assert_not_reached (); + * break; + * } + */ /** - * ncm_csq1d_get_poincare_hp: + * ncm_csq1d_compute_nonadiab: * @csq1d: a #NcmCSQ1D * @model: (allow-none): a #NcmModel * @t: time $t$ - * @x: (out): $x$ - * @lny: (out): $\ln(y)$ + * @state: a #NcmCSQ1DState to store the result * - * Computes the complex structure matrix. + * Computes the value of the non-adiabatic VDC order two in the variables $\chi$ and + * $U$ at $t$. The result is stored in the state object in the frame NCM_CSQ1D_FRAME_NONADIAB1. + * Use ncm_csq1d_change_frame() to change the frame. * + * Returns: (transfer none): the @state object with the result. */ -void -ncm_csq1d_get_poincare_hp (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, gdouble *x, gdouble *lny) +NcmCSQ1DState * +ncm_csq1d_compute_nonadiab (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, NcmCSQ1DState *state) +{ + _ncm_csq1d_compute_nonadiab (csq1d, model, t, state); + + return state; +} + +/** + * ncm_csq1d_compute_H: + * @csq1d: a #NcmCSQ1D + * @model: (allow-none): a #NcmModel + * @t: time $t$ + * @state: a #NcmCSQ1DState to store the result + * + * Computes the Hamiltonian vector state of the original frame at $t$. The result is + * stored in the state object in the frame NCM_CSQ1D_FRAME_ORIG. + * Use ncm_csq1d_change_frame() to change the frame. + * + * Returns: (transfer none): the @state object with the result. + */ +NcmCSQ1DState * +ncm_csq1d_compute_H (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, NcmCSQ1DState *state) +{ + ncm_csq1d_state_set_ag (state, NCM_CSQ1D_FRAME_ORIG, t, 0.0, ncm_csq1d_eval_xi (csq1d, model, t)); + + return state; +} + +static void +_ncm_csq1d_eval_state (NcmCSQ1D *csq1d, const gdouble t, NcmCSQ1DState *state) { NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); const gdouble a_t = asinh (t); + const gdouble alpha = ncm_spline_eval (self->alpha_s, a_t); + const gdouble gamma = ncm_spline_eval (self->gamma_s, a_t); - const gdouble alpha = ncm_spline_eval (self->alpha_s, a_t); - const gdouble dgamma = ncm_spline_eval (self->dgamma_s, a_t); - const gdouble gamma = ncm_csq1d_eval_xi (csq1d, model, t, self->k) + dgamma; + ncm_csq1d_state_set_ag (state, NCM_CSQ1D_FRAME_ORIG, t, alpha, gamma); +} - x[0] = exp (-gamma) * tanh (alpha); - lny[0] = -gamma - gsl_sf_lncosh (alpha); +/** + * ncm_csq1d_eval_at: + * @csq1d: a #NcmCSQ1D + * @model: (allow-none): a #NcmModel + * @t: time $t$ + * @state: a #NcmCSQ1DState to store the result + * + * Computes the system state at $t$, the result is stored in the state object + * in the frame NCM_CSQ1D_FRAME_ORIG. Use ncm_csq1d_change_frame() to change the frame. + * + * Returns: (transfer none): the @state object with the result. + */ +NcmCSQ1DState * +ncm_csq1d_eval_at (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, NcmCSQ1DState *state) +{ + NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); + + if (t > self->vacuum_final_time) + _ncm_csq1d_eval_state (csq1d, t, state); + else + ncm_csq1d_compute_adiab_frame (csq1d, model, NCM_CSQ1D_FRAME_ORIG, t, state, NULL, NULL); + + return state; +} + +/** + * ncm_csq1d_eval_at_frame: + * @csq1d: a #NcmCSQ1D + * @model: (allow-none): a #NcmModel + * @frame: a #NcmCSQ1DFrame + * @t: time $t$ + * @state: a #NcmCSQ1DState to store the result + * + * Computes the system state at $t$, the result is stored in the state object + * in the frame @frame. + * + * Returns: (transfer none): the @state object with the result. + */ +NcmCSQ1DState * +ncm_csq1d_eval_at_frame (NcmCSQ1D *csq1d, NcmModel *model, const NcmCSQ1DFrame frame, const gdouble t, NcmCSQ1DState *state) +{ + NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); + + if (t > self->vacuum_final_time) + { + _ncm_csq1d_eval_state (csq1d, t, state); + ncm_csq1d_change_frame (csq1d, model, state, frame); + } + else + { + ncm_csq1d_compute_adiab_frame (csq1d, model, frame, t, state, NULL, NULL); + } + + return state; } #define _ALPHA_TO_THETA(alpha) (atan (sinh (alpha))) @@ -2502,256 +3062,354 @@ ncm_csq1d_get_poincare_hp (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, gd static void _ncm_csq1d_ct_g0g1 (const gdouble alpha, const gdouble gamma, const gdouble p, gdouble *alphap, gdouble *gammap) { - const gdouble theta = _ALPHA_TO_THETA (alpha); - gdouble thetap = 0.0; + const gdouble l_theta = _ALPHA_TO_THETA (alpha); + const gdouble l_gamma = gamma; + gdouble thetap = 0.0; - ncm_util_mln_1mIexpzA_1pIexpmzA (gamma, theta, tanh (0.5 * p), gammap, &thetap); + ncm_util_mln_1mIexpzA_1pIexpmzA (l_gamma, l_theta, tanh (0.5 * p), gammap, &thetap); alphap[0] = _THETA_TO_ALPHA (thetap); } -/** - * ncm_csq1d_get_poincare_hp_frame: - * @csq1d: a #NcmCSQ1D - * @model: (allow-none): a #NcmModel - * @adiab_frame: which adiabatic frame to use - * @t: time $t$ - * @x: (out): $x$ - * @lny: (out): $\ln(y)$ - * - * Computes the complex structure matrix. - * - */ -void -ncm_csq1d_get_poincare_hp_frame (NcmCSQ1D *csq1d, NcmModel *model, guint adiab_frame, const gdouble t, gdouble *x, gdouble *lny) +static void +_ncm_csq1d_change_adiab1_to_orig (NcmCSQ1D *csq1d, NcmModel *model, NcmCSQ1DState *state) { NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); - const gdouble a_t = asinh (t); + const gdouble t = state->t; + const gdouble xi = ncm_csq1d_eval_xi (csq1d, model, t); + + ncm_csq1d_state_set_ag (state, NCM_CSQ1D_FRAME_ORIG, t, state->alpha, state->gamma + xi); +} + +static void +_ncm_csq1d_change_orig_to_adiab1 (NcmCSQ1D *csq1d, NcmModel *model, NcmCSQ1DState *state) +{ + NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); + const gdouble t = state->t; + const gdouble xi = ncm_csq1d_eval_xi (csq1d, model, t); - switch (adiab_frame) + ncm_csq1d_state_set_ag (state, NCM_CSQ1D_FRAME_ADIAB1, t, state->alpha, state->gamma - xi); +} + +static void +_ncm_csq1d_change_adiab2_to_adiab1 (NcmCSQ1D *csq1d, NcmModel *model, NcmCSQ1DState *state) +{ + NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); + const gdouble t = state->t; + const gdouble F1 = ncm_csq1d_eval_F1 (csq1d, model, t); + const gdouble xi1 = atanh (-F1); + gdouble alphap = 0.0; + gdouble gammap = 0.0; + + if (fabs (F1) >= 1.0) + g_error ("ncm_csq1d_change_adiab2_to_adiab1: |F1| >= 1 at t = % 22.15e", t); + + _ncm_csq1d_ct_g0g1 (state->alpha, state->gamma, -xi1, &alphap, &gammap); + ncm_csq1d_state_set_ag (state, NCM_CSQ1D_FRAME_ADIAB1, t, alphap, gammap); +} + +static void +_ncm_csq1d_change_adiab1_to_adiab2 (NcmCSQ1D *csq1d, NcmModel *model, NcmCSQ1DState *state) +{ + NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); + const gdouble t = state->t; + const gdouble F1 = ncm_csq1d_eval_F1 (csq1d, model, t); + const gdouble xi1 = atanh (-F1); + gdouble alphap = 0.0; + gdouble gammap = 0.0; + + if (fabs (F1) >= 1.0) + g_error ("ncm_csq1d_change_adiab1_to_adiab2: |F1| >= 1 at t = % 22.15e", t); + + _ncm_csq1d_ct_g0g1 (state->alpha, state->gamma, xi1, &alphap, &gammap); + ncm_csq1d_state_set_ag (state, NCM_CSQ1D_FRAME_ADIAB2, t, alphap, gammap); +} + +static void +_ncm_csq1d_change_nonadiab1_to_orig (NcmCSQ1D *csq1d, NcmModel *model, NcmCSQ1DState *state) +{ + NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); + const gdouble t = state->t; + const gdouble int_1_m = ncm_csq1d_eval_int_1_m (csq1d, model, t); + const gdouble q0 = int_1_m; + const gdouble q1 = ncm_csq1d_eval_int_q2mnu2 (csq1d, model, t); + gdouble chi, Up; + + ncm_csq1d_state_get_up (state, &chi, &Up); + ncm_csq1d_state_set_up (state, NCM_CSQ1D_FRAME_ORIG, t, chi - exp (Up) * (q0 + q1), Up); +} + +static void +_ncm_csq1d_change_orig_to_nonadiab1 (NcmCSQ1D *csq1d, NcmModel *model, NcmCSQ1DState *state) +{ + NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); + const gdouble t = state->t; + const gdouble int_1_m = ncm_csq1d_eval_int_1_m (csq1d, model, t); + const gdouble q0 = int_1_m; + const gdouble q1 = ncm_csq1d_eval_int_q2mnu2 (csq1d, model, t); + gdouble chi, Up; + + ncm_csq1d_state_get_up (state, &chi, &Up); + ncm_csq1d_state_set_up (state, NCM_CSQ1D_FRAME_NONADIAB1, t, chi + exp (Up) * (q0 + q1), Up); +} + +static void +_ncm_csq1d_change_nonadiab1_to_nonadiab2 (NcmCSQ1D *csq1d, NcmModel *model, NcmCSQ1DState *state) +{ + NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); + const gdouble t = state->t; + + /* p1 g1 */ { - case 0: - { - const gdouble alpha = ncm_spline_eval (self->alpha_s, a_t); - const gdouble dgamma = ncm_spline_eval (self->dgamma_s, a_t); - const gdouble gamma = ncm_csq1d_eval_xi (csq1d, model, t, self->k) + dgamma; + const gdouble p1 = ncm_csq1d_eval_int_qmnu2 (csq1d, model, t); + gdouble chi, Up; - x[0] = exp (-gamma) * tanh (alpha); - lny[0] = -gamma - gsl_sf_lncosh (alpha); - break; - } - case 1: - { - const gdouble alpha = ncm_spline_eval (self->alpha_s, a_t); - const gdouble dgamma = ncm_spline_eval (self->dgamma_s, a_t); + ncm_csq1d_state_get_up (state, &chi, &Up); - x[0] = exp (-dgamma) * tanh (alpha); - lny[0] = -dgamma - gsl_sf_lncosh (alpha); - break; - } - case 2: - { - const gdouble alpha = ncm_spline_eval (self->alpha_s, a_t); - const gdouble dgamma = ncm_spline_eval (self->dgamma_s, a_t); - const gdouble theta = _ALPHA_TO_THETA (alpha); - const gdouble F1 = ncm_csq1d_eval_F1 (csq1d, model, t, self->k); - const gdouble xi1 = atanh (-F1); + Up = Up + 2.0 * p1; - gdouble thetap = 0.0; - gdouble alphap = 0.0; - gdouble gammap = 0.0; + ncm_csq1d_state_set_up (state, NCM_CSQ1D_FRAME_NONADIAB2, t, chi, Up); + } - ncm_util_mln_1mIexpzA_1pIexpmzA (dgamma, theta, tanh (0.5 * xi1), &gammap, &thetap); + /* r1 g2 */ + { + const gdouble r1 = 0.5 * ncm_csq1d_eval_int_mnu2 (csq1d, model, t); + gdouble alpha, gamma, alphap, gammap; - alphap = _THETA_TO_ALPHA (thetap); + ncm_csq1d_state_get_ag (state, &alpha, &gamma); - x[0] = exp (-gammap) * tanh (alphap); - lny[0] = -gammap - gsl_sf_lncosh (alphap); - break; - } - default: - g_assert_not_reached (); - break; + _ncm_csq1d_ct_g0g1 (alpha, gamma, -2.0 * r1, &alphap, &gammap); + + ncm_csq1d_state_set_ag (state, NCM_CSQ1D_FRAME_NONADIAB2, t, alphap, gammap); } } -/** - * ncm_csq1d_alpha_dgamma_to_minkowski_frame: - * @csq1d: a #NcmCSQ1D - * @model: (allow-none): a #NcmModel - * @adiab_frame: which adiabatic frame to use - * @t: time $t$ - * @alpha: $\alpha$ - * @dgamma: $\delta\gamma$ - * @x1: (out): $x_1$ - * @x2: (out): $x_2$ - * - * Computes the complex structure matrix. - * - */ -void -ncm_csq1d_alpha_dgamma_to_minkowski_frame (NcmCSQ1D *csq1d, NcmModel *model, guint adiab_frame, const gdouble t, const gdouble alpha, const gdouble dgamma, gdouble *x1, gdouble *x2) +static void +_ncm_csq1d_change_nonadiab2_to_nonadiab1 (NcmCSQ1D *csq1d, NcmModel *model, NcmCSQ1DState *state) { NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); + const gdouble t = state->t; - switch (adiab_frame) + /* r1 g2 */ { - case 0: - { - const gdouble gamma = ncm_csq1d_eval_xi (csq1d, model, t, self->k) + dgamma; + const gdouble r1 = 0.5 * ncm_csq1d_eval_int_mnu2 (csq1d, model, t); + gdouble alpha, gamma, alphap, gammap; - x1[0] = +sinh (alpha); - x2[0] = -cosh (alpha) * sinh (gamma); - break; - } - case 1: - { - x1[0] = +sinh (alpha); - x2[0] = -cosh (alpha) * sinh (dgamma); - break; - } - case 2: - { - const gdouble theta = _ALPHA_TO_THETA (alpha); - const gdouble F1 = ncm_csq1d_eval_F1 (csq1d, model, t, self->k); - const gdouble xi1 = atanh (-F1); + ncm_csq1d_state_get_ag (state, &alpha, &gamma); - gdouble thetap = 0.0; - gdouble alphap = 0.0; - gdouble gammap = 0.0; + _ncm_csq1d_ct_g0g1 (alpha, gamma, +2.0 * r1, &alphap, &gammap); - ncm_util_mln_1mIexpzA_1pIexpmzA (dgamma, theta, tanh (0.5 * xi1), &gammap, &thetap); + ncm_csq1d_state_set_ag (state, NCM_CSQ1D_FRAME_NONADIAB1, t, alphap, gammap); + } - alphap = _THETA_TO_ALPHA (thetap); + { + const gdouble p1 = ncm_csq1d_eval_int_qmnu2 (csq1d, model, t); + gdouble chi, Up; + + ncm_csq1d_state_get_up (state, &chi, &Up); + + /* p1 g1 */ + Up = Up - 2.0 * p1; - x1[0] = +sinh (alphap); - x2[0] = -cosh (alphap) * sinh (gammap); + ncm_csq1d_state_set_up (state, NCM_CSQ1D_FRAME_NONADIAB1, t, chi, Up); + } +} + +static void +_ncm_csq1d_change_frame_to_orig (NcmCSQ1D *csq1d, NcmModel *model, NcmCSQ1DState *state) +{ + NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); + + switch (state->frame) + { + case NCM_CSQ1D_FRAME_ORIG: + break; + case NCM_CSQ1D_FRAME_ADIAB1: + _ncm_csq1d_change_adiab1_to_orig (csq1d, model, state); + break; + case NCM_CSQ1D_FRAME_ADIAB2: + _ncm_csq1d_change_adiab2_to_adiab1 (csq1d, model, state); + _ncm_csq1d_change_adiab1_to_orig (csq1d, model, state); + break; + case NCM_CSQ1D_FRAME_NONADIAB1: + _ncm_csq1d_change_nonadiab1_to_orig (csq1d, model, state); + break; + case NCM_CSQ1D_FRAME_NONADIAB2: + _ncm_csq1d_change_nonadiab2_to_nonadiab1 (csq1d, model, state); + _ncm_csq1d_change_nonadiab1_to_orig (csq1d, model, state); break; - } default: - g_assert_not_reached (); + g_error ("_ncm_csq1d_change_frame_to_orig: Invalid frame %d", state->frame); break; } } -/** - * ncm_csq1d_get_minkowski_frame: - * @csq1d: a #NcmCSQ1D - * @model: (allow-none): a #NcmModel - * @adiab_frame: which adiabatic frame to use - * @t: time $t$ - * @x1: (out): $x_1$ - * @x2: (out): $x_2$ - * - * Computes the complex structure matrix. - * - */ -void -ncm_csq1d_get_minkowski_frame (NcmCSQ1D *csq1d, NcmModel *model, guint adiab_frame, const gdouble t, gdouble *x1, gdouble *x2) +static void +_ncm_csq1d_change_frame_to_adiab1 (NcmCSQ1D *csq1d, NcmModel *model, NcmCSQ1DState *state) { NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); - const gdouble a_t = asinh (t); - const gdouble alpha = ncm_spline_eval (self->alpha_s, a_t); - const gdouble dgamma = ncm_spline_eval (self->dgamma_s, a_t); - ncm_csq1d_alpha_dgamma_to_minkowski_frame (csq1d, model, adiab_frame, t, alpha, dgamma, x1, x2); + switch (state->frame) + { + case NCM_CSQ1D_FRAME_ORIG: + _ncm_csq1d_change_orig_to_adiab1 (csq1d, model, state); + break; + case NCM_CSQ1D_FRAME_ADIAB1: + break; + case NCM_CSQ1D_FRAME_ADIAB2: + _ncm_csq1d_change_adiab2_to_adiab1 (csq1d, model, state); + break; + case NCM_CSQ1D_FRAME_NONADIAB1: + _ncm_csq1d_change_nonadiab1_to_orig (csq1d, model, state); + _ncm_csq1d_change_orig_to_adiab1 (csq1d, model, state); + break; + case NCM_CSQ1D_FRAME_NONADIAB2: + _ncm_csq1d_change_nonadiab2_to_nonadiab1 (csq1d, model, state); + _ncm_csq1d_change_nonadiab1_to_orig (csq1d, model, state); + _ncm_csq1d_change_orig_to_adiab1 (csq1d, model, state); + break; + default: + g_assert_not_reached (); + break; + } } -/** - * ncm_csq1d_get_Hadiab_poincare_hp: - * @csq1d: a #NcmCSQ1D - * @model: (allow-none): a #NcmModel - * @t: time $t$ - * @x: (out): $x$ - * @lny: (out): $\ln(y)$ - * - * Computes the complex structure matrix. - * - */ -void -ncm_csq1d_get_Hadiab_poincare_hp (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, gdouble *x, gdouble *lny) +static void +_ncm_csq1d_change_frame_to_adiab2 (NcmCSQ1D *csq1d, NcmModel *model, NcmCSQ1DState *state) { NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); - gdouble alpha, dgamma, gamma; - - ncm_csq1d_eval_adiab_at (csq1d, model, t, &alpha, &dgamma, NULL, NULL); - - gamma = ncm_csq1d_eval_xi (csq1d, model, t, self->k) + dgamma; - - x[0] = exp (-gamma) * tanh (alpha); - lny[0] = -gamma - gsl_sf_lncosh (alpha); + switch (state->frame) + { + case NCM_CSQ1D_FRAME_ORIG: + _ncm_csq1d_change_orig_to_adiab1 (csq1d, model, state); + _ncm_csq1d_change_adiab1_to_adiab2 (csq1d, model, state); + break; + case NCM_CSQ1D_FRAME_ADIAB1: + _ncm_csq1d_change_adiab1_to_adiab2 (csq1d, model, state); + break; + case NCM_CSQ1D_FRAME_ADIAB2: + break; + case NCM_CSQ1D_FRAME_NONADIAB1: + _ncm_csq1d_change_nonadiab1_to_orig (csq1d, model, state); + _ncm_csq1d_change_orig_to_adiab1 (csq1d, model, state); + _ncm_csq1d_change_adiab1_to_adiab2 (csq1d, model, state); + break; + case NCM_CSQ1D_FRAME_NONADIAB2: + _ncm_csq1d_change_nonadiab2_to_nonadiab1 (csq1d, model, state); + _ncm_csq1d_change_nonadiab1_to_orig (csq1d, model, state); + _ncm_csq1d_change_orig_to_adiab1 (csq1d, model, state); + _ncm_csq1d_change_adiab1_to_adiab2 (csq1d, model, state); + break; + default: + g_assert_not_reached (); + break; + } } -/** - * ncm_csq1d_get_H_poincare_disc: - * @csq1d: a #NcmCSQ1D - * @model: (allow-none): a #NcmModel - * @t: time $t$ - * @x: (out): $x$ - * @lny: (out): $\ln(y)$ - * - * Computes the complex structure matrix. - * - */ -void -ncm_csq1d_get_H_poincare_disc (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, gdouble *x, gdouble *lny) +static void +_ncm_csq1d_change_frame_to_nonadiab1 (NcmCSQ1D *csq1d, NcmModel *model, NcmCSQ1DState *state) { NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); - const gdouble xi = ncm_csq1d_eval_xi (csq1d, model, t, self->k); - x[0] = 0.0; - lny[0] = -tanh (xi / 2); + switch (state->frame) + { + case NCM_CSQ1D_FRAME_ORIG: + _ncm_csq1d_change_orig_to_nonadiab1 (csq1d, model, state); + break; + case NCM_CSQ1D_FRAME_ADIAB1: + _ncm_csq1d_change_adiab1_to_orig (csq1d, model, state); + _ncm_csq1d_change_orig_to_nonadiab1 (csq1d, model, state); + break; + case NCM_CSQ1D_FRAME_ADIAB2: + _ncm_csq1d_change_adiab2_to_adiab1 (csq1d, model, state); + _ncm_csq1d_change_adiab1_to_orig (csq1d, model, state); + _ncm_csq1d_change_orig_to_nonadiab1 (csq1d, model, state); + break; + case NCM_CSQ1D_FRAME_NONADIAB1: + break; + case NCM_CSQ1D_FRAME_NONADIAB2: + _ncm_csq1d_change_nonadiab2_to_nonadiab1 (csq1d, model, state); + break; + default: + g_assert_not_reached (); + break; + } } -/** - * ncm_csq1d_get_Hadiab_poincare_disc: - * @csq1d: a #NcmCSQ1D - * @model: (allow-none): a #NcmModel - * @t: time $t$ - * @x: (out): $x$ - * @lny: (out): $\ln(y)$ - * - * Computes the complex structure matrix. - * - */ -void -ncm_csq1d_get_Hadiab_poincare_disc (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, gdouble *x, gdouble *lny) +static void +_ncm_csq1d_change_frame_to_nonadiab2 (NcmCSQ1D *csq1d, NcmModel *model, NcmCSQ1DState *state) { NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); - gdouble alpha, dgamma, gamma; - - ncm_csq1d_eval_adiab_at (csq1d, model, t, &alpha, &dgamma, NULL, NULL); - - gamma = ncm_csq1d_eval_xi (csq1d, model, t, self->k) + dgamma; - - x[0] = +sinh (alpha) / (1.0 + cosh (alpha) * cosh (gamma)); - lny[0] = -sinh (gamma) * cosh (alpha) / (1.0 + cosh (alpha) * cosh (gamma)); + switch (state->frame) + { + case NCM_CSQ1D_FRAME_ORIG: + _ncm_csq1d_change_orig_to_nonadiab1 (csq1d, model, state); + _ncm_csq1d_change_nonadiab1_to_nonadiab2 (csq1d, model, state); + break; + case NCM_CSQ1D_FRAME_ADIAB1: + _ncm_csq1d_change_adiab1_to_orig (csq1d, model, state); + _ncm_csq1d_change_orig_to_nonadiab1 (csq1d, model, state); + _ncm_csq1d_change_nonadiab1_to_nonadiab2 (csq1d, model, state); + break; + case NCM_CSQ1D_FRAME_ADIAB2: + _ncm_csq1d_change_adiab2_to_adiab1 (csq1d, model, state); + _ncm_csq1d_change_adiab1_to_orig (csq1d, model, state); + _ncm_csq1d_change_orig_to_nonadiab1 (csq1d, model, state); + _ncm_csq1d_change_nonadiab1_to_nonadiab2 (csq1d, model, state); + break; + case NCM_CSQ1D_FRAME_NONADIAB1: + _ncm_csq1d_change_nonadiab1_to_nonadiab2 (csq1d, model, state); + break; + case NCM_CSQ1D_FRAME_NONADIAB2: + break; + default: + g_assert_not_reached (); + break; + } } /** - * ncm_csq1d_get_poincare_disc: + * ncm_csq1d_change_frame: * @csq1d: a #NcmCSQ1D * @model: (allow-none): a #NcmModel - * @t: time $t$ - * @x: (out): $x$ - * @lny: (out): $\ln(y)$ + * @state: a #NcmCSQ1DState + * @frame: which frame to use * - * Computes the complex structure matrix. + * Changes the frame of the @state object to the given @frame. The state object + * must be a valid state object, it cannot be NULL. The state object is updated + * in place. * + * Returns: (transfer none): the state object in the new frame. */ -void -ncm_csq1d_get_poincare_disc (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, gdouble *x, gdouble *lny) +NcmCSQ1DState * +ncm_csq1d_change_frame (NcmCSQ1D *csq1d, NcmModel *model, NcmCSQ1DState *state, NcmCSQ1DFrame frame) { NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); - const gdouble a_t = asinh (t); - const gdouble alpha = ncm_spline_eval (self->alpha_s, a_t); - const gdouble dgamma = ncm_spline_eval (self->dgamma_s, a_t); - const gdouble gamma = ncm_csq1d_eval_xi (csq1d, model, t, self->k) + dgamma; + switch (frame) + { + case NCM_CSQ1D_FRAME_ORIG: + _ncm_csq1d_change_frame_to_orig (csq1d, model, state); + break; + case NCM_CSQ1D_FRAME_ADIAB1: + _ncm_csq1d_change_frame_to_adiab1 (csq1d, model, state); + break; + case NCM_CSQ1D_FRAME_ADIAB2: + _ncm_csq1d_change_frame_to_adiab2 (csq1d, model, state); + break; + case NCM_CSQ1D_FRAME_NONADIAB1: + _ncm_csq1d_change_frame_to_nonadiab1 (csq1d, model, state); + break; + case NCM_CSQ1D_FRAME_NONADIAB2: + _ncm_csq1d_change_frame_to_nonadiab2 (csq1d, model, state); + break; + default: + g_assert_not_reached (); + break; + } - x[0] = +sinh (alpha) / (1.0 + cosh (alpha) * cosh (gamma)); - lny[0] = -sinh (gamma) * cosh (alpha) / (1.0 + cosh (alpha) * cosh (gamma)); + return state; } static gint _ncm_csq1d_f_Prop (realtype t, N_Vector y, N_Vector ydot, gpointer f_data); @@ -2833,11 +3491,11 @@ _ncm_csq1d_f_Prop (realtype t, N_Vector y, N_Vector ydot, gpointer f_data) const gdouble c = NV_Ith_S (y, 2); const gdouble h = NV_Ith_S (y, 3); - const gdouble m = ncm_csq1d_eval_m (ws->csq1d, ws->model, t, self->k); - const gdouble nu2 = ncm_csq1d_eval_nu2 (ws->csq1d, ws->model, t, self->k); + const gdouble m = ncm_csq1d_eval_m (ws->csq1d, ws->model, t); + const gdouble nu2 = ncm_csq1d_eval_nu2 (ws->csq1d, ws->model, t); const gdouble mnu2 = m * nu2; const gdouble mnu2_2 = 0.5 * mnu2; - const gdouble int_1_m = ncm_csq1d_eval_int_1_m (ws->csq1d, ws->model, t, self->k); + const gdouble int_1_m = ncm_csq1d_eval_int_1_m (ws->csq1d, ws->model, t); const gdouble q = -int_1_m; const gdouble q2 = q * q; @@ -2865,11 +3523,11 @@ _ncm_csq1d_J_Prop (realtype t, N_Vector y, N_Vector fy, SUNMatrix J, gpointer ja NcmCSQ1DWS *ws = (NcmCSQ1DWS *) jac_data; NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (ws->csq1d); - const gdouble m = ncm_csq1d_eval_m (ws->csq1d, ws->model, t, self->k); - const gdouble nu2 = ncm_csq1d_eval_nu2 (ws->csq1d, ws->model, t, self->k); + const gdouble m = ncm_csq1d_eval_m (ws->csq1d, ws->model, t); + const gdouble nu2 = ncm_csq1d_eval_nu2 (ws->csq1d, ws->model, t); const gdouble mnu2 = m * nu2; const gdouble mnu2_2 = 0.5 * mnu2; - const gdouble int_1_m = ncm_csq1d_eval_int_1_m (ws->csq1d, ws->model, t, self->k); + const gdouble int_1_m = ncm_csq1d_eval_int_1_m (ws->csq1d, ws->model, t); const gdouble q = -int_1_m; const gdouble q2 = q * q; @@ -2947,8 +3605,10 @@ _ncm_csq1d_prepare_prop_eval_u1 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble * @tii: integral approximation time $t_{\mathrm{i}i}$ * @tf: max time $t_f$ * - * - * Computes the complex structure matrix. + * Computes the propagator for the given @csq1d and @model from @ti to @tf. The + * propagator is computed using the integral approximation time @tii. The + * propagator is stored in the @csq1d object and can be used to compute the + * propagator a state from @ti to any time between @tii and @tf. * */ void @@ -2964,12 +3624,13 @@ ncm_csq1d_prepare_prop (NcmCSQ1D *csq1d, NcmModel *model, const gdouble ti, cons gint i; _ncm_csq1d_prepare_prop_eval_u1 (csq1d, model, ti, tii, u1); + self->ti_Prop = ti; /* * ncm_message ("% 22.15g % 22.15g % 22.15g % 22.15g % 22.15g % 22.15g % 22.15g % 22.15g\n", ti, tii, - * u1[0], +ncm_csq1d_eval_int_qmnu2 (csq1d, model, tii, self->k), - * u1[1], +ncm_csq1d_eval_int_q2mnu2 (csq1d, model, tii, self->k), - * u1[2], -ncm_csq1d_eval_int_mnu2 (csq1d, model, tii, self->k) + * u1[0], +ncm_csq1d_eval_int_qmnu2 (csq1d, model, tii), + * u1[1], +ncm_csq1d_eval_int_q2mnu2 (csq1d, model, tii), + * u1[2], -ncm_csq1d_eval_int_mnu2 (csq1d, model, tii) * ); */ @@ -3039,8 +3700,8 @@ _ncm_csq1d_prepare_prop_mnu2 (gdouble t, gpointer params) NcmCSQ1DWS *ws = (NcmCSQ1DWS *) params; NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (ws->csq1d); - const gdouble m = ncm_csq1d_eval_m (ws->csq1d, ws->model, t, self->k); - const gdouble nu2 = ncm_csq1d_eval_nu2 (ws->csq1d, ws->model, t, self->k); + const gdouble m = ncm_csq1d_eval_m (ws->csq1d, ws->model, t); + const gdouble nu2 = ncm_csq1d_eval_nu2 (ws->csq1d, ws->model, t); return m * nu2; } @@ -3051,8 +3712,8 @@ _ncm_csq1d_prepare_prop_qmnu2 (gdouble t, gpointer params) NcmCSQ1DWS *ws = (NcmCSQ1DWS *) params; NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (ws->csq1d); - const gdouble m = ncm_csq1d_eval_m (ws->csq1d, ws->model, t, self->k); - const gdouble nu2 = ncm_csq1d_eval_nu2 (ws->csq1d, ws->model, t, self->k); + const gdouble m = ncm_csq1d_eval_m (ws->csq1d, ws->model, t); + const gdouble nu2 = ncm_csq1d_eval_nu2 (ws->csq1d, ws->model, t); const gdouble mnu2 = m * nu2; if (mnu2 == 0) @@ -3061,7 +3722,7 @@ _ncm_csq1d_prepare_prop_qmnu2 (gdouble t, gpointer params) } else { - const gdouble int_1_m = ncm_csq1d_eval_int_1_m (ws->csq1d, ws->model, t, self->k); + const gdouble int_1_m = ncm_csq1d_eval_int_1_m (ws->csq1d, ws->model, t); const gdouble q = -int_1_m; return q * mnu2; @@ -3074,8 +3735,8 @@ _ncm_csq1d_prepare_prop_q2mnu2 (gdouble t, gpointer params) NcmCSQ1DWS *ws = (NcmCSQ1DWS *) params; NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (ws->csq1d); - const gdouble m = ncm_csq1d_eval_m (ws->csq1d, ws->model, t, self->k); - const gdouble nu2 = ncm_csq1d_eval_nu2 (ws->csq1d, ws->model, t, self->k); + const gdouble m = ncm_csq1d_eval_m (ws->csq1d, ws->model, t); + const gdouble nu2 = ncm_csq1d_eval_nu2 (ws->csq1d, ws->model, t); const gdouble mnu2 = m * nu2; if (mnu2 == 0) @@ -3084,7 +3745,7 @@ _ncm_csq1d_prepare_prop_q2mnu2 (gdouble t, gpointer params) } else { - const gdouble int_1_m = ncm_csq1d_eval_int_1_m (ws->csq1d, ws->model, t, self->k); + const gdouble int_1_m = ncm_csq1d_eval_int_1_m (ws->csq1d, ws->model, t); const gdouble q = -int_1_m; return q * q * mnu2; @@ -3106,16 +3767,18 @@ ncm_csq1d_get_tf_prop (NcmCSQ1D *csq1d) } /** - * ncm_csq1d_get_prop_vector_chi_Up: + * ncm_csq1d_get_prop_vector: * @csq1d: a #NcmCSQ1D * @model: (allow-none): a #NcmModel * @t: time $t$ - * @chi: (out): $\chi$ - * @Up: (out): $U_+$ + * @state: a #NcmCSQ1DState to store the result + * + * Computes the state vector associated with the propagator at time $t$. * + * Returns: (transfer none): the @state object with the result. */ -void -ncm_csq1d_get_prop_vector_chi_Up (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, gdouble *chi, gdouble *Up) +NcmCSQ1DState * +ncm_csq1d_compute_prop_vector (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, NcmCSQ1DState *state) { NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); const gdouble b = ncm_spline_eval (self->R[1], t); @@ -3123,30 +3786,18 @@ ncm_csq1d_get_prop_vector_chi_Up (NcmCSQ1D *csq1d, NcmModel *model, const gdoubl const gdouble h = ncm_spline_eval (self->R[3], t); const gdouble n0 = sqrt (-(b * c + h * h)); - chi[0] = h / n0; - Up[0] = log (-c / n0); + ncm_csq1d_state_set_up (state, NCM_CSQ1D_FRAME_ORIG, t, h / n0, log (-c / n0)); + + return state; } -/** - * ncm_csq1d_evolve_prop_vector_chi_Up: - * @csq1d: a #NcmCSQ1D - * @model: (allow-none): a #NcmModel - * @t: time $t$ - * @nonadiab_frame: frame - * @chi_i: $\chi_i$ - * @Up_i: $U_{+i}$ - * @chi: (out): $\chi$ - * @Up: (out): $U_+$ - * - * - */ -void -ncm_csq1d_evolve_prop_vector_chi_Up (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const guint nonadiab_frame, gdouble chi_i, gdouble Up_i, gdouble *chi, gdouble *Up) +static void +_ncm_csq1d_evolve_prop_vector (NcmCSQ1D *csq1d, NcmModel *model, NcmCSQ1DState *initial_state, const NcmCSQ1DFrame frame, const gdouble t, NcmCSQ1DState *state) { NcmCSQ1DPrivate * const self = ncm_csq1d_get_instance_private (csq1d); - const gdouble int_1_m = ncm_csq1d_eval_int_1_m (csq1d, model, t, self->k); + const gdouble int_1_m = ncm_csq1d_eval_int_1_m (csq1d, model, t); const gdouble q0 = int_1_m; - const gdouble q1 = ncm_csq1d_eval_int_q2mnu2 (csq1d, model, t, self->k); + const gdouble q1 = ncm_csq1d_eval_int_q2mnu2 (csq1d, model, t); const gdouble a = ncm_spline_eval (self->R[0], t); const gdouble b = ncm_spline_eval (self->R[1], t); const gdouble c = ncm_spline_eval (self->R[2], t); @@ -3155,83 +3806,105 @@ ncm_csq1d_evolve_prop_vector_chi_Up (NcmCSQ1D *csq1d, NcmModel *model, const gdo const gdouble a22 = a - h; const gdouble a12 = b; const gdouble a21 = c; - const gdouble onepchi2 = 1.0 + chi_i * chi_i; - const gdouble exp_Up_i = exp (Up_i); + const gdouble init_ti = ncm_csq1d_state_get_time (initial_state); + const gdouble q1_ti = ncm_csq1d_eval_int_qmnu2 (csq1d, model, init_ti); + gdouble chi_i, Up_i; + + if (init_ti != self->ti_Prop) + g_error ("Initial time does not match the propagator initial time"); + + if (initial_state->frame != NCM_CSQ1D_FRAME_NONADIAB1) + g_error ("Initial state must be in the non-adiabatic 1 frame"); - chi[0] = a12 * a21 * chi_i + a22 * (a11 * chi_i - a12 * exp_Up_i) - a11 * a21 * onepchi2 / exp_Up_i; - Up[0] = -(2.0 * a21 * a22 * chi_i - a22 * a22 * exp_Up_i - a21 * a21 * onepchi2 / exp_Up_i); + ncm_csq1d_state_get_up (initial_state, &chi_i, &Up_i); + + /* + * The propagator is computed in a intermediate frame, we need to change from the + * non-adibatic 1 to the intermediate frame first. This transformation does not + * change Up_i, so we can use it to compute the new chi_i. + */ + chi_i = (chi_i - exp (Up_i) * q1_ti); - switch (nonadiab_frame) { - case 0: - chi[0] = (chi[0] - Up[0] * q0); - Up[0] = log (Up[0]); - break; - case 1: - /* q1 L2p */ - chi[0] = (chi[0] + Up[0] * q1); - Up[0] = log (Up[0]); - break; - case 2: - { - const gdouble p1 = ncm_csq1d_eval_int_qmnu2 (csq1d, model, t, self->k); + const gdouble onepchi2 = 1.0 + chi_i * chi_i; + const gdouble exp_Up_i = exp (Up_i); + gdouble chi, Up; + + chi = a12 * a21 * chi_i + a22 * (a11 * chi_i - a12 * exp_Up_i) - a11 * a21 * onepchi2 / exp_Up_i; + Up = -(2.0 * a21 * a22 * chi_i - a22 * a22 * exp_Up_i - a21 * a21 * onepchi2 / exp_Up_i); - /* q1 L2p */ - chi[0] = (chi[0] + Up[0] * q1); - Up[0] = log (Up[0]); + /* + * The transformation above result in a new chi and Up in the intermediate frame. + * We can now use these values and transform to the final frame. + */ + + switch (frame) + { + case NCM_CSQ1D_FRAME_ORIG: + chi = (chi - Up * q0); + Up = log (Up); - /* p1 g1 */ - Up[0] = Up[0] + 2.0 * p1; + ncm_csq1d_state_set_up (state, NCM_CSQ1D_FRAME_ORIG, t, chi, Up); + break; + case NCM_CSQ1D_FRAME_NONADIAB1: + /* q1 L2p */ + chi = (chi + Up * q1); + Up = log (Up); - /* r1 g2 */ + ncm_csq1d_state_set_up (state, NCM_CSQ1D_FRAME_NONADIAB1, t, chi, Up); + break; + case NCM_CSQ1D_FRAME_NONADIAB2: { - const gdouble alpha = asinh (chi[0]); - const gdouble gamma = Up[0] - 0.5 * log1p (chi[0] * chi[0]); - const gdouble r1 = 0.5 * ncm_csq1d_eval_int_mnu2 (csq1d, model, t, self->k); + const gdouble p1 = ncm_csq1d_eval_int_qmnu2 (csq1d, model, t); + + /* q1 L2p */ + chi = (chi + Up * q1); + Up = log (Up); + + /* p1 g1 */ + Up = Up + 2.0 * p1; + + /* r1 g2 */ + { + const gdouble alpha = asinh (chi); + const gdouble gamma = Up - 0.5 * log1p (chi * chi); + const gdouble r1 = 0.5 * ncm_csq1d_eval_int_mnu2 (csq1d, model, t); - gdouble alphap, gammap; + gdouble alphap, gammap; - _ncm_csq1d_ct_g0g1 (alpha, gamma, -2.0 * r1, &alphap, &gammap); + _ncm_csq1d_ct_g0g1 (alpha, gamma, -2.0 * r1, &alphap, &gammap); - chi[0] = sinh (alphap); - Up[0] = gammap + 0.5 * log1p (chi[0] * chi[0]); + chi = sinh (alphap); + Up = gammap + 0.5 * log1p (chi * chi); + } + ncm_csq1d_state_set_up (state, NCM_CSQ1D_FRAME_NONADIAB2, t, chi, Up); + break; } - break; + default: + g_assert_not_reached (); + break; } - default: - g_assert_not_reached (); - break; } } /** - * ncm_csq1d_alpha_gamma_circle: + * ncm_csq1d_evolve_prop_vector: * @csq1d: a #NcmCSQ1D * @model: (allow-none): a #NcmModel - * @alpha: $\alpha$ variable - * @gamma: $\gamma$ variable - * @r: radius - * @theta: angle - * @alphap: (out): output $\alpha$ variable - * @gammap: (out): output $\gamma$ variable + * @initial_state: initial state + * @frame: frame + * @t: time $t$ * - * Computes the complex structure matrix parameters for a circle - * around the point $(\alpha, \gamma)$ with radius $r$ and angle - * $\theta$. + * Uses the propagator to evolve the state vector @initial_state to time $t$ and + * at frame @frame. * + * Returns: (transfer none): the state vector. */ -void -ncm_csq1d_alpha_gamma_circle (NcmCSQ1D *csq1d, NcmModel *model, const gdouble alpha, const gdouble gamma, const gdouble r, const gdouble theta, gdouble *alphap, gdouble *gammap) -{ - const gdouble ct = cos (theta); - const gdouble st = sin (theta); - const gdouble tr = tanh (r); - const gdouble ca = cosh (alpha); - const gdouble sa = sinh (alpha); - const gdouble t1 = cosh (r) * sa + ct * ca * sinh (r); - const gdouble t2 = -(2.0 * st * tr / (ca + tr * (st + ct * sa))); - - alphap[0] = asinh (t1); - gammap[0] = gamma + 0.5 * log1p (t2); +NcmCSQ1DState * +ncm_csq1d_evolve_prop_vector (NcmCSQ1D *csq1d, NcmModel *model, NcmCSQ1DState *initial_state, const NcmCSQ1DFrame frame, const gdouble t, NcmCSQ1DState *state) +{ + _ncm_csq1d_evolve_prop_vector (csq1d, model, initial_state, frame, t, state); + + return state; } diff --git a/numcosmo/math/ncm_csq1d.h b/numcosmo/math/ncm_csq1d.h index 0d48190b7..286aa66c9 100644 --- a/numcosmo/math/ncm_csq1d.h +++ b/numcosmo/math/ncm_csq1d.h @@ -1,4 +1,5 @@ /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */ + /*************************************************************************** * ncm_csq1d.h * @@ -35,37 +36,33 @@ G_BEGIN_DECLS #define NCM_TYPE_CSQ1D (ncm_csq1d_get_type ()) +#define NCM_TYPE_CSQ1D_STATE (ncm_csq1d_state_get_type ()) G_DECLARE_DERIVABLE_TYPE (NcmCSQ1D, ncm_csq1d, NCM, CSQ1D, GObject) +GType ncm_csq1d_state_get_type (void) G_GNUC_CONST; + struct _NcmCSQ1DClass { /*< private >*/ GObjectClass parent_class; - gdouble (*eval_xi) (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); - gdouble (*eval_dxi) (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); - gdouble (*eval_nu) (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); - gdouble (*eval_nu2) (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); - gdouble (*eval_m) (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); - gdouble (*eval_int_1_m) (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); - gdouble (*eval_int_mnu2) (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); - gdouble (*eval_int_qmnu2) (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); - gdouble (*eval_int_q2mnu2) (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); - gdouble (*eval_dm) (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); - gdouble (*eval_F1) (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); - gdouble (*eval_F2) (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); - gdouble (*eval_FN) (NcmCSQ1D *csq1d, NcmModel *model, const gint n, const gdouble t, const gdouble k); - gdouble (*eval_powspec_factor) (NcmCSQ1D *csq1d, NcmModel *model, const gdouble k); + gdouble (*eval_xi) (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); + gdouble (*eval_nu) (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); + gdouble (*eval_nu2) (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); + gdouble (*eval_m) (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); + gdouble (*eval_int_1_m) (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); + gdouble (*eval_int_mnu2) (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); + gdouble (*eval_int_qmnu2) (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); + gdouble (*eval_int_q2mnu2) (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); + gdouble (*eval_F1) (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); + gdouble (*eval_F2) (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); void (*prepare) (NcmCSQ1D *csq1d, NcmModel *model); /* Padding to allow 18 virtual functions without breaking ABI. */ gpointer padding[3]; }; -typedef struct _NcmCSQ1DSingFitUp NcmCSQ1DSingFitUp; -typedef struct _NcmCSQ1DSingFitUm NcmCSQ1DSingFitUm; - /** * NcmCSQ1DEvolState: * @NCM_CSQ1D_EVOL_STATE_INVALID: Invalid state @@ -73,7 +70,13 @@ typedef struct _NcmCSQ1DSingFitUm NcmCSQ1DSingFitUm; * @NCM_CSQ1D_EVOL_STATE_UP: $(\chi,\, U_+)$ state variables * @NCM_CSQ1D_EVOL_STATE_UM: $(\chi,\, U_-)$ state variables * - * Variables describing the system state. + * Variables describing the system evolution state. The state @NCM_CSQ1D_EVOL_STATE_ADIABATIC + * is used to describe the adiabatic evolution of the system, this state use the frame + * #NCM_CSQ1D_FRAME_ADIAB1 with the variables $(\alpha,\, \delta\gamma)$ to compute the evolution. + * The state @NCM_CSQ1D_EVOL_STATE_UP and @NCM_CSQ1D_EVOL_STATE_UM are used to describe the + * non-adiabatic evolution of the system, these states use the frame #NCM_CSQ1D_FRAME_ORIG with + * the variables $(\chi,\, U_+)$ and $(\chi,\, U_-)$ to compute the evolution, respectively. + * */ typedef enum _NcmCSQ1DEvolState { @@ -83,46 +86,134 @@ typedef enum _NcmCSQ1DEvolState NCM_CSQ1D_EVOL_STATE_UM, } NcmCSQ1DEvolState; +/** + * NcmCSQ1DInitialStateTypeType: + * @NCM_CSQ1D_INITIAL_CONDITION_TYPE_AD_HOC: Ad-hoc initial condition + * @NCM_CSQ1D_INITIAL_CONDITION_TYPE_ADIABATIC2: Second order adiabatic vacuum + * @NCM_CSQ1D_INITIAL_CONDITION_TYPE_ADIABATIC4: Fourth order adiabatic vacuum + * @NCM_CSQ1D_INITIAL_CONDITION_TYPE_NONADIABATIC2: Second order non-adiabatic vacuum + * + * Initial conditions for the system. The initial condition + * @NCM_CSQ1D_INITIAL_CONDITION_TYPE_AD_HOC is used to set an arbitrary initial + * condition. The initial conditions @NCM_CSQ1D_INITIAL_CONDITION_TYPE_ADIABATIC2, + * @NCM_CSQ1D_INITIAL_CONDITION_TYPE_ADIABATIC4 and + * @NCM_CSQ1D_INITIAL_CONDITION_TYPE_NONADIABATIC2 are used to set the initial + * conditions for the adiabatic and non-adiabatic vacuum initial conditions. + * + * If the initial condition is set to @NCM_CSQ1D_INITIAL_CONDITION_TYPE_AD_HOC + * the initial condition must be set using the function family ncm_csq1d_set_init_cond*. + * + */ +typedef enum _NcmCSQ1DInitialStateType /*< enum,underscore_name=NCM_CSQ1D_INITIAL_CONDITION_TYPE >*/ +{ + NCM_CSQ1D_INITIAL_CONDITION_TYPE_AD_HOC = 0, + NCM_CSQ1D_INITIAL_CONDITION_TYPE_ADIABATIC2, + NCM_CSQ1D_INITIAL_CONDITION_TYPE_ADIABATIC4, + NCM_CSQ1D_INITIAL_CONDITION_TYPE_NONADIABATIC2, + /*< private >*/ + NCM_CSQ1D_INITIAL_CONDITION_TYPE_LENGTH, +} NcmCSQ1DInitialStateType; + + +/** + * NcmCSQ1DFrame: + * @NCM_CSQ1D_FRAME_ORIG: Original frame + * @NCM_CSQ1D_FRAME_ADIAB1: Adiabatic frame 1 + * @NCM_CSQ1D_FRAME_ADIAB2: Adiabatic frame 2 + * @NCM_CSQ1D_FRAME_NONADIAB1: Non-adiabatic frame 1 + * @NCM_CSQ1D_FRAME_NONADIAB2: Non-adiabatic frame 2 + * + * Frames for the system. + * + */ +typedef enum _NcmCSQ1DFrame +{ + NCM_CSQ1D_FRAME_ORIG = 0, + NCM_CSQ1D_FRAME_ADIAB1, + NCM_CSQ1D_FRAME_ADIAB2, + NCM_CSQ1D_FRAME_NONADIAB1, + NCM_CSQ1D_FRAME_NONADIAB2, +} NcmCSQ1DFrame; + +/** + * NcmCSQ1DState: + * + * Represents the state of the system. + */ +typedef struct _NcmCSQ1DState +{ + /*< private >*/ + NcmCSQ1DFrame frame; + gdouble alpha; + gdouble gamma; + gdouble t; +} NcmCSQ1DState; + +/* State related functions */ + +NcmCSQ1DState *ncm_csq1d_state_new (void); +NcmCSQ1DState *ncm_csq1d_state_copy (NcmCSQ1DState *state); +void ncm_csq1d_state_free (NcmCSQ1DState *state); + +void ncm_csq1d_state_set_ag (NcmCSQ1DState *state, const NcmCSQ1DFrame frame, const gdouble t, const gdouble alpha, const gdouble gamma); +void ncm_csq1d_state_set_up (NcmCSQ1DState *state, const NcmCSQ1DFrame frame, const gdouble t, const gdouble chi, const gdouble Up); +void ncm_csq1d_state_set_um (NcmCSQ1DState *state, const NcmCSQ1DFrame frame, const gdouble t, const gdouble chi, const gdouble Um); + +gdouble ncm_csq1d_state_get_time (NcmCSQ1DState *state); +NcmCSQ1DFrame ncm_csq1d_state_get_frame (NcmCSQ1DState *state); + +void ncm_csq1d_state_get_ag (NcmCSQ1DState *state, gdouble *alpha, gdouble *gamma); +void ncm_csq1d_state_get_up (NcmCSQ1DState *state, gdouble *chi, gdouble *Up); +void ncm_csq1d_state_get_um (NcmCSQ1DState *state, gdouble *chi, gdouble *Um); +void ncm_csq1d_state_get_J (NcmCSQ1DState *state, gdouble *J11, gdouble *J12, gdouble *J22); + +void ncm_csq1d_state_get_phi_Pphi (NcmCSQ1DState *state, gdouble *phi, gdouble *Pphi); +void ncm_csq1d_state_get_poincare_half_plane (NcmCSQ1DState *state, gdouble *x, gdouble *lny); +void ncm_csq1d_state_get_poincare_disc (NcmCSQ1DState *state, gdouble *x, gdouble *y); +void ncm_csq1d_state_get_minkowski (NcmCSQ1DState *state, gdouble *x1, gdouble *x2); +void ncm_csq1d_state_get_circle (NcmCSQ1DState *state, const gdouble r, const gdouble theta, NcmCSQ1DState *cstate); +gdouble ncm_csq1d_state_compute_distance (NcmCSQ1DState *state, NcmCSQ1DState *state1); + +/* CSQ1D methods */ + NcmCSQ1D *ncm_csq1d_ref (NcmCSQ1D *csq1d); void ncm_csq1d_free (NcmCSQ1D *csq1d); void ncm_csq1d_clear (NcmCSQ1D **csq1d); void ncm_csq1d_set_reltol (NcmCSQ1D *csq1d, const gdouble reltol); void ncm_csq1d_set_abstol (NcmCSQ1D *csq1d, const gdouble abstol); -void ncm_csq1d_set_k (NcmCSQ1D *csq1d, const gdouble k); void ncm_csq1d_set_ti (NcmCSQ1D *csq1d, const gdouble ti); void ncm_csq1d_set_tf (NcmCSQ1D *csq1d, const gdouble tf); void ncm_csq1d_set_adiab_threshold (NcmCSQ1D *csq1d, const gdouble adiab_threshold); void ncm_csq1d_set_prop_threshold (NcmCSQ1D *csq1d, const gdouble prop_threshold); void ncm_csq1d_set_save_evol (NcmCSQ1D *csq1d, const gboolean save); -void ncm_csq1d_set_max_order_2 (NcmCSQ1D *csq1d, const gboolean truncate); -void ncm_csq1d_set_init_cond (NcmCSQ1D *csq1d, NcmCSQ1DEvolState state, const gdouble ti, const gdouble x, const gdouble y); +void ncm_csq1d_set_init_cond (NcmCSQ1D *csq1d, NcmModel *model, NcmCSQ1DEvolState evol_state, NcmCSQ1DState *initial_state); void ncm_csq1d_set_init_cond_adiab (NcmCSQ1D *csq1d, NcmModel *model, const gdouble ti); +void ncm_csq1d_set_initial_condition_type (NcmCSQ1D *csq1d, const NcmCSQ1DInitialStateType initial_condition_type); +void ncm_csq1d_set_vacuum_reltol (NcmCSQ1D *csq1d, const gdouble vacuum_reltol); +void ncm_csq1d_set_vacuum_max_time (NcmCSQ1D *csq1d, const gdouble vacuum_max_time); gdouble ncm_csq1d_get_reltol (NcmCSQ1D *csq1d); gdouble ncm_csq1d_get_abstol (NcmCSQ1D *csq1d); -gdouble ncm_csq1d_get_k (NcmCSQ1D *csq1d); gdouble ncm_csq1d_get_ti (NcmCSQ1D *csq1d); gdouble ncm_csq1d_get_tf (NcmCSQ1D *csq1d); gdouble ncm_csq1d_get_adiab_threshold (NcmCSQ1D *csq1d); gdouble ncm_csq1d_get_prop_threshold (NcmCSQ1D *csq1d); gboolean ncm_csq1d_get_save_evol (NcmCSQ1D *csq1d); -gboolean ncm_csq1d_get_max_order_2 (NcmCSQ1D *csq1d); - -NCM_INLINE gdouble ncm_csq1d_eval_xi (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); -NCM_INLINE gdouble ncm_csq1d_eval_dxi (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); -NCM_INLINE gdouble ncm_csq1d_eval_nu (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); -NCM_INLINE gdouble ncm_csq1d_eval_nu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); -NCM_INLINE gdouble ncm_csq1d_eval_m (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); -NCM_INLINE gdouble ncm_csq1d_eval_int_1_m (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); -NCM_INLINE gdouble ncm_csq1d_eval_int_mnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); -NCM_INLINE gdouble ncm_csq1d_eval_int_qmnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); -NCM_INLINE gdouble ncm_csq1d_eval_int_q2mnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); -NCM_INLINE gdouble ncm_csq1d_eval_dm (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); -NCM_INLINE gdouble ncm_csq1d_eval_F1 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); -NCM_INLINE gdouble ncm_csq1d_eval_F2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); -NCM_INLINE gdouble ncm_csq1d_eval_FN (NcmCSQ1D *csq1d, NcmModel *model, const gint n, const gdouble t, const gdouble k); -NCM_INLINE gdouble ncm_csq1d_eval_powspec_factor (NcmCSQ1D *csq1d, NcmModel *model, const gdouble k); +NcmCSQ1DInitialStateType ncm_csq1d_get_initial_condition_type (NcmCSQ1D *csq1d); +gdouble ncm_csq1d_get_vacuum_reltol (NcmCSQ1D *csq1d); +gdouble ncm_csq1d_get_vacuum_max_time (NcmCSQ1D *csq1d); + +NCM_INLINE gdouble ncm_csq1d_eval_xi (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); +NCM_INLINE gdouble ncm_csq1d_eval_nu (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); +NCM_INLINE gdouble ncm_csq1d_eval_nu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); +NCM_INLINE gdouble ncm_csq1d_eval_m (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); +NCM_INLINE gdouble ncm_csq1d_eval_int_1_m (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); +NCM_INLINE gdouble ncm_csq1d_eval_int_mnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); +NCM_INLINE gdouble ncm_csq1d_eval_int_qmnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); +NCM_INLINE gdouble ncm_csq1d_eval_int_q2mnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); +NCM_INLINE gdouble ncm_csq1d_eval_F1 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); +NCM_INLINE gdouble ncm_csq1d_eval_F2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); void ncm_csq1d_prepare (NcmCSQ1D *csq1d, NcmModel *model); @@ -131,32 +222,21 @@ GArray *ncm_csq1d_get_time_array (NcmCSQ1D *csq1d, gdouble *smallest_t); gboolean ncm_csq1d_find_adiab_time_limit (NcmCSQ1D *csq1d, NcmModel *model, gdouble t0, gdouble t1, const gdouble reltol, gdouble *ti); gdouble ncm_csq1d_find_adiab_max (NcmCSQ1D *csq1d, NcmModel *model, gdouble t0, gdouble t1, const gdouble border_eps, gdouble *F1_min, gdouble *t_Bl, gdouble *t_Bu); -void ncm_csq1d_eval_adiab_at (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, gdouble *alpha, gdouble *dgamma, gdouble *alpha_reltol, gdouble *dgamma_reltol); -void ncm_csq1d_eval_nonadiab_at (NcmCSQ1D *csq1d, NcmModel *model, guint nonadiab_frame, const gdouble t, gdouble *chi, gdouble *Up); -void ncm_csq1d_eval_at (NcmCSQ1D *csq1d, const gdouble t, gdouble *alpha, gdouble *dgamma); - -void ncm_csq1d_alpha_dgamma_to_phi_Pphi (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble alpha, const gdouble dgamma, gdouble *phi, gdouble *Pphi); -void ncm_csq1d_get_J_at (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, gdouble *J11, gdouble *J12, gdouble *J22); +NcmCSQ1DState *ncm_csq1d_compute_adiab (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, NcmCSQ1DState *state, gdouble *alpha_reltol, gdouble *dgamma_reltol); +NcmCSQ1DState *ncm_csq1d_compute_adiab_frame (NcmCSQ1D *csq1d, NcmModel *model, const NcmCSQ1DFrame frame, const gdouble t, NcmCSQ1DState *state, gdouble *alpha_reltol, gdouble *dgamma_reltol); +NcmCSQ1DState *ncm_csq1d_compute_nonadiab (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, NcmCSQ1DState *state); +NcmCSQ1DState *ncm_csq1d_compute_H (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, NcmCSQ1DState *state); +NcmCSQ1DState *ncm_csq1d_eval_at (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, NcmCSQ1DState *state); +NcmCSQ1DState *ncm_csq1d_eval_at_frame (NcmCSQ1D *csq1d, NcmModel *model, const NcmCSQ1DFrame frame, const gdouble t, NcmCSQ1DState *state); -void ncm_csq1d_get_H_poincare_hp (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, gdouble *x, gdouble *lny); -void ncm_csq1d_get_Hadiab_poincare_hp (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, gdouble *x, gdouble *lny); -void ncm_csq1d_get_poincare_hp (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, gdouble *x, gdouble *lny); -void ncm_csq1d_get_poincare_hp_frame (NcmCSQ1D *csq1d, NcmModel *model, guint adiab_frame, const gdouble t, gdouble *x, gdouble *lny); - -void ncm_csq1d_alpha_dgamma_to_minkowski_frame (NcmCSQ1D *csq1d, NcmModel *model, guint adiab_frame, const gdouble t, const gdouble alpha, const gdouble dgamma, gdouble *x1, gdouble *x2); -void ncm_csq1d_get_minkowski_frame (NcmCSQ1D *csq1d, NcmModel *model, guint adiab_frame, const gdouble t, gdouble *x1, gdouble *x2); - -void ncm_csq1d_get_H_poincare_disc (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, gdouble *x, gdouble *lny); -void ncm_csq1d_get_Hadiab_poincare_disc (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, gdouble *x, gdouble *lny); -void ncm_csq1d_get_poincare_disc (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, gdouble *x, gdouble *lny); +NcmCSQ1DState *ncm_csq1d_change_frame (NcmCSQ1D *csq1d, NcmModel *model, NcmCSQ1DState *state, NcmCSQ1DFrame frame); void ncm_csq1d_prepare_prop (NcmCSQ1D *csq1d, NcmModel *model, const gdouble ti, const gdouble tii, const gdouble tf); gdouble ncm_csq1d_get_tf_prop (NcmCSQ1D *csq1d); -void ncm_csq1d_get_prop_vector_chi_Up (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, gdouble *chi, gdouble *Up); -void ncm_csq1d_evolve_prop_vector_chi_Up (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const guint nonadiab_frame, gdouble chi_i, gdouble Up_i, gdouble *chi, gdouble *Up); +NcmCSQ1DState *ncm_csq1d_compute_prop_vector (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, NcmCSQ1DState *state); -void ncm_csq1d_alpha_gamma_circle (NcmCSQ1D *csq1d, NcmModel *model, const gdouble alpha, const gdouble gamma, const gdouble r, const gdouble theta, gdouble *alphap, gdouble *gammap); +NcmCSQ1DState *ncm_csq1d_evolve_prop_vector (NcmCSQ1D *csq1d, NcmModel *model, NcmCSQ1DState *initial_state, const NcmCSQ1DFrame frame, const gdouble t, NcmCSQ1DState *state); G_END_DECLS @@ -169,87 +249,63 @@ G_END_DECLS G_BEGIN_DECLS NCM_INLINE gdouble -ncm_csq1d_eval_xi (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k) -{ - return NCM_CSQ1D_GET_CLASS (csq1d)->eval_xi (csq1d, model, t, k); -} - -NCM_INLINE gdouble -ncm_csq1d_eval_dxi (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k) -{ - return NCM_CSQ1D_GET_CLASS (csq1d)->eval_dxi (csq1d, model, t, k); -} - -NCM_INLINE gdouble -ncm_csq1d_eval_nu (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k) -{ - return NCM_CSQ1D_GET_CLASS (csq1d)->eval_nu (csq1d, model, t, k); -} - -NCM_INLINE gdouble -ncm_csq1d_eval_nu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k) -{ - return NCM_CSQ1D_GET_CLASS (csq1d)->eval_nu2 (csq1d, model, t, k); -} - -NCM_INLINE gdouble -ncm_csq1d_eval_m (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k) +ncm_csq1d_eval_xi (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) { - return NCM_CSQ1D_GET_CLASS (csq1d)->eval_m (csq1d, model, t, k); + return NCM_CSQ1D_GET_CLASS (csq1d)->eval_xi (csq1d, model, t); } NCM_INLINE gdouble -ncm_csq1d_eval_int_1_m (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k) +ncm_csq1d_eval_nu (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) { - return NCM_CSQ1D_GET_CLASS (csq1d)->eval_int_1_m (csq1d, model, t, k); + return NCM_CSQ1D_GET_CLASS (csq1d)->eval_nu (csq1d, model, t); } NCM_INLINE gdouble -ncm_csq1d_eval_int_mnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k) +ncm_csq1d_eval_nu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) { - return NCM_CSQ1D_GET_CLASS (csq1d)->eval_int_mnu2 (csq1d, model, t, k); + return NCM_CSQ1D_GET_CLASS (csq1d)->eval_nu2 (csq1d, model, t); } NCM_INLINE gdouble -ncm_csq1d_eval_int_qmnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k) +ncm_csq1d_eval_m (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) { - return NCM_CSQ1D_GET_CLASS (csq1d)->eval_int_qmnu2 (csq1d, model, t, k); + return NCM_CSQ1D_GET_CLASS (csq1d)->eval_m (csq1d, model, t); } NCM_INLINE gdouble -ncm_csq1d_eval_int_q2mnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k) +ncm_csq1d_eval_int_1_m (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) { - return NCM_CSQ1D_GET_CLASS (csq1d)->eval_int_q2mnu2 (csq1d, model, t, k); + return NCM_CSQ1D_GET_CLASS (csq1d)->eval_int_1_m (csq1d, model, t); } NCM_INLINE gdouble -ncm_csq1d_eval_dm (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k) +ncm_csq1d_eval_int_mnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) { - return NCM_CSQ1D_GET_CLASS (csq1d)->eval_dm (csq1d, model, t, k); + return NCM_CSQ1D_GET_CLASS (csq1d)->eval_int_mnu2 (csq1d, model, t); } NCM_INLINE gdouble -ncm_csq1d_eval_F1 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k) +ncm_csq1d_eval_int_qmnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) { - return NCM_CSQ1D_GET_CLASS (csq1d)->eval_F1 (csq1d, model, t, k); + return NCM_CSQ1D_GET_CLASS (csq1d)->eval_int_qmnu2 (csq1d, model, t); } NCM_INLINE gdouble -ncm_csq1d_eval_F2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k) +ncm_csq1d_eval_int_q2mnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) { - return NCM_CSQ1D_GET_CLASS (csq1d)->eval_F2 (csq1d, model, t, k); + return NCM_CSQ1D_GET_CLASS (csq1d)->eval_int_q2mnu2 (csq1d, model, t); } NCM_INLINE gdouble -ncm_csq1d_eval_FN (NcmCSQ1D *csq1d, NcmModel *model, const gint n, const gdouble t, const gdouble k) +ncm_csq1d_eval_F1 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) { - return NCM_CSQ1D_GET_CLASS (csq1d)->eval_FN (csq1d, model, n, t, k); + return NCM_CSQ1D_GET_CLASS (csq1d)->eval_F1 (csq1d, model, t); } NCM_INLINE gdouble -ncm_csq1d_eval_powspec_factor (NcmCSQ1D *csq1d, NcmModel *model, const gdouble k) +ncm_csq1d_eval_F2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) { - return NCM_CSQ1D_GET_CLASS (csq1d)->eval_powspec_factor (csq1d, model, k); + return NCM_CSQ1D_GET_CLASS (csq1d)->eval_F2 (csq1d, model, t); } G_END_DECLS diff --git a/numcosmo/math/ncm_fftlog.c b/numcosmo/math/ncm_fftlog.c index cfd8c444d..16689b649 100644 --- a/numcosmo/math/ncm_fftlog.c +++ b/numcosmo/math/ncm_fftlog.c @@ -133,6 +133,7 @@ typedef struct _NcmFftlogPrivate gint N_2; gint Nf; gint Nf_2; + guint max_n; guint nderivs; guint pad; gdouble lnk0; @@ -171,6 +172,7 @@ enum PROP_LNK0, PROP_LR, PROP_N, + PROP_MAX_N, PROP_PAD, PROP_NORING, PROP_NAME, @@ -203,6 +205,7 @@ ncm_fftlog_init (NcmFftlog *fftlog) self->N_2 = 0; self->Nf = 0; self->Nf_2 = 0; + self->max_n = 0; self->pad = 0; self->noring = FALSE; self->prepared = FALSE; @@ -253,6 +256,9 @@ _ncm_fftlog_set_property (GObject *object, guint prop_id, const GValue *value, G case PROP_N: ncm_fftlog_set_size (fftlog, g_value_get_uint (value)); break; + case PROP_MAX_N: + ncm_fftlog_set_max_size (fftlog, g_value_get_uint (value)); + break; case PROP_PAD: ncm_fftlog_set_padding (fftlog, g_value_get_double (value)); break; @@ -308,6 +314,9 @@ _ncm_fftlog_get_property (GObject *object, guint prop_id, GValue *value, GParamS case PROP_N: g_value_set_uint (value, ncm_fftlog_get_size (fftlog)); break; + case PROP_MAX_N: + g_value_set_uint (value, ncm_fftlog_get_max_size (fftlog)); + break; case PROP_PAD: g_value_set_double (value, ncm_fftlog_get_padding (fftlog)); break; @@ -460,6 +469,21 @@ ncm_fftlog_class_init (NcmFftlogClass *klass) 0, G_MAXUINT, 10, G_PARAM_READWRITE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB)); + /** + * NcmFftlog:max-n: + * + * The maximum number of knots in the fundamental interval. + * This limit is used when calibrating the number of knots. + * + */ + g_object_class_install_property (object_class, + PROP_MAX_N, + g_param_spec_uint ("max-n", + NULL, + "Maximum number of knots", + 0, G_MAXUINT, 100000, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB)); + /** * NcmFftlog:padding: * @@ -515,6 +539,12 @@ ncm_fftlog_class_init (NcmFftlogClass *klass) "Whether to use evaluation interval", FALSE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB)); + + /** + * NcmFftlog:use-smooth-padding: + * + * Whether to use a smooth padding + */ g_object_class_install_property (object_class, PROP_SMOOTH_PADDING, g_param_spec_boolean ("use-smooth-padding", @@ -522,6 +552,13 @@ ncm_fftlog_class_init (NcmFftlogClass *klass) "Whether to use a smooth padding", FALSE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB)); + + /** + * NcmFftlog:smooth-padding-scale: + * + * Log10 of the smoothing scale. + * + */ g_object_class_install_property (object_class, PROP_SMOOTH_PADDING_SCALE, g_param_spec_double ("smooth-padding-scale", @@ -529,6 +566,13 @@ ncm_fftlog_class_init (NcmFftlogClass *klass) "Log10 of the smoothing scale", -G_MAXDOUBLE, +G_MAXDOUBLE, -200.0, G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB)); + + /** + * NcmFftlog:eval-r-min: + * + * The minimum value of the evaluation interval. + * + */ g_object_class_install_property (object_class, PROP_EVAL_R_MIN, g_param_spec_double ("eval-r-min", @@ -536,6 +580,13 @@ ncm_fftlog_class_init (NcmFftlogClass *klass) "Evaluation r_min", 0.0, G_MAXDOUBLE, 0.0, G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB)); + + /** + * NcmFftlog:eval-r-max: + * + * The maximum value of the evaluation interval. + * + */ g_object_class_install_property (object_class, PROP_EVAL_R_MAX, g_param_spec_double ("eval-r-max", @@ -826,6 +877,37 @@ ncm_fftlog_set_size (NcmFftlog *fftlog, guint n) #endif /* HAVE_FFTW3 */ } +/** + * ncm_fftlog_set_max_size: + * @fftlog: a #NcmFftlog + * @max_n: maximum number of knots + * + * Sets the maximum number of knots in the fundamental interval. + * + */ +void +ncm_fftlog_set_max_size (NcmFftlog *fftlog, guint max_n) +{ + NcmFftlogPrivate * const self = ncm_fftlog_get_instance_private (fftlog); + + self->max_n = max_n; +} + +/** + * ncm_fftlog_get_max_size: + * @fftlog: a #NcmFftlog + * + * Gets the maximum number of knots in the fundamental interval. + * + */ +guint +ncm_fftlog_get_max_size (NcmFftlog *fftlog) +{ + NcmFftlogPrivate * const self = ncm_fftlog_get_instance_private (fftlog); + + return self->max_n; +} + /** * ncm_fftlog_set_padding: * @fftlog: a #NcmFftlog @@ -1552,6 +1634,14 @@ ncm_fftlog_calibrate_size_gsl (NcmFftlog *fftlog, gsl_function *Fk, const gdoubl ncm_vector_free (eval_lnr_vec); g_clear_pointer (&s, g_free); + if (self->N > (gint) self->max_n) + { + g_message ("ncm_fftlog_calibrate_size_gsl: maximum number of knots reached. " + "Requested precision %e, achieved precision %e.", reltol, lreltol); + + return; + } + if (lreltol > reltol) ncm_fftlog_calibrate_size_gsl (fftlog, Fk, reltol); } diff --git a/numcosmo/math/ncm_fftlog.h b/numcosmo/math/ncm_fftlog.h index 26491d995..0a83f1d3f 100644 --- a/numcosmo/math/ncm_fftlog.h +++ b/numcosmo/math/ncm_fftlog.h @@ -76,6 +76,9 @@ gdouble ncm_fftlog_get_lnk0 (NcmFftlog *fftlog); void ncm_fftlog_set_size (NcmFftlog *fftlog, guint n); +void ncm_fftlog_set_max_size (NcmFftlog *fftlog, guint max_n); +guint ncm_fftlog_get_max_size (NcmFftlog *fftlog); + void ncm_fftlog_set_padding (NcmFftlog *fftlog, gdouble pad_p); gdouble ncm_fftlog_get_padding (NcmFftlog *fftlog); diff --git a/numcosmo/math/ncm_powspec.c b/numcosmo/math/ncm_powspec.c index 69346dba0..12e884e7b 100644 --- a/numcosmo/math/ncm_powspec.c +++ b/numcosmo/math/ncm_powspec.c @@ -685,7 +685,7 @@ ncm_powspec_get_nknots (NcmPowspec *powspec, guint *Nz, guint *Nk) /** * ncm_powspec_prepare: * @powspec: a #NcmPowspec - * @model: a #NcmModel + * @model: (allow-none): a #NcmModel * * Prepares the power spectrum @powspec using the model @model. * @@ -700,7 +700,7 @@ ncm_powspec_prepare (NcmPowspec *powspec, NcmModel *model) /** * ncm_powspec_prepare_if_needed: * @powspec: a #NcmPowspec - * @model: a #NcmModel + * @model: (allow-none): a #NcmModel * * Prepares the object @powspec using the model @model if it was changed * since last preparation. @@ -719,7 +719,7 @@ ncm_powspec_prepare_if_needed (NcmPowspec *powspec, NcmModel *model) /** * ncm_powspec_eval: * @powspec: a #NcmPowspec - * @model: a #NcmModel + * @model: (allow-none): a #NcmModel * @z: time $z$ * @k: mode $k$ * @@ -736,7 +736,7 @@ ncm_powspec_eval (NcmPowspec *powspec, NcmModel *model, const gdouble z, const g /** * ncm_powspec_eval_vec: * @powspec: a #NcmPowspec - * @model: a #NcmModel + * @model: (allow-none): a #NcmModel * @z: time $z$ * @k: a #NcmVector * @Pk: a #NcmVector @@ -754,7 +754,7 @@ ncm_powspec_eval_vec (NcmPowspec *powspec, NcmModel *model, const gdouble z, Ncm /** * ncm_powspec_get_spline_2d: * @powspec: a #NcmPowspec - * @model: a #NcmModel compatible with @powspec + * @model: (allow-none): a #NcmModel * * Compute a 2D spline for the power spectrum. * @@ -810,7 +810,7 @@ _ncm_powspec_var_tophat_R_integ (gpointer user_data, gdouble lnk, gdouble weight /** * ncm_powspec_var_tophat_R: * @powspec: a #NcmPowspec - * @model: a #NcmModel + * @model: (allow-none): a #NcmModel * @reltol: relative tolerance for integration * @z: the value of $z$ * @R: the value of $R$ @@ -851,7 +851,7 @@ ncm_powspec_var_tophat_R (NcmPowspec *powspec, NcmModel *model, const gdouble re /** * ncm_powspec_sigma_tophat_R: * @powspec: a #NcmPowspec - * @model: a #NcmModel + * @model: (allow-none): a #NcmModel * @reltol: relative tolerance for integration * @z: the value of $z$ * @R: the value of $R$ @@ -881,7 +881,7 @@ _ncm_powspec_corr3D_integ (gpointer user_data, gdouble lnk, gdouble weight) /** * ncm_powspec_corr3d: * @powspec: a #NcmPowspec - * @model: a #NcmModel + * @model: (allow-none): a #NcmModel * @reltol: relative tolerance for integration * @z: the value of $z$ * @r: the value of $r$ @@ -932,7 +932,7 @@ _ncm_powspec_sproj_integ (gpointer user_data, gdouble lnk, gdouble weight) /** * ncm_powspec_sproj: * @powspec: a #NcmPowspec - * @model: a #NcmModel + * @model: (allow-none): a #NcmModel * @reltol: relative tolerance for integration * @ell: the value of $\ell$ * @z1: the value of $z_1$ diff --git a/numcosmo/math/ncm_powspec_filter.c b/numcosmo/math/ncm_powspec_filter.c index 34ed622e9..89bb25fe3 100644 --- a/numcosmo/math/ncm_powspec_filter.c +++ b/numcosmo/math/ncm_powspec_filter.c @@ -77,6 +77,8 @@ enum PROP_ZF, PROP_RELTOL, PROP_RELTOL_Z, + PROP_MAX_K_KNOTS, + PROP_MAX_Z_KNOTS, PROP_POWERSPECTRUM, PROP_SIZE, }; @@ -96,6 +98,8 @@ struct _NcmPowspecFilter gboolean calibrated; gdouble reltol; gdouble reltol_z; + guint max_k_knots; + guint max_z_knots; NcmSpline2d *var; NcmSpline2d *dvar; NcmModelCtrl *ctrl; @@ -115,6 +119,8 @@ ncm_powspec_filter_init (NcmPowspecFilter *psf) psf->zf = 0.0; psf->reltol = 0.0; psf->reltol_z = 0.0; + psf->max_k_knots = 0; + psf->max_z_knots = 0; psf->type = NCM_POWSPEC_FILTER_TYPE_LEN; psf->fftlog = NULL; psf->calibrated = FALSE; @@ -151,6 +157,12 @@ _ncm_powspec_filter_set_property (GObject *object, guint prop_id, const GValue * case PROP_RELTOL_Z: psf->reltol_z = g_value_get_double (value); break; + case PROP_MAX_K_KNOTS: + psf->max_k_knots = g_value_get_uint (value); + break; + case PROP_MAX_Z_KNOTS: + psf->max_z_knots = g_value_get_uint (value); + break; case PROP_POWERSPECTRUM: psf->ps = g_value_dup_object (value); psf->zi = ncm_powspec_get_zi (psf->ps); @@ -189,6 +201,12 @@ _ncm_powspec_filter_get_property (GObject *object, guint prop_id, GValue *value, case PROP_RELTOL_Z: g_value_set_double (value, psf->reltol_z); break; + case PROP_MAX_K_KNOTS: + g_value_set_uint (value, psf->max_k_knots); + break; + case PROP_MAX_Z_KNOTS: + g_value_set_uint (value, psf->max_z_knots); + break; case PROP_POWERSPECTRUM: g_value_set_object (value, psf->ps); break; @@ -314,6 +332,32 @@ ncm_powspec_filter_class_init (NcmPowspecFilterClass *klass) GSL_DBL_EPSILON, 1.0, 1.0e-6, G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB)); + /** + * NcmPowspecFilter:max-k-knots: + * + * The maximum number of knots in the k direction. + */ + g_object_class_install_property (object_class, + PROP_MAX_K_KNOTS, + g_param_spec_uint ("max-k-knots", + NULL, + "Maximum number of knots in the k direction", + 0, G_MAXUINT, 10000, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB)); + + /** + * NcmPowspecFilter:max-z-knots: + * + * The maximum number of knots in the redshift direction. + */ + g_object_class_install_property (object_class, + PROP_MAX_Z_KNOTS, + g_param_spec_uint ("max-z-knots", + NULL, + "Maximum number of knots in the redshift direction", + 0, G_MAXUINT, 1000, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB)); + /** * NcmPowspecFilter:type: * @@ -535,6 +579,7 @@ ncm_powspec_filter_prepare (NcmPowspecFilter *psf, NcmModel *model) ncm_powspec_get_nknots (psf->ps, &N_z, &N_k); + ncm_fftlog_set_max_size (psf->fftlog, psf->max_k_knots); ncm_fftlog_calibrate_size_gsl (psf->fftlog, &F, psf->reltol); N_k = ncm_fftlog_get_size (psf->fftlog); diff --git a/numcosmo/math/ncm_powspec_spline2d.c b/numcosmo/math/ncm_powspec_spline2d.c new file mode 100644 index 000000000..45dcb49b2 --- /dev/null +++ b/numcosmo/math/ncm_powspec_spline2d.c @@ -0,0 +1,359 @@ +/*************************************************************************** + * ncm_powspec_spline2d.c + * + * Tue February 16 17:00:52 2016 + * Copyright 2016 Sandro Dias Pinto Vitenti + * + ****************************************************************************/ +/* + * ncm_powspec_spline2d.c + * Copyright (C) 2016 Sandro Dias Pinto Vitenti + * + * numcosmo is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * numcosmo is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +/** + * SECTION:ncm_powspec_spline2d + * @title: NcmPowspecSpline2d + * @short_description: Power spectrum implementation using a 2D spline + * @stability: Stable + * @include: numcosmo/math/ncm_powspec_spline2d.h + * + * #NcmPowspecSpline2d is a power spectrum implementation using a 2D spline. + * + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif /* HAVE_CONFIG_H */ +#include "build_cfg.h" + +#include "math/ncm_powspec_spline2d.h" +#include "math/ncm_serialize.h" +#include "math/ncm_cfg.h" +#include "math/ncm_integral1d_ptr.h" +#include "math/ncm_memory_pool.h" +#include "math/ncm_sf_sbessel.h" +#include "math/ncm_c.h" +#include "math/ncm_spline2d_bicubic.h" + +#ifndef NUMCOSMO_GIR_SCAN +#include +#endif /* NUMCOSMO_GIR_SCAN */ + +typedef struct _NcmPowspecSpline2dPrivate +{ + /*< private > */ + NcmSpline2d *spline2d; + gdouble intern_lnkmin; + gdouble intern_lnkmax; + gdouble intern_lnkmax_m1; +} NcmPowspecSpline2dPrivate; + +struct _NcmPowspecSpline2d +{ + NcmPowspec parent_instance; +}; + +enum +{ + PROP_0, + PROP_SPLINE2D, +}; + +G_DEFINE_TYPE_WITH_PRIVATE (NcmPowspecSpline2d, ncm_powspec_spline2d, NCM_TYPE_POWSPEC) + +static void +ncm_powspec_spline2d_init (NcmPowspecSpline2d *ps_s2d) +{ + NcmPowspecSpline2dPrivate * const self = ncm_powspec_spline2d_get_instance_private (ps_s2d); + + self->spline2d = NULL; + self->intern_lnkmin = 0.0; + self->intern_lnkmax = 0.0; + self->intern_lnkmax_m1 = 0.0; +} + +static void +_ncm_powspec_spline2d_dispose (GObject *object) +{ + NcmPowspecSpline2d *ps_s2d = NCM_POWSPEC_SPLINE2D (object); + NcmPowspecSpline2dPrivate * const self = ncm_powspec_spline2d_get_instance_private (ps_s2d); + + ncm_spline2d_clear (&self->spline2d); + + /* Chain up : end */ + G_OBJECT_CLASS (ncm_powspec_spline2d_parent_class)->dispose (object); +} + +static void +_ncm_powspec_spline2d_finalize (GObject *object) +{ + /* Chain up : end */ + G_OBJECT_CLASS (ncm_powspec_spline2d_parent_class)->finalize (object); +} + +static void +_ncm_powspec_spline2d_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +{ + NcmPowspecSpline2d *ps_s2d = NCM_POWSPEC_SPLINE2D (object); + + g_return_if_fail (NCM_IS_POWSPEC_SPLINE2D (object)); + + switch (prop_id) + { + case PROP_SPLINE2D: + ncm_powspec_spline2d_set_spline2d (ps_s2d, g_value_get_object (value)); + break; + default: /* LCOV_EXCL_LINE */ + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); /* LCOV_EXCL_LINE */ + break; /* LCOV_EXCL_LINE */ + } +} + +static void +_ncm_powspec_spline2d_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +{ + NcmPowspecSpline2d *ps_s2d = NCM_POWSPEC_SPLINE2D (object); + + g_return_if_fail (NCM_IS_POWSPEC_SPLINE2D (object)); + + switch (prop_id) + { + case PROP_SPLINE2D: + g_value_set_object (value, ncm_powspec_spline2d_peek_spline2d (ps_s2d)); + break; + default: /* LCOV_EXCL_LINE */ + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); /* LCOV_EXCL_LINE */ + break; /* LCOV_EXCL_LINE */ + } +} + +static void +_ncm_powspec_spline2d_prepare (NcmPowspec *powspec, NcmModel *model) +{ + NcmPowspecSpline2d *ps_s2d = NCM_POWSPEC_SPLINE2D (powspec); + NcmPowspecSpline2dPrivate * const self = ncm_powspec_spline2d_get_instance_private (ps_s2d); + + if (!ncm_spline2d_is_init (self->spline2d)) + ncm_spline2d_prepare (self->spline2d); +} + +static gdouble +_ncm_powspec_spline2d_eval (NcmPowspec *powspec, NcmModel *model, const gdouble z, const gdouble k) +{ + NcmPowspecSpline2d *ps_s2d = NCM_POWSPEC_SPLINE2D (powspec); + NcmPowspecSpline2dPrivate * const self = ncm_powspec_spline2d_get_instance_private (ps_s2d); + const gdouble lnk = log (k); + + if (lnk < self->intern_lnkmin) + { + const gdouble lnPkmin = ncm_spline2d_eval (self->spline2d, z, self->intern_lnkmin); + + return exp (lnPkmin + 3.0 * (lnk - self->intern_lnkmin)); + } + else if (lnk > self->intern_lnkmax) + { + const gdouble lnkmax = self->intern_lnkmax; + const gdouble kmax = exp (self->intern_lnkmax); + const gdouble lnPkmax = ncm_spline2d_eval (self->spline2d, z, self->intern_lnkmax); + const gdouble lnPkmax_m1 = ncm_spline2d_eval (self->spline2d, z, self->intern_lnkmax_m1); + const gdouble delta_lnk = lnk - lnkmax; + const gdouble lambda = (lnPkmax - lnPkmax_m1) / (self->intern_lnkmax - self->intern_lnkmax_m1); + + return exp (lnPkmax - 0.5 * 10.0 * gsl_pow_2 (delta_lnk) + lambda * delta_lnk); + } + else + { + return exp (ncm_spline2d_eval (self->spline2d, z, lnk)); + } +} + +static void +_ncm_powspec_spline2d_eval_vec (NcmPowspec *powspec, NcmModel *model, const gdouble z, NcmVector *k, NcmVector *Pk) +{ + NcmPowspecSpline2d *ps_s2d = NCM_POWSPEC_SPLINE2D (powspec); + NcmPowspecSpline2dPrivate * const self = ncm_powspec_spline2d_get_instance_private (ps_s2d); + guint n = ncm_vector_len (k); + guint i; + + g_assert_cmpuint (n, ==, ncm_vector_len (Pk)); + + for (i = 0; i < n; i++) + { + const gdouble k_i = ncm_vector_get (k, i); + + ncm_vector_set (Pk, i, _ncm_powspec_spline2d_eval (powspec, model, z, k_i)); + } +} + +void +_ncm_powspec_spline2d_get_nknots (NcmPowspec *powspec, guint *Nz, guint *Nk) +{ + NcmPowspecSpline2d *ps_s2d = NCM_POWSPEC_SPLINE2D (powspec); + NcmPowspecSpline2dPrivate * const self = ncm_powspec_spline2d_get_instance_private (ps_s2d); + + Nz[0] = ncm_vector_len (ncm_spline2d_peek_xv (self->spline2d)); + Nk[0] = ncm_vector_len (ncm_spline2d_peek_yv (self->spline2d)); +} + +static NcmSpline2d * +_ncm_powspec_spline2d_get_spline_2d (NcmPowspec *powspec, NcmModel *model) +{ + NcmPowspecSpline2d *ps_s2d = NCM_POWSPEC_SPLINE2D (powspec); + NcmPowspecSpline2dPrivate * const self = ncm_powspec_spline2d_get_instance_private (ps_s2d); + + return ncm_spline2d_ref (self->spline2d); +} + +static void +ncm_powspec_spline2d_class_init (NcmPowspecSpline2dClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + NcmPowspecClass *powspec_class = NCM_POWSPEC_CLASS (klass); + + object_class->set_property = &_ncm_powspec_spline2d_set_property; + object_class->get_property = &_ncm_powspec_spline2d_get_property; + object_class->dispose = &_ncm_powspec_spline2d_dispose; + object_class->finalize = &_ncm_powspec_spline2d_finalize; + + /** + * NcmPowspecSpline2d:reltol: + * + * The relative tolerance on the interpolation error. + */ + g_object_class_install_property (object_class, + PROP_SPLINE2D, + g_param_spec_object ("spline2d", + NULL, + "Spline2d representing the values of the power-spectrum", + NCM_TYPE_SPLINE2D, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB)); + + powspec_class->prepare = &_ncm_powspec_spline2d_prepare; + powspec_class->eval = &_ncm_powspec_spline2d_eval; + powspec_class->eval_vec = &_ncm_powspec_spline2d_eval_vec; + powspec_class->get_nknots = &_ncm_powspec_spline2d_get_nknots; + powspec_class->get_spline_2d = &_ncm_powspec_spline2d_get_spline_2d; +} + +NcmPowspecSpline2d * +ncm_powspec_spline2d_new (NcmSpline2d *spline2d) +{ + NcmPowspecSpline2d *ps_s2d = g_object_new (NCM_TYPE_POWSPEC_SPLINE2D, + "spline2d", spline2d, + NULL); + + return ps_s2d; +} + +/** + * ncm_powspec_spline2d_ref: + * @ps_s2d: a #NcmPowspecSpline2d + * + * Increases the reference count of @ps_s2d by one atomically. + * + * Returns: (transfer full): @ps_s2d. + */ +NcmPowspecSpline2d * +ncm_powspec_spline2d_ref (NcmPowspecSpline2d *ps_s2d) +{ + return g_object_ref (ps_s2d); +} + +/** + * ncm_powspec_spline2d_free: + * @ps_s2d: a #NcmPowspecSpline2d + * + * Atomically decrements the reference count of @ps_s2d by one. + * If the reference count drops to 0, + * all memory allocated by @ps_s2d is released. + * + */ +void +ncm_powspec_spline2d_free (NcmPowspecSpline2d *ps_s2d) +{ + g_object_unref (ps_s2d); +} + +/** + * ncm_powspec_spline2d_clear: + * @ps_s2d: a #NcmPowspecSpline2d + * + * If @ps_s2d is different from NULL, + * atomically decrements the reference count of @powspec by one. + * If the reference count drops to 0, + * all memory allocated by @powspec is released and @powspec is set to NULL. + * + */ +void +ncm_powspec_spline2d_clear (NcmPowspecSpline2d **ps_s2d) +{ + g_clear_object (ps_s2d); +} + +/** + * ncm_powspec_spline2d_set_spline2d: + * @ps_s2d: a #NcmPowspecSpline2d + * @spline2d: a NcmSpline2d + * + * Sets the #NcmSpline2d to @spline2d. + * + */ +void +ncm_powspec_spline2d_set_spline2d (NcmPowspecSpline2d *ps_s2d, NcmSpline2d *spline2d) +{ + NcmPowspecSpline2dPrivate * const self = ncm_powspec_spline2d_get_instance_private (ps_s2d); + + g_assert_nonnull (spline2d); + + ncm_spline2d_clear (&self->spline2d); + + self->spline2d = ncm_spline2d_ref (spline2d); + + { + NcmVector *z_vec = ncm_spline2d_peek_xv (self->spline2d); + NcmVector *lnk_vec = ncm_spline2d_peek_yv (self->spline2d); + const gdouble lnkmin = ncm_vector_get (lnk_vec, 0); + const gdouble lnkmax = ncm_vector_get (lnk_vec, ncm_vector_len (lnk_vec) - 1); + const gdouble lnkmax_m1 = lnkmax - 1.0; + + self->intern_lnkmin = lnkmin; + self->intern_lnkmax = lnkmax; + self->intern_lnkmax_m1 = lnkmax_m1; + + ncm_powspec_set_kmin (NCM_POWSPEC (ps_s2d), exp (lnkmin)); + ncm_powspec_set_kmax (NCM_POWSPEC (ps_s2d), exp (lnkmax)); + + ncm_powspec_set_zi (NCM_POWSPEC (ps_s2d), ncm_vector_get (z_vec, 0)); + ncm_powspec_set_zf (NCM_POWSPEC (ps_s2d), ncm_vector_get (z_vec, ncm_vector_len (z_vec) - 1)); + } +} + +/** + * ncm_powspec_spline2d_peek_spline2d: + * @ps_s2d: a #NcmPowspecSpline2d + * + * Peeks the current #NcmSpline2d. + * + * Returns: (transfer none): the current #NcmSpline2d. + */ +NcmSpline2d * +ncm_powspec_spline2d_peek_spline2d (NcmPowspecSpline2d *ps_s2d) +{ + NcmPowspecSpline2dPrivate * const self = ncm_powspec_spline2d_get_instance_private (ps_s2d); + + return self->spline2d; +} + diff --git a/numcosmo/math/ncm_powspec_spline2d.h b/numcosmo/math/ncm_powspec_spline2d.h new file mode 100644 index 000000000..c86045a79 --- /dev/null +++ b/numcosmo/math/ncm_powspec_spline2d.h @@ -0,0 +1,55 @@ +/*************************************************************************** + * ncm_powspec_spline2d.h + * + * Tue February 16 17:01:03 2016 + * Copyright 2016 Sandro Dias Pinto Vitenti + * + ****************************************************************************/ +/* + * ncm_powspec_spline2d.h + * Copyright (C) 2016 Sandro Dias Pinto Vitenti + * + * numcosmo is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * numcosmo is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef _NCM_POWSPEC_SPLINE2D_H_ +#define _NCM_POWSPEC_SPLINE2D_H_ + +#include +#include +#include +#include +#include +#include +#include + +G_BEGIN_DECLS + +#define NCM_TYPE_POWSPEC_SPLINE2D (ncm_powspec_spline2d_get_type ()) + +G_DECLARE_FINAL_TYPE (NcmPowspecSpline2d, ncm_powspec_spline2d, NCM, POWSPEC_SPLINE2D, NcmPowspec) + +NcmPowspecSpline2d *ncm_powspec_spline2d_new (NcmSpline2d * spline2d); +NcmPowspecSpline2d *ncm_powspec_spline2d_ref (NcmPowspecSpline2d *ps_s2d); + +void ncm_powspec_spline2d_free (NcmPowspecSpline2d *ps_s2d); +void ncm_powspec_spline2d_clear (NcmPowspecSpline2d **ps_s2d); + +void ncm_powspec_spline2d_set_spline2d (NcmPowspecSpline2d *ps_s2d, NcmSpline2d *spline2d); +NcmSpline2d *ncm_powspec_spline2d_peek_spline2d (NcmPowspecSpline2d *ps_s2d); + +G_END_DECLS + +#endif /* _NCM_POWSPEC_SPLINE2D_H_ */ + diff --git a/numcosmo/math/ncm_util.c b/numcosmo/math/ncm_util.c index bdd891d81..723df5fbb 100644 --- a/numcosmo/math/ncm_util.c +++ b/numcosmo/math/ncm_util.c @@ -513,20 +513,21 @@ ncm_util_mln_1mIexpzA_1pIexpmzA (const gdouble rho, const gdouble theta, const g if (exp (fabs (rho)) * fabs (A) < 0.1) { - const gdouble A2 = A * A; - gdouble Apow_two_ip1 = A; + const double complex z_p_ipi_2 = z + 0.5 * M_PI * I; + const double complex T = cexp (z_p_ipi_2); + double complex Tn = T; + gdouble An = A; gint i; zp = 0.0; for (i = 0; ; i++) { - const gdouble two_ip1 = (2.0 * i + 1.0); - const gdouble ip1 = (i + 1.0); - double complex dz = (2.0 * I * ccosh (two_ip1 * z) / two_ip1 - csinh (2.0 * ip1 * z) * A / ip1) * - ((i % 2 == 0) ? 1.0 : -1.0) * Apow_two_ip1; + const gdouble n = i + 1.0; + double complex dz = (1.0 / Tn - Tn) * An / n; - Apow_two_ip1 *= A2; + An *= A; + Tn *= T; zp += dz; @@ -534,7 +535,7 @@ ncm_util_mln_1mIexpzA_1pIexpmzA (const gdouble rho, const gdouble theta, const g break; } - zp = z + zp; + zp = z - zp; } else { @@ -553,7 +554,7 @@ ncm_util_mln_1mIexpzA_1pIexpmzA (const gdouble rho, const gdouble theta, const g * @abstol: the absolute precision * * Compare x and y and return -1 if x < y, 0 if x == y and 1 if x > y, - * all comparisons are done with precision @prec. + * all comparisons are done with precision @reltol and @abstol. * * Returns: -1, 0, 1. */ diff --git a/numcosmo/meson.build b/numcosmo/meson.build index 4bd6d2f3b..4514bf398 100644 --- a/numcosmo/meson.build +++ b/numcosmo/meson.build @@ -102,6 +102,7 @@ ncm_sources = files( 'math/ncm_powspec_corr3d.c', 'math/ncm_powspec_filter.c', 'math/ncm_powspec_sphere_proj.c', + 'math/ncm_powspec_spline2d.c', 'math/ncm_prior.c', 'math/ncm_prior_flat.c', 'math/ncm_prior_flat_func.c', @@ -235,6 +236,7 @@ ncm_headers = files( 'math/ncm_powspec_corr3d.h', 'math/ncm_powspec_filter.h', 'math/ncm_powspec_sphere_proj.h', + 'math/ncm_powspec_spline2d.h', 'math/ncm_prior.h', 'math/ncm_prior_flat.h', 'math/ncm_prior_flat_func.h', @@ -394,6 +396,7 @@ nc_headers = files( 'model/nc_hicosmo_lcdm.h', 'model/nc_hicosmo_qconst.h', 'model/nc_hicosmo_qgrw.h', + 'model/nc_hicosmo_qgw.h', 'model/nc_hicosmo_qlinear.h', 'model/nc_hicosmo_qrbf.h', 'model/nc_hicosmo_qspline.h', @@ -410,6 +413,7 @@ nc_headers = files( 'perturbations/nc_hipert_boltzmann_std.h', 'perturbations/nc_hipert_comp.h', 'perturbations/nc_hipert_comp_pb.h', + 'perturbations/nc_hipert_em.h', 'perturbations/nc_hipert_first_order.h', 'perturbations/nc_hipert_grav.h', 'perturbations/nc_hipert_grav_einstein.h', @@ -439,7 +443,7 @@ nc_headers = files( 'nc_planck_fi_cor_ttteee.h', 'nc_powspec_ml.h', 'nc_powspec_ml_cbe.h', - 'nc_powspec_ml_fix_spline.h', + 'nc_powspec_ml_spline.h', 'nc_powspec_ml_transfer.h', 'nc_powspec_mnl.h', 'nc_powspec_mnl_halofit.h', @@ -550,6 +554,7 @@ nc_sources = files( 'model/nc_hicosmo_lcdm.c', 'model/nc_hicosmo_qconst.c', 'model/nc_hicosmo_qgrw.c', + 'model/nc_hicosmo_qgw.c', 'model/nc_hicosmo_qlinear.c', 'model/nc_hicosmo_qrbf.c', 'model/nc_hicosmo_qspline.c', @@ -566,6 +571,7 @@ nc_sources = files( 'perturbations/nc_hipert_boltzmann_std.c', 'perturbations/nc_hipert_comp.c', 'perturbations/nc_hipert_comp_pb.c', + 'perturbations/nc_hipert_em.c', 'perturbations/nc_hipert_first_order.c', 'perturbations/nc_hipert_grav.c', 'perturbations/nc_hipert_grav_einstein.c', @@ -595,7 +601,7 @@ nc_sources = files( 'nc_planck_fi_cor_ttteee.c', 'nc_powspec_ml.c', 'nc_powspec_ml_cbe.c', - 'nc_powspec_ml_fix_spline.c', + 'nc_powspec_ml_spline.c', 'nc_powspec_ml_transfer.c', 'nc_powspec_mnl.c', 'nc_powspec_mnl_halofit.c', @@ -756,7 +762,7 @@ libnumcosmo_dep = declare_dependency( # Generate pkg-config files # Code using NumCosmo frequently depends directly on gsl, glib, gobject, and gio, so we -# include them in the Requires field. +# include them in the Requires field. # This happends mostly because of inlining, but also because of the many macros defined # in the glib headers. pkg.generate( diff --git a/numcosmo/model/nc_hicosmo_Vexp.c b/numcosmo/model/nc_hicosmo_Vexp.c index fb9974906..89bfe57e3 100644 --- a/numcosmo/model/nc_hicosmo_Vexp.c +++ b/numcosmo/model/nc_hicosmo_Vexp.c @@ -40,7 +40,9 @@ #include "model/nc_hicosmo_Vexp.h" #include "perturbations/nc_hipert_adiab.h" #include "perturbations/nc_hipert_gw.h" +#include "perturbations/nc_hipert_em.h" #include "math/ncm_spline_cubic_notaknot.h" +#include "nc_enum_types.h" #ifndef NUMCOSMO_GIR_SCAN #include @@ -56,6 +58,7 @@ static void nc_hipert_iadiab_interface_init (NcHIPertIAdiabInterface *iface); static void nc_hipert_igw_interface_init (NcHIPertIGWInterface *iface); +static void nc_hipert_iem_interface_init (NcHIPertIEMInterface *iface); struct _NcHICosmoVexpPrivate { @@ -94,6 +97,11 @@ struct _NcHICosmoVexpPrivate NcmSpline *lnqc_mtau; NcmSpline *lnqe_tau; NcmSpline *phi_tau; + NcHICosmoVexpEMCoupling em_coupling; + gdouble (*em_eval_xi) (NcHICosmoVexp *Vexp, const gdouble tau, const gdouble k); + gdouble (*em_eval_F1) (NcHICosmoVexp *Vexp, const gdouble tau, const gdouble k); + gdouble (*em_eval_nu) (NcHICosmoVexp *Vexp, const gdouble tau, const gdouble k); + gdouble (*em_eval_m) (NcHICosmoVexp *Vexp, const gdouble tau, const gdouble k); }; G_DEFINE_TYPE_WITH_CODE (NcHICosmoVexp, nc_hicosmo_Vexp, NC_TYPE_HICOSMO, @@ -101,6 +109,8 @@ G_DEFINE_TYPE_WITH_CODE (NcHICosmoVexp, nc_hicosmo_Vexp, NC_TYPE_HICOSMO, nc_hipert_iadiab_interface_init) G_IMPLEMENT_INTERFACE (NC_TYPE_HIPERT_IGW, nc_hipert_igw_interface_init) + G_IMPLEMENT_INTERFACE (NC_TYPE_HIPERT_IEM, + nc_hipert_iem_interface_init) G_ADD_PRIVATE (NcHICosmoVexp) ); @@ -109,6 +119,7 @@ enum PROP_0, PROP_GLUE_DE, PROP_SET_XB_MAX, + PROP_EM_COUPLING, PROP_SIZE, }; @@ -193,12 +204,12 @@ nc_hicosmo_Vexp_init (NcHICosmoVexp *Vexp) NcmVector *mtau_v = ncm_vector_new_array (mtau); NcmVector *tau_v = ncm_vector_new_array (tau); NcmVector *tau_q_v = ncm_vector_new_array (tau_q); - NcmVector *mz_v = ncm_vector_new_array (tau_q); + NcmVector *mz_v = ncm_vector_new_array (mz); NcmVector *lnqc_v = ncm_vector_new_array (lnqc); NcmVector *lnqe_v = ncm_vector_new_array (lnqe); NcmVector *phi_v = ncm_vector_new_array (phi); - NcmVector *E2_v = ncm_vector_new_array (phi); + NcmVector *E2_v = ncm_vector_new_array (E2); ncm_spline_set (Vexp->priv->lnqc_mtau, mtau_v, lnqc_v, FALSE); ncm_spline_set (Vexp->priv->lnqe_tau, tau_v, lnqe_v, FALSE); @@ -226,6 +237,12 @@ nc_hicosmo_Vexp_init (NcHICosmoVexp *Vexp) ncm_vector_clear (&E2_v); } } + + Vexp->priv->em_coupling = NC_HICOSMO_VEXP_EM_COUPLING_INVALID; + Vexp->priv->em_eval_xi = NULL; + Vexp->priv->em_eval_F1 = NULL; + Vexp->priv->em_eval_nu = NULL; + Vexp->priv->em_eval_m = NULL; } static void @@ -243,9 +260,12 @@ _nc_hicosmo_Vexp_get_property (GObject *object, guint prop_id, GValue *value, GP case PROP_SET_XB_MAX: g_value_set_boolean (value, Vexp->priv->set_xb_max); break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + case PROP_EM_COUPLING: + g_value_set_enum (value, nc_hicosmo_Vexp_get_em_coupling (Vexp)); break; + default: /* LCOV_EXCL_LINE */ + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); /* LCOV_EXCL_LINE */ + break; /* LCOV_EXCL_LINE */ } } @@ -266,9 +286,12 @@ _nc_hicosmo_Vexp_set_property (GObject *object, guint prop_id, const GValue *val Vexp->priv->set_xb_max = g_value_get_boolean (value); ncm_model_state_mark_outdated (NCM_MODEL (Vexp)); break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + case PROP_EM_COUPLING: + nc_hicosmo_Vexp_set_em_coupling (Vexp, g_value_get_enum (value)); break; + default: /* LCOV_EXCL_LINE */ + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); /* LCOV_EXCL_LINE */ + break; /* LCOV_EXCL_LINE */ } } @@ -404,6 +427,17 @@ nc_hicosmo_Vexp_class_init (NcHICosmoVexpClass *klass) NC_HICOSMO_DEFAULT_PARAMS_ABSTOL, NC_HICOSMO_VEXP_DEFAULT_X_B, NCM_PARAM_TYPE_FIXED); + /* Set em_b param info */ + ncm_model_class_set_sparam (model_class, NC_HICOSMO_VEXP_EM_B, "B_\\mathrm{em}", "Bem", + 1.0e-100, 1.0e100, 1.0e-2, + NC_HICOSMO_DEFAULT_PARAMS_ABSTOL, NC_HICOSMO_VEXP_DEFAULT_EM_B, + NCM_PARAM_TYPE_FIXED); + /* Set em_beta param info */ + ncm_model_class_set_sparam (model_class, NC_HICOSMO_VEXP_EM_BETA, "\\beta_\\mathrm{em}", "betaem", + 1.0e-10, 1.0e4, 1.0e-2, + NC_HICOSMO_DEFAULT_PARAMS_ABSTOL, NC_HICOSMO_VEXP_DEFAULT_EM_B, + NCM_PARAM_TYPE_FIXED); + /* Check for errors in parameters initialization */ ncm_model_class_check_params_info (model_class); @@ -421,6 +455,14 @@ nc_hicosmo_Vexp_class_init (NcHICosmoVexpClass *klass) "Whether to use max xb allowed by the matching", FALSE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB)); + g_object_class_install_property (object_class, + PROP_EM_COUPLING, + g_param_spec_enum ("em-coupling", + NULL, + "Electromagnetic coupling", + NC_TYPE_HICOSMO_VEXP_EM_COUPLING, + NC_HICOSMO_VEXP_EM_COUPLING_NONE, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB)); nc_hicosmo_set_H0_impl (parent_class, &_nc_hicosmo_Vexp_H0); nc_hicosmo_set_xb_impl (parent_class, &_nc_hicosmo_Vexp_xb); @@ -531,60 +573,66 @@ _nc_hicosmo_Vexp_init_dx_alpha_series (const gdouble dalpha) #define D_PHI (ncm_model_orig_param_get (VECTOR, NC_HICOSMO_VEXP_D_PHI)) #define ALPHA_B (ncm_model_orig_param_get (VECTOR, NC_HICOSMO_VEXP_ALPHA_B)) #define X_B (ncm_model_orig_param_get (VECTOR, NC_HICOSMO_VEXP_X_B)) +#define EM_B (ncm_model_orig_param_get (VECTOR, NC_HICOSMO_VEXP_EM_B)) +#define EM_BETA (ncm_model_orig_param_get (VECTOR, NC_HICOSMO_VEXP_EM_BETA)) #define LAMBDAp (1.0 + 1.0 / M_SQRT2) #define LAMBDAm (1.0 - 1.0 / M_SQRT2) -static gdouble _nc_hicosmo_Vexp_zeta_eval_mnu (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k); +static gdouble _nc_hicosmo_Vexp_zeta_eval_xi (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k); +static gdouble _nc_hicosmo_Vexp_zeta_eval_F1 (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k); static gdouble _nc_hicosmo_Vexp_zeta_eval_nu (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k); -static gdouble _nc_hicosmo_Vexp_zeta_eval_dlnmnu (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k); -static void _nc_hicosmo_Vexp_zeta_eval_system (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k, gdouble *nu, gdouble *dlnmnu); - -static guint _nc_hicosmo_Vexp_zeta_nsing (NcHIPertIAdiab *iad, const gdouble k); -static void _nc_hicosmo_Vexp_zeta_get_sing_info (NcHIPertIAdiab *iad, const gdouble k, const guint sing, gdouble *ts, gdouble *dts_i, gdouble *dts_f, NcmHOAASingType *st); -static gdouble _nc_hicosmo_Vexp_zeta_eval_sing_mnu (NcHIPertIAdiab *iad, const gdouble tau_m_taus, const gdouble k, guint sing); -static gdouble _nc_hicosmo_Vexp_zeta_eval_sing_dlnmnu (NcHIPertIAdiab *iad, const gdouble tau_m_taus, const gdouble k, guint sing); -static void _nc_hicosmo_Vexp_zeta_eval_sing_system (NcHIPertIAdiab *iad, const gdouble tau_m_taus, const gdouble k, guint sing, gdouble *nu, gdouble *dlnmnu); +static gdouble _nc_hicosmo_Vexp_zeta_eval_m (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k); +static gdouble _nc_hicosmo_Vexp_zeta_eval_unit (NcHIPertIAdiab *iad); +static gdouble _nc_hicosmo_Vexp_zeta_eval_x (NcHIPertIAdiab *iad, const gdouble tau); static void nc_hipert_iadiab_interface_init (NcHIPertIAdiabInterface *iface) { - iface->eval_mnu = &_nc_hicosmo_Vexp_zeta_eval_mnu; - iface->eval_nu = &_nc_hicosmo_Vexp_zeta_eval_nu; - iface->eval_dlnmnu = &_nc_hicosmo_Vexp_zeta_eval_dlnmnu; - iface->eval_system = &_nc_hicosmo_Vexp_zeta_eval_system; - - iface->nsing = &_nc_hicosmo_Vexp_zeta_nsing; - iface->get_sing_info = &_nc_hicosmo_Vexp_zeta_get_sing_info; - iface->eval_sing_mnu = &_nc_hicosmo_Vexp_zeta_eval_sing_mnu; - iface->eval_sing_dlnmnu = &_nc_hicosmo_Vexp_zeta_eval_sing_dlnmnu; - iface->eval_sing_system = &_nc_hicosmo_Vexp_zeta_eval_sing_system; + iface->eval_xi = &_nc_hicosmo_Vexp_zeta_eval_xi; + iface->eval_F1 = &_nc_hicosmo_Vexp_zeta_eval_F1; + iface->eval_nu = &_nc_hicosmo_Vexp_zeta_eval_nu; + iface->eval_m = &_nc_hicosmo_Vexp_zeta_eval_m; + iface->eval_unit = &_nc_hicosmo_Vexp_zeta_eval_unit; + iface->eval_x = &_nc_hicosmo_Vexp_zeta_eval_x; } -static gdouble _nc_hicosmo_Vexp_gw_eval_mnu (NcHIPertIGW *igw, const gdouble tau, const gdouble k); +static gdouble _nc_hicosmo_Vexp_gw_eval_xi (NcHIPertIGW *igw, const gdouble tau, const gdouble k); +static gdouble _nc_hicosmo_Vexp_gw_eval_F1 (NcHIPertIGW *igw, const gdouble tau, const gdouble k); static gdouble _nc_hicosmo_Vexp_gw_eval_nu (NcHIPertIGW *igw, const gdouble tau, const gdouble k); -static gdouble _nc_hicosmo_Vexp_gw_eval_dlnmnu (NcHIPertIGW *igw, const gdouble tau, const gdouble k); -static void _nc_hicosmo_Vexp_gw_eval_system (NcHIPertIGW *igw, const gdouble tau, const gdouble k, gdouble *nu, gdouble *dlnmnu); - -static guint _nc_hicosmo_Vexp_gw_nsing (NcHIPertIGW *igw, const gdouble k); -static void _nc_hicosmo_Vexp_gw_get_sing_info (NcHIPertIGW *igw, const gdouble k, const guint sing, gdouble *ts, gdouble *dts_i, gdouble *dts_f, NcmHOAASingType *st); -static gdouble _nc_hicosmo_Vexp_gw_eval_sing_mnu (NcHIPertIGW *igw, const gdouble tau_m_taus, const gdouble k, guint sing); -static gdouble _nc_hicosmo_Vexp_gw_eval_sing_dlnmnu (NcHIPertIGW *igw, const gdouble tau_m_taus, const gdouble k, guint sing); -static void _nc_hicosmo_Vexp_gw_eval_sing_system (NcHIPertIGW *igw, const gdouble tau_m_taus, const gdouble k, guint sing, gdouble *nu, gdouble *dlnmnu); +static gdouble _nc_hicosmo_Vexp_gw_eval_m (NcHIPertIGW *igw, const gdouble tau, const gdouble k); +static gdouble _nc_hicosmo_Vexp_gw_eval_unit (NcHIPertIGW *igw); +static gdouble _nc_hicosmo_Vexp_gw_eval_x (NcHIPertIGW *igw, const gdouble tau); static void nc_hipert_igw_interface_init (NcHIPertIGWInterface *iface) { - iface->eval_mnu = &_nc_hicosmo_Vexp_gw_eval_mnu; - iface->eval_nu = &_nc_hicosmo_Vexp_gw_eval_nu; - iface->eval_dlnmnu = &_nc_hicosmo_Vexp_gw_eval_dlnmnu; - iface->eval_system = &_nc_hicosmo_Vexp_gw_eval_system; + iface->eval_xi = &_nc_hicosmo_Vexp_gw_eval_xi; + iface->eval_F1 = &_nc_hicosmo_Vexp_gw_eval_F1; + iface->eval_nu = &_nc_hicosmo_Vexp_gw_eval_nu; + iface->eval_m = &_nc_hicosmo_Vexp_gw_eval_m; + iface->eval_unit = &_nc_hicosmo_Vexp_gw_eval_unit; + iface->eval_x = &_nc_hicosmo_Vexp_gw_eval_x; +} + +static gdouble _nc_hicosmo_Vexp_em_eval_xi (NcHIPertIEM *iem, const gdouble tau, const gdouble k); +static gdouble _nc_hicosmo_Vexp_em_eval_F1 (NcHIPertIEM *iem, const gdouble tau, const gdouble k); +static gdouble _nc_hicosmo_Vexp_em_eval_nu (NcHIPertIEM *iem, const gdouble tau, const gdouble k); +static gdouble _nc_hicosmo_Vexp_em_eval_m (NcHIPertIEM *iem, const gdouble tau, const gdouble k); +static gdouble _nc_hicosmo_Vexp_em_eval_unit (NcHIPertIEM *iem); +static gdouble _nc_hicosmo_Vexp_em_eval_x (NcHIPertIEM *iem, const gdouble tau); +static gdouble _nc_hicosmo_Vexp_em_eval_lapse (NcHIPertIEM *iem, const gdouble tau); - iface->nsing = &_nc_hicosmo_Vexp_gw_nsing; - iface->get_sing_info = &_nc_hicosmo_Vexp_gw_get_sing_info; - iface->eval_sing_mnu = &_nc_hicosmo_Vexp_gw_eval_sing_mnu; - iface->eval_sing_dlnmnu = &_nc_hicosmo_Vexp_gw_eval_sing_dlnmnu; - iface->eval_sing_system = &_nc_hicosmo_Vexp_gw_eval_sing_system; +static void +nc_hipert_iem_interface_init (NcHIPertIEMInterface *iface) +{ + iface->eval_xi = &_nc_hicosmo_Vexp_em_eval_xi; + iface->eval_F1 = &_nc_hicosmo_Vexp_em_eval_F1; + iface->eval_nu = &_nc_hicosmo_Vexp_em_eval_nu; + iface->eval_m = &_nc_hicosmo_Vexp_em_eval_m; + iface->eval_unit = &_nc_hicosmo_Vexp_em_eval_unit; + iface->eval_x = &_nc_hicosmo_Vexp_em_eval_x; + iface->eval_lapse = &_nc_hicosmo_Vexp_em_eval_lapse; } static gdouble @@ -1690,7 +1738,7 @@ _nc_hicosmo_Vexp_H0 (NcHICosmo *cosmo) static gdouble _nc_hicosmo_Vexp_Omega_t0 (NcHICosmo *cosmo) { - return OMEGA_C; + return OMEGA_C + OMEGA_L; } static gdouble @@ -1701,8 +1749,12 @@ _nc_hicosmo_Vexp_xb (NcHICosmo *cosmo) #define _NC_HICOSMO_VEXP_PHIA NC_HICOSMO_VEXP_START_T +/* + * Interface implementation -- NcHIPertIAdiab + */ + static gdouble -_nc_hicosmo_Vexp_zeta_eval_mnu (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k) +_nc_hicosmo_Vexp_zeta_eval_xi (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k) { NcHICosmoVexp *Vexp = NC_HICOSMO_VEXP (iad); @@ -1782,12 +1834,12 @@ _nc_hicosmo_Vexp_zeta_eval_mnu (NcHIPertIAdiab *iad, const gdouble tau, const gd break; } - return mnu; + return log (mnu); } } static gdouble -_nc_hicosmo_Vexp_zeta_eval_nu (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k) +_nc_hicosmo_Vexp_zeta_eval_F1 (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k) { NcHICosmoVexp *Vexp = NC_HICOSMO_VEXP (iad); @@ -1796,8 +1848,8 @@ _nc_hicosmo_Vexp_zeta_eval_nu (NcHIPertIAdiab *iad, const gdouble tau, const gdo { const gdouble tau2 = tau * tau; const gdouble lna_a0e = 0.5 * tau2 + Vexp->priv->alpha_b - Vexp->priv->alpha_0e; - gdouble nu; - guint branch = 0; + guint branch = 0; + gdouble dlnmnu, nu; if (tau > Vexp->priv->tau_qt_c) { @@ -1811,11 +1863,13 @@ _nc_hicosmo_Vexp_zeta_eval_nu (NcHIPertIAdiab *iad, const gdouble tau, const gdo { case 0: /* Classical contraction */ { - const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqc_mtau, -tau); - const gdouble q = exp (lnq); - const gdouble E = _nc_hicosmo_Vexp_Hc_H0_q (Vexp, q, Vexp->priv->cl_bc); + const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqc_mtau, -tau); + const gdouble q = exp (lnq); + const gdouble dlnx_dalpha = _nc_hicosmo_Vexp_cl_dlnx_dalpha (Vexp, q, Vexp->priv->cl_bc); + const gdouble E = _nc_hicosmo_Vexp_Hc_H0_q (Vexp, q, Vexp->priv->cl_bc); - nu = exp (-lna_a0e) * k * tau / E; + nu = exp (-lna_a0e) * k * tau / E; + dlnmnu = 2.0 * (dlnx_dalpha + 1.0) * tau; break; } @@ -1827,17 +1881,24 @@ _nc_hicosmo_Vexp_zeta_eval_nu (NcHIPertIAdiab *iad, const gdouble tau, const gdo _nc_hicosmo_Vexp_H_x (Vexp, 0.0, alpha, phi, &H_lp, &xq); - nu = exp (-lna_a0e) * k * tau / (H_lp * Vexp->priv->RH_lp); + { + const gdouble dlnx_dalpha = _nc_hicosmo_Vexp_qt_dlnx_dalpha (Vexp, 0.0, alpha, phi); + + nu = exp (-lna_a0e) * k * tau / (H_lp * Vexp->priv->RH_lp); + dlnmnu = 2.0 * (dlnx_dalpha + 1.0) * tau; + } break; } case 2: /* Classical expansion */ { - const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqe_tau, tau); - const gdouble q = exp (lnq); - const gdouble E = _nc_hicosmo_Vexp_He_H0_q (Vexp, q, Vexp->priv->cl_be); + const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqe_tau, tau); + const gdouble q = exp (lnq); + const gdouble dlnx_dalpha = _nc_hicosmo_Vexp_cl_dlnx_dalpha (Vexp, q, Vexp->priv->cl_be); + const gdouble E = _nc_hicosmo_Vexp_He_H0_q (Vexp, q, Vexp->priv->cl_be); - nu = exp (-lna_a0e) * k * tau / E; + nu = exp (-lna_a0e) * k * tau / E; + dlnmnu = 2.0 * (dlnx_dalpha + 1.0) * tau; break; } @@ -1846,19 +1907,21 @@ _nc_hicosmo_Vexp_zeta_eval_nu (NcHIPertIAdiab *iad, const gdouble tau, const gdo break; } - return nu; + return dlnmnu / (2.0 * nu); } } static gdouble -_nc_hicosmo_Vexp_zeta_eval_dlnmnu (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k) +_nc_hicosmo_Vexp_zeta_eval_nu (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k) { NcHICosmoVexp *Vexp = NC_HICOSMO_VEXP (iad); _nc_hicosmo_Vexp_prepare (Vexp); { - gdouble dlnmnu; + const gdouble tau2 = tau * tau; + const gdouble lna_a0e = 0.5 * tau2 + Vexp->priv->alpha_b - Vexp->priv->alpha_0e; + gdouble nu; guint branch = 0; if (tau > Vexp->priv->tau_qt_c) @@ -1873,11 +1936,11 @@ _nc_hicosmo_Vexp_zeta_eval_dlnmnu (NcHIPertIAdiab *iad, const gdouble tau, const { case 0: /* Classical contraction */ { - const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqc_mtau, -tau); - const gdouble q = exp (lnq); - const gdouble dlnx_dalpha = _nc_hicosmo_Vexp_cl_dlnx_dalpha (Vexp, q, Vexp->priv->cl_bc); + const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqc_mtau, -tau); + const gdouble q = exp (lnq); + const gdouble E = _nc_hicosmo_Vexp_Hc_H0_q (Vexp, q, Vexp->priv->cl_bc); - dlnmnu = 2.0 * (dlnx_dalpha + 1.0) * tau; + nu = exp (-lna_a0e) * k * tau / E; break; } @@ -1889,21 +1952,17 @@ _nc_hicosmo_Vexp_zeta_eval_dlnmnu (NcHIPertIAdiab *iad, const gdouble tau, const _nc_hicosmo_Vexp_H_x (Vexp, 0.0, alpha, phi, &H_lp, &xq); - { - const gdouble dlnx_dalpha = _nc_hicosmo_Vexp_qt_dlnx_dalpha (Vexp, 0.0, alpha, phi); - - dlnmnu = 2.0 * (dlnx_dalpha + 1.0) * tau; - } + nu = exp (-lna_a0e) * k * tau / (H_lp * Vexp->priv->RH_lp); break; } case 2: /* Classical expansion */ { - const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqe_tau, tau); - const gdouble q = exp (lnq); - const gdouble dlnx_dalpha = _nc_hicosmo_Vexp_cl_dlnx_dalpha (Vexp, q, Vexp->priv->cl_be); + const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqe_tau, tau); + const gdouble q = exp (lnq); + const gdouble E = _nc_hicosmo_Vexp_He_H0_q (Vexp, q, Vexp->priv->cl_be); - dlnmnu = 2.0 * (dlnx_dalpha + 1.0) * tau; + nu = exp (-lna_a0e) * k * tau / E; break; } @@ -1912,12 +1971,12 @@ _nc_hicosmo_Vexp_zeta_eval_dlnmnu (NcHIPertIAdiab *iad, const gdouble tau, const break; } - return dlnmnu; + return nu; } } -static void -_nc_hicosmo_Vexp_zeta_eval_system (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k, gdouble *nu, gdouble *dlnmnu) +static gdouble +_nc_hicosmo_Vexp_zeta_eval_m (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k) { NcHICosmoVexp *Vexp = NC_HICOSMO_VEXP (iad); @@ -1926,7 +1985,9 @@ _nc_hicosmo_Vexp_zeta_eval_system (NcHIPertIAdiab *iad, const gdouble tau, const { const gdouble tau2 = tau * tau; const gdouble lna_a0e = 0.5 * tau2 + Vexp->priv->alpha_b - Vexp->priv->alpha_0e; - guint branch = 0; + + gdouble m; + guint branch = 0; if (tau > Vexp->priv->tau_qt_c) { @@ -1940,43 +2001,55 @@ _nc_hicosmo_Vexp_zeta_eval_system (NcHIPertIAdiab *iad, const gdouble tau, const { case 0: /* Classical contraction */ { - const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqc_mtau, -tau); - const gdouble q = exp (lnq); - const gdouble E = _nc_hicosmo_Vexp_Hc_H0_q (Vexp, q, Vexp->priv->cl_bc); - const gdouble dlnx_dalpha = _nc_hicosmo_Vexp_cl_dlnx_dalpha (Vexp, q, Vexp->priv->cl_bc); + const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqc_mtau, -tau); + const gdouble q = exp (lnq); + const gdouble x = _nc_hicosmo_Vexp_x_q (q, Vexp->priv->cl_bc); + const gdouble E = _nc_hicosmo_Vexp_Hc_H0_q (Vexp, q, Vexp->priv->cl_bc); + + if (fabs (x) < 1.0e-1) + { + const gdouble dalpha = 0.5 * (tau - Vexp->priv->tau_x0) * (tau + Vexp->priv->tau_x0); + const gdouble x_s = _nc_hicosmo_Vexp_init_x_alpha_series (dalpha); - nu[0] = exp (-lna_a0e) * k * tau / E; - dlnmnu[0] = 2.0 * (dlnx_dalpha + 1.0) * tau; + m = x_s * x_s * exp (3.0 * lna_a0e) * E / tau; + } + else + { + m = x * x * exp (3.0 * lna_a0e) * E / tau; + } break; } case 1: /* Quantum phase */ { const gdouble alpha = 0.5 * tau * tau + Vexp->priv->alpha_b; - const gdouble phi = (fabs (tau) < _NC_HICOSMO_VEXP_PHIA) ? _nc_hicosmo_Vexp_qt_phi_tau (Vexp, tau) : (ncm_spline_eval (Vexp->priv->phi_tau, tau) * tau); + const gdouble phi = (fabs (tau) < _NC_HICOSMO_VEXP_PHIA) ? _nc_hicosmo_Vexp_qt_phi_tau (Vexp, tau) : ncm_spline_eval (Vexp->priv->phi_tau, tau) * tau; gdouble H_lp, xq; _nc_hicosmo_Vexp_H_x (Vexp, 0.0, alpha, phi, &H_lp, &xq); - { - const gdouble E = H_lp * Vexp->priv->RH_lp; - const gdouble dlnx_dalpha = _nc_hicosmo_Vexp_qt_dlnx_dalpha (Vexp, 0.0, alpha, phi); - - nu[0] = exp (-lna_a0e) * k * tau / E; - dlnmnu[0] = 2.0 * (dlnx_dalpha + 1.0) * tau; - } + m = xq * xq * exp (3.0 * lna_a0e) * (H_lp * Vexp->priv->RH_lp) / tau; break; } case 2: /* Classical expansion */ { - const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqe_tau, tau); - const gdouble q = exp (lnq); - const gdouble E = _nc_hicosmo_Vexp_He_H0_q (Vexp, q, Vexp->priv->cl_be); - const gdouble dlnx_dalpha = _nc_hicosmo_Vexp_cl_dlnx_dalpha (Vexp, q, Vexp->priv->cl_be); + const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqe_tau, tau); + const gdouble q = exp (lnq); + const gdouble x = _nc_hicosmo_Vexp_x_q (q, Vexp->priv->cl_be); + const gdouble E = _nc_hicosmo_Vexp_He_H0_q (Vexp, q, Vexp->priv->cl_be); + + if (fabs (x) < 1.0e-1) + { + const gdouble dalpha = 0.5 * (tau - Vexp->priv->tau_x0) * (tau + Vexp->priv->tau_x0); + const gdouble x_s = _nc_hicosmo_Vexp_init_x_alpha_series (dalpha); - nu[0] = exp (-lna_a0e) * k * tau / E; - dlnmnu[0] = 2.0 * (dlnx_dalpha + 1.0) * tau; + m = x_s * x_s * exp (3.0 * lna_a0e) * E / tau; + } + else + { + m = x * x * exp (3.0 * lna_a0e) * E / tau; + } break; } @@ -1984,263 +2057,35 @@ _nc_hicosmo_Vexp_zeta_eval_system (NcHIPertIAdiab *iad, const gdouble tau, const g_assert_not_reached (); break; } - } - - return; -} - -static guint -_nc_hicosmo_Vexp_zeta_nsing (NcHIPertIAdiab *iad, const gdouble k) -{ - NcHICosmoVexp *Vexp = NC_HICOSMO_VEXP (iad); - - _nc_hicosmo_Vexp_prepare (Vexp); - - if (Vexp->priv->tau_x0 != 0.0) - return 2; - else - return 1; -} - -static void -_nc_hicosmo_Vexp_zeta_get_sing_info (NcHIPertIAdiab *iad, const gdouble k, const guint sing, gdouble *ts, gdouble *dts_i, gdouble *dts_f, NcmHOAASingType *st) -{ - NcHICosmoVexp *Vexp = NC_HICOSMO_VEXP (iad); - - _nc_hicosmo_Vexp_prepare (Vexp); - switch (sing) - { - case 0: - ts[0] = 0.0; - dts_i[0] = -0.1; - dts_f[0] = +0.1; - st[0] = NCM_HOAA_SING_TYPE_INF; - break; - case 1: - ts[0] = Vexp->priv->tau_x0; - dts_i[0] = Vexp->priv->tau_x0_i - Vexp->priv->tau_x0; - dts_f[0] = Vexp->priv->tau_x0_f - Vexp->priv->tau_x0; - st[0] = NCM_HOAA_SING_TYPE_ZERO; - break; - default: - g_assert_not_reached (); - break; + return m; } } static gdouble -_nc_hicosmo_Vexp_zeta_eval_sing_mnu (NcHIPertIAdiab *iad, const gdouble tau_m_taus, const gdouble k, guint sing) +_nc_hicosmo_Vexp_zeta_eval_unit (NcHIPertIAdiab *iad) { - if (sing == 0) - { - return _nc_hicosmo_Vexp_zeta_eval_mnu (iad, tau_m_taus, k); - } - else - { - NcHICosmoVexp *Vexp = NC_HICOSMO_VEXP (iad); - - _nc_hicosmo_Vexp_prepare (Vexp); - - { - const gdouble tau = tau_m_taus + Vexp->priv->tau_x0; - const gdouble tau2 = tau * tau; - const gdouble lna_a0e = 0.5 * tau2 + Vexp->priv->alpha_b - Vexp->priv->alpha_0e; - gdouble mnu; - guint branch = 0; - - if (tau > Vexp->priv->tau_qt_c) - { - branch++; - - if (tau > Vexp->priv->tau_qt_e) - branch++; - } - - switch (branch) - { - case 0: /* Classical contraction */ - { - const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqc_mtau, -tau); - const gdouble q = exp (lnq); - const gdouble x = _nc_hicosmo_Vexp_x_q (q, Vexp->priv->cl_bc); - - if (fabs (x) < 1.0e-1) - { - const gdouble dalpha = 0.5 * tau_m_taus * (tau + Vexp->priv->tau_x0); - const gdouble x_s = _nc_hicosmo_Vexp_init_x_alpha_series (dalpha); - - mnu = k * x_s * x_s * exp (2.0 * lna_a0e); - } - else - { - mnu = k * x * x * exp (2.0 * lna_a0e); - } - - break; - } - case 1: /* Quantum phase */ - { - const gdouble alpha = 0.5 * tau * tau + Vexp->priv->alpha_b; - const gdouble phi = (fabs (tau) < _NC_HICOSMO_VEXP_PHIA) ? _nc_hicosmo_Vexp_qt_phi_tau (Vexp, tau) : (ncm_spline_eval (Vexp->priv->phi_tau, tau) * tau); - gdouble H_lp, xq; - - _nc_hicosmo_Vexp_H_x (Vexp, 0.0, alpha, phi, &H_lp, &xq); - - mnu = k * xq * xq * exp (2.0 * lna_a0e); - - break; - } - case 2: /* Classical expansion */ - { - const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqe_tau, tau); - const gdouble q = exp (lnq); - const gdouble x = _nc_hicosmo_Vexp_x_q (q, Vexp->priv->cl_be); - - if (fabs (x) < 1.0e-1) - { - const gdouble dalpha = 0.5 * tau_m_taus * (tau + Vexp->priv->tau_x0); - const gdouble x_s = _nc_hicosmo_Vexp_init_x_alpha_series (dalpha); - - mnu = k * x_s * x_s * exp (2.0 * lna_a0e); - } - else - { - mnu = k * x * x * exp (2.0 * lna_a0e); - } + NcHICosmoVexp *Vexp = NC_HICOSMO_VEXP (iad); + NcHICosmo *cosmo = NC_HICOSMO (iad); + const gdouble RH_lp = nc_hicosmo_RH_planck (cosmo); + const gdouble factor = sqrt (8.0 * ncm_c_pi () / 3.0); - break; - } - default: - g_assert_not_reached (); - break; - } - return mnu; - } - } + return factor / RH_lp; } static gdouble -_nc_hicosmo_Vexp_zeta_eval_sing_dlnmnu (NcHIPertIAdiab *iad, const gdouble tau_m_taus, const gdouble k, guint sing) +_nc_hicosmo_Vexp_zeta_eval_x (NcHIPertIAdiab *iad, const gdouble tau) { - if (sing == 0) - { - return _nc_hicosmo_Vexp_zeta_eval_dlnmnu (iad, tau_m_taus, k); - } - else - { - NcHICosmoVexp *Vexp = NC_HICOSMO_VEXP (iad); - - _nc_hicosmo_Vexp_prepare (Vexp); - - { - const gdouble tau = tau_m_taus + Vexp->priv->tau_x0; - gdouble dlnmnu; - guint branch = 0; - - if (tau > Vexp->priv->tau_qt_c) - { - branch++; - - if (tau > Vexp->priv->tau_qt_e) - branch++; - } - - switch (branch) - { - case 0: /* Classical contraction */ - { - const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqc_mtau, -tau); - const gdouble q = exp (lnq); - const gdouble x = _nc_hicosmo_Vexp_x_q (q, Vexp->priv->cl_bc); - - if (fabs (x) < 1.0e-1) - { - const gdouble dalpha = 0.5 * tau_m_taus * (tau + Vexp->priv->tau_x0); - const gdouble x_s = _nc_hicosmo_Vexp_init_x_alpha_series (dalpha); - const gdouble dx = _nc_hicosmo_Vexp_init_dx_alpha_series (dalpha); - const gdouble dlnx_dalpha = dx / x_s; - - dlnmnu = 2.0 * (dlnx_dalpha + 1.0) * tau; - } - else - { - const gdouble dlnx_dalpha = _nc_hicosmo_Vexp_cl_dlnx_dalpha (Vexp, q, Vexp->priv->cl_bc); - - dlnmnu = 2.0 * (dlnx_dalpha + 1.0) * tau; - } - - break; - } - case 1: /* Quantum phase */ - { - const gdouble alpha = 0.5 * tau * tau + Vexp->priv->alpha_b; - const gdouble phi = (fabs (tau) < _NC_HICOSMO_VEXP_PHIA) ? _nc_hicosmo_Vexp_qt_phi_tau (Vexp, tau) : (ncm_spline_eval (Vexp->priv->phi_tau, tau) * tau); - gdouble H_lp, xq; - - _nc_hicosmo_Vexp_H_x (Vexp, 0.0, alpha, phi, &H_lp, &xq); - - { - const gdouble dlnx_dalpha = _nc_hicosmo_Vexp_qt_dlnx_dalpha (Vexp, 0.0, alpha, phi); - - dlnmnu = 2.0 * (dlnx_dalpha + 1.0) * tau; - } - - break; - } - case 2: /* Classical expansion */ - { - const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqe_tau, tau); - const gdouble q = exp (lnq); - const gdouble x = _nc_hicosmo_Vexp_x_q (q, Vexp->priv->cl_be); - - if (fabs (x) < 1.0e-1) - { - const gdouble dalpha = 0.5 * tau_m_taus * (tau + Vexp->priv->tau_x0); - const gdouble x_s = _nc_hicosmo_Vexp_init_x_alpha_series (dalpha); - const gdouble dx = _nc_hicosmo_Vexp_init_dx_alpha_series (dalpha); - const gdouble dlnx_dalpha = dx / x_s; - - dlnmnu = 2.0 * (dlnx_dalpha + 1.0) * tau; - } - else - { - const gdouble dlnx_dalpha = _nc_hicosmo_Vexp_cl_dlnx_dalpha (Vexp, q, Vexp->priv->cl_be); - - dlnmnu = 2.0 * (dlnx_dalpha + 1.0) * tau; - } - - break; - } - default: - g_assert_not_reached (); - break; - } - - return dlnmnu; - } - } + return nc_hicosmo_Vexp_xe_tau (NC_HICOSMO_VEXP (iad), tau); } -static void -_nc_hicosmo_Vexp_zeta_eval_sing_system (NcHIPertIAdiab *iad, const gdouble tau_m_taus, const gdouble k, guint sing, gdouble *nu, gdouble *dlnmnu) -{ - NcHICosmoVexp *Vexp = NC_HICOSMO_VEXP (iad); - - if (sing == 0) - { - return _nc_hicosmo_Vexp_zeta_eval_system (iad, tau_m_taus, k, nu, dlnmnu); - } - else - { - nu[0] = _nc_hicosmo_Vexp_zeta_eval_nu (iad, tau_m_taus + Vexp->priv->tau_x0, k); - dlnmnu[0] = _nc_hicosmo_Vexp_zeta_eval_sing_dlnmnu (iad, tau_m_taus, k, sing); - } -} +/* + * Interface implementation -- NcHIPertIGW + */ static gdouble -_nc_hicosmo_Vexp_gw_eval_mnu (NcHIPertIGW *igw, const gdouble tau, const gdouble k) +_nc_hicosmo_Vexp_gw_eval_xi (NcHIPertIGW *igw, const gdouble tau, const gdouble k) { NcHICosmoVexp *Vexp = NC_HICOSMO_VEXP (igw); @@ -2250,12 +2095,12 @@ _nc_hicosmo_Vexp_gw_eval_mnu (NcHIPertIGW *igw, const gdouble tau, const gdouble const gdouble tau2 = tau * tau; const gdouble lna_a0e = 0.5 * tau2 + Vexp->priv->alpha_b - Vexp->priv->alpha_0e; - return exp (2.0 * lna_a0e) * k; + return 2.0 * lna_a0e + log (k); } } static gdouble -_nc_hicosmo_Vexp_gw_eval_nu (NcHIPertIGW *igw, const gdouble tau, const gdouble k) +_nc_hicosmo_Vexp_gw_eval_F1 (NcHIPertIGW *igw, const gdouble tau, const gdouble k) { NcHICosmoVexp *Vexp = NC_HICOSMO_VEXP (igw); @@ -2314,27 +2159,22 @@ _nc_hicosmo_Vexp_gw_eval_nu (NcHIPertIGW *igw, const gdouble tau, const gdouble break; } - return nu; + return tau / nu; /* dxi = 2 * tau, F1 = dxi / (2nu). */ } } static gdouble -_nc_hicosmo_Vexp_gw_eval_dlnmnu (NcHIPertIGW *igw, const gdouble tau, const gdouble k) +_nc_hicosmo_Vexp_gw_eval_nu (NcHIPertIGW *igw, const gdouble tau, const gdouble k) { - return 2.0 * tau; -} - -static void -_nc_hicosmo_Vexp_gw_eval_system (NcHIPertIGW *igw, const gdouble tau, const gdouble k, gdouble *nu, gdouble *dlnmnu) -{ - NcHICosmoVexp *Vexp = NC_HICOSMO_VEXP (igw); + NcHICosmoVexp *Vexp = NC_HICOSMO_VEXP (igw); _nc_hicosmo_Vexp_prepare (Vexp); { const gdouble tau2 = tau * tau; const gdouble lna_a0e = 0.5 * tau2 + Vexp->priv->alpha_b - Vexp->priv->alpha_0e; - guint branch = 0; + gdouble nu; + guint branch = 0; if (tau > Vexp->priv->tau_qt_c) { @@ -2352,8 +2192,7 @@ _nc_hicosmo_Vexp_gw_eval_system (NcHIPertIGW *igw, const gdouble tau, const gdou const gdouble q = exp (lnq); const gdouble E = _nc_hicosmo_Vexp_Hc_H0_q (Vexp, q, Vexp->priv->cl_bc); - nu[0] = exp (-lna_a0e) * k * tau / E; - dlnmnu[0] = 2.0 * tau; + nu = exp (-lna_a0e) * k * tau / E; break; } @@ -2365,12 +2204,8 @@ _nc_hicosmo_Vexp_gw_eval_system (NcHIPertIGW *igw, const gdouble tau, const gdou _nc_hicosmo_Vexp_H_x (Vexp, 0.0, alpha, phi, &H_lp, &xq); - { - const gdouble E = H_lp * Vexp->priv->RH_lp; + nu = exp (-lna_a0e) * k * tau / (H_lp * Vexp->priv->RH_lp); - nu[0] = exp (-lna_a0e) * k * tau / E; - dlnmnu[0] = 2.0 * tau; - } break; } case 2: /* Classical expansion */ @@ -2379,8 +2214,7 @@ _nc_hicosmo_Vexp_gw_eval_system (NcHIPertIGW *igw, const gdouble tau, const gdou const gdouble q = exp (lnq); const gdouble E = _nc_hicosmo_Vexp_He_H0_q (Vexp, q, Vexp->priv->cl_be); - nu[0] = exp (-lna_a0e) * k * tau / E; - dlnmnu[0] = 2.0 * tau; + nu = exp (-lna_a0e) * k * tau / E; break; } @@ -2388,297 +2222,178 @@ _nc_hicosmo_Vexp_gw_eval_system (NcHIPertIGW *igw, const gdouble tau, const gdou g_assert_not_reached (); break; } - } - return; + return nu; + } } -static guint -_nc_hicosmo_Vexp_gw_nsing (NcHIPertIGW *igw, const gdouble k) +static gdouble +_nc_hicosmo_Vexp_gw_eval_m (NcHIPertIGW *igw, const gdouble tau, const gdouble k) { - return 1; -} + NcHICosmoVexp *Vexp = NC_HICOSMO_VEXP (igw); -static void -_nc_hicosmo_Vexp_gw_get_sing_info (NcHIPertIGW *igw, const gdouble k, const guint sing, gdouble *ts, gdouble *dts_i, gdouble *dts_f, NcmHOAASingType *st) -{ - g_assert_cmpuint (sing, ==, 0); + _nc_hicosmo_Vexp_prepare (Vexp); - ts[0] = +0.0; - dts_i[0] = -0.1; - dts_f[0] = +0.1; - st[0] = NCM_HOAA_SING_TYPE_INF; -} + { + const gdouble tau2 = tau * tau; + const gdouble lna_a0e = 0.5 * tau2 + Vexp->priv->alpha_b - Vexp->priv->alpha_0e; + guint branch = 0; + gdouble m; -static gdouble -_nc_hicosmo_Vexp_gw_eval_sing_mnu (NcHIPertIGW *igw, const gdouble tau_m_taus, const gdouble k, guint sing) -{ - return _nc_hicosmo_Vexp_gw_eval_mnu (igw, tau_m_taus, k); -} + if (tau > Vexp->priv->tau_qt_c) + { + branch++; -static gdouble -_nc_hicosmo_Vexp_gw_eval_sing_dlnmnu (NcHIPertIGW *igw, const gdouble tau_m_taus, const gdouble k, guint sing) -{ - return _nc_hicosmo_Vexp_gw_eval_dlnmnu (igw, tau_m_taus, k); -} + if (tau > Vexp->priv->tau_qt_e) + branch++; + } -static void -_nc_hicosmo_Vexp_gw_eval_sing_system (NcHIPertIGW *igw, const gdouble tau_m_taus, const gdouble k, guint sing, gdouble *nu, gdouble *dlnmnu) -{ - _nc_hicosmo_Vexp_gw_eval_system (igw, tau_m_taus, k, nu, dlnmnu); -} + switch (branch) + { + case 0: /* Classical contraction */ + { + const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqc_mtau, -tau); + const gdouble q = exp (lnq); + const gdouble E = _nc_hicosmo_Vexp_Hc_H0_q (Vexp, q, Vexp->priv->cl_bc); -/** - * nc_hicosmo_Vexp_new: - * - * This function instantiates a new object of type #NcHICosmoVexp. - * - * Returns: A new #NcHICosmoVexp - */ -NcHICosmoVexp * -nc_hicosmo_Vexp_new (void) -{ - NcHICosmoVexp *Vexp = g_object_new (NC_TYPE_HICOSMO_VEXP, NULL); + m = exp (3.0 * lna_a0e) * E / tau; - return Vexp; -} + break; + } + case 1: /* Quantum phase */ + { + const gdouble alpha = 0.5 * tau * tau + Vexp->priv->alpha_b; + const gdouble phi = (fabs (tau) < _NC_HICOSMO_VEXP_PHIA) ? _nc_hicosmo_Vexp_qt_phi_tau (Vexp, tau) : (ncm_spline_eval (Vexp->priv->phi_tau, tau) * tau); + gdouble H_lp, xq; -/** - * nc_hicosmo_Vexp_tau_min: - * @Vexp: a #NcHICosmoVexp - * - * The minimum value of the time variable suitable to describe the bounce, $\tau_{min}$. - * - * Returns: $\tau_{min}$ - */ -gdouble -nc_hicosmo_Vexp_tau_min (NcHICosmoVexp *Vexp) -{ - _nc_hicosmo_Vexp_prepare (Vexp); - { - NcmVector *lnqc_mtau_xv = ncm_spline_peek_xv (Vexp->priv->lnqc_mtau); + _nc_hicosmo_Vexp_H_x (Vexp, 0.0, alpha, phi, &H_lp, &xq); - return -ncm_vector_get (lnqc_mtau_xv, ncm_vector_len (lnqc_mtau_xv) - 1); - } -} + m = exp (3.0 * lna_a0e) * (H_lp * Vexp->priv->RH_lp) / tau; -/** - * nc_hicosmo_Vexp_tau_max: - * @Vexp: a #NcHICosmoVexp - * - * The maximum value of the time variable suitable to describe the bounce, $\tau_{max}$. - * - * Returns: $\tau_{max}$ - */ -gdouble -nc_hicosmo_Vexp_tau_max (NcHICosmoVexp *Vexp) -{ - _nc_hicosmo_Vexp_prepare (Vexp); - { - NcmVector *lnqe_tau_xv = ncm_spline_peek_xv (Vexp->priv->lnqe_tau); + break; + } + case 2: /* Classical expansion */ + { + const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqe_tau, tau); + const gdouble q = exp (lnq); + const gdouble E = _nc_hicosmo_Vexp_He_H0_q (Vexp, q, Vexp->priv->cl_be); - return ncm_vector_get (lnqe_tau_xv, ncm_vector_len (lnqe_tau_xv) - 1); + m = exp (3.0 * lna_a0e) * E / tau; + + break; + } + default: + g_assert_not_reached (); + break; + } + + return m; } } -/** - * nc_hicosmo_Vexp_tau_qt_c: - * @Vexp: a #NcHICosmoVexp - * - * FIXME - * - * Returns: FIXME - */ -gdouble -nc_hicosmo_Vexp_tau_qt_c (NcHICosmoVexp *Vexp) +static gdouble +_nc_hicosmo_Vexp_gw_eval_unit (NcHIPertIGW *igw) { - _nc_hicosmo_Vexp_prepare (Vexp); + NcHICosmoVexp *Vexp = NC_HICOSMO_VEXP (igw); + NcHICosmo *cosmo = NC_HICOSMO (igw); + const gdouble RH_lp = nc_hicosmo_RH_planck (cosmo); + const gdouble factor = sqrt (32.0 * ncm_c_pi ()); - return Vexp->priv->tau_qt_c; + return factor / RH_lp; } -/** - * nc_hicosmo_Vexp_tau_qt_e: - * @Vexp: a #NcHICosmoVexp - * - * FIXME - * - * Returns: FIXME - */ -gdouble -nc_hicosmo_Vexp_tau_qt_e (NcHICosmoVexp *Vexp) +static gdouble +_nc_hicosmo_Vexp_gw_eval_x (NcHIPertIGW *igw, const gdouble tau) { - _nc_hicosmo_Vexp_prepare (Vexp); - - return Vexp->priv->tau_qt_e; + return nc_hicosmo_Vexp_xe_tau (NC_HICOSMO_VEXP (igw), tau); } -/** - * nc_hicosmo_Vexp_xbe: - * @Vexp: a #NcHICosmoVexp - * - * FIXME - * - * Returns: FIXME +/* + * Interface implementation -- NcHIPertIGW */ -gdouble -nc_hicosmo_Vexp_xbe (NcHICosmoVexp *Vexp) + +static gdouble +_nc_hicosmo_Vexp_em_eval_xi (NcHIPertIEM *iem, const gdouble tau, const gdouble k) { + NcHICosmoVexp *Vexp = NC_HICOSMO_VEXP (iem); + _nc_hicosmo_Vexp_prepare (Vexp); - return exp (-Vexp->priv->alpha_b + Vexp->priv->alpha_0e); + return Vexp->priv->em_eval_xi (Vexp, tau, k); } -/** - * nc_hicosmo_Vexp_xbc: - * @Vexp: a #NcHICosmoVexp - * - * FIXME - * - * Returns: FIXME - */ -gdouble -nc_hicosmo_Vexp_xbc (NcHICosmoVexp *Vexp) +static gdouble +_nc_hicosmo_Vexp_em_eval_F1 (NcHIPertIEM *iem, const gdouble tau, const gdouble k) { + NcHICosmoVexp *Vexp = NC_HICOSMO_VEXP (iem); + _nc_hicosmo_Vexp_prepare (Vexp); - return exp (-Vexp->priv->alpha_b + Vexp->priv->alpha_0c); + return Vexp->priv->em_eval_F1 (Vexp, tau, k); } -/** - * nc_hicosmo_Vexp_alpha_0e: - * @Vexp: a #NcHICosmoVexp - * - * FIXME - * - * Returns: FIXME - */ -gdouble -nc_hicosmo_Vexp_alpha_0e (NcHICosmoVexp *Vexp) +static gdouble +_nc_hicosmo_Vexp_em_eval_nu (NcHIPertIEM *iem, const gdouble tau, const gdouble k) { + NcHICosmoVexp *Vexp = NC_HICOSMO_VEXP (iem); + _nc_hicosmo_Vexp_prepare (Vexp); - return Vexp->priv->alpha_0e; + return Vexp->priv->em_eval_nu (Vexp, tau, k); } -/** - * nc_hicosmo_Vexp_alpha_0c: - * @Vexp: a #NcHICosmoVexp - * - * FIXME - * - * Returns: FIXME - */ -gdouble -nc_hicosmo_Vexp_alpha_0c (NcHICosmoVexp *Vexp) +static gdouble +_nc_hicosmo_Vexp_em_eval_m (NcHIPertIEM *iem, const gdouble tau, const gdouble k) { + NcHICosmoVexp *Vexp = NC_HICOSMO_VEXP (iem); + _nc_hicosmo_Vexp_prepare (Vexp); - return Vexp->priv->alpha_0c; + return Vexp->priv->em_eval_m (Vexp, tau, k); } -/** - * nc_hicosmo_Vexp_x_tau: - * @Vexp: a #NcHICosmoVexp - * @tau: $\tau$ - * - * FIXME - * - * Returns: $x$. - */ -gdouble -nc_hicosmo_Vexp_x_tau (NcHICosmoVexp *Vexp, const gdouble tau) +static gdouble +_nc_hicosmo_Vexp_em_eval_unit (NcHIPertIEM *iem) { - _nc_hicosmo_Vexp_prepare (Vexp); - { - const gdouble alpha = Vexp->priv->alpha_b + 0.5 * tau * tau; + NcHICosmoVexp *Vexp = NC_HICOSMO_VEXP (iem); + NcHICosmo *cosmo = NC_HICOSMO (iem); + const gdouble hbar_c_mu0 = ncm_c_hbar () * ncm_c_c () * ncm_c_magnetic_constant (); + const gdouble RH = nc_hicosmo_RH_Mpc (cosmo) * ncm_c_Mpc (); - if (tau < 0.0) - return exp (Vexp->priv->alpha_0c - alpha); - else - return exp (Vexp->priv->alpha_0e - alpha); - } + /* Factor in Gauss (1.0e-4 Tesla) */ + + return sqrt (hbar_c_mu0) * 1.0e4 / gsl_pow_2 (RH); } -/** - * nc_hicosmo_Vexp_tau_xe: - * @Vexp: a #NcHICosmoVexp - * @xe: $x_e$ - * - * FIXME - * - * Returns: $\tau$. - */ -gdouble -nc_hicosmo_Vexp_tau_xe (NcHICosmoVexp *Vexp, const gdouble xe) +static gdouble +_nc_hicosmo_Vexp_em_eval_x (NcHIPertIEM *iem, const gdouble tau) { - _nc_hicosmo_Vexp_prepare (Vexp); - { - const gdouble log_xe = log (xe); - const gdouble alpha = Vexp->priv->alpha_0e - log_xe; - - if (alpha < Vexp->priv->alpha_b) - g_warning ("nc_hicosmo_Vexp_tau_xe: too high value of xe = % 22.15g, using the maximum value = % 22.15g.", - xe, exp (Vexp->priv->alpha_0e - Vexp->priv->alpha_b)); + return nc_hicosmo_Vexp_xe_tau (NC_HICOSMO_VEXP (iem), tau); +} +static gdouble _nc_hicosmo_Vexp_em_eval_m_none (NcHICosmoVexp *Vexp, const gdouble tau, const gdouble k); - return +sqrt (2.0 * (alpha - Vexp->priv->alpha_b)); - } +static gdouble +_nc_hicosmo_Vexp_em_eval_lapse (NcHIPertIEM *iem, const gdouble tau) +{ + return 1.0 / (4.0 * _nc_hicosmo_Vexp_em_eval_m_none (NC_HICOSMO_VEXP (iem), tau, 0.0)); } -/** - * nc_hicosmo_Vexp_tau_xc: - * @Vexp: a #NcHICosmoVexp - * @xc: $x_c$ - * - * FIXME - * - * Returns: $\tau$. +/* + * EM implementation that is independent of the specific form of the + * potential. This is the default implementation. */ -gdouble -nc_hicosmo_Vexp_tau_xc (NcHICosmoVexp *Vexp, const gdouble xc) + +static gdouble +_nc_hicosmo_Vexp_em_eval_nu_all (NcHICosmoVexp *Vexp, const gdouble tau, const gdouble k) { _nc_hicosmo_Vexp_prepare (Vexp); - { - const gdouble log_xc = log (xc); - const gdouble alpha = Vexp->priv->alpha_0c - log_xc; - return -sqrt (2.0 * (alpha - Vexp->priv->alpha_b)); - } -} - -/** - * nc_hicosmo_Vexp_alpha: - * @Vexp: a #NcHICosmoVexp - * @tau: $\tau$ - * - * Computes $\alpha = \ln a$, where $a$ is the scale factor, at time @tau. - * - * Returns: $\alpha(\tau)$. - */ -gdouble -nc_hicosmo_Vexp_alpha (NcHICosmoVexp *Vexp, const gdouble tau) -{ - _nc_hicosmo_Vexp_prepare (Vexp); - - return 0.5 * tau * tau + Vexp->priv->alpha_b; -} - -/** - * nc_hicosmo_Vexp_phi: - * @Vexp: a #NcHICosmoVexp - * @tau: $\tau$ - * - * Computes the scalar field $\phi$ at time @tau. - * - * Returns: $\phi(\tau)$. - */ -gdouble -nc_hicosmo_Vexp_phi (NcHICosmoVexp *Vexp, const gdouble tau) -{ - _nc_hicosmo_Vexp_prepare (Vexp); - { - guint branch = 0; + { + const gdouble tau2 = tau * tau; + const gdouble lna_a0e = 0.5 * tau2 + Vexp->priv->alpha_b - Vexp->priv->alpha_0e; + gdouble nu; + guint branch = 0; if (tau > Vexp->priv->tau_qt_c) { @@ -2692,47 +2407,33 @@ nc_hicosmo_Vexp_phi (NcHICosmoVexp *Vexp, const gdouble tau) { case 0: /* Classical contraction */ { - const gdouble tau0 = Vexp->priv->tau_qt_c; - const gdouble phi0 = ncm_spline_eval (Vexp->priv->phi_tau, tau0) * tau0; - const gdouble lnq0 = ncm_spline_eval (Vexp->priv->lnqc_mtau, -tau0); - const gdouble q0 = exp (lnq0); - const gdouble E0 = _nc_hicosmo_Vexp_Hc_H0_q (Vexp, q0, Vexp->priv->cl_bc); - const gdouble sqrt1mx02 = sqrt (_nc_hicosmo_Vexp_1mx_q (q0, Vexp->priv->cl_bc) * _nc_hicosmo_Vexp_1px_q (q0, Vexp->priv->cl_bc)); - const gdouble L0 = fabs (E0) * sqrt1mx02 * exp (3.0 * phi0 / M_SQRT2); - - const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqc_mtau, -tau); - const gdouble q = exp (lnq); - const gdouble E = _nc_hicosmo_Vexp_Hc_H0_q (Vexp, q, Vexp->priv->cl_bc); - const gdouble sqrt1mx2 = sqrt (_nc_hicosmo_Vexp_1mx_q (q, Vexp->priv->cl_bc) * _nc_hicosmo_Vexp_1px_q (q, Vexp->priv->cl_bc)); + const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqc_mtau, -tau); + const gdouble q = exp (lnq); + const gdouble E = _nc_hicosmo_Vexp_Hc_H0_q (Vexp, q, Vexp->priv->cl_bc); - return M_SQRT2 * log (L0 / fabs (E * sqrt1mx2)) / 3.0; + nu = exp (-lna_a0e) * k * tau / E; break; } case 1: /* Quantum phase */ { - const gdouble phi = (fabs (tau) < _NC_HICOSMO_VEXP_PHIA) ? _nc_hicosmo_Vexp_qt_phi_tau (Vexp, tau) : ncm_spline_eval (Vexp->priv->phi_tau, tau) * tau; + const gdouble alpha = 0.5 * tau * tau + Vexp->priv->alpha_b; + const gdouble phi = (fabs (tau) < _NC_HICOSMO_VEXP_PHIA) ? _nc_hicosmo_Vexp_qt_phi_tau (Vexp, tau) : (ncm_spline_eval (Vexp->priv->phi_tau, tau) * tau); + gdouble H_lp, xq; - return phi; + _nc_hicosmo_Vexp_H_x (Vexp, 0.0, alpha, phi, &H_lp, &xq); + + nu = exp (-lna_a0e) * k * tau / (H_lp * Vexp->priv->RH_lp); break; } case 2: /* Classical expansion */ { - const gdouble tau0 = Vexp->priv->tau_qt_e; - const gdouble phi0 = ncm_spline_eval (Vexp->priv->phi_tau, tau0) * tau0; - const gdouble lnq0 = ncm_spline_eval (Vexp->priv->lnqe_tau, tau0); - const gdouble q0 = exp (lnq0); - const gdouble E0 = _nc_hicosmo_Vexp_He_H0_q (Vexp, q0, Vexp->priv->cl_be); - const gdouble sqrt1mx02 = sqrt (_nc_hicosmo_Vexp_1mx_q (q0, Vexp->priv->cl_be) * _nc_hicosmo_Vexp_1px_q (q0, Vexp->priv->cl_be)); - const gdouble L0 = fabs (E0) * sqrt1mx02 * exp (3.0 * phi0 / M_SQRT2); - - const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqe_tau, tau); - const gdouble q = exp (lnq); - const gdouble E = _nc_hicosmo_Vexp_He_H0_q (Vexp, q, Vexp->priv->cl_be); - const gdouble sqrt1mx2 = sqrt (_nc_hicosmo_Vexp_1mx_q (q, Vexp->priv->cl_be) * _nc_hicosmo_Vexp_1px_q (q, Vexp->priv->cl_be)); + const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqe_tau, tau); + const gdouble q = exp (lnq); + const gdouble E = _nc_hicosmo_Vexp_He_H0_q (Vexp, q, Vexp->priv->cl_be); - return M_SQRT2 * log (L0 / fabs (E * sqrt1mx2)) / 3.0; + nu = exp (-lna_a0e) * k * tau / E; break; } @@ -2740,23 +2441,37 @@ nc_hicosmo_Vexp_phi (NcHICosmoVexp *Vexp, const gdouble tau) g_assert_not_reached (); break; } + + return nu; } } -/** - * nc_hicosmo_Vexp_Ricci_scale: - * @Vexp: a #NcHICosmoVexp - * @tau: $\tau$ - * - * FIXME - * - * Returns: $L_R(\tau) / \ell_\mathrm{P}$. +/* + * EM implementation that is independent of the specific form of the + * potential. */ -gdouble -nc_hicosmo_Vexp_Ricci_scale (NcHICosmoVexp *Vexp, const gdouble tau) + +static gdouble +_nc_hicosmo_Vexp_em_eval_xi_none (NcHICosmoVexp *Vexp, const gdouble tau, const gdouble k) { - _nc_hicosmo_Vexp_prepare (Vexp); + return log (0.25 * k); +} + +static gdouble +_nc_hicosmo_Vexp_em_eval_F1_none (NcHICosmoVexp *Vexp, const gdouble tau, const gdouble k) +{ + return 0.0; +} + +static gdouble +_nc_hicosmo_Vexp_em_eval_m_none (NcHICosmoVexp *Vexp, const gdouble tau, const gdouble k) +{ + const gdouble F = 0.25; + { + const gdouble tau2 = tau * tau; + const gdouble lna_a0e = 0.5 * tau2 + Vexp->priv->alpha_b - Vexp->priv->alpha_0e; + gdouble N; guint branch = 0; if (tau > Vexp->priv->tau_qt_c) @@ -2771,32 +2486,33 @@ nc_hicosmo_Vexp_Ricci_scale (NcHICosmoVexp *Vexp, const gdouble tau) { case 0: /* Classical contraction */ { - const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqc_mtau, -tau); - const gdouble q = exp (lnq); - const gdouble E = _nc_hicosmo_Vexp_Hc_H0_q (Vexp, q, Vexp->priv->cl_bc); - const gdouble two_3mx2 = _nc_hicosmo_Vexp_1mx_q (q, Vexp->priv->cl_bc) * _nc_hicosmo_Vexp_1px_q (q, Vexp->priv->cl_bc) - 1.0 / 3.0; + const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqc_mtau, -tau); + const gdouble q = exp (lnq); + const gdouble E = _nc_hicosmo_Vexp_Hc_H0_q (Vexp, q, Vexp->priv->cl_bc); - return Vexp->priv->RH_lp / ((sqrt (18.0 * fabs (two_3mx2)) * fabs (E))); + N = exp (-lna_a0e) * tau / E; break; } case 1: /* Quantum phase */ { const gdouble alpha = 0.5 * tau * tau + Vexp->priv->alpha_b; - const gdouble phi = (fabs (tau) < _NC_HICOSMO_VEXP_PHIA) ? _nc_hicosmo_Vexp_qt_phi_tau (Vexp, tau) : ncm_spline_eval (Vexp->priv->phi_tau, tau) * tau; + const gdouble phi = (fabs (tau) < _NC_HICOSMO_VEXP_PHIA) ? _nc_hicosmo_Vexp_qt_phi_tau (Vexp, tau) : (ncm_spline_eval (Vexp->priv->phi_tau, tau) * tau); + gdouble H_lp, xq; - return _nc_hicosmo_Vexp_qt_Ricci_scale (Vexp, NC_HICOSMO (Vexp), alpha, phi); + _nc_hicosmo_Vexp_H_x (Vexp, 0.0, alpha, phi, &H_lp, &xq); + + N = exp (-lna_a0e) * tau / (H_lp * Vexp->priv->RH_lp); break; } case 2: /* Classical expansion */ { - const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqe_tau, tau); - const gdouble q = exp (lnq); - const gdouble E = _nc_hicosmo_Vexp_He_H0_q (Vexp, q, Vexp->priv->cl_be); - const gdouble two_3mx2 = _nc_hicosmo_Vexp_1mx_q (q, Vexp->priv->cl_be) * _nc_hicosmo_Vexp_1px_q (q, Vexp->priv->cl_be) - 1.0 / 3.0; + const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqe_tau, tau); + const gdouble q = exp (lnq); + const gdouble E = _nc_hicosmo_Vexp_He_H0_q (Vexp, q, Vexp->priv->cl_be); - return Vexp->priv->RH_lp / ((sqrt (18.0 * fabs (two_3mx2)) * fabs (E))); + N = exp (-lna_a0e) * tau / E; break; } @@ -2804,23 +2520,32 @@ nc_hicosmo_Vexp_Ricci_scale (NcHICosmoVexp *Vexp, const gdouble tau) g_assert_not_reached (); break; } + + return F / N; } } -/** - * nc_hicosmo_Vexp_x_y: - * @Vexp: a #NcHICosmoVexp - * @tau: $\tau$ - * @x: (out): the value of $x(\tau)$ - * @y: (out): the value of $y(\tau)$ - * - * FIXME - * - */ -void -nc_hicosmo_Vexp_x_y (NcHICosmoVexp *Vexp, const gdouble tau, gdouble *x, gdouble *y) +static gdouble +_nc_hicosmo_Vexp_em_eval_xi_cauchy (NcHICosmoVexp *Vexp, const gdouble tau, const gdouble k) { - _nc_hicosmo_Vexp_prepare (Vexp); + NcHICosmo *cosmo = NC_HICOSMO (Vexp); + const gdouble B = EM_B; + const gdouble beta = EM_BETA; + const gdouble phi = nc_hicosmo_Vexp_phi (Vexp, tau); + + return log (0.25 * k) + log1p (4.0 * B / (1.0 + gsl_pow_2 (phi / beta))); +} + +static gdouble +_nc_hicosmo_Vexp_em_eval_F1_cauchy (NcHICosmoVexp *Vexp, const gdouble tau, const gdouble k) +{ + NcHICosmo *cosmo = NC_HICOSMO (Vexp); + const gdouble B = EM_B; + const gdouble beta = EM_BETA; + const gdouble phi = nc_hicosmo_Vexp_phi (Vexp, tau); + const gdouble t1 = -8.0 * phi * B / (beta * beta) * 1.0 / gsl_pow_2 (1.0 + gsl_pow_2 (phi / beta)) * 1.0 / (1.0 + 4.0 * B / (1.0 + gsl_pow_2 (phi / beta))); + gdouble x; + { guint branch = 0; @@ -2845,11 +2570,11 @@ nc_hicosmo_Vexp_x_y (NcHICosmoVexp *Vexp, const gdouble tau, gdouble *x, gdouble const gdouble dalpha = 0.5 * (tau - Vexp->priv->tau_x0) * (tau + Vexp->priv->tau_x0); const gdouble x_s = _nc_hicosmo_Vexp_init_x_alpha_series (dalpha); - x[0] = x_s; + x = x_s; } else { - x[0] = xl; + x = xl; } break; @@ -2862,7 +2587,7 @@ nc_hicosmo_Vexp_x_y (NcHICosmoVexp *Vexp, const gdouble tau, gdouble *x, gdouble _nc_hicosmo_Vexp_H_x (Vexp, 0.0, alpha, phi, &H_lp, &xq); - x[0] = xq; + x = xq; break; } @@ -2877,11 +2602,11 @@ nc_hicosmo_Vexp_x_y (NcHICosmoVexp *Vexp, const gdouble tau, gdouble *x, gdouble const gdouble dalpha = 0.5 * (tau - Vexp->priv->tau_x0) * (tau + Vexp->priv->tau_x0); const gdouble x_s = _nc_hicosmo_Vexp_init_x_alpha_series (dalpha); - x[0] = x_s; + x = x_s; } else { - x[0] = xl; + x = xl; } break; @@ -2890,145 +2615,584 @@ nc_hicosmo_Vexp_x_y (NcHICosmoVexp *Vexp, const gdouble tau, gdouble *x, gdouble g_assert_not_reached (); break; } + } - y[0] = GSL_SIGN (tau) * sqrt (fabs (1.0 - x[0] * x[0])); + { + const gdouble nu = _nc_hicosmo_Vexp_em_eval_nu_all (Vexp, tau, k); + + return t1 * tau * x / (2.0 * nu); + } +} + +static gdouble +_nc_hicosmo_Vexp_em_eval_m_cauchy (NcHICosmoVexp *Vexp, const gdouble tau, const gdouble k) +{ + NcHICosmo *cosmo = NC_HICOSMO (Vexp); + const gdouble B = EM_B; + const gdouble beta = EM_BETA; + const gdouble phi = nc_hicosmo_Vexp_phi (Vexp, tau); + const gdouble F = 0.25 + B / (1.0 + gsl_pow_2 (phi / beta)); + + { + const gdouble tau2 = tau * tau; + const gdouble lna_a0e = 0.5 * tau2 + Vexp->priv->alpha_b - Vexp->priv->alpha_0e; + gdouble N; + guint branch = 0; + + if (tau > Vexp->priv->tau_qt_c) + { + branch++; + + if (tau > Vexp->priv->tau_qt_e) + branch++; + } + + switch (branch) + { + case 0: /* Classical contraction */ + { + const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqc_mtau, -tau); + const gdouble q = exp (lnq); + const gdouble E = _nc_hicosmo_Vexp_Hc_H0_q (Vexp, q, Vexp->priv->cl_bc); + + N = exp (-lna_a0e) * tau / E; + + break; + } + case 1: /* Quantum phase */ + { + const gdouble alpha = 0.5 * tau * tau + Vexp->priv->alpha_b; + const gdouble phi = (fabs (tau) < _NC_HICOSMO_VEXP_PHIA) ? _nc_hicosmo_Vexp_qt_phi_tau (Vexp, tau) : (ncm_spline_eval (Vexp->priv->phi_tau, tau) * tau); + gdouble H_lp, xq; + + _nc_hicosmo_Vexp_H_x (Vexp, 0.0, alpha, phi, &H_lp, &xq); + + N = exp (-lna_a0e) * tau / (H_lp * Vexp->priv->RH_lp); + + break; + } + case 2: /* Classical expansion */ + { + const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqe_tau, tau); + const gdouble q = exp (lnq); + const gdouble E = _nc_hicosmo_Vexp_He_H0_q (Vexp, q, Vexp->priv->cl_be); + + N = exp (-lna_a0e) * tau / E; + + break; + } + default: + g_assert_not_reached (); + break; + } + + return F / N; + } +} + +static gdouble +_nc_hicosmo_Vexp_em_eval_xi_gauss (NcHICosmoVexp *Vexp, const gdouble tau, const gdouble k) +{ + NcHICosmo *cosmo = NC_HICOSMO (Vexp); + const gdouble B = EM_B; + const gdouble beta = EM_BETA; + const gdouble phi = nc_hicosmo_Vexp_phi (Vexp, tau); + + return log (0.25 * k) + log1p (4.0 * B * exp (-gsl_pow_2 (phi / beta))); +} + +static gdouble +_nc_hicosmo_Vexp_em_eval_F1_gauss (NcHICosmoVexp *Vexp, const gdouble tau, const gdouble k) +{ + NcHICosmo *cosmo = NC_HICOSMO (Vexp); + const gdouble B = EM_B; + const gdouble beta = EM_BETA; + const gdouble phi = nc_hicosmo_Vexp_phi (Vexp, tau); + const gdouble t1 = -8.0 * phi * B / (beta * beta) * exp (-gsl_pow_2 (phi / beta)) / (1.0 + 4.0 * B * exp (-gsl_pow_2 (phi / beta))); + gdouble x; + + { + guint branch = 0; + + if (tau > Vexp->priv->tau_qt_c) + { + branch++; + + if (tau > Vexp->priv->tau_qt_e) + branch++; + } + + switch (branch) + { + case 0: /* Classical contraction */ + { + const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqc_mtau, -tau); + const gdouble q = exp (lnq); + const gdouble xl = _nc_hicosmo_Vexp_x_q (q, Vexp->priv->cl_bc); + + if (fabs (xl) < 1.0e-1) + { + const gdouble dalpha = 0.5 * (tau - Vexp->priv->tau_x0) * (tau + Vexp->priv->tau_x0); + const gdouble x_s = _nc_hicosmo_Vexp_init_x_alpha_series (dalpha); + + x = x_s; + } + else + { + x = xl; + } + + break; + } + case 1: /* Quantum phase */ + { + const gdouble alpha = 0.5 * tau * tau + Vexp->priv->alpha_b; + const gdouble phi = (fabs (tau) < _NC_HICOSMO_VEXP_PHIA) ? _nc_hicosmo_Vexp_qt_phi_tau (Vexp, tau) : ncm_spline_eval (Vexp->priv->phi_tau, tau) * tau; + gdouble H_lp, xq; + + _nc_hicosmo_Vexp_H_x (Vexp, 0.0, alpha, phi, &H_lp, &xq); + + x = xq; + + break; + } + case 2: /* Classical expansion */ + { + const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqe_tau, tau); + const gdouble q = exp (lnq); + const gdouble xl = _nc_hicosmo_Vexp_x_q (q, Vexp->priv->cl_be); + + if (fabs (xl) < 1.0e-1) + { + const gdouble dalpha = 0.5 * (tau - Vexp->priv->tau_x0) * (tau + Vexp->priv->tau_x0); + const gdouble x_s = _nc_hicosmo_Vexp_init_x_alpha_series (dalpha); + + x = x_s; + } + else + { + x = xl; + } + + break; + } + default: + g_assert_not_reached (); + break; + } + } + + { + const gdouble nu = _nc_hicosmo_Vexp_em_eval_nu_all (Vexp, tau, k); + + return t1 * tau * x / (2.0 * nu); + } +} + +static gdouble +_nc_hicosmo_Vexp_em_eval_m_gauss (NcHICosmoVexp *Vexp, const gdouble tau, const gdouble k) +{ + NcHICosmo *cosmo = NC_HICOSMO (Vexp); + const gdouble B = EM_B; + const gdouble beta = EM_BETA; + const gdouble phi = nc_hicosmo_Vexp_phi (Vexp, tau); + const gdouble F = 0.25 + B * exp (-gsl_pow_2 (phi / beta)); + + { + const gdouble tau2 = tau * tau; + const gdouble lna_a0e = 0.5 * tau2 + Vexp->priv->alpha_b - Vexp->priv->alpha_0e; + gdouble N; + guint branch = 0; + + if (tau > Vexp->priv->tau_qt_c) + { + branch++; + + if (tau > Vexp->priv->tau_qt_e) + branch++; + } + + switch (branch) + { + case 0: /* Classical contraction */ + { + const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqc_mtau, -tau); + const gdouble q = exp (lnq); + const gdouble E = _nc_hicosmo_Vexp_Hc_H0_q (Vexp, q, Vexp->priv->cl_bc); + + N = exp (-lna_a0e) * tau / E; + + break; + } + case 1: /* Quantum phase */ + { + const gdouble alpha = 0.5 * tau * tau + Vexp->priv->alpha_b; + const gdouble phi = (fabs (tau) < _NC_HICOSMO_VEXP_PHIA) ? _nc_hicosmo_Vexp_qt_phi_tau (Vexp, tau) : (ncm_spline_eval (Vexp->priv->phi_tau, tau) * tau); + gdouble H_lp, xq; + + _nc_hicosmo_Vexp_H_x (Vexp, 0.0, alpha, phi, &H_lp, &xq); + + N = exp (-lna_a0e) * tau / (H_lp * Vexp->priv->RH_lp); + + break; + } + case 2: /* Classical expansion */ + { + const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqe_tau, tau); + const gdouble q = exp (lnq); + const gdouble E = _nc_hicosmo_Vexp_He_H0_q (Vexp, q, Vexp->priv->cl_be); + + N = exp (-lna_a0e) * tau / E; + + break; + } + default: + g_assert_not_reached (); + break; + } + + return F / N; + } +} + +/** + * nc_hicosmo_Vexp_new: + * + * This function instantiates a new object of type #NcHICosmoVexp. + * + * Returns: A new #NcHICosmoVexp + */ +NcHICosmoVexp * +nc_hicosmo_Vexp_new (void) +{ + NcHICosmoVexp *Vexp = g_object_new (NC_TYPE_HICOSMO_VEXP, NULL); + + return Vexp; +} + +/** + * nc_hicosmo_Vexp_set_em_coupling: + * @Vexp: a #NcHICosmoVexp + * @coupling: a #NcHICosmoVexpEMCoupling + * + * Set the electromagnetic coupling. + */ +void +nc_hicosmo_Vexp_set_em_coupling (NcHICosmoVexp *Vexp, const NcHICosmoVexpEMCoupling coupling) +{ + if (Vexp->priv->em_coupling == coupling) + return; + + switch (coupling) + { + case NC_HICOSMO_VEXP_EM_COUPLING_NONE: + Vexp->priv->em_eval_F1 = _nc_hicosmo_Vexp_em_eval_F1_none; + Vexp->priv->em_eval_nu = _nc_hicosmo_Vexp_em_eval_nu_all; + Vexp->priv->em_eval_m = _nc_hicosmo_Vexp_em_eval_m_none; + Vexp->priv->em_eval_xi = _nc_hicosmo_Vexp_em_eval_xi_none; + break; + case NC_HICOSMO_VEXP_EM_COUPLING_CAUCHY: + Vexp->priv->em_eval_F1 = _nc_hicosmo_Vexp_em_eval_F1_cauchy; + Vexp->priv->em_eval_nu = _nc_hicosmo_Vexp_em_eval_nu_all; + Vexp->priv->em_eval_m = _nc_hicosmo_Vexp_em_eval_m_cauchy; + Vexp->priv->em_eval_xi = _nc_hicosmo_Vexp_em_eval_xi_cauchy; + break; + case NC_HICOSMO_VEXP_EM_COUPLING_GAUSS: + Vexp->priv->em_eval_F1 = _nc_hicosmo_Vexp_em_eval_F1_gauss; + Vexp->priv->em_eval_nu = _nc_hicosmo_Vexp_em_eval_nu_all; + Vexp->priv->em_eval_m = _nc_hicosmo_Vexp_em_eval_m_gauss; + Vexp->priv->em_eval_xi = _nc_hicosmo_Vexp_em_eval_xi_gauss; + break; + default: + g_error ("Unknown electromagnetic coupling"); + + return; + } + + Vexp->priv->em_coupling = coupling; + ncm_model_state_mark_outdated (NCM_MODEL (Vexp)); +} + +/** + * nc_hicosmo_Vexp_get_em_coupling: + * @Vexp: a #NcHICosmoVexp + * + * Get the electromagnetic coupling. + * + * Returns: a #NcHICosmoVexpEMCoupling + */ +NcHICosmoVexpEMCoupling +nc_hicosmo_Vexp_get_em_coupling (NcHICosmoVexp *Vexp) +{ + return Vexp->priv->em_coupling; +} + +/** + * nc_hicosmo_Vexp_tau_min: + * @Vexp: a #NcHICosmoVexp + * + * The minimum value of the time variable suitable to describe the bounce, $\tau_{min}$. + * + * Returns: $\tau_{min}$ + */ +gdouble +nc_hicosmo_Vexp_tau_min (NcHICosmoVexp *Vexp) +{ + _nc_hicosmo_Vexp_prepare (Vexp); + { + NcmVector *lnqc_mtau_xv = ncm_spline_peek_xv (Vexp->priv->lnqc_mtau); + + return -ncm_vector_get (lnqc_mtau_xv, ncm_vector_len (lnqc_mtau_xv) - 1); + } +} + +/** + * nc_hicosmo_Vexp_tau_max: + * @Vexp: a #NcHICosmoVexp + * + * The maximum value of the time variable suitable to describe the bounce, $\tau_{max}$. + * + * Returns: $\tau_{max}$ + */ +gdouble +nc_hicosmo_Vexp_tau_max (NcHICosmoVexp *Vexp) +{ + _nc_hicosmo_Vexp_prepare (Vexp); + { + NcmVector *lnqe_tau_xv = ncm_spline_peek_xv (Vexp->priv->lnqe_tau); + + return ncm_vector_get (lnqe_tau_xv, ncm_vector_len (lnqe_tau_xv) - 1); + } +} + +/** + * nc_hicosmo_Vexp_tau_qt_c: + * @Vexp: a #NcHICosmoVexp + * + * Value of the time $\tau$ when the quantum regime begins during the contraction + * phase. + * + * Returns: $\tau_\mathrm{qc}$. + */ +gdouble +nc_hicosmo_Vexp_tau_qt_c (NcHICosmoVexp *Vexp) +{ + _nc_hicosmo_Vexp_prepare (Vexp); + + return Vexp->priv->tau_qt_c; +} + +/** + * nc_hicosmo_Vexp_tau_qt_e: + * @Vexp: a #NcHICosmoVexp + * + * Value of the time $\tau$ when the quantum regime ends during the expanding phase. + * + * Returns: $\tau_\mathrm{qe}$. + */ +gdouble +nc_hicosmo_Vexp_tau_qt_e (NcHICosmoVexp *Vexp) +{ + _nc_hicosmo_Vexp_prepare (Vexp); + + return Vexp->priv->tau_qt_e; +} + +/** + * nc_hicosmo_Vexp_xbe: + * @Vexp: a #NcHICosmoVexp + * + * Computes the value of $a_{0\mathrm{e}} / a_b$ where $a_{0\mathrm{e}}$ is the value + * of the scale factor at the scale when the Hubble parameter is equal to $\Omega_i + * H_0$. Where $\Omega_i$ is the density parameter of the cold dark matter if $d_\phi > + * 0$ or the density parameter of the cosmological constant if $d_\phi < 0$. + * + * Returns: $a_{0\mathrm{e}} / a_b$. + */ +gdouble +nc_hicosmo_Vexp_xbe (NcHICosmoVexp *Vexp) +{ + _nc_hicosmo_Vexp_prepare (Vexp); + + return exp (-Vexp->priv->alpha_b + Vexp->priv->alpha_0e); +} + +/** + * nc_hicosmo_Vexp_xbc: + * @Vexp: a #NcHICosmoVexp + * + * Computes the value of $a_{0\mathrm{c}} / a_b$ where $a_{0\mathrm{c}}$ is the value + * of the scale factor at the scale when the Hubble parameter is equal to $\Omega_i + * H_0$. Where $\Omega_i$ is the density parameter of the cold dark matter if $d_\phi < + * 0$ or the density parameter of the cosmological constant if $d_\phi > 0$. + * + * Returns: $a_{0\mathrm{c}} / a_b$. + */ +gdouble +nc_hicosmo_Vexp_xbc (NcHICosmoVexp *Vexp) +{ + _nc_hicosmo_Vexp_prepare (Vexp); + + return exp (-Vexp->priv->alpha_b + Vexp->priv->alpha_0c); +} + +/** + * nc_hicosmo_Vexp_alpha_0e: + * @Vexp: a #NcHICosmoVexp + * + * FIXME + * + * Returns: FIXME + */ +gdouble +nc_hicosmo_Vexp_alpha_0e (NcHICosmoVexp *Vexp) +{ + _nc_hicosmo_Vexp_prepare (Vexp); + + return Vexp->priv->alpha_0e; +} + +/** + * nc_hicosmo_Vexp_alpha_0c: + * @Vexp: a #NcHICosmoVexp + * + * FIXME + * + * Returns: FIXME + */ +gdouble +nc_hicosmo_Vexp_alpha_0c (NcHICosmoVexp *Vexp) +{ + _nc_hicosmo_Vexp_prepare (Vexp); + + return Vexp->priv->alpha_0c; +} + +/** + * nc_hicosmo_Vexp_xe_tau: + * @Vexp: a #NcHICosmoVexp + * @tau: $\tau$ + * + * Computes the value of $x_e$ at time $\tau$. Note that all interface implementations of + * perturbations use the observables computed at $x_\mathrm{e} = 1$, for example, the + * physical wave number $k$ at $\tau$ is $k_\mathrm{phys} = k x_\mathrm{e}$. + * + * Returns: $x_\mathrm{e}$. + */ +gdouble +nc_hicosmo_Vexp_xe_tau (NcHICosmoVexp *Vexp, const gdouble tau) +{ + _nc_hicosmo_Vexp_prepare (Vexp); + { + const gdouble alpha = Vexp->priv->alpha_b + 0.5 * tau * tau; + + return exp (Vexp->priv->alpha_0e - alpha); + } +} + +/** + * nc_hicosmo_Vexp_xc_tau: + * @Vexp: a #NcHICosmoVexp + * @tau: $\tau$ + * + * Computes the value of $x_c$ at time $\tau$. Note that all interface implementations of + * perturbations use the observables computed at $x_\mathrm{e} = 1$, see nc_hicosmo_Vexp_xe_tau(). + * + * + * Returns: $x_mathrm{c}$. + */ +gdouble +nc_hicosmo_Vexp_xc_tau (NcHICosmoVexp *Vexp, const gdouble tau) +{ + _nc_hicosmo_Vexp_prepare (Vexp); + { + const gdouble alpha = Vexp->priv->alpha_b + 0.5 * tau * tau; - return; + return exp (Vexp->priv->alpha_0c - alpha); } } /** - * nc_hicosmo_Vexp_eval_nu: + * nc_hicosmo_Vexp_tau_xe: * @Vexp: a #NcHICosmoVexp - * @tau: $\tau$ - * @k: $k$ + * @xe: $x_e$ * * FIXME * - * Returns: $\nu(\tau, k)$ + * Returns: $\tau$. */ gdouble -nc_hicosmo_Vexp_eval_nu (NcHICosmoVexp *Vexp, const gdouble tau, const gdouble k) +nc_hicosmo_Vexp_tau_xe (NcHICosmoVexp *Vexp, const gdouble xe) { _nc_hicosmo_Vexp_prepare (Vexp); - { - const gdouble tau2 = tau * tau; - const gdouble lna_a0e = 0.5 * tau2 + Vexp->priv->alpha_b - Vexp->priv->alpha_0e; - gdouble nu; - guint branch = 0; - - if (tau > Vexp->priv->tau_qt_c) - { - branch++; - - if (tau > Vexp->priv->tau_qt_e) - branch++; - } - - switch (branch) - { - case 0: /* Classical contraction */ - { - const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqc_mtau, -tau); - const gdouble q = exp (lnq); - const gdouble E = _nc_hicosmo_Vexp_Hc_H0_q (Vexp, q, Vexp->priv->cl_bc); - - nu = exp (-lna_a0e) * k * tau / E; - - break; - } - case 1: /* Quantum phase */ - { - const gdouble alpha = 0.5 * tau * tau + Vexp->priv->alpha_b; - const gdouble phi = (fabs (tau) < _NC_HICOSMO_VEXP_PHIA) ? _nc_hicosmo_Vexp_qt_phi_tau (Vexp, tau) : (ncm_spline_eval (Vexp->priv->phi_tau, tau) * tau); - gdouble H_lp, xq; - - _nc_hicosmo_Vexp_H_x (Vexp, 0.0, alpha, phi, &H_lp, &xq); - - nu = exp (-lna_a0e) * k * tau / (H_lp * Vexp->priv->RH_lp); - - break; - } - case 2: /* Classical expansion */ - { - const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqe_tau, tau); - const gdouble q = exp (lnq); - const gdouble E = _nc_hicosmo_Vexp_He_H0_q (Vexp, q, Vexp->priv->cl_be); - - nu = exp (-lna_a0e) * k * tau / E; - - break; - } - default: - g_assert_not_reached (); - break; - } + const gdouble log_xe = log (xe); + const gdouble alpha = Vexp->priv->alpha_0e - log_xe; - return nu; + /* + * We need to test for alpha < Vexp->priv->alpha_b, the fabs is to avoid domain + * problems when alpha is approximately equal to Vexp->priv->alpha_b. + */ + return +sqrt (2.0 * fabs (alpha - Vexp->priv->alpha_b)); } } /** - * nc_hicosmo_Vexp_gauss_eval_F: + * nc_hicosmo_Vexp_tau_xc: * @Vexp: a #NcHICosmoVexp - * @tau: $\tau$ - * @k: $k$ - * @B: $B$ - * @beta: $\beta$ + * @xc: $x_c$ * * FIXME * - * Returns: $F$ + * Returns: $\tau$. */ gdouble -nc_hicosmo_Vexp_gauss_eval_F (NcHICosmoVexp *Vexp, const gdouble tau, const gdouble k, const gdouble B, const gdouble beta) +nc_hicosmo_Vexp_tau_xc (NcHICosmoVexp *Vexp, const gdouble xc) { - const gdouble phi = nc_hicosmo_Vexp_phi (Vexp, tau); + _nc_hicosmo_Vexp_prepare (Vexp); + { + const gdouble log_xc = log (xc); + const gdouble alpha = Vexp->priv->alpha_0c - log_xc; - return 0.25 + B * exp (-gsl_pow_2 (phi / beta)); + /* + * We need to test for alpha < Vexp->priv->alpha_b, the fabs is to avoid domain + * problems when alpha is approximately equal to Vexp->priv->alpha_b. + */ + return -sqrt (2.0 * fabs (alpha - Vexp->priv->alpha_b)); + } } /** - * nc_hicosmo_Vexp_cauchy_eval_F: + * nc_hicosmo_Vexp_alpha: * @Vexp: a #NcHICosmoVexp * @tau: $\tau$ - * @k: $k$ - * @B: $B$ - * @beta: $\beta$ * - * FIXME + * Computes $\alpha = \ln a$, where $a$ is the scale factor, at time @tau. * - * Returns: $F$ + * Returns: $\alpha(\tau)$. */ gdouble -nc_hicosmo_Vexp_cauchy_eval_F (NcHICosmoVexp *Vexp, const gdouble tau, const gdouble k, const gdouble B, const gdouble beta) +nc_hicosmo_Vexp_alpha (NcHICosmoVexp *Vexp, const gdouble tau) { - const gdouble phi = nc_hicosmo_Vexp_phi (Vexp, tau); + _nc_hicosmo_Vexp_prepare (Vexp); - return 0.25 + B / (1.0 + gsl_pow_2 (phi / beta)); + return 0.5 * tau * tau + Vexp->priv->alpha_b; } /** - * nc_hicosmo_Vexp_gauss_eval_m: + * nc_hicosmo_Vexp_phi: * @Vexp: a #NcHICosmoVexp * @tau: $\tau$ - * @B: $B$ - * @beta: $\beta$ * - * FIXME + * Computes the scalar field $\phi$ at time @tau. * - * Returns: $F$ + * Returns: $\phi(\tau)$. */ gdouble -nc_hicosmo_Vexp_gauss_eval_m (NcHICosmoVexp *Vexp, const gdouble tau, const gdouble B, const gdouble beta) +nc_hicosmo_Vexp_phi (NcHICosmoVexp *Vexp, const gdouble tau) { - const gdouble F = nc_hicosmo_Vexp_gauss_eval_F (Vexp, tau, 0.0, B, beta); - + _nc_hicosmo_Vexp_prepare (Vexp); { - const gdouble tau2 = tau * tau; - const gdouble lna_a0e = 0.5 * tau2 + Vexp->priv->alpha_b - Vexp->priv->alpha_0e; - gdouble N; guint branch = 0; if (tau > Vexp->priv->tau_qt_c) @@ -3043,33 +3207,47 @@ nc_hicosmo_Vexp_gauss_eval_m (NcHICosmoVexp *Vexp, const gdouble tau, const gdou { case 0: /* Classical contraction */ { - const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqc_mtau, -tau); - const gdouble q = exp (lnq); - const gdouble E = _nc_hicosmo_Vexp_Hc_H0_q (Vexp, q, Vexp->priv->cl_bc); + const gdouble tau0 = Vexp->priv->tau_qt_c; + const gdouble phi0 = ncm_spline_eval (Vexp->priv->phi_tau, tau0) * tau0; + const gdouble lnq0 = ncm_spline_eval (Vexp->priv->lnqc_mtau, -tau0); + const gdouble q0 = exp (lnq0); + const gdouble E0 = _nc_hicosmo_Vexp_Hc_H0_q (Vexp, q0, Vexp->priv->cl_bc); + const gdouble sqrt1mx02 = sqrt (_nc_hicosmo_Vexp_1mx_q (q0, Vexp->priv->cl_bc) * _nc_hicosmo_Vexp_1px_q (q0, Vexp->priv->cl_bc)); + const gdouble L0 = fabs (E0) * sqrt1mx02 * exp (3.0 * phi0 / M_SQRT2); - N = exp (-lna_a0e) * tau / E; + const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqc_mtau, -tau); + const gdouble q = exp (lnq); + const gdouble E = _nc_hicosmo_Vexp_Hc_H0_q (Vexp, q, Vexp->priv->cl_bc); + const gdouble sqrt1mx2 = sqrt (_nc_hicosmo_Vexp_1mx_q (q, Vexp->priv->cl_bc) * _nc_hicosmo_Vexp_1px_q (q, Vexp->priv->cl_bc)); + + return M_SQRT2 * log (L0 / fabs (E * sqrt1mx2)) / 3.0; break; } case 1: /* Quantum phase */ { - const gdouble alpha = 0.5 * tau * tau + Vexp->priv->alpha_b; - const gdouble phi = (fabs (tau) < _NC_HICOSMO_VEXP_PHIA) ? _nc_hicosmo_Vexp_qt_phi_tau (Vexp, tau) : (ncm_spline_eval (Vexp->priv->phi_tau, tau) * tau); - gdouble H_lp, xq; - - _nc_hicosmo_Vexp_H_x (Vexp, 0.0, alpha, phi, &H_lp, &xq); + const gdouble phi = (fabs (tau) < _NC_HICOSMO_VEXP_PHIA) ? _nc_hicosmo_Vexp_qt_phi_tau (Vexp, tau) : ncm_spline_eval (Vexp->priv->phi_tau, tau) * tau; - N = exp (-lna_a0e) * tau / (H_lp * Vexp->priv->RH_lp); + return phi; break; } case 2: /* Classical expansion */ { - const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqe_tau, tau); - const gdouble q = exp (lnq); - const gdouble E = _nc_hicosmo_Vexp_He_H0_q (Vexp, q, Vexp->priv->cl_be); + const gdouble tau0 = Vexp->priv->tau_qt_e; + const gdouble phi0 = ncm_spline_eval (Vexp->priv->phi_tau, tau0) * tau0; + const gdouble lnq0 = ncm_spline_eval (Vexp->priv->lnqe_tau, tau0); + const gdouble q0 = exp (lnq0); + const gdouble E0 = _nc_hicosmo_Vexp_He_H0_q (Vexp, q0, Vexp->priv->cl_be); + const gdouble sqrt1mx02 = sqrt (_nc_hicosmo_Vexp_1mx_q (q0, Vexp->priv->cl_be) * _nc_hicosmo_Vexp_1px_q (q0, Vexp->priv->cl_be)); + const gdouble L0 = fabs (E0) * sqrt1mx02 * exp (3.0 * phi0 / M_SQRT2); - N = exp (-lna_a0e) * tau / E; + const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqe_tau, tau); + const gdouble q = exp (lnq); + const gdouble E = _nc_hicosmo_Vexp_He_H0_q (Vexp, q, Vexp->priv->cl_be); + const gdouble sqrt1mx2 = sqrt (_nc_hicosmo_Vexp_1mx_q (q, Vexp->priv->cl_be) * _nc_hicosmo_Vexp_1px_q (q, Vexp->priv->cl_be)); + + return M_SQRT2 * log (L0 / fabs (E * sqrt1mx2)) / 3.0; break; } @@ -3077,31 +3255,23 @@ nc_hicosmo_Vexp_gauss_eval_m (NcHICosmoVexp *Vexp, const gdouble tau, const gdou g_assert_not_reached (); break; } - - return F / N; } } /** - * nc_hicosmo_Vexp_cauchy_eval_m: + * nc_hicosmo_Vexp_Ricci_scale: * @Vexp: a #NcHICosmoVexp * @tau: $\tau$ - * @B: $B$ - * @beta: $\beta$ * * FIXME * - * Returns: $F$ + * Returns: $L_R(\tau) / \ell_\mathrm{P}$. */ gdouble -nc_hicosmo_Vexp_cauchy_eval_m (NcHICosmoVexp *Vexp, const gdouble tau, const gdouble B, const gdouble beta) +nc_hicosmo_Vexp_Ricci_scale (NcHICosmoVexp *Vexp, const gdouble tau) { - const gdouble F = nc_hicosmo_Vexp_cauchy_eval_F (Vexp, tau, 0.0, B, beta); - + _nc_hicosmo_Vexp_prepare (Vexp); { - const gdouble tau2 = tau * tau; - const gdouble lna_a0e = 0.5 * tau2 + Vexp->priv->alpha_b - Vexp->priv->alpha_0e; - gdouble N; guint branch = 0; if (tau > Vexp->priv->tau_qt_c) @@ -3116,33 +3286,32 @@ nc_hicosmo_Vexp_cauchy_eval_m (NcHICosmoVexp *Vexp, const gdouble tau, const gdo { case 0: /* Classical contraction */ { - const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqc_mtau, -tau); - const gdouble q = exp (lnq); - const gdouble E = _nc_hicosmo_Vexp_Hc_H0_q (Vexp, q, Vexp->priv->cl_bc); + const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqc_mtau, -tau); + const gdouble q = exp (lnq); + const gdouble E = _nc_hicosmo_Vexp_Hc_H0_q (Vexp, q, Vexp->priv->cl_bc); + const gdouble two_3mx2 = _nc_hicosmo_Vexp_1mx_q (q, Vexp->priv->cl_bc) * _nc_hicosmo_Vexp_1px_q (q, Vexp->priv->cl_bc) - 1.0 / 3.0; - N = exp (-lna_a0e) * tau / E; + return Vexp->priv->RH_lp / ((sqrt (18.0 * fabs (two_3mx2)) * fabs (E))); break; } case 1: /* Quantum phase */ { const gdouble alpha = 0.5 * tau * tau + Vexp->priv->alpha_b; - const gdouble phi = (fabs (tau) < _NC_HICOSMO_VEXP_PHIA) ? _nc_hicosmo_Vexp_qt_phi_tau (Vexp, tau) : (ncm_spline_eval (Vexp->priv->phi_tau, tau) * tau); - gdouble H_lp, xq; - - _nc_hicosmo_Vexp_H_x (Vexp, 0.0, alpha, phi, &H_lp, &xq); + const gdouble phi = (fabs (tau) < _NC_HICOSMO_VEXP_PHIA) ? _nc_hicosmo_Vexp_qt_phi_tau (Vexp, tau) : ncm_spline_eval (Vexp->priv->phi_tau, tau) * tau; - N = exp (-lna_a0e) * tau / (H_lp * Vexp->priv->RH_lp); + return _nc_hicosmo_Vexp_qt_Ricci_scale (Vexp, NC_HICOSMO (Vexp), alpha, phi); break; } case 2: /* Classical expansion */ { - const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqe_tau, tau); - const gdouble q = exp (lnq); - const gdouble E = _nc_hicosmo_Vexp_He_H0_q (Vexp, q, Vexp->priv->cl_be); + const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqe_tau, tau); + const gdouble q = exp (lnq); + const gdouble E = _nc_hicosmo_Vexp_He_H0_q (Vexp, q, Vexp->priv->cl_be); + const gdouble two_3mx2 = _nc_hicosmo_Vexp_1mx_q (q, Vexp->priv->cl_be) * _nc_hicosmo_Vexp_1px_q (q, Vexp->priv->cl_be) - 1.0 / 3.0; - N = exp (-lna_a0e) * tau / E; + return Vexp->priv->RH_lp / ((sqrt (18.0 * fabs (two_3mx2)) * fabs (E))); break; } @@ -3150,70 +3319,22 @@ nc_hicosmo_Vexp_cauchy_eval_m (NcHICosmoVexp *Vexp, const gdouble tau, const gdo g_assert_not_reached (); break; } - - return F / N; } } /** - * nc_hicosmo_Vexp_gauss_eval_xi: - * @Vexp: a #NcHICosmoVexp - * @tau: $\tau$ - * @k: $k$ - * @B: $B$ - * @beta: $\beta$ - * - * FIXME - * - * Returns: $\xi$ - */ -gdouble -nc_hicosmo_Vexp_gauss_eval_xi (NcHICosmoVexp *Vexp, const gdouble tau, const gdouble k, const gdouble B, const gdouble beta) -{ - const gdouble phi = nc_hicosmo_Vexp_phi (Vexp, tau); - - return log (0.25 * k) + log1p (4.0 * B * exp (-gsl_pow_2 (phi / beta))); -} - -/** - * nc_hicosmo_Vexp_cauchy_eval_xi: - * @Vexp: a #NcHICosmoVexp - * @tau: $\tau$ - * @k: $k$ - * @B: $B$ - * @beta: $\beta$ - * - * FIXME - * - * Returns: $\xi$ - */ -gdouble -nc_hicosmo_Vexp_cauchy_eval_xi (NcHICosmoVexp *Vexp, const gdouble tau, const gdouble k, const gdouble B, const gdouble beta) -{ - const gdouble phi = nc_hicosmo_Vexp_phi (Vexp, tau); - - return log (0.25 * k) + log1p (4.0 * B / (1.0 + gsl_pow_2 (phi / beta))); -} - -/** - * nc_hicosmo_Vexp_eval_F1: + * nc_hicosmo_Vexp_E_tau: * @Vexp: a #NcHICosmoVexp * @tau: $\tau$ - * @k: $k$ - * @B: $B$ - * @beta: $\beta$ * * FIXME * - * Returns: $F_1$ + * Returns: $E(\tau)$. */ gdouble -nc_hicosmo_Vexp_gauss_eval_F1 (NcHICosmoVexp *Vexp, const gdouble tau, const gdouble k, const gdouble B, const gdouble beta) +nc_hicosmo_Vexp_E_tau (NcHICosmoVexp *Vexp, const gdouble tau) { - const gdouble phi = nc_hicosmo_Vexp_phi (Vexp, tau); - const gdouble t1 = -8.0 * phi * B / (beta * beta) * exp (-gsl_pow_2 (phi / beta)) / (1.0 + 4.0 * B * exp (-gsl_pow_2 (phi / beta))); - gdouble x; - + _nc_hicosmo_Vexp_prepare (Vexp); { guint branch = 0; @@ -3231,31 +3352,21 @@ nc_hicosmo_Vexp_gauss_eval_F1 (NcHICosmoVexp *Vexp, const gdouble tau, const gdo { const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqc_mtau, -tau); const gdouble q = exp (lnq); - const gdouble xl = _nc_hicosmo_Vexp_x_q (q, Vexp->priv->cl_bc); - - if (fabs (xl) < 1.0e-1) - { - const gdouble dalpha = 0.5 * (tau - Vexp->priv->tau_x0) * (tau + Vexp->priv->tau_x0); - const gdouble x_s = _nc_hicosmo_Vexp_init_x_alpha_series (dalpha); + const gdouble E = _nc_hicosmo_Vexp_Hc_H0_q (Vexp, q, Vexp->priv->cl_bc); - x = x_s; - } - else - { - x = xl; - } + return E; break; } case 1: /* Quantum phase */ { const gdouble alpha = 0.5 * tau * tau + Vexp->priv->alpha_b; - const gdouble phi = (fabs (tau) < _NC_HICOSMO_VEXP_PHIA) ? _nc_hicosmo_Vexp_qt_phi_tau (Vexp, tau) : ncm_spline_eval (Vexp->priv->phi_tau, tau) * tau; + const gdouble phi = (fabs (tau) < _NC_HICOSMO_VEXP_PHIA) ? _nc_hicosmo_Vexp_qt_phi_tau (Vexp, tau) : (ncm_spline_eval (Vexp->priv->phi_tau, tau) * tau); gdouble H_lp, xq; _nc_hicosmo_Vexp_H_x (Vexp, 0.0, alpha, phi, &H_lp, &xq); - x = xq; + return (H_lp * Vexp->priv->RH_lp); break; } @@ -3263,54 +3374,36 @@ nc_hicosmo_Vexp_gauss_eval_F1 (NcHICosmoVexp *Vexp, const gdouble tau, const gdo { const gdouble lnq = ncm_spline_eval (Vexp->priv->lnqe_tau, tau); const gdouble q = exp (lnq); - const gdouble xl = _nc_hicosmo_Vexp_x_q (q, Vexp->priv->cl_be); - - if (fabs (xl) < 1.0e-1) - { - const gdouble dalpha = 0.5 * (tau - Vexp->priv->tau_x0) * (tau + Vexp->priv->tau_x0); - const gdouble x_s = _nc_hicosmo_Vexp_init_x_alpha_series (dalpha); + const gdouble E = _nc_hicosmo_Vexp_He_H0_q (Vexp, q, Vexp->priv->cl_be); - x = x_s; - } - else - { - x = xl; - } + return E; break; } default: g_assert_not_reached (); - break; - } - } - { - const gdouble nu = nc_hicosmo_Vexp_eval_nu (Vexp, tau, k); + return 0.0; - return t1 * tau * x / (2.0 * nu); + break; + } } } /** - * nc_hicosmo_Vexp_cauchy_eval_F1: + * nc_hicosmo_Vexp_x_y: * @Vexp: a #NcHICosmoVexp * @tau: $\tau$ - * @k: $k$ - * @B: $B$ - * @beta: $\beta$ + * @x: (out): the value of $x(\tau)$ + * @y: (out): the value of $y(\tau)$ * * FIXME * - * Returns: $F_1$ */ -gdouble -nc_hicosmo_Vexp_cauchy_eval_F1 (NcHICosmoVexp *Vexp, const gdouble tau, const gdouble k, const gdouble B, const gdouble beta) +void +nc_hicosmo_Vexp_x_y (NcHICosmoVexp *Vexp, const gdouble tau, gdouble *x, gdouble *y) { - const gdouble phi = nc_hicosmo_Vexp_phi (Vexp, tau); - const gdouble t1 = -8.0 * phi * B / (beta * beta) * 1.0 / gsl_pow_2 (1.0 + gsl_pow_2 (phi / beta)) * 1.0 / (1.0 + 4.0 * B / (1.0 + gsl_pow_2 (phi / beta))); - gdouble x; - + _nc_hicosmo_Vexp_prepare (Vexp); { guint branch = 0; @@ -3335,11 +3428,11 @@ nc_hicosmo_Vexp_cauchy_eval_F1 (NcHICosmoVexp *Vexp, const gdouble tau, const gd const gdouble dalpha = 0.5 * (tau - Vexp->priv->tau_x0) * (tau + Vexp->priv->tau_x0); const gdouble x_s = _nc_hicosmo_Vexp_init_x_alpha_series (dalpha); - x = x_s; + x[0] = x_s; } else { - x = xl; + x[0] = xl; } break; @@ -3352,7 +3445,7 @@ nc_hicosmo_Vexp_cauchy_eval_F1 (NcHICosmoVexp *Vexp, const gdouble tau, const gd _nc_hicosmo_Vexp_H_x (Vexp, 0.0, alpha, phi, &H_lp, &xq); - x = xq; + x[0] = xq; break; } @@ -3367,11 +3460,11 @@ nc_hicosmo_Vexp_cauchy_eval_F1 (NcHICosmoVexp *Vexp, const gdouble tau, const gd const gdouble dalpha = 0.5 * (tau - Vexp->priv->tau_x0) * (tau + Vexp->priv->tau_x0); const gdouble x_s = _nc_hicosmo_Vexp_init_x_alpha_series (dalpha); - x = x_s; + x[0] = x_s; } else { - x = xl; + x[0] = xl; } break; @@ -3380,12 +3473,10 @@ nc_hicosmo_Vexp_cauchy_eval_F1 (NcHICosmoVexp *Vexp, const gdouble tau, const gd g_assert_not_reached (); break; } - } - { - const gdouble nu = nc_hicosmo_Vexp_eval_nu (Vexp, tau, k); + y[0] = GSL_SIGN (tau) * sqrt (fabs (1.0 - x[0] * x[0])); - return t1 * tau * x / (2.0 * nu); + return; } } diff --git a/numcosmo/model/nc_hicosmo_Vexp.h b/numcosmo/model/nc_hicosmo_Vexp.h index f44d57f31..edc8f062c 100644 --- a/numcosmo/model/nc_hicosmo_Vexp.h +++ b/numcosmo/model/nc_hicosmo_Vexp.h @@ -57,8 +57,17 @@ struct _NcHICosmoVexpClass * @NC_HICOSMO_VEXP_D_PHI: mean of the scalar field wave function distribution * @NC_HICOSMO_VEXP_ALPHA_B: logarithm base e of the scale factor at the bounce * @NC_HICOSMO_VEXP_X_B: ratio of the scale factor today and at the bounce + * @NC_HICOSMO_VEXP_EM_B: electromagnetic coupling amplitude + * @NC_HICOSMO_VEXP_EM_BETA: electromagnetic coupling scale + * + * Scalar field parameters enumerator. This enumerator is used to access the scalar field parameters + * in the NcHICosmoVexp object. + * + * The parameters @NC_HICOSMO_VEXP_EM_B and @NC_HICOSMO_VEXP_EM_BETA are used to define the + * electromagnetic coupling amplitude and scale, respectively. They are only used if the + * electromagnetic coupling is set to NC_HICOSMO_VEXP_EM_COUPLING_GAUSS or + * NC_HICOSMO_VEXP_EM_COUPLING_CAUCHY. * - * FIXME * */ typedef enum /*< enum,underscore_name=NC_HICOSMO_VEXP_SPARAMS >*/ @@ -70,10 +79,29 @@ typedef enum /*< enum,underscore_name=NC_HICOSMO_VEXP_SPARAMS >*/ NC_HICOSMO_VEXP_D_PHI, NC_HICOSMO_VEXP_ALPHA_B, NC_HICOSMO_VEXP_X_B, + NC_HICOSMO_VEXP_EM_B, + NC_HICOSMO_VEXP_EM_BETA, /* < private > */ NC_HICOSMO_VEXP_SPARAM_LEN, /*< skip >*/ } NcHICosmoVexpSParams; +/** + * NcHICosmoVexpEMCoupling: + * @NC_HICOSMO_VEXP_EM_COUPLING_NONE: No coupling + * @NC_HICOSMO_VEXP_EM_COUPLING_GAUSS: Gaussian coupling + * @NC_HICOSMO_VEXP_EM_COUPLING_CAUCHY: Cauchy coupling + * + * Electromagnetic coupling enumerator. + * + */ +typedef enum /*< enum,underscore_name=NC_HICOSMO_VEXP_EM_COUPLING >*/ +{ + NC_HICOSMO_VEXP_EM_COUPLING_NONE = 0, + NC_HICOSMO_VEXP_EM_COUPLING_GAUSS, + NC_HICOSMO_VEXP_EM_COUPLING_CAUCHY, + NC_HICOSMO_VEXP_EM_COUPLING_INVALID, +} NcHICosmoVexpEMCoupling; + struct _NcHICosmoVexp { /*< private >*/ @@ -85,6 +113,9 @@ GType nc_hicosmo_Vexp_get_type (void) G_GNUC_CONST; NcHICosmoVexp *nc_hicosmo_Vexp_new (void); +void nc_hicosmo_Vexp_set_em_coupling (NcHICosmoVexp *Vexp, const NcHICosmoVexpEMCoupling coupling); +NcHICosmoVexpEMCoupling nc_hicosmo_Vexp_get_em_coupling (NcHICosmoVexp *Vexp); + gdouble nc_hicosmo_Vexp_tau_min (NcHICosmoVexp *Vexp); gdouble nc_hicosmo_Vexp_tau_max (NcHICosmoVexp *Vexp); @@ -94,7 +125,8 @@ gdouble nc_hicosmo_Vexp_tau_qt_e (NcHICosmoVexp *Vexp); gdouble nc_hicosmo_Vexp_xbe (NcHICosmoVexp *Vexp); gdouble nc_hicosmo_Vexp_xbc (NcHICosmoVexp *Vexp); -gdouble nc_hicosmo_Vexp_x_tau (NcHICosmoVexp *Vexp, const gdouble tau); +gdouble nc_hicosmo_Vexp_xe_tau (NcHICosmoVexp *Vexp, const gdouble tau); +gdouble nc_hicosmo_Vexp_xc_tau (NcHICosmoVexp *Vexp, const gdouble tau); gdouble nc_hicosmo_Vexp_tau_xe (NcHICosmoVexp *Vexp, const gdouble xe); gdouble nc_hicosmo_Vexp_tau_xc (NcHICosmoVexp *Vexp, const gdouble xc); @@ -104,23 +136,10 @@ gdouble nc_hicosmo_Vexp_alpha_0c (NcHICosmoVexp *Vexp); gdouble nc_hicosmo_Vexp_alpha (NcHICosmoVexp *Vexp, const gdouble tau); gdouble nc_hicosmo_Vexp_phi (NcHICosmoVexp *Vexp, const gdouble tau); +gdouble nc_hicosmo_Vexp_E_tau (NcHICosmoVexp *Vexp, const gdouble tau); gdouble nc_hicosmo_Vexp_Ricci_scale (NcHICosmoVexp *Vexp, const gdouble tau); void nc_hicosmo_Vexp_x_y (NcHICosmoVexp *Vexp, const gdouble tau, gdouble *x, gdouble *y); -gdouble nc_hicosmo_Vexp_eval_nu (NcHICosmoVexp *Vexp, const gdouble tau, const gdouble k); - -gdouble nc_hicosmo_Vexp_eval_F (NcHICosmoVexp *Vexp, const gdouble tau, const gdouble k, const gdouble B, const gdouble beta); - -gdouble nc_hicosmo_Vexp_gauss_eval_m (NcHICosmoVexp *Vexp, const gdouble tau, const gdouble B, const gdouble beta); -gdouble nc_hicosmo_Vexp_gauss_eval_xi (NcHICosmoVexp *Vexp, const gdouble tau, const gdouble k, const gdouble B, const gdouble beta); -gdouble nc_hicosmo_Vexp_gauss_eval_F1 (NcHICosmoVexp *Vexp, const gdouble tau, const gdouble k, const gdouble B, const gdouble beta); - -gdouble nc_hicosmo_Vexp_cauchy_eval_F (NcHICosmoVexp *Vexp, const gdouble tau, const gdouble k, const gdouble B, const gdouble beta); -gdouble nc_hicosmo_Vexp_cauchy_eval_m (NcHICosmoVexp *Vexp, const gdouble tau, const gdouble B, const gdouble beta); -gdouble nc_hicosmo_Vexp_cauchy_eval_xi (NcHICosmoVexp *Vexp, const gdouble tau, const gdouble k, const gdouble B, const gdouble beta); -gdouble nc_hicosmo_Vexp_cauchy_eval_F1 (NcHICosmoVexp *Vexp, const gdouble tau, const gdouble k, const gdouble B, const gdouble beta); - - #define NC_HICOSMO_VEXP_DEFAULT_H0 (70.0) #define NC_HICOSMO_VEXP_DEFAULT_OMEGA_C (0.25) #define NC_HICOSMO_VEXP_DEFAULT_OMEGA_L (0.75) @@ -128,6 +147,8 @@ gdouble nc_hicosmo_Vexp_cauchy_eval_F1 (NcHICosmoVexp *Vexp, const gdouble tau, #define NC_HICOSMO_VEXP_DEFAULT_D_PHI (-0.3) #define NC_HICOSMO_VEXP_DEFAULT_ALPHA_B (0.1) #define NC_HICOSMO_VEXP_DEFAULT_X_B (1.0e30) +#define NC_HICOSMO_VEXP_DEFAULT_EM_B (1.0e-10) +#define NC_HICOSMO_VEXP_DEFAULT_EM_BETA (1.0e-1) #define NC_HICOSMO_VEXP_DEBUG_EVOL_QT (FALSE) #define NC_HICOSMO_VEXP_DEBUG_EVOL_CL (FALSE) diff --git a/numcosmo/model/nc_hicosmo_qgrw.c b/numcosmo/model/nc_hicosmo_qgrw.c index 94bce987c..3e597c253 100644 --- a/numcosmo/model/nc_hicosmo_qgrw.c +++ b/numcosmo/model/nc_hicosmo_qgrw.c @@ -26,15 +26,18 @@ /** * SECTION:nc_hicosmo_qgrw * @title: NcHICosmoQGRW - * @short_description: Radiation plus $w$-fluid model with a quantum generated bounce phase model. + * @short_description: Radiation plus $w$-fluid model with a quantum generated bounce + * phase model. * - * In this model the adiabatic mode $\zeta$ has its mass, speed of sound square $c_s^2$ and frequency square $\nu_\zeta^2$ given by - * \begin{align} - * m_\zeta &= 3 \Delta_\bar{K}\sqrt{\Omega_{w0}} x^{-3(1-w)/2}\frac{(1 + w) + 4R/3}{c_s^2}\frac{1}{\sqrt{(1-exp(-2\vert\alpha\vert)) + (1-exp(-3(1-w)\vert\alpha\vert))}}, \\\\ + * In this model the adiabatic mode $\zeta$ has its mass, speed of sound square $c_s^2$ + * and frequency square $\nu_\zeta^2$ given by \begin{align} m_\zeta &= 3 + * \Delta_\bar{K}\sqrt{\Omega_{w0}} x^{-3(1-w)/2}\frac{(1 + w) + + * 4R/3}{c_s^2}\frac{1}{\sqrt{(1-exp(-2\vert\alpha\vert)) + + * (1-exp(-3(1-w)\vert\alpha\vert))}}, \\\\ * c_s^2 &= \frac{w (1 + w) + 4R/9}{(1+w) + 4R/3}, \\\\ - * \nu_\zeta^2 &= \frac {c_s^2 k^2}{\Omega_{w0} x^{1+3w} ((1-exp(-2\vert\alpha\vert)) + (1-exp(-3(1-w)\vert\alpha\vert)))}, - * \end{align} - * where $$R \equiv \frac{\Omega_{r0} x}{\Omega_{w0} x^{3w}}.$$ + * \nu_\zeta^2 &= \frac {c_s^2 k^2}{\Omega_{w0} x^{1+3w} ((1-exp(-2\vert\alpha\vert)) + + * (1-exp(-3(1-w)\vert\alpha\vert)))}, \end{align} where $$R \equiv \frac{\Omega_{r0} + * x}{\Omega_{w0} x^{3w}}.$$ * */ diff --git a/numcosmo/model/nc_hicosmo_qgw.c b/numcosmo/model/nc_hicosmo_qgw.c new file mode 100644 index 000000000..9c1de7961 --- /dev/null +++ b/numcosmo/model/nc_hicosmo_qgw.c @@ -0,0 +1,450 @@ +/*************************************************************************** + * nc_hicosmo_qgw.c + * + * Tue March 19 10:45:17 2024 + * Copyright 2024 Sandro Dias Pinto Vitenti + * > + ****************************************************************************/ +/* + * nc_hicosmo_qgw.c + * Copyright (C) 2024 Sandro Dias Pinto Vitenti + * + * numcosmo is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * numcosmo is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +/** + * SECTION:nc_hicosmo_qgw + * @title: NcHICosmoQGW + * @short_description: $w$-fluid model with a quantum generated bounce phase model. + * + * The NcHICosmoQGW class implements the $w$-fluid model with a quantum generated + * bounce phase model. + * + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif /* HAVE_CONFIG_H */ +#include "build_cfg.h" + +#include "model/nc_hicosmo_qgw.h" +#include "perturbations/nc_hipert_adiab.h" + +#ifndef NUMCOSMO_GIR_SCAN +#include +#endif /* NUMCOSMO_GIR_SCAN */ + +static void nc_hipert_iadiab_interface_init (NcHIPertIAdiabInterface *iface); + +struct _NcHICosmoQGWPrivate +{ + guint place_holder; +}; + +G_DEFINE_TYPE_WITH_CODE (NcHICosmoQGW, nc_hicosmo_qgw, NC_TYPE_HICOSMO, + G_IMPLEMENT_INTERFACE (NC_TYPE_HIPERT_IADIAB, + nc_hipert_iadiab_interface_init) + G_ADD_PRIVATE (NcHICosmoQGW) + ); + +enum +{ + PROP_0, + PROP_SIZE, +}; + +static void +nc_hicosmo_qgw_init (NcHICosmoQGW *cosmo_qgw) +{ + NcHICosmoQGWPrivate * const self = cosmo_qgw->priv = nc_hicosmo_qgw_get_instance_private (cosmo_qgw); + + self->place_holder = 0; +} + +static void +nc_hicosmo_qgw_finalize (GObject *object) +{ + /* Chain up : end */ + G_OBJECT_CLASS (nc_hicosmo_qgw_parent_class)->finalize (object); +} + +static gdouble _nc_hicosmo_qgw_E2 (NcHICosmo *cosmo, gdouble z); +static gdouble _nc_hicosmo_qgw_dE2_dz (NcHICosmo *cosmo, gdouble z); +static gdouble _nc_hicosmo_qgw_E2 (NcHICosmo *cosmo, gdouble z); +static gdouble _nc_hicosmo_qgw_d2E2_dz2 (NcHICosmo *cosmo, gdouble z); +static gdouble _nc_hicosmo_qgw_bgp_cs2 (NcHICosmo *cosmo, gdouble z); + +static gdouble _nc_hicosmo_qgw_H0 (NcHICosmo *cosmo); +static gdouble _nc_hicosmo_qgw_Omega_t0 (NcHICosmo *cosmo); +static gdouble _nc_hicosmo_qgw_Omega_c0 (NcHICosmo *cosmo); +static gdouble _nc_hicosmo_qgw_xb (NcHICosmo *cosmo); + +static void +nc_hicosmo_qgw_class_init (NcHICosmoQGWClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + NcHICosmoClass *parent_class = NC_HICOSMO_CLASS (klass); + NcmModelClass *model_class = NCM_MODEL_CLASS (klass); + + object_class->finalize = nc_hicosmo_qgw_finalize; + + ncm_model_class_set_name_nick (model_class, "QGW", "QGW"); + ncm_model_class_add_params (model_class, NC_HICOSMO_QGW_SPARAM_LEN, 0, PROP_SIZE); + + /* Set H_0 param info */ + ncm_model_class_set_sparam (model_class, NC_HICOSMO_QGW_H0, "H_0", "H0", + 10.0, 500.0, 1.0, + NC_HICOSMO_DEFAULT_PARAMS_ABSTOL, NC_HICOSMO_QGW_DEFAULT_H0, + NCM_PARAM_TYPE_FIXED); + /* Set Omega_x0 param info */ + ncm_model_class_set_sparam (model_class, NC_HICOSMO_QGW_OMEGA_W, "\\Omega_{w0}", "Omegaw", + 1e-8, 10.0, 1.0e-2, + NC_HICOSMO_DEFAULT_PARAMS_ABSTOL, NC_HICOSMO_QGW_DEFAULT_OMEGA_W, + NCM_PARAM_TYPE_FREE); + /* Set w param info */ + ncm_model_class_set_sparam (model_class, NC_HICOSMO_QGW_W, "w", "w", + 1e-50, 1.0, 1.0e-8, + NC_HICOSMO_DEFAULT_PARAMS_ABSTOL, NC_HICOSMO_QGW_DEFAULT_W, + NCM_PARAM_TYPE_FIXED); + /* Set xb param info */ + ncm_model_class_set_sparam (model_class, NC_HICOSMO_QGW_X_B, "x_b", "xb", + 1.0e10, 1.0e40, 1.0e25, + NC_HICOSMO_DEFAULT_PARAMS_ABSTOL, NC_HICOSMO_QGW_DEFAULT_X_B, + NCM_PARAM_TYPE_FIXED); + + + /* Check for errors in parameters initialization */ + ncm_model_class_check_params_info (model_class); + + nc_hicosmo_set_H0_impl (parent_class, &_nc_hicosmo_qgw_H0); + nc_hicosmo_set_E2_impl (parent_class, &_nc_hicosmo_qgw_E2); + nc_hicosmo_set_Omega_c0_impl (parent_class, &_nc_hicosmo_qgw_Omega_c0); + nc_hicosmo_set_Omega_t0_impl (parent_class, &_nc_hicosmo_qgw_Omega_t0); + nc_hicosmo_set_xb_impl (parent_class, &_nc_hicosmo_qgw_xb); + nc_hicosmo_set_dE2_dz_impl (parent_class, &_nc_hicosmo_qgw_dE2_dz); + nc_hicosmo_set_d2E2_dz2_impl (parent_class, &_nc_hicosmo_qgw_d2E2_dz2); + nc_hicosmo_set_bgp_cs2_impl (parent_class, &_nc_hicosmo_qgw_bgp_cs2); +} + +#define VECTOR (NCM_MODEL (cosmo)) +#define MACRO_H0 (ncm_model_orig_param_get (VECTOR, NC_HICOSMO_QGW_H0)) +#define OMEGA_W (ncm_model_orig_param_get (VECTOR, NC_HICOSMO_QGW_OMEGA_W)) +#define W (ncm_model_orig_param_get (VECTOR, NC_HICOSMO_QGW_W)) +#define X_B (ncm_model_orig_param_get (VECTOR, NC_HICOSMO_QGW_X_B)) + +static gdouble _nc_hicosmo_qgw_adiab_eval_xi (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k); +static gdouble _nc_hicosmo_qgw_adiab_eval_F1 (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k); +static gdouble _nc_hicosmo_qgw_adiab_eval_nu (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k); +static gdouble _nc_hicosmo_qgw_adiab_eval_m (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k); +static gdouble _nc_hicosmo_qgw_adiab_eval_unit (NcHIPertIAdiab *iad); +static gdouble _nc_hicosmo_qgw_adiab_eval_x (NcHIPertIAdiab *iad, const gdouble tau); +static gdouble _nc_hicosmo_qgw_adiab_eval_p2Psi (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k); +static gdouble _nc_hicosmo_qgw_adiab_eval_p2drho (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k); +static gdouble _nc_hicosmo_qgw_adiab_eval_lapse (NcHIPertIAdiab *iad, const gdouble tau); +static gdouble _nc_hicosmo_qgw_adiab_eval_tau_hubble (NcHIPertIAdiab *iad, const gdouble k); +static gdouble _nc_hicosmo_qgw_adiab_eval_tau_jeans (NcHIPertIAdiab *iad, const gdouble k); +static gdouble _nc_hicosmo_qgw_adiab_eval_hubble (NcHIPertIAdiab *iad, const gdouble tau); + +static void +nc_hipert_iadiab_interface_init (NcHIPertIAdiabInterface *iface) +{ + iface->eval_xi = &_nc_hicosmo_qgw_adiab_eval_xi; + iface->eval_F1 = &_nc_hicosmo_qgw_adiab_eval_F1; + iface->eval_nu = &_nc_hicosmo_qgw_adiab_eval_nu; + iface->eval_m = &_nc_hicosmo_qgw_adiab_eval_m; + iface->eval_unit = &_nc_hicosmo_qgw_adiab_eval_unit; + iface->eval_x = &_nc_hicosmo_qgw_adiab_eval_x; + iface->eval_p2Psi = &_nc_hicosmo_qgw_adiab_eval_p2Psi; + iface->eval_p2drho = &_nc_hicosmo_qgw_adiab_eval_p2drho; + iface->eval_lapse = &_nc_hicosmo_qgw_adiab_eval_lapse; + iface->eval_tau_hubble = &_nc_hicosmo_qgw_adiab_eval_tau_hubble; + iface->eval_tau_jeans = &_nc_hicosmo_qgw_adiab_eval_tau_jeans; + iface->eval_hubble = &_nc_hicosmo_qgw_adiab_eval_hubble; +} + +/* + * Interface implementation -- NcHIPertIAdiab + */ + +static gdouble +_nc_hicosmo_qgw_adiab_eval_xi (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k) +{ + NcHICosmoQGW *qgw = NC_HICOSMO_QGW (iad); + NcHICosmo *cosmo = NC_HICOSMO (iad); + const gdouble w = W; + const gdouble xb = X_B; + const gdouble Omega_w = OMEGA_W; + const gdouble xb2 = xb * xb; + const gdouble cs = sqrt (w); + const gdouble tanh_tau = tanh (tau); + const gdouble tanh_tau2 = tanh_tau * tanh_tau; + const gdouble lnfact = log (3.0 * (1.0 + w) * k / (cs * tanh_tau2)); + const gdouble x = _nc_hicosmo_qgw_adiab_eval_x (iad, tau); + + return lnfact - 2.0 * log (x); +} + +static gdouble +_nc_hicosmo_qgw_adiab_eval_F1 (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k) +{ + NcHICosmoQGW *qgw = NC_HICOSMO_QGW (iad); + NcHICosmo *cosmo = NC_HICOSMO (iad); + const gdouble w = W; + const gdouble xb = X_B; + const gdouble Omega_w = OMEGA_W; + const gdouble xb_1p3w_2 = pow (xb, (1.0 + 3.0 * w) / 2.0); + const gdouble sqrt_Omega_w = sqrt (Omega_w); + const gdouble cs = sqrt (w); + const gdouble tanh_tau = tanh (tau); + const gdouble cosh_tau = cosh (tau); + const gdouble cosh_2tau = cosh (2.0 * tau); + const gdouble fact = xb_1p3w_2 * sqrt_Omega_w / (2.0 * cs * k); + + return fact / pow (cosh_tau, (7.0 - 3.0 * w) / (3.0 * (1.0 - w))) / tanh_tau * (cosh_2tau + 3.0 * w - 4.0); +} + +static gdouble +_nc_hicosmo_qgw_adiab_eval_nu (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k) +{ + NcHICosmoQGW *qgw = NC_HICOSMO_QGW (iad); + NcHICosmo *cosmo = NC_HICOSMO (iad); + const gdouble w = W; + const gdouble Omega_w = OMEGA_W; + const gdouble w2 = w * w; + const gdouble sqrt_Omega_w = sqrt (Omega_w); + const gdouble cs = sqrt (w); + const gdouble x = _nc_hicosmo_qgw_adiab_eval_x (iad, tau); + + return cs * 2.0 / (3.0 * (1.0 - w)) * k / sqrt_Omega_w / pow (x, 0.5 + 1.5 * w); +} + +static gdouble +_nc_hicosmo_qgw_adiab_eval_m (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k) +{ + NcHICosmoQGW *qgw = NC_HICOSMO_QGW (iad); + NcHICosmo *cosmo = NC_HICOSMO (iad); + const gdouble w = W; + const gdouble Omega_w = OMEGA_W; + const gdouble w2 = w * w; + const gdouble sqrt_Omega_w = sqrt (Omega_w); + const gdouble cs2 = w; + const gdouble tanh_tau = tanh (tau); + const gdouble tanh_tau2 = tanh_tau * tanh_tau; + const gdouble x = _nc_hicosmo_qgw_adiab_eval_x (iad, tau); + + return 9.0 * (1.0 - w2) * sqrt_Omega_w / (2.0 * pow (x, 1.5 * (1.0 - w)) * cs2 * tanh_tau2); +} + +static gdouble +_nc_hicosmo_qgw_adiab_eval_unit (NcHIPertIAdiab *iad) +{ + NcHICosmoQGW *qgw = NC_HICOSMO_QGW (iad); + NcHICosmo *cosmo = NC_HICOSMO (iad); + const gdouble RH_lp = nc_hicosmo_RH_planck (cosmo); + const gdouble factor = sqrt (8.0 * ncm_c_pi () / 3.0); + + return factor / RH_lp; +} + +static gdouble +_nc_hicosmo_qgw_adiab_eval_x (NcHIPertIAdiab *iad, const gdouble tau) +{ + NcHICosmoQGW *qgw = NC_HICOSMO_QGW (iad); + NcHICosmo *cosmo = NC_HICOSMO (iad); + const gdouble xb = X_B; + const gdouble w = W; + + return xb / pow (cosh (tau), 2.0 / (3.0 * (1 - w))); +} + +static gdouble +_nc_hicosmo_qgw_adiab_eval_p2Psi (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k) +{ + NcHICosmoQGW *qgw = NC_HICOSMO_QGW (iad); + NcHICosmo *cosmo = NC_HICOSMO (iad); + const gdouble w = W; + const gdouble Omega_w = OMEGA_W; + const gdouble tanh_tau = tanh (tau); + const gdouble x = _nc_hicosmo_qgw_adiab_eval_x (iad, tau); + const gdouble sqrt_Omega_w = sqrt (Omega_w); + + return -sqrt_Omega_w *pow (x, 2.5 + 1.5 *w) * tanh_tau / (2.0 * k * k); +} + +static gdouble +_nc_hicosmo_qgw_adiab_eval_p2drho (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k) +{ + NcHICosmoQGW *qgw = NC_HICOSMO_QGW (iad); + NcHICosmo *cosmo = NC_HICOSMO (iad); + const gdouble w = W; + const gdouble Omega_w = OMEGA_W; + const gdouble tanh_tau = tanh (tau); + const gdouble x = _nc_hicosmo_qgw_adiab_eval_x (iad, tau); + const gdouble sqrt_Omega_w = sqrt (Omega_w); + + return -tanh_tau *pow (x, 1.5 *(1.0 - w)) / (sqrt_Omega_w * (1.0 + w)); +} + +static gdouble +_nc_hicosmo_qgw_adiab_eval_lapse (NcHIPertIAdiab *iad, const gdouble tau) +{ + NcHICosmoQGW *qgw = NC_HICOSMO_QGW (iad); + NcHICosmo *cosmo = NC_HICOSMO (iad); + const gdouble w = W; + const gdouble xb = X_B; + const gdouble Omega_w = OMEGA_W; + const gdouble sqrt_Omega_w = sqrt (Omega_w); + const gdouble x = _nc_hicosmo_qgw_adiab_eval_x (iad, tau); + + return 2.0 / (3.0 * (1.0 - w) * sqrt_Omega_w * pow (x, 1.5 * (1.0 + w))); +} + +static gdouble +_nc_hicosmo_qgw_adiab_eval_tau_hubble (NcHIPertIAdiab *iad, gdouble k) +{ + NcHICosmoQGW *qgw = NC_HICOSMO_QGW (iad); + NcHICosmo *cosmo = NC_HICOSMO (iad); + const gdouble k2 = k * k; + const gdouble Omega_w = OMEGA_W; + const gdouble w = W; + const gdouble xb = X_B; + const gdouble xf = pow (k2 / Omega_w, 1.0 / (1.0 + 3.0 * w)); + const gdouble xb_xf = xb / xf; + const gdouble f0 = pow (xb_xf, 1.5 * (1.0 - w)); + + return acosh (f0); +} + +static gdouble +_nc_hicosmo_qgw_adiab_eval_tau_jeans (NcHIPertIAdiab *iad, gdouble k) +{ + NcHICosmoQGW *qgw = NC_HICOSMO_QGW (iad); + NcHICosmo *cosmo = NC_HICOSMO (iad); + const gdouble k2 = k * k; + const gdouble Omega_w = OMEGA_W; + const gdouble w = W; + const gdouble xb = X_B; + const gdouble xf = pow (2.0 * w * k2 / (3.0 * Omega_w), 1.0 / (1.0 + 3.0 * w)); + const gdouble xb_xf = xb / xf; + const gdouble f0 = pow (xb_xf, 1.5 * (1.0 - w)); + + return acosh (f0); +} + +static gdouble +_nc_hicosmo_qgw_adiab_eval_hubble (NcHIPertIAdiab *iad, const gdouble tau) +{ + NcHICosmoQGW *qgw = NC_HICOSMO_QGW (iad); + NcHICosmo *cosmo = NC_HICOSMO (iad); + const gdouble w = W; + const gdouble tanh_tau = tanh (tau); + const gdouble lapse = _nc_hicosmo_qgw_adiab_eval_lapse (iad, tau); + + return 2.0 * tanh_tau / (3.0 * (1.0 - w) * lapse); +} + +/* + * NcHICosmo virtual methods + */ + +static gdouble +_nc_hicosmo_qgw_E2 (NcHICosmo *cosmo, gdouble z) +{ + NcHICosmoQGW *qgw = NC_HICOSMO_QGW (cosmo); + + NcHICosmoQGWPrivate * const self = qgw->priv = nc_hicosmo_qgw_get_instance_private (qgw); + const gdouble x = 1.0 + z; + const gdouble x3_1pw = pow (x, 3.0 * (1.0 + W)); + const gdouble Omega_w = OMEGA_W; + + return Omega_w * x3_1pw; +} + +/**************************************************************************** + * Normalized Hubble function redshift derivative + ****************************************************************************/ + +static gdouble +_nc_hicosmo_qgw_dE2_dz (NcHICosmo *cosmo, gdouble z) +{ + const gdouble x = 1.0 + z; + const gdouble three_1pw = 3.0 * (1.0 + W); + const gdouble x2p3w = pow (x, three_1pw - 1.0); + + return three_1pw * x2p3w; +} + +static gdouble +_nc_hicosmo_qgw_d2E2_dz2 (NcHICosmo *cosmo, gdouble z) +{ + const gdouble x = 1.0 + z; + const gdouble three_1pw = 3.0 * (1.0 + W); + const gdouble twop3w = 2.0 + 3.0 * W; + + return three_1pw * twop3w * pow (x, twop3w - 1.0); +} + +/**************************************************************************** + * Speed of sound squared + ****************************************************************************/ +static gdouble +_nc_hicosmo_qgw_bgp_cs2 (NcHICosmo *cosmo, gdouble z) +{ + const gdouble w = W; + + return w; +} + +/**************************************************************************** + * Simple functions + ****************************************************************************/ +static gdouble +_nc_hicosmo_qgw_H0 (NcHICosmo *cosmo) +{ + return MACRO_H0 * OMEGA_W; +} + +static gdouble +_nc_hicosmo_qgw_Omega_t0 (NcHICosmo *cosmo) +{ + return 1.0; +} + +static gdouble +_nc_hicosmo_qgw_Omega_c0 (NcHICosmo *cosmo) +{ + return OMEGA_W; +} + +static gdouble +_nc_hicosmo_qgw_xb (NcHICosmo *cosmo) +{ + return X_B; +} + +/** + * nc_hicosmo_qgw_new: + * + * FIXME + * + * Returns: FIXME + */ +NcHICosmoQGW * +nc_hicosmo_qgw_new (void) +{ + NcHICosmoQGW *qgw = g_object_new (NC_TYPE_HICOSMO_QGW, NULL); + + return qgw; +} + diff --git a/numcosmo/model/nc_hicosmo_qgw.h b/numcosmo/model/nc_hicosmo_qgw.h new file mode 100644 index 000000000..eef1f4b7a --- /dev/null +++ b/numcosmo/model/nc_hicosmo_qgw.h @@ -0,0 +1,115 @@ +/*************************************************************************** + * nc_hicosmo_qgw.h + * + * Tue March 19 10:45:17 2024 + * Copyright 2024 Sandro Dias Pinto Vitenti + * > + ****************************************************************************/ +/* + * nc_hicosmo_qgw.h + * Copyright (C) 2024 Sandro Dias Pinto Vitenti + * + * numcosmo is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * numcosmo is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef _NC_HICOSMO_QGW_H_ +#define _NC_HICOSMO_QGW_H_ + +#include +#include +#include + +G_BEGIN_DECLS + +#define NC_TYPE_HICOSMO_QGW (nc_hicosmo_qgw_get_type ()) +#define NC_HICOSMO_QGW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NC_TYPE_HICOSMO_QGW, NcHICosmoQGW)) +#define NC_HICOSMO_QGW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NC_TYPE_HICOSMO_QGW, NcHICosmoQGWClass)) +#define NC_IS_HICOSMO_QGW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NC_TYPE_HICOSMO_QGW)) +#define NC_IS_HICOSMO_QGW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NC_TYPE_HICOSMO_QGW)) +#define NC_HICOSMO_QGW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NC_TYPE_HICOSMO_QGW, NcHICosmoQGWClass)) + + +typedef struct _NcHICosmoQGWClass NcHICosmoQGWClass; +typedef struct _NcHICosmoQGW NcHICosmoQGW; +typedef struct _NcHICosmoQGWPrivate NcHICosmoQGWPrivate; + +/** + * NcHICosmoQGWSParams: + * @NC_HICOSMO_QGW_H0: Hubble constant. + * @NC_HICOSMO_QGW_OMEGA_W: $w$-fluid density at $a_0$. + * @NC_HICOSMO_QGW_W: $w$-fluid equation of state. + * @NC_HICOSMO_QGW_X_B: Redshift at the bounce. + * + * Parameter of the Quantum Gravity Radiation W model. + * + */ +typedef enum /*< enum,underscore_name=NC_HICOSMO_QGW_SPARAMS >*/ +{ + NC_HICOSMO_QGW_H0 = 0, + NC_HICOSMO_QGW_OMEGA_W, + NC_HICOSMO_QGW_W, + NC_HICOSMO_QGW_X_B, + /* < private > */ + NC_HICOSMO_QGW_SPARAM_LEN, /*< skip >*/ +} NcHICosmoQGWSParams; + +/** + * NC_HICOSMO_QGW_DEFAULT_H0: (value 73.0) + * + * Default value for $H_0$. + */ +#define NC_HICOSMO_QGW_DEFAULT_H0 ncm_c_hubble_cte_planck6_base () + +/** + * NC_HICOSMO_QGW_DEFAULT_OMEGA_W: (value 1.0) + * + * Default $\Omega_{w0}$. + */ +#define NC_HICOSMO_QGW_DEFAULT_OMEGA_W (1.0) + +/** + * NC_HICOSMO_QGW_DEFAULT_W: (value 1.0e-5) + * + * Default $w$. + */ +#define NC_HICOSMO_QGW_DEFAULT_W (1.0e-5) + +/** + * NC_HICOSMO_QGW_DEFAULT_OMEGA_X_B: (value 1.0e30) + * + * Default $x_b$. + */ +#define NC_HICOSMO_QGW_DEFAULT_X_B (1.0e30) + +struct _NcHICosmoQGWClass +{ + NcHICosmoClass parent_class; + /*< private >*/ +}; + +struct _NcHICosmoQGW +{ + NcHICosmo parent_instance; + /*< private >*/ + NcHICosmoQGWPrivate *priv; +}; + +GType nc_hicosmo_qgw_get_type (void) G_GNUC_CONST; + +NcHICosmoQGW *nc_hicosmo_qgw_new (void); + +G_END_DECLS + +#endif /* _NC_HICOSMO_QGW_H_ */ + diff --git a/numcosmo/nc_de_cont.c b/numcosmo/nc_de_cont.c index 79ff5e5b0..4ad8042f8 100644 --- a/numcosmo/nc_de_cont.c +++ b/numcosmo/nc_de_cont.c @@ -30,7 +30,9 @@ * @title: NcDECont * @short_description: Dark energy contraction perturbations model * - * FIXME + * This object provides the computation of cosmological perturbations in + * a contracting universe with dark energy. It solves the equation of motion + * for the gauge invariant variable $\zeta$. * */ @@ -62,13 +64,19 @@ #endif /* NUMCOSMO_GIR_SCAN */ -struct _NcDEContPrivate +typedef struct _NcDEContPrivate { gdouble Omega_w; gdouble Omega_L; gdouble cs2; gdouble cs; gdouble w; + gdouble k; +} NcDEContPrivate; + +struct _NcDECont +{ + NcmCSQ1D parent; }; enum @@ -78,6 +86,7 @@ enum PROP_OMEGA_L, PROP_CS2, PROP_W, + PROP_K, }; G_DEFINE_TYPE_WITH_PRIVATE (NcDECont, nc_de_cont, NCM_TYPE_CSQ1D) @@ -85,7 +94,7 @@ G_DEFINE_TYPE_WITH_PRIVATE (NcDECont, nc_de_cont, NCM_TYPE_CSQ1D) static void nc_de_cont_init (NcDECont *dec) { - NcDEContPrivate * const self = dec->priv = nc_de_cont_get_instance_private (dec); + NcDEContPrivate * const self = nc_de_cont_get_instance_private (dec); self->Omega_w = 0.0; self->Omega_L = 0.0; @@ -98,7 +107,7 @@ static void _nc_de_cont_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { NcDECont *dec = NC_DE_CONT (object); - NcDEContPrivate * const self = dec->priv; + NcDEContPrivate * const self = nc_de_cont_get_instance_private (dec); g_return_if_fail (NC_IS_DE_CONT (object)); @@ -117,9 +126,12 @@ _nc_de_cont_set_property (GObject *object, guint prop_id, const GValue *value, G case PROP_W: self->w = g_value_get_double (value); break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + case PROP_K: + self->k = g_value_get_double (value); break; + default: /* LCOV_EXCL_LINE */ + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); /* LCOV_EXCL_LINE */ + break; /* LCOV_EXCL_LINE */ } } @@ -127,7 +139,7 @@ static void _nc_de_cont_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { NcDECont *dec = NC_DE_CONT (object); - NcDEContPrivate * const self = dec->priv; + NcDEContPrivate * const self = nc_de_cont_get_instance_private (dec); g_return_if_fail (NC_IS_DE_CONT (object)); @@ -145,9 +157,12 @@ _nc_de_cont_get_property (GObject *object, guint prop_id, GValue *value, GParamS case PROP_W: g_value_set_double (value, self->w); break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + case PROP_K: + g_value_set_double (value, self->k); break; + default: /* LCOV_EXCL_LINE */ + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); /* LCOV_EXCL_LINE */ + break; /* LCOV_EXCL_LINE */ } } @@ -155,7 +170,7 @@ static void _nc_de_cont_dispose (GObject *object) { /*NcDECont *dec = NC_DE_CONT (object);*/ - /*NcDEContPrivate * const self = dec->priv;*/ + /*NcDEContPrivate * const self = nc_de_cont_get_instance_private (dec);*/ /* Chain up : end */ G_OBJECT_CLASS (nc_de_cont_parent_class)->dispose (object); @@ -165,21 +180,21 @@ static void _nc_de_cont_finalize (GObject *object) { /*NcDECont *dec = NC_DE_CONT (object);*/ - /*NcDEContPrivate * const self = dec->priv;*/ + /*NcDEContPrivate * const self = nc_de_cont_get_instance_private (dec);*/ /* Chain up : end */ G_OBJECT_CLASS (nc_de_cont_parent_class)->finalize (object); } -static gdouble _nc_de_cont_eval_m (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); -static gdouble _nc_de_cont_eval_int_1_m (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); -static gdouble _nc_de_cont_eval_int_mnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); -static gdouble _nc_de_cont_eval_int_qmnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); -static gdouble _nc_de_cont_eval_int_q2mnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); -static gdouble _nc_de_cont_eval_nu (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); -static gdouble _nc_de_cont_eval_xi (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); -static gdouble _nc_de_cont_eval_F1 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); -static gdouble _nc_de_cont_eval_F2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k); +static gdouble _nc_de_cont_eval_m (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); +static gdouble _nc_de_cont_eval_int_1_m (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); +static gdouble _nc_de_cont_eval_int_mnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); +static gdouble _nc_de_cont_eval_int_qmnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); +static gdouble _nc_de_cont_eval_int_q2mnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); +static gdouble _nc_de_cont_eval_nu (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); +static gdouble _nc_de_cont_eval_xi (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); +static gdouble _nc_de_cont_eval_F1 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); +static gdouble _nc_de_cont_eval_F2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); static void nc_de_cont_class_init (NcDEContClass *klass) @@ -220,6 +235,15 @@ nc_de_cont_class_init (NcDEContClass *klass) "w", 1.0e-30, 1.0, 1.0e-2, G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB)); + + g_object_class_install_property (object_class, + PROP_K, + g_param_spec_double ("k", + NULL, + "k", + G_MINDOUBLE, G_MAXDOUBLE, 1.0, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB)); + csq1d_class->eval_m = &_nc_de_cont_eval_m; csq1d_class->eval_int_1_m = &_nc_de_cont_eval_int_1_m; csq1d_class->eval_int_mnu2 = &_nc_de_cont_eval_int_mnu2; @@ -232,10 +256,10 @@ nc_de_cont_class_init (NcDEContClass *klass) } static gdouble -_nc_de_cont_eval_m (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k) +_nc_de_cont_eval_m (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) { NcDECont *dec = NC_DE_CONT (csq1d); - NcDEContPrivate * const self = dec->priv; + NcDEContPrivate * const self = nc_de_cont_get_instance_private (dec); const gdouble t_1p3w = pow (t, 1.0 + 3.0 * self->w); const gdouble t_3p3w = t * t * t_1p3w; @@ -246,10 +270,10 @@ _nc_de_cont_eval_m (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdo } static gdouble -_nc_de_cont_eval_int_1_m (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k) +_nc_de_cont_eval_int_1_m (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) { NcDECont *dec = NC_DE_CONT (csq1d); - NcDEContPrivate * const self = dec->priv; + NcDEContPrivate * const self = nc_de_cont_get_instance_private (dec); const gdouble t_3w = pow (t, 3.0 * self->w); const gdouble t_1p3w = t * t_3w; @@ -263,11 +287,12 @@ _nc_de_cont_eval_int_1_m (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, con } static gdouble -_nc_de_cont_eval_int_mnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k) +_nc_de_cont_eval_int_mnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) { NcDECont *dec = NC_DE_CONT (csq1d); - NcDEContPrivate * const self = dec->priv; + NcDEContPrivate * const self = nc_de_cont_get_instance_private (dec); + const gdouble k = self->k; const gdouble three1pw = 3.0 * (1.0 + self->w); const gdouble t_3p3w = pow (t, three1pw); const gdouble z = -t_3p3w * self->Omega_w / self->Omega_L; @@ -287,11 +312,12 @@ _nc_de_cont_eval_int_mnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, co } static gdouble -_nc_de_cont_eval_int_qmnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k) +_nc_de_cont_eval_int_qmnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) { NcDECont *dec = NC_DE_CONT (csq1d); - NcDEContPrivate * const self = dec->priv; + NcDEContPrivate * const self = nc_de_cont_get_instance_private (dec); + const gdouble k = self->k; const gdouble three1pw = 3.0 * (1.0 + self->w); const gdouble t_3p3w = pow (t, three1pw); const gdouble z = -t_3p3w * self->Omega_w / self->Omega_L; @@ -314,11 +340,12 @@ _nc_de_cont_eval_int_qmnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, c } static gdouble -_nc_de_cont_eval_int_q2mnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k) +_nc_de_cont_eval_int_q2mnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) { NcDECont *dec = NC_DE_CONT (csq1d); - NcDEContPrivate * const self = dec->priv; + NcDEContPrivate * const self = nc_de_cont_get_instance_private (dec); + const gdouble k = self->k; const gdouble three1pw = 3.0 * (1.0 + self->w); const gdouble t_3p3w = pow (t, three1pw); const gdouble z = -t_3p3w * self->Omega_w / self->Omega_L; @@ -347,11 +374,12 @@ _nc_de_cont_eval_int_q2mnu2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, } static gdouble -_nc_de_cont_eval_nu (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k) +_nc_de_cont_eval_nu (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) { NcDECont *dec = NC_DE_CONT (csq1d); - NcDEContPrivate * const self = dec->priv; + NcDEContPrivate * const self = nc_de_cont_get_instance_private (dec); + const gdouble k = self->k; const gdouble t_1p3w = pow (t, 1.0 + 3.0 * self->w); const gdouble t_3p3w = t * t * t_1p3w; const gdouble E2 = self->Omega_w * t_3p3w + self->Omega_L; @@ -360,11 +388,12 @@ _nc_de_cont_eval_nu (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const g } static gdouble -_nc_de_cont_eval_xi (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k) +_nc_de_cont_eval_xi (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) { NcDECont *dec = NC_DE_CONT (csq1d); - NcDEContPrivate * const self = dec->priv; + NcDEContPrivate * const self = nc_de_cont_get_instance_private (dec); + const gdouble k = self->k; const gdouble t_1p3w = pow (t, 1.0 + 3.0 * self->w); const gdouble t_3p3w = t * t * t_1p3w; const gdouble E2 = self->Omega_w * t_3p3w + self->Omega_L; @@ -373,11 +402,12 @@ _nc_de_cont_eval_xi (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const g } static gdouble -_nc_de_cont_eval_F1 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k) +_nc_de_cont_eval_F1 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) { NcDECont *dec = NC_DE_CONT (csq1d); - NcDEContPrivate * const self = dec->priv; + NcDEContPrivate * const self = nc_de_cont_get_instance_private (dec); + const gdouble k = self->k; const gdouble t_1p3w = pow (t, 1.0 + 3.0 * self->w); const gdouble t_3p3w = t * t * t_1p3w; const gdouble E2 = self->Omega_w * t_3p3w + self->Omega_L; @@ -387,11 +417,12 @@ _nc_de_cont_eval_F1 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const g } static gdouble -_nc_de_cont_eval_F2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t, const gdouble k) +_nc_de_cont_eval_F2 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) { NcDECont *dec = NC_DE_CONT (csq1d); - NcDEContPrivate * const self = dec->priv; + NcDEContPrivate * const self = nc_de_cont_get_instance_private (dec); + const gdouble k = self->k; const gdouble t_1p3w = pow (t, 1.0 + 3.0 * self->w); const gdouble t_3p3w = t * t * t_1p3w; const gdouble E2 = self->Omega_w * t_3p3w + self->Omega_L; @@ -464,3 +495,35 @@ nc_de_cont_clear (NcDECont **dec) g_clear_object (dec); } +/** + * nc_de_cont_set_k: + * @dec: a #NcDECont + * @k: the value of $k$ + * + * Sets the value of $k$. + * + */ +void +nc_de_cont_set_k (NcDECont *dec, const gdouble k) +{ + NcDEContPrivate * const self = nc_de_cont_get_instance_private (dec); + + self->k = k; +} + +/** + * nc_de_cont_get_k: + * @dec: a #NcDECont + * + * Gets the value of $k$. + * + * Returns: the value of $k$. + */ +gdouble +nc_de_cont_get_k (NcDECont *dec) +{ + NcDEContPrivate * const self = nc_de_cont_get_instance_private (dec); + + return self->k; +} + diff --git a/numcosmo/nc_de_cont.h b/numcosmo/nc_de_cont.h index d718b618f..56f5d1a7a 100644 --- a/numcosmo/nc_de_cont.h +++ b/numcosmo/nc_de_cont.h @@ -1,4 +1,5 @@ /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */ + /*************************************************************************** * nc_de_cont.h * @@ -14,12 +15,12 @@ * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * numcosmo is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -34,31 +35,10 @@ G_BEGIN_DECLS -#define NC_TYPE_DE_CONT (nc_de_cont_get_type ()) -#define NC_DE_CONT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NC_TYPE_DE_CONT, NcDECont)) -#define NC_DE_CONT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NC_TYPE_DE_CONT, NcDEContClass)) -#define NC_IS_DE_CONT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NC_TYPE_DE_CONT)) -#define NC_IS_DE_CONT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NC_TYPE_DE_CONT)) -#define NC_DE_CONT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NC_TYPE_DE_CONT, NcDEContClass)) - -typedef struct _NcDEContClass NcDEContClass; -typedef struct _NcDECont NcDECont; -typedef struct _NcDEContPrivate NcDEContPrivate; +#define NC_TYPE_DE_CONT (nc_de_cont_get_type ()) -struct _NcDEContClass -{ - /*< private >*/ - NcmCSQ1DClass parent_class; -}; +G_DECLARE_FINAL_TYPE (NcDECont, nc_de_cont, NC, DE_CONT, NcmCSQ1D) -struct _NcDECont -{ - /*< private >*/ - NcmCSQ1D parent_instance; - NcDEContPrivate *priv; -}; - -GType nc_de_cont_get_type (void) G_GNUC_CONST; NcDECont *nc_de_cont_new (const gdouble Omegaw, const gdouble OmegaL, const gdouble cs2, const gdouble w); NcDECont *nc_de_cont_ref (NcDECont *dec); @@ -66,6 +46,10 @@ NcDECont *nc_de_cont_ref (NcDECont *dec); void nc_de_cont_free (NcDECont *dec); void nc_de_cont_clear (NcDECont **dec); +void nc_de_cont_set_k (NcDECont *dec, const gdouble k); +gdouble nc_de_cont_get_k (NcDECont *dec); + G_END_DECLS #endif /* _NC_DE_CONT_H_ */ + diff --git a/numcosmo/nc_powspec_ml.h b/numcosmo/nc_powspec_ml.h index a49228575..c136fa998 100644 --- a/numcosmo/nc_powspec_ml.h +++ b/numcosmo/nc_powspec_ml.h @@ -33,30 +33,19 @@ G_BEGIN_DECLS -#define NC_TYPE_POWSPEC_ML (nc_powspec_ml_get_type ()) -#define NC_POWSPEC_ML(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NC_TYPE_POWSPEC_ML, NcPowspecML)) -#define NC_POWSPEC_ML_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NC_TYPE_POWSPEC_ML, NcPowspecMLClass)) -#define NC_IS_POWSPEC_ML(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NC_TYPE_POWSPEC_ML)) -#define NC_IS_POWSPEC_ML_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NC_TYPE_POWSPEC_ML)) -#define NC_POWSPEC_ML_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NC_TYPE_POWSPEC_ML, NcPowspecMLClass)) +#define NC_TYPE_POWSPEC_ML (nc_powspec_ml_get_type ()) -typedef struct _NcPowspecMLClass NcPowspecMLClass; -typedef struct _NcPowspecML NcPowspecML; +G_DECLARE_DERIVABLE_TYPE (NcPowspecML, nc_powspec_ml, NC, POWSPEC_ML, NcmPowspec) struct _NcPowspecMLClass { /*< private > */ NcmPowspecClass parent_class; -}; -struct _NcPowspecML -{ - /*< private > */ - NcmPowspec parent_instance; + /* Padding to allow 18 virtual functions without breaking ABI. */ + gpointer padding[18]; }; -GType nc_powspec_ml_get_type (void) G_GNUC_CONST; - NcPowspecML *nc_powspec_ml_ref (NcPowspecML *ps_ml); void nc_powspec_ml_free (NcPowspecML *ps_ml); diff --git a/numcosmo/nc_powspec_ml_fix_spline.c b/numcosmo/nc_powspec_ml_fix_spline.c deleted file mode 100644 index 9ba5795fb..000000000 --- a/numcosmo/nc_powspec_ml_fix_spline.c +++ /dev/null @@ -1,259 +0,0 @@ -/*************************************************************************** - * nc_powspec_ml_fix_spline.c - * - * Sun Jun 18 10:26:38 2017 - * Copyright 2017 Mariana Penna Lima - * - ****************************************************************************/ -/* - * nc_powspec_ml_fix_spline.c - * Copyright (C) 2017 Mariana Penna Lima - * - * numcosmo is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * numcosmo is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -/** - * SECTION:nc_powspec_ml_fix_spline - * @title: NcPowspecMLFixSpline - * @short_description: Class for linear matter power spectrum from a fixed spline. - * @stability: Stable - * @include: numcosmo/nc_powspec_ml_fix_spline.h - * - * Provides a linear matter power spectrum as a function of mode $k$ at a redshift $z_0$ computing - * a spline, whose knots and the respective $P(k, z = z_0)$ values are provided in a file. - * - * - * - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif /* HAVE_CONFIG_H */ -#include "build_cfg.h" - -#include "nc_powspec_ml_fix_spline.h" -#include "nc_hiprim.h" - -enum -{ - PROP_0, - PROP_FILENAME, - PROP_SIZE -}; - -G_DEFINE_TYPE (NcPowspecMLFixSpline, nc_powspec_ml_fix_spline, NC_TYPE_POWSPEC_ML) - -static void -nc_powspec_ml_fix_spline_init (NcPowspecMLFixSpline *ps_fs) -{ - ps_fs->ser = ncm_serialize_new (0); - ps_fs->Pk = NULL; - ps_fs->gf = nc_growth_func_new (); - ps_fs->filename = NULL; -} - -static void -_nc_powspec_ml_fix_spline_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) -{ - NcPowspecMLFixSpline *ps_fs = NC_POWSPEC_ML_FIX_SPLINE (object); - - g_return_if_fail (NC_IS_POWSPEC_ML_FIX_SPLINE (object)); - - switch (prop_id) - { - case PROP_FILENAME: - nc_powspec_ml_fix_spline_set_file (ps_fs, g_value_get_string (value)); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -_nc_powspec_ml_fix_spline_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) -{ - NcPowspecMLFixSpline *ps_fs = NC_POWSPEC_ML_FIX_SPLINE (object); - - g_return_if_fail (NC_IS_POWSPEC_ML_FIX_SPLINE (object)); - - switch (prop_id) - { - case PROP_FILENAME: - g_value_set_string (value, ps_fs->filename); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static void -_nc_powspec_ml_fix_spline_constructed (GObject *object) -{ - /* Chain up : start */ - G_OBJECT_CLASS (nc_powspec_ml_fix_spline_parent_class)->constructed (object); -} - -static void -_nc_powspec_ml_fix_spline_dispose (GObject *object) -{ - NcPowspecMLFixSpline *ps_fs = NC_POWSPEC_ML_FIX_SPLINE (object); - - g_clear_pointer (&ps_fs->filename, g_free); - ncm_spline_clear (&ps_fs->Pk); - ncm_serialize_clear (&ps_fs->ser); - nc_growth_func_clear (&ps_fs->gf); - - /* Chain up : end */ - G_OBJECT_CLASS (nc_powspec_ml_fix_spline_parent_class)->dispose (object); -} - -static void -_nc_powspec_ml_fix_spline_finalize (GObject *object) -{ - /* Chain up : end */ - G_OBJECT_CLASS (nc_powspec_ml_fix_spline_parent_class)->finalize (object); -} - -static void _nc_powspec_ml_fix_spline_prepare (NcmPowspec *powspec, NcmModel *model); -static gdouble _nc_powspec_ml_fix_spline_eval (NcmPowspec *powspec, NcmModel *model, const gdouble z, const gdouble k); -static void _nc_powspec_ml_fix_spline_eval_vec (NcmPowspec *powspec, NcmModel *model, const gdouble z, NcmVector *k, NcmVector *Pk); -static void _nc_powspec_ml_fix_spline_get_nknots (NcmPowspec *powspec, guint *Nz, guint *Nk); - -static void -nc_powspec_ml_fix_spline_class_init (NcPowspecMLFixSplineClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - NcmPowspecClass *powspec_class = NCM_POWSPEC_CLASS (klass); - - object_class->set_property = &_nc_powspec_ml_fix_spline_set_property; - object_class->get_property = &_nc_powspec_ml_fix_spline_get_property; - - object_class->constructed = &_nc_powspec_ml_fix_spline_constructed; - - object_class->dispose = &_nc_powspec_ml_fix_spline_dispose; - object_class->finalize = &_nc_powspec_ml_fix_spline_finalize; - - /** - * NcPowspecMLFixSpline:filename: - * - * The file name containing $P(k, z=z_0)$ in a serialized #NcmSpline format. - * - */ - g_object_class_install_property (object_class, - PROP_FILENAME, - g_param_spec_string ("filename", - NULL, - "Filename", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB)); - - - powspec_class->prepare = &_nc_powspec_ml_fix_spline_prepare; - powspec_class->eval = &_nc_powspec_ml_fix_spline_eval; - powspec_class->eval_vec = &_nc_powspec_ml_fix_spline_eval_vec; - powspec_class->get_nknots = &_nc_powspec_ml_fix_spline_get_nknots; -} - -static void -_nc_powspec_ml_fix_spline_prepare (NcmPowspec *powspec, NcmModel *model) -{ - NcHICosmo *cosmo = NC_HICOSMO (model); - NcPowspecMLFixSpline *ps_fs = NC_POWSPEC_ML_FIX_SPLINE (powspec); - - g_assert (NC_IS_HICOSMO (cosmo)); - g_assert (ncm_model_peek_submodel_by_mid (model, nc_hiprim_id ()) != NULL); - - nc_growth_func_prepare_if_needed (ps_fs->gf, cosmo); - ncm_spline_prepare (ps_fs->Pk); -} - -static gdouble -_nc_powspec_ml_fix_spline_eval (NcmPowspec *powspec, NcmModel *model, const gdouble z, const gdouble k) -{ - NcHICosmo *cosmo = NC_HICOSMO (model); - NcPowspecMLFixSpline *ps_fs = NC_POWSPEC_ML_FIX_SPLINE (powspec); - const gdouble growth = nc_growth_func_eval (ps_fs->gf, cosmo, z); - const gdouble gf2 = gsl_pow_2 (growth); - - return ncm_spline_eval (ps_fs->Pk, k) * gf2; -} - -static void -_nc_powspec_ml_fix_spline_eval_vec (NcmPowspec *powspec, NcmModel *model, const gdouble z, NcmVector *k, NcmVector *Pk) -{ - const guint len = ncm_vector_len (k); - guint i; - - for (i = 0; i < len; i++) - { - const gdouble ki = ncm_vector_get (k, i); - const gdouble Pk_z = _nc_powspec_ml_fix_spline_eval (powspec, model, z, ki); - - ncm_vector_set (Pk, i, Pk_z); - } -} - -static void -_nc_powspec_ml_fix_spline_get_nknots (NcmPowspec *powspec, guint *Nz, guint *Nk) -{ - Nz[0] = 20; - Nk[0] = 1000; -} - -/** - * nc_powspec_ml_fix_spline_new: - * @filename: a file containing a serialized #NcmSpline - * - * Creates a new #NcPowspecMLFixSpline from a spline of the power spectrum, - * $P(k, z=z_0)$ at a given redshift $z_0$, which is present in the serialized object @filename. - * - * Returns: (transfer full): the newly created #NcPowspecMLFixSpline. - */ -NcPowspecMLFixSpline * -nc_powspec_ml_fix_spline_new (const gchar *filename) -{ - NcPowspecMLFixSpline *ps_fs = g_object_new (NC_TYPE_POWSPEC_ML_FIX_SPLINE, - "filename", filename, - NULL); - - return ps_fs; -} - -/** - * nc_powspec_ml_fix_spline_set_file: - * @ps_fs: a #NcPowspecMLFixSpline - * @filename: a file containing a serialized #NcmSpline - * - * Attributes a spline of the power spectrum at a redshift $z_0$, P(k, z_0), from @filename. - * - */ -void -nc_powspec_ml_fix_spline_set_file (NcPowspecMLFixSpline *ps_fs, const gchar *filename) -{ - g_assert (filename != NULL); - { - GObject *obj = ncm_serialize_from_file (ps_fs->ser, filename); - - g_assert (NCM_IS_SPLINE (obj)); - - g_clear_pointer (&ps_fs->filename, g_free); - ncm_spline_clear (&ps_fs->Pk); - - ps_fs->filename = g_strdup (filename); - ps_fs->Pk = NCM_SPLINE (obj); - } -} - diff --git a/numcosmo/nc_powspec_ml_fix_spline.h b/numcosmo/nc_powspec_ml_fix_spline.h deleted file mode 100644 index 0a6609e0f..000000000 --- a/numcosmo/nc_powspec_ml_fix_spline.h +++ /dev/null @@ -1,73 +0,0 @@ -/*************************************************************************** - * nc_powspec_ml_fix_spline.h - * - * Sun Jun 18 10:26:38 2017 - * Copyright 2017 Mariana Penna Lima - * - ****************************************************************************/ -/* - * nc_powspec_ml_fix_spline.h - * Copyright (C) 2017 Mariana Penna Lima - * - * numcosmo is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * numcosmo is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -#ifndef _NC_POWSPEC_ML_FIX_SPLINE_H_ -#define _NC_POWSPEC_ML_FIX_SPLINE_H_ - -#include -#include -#include -#include -#include -#include - -G_BEGIN_DECLS - -#define NC_TYPE_POWSPEC_ML_FIX_SPLINE (nc_powspec_ml_fix_spline_get_type ()) -#define NC_POWSPEC_ML_FIX_SPLINE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NC_TYPE_POWSPEC_ML_FIX_SPLINE, NcPowspecMLFixSpline)) -#define NC_POWSPEC_ML_FIX_SPLINE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NC_TYPE_POWSPEC_ML_FIX_SPLINE, NcPowspecMLFixSplineClass)) -#define NC_IS_POWSPEC_ML_FIX_SPLINE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NC_TYPE_POWSPEC_ML_FIX_SPLINE)) -#define NC_IS_POWSPEC_ML_FIX_SPLINE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NC_TYPE_POWSPEC_ML_FIX_SPLINE)) -#define NC_POWSPEC_ML_FIX_SPLINE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NC_TYPE_POWSPEC_ML_FIX_SPLINE, NcPowspecMLFixSplineClass)) - -typedef struct _NcPowspecMLFixSplineClass NcPowspecMLFixSplineClass; -typedef struct _NcPowspecMLFixSpline NcPowspecMLFixSpline; - -struct _NcPowspecMLFixSplineClass -{ - /*< private > */ - NcPowspecMLClass parent_class; -}; - -struct _NcPowspecMLFixSpline -{ - /*< private > */ - NcPowspecML parent_instance; - NcmSerialize *ser; - NcmSpline *Pk; - NcGrowthFunc *gf; - gchar *filename; -}; - -GType nc_powspec_ml_fix_spline_get_type (void) G_GNUC_CONST; - -NcPowspecMLFixSpline *nc_powspec_ml_fix_spline_new (const gchar *filename); - -void nc_powspec_ml_fix_spline_set_file (NcPowspecMLFixSpline *ps_fs, const gchar *filename); - -G_END_DECLS - -#endif /* _NC_POWSPEC_ML_FIX_SPLINE_H_ */ - diff --git a/numcosmo/nc_powspec_ml_spline.c b/numcosmo/nc_powspec_ml_spline.c new file mode 100644 index 000000000..cdc58fb28 --- /dev/null +++ b/numcosmo/nc_powspec_ml_spline.c @@ -0,0 +1,274 @@ +/*************************************************************************** + * nc_powspec_ml_spline.c + * + * Sun Jun 18 10:26:38 2017 + * Copyright 2017 Mariana Penna Lima + * + ****************************************************************************/ +/* + * nc_powspec_ml_spline.c + * Copyright (C) 2017 Mariana Penna Lima + * + * numcosmo is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * numcosmo is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +/** + * SECTION:nc_powspec_ml_spline + * @title: NcPowspecMLSpline + * @short_description: Class for linear matter power spectrum from a 1d-spline. + * @stability: Stable + * @include: numcosmo/nc_powspec_ml_spline.h + * + * Provides a linear matter power spectrum as a function of mode $k$ at a redshift + * $z_0$ computing a spline, whose knots and the respective $P(k, z = z_0)$ values are + * provided in a file. The time evolution of the power spectrum is computed using the + * growth function. + * + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif /* HAVE_CONFIG_H */ +#include "build_cfg.h" + +#include "nc_powspec_ml_spline.h" +#include "nc_hiprim.h" + +struct _NcPowspecMLSpline +{ + /*< private > */ + NcPowspecML parent_instance; + NcmSerialize *ser; + NcmSpline *Pk; + NcGrowthFunc *gf; +}; + +enum +{ + PROP_0, + PROP_SPLINE, + PROP_SIZE +}; + +G_DEFINE_TYPE (NcPowspecMLSpline, nc_powspec_ml_spline, NC_TYPE_POWSPEC_ML) + +static void +nc_powspec_ml_spline_init (NcPowspecMLSpline *ps_fs) +{ + ps_fs->ser = ncm_serialize_new (0); + ps_fs->Pk = NULL; + ps_fs->gf = nc_growth_func_new (); +} + +static void +_nc_powspec_ml_spline_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +{ + NcPowspecMLSpline *ps_fs = NC_POWSPEC_ML_SPLINE (object); + + g_return_if_fail (NC_IS_POWSPEC_ML_SPLINE (object)); + + switch (prop_id) + { + case PROP_SPLINE: + nc_powspec_ml_spline_set_spline (ps_fs, g_value_get_object (value)); + break; + default: /* LCOV_EXCL_LINE */ + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); /* LCOV_EXCL_LINE */ + break; /* LCOV_EXCL_LINE */ + } +} + +static void +_nc_powspec_ml_spline_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +{ + NcPowspecMLSpline *ps_fs = NC_POWSPEC_ML_SPLINE (object); + + g_return_if_fail (NC_IS_POWSPEC_ML_SPLINE (object)); + + switch (prop_id) + { + case PROP_SPLINE: + g_value_set_object (value, nc_powspec_ml_spline_peek_spline (ps_fs)); + break; + default: /* LCOV_EXCL_LINE */ + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); /* LCOV_EXCL_LINE */ + break; /* LCOV_EXCL_LINE */ + } +} + +static void +_nc_powspec_ml_spline_constructed (GObject *object) +{ + /* Chain up : start */ + G_OBJECT_CLASS (nc_powspec_ml_spline_parent_class)->constructed (object); +} + +static void +_nc_powspec_ml_spline_dispose (GObject *object) +{ + NcPowspecMLSpline *ps_fs = NC_POWSPEC_ML_SPLINE (object); + + ncm_spline_clear (&ps_fs->Pk); + ncm_serialize_clear (&ps_fs->ser); + nc_growth_func_clear (&ps_fs->gf); + + /* Chain up : end */ + G_OBJECT_CLASS (nc_powspec_ml_spline_parent_class)->dispose (object); +} + +static void +_nc_powspec_ml_spline_finalize (GObject *object) +{ + /* Chain up : end */ + G_OBJECT_CLASS (nc_powspec_ml_spline_parent_class)->finalize (object); +} + +static void _nc_powspec_ml_spline_prepare (NcmPowspec *powspec, NcmModel *model); +static gdouble _nc_powspec_ml_spline_eval (NcmPowspec *powspec, NcmModel *model, const gdouble z, const gdouble k); +static void _nc_powspec_ml_spline_eval_vec (NcmPowspec *powspec, NcmModel *model, const gdouble z, NcmVector *k, NcmVector *Pk); +static void _nc_powspec_ml_spline_get_nknots (NcmPowspec *powspec, guint *Nz, guint *Nk); + +static void +nc_powspec_ml_spline_class_init (NcPowspecMLSplineClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + NcmPowspecClass *powspec_class = NCM_POWSPEC_CLASS (klass); + + object_class->set_property = &_nc_powspec_ml_spline_set_property; + object_class->get_property = &_nc_powspec_ml_spline_get_property; + + object_class->constructed = &_nc_powspec_ml_spline_constructed; + + object_class->dispose = &_nc_powspec_ml_spline_dispose; + object_class->finalize = &_nc_powspec_ml_spline_finalize; + + /** + * NcPowspecMLSpline:filename: + * + * The file name containing $P(k, z=z_0)$ in a serialized #NcmSpline format. + * + */ + g_object_class_install_property (object_class, + PROP_SPLINE, + g_param_spec_object ("spline", + NULL, + "Spline representing Pk at z=0", + NCM_TYPE_SPLINE, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB)); + + + powspec_class->prepare = &_nc_powspec_ml_spline_prepare; + powspec_class->eval = &_nc_powspec_ml_spline_eval; + powspec_class->eval_vec = &_nc_powspec_ml_spline_eval_vec; + powspec_class->get_nknots = &_nc_powspec_ml_spline_get_nknots; +} + +static void +_nc_powspec_ml_spline_prepare (NcmPowspec *powspec, NcmModel *model) +{ + NcHICosmo *cosmo = NC_HICOSMO (model); + NcPowspecMLSpline *ps_fs = NC_POWSPEC_ML_SPLINE (powspec); + + g_assert (NC_IS_HICOSMO (cosmo)); + g_assert (ncm_model_peek_submodel_by_mid (model, nc_hiprim_id ()) != NULL); + + nc_growth_func_prepare_if_needed (ps_fs->gf, cosmo); + ncm_spline_prepare (ps_fs->Pk); +} + +static gdouble +_nc_powspec_ml_spline_eval (NcmPowspec *powspec, NcmModel *model, const gdouble z, const gdouble k) +{ + NcHICosmo *cosmo = NC_HICOSMO (model); + NcPowspecMLSpline *ps_fs = NC_POWSPEC_ML_SPLINE (powspec); + const gdouble growth = nc_growth_func_eval (ps_fs->gf, cosmo, z); + const gdouble gf2 = gsl_pow_2 (growth); + + return ncm_spline_eval (ps_fs->Pk, k) * gf2; +} + +static void +_nc_powspec_ml_spline_eval_vec (NcmPowspec *powspec, NcmModel *model, const gdouble z, NcmVector *k, NcmVector *Pk) +{ + const guint len = ncm_vector_len (k); + guint i; + + for (i = 0; i < len; i++) + { + const gdouble ki = ncm_vector_get (k, i); + const gdouble Pk_z = _nc_powspec_ml_spline_eval (powspec, model, z, ki); + + ncm_vector_set (Pk, i, Pk_z); + } +} + +static void +_nc_powspec_ml_spline_get_nknots (NcmPowspec *powspec, guint *Nz, guint *Nk) +{ + NcPowspecMLSpline *ps_fs = NC_POWSPEC_ML_SPLINE (powspec); + NcmPowspec *powspec_base = NCM_POWSPEC (ps_fs); + const gdouble zi = ncm_powspec_get_zi (powspec_base); + const gdouble zf = ncm_powspec_get_zf (powspec_base); + + Nz[0] = GSL_MAX ((zf - zi) * 50, 10); + Nk[0] = ncm_spline_get_len (ps_fs->Pk); +} + +/** + * nc_powspec_ml_spline_new: + * @Pk: a #NcmSpline + * + * Creates a new #NcPowspecMLSpline from a spline @Pk of the power spectrum, $P(k, + * z=z_0)$ at a given redshift $z_0$. + * + * Returns: (transfer full): the newly created #NcPowspecMLSpline. + */ +NcPowspecMLSpline * +nc_powspec_ml_spline_new (NcmSpline *Pk) +{ + NcPowspecMLSpline *ps_fs = g_object_new (NC_TYPE_POWSPEC_ML_SPLINE, + "spline", Pk, + NULL); + + return ps_fs; +} + +/** + * nc_powspec_ml_spline_set_spline: + * @ps_fs: a #NcPowspecMLSpline + * @Pk: a #NcmSpline + * + * Attributes a spline of the power spectrum at a redshift $z_0$, P(k, z_0), from @Pk. + * + */ +void +nc_powspec_ml_spline_set_spline (NcPowspecMLSpline *ps_fs, NcmSpline *Pk) +{ + ncm_spline_clear (&ps_fs->Pk); + ps_fs->Pk = ncm_spline_ref (Pk); +} + +/** + * nc_powspec_ml_spline_peek_spline: + * @ps_fs: a #NcPowspecMLSpline + * + * Returns: (transfer none): the spline of the power spectrum at a redshift $z_0$, P(k, + * z_0). + */ +NcmSpline * +nc_powspec_ml_spline_peek_spline (NcPowspecMLSpline *ps_fs) +{ + return ps_fs->Pk; +} + diff --git a/numcosmo/nc_powspec_ml_spline.h b/numcosmo/nc_powspec_ml_spline.h new file mode 100644 index 000000000..6dc006fa6 --- /dev/null +++ b/numcosmo/nc_powspec_ml_spline.h @@ -0,0 +1,50 @@ +/*************************************************************************** + * nc_powspec_ml_spline.h + * + * Sun Jun 18 10:26:38 2017 + * Copyright 2017 Mariana Penna Lima + * + ****************************************************************************/ +/* + * nc_powspec_ml_spline.h + * Copyright (C) 2017 Mariana Penna Lima + * + * numcosmo is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * numcosmo is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef _NC_POWSPEC_ML_SPLINE_H_ +#define _NC_POWSPEC_ML_SPLINE_H_ + +#include +#include +#include +#include +#include +#include + +G_BEGIN_DECLS + +#define NC_TYPE_POWSPEC_ML_SPLINE (nc_powspec_ml_spline_get_type ()) + +G_DECLARE_FINAL_TYPE (NcPowspecMLSpline, nc_powspec_ml_spline, NC, POWSPEC_ML_SPLINE, NcPowspecML) + +NcPowspecMLSpline *nc_powspec_ml_spline_new (NcmSpline * Pk); + +void nc_powspec_ml_spline_set_spline (NcPowspecMLSpline *ps_fs, NcmSpline *Pk); +NcmSpline *nc_powspec_ml_spline_peek_spline (NcPowspecMLSpline *ps_fs); + +G_END_DECLS + +#endif /* _NC_POWSPEC_ML_SPLINE_H_ */ + diff --git a/numcosmo/numcosmo-math.h b/numcosmo/numcosmo-math.h index c0f9dffac..dd614ce1e 100644 --- a/numcosmo/numcosmo-math.h +++ b/numcosmo/numcosmo-math.h @@ -76,10 +76,11 @@ #include #include #include -#include +#include #include #include -#include +#include +#include #include #include #include diff --git a/numcosmo/numcosmo.h b/numcosmo/numcosmo.h index 654831768..1a39edac4 100644 --- a/numcosmo/numcosmo.h +++ b/numcosmo/numcosmo.h @@ -37,7 +37,7 @@ #include #include #include -#include +#include #include #include #include @@ -57,23 +57,25 @@ #include /* Perturbations */ -#include -#include -#include -#include #include -#include -#include -#include -#include +#include #include +#include +#include +#include +#include +#include #include -#include #include -#include -#include +#include +#include +#include +#include +#include +#include /* Model implementations */ +#include #include #include #include @@ -89,6 +91,7 @@ #include #include #include +#include #include #include #include @@ -197,3 +200,4 @@ #include #endif /* _NUMCOSMO_H */ + diff --git a/numcosmo/perturbations/nc_hipert_adiab.c b/numcosmo/perturbations/nc_hipert_adiab.c index 027bdca61..bc810a000 100644 --- a/numcosmo/perturbations/nc_hipert_adiab.c +++ b/numcosmo/perturbations/nc_hipert_adiab.c @@ -31,8 +31,11 @@ * This object provides the computation of the adiabatic mode for the cosmological * perturbations. It solves the equation of motion for the gauge invariant variable * (see [Vitenti (2013)][XVitenti2013] for notation and details) - * $$\zeta \equiv \Psi - \frac{2\bar{K}}{\kappa(\bar{\rho} + \bar{p})} + H\mathcal{V}.$$ - * Its conjugated momentum is give by + * $$ + * \zeta \equiv \Psi - \frac{2\bar{K}}{\kappa(\bar{\rho} + \bar{p})} + H\mathcal{V}. + * $$ + * Its conjugated + * momentum is give by * \begin{split} * P_\zeta &= \frac{2\bar{D}^2_\bar{K}\Psi}{x^3H}, * \end{split} @@ -40,17 +43,22 @@ * The equations of motion in their first order form are * \begin{align} * \zeta^\prime &= \frac{P_\zeta}{m_\zeta}, \\\\ - * P_\zeta^\prime &= -m_\zeta\mu_\zeta^2\zeta. - * \end{align} - * The mass $m_\zeta$ and the frequency $\mu_\zeta$ are defined by + * P_\zeta^\prime &= -m_\zeta\mu_\zeta^2\zeta. \end{align} The mass $m_\zeta$ and the + * frequency $\mu_\zeta$ are defined by * \begin{align} - * m_\zeta &= \frac{3\Delta_\bar{K}(\bar{\rho} + \bar{p})}{\rho_\text{crit0} N x^3 c_s^2 E^2}, \\\\ + * m_\zeta &= \frac{3\Delta_\bar{K}(\bar{\rho} + \bar{p})}{\rho_\text{crit0} N x^3 + * c_s^2 E^2}, + * \\\\ * \mu_\zeta^2 &= x^2N^2c_s^2k^2, * \end{align} * where $\bar{\rho} + \bar{p}$ is the background total energy density plus pressure, - * $E^2 = H^2/H_0^2$ is the dimensionless Hubble function squared (nc_hicosmo_E2()), $c_s^2$ the speed of sound, - * $N$ is the lapse function that in this case (using $\alpha$ as time variable) is $N \equiv \vert{}E\vert^{-1}$, $\rho_\text{crit0}$ - * is the critical density today defined by $\rho_\text{crit0} \equiv 3H_0^2/\kappa$ and $$\Delta_\bar{K} \equiv \frac{k^2}{k^2 + \Omega_{k0}}.$$ + * $E^2 = H^2/H_0^2$ is the dimensionless Hubble function squared (nc_hicosmo_E2()), + * $c_s^2$ the speed of sound, $N$ is the lapse function that in this case (using + * $\alpha$ as time variable) is $N \equiv \vert{}E\vert^{-1}$, $\rho_\text{crit0}$ is + * the critical density today defined by $\rho_\text{crit0} \equiv 3H_0^2/\kappa$ and + * $$ + * \Delta_\bar{K} \equiv \frac{k^2}{k^2 + \Omega_{k0}}. + * $$ * */ @@ -59,8 +67,11 @@ #endif /* HAVE_CONFIG_H */ #include "build_cfg.h" -#include "math/ncm_spline_cubic_notaknot.h" #include "perturbations/nc_hipert_adiab.h" +#include "math/ncm_spline_cubic_notaknot.h" +#include "math/ncm_spline2d_bicubic.h" +#include "math/ncm_ode_spline.h" +#include "math/ncm_model_ctrl.h" #ifndef NUMCOSMO_GIR_SCAN #include @@ -68,36 +79,41 @@ #include #endif /* NUMCOSMO_GIR_SCAN */ -G_DEFINE_INTERFACE (NcHIPertIAdiab, nc_hipert_iadiab, G_TYPE_OBJECT) +struct _NcHIPertAdiab +{ + NcmCSQ1D parent_instance; + gdouble k; + NcmSpline2d *powspec_alpha; + NcmSpline2d *powspec_gamma; + NcmOdeSpline *ctime_forward; + NcmOdeSpline *ctime_backward; + NcmModelCtrl *model_ctrl; +}; -static guint _nc_hipert_iadiab_nsing (NcHIPertIAdiab *iad, const gdouble k) { return 0; } -static void _nc_hipert_iadiab_get_sing_info (NcHIPertIAdiab *iad, const gdouble k, const guint sing, gdouble *ts, gdouble *dts_i, gdouble *dts_f, NcmHOAASingType *st) { g_error ("_nc_hipert_iadiab_get_sing_info: no singularity implemented."); return; } -static gdouble _nc_hipert_iadiab_eval_sing_mnu (NcHIPertIAdiab *iad, const gdouble tau_m_taus, const gdouble k, const guint sing) { g_error ("_nc_hipert_iadiab_eval_sing_mnu: no singularity implemented."); return 0.0; } -static gdouble _nc_hipert_iadiab_eval_sing_dlnmnu (NcHIPertIAdiab *iad, const gdouble tau_m_taus, const gdouble k, const guint sing) { g_error ("_nc_hipert_iadiab_eval_sing_dlnmnu: no singularity implemented."); return 0.0; } -static void _nc_hipert_iadiab_eval_sing_system (NcHIPertIAdiab *iad, const gdouble tau_m_taus, const gdouble k, const guint sing, gdouble *nu, gdouble *dlnmnu) { g_error ("_nc_hipert_iadiab_eval_sing_system: no singularity implemented."); } -static gdouble _nc_hipert_iadiab_eval_powspec_factor (NcHIPertIAdiab *iad); +G_DEFINE_INTERFACE (NcHIPertIAdiab, nc_hipert_iadiab, G_TYPE_OBJECT) +G_DEFINE_TYPE (NcHIPertAdiab, nc_hipert_adiab, NCM_TYPE_CSQ1D) static void nc_hipert_iadiab_default_init (NcHIPertIAdiabInterface *iface) { - iface->eval_mnu = NULL; - iface->eval_nu = NULL; - iface->eval_dlnmnu = NULL; - iface->eval_system = NULL; - - iface->nsing = &_nc_hipert_iadiab_nsing; - iface->get_sing_info = &_nc_hipert_iadiab_get_sing_info; - iface->eval_sing_mnu = &_nc_hipert_iadiab_eval_sing_mnu; - iface->eval_sing_dlnmnu = &_nc_hipert_iadiab_eval_sing_dlnmnu; - iface->eval_sing_system = &_nc_hipert_iadiab_eval_sing_system; - - iface->eval_powspec_factor = &_nc_hipert_iadiab_eval_powspec_factor; + iface->eval_xi = NULL; + iface->eval_F1 = NULL; + iface->eval_nu = NULL; + iface->eval_m = NULL; + iface->eval_unit = NULL; + iface->eval_x = NULL; + iface->eval_p2Psi = NULL; + iface->eval_p2drho = NULL; + iface->eval_lapse = NULL; + iface->eval_tau_hubble = NULL; + iface->eval_tau_jeans = NULL; + iface->eval_hubble = NULL; } -G_DEFINE_TYPE (NcHIPertAdiab, nc_hipert_adiab, NCM_TYPE_HOAA) - -enum { +enum +{ PROP_0, + PROP_K, PROP_SIZE, }; @@ -107,43 +123,72 @@ typedef struct _NcHIPertAdiabArg NcHIPertAdiab *pa; } NcHIPertAdiabArg; +static gdouble _nc_hipert_adiab_cosmic_time_integ_forward (const gdouble t, gdouble tau, void *params); +static gdouble _nc_hipert_adiab_cosmic_time_integ_backward (const gdouble t, gdouble tau, void *params); + static void nc_hipert_adiab_init (NcHIPertAdiab *pa) { + NcmSpline *s1 = ncm_spline_cubic_notaknot_new (); + NcmSpline *s2 = ncm_spline_cubic_notaknot_new (); + + pa->k = 0.0; + pa->powspec_alpha = NULL; + pa->powspec_gamma = NULL; + pa->ctime_forward = ncm_ode_spline_new_full (s1, _nc_hipert_adiab_cosmic_time_integ_forward, 0.0, 0.0, 500.0); + pa->ctime_backward = ncm_ode_spline_new_full (s2, _nc_hipert_adiab_cosmic_time_integ_backward, 0.0, 0.0, 500.0); + pa->model_ctrl = ncm_model_ctrl_new (NULL); + + ncm_ode_spline_auto_abstol (pa->ctime_forward, TRUE); + ncm_ode_spline_auto_abstol (pa->ctime_backward, TRUE); + + ncm_spline_free (s1); + ncm_spline_free (s2); } static void _nc_hipert_adiab_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - /* NcHIPertAdiab *pa = NC_HIPERT_ADIAB (object); */ + NcHIPertAdiab *pa = NC_HIPERT_ADIAB (object); + g_return_if_fail (NC_IS_HIPERT_ADIAB (object)); switch (prop_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + case PROP_K: + nc_hipert_adiab_set_k (pa, g_value_get_double (value)); break; + default: /* LCOV_EXCL_LINE */ + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); /* LCOV_EXCL_LINE */ + break; /* LCOV_EXCL_LINE */ } } static void _nc_hipert_adiab_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - /* NcHIPertAdiab *pa = NC_HIPERT_ADIAB (object); */ + NcHIPertAdiab *pa = NC_HIPERT_ADIAB (object); + g_return_if_fail (NC_IS_HIPERT_ADIAB (object)); switch (prop_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + case PROP_K: + g_value_set_double (value, nc_hipert_adiab_get_k (pa)); break; + default: /* LCOV_EXCL_LINE */ + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); /* LCOV_EXCL_LINE */ + break; /* LCOV_EXCL_LINE */ } } static void _nc_hipert_adiab_dispose (GObject *object) { - /*NcHIPertAdiab *pa = NC_HIPERT_ADIAB (object);*/ + NcHIPertAdiab *pa = NC_HIPERT_ADIAB (object); + + ncm_spline2d_clear (&pa->powspec_alpha); + ncm_spline2d_clear (&pa->powspec_gamma); /* Chain up : end */ G_OBJECT_CLASS (nc_hipert_adiab_parent_class)->dispose (object); @@ -152,208 +197,270 @@ _nc_hipert_adiab_dispose (GObject *object) static void _nc_hipert_adiab_finalize (GObject *object) { - /* Chain up : end */ G_OBJECT_CLASS (nc_hipert_adiab_parent_class)->finalize (object); } -static gdouble _nc_hipert_adiab_eval_mnu (NcmHOAA *hoaa, NcmModel *model, const gdouble t, const gdouble k); -static gdouble _nc_hipert_adiab_eval_nu (NcmHOAA *hoaa, NcmModel *model, const gdouble t, const gdouble k); -static gdouble _nc_hipert_adiab_eval_dlnmnu (NcmHOAA *hoaa, NcmModel *model, const gdouble t, const gdouble k); -static void _nc_hipert_adiab_eval_system (NcmHOAA *hoaa, NcmModel *model, const gdouble t, const gdouble k, gdouble *nu, gdouble *dlnmnu, gdouble *Vnu); - -static guint _nc_hipert_adiab_nsing (NcmHOAA *hoaa, NcmModel *model, const gdouble k); -static void _nc_hipert_adiab_get_sing_info (NcmHOAA *hoaa, NcmModel *model, const gdouble k, const guint sing, gdouble *ts, gdouble *dts_i, gdouble *dts_f, NcmHOAASingType *st); -static gdouble _nc_hipert_adiab_eval_sing_mnu (NcmHOAA *hoaa, NcmModel *model, const gdouble t_m_ts, const gdouble k, const guint sing); -static gdouble _nc_hipert_adiab_eval_sing_dlnmnu (NcmHOAA *hoaa, NcmModel *model, const gdouble t_m_ts, const gdouble k, const guint sing); -static void _nc_hipert_adiab_eval_sing_system (NcmHOAA *hoaa, NcmModel *model, const gdouble t_m_ts, const gdouble k, const guint sing, gdouble *nu, gdouble *dlnmnu, gdouble *Vnu); +static gdouble _nc_hipert_adiab_eval_xi (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); +static gdouble _nc_hipert_adiab_eval_F1 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); +static gdouble _nc_hipert_adiab_eval_nu (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); +static gdouble _nc_hipert_adiab_eval_m (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); -static gdouble _nc_hipert_adiab_eval_powspec_factor (NcmHOAA *hoaa, NcmModel *model); - -static void _nc_hipert_adiab_prepare (NcmHOAA *hoaa, NcmModel *model); +static void _nc_hipert_adiab_prepare (NcmCSQ1D *csq1d, NcmModel *model); static void nc_hipert_adiab_class_init (NcHIPertAdiabClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - NcmHOAAClass *hoaa_class = NCM_HOAA_CLASS (klass); + NcmCSQ1DClass *csq1d_class = NCM_CSQ1D_CLASS (klass); object_class->set_property = &_nc_hipert_adiab_set_property; object_class->get_property = &_nc_hipert_adiab_get_property; object_class->dispose = &_nc_hipert_adiab_dispose; object_class->finalize = &_nc_hipert_adiab_finalize; - hoaa_class->eval_mnu = &_nc_hipert_adiab_eval_mnu; - hoaa_class->eval_nu = &_nc_hipert_adiab_eval_nu; - hoaa_class->eval_dlnmnu = &_nc_hipert_adiab_eval_dlnmnu; - hoaa_class->eval_V = NULL; - hoaa_class->eval_system = &_nc_hipert_adiab_eval_system; - hoaa_class->prepare = &_nc_hipert_adiab_prepare; + g_object_class_install_property (object_class, + PROP_K, + g_param_spec_double ("k", + NULL, + "Wave number", + 0.0, G_MAXDOUBLE, 1.0, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB)); - hoaa_class->nsing = &_nc_hipert_adiab_nsing; - hoaa_class->get_sing_info = &_nc_hipert_adiab_get_sing_info; - hoaa_class->eval_sing_mnu = &_nc_hipert_adiab_eval_sing_mnu; - hoaa_class->eval_sing_dlnmnu = &_nc_hipert_adiab_eval_sing_dlnmnu; - hoaa_class->eval_sing_V = NULL; - hoaa_class->eval_sing_system = &_nc_hipert_adiab_eval_sing_system; - hoaa_class->eval_powspec_factor = &_nc_hipert_adiab_eval_powspec_factor; + csq1d_class->eval_xi = &_nc_hipert_adiab_eval_xi; + csq1d_class->eval_F1 = &_nc_hipert_adiab_eval_F1; + csq1d_class->eval_nu = &_nc_hipert_adiab_eval_nu; + csq1d_class->eval_m = &_nc_hipert_adiab_eval_m; + csq1d_class->prepare = &_nc_hipert_adiab_prepare; } -static gdouble -_nc_hipert_adiab_eval_mnu (NcmHOAA *hoaa, NcmModel *model, const gdouble t, const gdouble k) +static gdouble +_nc_hipert_adiab_eval_xi (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) { - return nc_hipert_iadiab_eval_mnu (NC_HIPERT_IADIAB (model), t, k); -} + NcHIPertAdiab *pa = NC_HIPERT_ADIAB (csq1d); + const gdouble k = pa->k; -static gdouble -_nc_hipert_adiab_eval_nu (NcmHOAA *hoaa, NcmModel *model, const gdouble t, const gdouble k) -{ - return nc_hipert_iadiab_eval_nu (NC_HIPERT_IADIAB (model), t, k); + return nc_hipert_iadiab_eval_xi (NC_HIPERT_IADIAB (model), t, k); } -static gdouble -_nc_hipert_adiab_eval_dlnmnu (NcmHOAA *hoaa, NcmModel *model, const gdouble t, const gdouble k) +static gdouble +_nc_hipert_adiab_eval_F1 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) { - return nc_hipert_iadiab_eval_dlnmnu (NC_HIPERT_IADIAB (model), t, k); -} + NcHIPertAdiab *pa = NC_HIPERT_ADIAB (csq1d); + const gdouble k = pa->k; -static void -_nc_hipert_adiab_eval_system (NcmHOAA *hoaa, NcmModel *model, const gdouble t, const gdouble k, gdouble *nu, gdouble *dlnmnu, gdouble *Vnu) -{ - Vnu[0] = 0.0; - nc_hipert_iadiab_eval_system (NC_HIPERT_IADIAB (model), t, k, nu, dlnmnu); + return nc_hipert_iadiab_eval_F1 (NC_HIPERT_IADIAB (model), t, k); } -static void -_nc_hipert_adiab_prepare (NcmHOAA *hoaa, NcmModel *model) +static gdouble +_nc_hipert_adiab_eval_nu (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) { - g_assert (NC_IS_HIPERT_IADIAB (model)); + NcHIPertAdiab *pa = NC_HIPERT_ADIAB (csq1d); + const gdouble k = pa->k; + + return nc_hipert_iadiab_eval_nu (NC_HIPERT_IADIAB (model), t, k); } -static guint -_nc_hipert_adiab_nsing (NcmHOAA *hoaa, NcmModel *model, const gdouble k) +static gdouble +_nc_hipert_adiab_eval_m (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) { - return nc_hipert_iadiab_nsing (NC_HIPERT_IADIAB (model), k); + NcHIPertAdiab *pa = NC_HIPERT_ADIAB (csq1d); + const gdouble k = pa->k; + + return nc_hipert_iadiab_eval_m (NC_HIPERT_IADIAB (model), t, k); } -static void -_nc_hipert_adiab_get_sing_info (NcmHOAA *hoaa, NcmModel *model, const gdouble k, const guint sing, gdouble *ts, gdouble *dts_i, gdouble *dts_f, NcmHOAASingType *st) +static void +_nc_hipert_adiab_prepare (NcmCSQ1D *csq1d, NcmModel *model) { - nc_hipert_iadiab_get_sing_info (NC_HIPERT_IADIAB (model), k, sing, ts, dts_i, dts_f, st); + g_assert (NC_IS_HIPERT_IADIAB (model)); } -static gdouble -_nc_hipert_adiab_eval_sing_mnu (NcmHOAA *hoaa, NcmModel *model, const gdouble t_m_ts, const gdouble k, const guint sing) +/** + * nc_hipert_iadiab_eval_xi: + * @iad: a #NcHIPertIAdiab + * @tau: $\tau$ + * @k: $k$ + * + * Computes the value of $\xi = \ln(m\nu)$. + * + * Returns: $\xi$. + */ +gdouble +nc_hipert_iadiab_eval_xi (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k) { - return nc_hipert_iadiab_eval_sing_mnu (NC_HIPERT_IADIAB (model), t_m_ts, k, sing); + return NC_HIPERT_IADIAB_GET_IFACE (iad)->eval_xi (iad, tau, k); } -static gdouble -_nc_hipert_adiab_eval_sing_dlnmnu (NcmHOAA *hoaa, NcmModel *model, const gdouble t_m_ts, const gdouble k, const guint sing) +/** + * nc_hipert_iadiab_eval_F1: + * @iad: a #NcHIPertIAdiab + * @tau: $\tau$ + * @k: $k$ + * + * Computes the value of $F_1 = \dot{\xi}/(2\nu)$. + * + * Returns: $F_1$. + */ +gdouble +nc_hipert_iadiab_eval_F1 (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k) { - return nc_hipert_iadiab_eval_sing_dlnmnu (NC_HIPERT_IADIAB (model), t_m_ts, k, sing); + return NC_HIPERT_IADIAB_GET_IFACE (iad)->eval_F1 (iad, tau, k); } -static void -_nc_hipert_adiab_eval_sing_system (NcmHOAA *hoaa, NcmModel *model, const gdouble t_m_ts, const gdouble k, const guint sing, gdouble *nu, gdouble *dlnmnu, gdouble *Vnu) +/** + * nc_hipert_iadiab_eval_nu: + * @iad: a #NcHIPertIAdiab + * @tau: $\tau$ + * @k: $k$ + * + * Computes the value of $\nu$. + * + * Returns: $\nu$. + */ +gdouble +nc_hipert_iadiab_eval_nu (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k) { - Vnu[0] = 0.0; - nc_hipert_iadiab_eval_sing_system (NC_HIPERT_IADIAB (model), t_m_ts, k, sing, nu, dlnmnu); + return NC_HIPERT_IADIAB_GET_IFACE (iad)->eval_nu (iad, tau, k); } -static gdouble -_nc_hipert_adiab_eval_powspec_factor (NcmHOAA *hoaa, NcmModel *model) +/** + * nc_hipert_iadiab_eval_m: + * @iad: a #NcHIPertIAdiab + * @tau: $\tau$ + * @k: $k$ + * + * Computes the value of $m$. + * + * Returns: $m$. + */ +gdouble +nc_hipert_iadiab_eval_m (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k) { - return nc_hipert_iadiab_eval_powspec_factor (NC_HIPERT_IADIAB (model)); + return NC_HIPERT_IADIAB_GET_IFACE (iad)->eval_m (iad, tau, k); } -static gdouble -_nc_hipert_iadiab_eval_powspec_factor (NcHIPertIAdiab *iad) -{ - g_assert (NC_IS_HICOSMO (iad)); - { - NcHICosmo *cosmo = NC_HICOSMO (iad); - const gdouble RH_lp = nc_hicosmo_RH_planck (cosmo); - return 4.0 / (3.0 * M_PI * gsl_pow_2 (RH_lp)); - } +/** + * nc_hipert_iadiab_eval_unit: + * @iad: a #NcHIPertIAdiab + * + * Numerical factor for the power spectrum of the adiabatic mode. + * + * Returns: the numerical factor for the power spectrum of the adiabatic mode. + */ +gdouble +nc_hipert_iadiab_eval_unit (NcHIPertIAdiab *iad) +{ + return NC_HIPERT_IADIAB_GET_IFACE (iad)->eval_unit (iad); } /** - * nc_hipert_iadiab_eval_mnu: + * nc_hipert_iadiab_eval_x: * @iad: a #NcHIPertIAdiab * @tau: $\tau$ - * @k: $k$ * - * FIXME + * Evaluates the value of $x = a_0/a$ at a given time $\tau$. * - * Returns: FIXME. + * Returns: $x$. */ +gdouble +nc_hipert_iadiab_eval_x (NcHIPertIAdiab *iad, const gdouble tau) +{ + return NC_HIPERT_IADIAB_GET_IFACE (iad)->eval_x (iad, tau); +} + /** - * nc_hipert_iadiab_eval_nu: + * nc_hipert_iadiab_eval_p2Psi: * @iad: a #NcHIPertIAdiab * @tau: $\tau$ - * @k: $k$ * - * FIXME + * Evaluates the conversion factor to convert the momentum of the adiabatic mode to the + * gauge invariant variable $\Psi$. * - * Returns: FIXME. + * Returns: the conversion factor. */ +gdouble +nc_hipert_iadiab_eval_p2Psi (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k) +{ + return NC_HIPERT_IADIAB_GET_IFACE (iad)->eval_p2Psi (iad, tau, k); +} + /** - * nc_hipert_iadiab_eval_dlnmnu: + * nc_hipert_iadiab_eval_p2drho: * @iad: a #NcHIPertIAdiab * @tau: $\tau$ - * @k: $k$ * - * FIXME + * Evaluates the conversion factor to convert the momentum of the adiabatic mode to the + * gauge invariant variable $\delta\rho$. * - * Returns: FIXME. + * Returns: the conversion factor. */ +gdouble +nc_hipert_iadiab_eval_p2drho (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k) +{ + return NC_HIPERT_IADIAB_GET_IFACE (iad)->eval_p2drho (iad, tau, k); +} + /** - * nc_hipert_iadiab_eval_system: + * nc_hipert_iadiab_eval_lapse: * @iad: a #NcHIPertIAdiab * @tau: $\tau$ - * @k: $k$ - * @nu: (out): $\nu$ - * @dlnmnu: (out): FIXME * - * FIXME + * Evaluates the lapse function at a given time $\tau$. * + * Returns: the lapse function. */ +gdouble +nc_hipert_iadiab_eval_lapse (NcHIPertIAdiab *iad, const gdouble tau) +{ + return NC_HIPERT_IADIAB_GET_IFACE (iad)->eval_lapse (iad, tau); +} + /** - * nc_hipert_iadiab_eval_sing_mnu: + * nc_hipert_iadiab_eval_tau_hubble: * @iad: a #NcHIPertIAdiab - * @tau_m_taus: $\tau - \tau_s$ * @k: $k$ - * @sing: singularity index - * - * FIXME * - * Returns: FIXME. + * Evaluates the time at where the Hubble radius is equal to the wave number $k$. + * + * Returns: the time at where the Hubble radius is equal to the wave number $k$. */ +gdouble +nc_hipert_iadiab_eval_tau_hubble (NcHIPertIAdiab *iad, const gdouble k) +{ + return NC_HIPERT_IADIAB_GET_IFACE (iad)->eval_tau_hubble (iad, k); +} + /** - * nc_hipert_iadiab_eval_sing_dlnmnu: + * nc_hipert_iadiab_eval_tau_jeans: * @iad: a #NcHIPertIAdiab - * @tau_m_taus: $\tau - \tau_s$ * @k: $k$ - * @sing: singularity index * - * FIXME + * Evaluates the time at where the Jeans scale is equal to the wave number $k$. * - * Returns: FIXME. + * Returns: the time at where the Jeans scale is equal to the wave number $k$. */ +gdouble +nc_hipert_iadiab_eval_tau_jeans (NcHIPertIAdiab *iad, const gdouble k) +{ + return NC_HIPERT_IADIAB_GET_IFACE (iad)->eval_tau_jeans (iad, k); +} + /** - * nc_hipert_iadiab_eval_sing_system: + * nc_hipert_iadiab_eval_hubble: * @iad: a #NcHIPertIAdiab - * @tau_m_taus: $\tau - \tau_s$ - * @k: $k$ - * @sing: singularity index - * @nu: (out): FIXME - * @dlnmnu: (out): FIXME + * @tau: $\tau$ * - * FIXME + * Evaluates the Hubble function at a given time $\tau$. * + * Returns: the Hubble function. */ +gdouble +nc_hipert_iadiab_eval_hubble (NcHIPertIAdiab *iad, const gdouble tau) +{ + return NC_HIPERT_IADIAB_GET_IFACE (iad)->eval_hubble (iad, tau); +} /** * nc_hipert_adiab_new: @@ -366,8 +473,8 @@ NcHIPertAdiab * nc_hipert_adiab_new (void) { NcHIPertAdiab *pa = g_object_new (NC_TYPE_HIPERT_ADIAB, - "opt", NCM_HOAA_OPT_DLNMNU_ONLY, NULL); + return pa; } @@ -410,3 +517,404 @@ nc_hipert_adiab_clear (NcHIPertAdiab **pa) { g_clear_object (pa); } + +/** + * nc_hipert_adiab_set_k: + * @adiab: a #NcHIPertAdiab + * @k: $k$ + * + * Sets the wave number $k$. + */ +void +nc_hipert_adiab_set_k (NcHIPertAdiab *adiab, const gdouble k) +{ + adiab->k = k; +} + +/** + * nc_hipert_adiab_get_k: + * @adiab: a #NcHIPertAdiab + * + * Gets the wave number $k$. + * + * Returns: $k$ + */ +gdouble +nc_hipert_adiab_get_k (NcHIPertAdiab *adiab) +{ + return adiab->k; +} + +typedef struct _NcHIPertAdiabCosmicTimeIntegArg +{ + NcHIPertAdiab *adiab; + NcmModel *model; +} NcHIPertAdiabCosmicTimeIntegArg; + +static gdouble +_nc_hipert_adiab_cosmic_time_integ_forward (gdouble t, gdouble tau, void *params) +{ + NcHIPertAdiabCosmicTimeIntegArg *arg = (NcHIPertAdiabCosmicTimeIntegArg *) params; + + return nc_hipert_iadiab_eval_lapse (NC_HIPERT_IADIAB (arg->model), tau); +} + +static gdouble +_nc_hipert_adiab_cosmic_time_integ_backward (gdouble t, gdouble tau, void *params) +{ + NcHIPertAdiabCosmicTimeIntegArg *arg = (NcHIPertAdiabCosmicTimeIntegArg *) params; + + return -nc_hipert_iadiab_eval_lapse (NC_HIPERT_IADIAB (arg->model), -tau); +} + +/** + * nc_hipert_adiab_eval_cosmic_time: + * @adiab: a #NcHIPertAdiab + * @model: a #NcmModel + * @tau: $\tau$ + * + * Evaluates the cosmic time at a given conformal time $\tau$. + * + * Returns: the cosmic time. + */ +gdouble +nc_hipert_adiab_eval_cosmic_time (NcHIPertAdiab *adiab, NcmModel *model, const gdouble tau) +{ + if (ncm_model_ctrl_update (adiab->model_ctrl, model)) + { + NcHIPertAdiabCosmicTimeIntegArg arg; + + arg.adiab = adiab; + arg.model = model; + + ncm_ode_spline_prepare (adiab->ctime_forward, &arg); + ncm_ode_spline_prepare (adiab->ctime_backward, &arg); + } + + if (tau > 0) + { + NcmSpline *s = ncm_ode_spline_peek_spline (adiab->ctime_forward); + + return ncm_spline_eval (s, tau); + } + else + { + NcmSpline *s = ncm_ode_spline_peek_spline (adiab->ctime_backward); + + return ncm_spline_eval (s, -tau); + } +} + +/** + * nc_hipert_adiab_eval_delta_critial: + * @adiab: a #NcHIPertAdiab + * @model: a #NcmModel + * @tau: $\tau$ + * + * Evaluates the critical density contrast at a given conformal time $\tau$. + * + * Returns: the critical density contrast. + */ +gdouble +nc_hipert_adiab_eval_delta_critial (NcHIPertAdiab *adiab, NcmModel *model, const gdouble tau) +{ + const gdouble tau_hubble = nc_hipert_iadiab_eval_tau_hubble (NC_HIPERT_IADIAB (model), adiab->k); + const gdouble E = nc_hipert_iadiab_eval_hubble (NC_HIPERT_IADIAB (model), tau); + const gdouble t_hubble = nc_hipert_adiab_eval_cosmic_time (adiab, model, -tau_hubble); + const gdouble t = nc_hipert_adiab_eval_cosmic_time (adiab, model, tau); + const gdouble delta_t = t_hubble - t; + const gdouble F = fabs (2.0 * E * delta_t / M_PI); + const gdouble cbrt_2 = cbrt (2.0); + const gdouble factor1 = cbrt (2.0 + 27.0 * gsl_pow_2 (F) - 3.0 * F * sqrt (12.0 + 81.0 * gsl_pow_2 (F))); + const gdouble factor2 = (1.0 + cbrt_2 / factor1 + factor1 / cbrt_2) / (3.0 * F); + + /* printf ("% 22.15g % 22.15g % 22.15g % 22.15g % 22.15g % 22.15g\n", tau, tau_hubble, t, t_hubble, fabs (E * delta_t), 5.0 * t_hubble / t); */ + + /*return sqrt (factor2); */ + + return 5.0 * t_hubble / t; +} + +static gdouble +_nc_hipert_eval_powspec_zeta_from_state (NcHIPertAdiab *adiab, NcmModel *model, NcmCSQ1DState *state, const gdouble k) +{ + const gdouble unit = nc_hipert_iadiab_eval_unit (NC_HIPERT_IADIAB (model)); + gdouble J11, J12, J22; + + ncm_csq1d_state_get_J (state, &J11, &J12, &J22); + + return gsl_pow_2 (unit) * (J11 / 2.0); +} + +static gdouble +_nc_hipert_eval_powspec_Psi_from_state (NcHIPertAdiab *adiab, NcmModel *model, NcmCSQ1DState *state, const gdouble k) +{ + const gdouble unit = nc_hipert_iadiab_eval_unit (NC_HIPERT_IADIAB (model)); + const gdouble tau = ncm_csq1d_state_get_time (state); + const gdouble p2Psi = nc_hipert_iadiab_eval_p2Psi (NC_HIPERT_IADIAB (model), tau, k); + gdouble J11, J12, J22; + + ncm_csq1d_state_get_J (state, &J11, &J12, &J22); + + return gsl_pow_2 (unit * p2Psi) * (J22 / 2.0); +} + +static gdouble +_nc_hipert_eval_powspec_drho_from_state (NcHIPertAdiab *adiab, NcmModel *model, NcmCSQ1DState *state, const gdouble k) +{ + const gdouble unit = nc_hipert_iadiab_eval_unit (NC_HIPERT_IADIAB (model)); + const gdouble tau = ncm_csq1d_state_get_time (state); + const gdouble p2drho = nc_hipert_iadiab_eval_p2drho (NC_HIPERT_IADIAB (model), tau, k); + gdouble J11, J12, J22; + + ncm_csq1d_state_get_J (state, &J11, &J12, &J22); + + return gsl_pow_2 (unit * p2drho) * (J22 / 2.0); +} + +/** + * nc_hipert_adiab_eval_powspec_zeta_at: + * @adiab: a #NcHIPertAdiab + * @model: a #NcmModel + * @tau: $\tau$ + * + * Evaluates the power spectrum of the gauge invariant variable $\zeta$ at a given time + * $\tau$. The power spectrum is given by + * $$ + * P_\zeta = u^2\frac{2\pi^2}{k^3} \frac{J_{11}}{2}. + * $$ + * where $u$ is the numerical factor for the power spectrum of the adiabatic mode, $k$ is + * the wave number. + * + * Returns: the power spectrum of the gauge invariant variable $\zeta$. + */ +gdouble +nc_hipert_adiab_eval_powspec_zeta_at (NcHIPertAdiab *adiab, NcmModel *model, const gdouble tau) +{ + const gdouble k = nc_hipert_adiab_get_k (adiab); + NcmCSQ1DState state; + + ncm_csq1d_eval_at (NCM_CSQ1D (adiab), model, tau, &state); + + return _nc_hipert_eval_powspec_zeta_from_state (adiab, model, &state, k); +} + +/** + * nc_hipert_adiab_eval_powspec_Psi_at: + * @adiab: a #NcHIPertAdiab + * @model: a #NcmModel + * @tau: $\tau$ + * + * Evaluates the power spectrum of the gauge invariant variable $\Psi$ at a given time + * $\tau$. The power spectrum is given by + * $$ + * P_\Psi = u^2\frac{2\pi^2}{k^3} \frac{J_{22}}{2}. + * $$ + * + * Returns: the power spectrum of the gauge invariant variable $\Psi$. + */ +gdouble +nc_hipert_adiab_eval_powspec_Psi_at (NcHIPertAdiab *adiab, NcmModel *model, const gdouble tau) +{ + const gdouble k = nc_hipert_adiab_get_k (adiab); + NcmCSQ1DState state; + + ncm_csq1d_eval_at (NCM_CSQ1D (adiab), model, tau, &state); + + return _nc_hipert_eval_powspec_Psi_from_state (adiab, model, &state, k); +} + +/** + * nc_hipert_adiab_eval_powspec_drho_at: + * @adiab: a #NcHIPertAdiab + * @model: a #NcmModel + * @tau: $\tau$ + * + * Evaluates the power spectrum of the gauge invariant variable $\delta\rho$ at a given time + * $\tau$. The power spectrum is given by + * $$ + * P_{\delta\rho} = u^2\frac{2\pi^2}{k^3} \frac{J_{22}}{2}. + * $$ + * + * Returns: the power spectrum of the gauge invariant variable $\delta\rho$. + */ +gdouble +nc_hipert_adiab_eval_powspec_drho_at (NcHIPertAdiab *adiab, NcmModel *model, const gdouble tau) +{ + const gdouble k = nc_hipert_adiab_get_k (adiab); + NcmCSQ1DState state; + + ncm_csq1d_eval_at (NCM_CSQ1D (adiab), model, tau, &state); + + return _nc_hipert_eval_powspec_drho_from_state (adiab, model, &state, k); +} + +/** + * nc_hipert_adiab_prepare_spectrum: + * @adiab: a #NcHIPertAdiab + * @model: a #NcmModel + * @k_array: (element-type gdouble): array of wave numbers + * @tau_array: (element-type gdouble): array of times to evaluate the power spectrum + * + * Prepares the computation of the power spectrum of the adiabatic mode. + * + */ +void +nc_hipert_adiab_prepare_spectrum (NcHIPertAdiab *adiab, NcmModel *model, GArray *k_array, GArray *tau_array) +{ + NcmCSQ1D *csq1d = NCM_CSQ1D (adiab); + NcmMatrix *powspec_alpha = ncm_matrix_new (k_array->len, tau_array->len); + NcmMatrix *powspec_gamma = ncm_matrix_new (k_array->len, tau_array->len); + guint i; + + for (i = 0; i < k_array->len; i++) + { + NcmCSQ1DState state; + guint j; + + nc_hipert_adiab_set_k (adiab, g_array_index (k_array, gdouble, i)); + ncm_csq1d_prepare (csq1d, model); + + for (j = 0; j < tau_array->len; j++) + { + const gdouble tau = g_array_index (tau_array, gdouble, j); + gdouble alpha, gamma; + + ncm_csq1d_eval_at (csq1d, model, tau, &state); + ncm_csq1d_state_get_ag (&state, &alpha, &gamma); + + ncm_matrix_set (powspec_alpha, i, j, alpha); + ncm_matrix_set (powspec_gamma, i, j, gamma); + } + } + + { + NcmVector *tau_vec = ncm_vector_new_array (tau_array); + NcmVector *k_vec = ncm_vector_new_array (k_array); + NcmSpline *s = ncm_spline_cubic_notaknot_new (); + + ncm_spline2d_clear (&adiab->powspec_alpha); + ncm_spline2d_clear (&adiab->powspec_gamma); + + adiab->powspec_alpha = ncm_spline2d_bicubic_notaknot_new (); + adiab->powspec_gamma = ncm_spline2d_bicubic_notaknot_new (); + + ncm_spline2d_set (adiab->powspec_alpha, tau_vec, k_vec, powspec_alpha, TRUE); + ncm_spline2d_set (adiab->powspec_gamma, tau_vec, k_vec, powspec_gamma, TRUE); + + ncm_matrix_free (powspec_alpha); + ncm_matrix_free (powspec_gamma); + ncm_vector_free (tau_vec); + ncm_vector_free (k_vec); + } +} + +static NcmPowspecSpline2d * +_nc_hipert_adiab_eval_powspec_func (NcHIPertAdiab *adiab, NcmModel *model, + gdouble (*eval_from_state)(NcHIPertAdiab *adiab, NcmModel *model, NcmCSQ1DState *state, const gdouble k)) +{ + NcmCSQ1D *csq1d = NCM_CSQ1D (adiab); + const gdouble unit = nc_hipert_iadiab_eval_unit (NC_HIPERT_IADIAB (model)); + gdouble tAd; + gboolean found; + guint i; + + if (!ncm_spline2d_is_init (adiab->powspec_alpha) || !ncm_spline2d_is_init (adiab->powspec_gamma)) + { + g_error ("Power spectrum not prepared."); + + return NULL; + } + else + { + NcmVector *tau_vec = ncm_spline2d_peek_xv (adiab->powspec_alpha); + NcmVector *k_vec = ncm_spline2d_peek_yv (adiab->powspec_alpha); + const guint tau_len = ncm_vector_len (tau_vec); + const guint k_len = ncm_vector_len (k_vec); + NcmMatrix *powspec_mat = ncm_matrix_new (k_len, tau_len); + guint i; + + for (i = 0; i < tau_len; i++) + { + const gdouble tau = ncm_vector_get (tau_vec, i); + guint j; + + for (j = 0; j < k_len; j++) + { + const gdouble k = ncm_vector_get (k_vec, j); + NcmCSQ1DState state; + + state.t = tau; + state.frame = NCM_CSQ1D_FRAME_ORIG; + state.alpha = ncm_spline2d_eval (adiab->powspec_alpha, tau, k); + state.gamma = ncm_spline2d_eval (adiab->powspec_gamma, tau, k); + + ncm_matrix_set (powspec_mat, j, i, log (eval_from_state (adiab, model, &state, k))); + } + } + + { + NcmSpline2d *powspec_spline = ncm_spline2d_bicubic_notaknot_new (); + NcmVector *lnk_vec = ncm_vector_dup (k_vec); + NcmPowspecSpline2d *powspec; + guint i; + + for (i = 0; i < k_len; i++) + ncm_vector_set (lnk_vec, i, log (ncm_vector_get (lnk_vec, i))); + + ncm_spline2d_set (powspec_spline, tau_vec, lnk_vec, powspec_mat, TRUE); + + powspec = ncm_powspec_spline2d_new (powspec_spline); + + ncm_matrix_free (powspec_mat); + + return powspec; + } + } +} + +/** + * nc_hipert_adiab_eval_powspec_zeta: + * @adiab: a #NcHIPertAdiab + * @model: a #NcmModel + * + * Evaluates the power spectrum for the gauge invariant variable $\zeta$. + * + * Returns: (transfer full): the power spectrum of $\zeta$. + */ +NcmPowspecSpline2d * +nc_hipert_adiab_eval_powspec_zeta (NcHIPertAdiab *adiab, NcmModel *model) +{ + return _nc_hipert_adiab_eval_powspec_func (adiab, model, _nc_hipert_eval_powspec_zeta_from_state); +} + +/** + * nc_hipert_adiab_eval_powspec_Psi: + * @adiab: a #NcHIPertAdiab + * @model: a #NcmModel + * + * Evaluates the power spectrum for the gauge invariant variable $\Psi$. + * + * Returns: (transfer full): the power spectrum of $\Psi$. + */ +NcmPowspecSpline2d * +nc_hipert_adiab_eval_powspec_Psi (NcHIPertAdiab *adiab, NcmModel *model) +{ + return _nc_hipert_adiab_eval_powspec_func (adiab, model, _nc_hipert_eval_powspec_Psi_from_state); +} + +/** + * nc_hipert_adiab_eval_powspec_drho: + * @adiab: a #NcHIPertAdiab + * @model: a #NcmModel + * + * Evaluates the power spectrum for the gauge invariant variable $\delta\rho$. + * + * Returns: (transfer full): the power spectrum of $\delta\rho$. + */ +NcmPowspecSpline2d * +nc_hipert_adiab_eval_powspec_drho (NcHIPertAdiab *adiab, NcmModel *model) +{ + return _nc_hipert_adiab_eval_powspec_func (adiab, model, _nc_hipert_eval_powspec_drho_from_state); +} + diff --git a/numcosmo/perturbations/nc_hipert_adiab.h b/numcosmo/perturbations/nc_hipert_adiab.h index 8b41841cb..9d9a9bd4a 100644 --- a/numcosmo/perturbations/nc_hipert_adiab.h +++ b/numcosmo/perturbations/nc_hipert_adiab.h @@ -13,12 +13,12 @@ * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * numcosmo is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -30,50 +30,39 @@ #include #include #include +#include #include -#include +#include G_BEGIN_DECLS -#define NC_TYPE_HIPERT_IADIAB (nc_hipert_iadiab_get_type ()) -#define NC_HIPERT_IADIAB(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NC_TYPE_HIPERT_IADIAB, NcHIPertIAdiab)) -#define NC_IS_HIPERT_IADIAB(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NC_TYPE_HIPERT_IADIAB)) -#define NC_HIPERT_IADIAB_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), NC_TYPE_HIPERT_IADIAB, NcHIPertIAdiabInterface)) +#define NC_TYPE_HIPERT_ADIAB (nc_hipert_adiab_get_type ()) +#define NC_TYPE_HIPERT_IADIAB (nc_hipert_iadiab_get_type ()) -typedef struct _NcHIPertIAdiab NcHIPertIAdiab; -typedef struct _NcHIPertIAdiabInterface NcHIPertIAdiabInterface; +G_DECLARE_INTERFACE (NcHIPertIAdiab, nc_hipert_iadiab, NC, HIPERT_IADIAB, GObject) +G_DECLARE_FINAL_TYPE (NcHIPertAdiab, nc_hipert_adiab, NC, HIPERT_ADIAB, NcmCSQ1D) struct _NcHIPertIAdiabInterface { /*< private >*/ GTypeInterface parent; - gdouble (*eval_mnu) (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k); + gdouble (*eval_xi) (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k); + gdouble (*eval_F1) (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k); gdouble (*eval_nu) (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k); - gdouble (*eval_dlnmnu) (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k); - void (*eval_system) (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k, gdouble *nu, gdouble *dlnmnu); - guint (*nsing) (NcHIPertIAdiab *iad, const gdouble k); - void (*get_sing_info) (NcHIPertIAdiab *iad, const gdouble k, const guint sing, gdouble *ts, gdouble *dts_i, gdouble *dts_f, NcmHOAASingType *st); - gdouble (*eval_sing_mnu) (NcHIPertIAdiab *iad, const gdouble tau_m_taus, const gdouble k, const guint sing); - gdouble (*eval_sing_dlnmnu) (NcHIPertIAdiab *iad, const gdouble tau_m_taus, const gdouble k, const guint sing); - void (*eval_sing_system) (NcHIPertIAdiab *iad, const gdouble tau_m_taus, const gdouble k, const guint sing, gdouble *nu, gdouble *dlnmnu); - gdouble (*eval_powspec_factor) (NcHIPertIAdiab *iad); + gdouble (*eval_m) (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k); + gdouble (*eval_unit) (NcHIPertIAdiab *iad); + gdouble (*eval_x) (NcHIPertIAdiab *iad, const gdouble tau); + gdouble (*eval_p2Psi) (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k); + gdouble (*eval_p2drho) (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k); + gdouble (*eval_lapse) (NcHIPertIAdiab *iad, const gdouble tau); + gdouble (*eval_tau_hubble) (NcHIPertIAdiab *iad, const gdouble k); + gdouble (*eval_tau_jeans) (NcHIPertIAdiab *iad, const gdouble k); + gdouble (*eval_hubble) (NcHIPertIAdiab *iad, const gdouble tau); + + /* Padding to allow 18 virtual functions without breaking ABI. */ + gpointer padding[12]; }; -#define NC_TYPE_HIPERT_ADIAB (nc_hipert_adiab_get_type ()) -#define NC_HIPERT_ADIAB(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NC_TYPE_HIPERT_ADIAB, NcHIPertAdiab)) -#define NC_HIPERT_ADIAB_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NC_TYPE_HIPERT_ADIAB, NcHIPertAdiabClass)) -#define NC_IS_HIPERT_ADIAB(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NC_TYPE_HIPERT_ADIAB)) -#define NC_IS_HIPERT_ADIAB_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NC_TYPE_HIPERT_ADIAB)) -#define NC_HIPERT_ADIAB_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NC_TYPE_HIPERT_ADIAB, NcHIPertAdiabClass)) - -typedef struct _NcHIPertAdiabClass NcHIPertAdiabClass; -typedef struct _NcHIPertAdiab NcHIPertAdiab; - -struct _NcHIPertAdiabClass -{ - /*< private >*/ - NcmHOAAClass parent_class; -}; /** * NcHIPertAdiabVars: @@ -81,9 +70,9 @@ struct _NcHIPertAdiabClass * @NC_HIPERT_ADIAB_IM_ZETA: $\text{Im}(\zeta)$ * @NC_HIPERT_ADIAB_RE_PZETA: $\text{Re}(P_\zeta)$ * @NC_HIPERT_ADIAB_IM_PZETA: $\text{Im}(P_\zeta)$ - * + * * Perturbation variables enumerator. - * + * */ typedef enum /*< enum,underscore_name=NC_HIPERT_ADIAB_VARS >*/ { @@ -93,106 +82,41 @@ typedef enum /*< enum,underscore_name=NC_HIPERT_ADIAB_VARS >*/ NC_HIPERT_ADIAB_IM_PZETA, } NcHIPertAdiabVars; -struct _NcHIPertAdiab -{ - /*< private >*/ - NcmHOAA parent_instance; -}; - -GType nc_hipert_iadiab_get_type (void) G_GNUC_CONST; -GType nc_hipert_adiab_get_type (void) G_GNUC_CONST; - -NCM_INLINE gdouble nc_hipert_iadiab_eval_mnu (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k); -NCM_INLINE gdouble nc_hipert_iadiab_eval_nu (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k); -NCM_INLINE gdouble nc_hipert_iadiab_eval_dlnmnu (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k); -NCM_INLINE void nc_hipert_iadiab_eval_system (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k, gdouble *nu, gdouble *dlnmnu); - -NCM_INLINE guint nc_hipert_iadiab_nsing (NcHIPertIAdiab *iad, const gdouble k); -NCM_INLINE void nc_hipert_iadiab_get_sing_info (NcHIPertIAdiab *iad, const gdouble k, const guint sing, gdouble *ts, gdouble *dts_i, gdouble *dts_f, NcmHOAASingType *st); -NCM_INLINE gdouble nc_hipert_iadiab_eval_sing_mnu (NcHIPertIAdiab *iad, const gdouble tau_m_taus, const gdouble k, const guint sing); -NCM_INLINE gdouble nc_hipert_iadiab_eval_sing_dlnmnu (NcHIPertIAdiab *iad, const gdouble tau_m_taus, const gdouble k, const guint sing); -NCM_INLINE void nc_hipert_iadiab_eval_sing_system (NcHIPertIAdiab *iad, const gdouble tau_m_taus, const gdouble k, const guint sing, gdouble *nu, gdouble *dlnmnu); - -NCM_INLINE gdouble nc_hipert_iadiab_eval_powspec_factor (NcHIPertIAdiab *iad); +gdouble nc_hipert_iadiab_eval_xi (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k); +gdouble nc_hipert_iadiab_eval_F1 (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k); +gdouble nc_hipert_iadiab_eval_nu (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k); +gdouble nc_hipert_iadiab_eval_m (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k); +gdouble nc_hipert_iadiab_eval_unit (NcHIPertIAdiab *iad); +gdouble nc_hipert_iadiab_eval_x (NcHIPertIAdiab *iad, const gdouble tau); +gdouble nc_hipert_iadiab_eval_p2Psi (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k); +gdouble nc_hipert_iadiab_eval_p2drho (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k); +gdouble nc_hipert_iadiab_eval_lapse (NcHIPertIAdiab *iad, const gdouble tau); +gdouble nc_hipert_iadiab_eval_tau_hubble (NcHIPertIAdiab *iad, const gdouble k); +gdouble nc_hipert_iadiab_eval_tau_jeans (NcHIPertIAdiab *iad, const gdouble k); +gdouble nc_hipert_iadiab_eval_hubble (NcHIPertIAdiab *iad, const gdouble tau); NcHIPertAdiab *nc_hipert_adiab_new (void); NcHIPertAdiab *nc_hipert_adiab_ref (NcHIPertAdiab *pa); void nc_hipert_adiab_free (NcHIPertAdiab *pa); void nc_hipert_adiab_clear (NcHIPertAdiab **pa); -G_END_DECLS - -#endif /* _NC_HIPERT_ADIAB_H_ */ - -#ifndef _NC_HIPERT_ADIAB_INLINE_H_ -#define _NC_HIPERT_ADIAB_INLINE_H_ -#ifdef NUMCOSMO_HAVE_INLINE -#ifndef __GTK_DOC_IGNORE__ +void nc_hipert_adiab_set_k (NcHIPertAdiab *adiab, const gdouble k); +gdouble nc_hipert_adiab_get_k (NcHIPertAdiab *adiab); -G_BEGIN_DECLS - -NCM_INLINE gdouble -nc_hipert_iadiab_eval_mnu (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k) -{ - return NC_HIPERT_IADIAB_GET_INTERFACE (iad)->eval_mnu (iad, tau, k); -} - -NCM_INLINE gdouble -nc_hipert_iadiab_eval_nu (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k) -{ - return NC_HIPERT_IADIAB_GET_INTERFACE (iad)->eval_nu (iad, tau, k); -} - -NCM_INLINE gdouble -nc_hipert_iadiab_eval_dlnmnu (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k) -{ - return NC_HIPERT_IADIAB_GET_INTERFACE (iad)->eval_dlnmnu (iad, tau, k); -} - -NCM_INLINE void -nc_hipert_iadiab_eval_system (NcHIPertIAdiab *iad, const gdouble tau, const gdouble k, gdouble *nu, gdouble *dlnmnu) -{ - NC_HIPERT_IADIAB_GET_INTERFACE (iad)->eval_system (iad, tau, k, nu, dlnmnu); -} - -NCM_INLINE guint -nc_hipert_iadiab_nsing (NcHIPertIAdiab *iad, const gdouble k) -{ - return NC_HIPERT_IADIAB_GET_INTERFACE (iad)->nsing (iad, k); -} - -NCM_INLINE void -nc_hipert_iadiab_get_sing_info (NcHIPertIAdiab *iad, const gdouble k, const guint sing, gdouble *ts, gdouble *dts_i, gdouble *dts_f, NcmHOAASingType *st) -{ - NC_HIPERT_IADIAB_GET_INTERFACE (iad)->get_sing_info (iad, k, sing, ts, dts_i, dts_f, st); -} - -NCM_INLINE gdouble -nc_hipert_iadiab_eval_sing_mnu (NcHIPertIAdiab *iad, const gdouble tau_m_taus, const gdouble k, const guint sing) -{ - return NC_HIPERT_IADIAB_GET_INTERFACE (iad)->eval_sing_mnu (iad, tau_m_taus, k, sing); -} +gdouble nc_hipert_adiab_eval_cosmic_time (NcHIPertAdiab *adiab, NcmModel *model, const gdouble tau); +gdouble nc_hipert_adiab_eval_delta_critial (NcHIPertAdiab *adiab, NcmModel *model, const gdouble tau); -NCM_INLINE gdouble -nc_hipert_iadiab_eval_sing_dlnmnu (NcHIPertIAdiab *iad, const gdouble tau_m_taus, const gdouble k, const guint sing) -{ - return NC_HIPERT_IADIAB_GET_INTERFACE (iad)->eval_sing_dlnmnu (iad, tau_m_taus, k, sing); -} +gdouble nc_hipert_adiab_eval_powspec_zeta_at (NcHIPertAdiab *adiab, NcmModel *model, const gdouble tau); +gdouble nc_hipert_adiab_eval_powspec_Psi_at (NcHIPertAdiab *adiab, NcmModel *model, const gdouble tau); +gdouble nc_hipert_adiab_eval_powspec_drho_at (NcHIPertAdiab *adiab, NcmModel *model, const gdouble tau); -NCM_INLINE void -nc_hipert_iadiab_eval_sing_system (NcHIPertIAdiab *iad, const gdouble tau_m_taus, const gdouble k, const guint sing, gdouble *nu, gdouble *dlnmnu) -{ - NC_HIPERT_IADIAB_GET_INTERFACE (iad)->eval_sing_system (iad, tau_m_taus, k, sing, nu, dlnmnu); -} +void nc_hipert_adiab_prepare_spectrum (NcHIPertAdiab *adiab, NcmModel *model, GArray *k_array, GArray *tau_array); -NCM_INLINE gdouble -nc_hipert_iadiab_eval_powspec_factor (NcHIPertIAdiab *iad) -{ - return NC_HIPERT_IADIAB_GET_INTERFACE (iad)->eval_powspec_factor (iad); -} +NcmPowspecSpline2d *nc_hipert_adiab_eval_powspec_zeta (NcHIPertAdiab *adiab, NcmModel *model); +NcmPowspecSpline2d *nc_hipert_adiab_eval_powspec_Psi (NcHIPertAdiab *adiab, NcmModel *model); +NcmPowspecSpline2d *nc_hipert_adiab_eval_powspec_drho (NcHIPertAdiab *adiab, NcmModel *model); G_END_DECLS -#endif /* __GTK_DOC_IGNORE__ */ -#endif /* NUMCOSMO_HAVE_INLINE */ -#endif /* _NC_HIPERT_ADIAB_INLINE_H_ */ +#endif /* _NC_HIPERT_ADIAB_H_ */ + diff --git a/numcosmo/perturbations/nc_hipert_em.c b/numcosmo/perturbations/nc_hipert_em.c new file mode 100644 index 000000000..fadd79353 --- /dev/null +++ b/numcosmo/perturbations/nc_hipert_em.c @@ -0,0 +1,443 @@ +/*************************************************************************** + * nc_hipert_em.h + * + * Sat March 16 10:53:30 2024 + * Copyright 2024 Sandro Dias Pinto Vitenti + * + ****************************************************************************/ +/* + * nc_hipert_em.c + * Copyright (C) 2024 Sandro Dias Pinto Vitenti + * + * numcosmo is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * numcosmo is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +/** + * SECTION:nc_hipert_em + * @title: NcHIPertEM + * @short_description: Perturbation object for electromagnetic mode. + * + * This object provides the computation of the electromagnetic wave mode for the cosmological + * perturbations. It solves the equation of motion for the (cosmological) gauge invariant + * variable $A$. + * + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif /* HAVE_CONFIG_H */ +#include "build_cfg.h" + +#include "math/ncm_spline_cubic_notaknot.h" +#include "perturbations/nc_hipert_em.h" + +#ifndef NUMCOSMO_GIR_SCAN +#include +#include +#include +#endif /* NUMCOSMO_GIR_SCAN */ + +struct _NcHIPertEM +{ + NcmCSQ1D parent_instance; + gdouble k; +}; + +G_DEFINE_INTERFACE (NcHIPertIEM, nc_hipert_iem, G_TYPE_OBJECT) +G_DEFINE_TYPE (NcHIPertEM, nc_hipert_em, NCM_TYPE_CSQ1D) + +static gdouble _nc_hipert_iem_eval_unit (NcHIPertIEM *iem); + +static void +nc_hipert_iem_default_init (NcHIPertIEMInterface *iface) +{ + iface->eval_xi = NULL; + iface->eval_F1 = NULL; + iface->eval_nu = NULL; + iface->eval_m = NULL; + iface->eval_unit = NULL; +} + +enum +{ + PROP_0, + PROP_K, + PROP_SIZE, +}; + +typedef struct _NcHIPertEMArg +{ + NcHICosmo *cosmo; + NcHIPertEM *pem; +} NcHIPertEMArg; + +static void +nc_hipert_em_init (NcHIPertEM *pem) +{ + pem->k = 0.0; +} + +static void +_nc_hipert_em_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) +{ + NcHIPertEM *pem = NC_HIPERT_EM (object); + + g_return_if_fail (NC_IS_HIPERT_EM (object)); + + switch (prop_id) + { + case PROP_K: + nc_hipert_em_set_k (pem, g_value_get_double (value)); + break; + default: /* LCOV_EXCL_LINE */ + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); /* LCOV_EXCL_LINE */ + break; /* LCOV_EXCL_LINE */ + } +} + +static void +_nc_hipert_em_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) +{ + /* NcHIPertEM *pem = NC_HIPERT_EM (object); */ + g_return_if_fail (NC_IS_HIPERT_EM (object)); + + switch (prop_id) + { + case PROP_K: + g_value_set_double (value, nc_hipert_em_get_k (NC_HIPERT_EM (object))); + break; + default: /* LCOV_EXCL_LINE */ + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); /* LCOV_EXCL_LINE */ + break; /* LCOV_EXCL_LINE */ + } +} + +static void +_nc_hipert_em_dispose (GObject *object) +{ + /*NcHIPertEM *pem = NC_HIPERT_EM (object);*/ + + /* Chain up : end */ + G_OBJECT_CLASS (nc_hipert_em_parent_class)->dispose (object); +} + +static void +_nc_hipert_em_finalize (GObject *object) +{ + /* Chain up : end */ + G_OBJECT_CLASS (nc_hipert_em_parent_class)->finalize (object); +} + +static gdouble _nc_hipert_em_eval_xi (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); +static gdouble _nc_hipert_em_eval_F1 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); +static gdouble _nc_hipert_em_eval_nu (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); +static gdouble _nc_hipert_em_eval_m (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); +static void _nc_hipert_em_prepare (NcmCSQ1D *csq1d, NcmModel *model); + +static void +nc_hipert_em_class_init (NcHIPertEMClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + NcmCSQ1DClass *csq1d_class = NCM_CSQ1D_CLASS (klass); + + object_class->set_property = &_nc_hipert_em_set_property; + object_class->get_property = &_nc_hipert_em_get_property; + object_class->dispose = &_nc_hipert_em_dispose; + object_class->finalize = &_nc_hipert_em_finalize; + + g_object_class_install_property (object_class, + PROP_K, + g_param_spec_double ("k", + NULL, + "Wave number", + 0.0, G_MAXDOUBLE, 1.0, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB)); + + csq1d_class->eval_xi = &_nc_hipert_em_eval_xi; + csq1d_class->eval_F1 = &_nc_hipert_em_eval_F1; + csq1d_class->eval_nu = &_nc_hipert_em_eval_nu; + csq1d_class->eval_m = &_nc_hipert_em_eval_m; + csq1d_class->prepare = &_nc_hipert_em_prepare; +} + +static gdouble +_nc_hipert_em_eval_xi (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) +{ + NcHIPertEM *pem = NC_HIPERT_EM (csq1d); + const gdouble k = pem->k; + + return nc_hipert_iem_eval_xi (NC_HIPERT_IEM (model), t, k); +} + +static gdouble +_nc_hipert_em_eval_F1 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) +{ + NcHIPertEM *pem = NC_HIPERT_EM (csq1d); + const gdouble k = pem->k; + + return nc_hipert_iem_eval_F1 (NC_HIPERT_IEM (model), t, k); +} + +static gdouble +_nc_hipert_em_eval_nu (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) +{ + NcHIPertEM *pem = NC_HIPERT_EM (csq1d); + const gdouble k = pem->k; + + return nc_hipert_iem_eval_nu (NC_HIPERT_IEM (model), t, k); +} + +static gdouble +_nc_hipert_em_eval_m (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) +{ + NcHIPertEM *pem = NC_HIPERT_EM (csq1d); + const gdouble k = pem->k; + + return nc_hipert_iem_eval_m (NC_HIPERT_IEM (model), t, k); +} + +static void +_nc_hipert_em_prepare (NcmCSQ1D *csq1d, NcmModel *model) +{ + g_assert (NC_IS_HIPERT_IEM (model)); +} + +/** + * nc_hipert_iem_eval_xi: + * @iem: a #NcHIPertIEM + * @tau: $\tau$ + * @k: $k$ + * + * Computes the value of $\xi = \ln(m\nu)$ + * + * Returns: $\xi$. + */ + +gdouble +nc_hipert_iem_eval_xi (NcHIPertIEM *iem, const gdouble tau, const gdouble k) +{ + return NC_HIPERT_IEM_GET_IFACE (iem)->eval_xi (iem, tau, k); +} + +/** + * nc_hipert_iem_eval_F1: + * @iem: a #NcHIPertIEM + * @tau: $\tau$ + * @k: $k$ + * + * Computes the value of $F_1 = \dot{\xi}/(2\nu)$. + * + * Returns: $F_1$. + */ + +gdouble +nc_hipert_iem_eval_F1 (NcHIPertIEM *iem, const gdouble tau, const gdouble k) +{ + return NC_HIPERT_IEM_GET_IFACE (iem)->eval_F1 (iem, tau, k); +} + +/** + * nc_hipert_iem_eval_nu: + * @iem: a #NcHIPertIEM + * @tau: $\tau$ + * @k: $k$ + * + * Computes the value of $\nu$. + * + * Returns: $\nu$. + */ +gdouble +nc_hipert_iem_eval_nu (NcHIPertIEM *iem, const gdouble tau, const gdouble k) +{ + return NC_HIPERT_IEM_GET_IFACE (iem)->eval_nu (iem, tau, k); +} + +/** + * nc_hipert_iem_eval_m: + * @iem: a #NcHIPertIEM + * @tau: $\tau$ + * @k: $k$ + * + * Computes the value of $m$. + * + * Returns: $m$. + */ +gdouble +nc_hipert_iem_eval_m (NcHIPertIEM *iem, const gdouble tau, const gdouble k) +{ + return NC_HIPERT_IEM_GET_IFACE (iem)->eval_m (iem, tau, k); +} + +/** + * nc_hipert_iem_eval_unit: + * @iem: a #NcHIPertIEM + * + * FIXME + * + * Returns: FIXME. + */ +gdouble +nc_hipert_iem_eval_unit (NcHIPertIEM *iem) +{ + return NC_HIPERT_IEM_GET_IFACE (iem)->eval_unit (iem); +} + +/** + * nc_hipert_iem_eval_x: + * @iem: a #NcHIPertIEM + * @tau: $\tau$ + * + * Evaluates the value of $x = a_0 / a$ at a given time $\tau$. + * + * Returns: $x$. + */ +gdouble +nc_hipert_iem_eval_x (NcHIPertIEM *iem, const gdouble tau) +{ + return NC_HIPERT_IEM_GET_IFACE (iem)->eval_x (iem, tau); +} + +/** + * nc_hipert_iem_eval_lapse: + * @iem: a #NcHIPertIEM + * @tau: $\tau$ + * + * Evaluates the value of the lapse function + * $N = \mathrm{d}t/\mathrm{d}\tau$ at a given time $\tau$. + * + * Returns: the lapse function $N(\tau)$. + */ +gdouble +nc_hipert_iem_eval_lapse (NcHIPertIEM *iem, const gdouble tau) +{ + return NC_HIPERT_IEM_GET_IFACE (iem)->eval_lapse (iem, tau); +} + +/** + * nc_hipert_em_new: + * + * Creates a new #NcHIPertEM object. + * + * Returns: (transfer full): a new #NcHIPertEM. + */ +NcHIPertEM * +nc_hipert_em_new (void) +{ + NcHIPertEM *pem = g_object_new (NC_TYPE_HIPERT_EM, + NULL); + + return pem; +} + +/** + * nc_hipert_em_ref: + * @pem: a #NcHIPertEM + * + * Increases the reference count of @pem. + * + * Returns: (transfer full): @pem. + */ +NcHIPertEM * +nc_hipert_em_ref (NcHIPertEM *pem) +{ + return g_object_ref (pem); +} + +/** + * nc_hipert_em_free: + * @pem: a #NcHIPertEM + * + * Decreases the reference count of @pem. + * + */ +void +nc_hipert_em_free (NcHIPertEM *pem) +{ + g_object_unref (pem); +} + +/** + * nc_hipert_em_clear: + * @pem: a #NcHIPertEM + * + * Decreases the reference count of *@pem and sets *@pem to NULL. + * + */ +void +nc_hipert_em_clear (NcHIPertEM **pem) +{ + g_clear_object (pem); +} + +/** + * nc_hipert_em_set_k: + * @pem: a #NcHIPertEM + * @k: the mode $k$ + * + * Sets the mode $k$ for the gravitational wave perturbation mode. + * + */ +void +nc_hipert_em_set_k (NcHIPertEM *pem, const gdouble k) +{ + pem->k = k; +} + +/** + * nc_hipert_em_get_k: + * @pem: a #NcHIPertEM + * + * Returns the mode $k$ for the gravitational wave perturbation mode. + * + * Returns: the mode $k$. + */ +gdouble +nc_hipert_em_get_k (NcHIPertEM *pem) +{ + return pem->k; +} + +/** + * nc_hipert_em_eval_PE_PB: + * @pem: a #NcHIPertEM + * @tau: $\tau$ + * @PE: (out): the electric field power spectrum + * @PB: (out): the magnetic field power spectrum + * + * Evaluates the electric and magnetic field power spectra in + * units of Gauss squared $G_\mathrm{s}^2$. + */ +void +nc_hipert_em_eval_PE_PB (NcHIPertEM *pem, NcmModel *model, const gdouble tau, gdouble *PE, gdouble *PB) +{ + NcmCSQ1D *csq1d = NCM_CSQ1D (pem); + NcHIPertIEM *iem = NC_HIPERT_IEM (model); + const gdouble unit = nc_hipert_iem_eval_unit (iem); + const gdouble m = ncm_csq1d_eval_m (csq1d, model, tau); + const gdouble k = pem->k; + const gdouble x = nc_hipert_iem_eval_x (iem, tau); + const gdouble N = nc_hipert_iem_eval_lapse (iem, tau); + const gdouble fact = ncm_c_two_pi_2 (); + + NcmCSQ1DState state; + gdouble J11, J12, J22; + + ncm_csq1d_eval_at (csq1d, model, tau, &state); + + ncm_csq1d_state_get_J (&state, &J11, &J12, &J22); + + *PE = unit * unit * gsl_pow_4 (x) * gsl_pow_3 (k) * J22 / gsl_pow_2 (N * m) / fact; + *PB = unit * unit * gsl_pow_4 (x) * gsl_pow_5 (k) * J11 / fact; +} + diff --git a/numcosmo/perturbations/nc_hipert_em.h b/numcosmo/perturbations/nc_hipert_em.h new file mode 100644 index 000000000..eed20aeca --- /dev/null +++ b/numcosmo/perturbations/nc_hipert_em.h @@ -0,0 +1,99 @@ +/*************************************************************************** + * nc_hipert_em.h + * + * Sat March 16 10:53:30 2024 + * Copyright 2024 Sandro Dias Pinto Vitenti + * + ****************************************************************************/ +/* + * nc_hipert_em.h + * Copyright (C) 2024 Sandro Dias Pinto Vitenti + * + * numcosmo is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * numcosmo is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef _NC_HIPERT_EM_H_ +#define _NC_HIPERT_EM_H_ + +#include +#include +#include +#include +#include +#include + +G_BEGIN_DECLS + +#define NC_TYPE_HIPERT_IEM (nc_hipert_iem_get_type ()) +#define NC_TYPE_HIPERT_EM (nc_hipert_em_get_type ()) + +G_DECLARE_INTERFACE (NcHIPertIEM, nc_hipert_iem, NC, HIPERT_IEM, GObject) +G_DECLARE_FINAL_TYPE (NcHIPertEM, nc_hipert_em, NC, HIPERT_EM, NcmCSQ1D) + +struct _NcHIPertIEMInterface +{ + /*< private >*/ + GTypeInterface parent; + gdouble (*eval_xi) (NcHIPertIEM *iem, const gdouble tau, const gdouble k); + gdouble (*eval_F1) (NcHIPertIEM *iem, const gdouble tau, const gdouble k); + gdouble (*eval_nu) (NcHIPertIEM *iem, const gdouble tau, const gdouble k); + gdouble (*eval_m) (NcHIPertIEM *iem, const gdouble tau, const gdouble k); + gdouble (*eval_unit) (NcHIPertIEM *iem); + gdouble (*eval_x) (NcHIPertIEM *iem, const gdouble tau); + gdouble (*eval_lapse) (NcHIPertIEM *iem, const gdouble tau); + + /* Padding to allow 18 virtual functions without breaking ABI. */ + gpointer padding[11]; +}; + +/** + * NcHIPertEMVars: + * @NC_HIPERT_EM_RE_H: $\text{Re}(\zeta)$ + * @NC_HIPERT_EM_IM_H: $\text{Im}(\zeta)$ + * @NC_HIPERT_EM_RE_PH: $\text{Re}(P_\zeta)$ + * @NC_HIPERT_EM_IM_PH: $\text{Im}(P_\zeta)$ + * + * Perturbation variables enumerator. + * + */ +typedef enum /*< enum,underscore_name=NC_HIPERT_EM_VARS >*/ +{ + NC_HIPERT_EM_RE_H = 0, + NC_HIPERT_EM_IM_H, + NC_HIPERT_EM_RE_PH, + NC_HIPERT_EM_IM_PH, +} NcHIPertEMVars; + + +gdouble nc_hipert_iem_eval_xi (NcHIPertIEM *iem, const gdouble tau, const gdouble k); +gdouble nc_hipert_iem_eval_F1 (NcHIPertIEM *iem, const gdouble tau, const gdouble k); +gdouble nc_hipert_iem_eval_nu (NcHIPertIEM *iem, const gdouble tau, const gdouble k); +gdouble nc_hipert_iem_eval_m (NcHIPertIEM *iem, const gdouble tau, const gdouble k); +gdouble nc_hipert_iem_eval_unit (NcHIPertIEM *iem); +gdouble nc_hipert_iem_eval_x (NcHIPertIEM *iem, const gdouble tau); + +NcHIPertEM *nc_hipert_em_new (void); +NcHIPertEM *nc_hipert_em_ref (NcHIPertEM *pem); +void nc_hipert_em_free (NcHIPertEM *pem); +void nc_hipert_em_clear (NcHIPertEM **pem); + +void nc_hipert_em_set_k (NcHIPertEM *pem, const gdouble k); +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); + +G_END_DECLS + +#endif /* _NC_HIPERT_EM_H_ */ + diff --git a/numcosmo/perturbations/nc_hipert_gw.c b/numcosmo/perturbations/nc_hipert_gw.c index eedaf30b4..7099fcdda 100644 --- a/numcosmo/perturbations/nc_hipert_gw.c +++ b/numcosmo/perturbations/nc_hipert_gw.c @@ -7,7 +7,7 @@ ****************************************************************************/ /* * nc_hipert_gw.c - * Copyright (C) 2014 Sandro Dias Pinto Vitenti + * Copyright (C) 2016 Sandro Dias Pinto Vitenti * * numcosmo is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -26,31 +26,11 @@ /** * SECTION:nc_hipert_gw * @title: NcHIPertGW - * @short_description: Perturbation object for gwatic mode only. + * @short_description: Perturbation object for gravitational wave mode. * - * This object provides the computation of the gwatic mode for the cosmological - * perturbations. It solves the equation of motion for the gauge invariant variable - * (see [Vitenti (2013)][XVitenti2013] for notation and details) - * $$\zeta \equiv \Psi - \frac{2\bar{K}}{\kappa(\bar{\rho} + \bar{p})} + H\mathcal{V}.$$ - * Its conjugated momentum is give by - * \begin{split} - * P_\zeta &= \frac{2\bar{D}^2_\bar{K}\Psi}{x^3H}, - * \end{split} - * - * The equations of motion in their first order form are - * \begin{align} - * \zeta^\prime &= \frac{P_\zeta}{m_\zeta}, \\\\ - * P_\zeta^\prime &= -m_\zeta\mu_\zeta^2\zeta. - * \end{align} - * The mass $m_\zeta$ and the frequency $\mu_\zeta$ are defined by - * \begin{align} - * m_\zeta &= \frac{3\Delta_\bar{K}(\bar{\rho} + \bar{p})}{\rho_\text{crit0} N x^3 c_s^2 E^2}, \\\\ - * \mu_\zeta^2 &= x^2N^2c_s^2k^2, - * \end{align} - * where $\bar{\rho} + \bar{p}$ is the background total energy density plus pressure, - * $E^2 = H^2/H_0^2$ is the dimensionless Hubble function squared (nc_hicosmo_E2()), $c_s^2$ the speed of sound, - * $N$ is the lapse function that in this case (using $\alpha$ as time variable) is $N \equiv \vert{}E\vert^{-1}$, $\rho_\text{crit0}$ - * is the critical density today defined by $\rho_\text{crit0} \equiv 3H_0^2/\kappa$ and $$\Delta_\bar{K} \equiv \frac{k^2}{k^2 + \Omega_{k0}}.$$ + * This object provides the computation of the gravitational wave mode for the + * cosmological perturbations. It solves the equation of motion for the gauge invariant + * variable $h$. * */ @@ -68,82 +48,85 @@ #include #endif /* NUMCOSMO_GIR_SCAN */ +struct _NcHIPertGW +{ + NcmCSQ1D parent_instance; + gdouble k; +}; + G_DEFINE_INTERFACE (NcHIPertIGW, nc_hipert_igw, G_TYPE_OBJECT) +G_DEFINE_TYPE (NcHIPertGW, nc_hipert_gw, NCM_TYPE_CSQ1D) -static guint _nc_hipert_igw_nsing (NcHIPertIGW *igw, const gdouble k) { return 0; } -static void _nc_hipert_igw_get_sing_info (NcHIPertIGW *igw, const gdouble k, const guint sing, gdouble *ts, gdouble *dts_i, gdouble *dts_f, NcmHOAASingType *st) { g_error ("_nc_hipert_igw_get_sing_info: no singularity implemented."); return; } -static gdouble _nc_hipert_igw_eval_sing_mnu (NcHIPertIGW *igw, const gdouble tau_m_taus, const gdouble k, const guint sing) { g_error ("_nc_hipert_igw_eval_sing_mnu: no singularity implemented."); return 0.0; } -static gdouble _nc_hipert_igw_eval_sing_dlnmnu (NcHIPertIGW *igw, const gdouble tau_m_taus, const gdouble k, const guint sing) { g_error ("_nc_hipert_igw_eval_sing_dlnmnu: no singularity implemented."); return 0.0; } -static void _nc_hipert_igw_eval_sing_system (NcHIPertIGW *igw, const gdouble tau_m_taus, const gdouble k, const guint sing, gdouble *nu, gdouble *dlnmnu) { g_error ("_nc_hipert_igw_eval_sing_system: no singularity implemented."); } -static gdouble _nc_hipert_igw_eval_powspec_factor (NcHIPertIGW *igw); +static gdouble _nc_hipert_igw_eval_unit (NcHIPertIGW *igw); static void nc_hipert_igw_default_init (NcHIPertIGWInterface *iface) { - iface->eval_mnu = NULL; - iface->eval_nu = NULL; - iface->eval_dlnmnu = NULL; - iface->eval_system = NULL; - - iface->nsing = &_nc_hipert_igw_nsing; - iface->get_sing_info = &_nc_hipert_igw_get_sing_info; - iface->eval_sing_mnu = &_nc_hipert_igw_eval_sing_mnu; - iface->eval_sing_dlnmnu = &_nc_hipert_igw_eval_sing_dlnmnu; - iface->eval_sing_system = &_nc_hipert_igw_eval_sing_system; - - iface->eval_powspec_factor = &_nc_hipert_igw_eval_powspec_factor; + iface->eval_xi = NULL; + iface->eval_F1 = NULL; + iface->eval_nu = NULL; + iface->eval_m = NULL; + iface->eval_unit = NULL; } -G_DEFINE_TYPE (NcHIPertGW, nc_hipert_gw, NCM_TYPE_HOAA) - -enum { +enum +{ PROP_0, + PROP_K, PROP_SIZE, }; typedef struct _NcHIPertGWArg { NcHICosmo *cosmo; - NcHIPertGW *pa; + NcHIPertGW *pgw; } NcHIPertGWArg; static void -nc_hipert_gw_init (NcHIPertGW *pa) +nc_hipert_gw_init (NcHIPertGW *pgw) { + pgw->k = 0.0; } static void _nc_hipert_gw_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { - /* NcHIPertGW *pa = NC_HIPERT_GW (object); */ + NcHIPertGW *pgw = NC_HIPERT_GW (object); + g_return_if_fail (NC_IS_HIPERT_GW (object)); switch (prop_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + case PROP_K: + nc_hipert_gw_set_k (pgw, g_value_get_double (value)); break; + default: /* LCOV_EXCL_LINE */ + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); /* LCOV_EXCL_LINE */ + break; /* LCOV_EXCL_LINE */ } } static void _nc_hipert_gw_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - /* NcHIPertGW *pa = NC_HIPERT_GW (object); */ + /* NcHIPertGW *pgw = NC_HIPERT_GW (object); */ g_return_if_fail (NC_IS_HIPERT_GW (object)); switch (prop_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + case PROP_K: + g_value_set_double (value, nc_hipert_gw_get_k (NC_HIPERT_GW (object))); break; + default: /* LCOV_EXCL_LINE */ + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); /* LCOV_EXCL_LINE */ + break; /* LCOV_EXCL_LINE */ } } static void _nc_hipert_gw_dispose (GObject *object) { - /*NcHIPertGW *pa = NC_HIPERT_GW (object);*/ + /*NcHIPertGW *pgw = NC_HIPERT_GW (object);*/ /* Chain up : end */ G_OBJECT_CLASS (nc_hipert_gw_parent_class)->dispose (object); @@ -152,208 +135,176 @@ _nc_hipert_gw_dispose (GObject *object) static void _nc_hipert_gw_finalize (GObject *object) { - /* Chain up : end */ G_OBJECT_CLASS (nc_hipert_gw_parent_class)->finalize (object); } -static gdouble _nc_hipert_gw_eval_mnu (NcmHOAA *hoaa, NcmModel *model, const gdouble t, const gdouble k); -static gdouble _nc_hipert_gw_eval_nu (NcmHOAA *hoaa, NcmModel *model, const gdouble t, const gdouble k); -static gdouble _nc_hipert_gw_eval_dlnmnu (NcmHOAA *hoaa, NcmModel *model, const gdouble t, const gdouble k); -static void _nc_hipert_gw_eval_system (NcmHOAA *hoaa, NcmModel *model, const gdouble t, const gdouble k, gdouble *nu, gdouble *dlnmnu, gdouble *Vnu); - -static guint _nc_hipert_gw_nsing (NcmHOAA *hoaa, NcmModel *model, const gdouble k); -static void _nc_hipert_gw_get_sing_info (NcmHOAA *hoaa, NcmModel *model, const gdouble k, const guint sing, gdouble *ts, gdouble *dts_i, gdouble *dts_f, NcmHOAASingType *st); -static gdouble _nc_hipert_gw_eval_sing_mnu (NcmHOAA *hoaa, NcmModel *model, const gdouble t_m_ts, const gdouble k, const guint sing); -static gdouble _nc_hipert_gw_eval_sing_dlnmnu (NcmHOAA *hoaa, NcmModel *model, const gdouble t_m_ts, const gdouble k, const guint sing); -static void _nc_hipert_gw_eval_sing_system (NcmHOAA *hoaa, NcmModel *model, const gdouble t_m_ts, const gdouble k, const guint sing, gdouble *nu, gdouble *dlnmnu, gdouble *Vnu); - -static gdouble _nc_hipert_adiab_eval_powspec_factor (NcmHOAA *hoaa, NcmModel *model); - -static void _nc_hipert_gw_prepare (NcmHOAA *hoaa, NcmModel *model); +static gdouble _nc_hipert_gw_eval_xi (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); +static gdouble _nc_hipert_gw_eval_F1 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); +static gdouble _nc_hipert_gw_eval_nu (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); +static gdouble _nc_hipert_gw_eval_m (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t); +static void _nc_hipert_gw_prepare (NcmCSQ1D *csq1d, NcmModel *model); static void nc_hipert_gw_class_init (NcHIPertGWClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - NcmHOAAClass *hoaa_class = NCM_HOAA_CLASS (klass); + NcmCSQ1DClass *csq1d_class = NCM_CSQ1D_CLASS (klass); object_class->set_property = &_nc_hipert_gw_set_property; object_class->get_property = &_nc_hipert_gw_get_property; object_class->dispose = &_nc_hipert_gw_dispose; object_class->finalize = &_nc_hipert_gw_finalize; - hoaa_class->eval_mnu = &_nc_hipert_gw_eval_mnu; - hoaa_class->eval_nu = &_nc_hipert_gw_eval_nu; - hoaa_class->eval_dlnmnu = &_nc_hipert_gw_eval_dlnmnu; - hoaa_class->eval_V = NULL; - hoaa_class->eval_system = &_nc_hipert_gw_eval_system; - hoaa_class->prepare = &_nc_hipert_gw_prepare; - - hoaa_class->nsing = &_nc_hipert_gw_nsing; - hoaa_class->get_sing_info = &_nc_hipert_gw_get_sing_info; - hoaa_class->eval_sing_mnu = &_nc_hipert_gw_eval_sing_mnu; - hoaa_class->eval_sing_dlnmnu = &_nc_hipert_gw_eval_sing_dlnmnu; - hoaa_class->eval_sing_V = NULL; - hoaa_class->eval_sing_system = &_nc_hipert_gw_eval_sing_system; - - hoaa_class->eval_powspec_factor = &_nc_hipert_adiab_eval_powspec_factor; -} - -static gdouble -_nc_hipert_gw_eval_mnu (NcmHOAA *hoaa, NcmModel *model, const gdouble t, const gdouble k) -{ - return nc_hipert_igw_eval_mnu (NC_HIPERT_IGW (model), t, k); -} - -static gdouble -_nc_hipert_gw_eval_nu (NcmHOAA *hoaa, NcmModel *model, const gdouble t, const gdouble k) -{ - return nc_hipert_igw_eval_nu (NC_HIPERT_IGW (model), t, k); + g_object_class_install_property (object_class, + PROP_K, + g_param_spec_double ("k", + NULL, + "Wave number", + 0.0, G_MAXDOUBLE, 1.0, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB)); + + csq1d_class->eval_xi = &_nc_hipert_gw_eval_xi; + csq1d_class->eval_F1 = &_nc_hipert_gw_eval_F1; + csq1d_class->eval_nu = &_nc_hipert_gw_eval_nu; + csq1d_class->eval_m = &_nc_hipert_gw_eval_m; + csq1d_class->prepare = &_nc_hipert_gw_prepare; } -static gdouble -_nc_hipert_gw_eval_dlnmnu (NcmHOAA *hoaa, NcmModel *model, const gdouble t, const gdouble k) +static gdouble +_nc_hipert_gw_eval_xi (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) { - return nc_hipert_igw_eval_dlnmnu (NC_HIPERT_IGW (model), t, k); -} + NcHIPertGW *pgw = NC_HIPERT_GW (csq1d); + const gdouble k = pgw->k; -static void -_nc_hipert_gw_eval_system (NcmHOAA *hoaa, NcmModel *model, const gdouble t, const gdouble k, gdouble *nu, gdouble *dlnmnu, gdouble *Vnu) -{ - Vnu[0] = 0.0; - nc_hipert_igw_eval_system (NC_HIPERT_IGW (model), t, k, nu, dlnmnu); + return nc_hipert_igw_eval_xi (NC_HIPERT_IGW (model), t, k); } -static void -_nc_hipert_gw_prepare (NcmHOAA *hoaa, NcmModel *model) +static gdouble +_nc_hipert_gw_eval_F1 (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) { - g_assert (NC_IS_HIPERT_IGW (model)); -} + NcHIPertGW *pgw = NC_HIPERT_GW (csq1d); + const gdouble k = pgw->k; -static guint -_nc_hipert_gw_nsing (NcmHOAA *hoaa, NcmModel *model, const gdouble k) -{ - return nc_hipert_igw_nsing (NC_HIPERT_IGW (model), k); + return nc_hipert_igw_eval_F1 (NC_HIPERT_IGW (model), t, k); } -static void -_nc_hipert_gw_get_sing_info (NcmHOAA *hoaa, NcmModel *model, const gdouble k, const guint sing, gdouble *ts, gdouble *dts_i, gdouble *dts_f, NcmHOAASingType *st) +static gdouble +_nc_hipert_gw_eval_nu (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) { - nc_hipert_igw_get_sing_info (NC_HIPERT_IGW (model), k, sing, ts, dts_i, dts_f, st); -} + NcHIPertGW *pgw = NC_HIPERT_GW (csq1d); + const gdouble k = pgw->k; -static gdouble -_nc_hipert_gw_eval_sing_mnu (NcmHOAA *hoaa, NcmModel *model, const gdouble t_m_ts, const gdouble k, const guint sing) -{ - return nc_hipert_igw_eval_sing_mnu (NC_HIPERT_IGW (model), t_m_ts, k, sing); + return nc_hipert_igw_eval_nu (NC_HIPERT_IGW (model), t, k); } -static gdouble -_nc_hipert_gw_eval_sing_dlnmnu (NcmHOAA *hoaa, NcmModel *model, const gdouble t_m_ts, const gdouble k, const guint sing) +static gdouble +_nc_hipert_gw_eval_m (NcmCSQ1D *csq1d, NcmModel *model, const gdouble t) { - return nc_hipert_igw_eval_sing_dlnmnu (NC_HIPERT_IGW (model), t_m_ts, k, sing); -} + NcHIPertGW *pgw = NC_HIPERT_GW (csq1d); + const gdouble k = pgw->k; -static void -_nc_hipert_gw_eval_sing_system (NcmHOAA *hoaa, NcmModel *model, const gdouble t_m_ts, const gdouble k, const guint sing, gdouble *nu, gdouble *dlnmnu, gdouble *Vnu) -{ - Vnu[0] = 0.0; - nc_hipert_igw_eval_sing_system (NC_HIPERT_IGW (model), t_m_ts, k, sing, nu, dlnmnu); + return nc_hipert_igw_eval_m (NC_HIPERT_IGW (model), t, k); } -static gdouble -_nc_hipert_adiab_eval_powspec_factor (NcmHOAA *hoaa, NcmModel *model) +static void +_nc_hipert_gw_prepare (NcmCSQ1D *csq1d, NcmModel *model) { - return nc_hipert_igw_eval_powspec_factor (NC_HIPERT_IGW (model)); -} - -static gdouble -_nc_hipert_igw_eval_powspec_factor (NcHIPertIGW *igw) -{ - g_assert (NC_IS_HICOSMO (igw)); - { - NcHICosmo *cosmo = NC_HICOSMO (igw); - const gdouble RH_lp = nc_hicosmo_RH_planck (cosmo); - return 16.0 / (M_PI * gsl_pow_2 (RH_lp)); - } + g_assert (NC_IS_HIPERT_IGW (model)); } /** - * nc_hipert_igw_eval_mnu: + * nc_hipert_igw_eval_xi: * @igw: a #NcHIPertIGW * @tau: $\tau$ * @k: $k$ * - * FIXME + * Computes the value of $\xi = \ln(m\nu)$ * - * Returns: FIXME. + * Returns: $\xi$. */ + +gdouble +nc_hipert_igw_eval_xi (NcHIPertIGW *igw, const gdouble tau, const gdouble k) +{ + return NC_HIPERT_IGW_GET_IFACE (igw)->eval_xi (igw, tau, k); +} + /** - * nc_hipert_igw_eval_nu: + * nc_hipert_igw_eval_F1: * @igw: a #NcHIPertIGW * @tau: $\tau$ * @k: $k$ * - * FIXME + * Computes the value of $F_1 = \dot{\xi}/(2\nu)$. * - * Returns: FIXME. + * Returns: $F_1$. */ + +gdouble +nc_hipert_igw_eval_F1 (NcHIPertIGW *igw, const gdouble tau, const gdouble k) +{ + return NC_HIPERT_IGW_GET_IFACE (igw)->eval_F1 (igw, tau, k); +} + /** - * nc_hipert_igw_eval_dlnmnu: + * nc_hipert_igw_eval_nu: * @igw: a #NcHIPertIGW * @tau: $\tau$ * @k: $k$ * - * FIXME + * Computes the value of $\nu$. * - * Returns: FIXME. + * Returns: $\nu$. */ +gdouble +nc_hipert_igw_eval_nu (NcHIPertIGW *igw, const gdouble tau, const gdouble k) +{ + return NC_HIPERT_IGW_GET_IFACE (igw)->eval_nu (igw, tau, k); +} + /** - * nc_hipert_igw_eval_system: + * nc_hipert_igw_eval_m: * @igw: a #NcHIPertIGW * @tau: $\tau$ * @k: $k$ - * @nu: (out): $\nu$ - * @dlnmnu: (out): FIXME - * - * FIXME - * - */ -/** - * nc_hipert_igw_eval_sing_mnu: - * @igw: a #NcHIPertIGW - * @tau_m_taus: $\tau - \tau_s$ - * @k: $k$ - * @sing: singularity index * - * FIXME + * Computes the value of $m$. * - * Returns: FIXME. + * Returns: $m$. */ +gdouble +nc_hipert_igw_eval_m (NcHIPertIGW *igw, const gdouble tau, const gdouble k) +{ + return NC_HIPERT_IGW_GET_IFACE (igw)->eval_m (igw, tau, k); +} + /** - * nc_hipert_igw_eval_sing_dlnmnu: + * nc_hipert_igw_eval_unit: * @igw: a #NcHIPertIGW - * @tau_m_taus: $\tau - \tau_s$ - * @k: $k$ - * @sing: singularity index * * FIXME * * Returns: FIXME. */ +gdouble +nc_hipert_igw_eval_unit (NcHIPertIGW *igw) +{ + return NC_HIPERT_IGW_GET_IFACE (igw)->eval_unit (igw); +} + /** - * nc_hipert_igw_eval_sing_system: + * nc_hipert_igw_eval_x: * @igw: a #NcHIPertIGW - * @tau_m_taus: $\tau - \tau_s$ - * @k: $k$ - * @sing: singularity index - * @nu: (out): FIXME - * @dlnmnu: (out): FIXME - * - * FIXME + * @tau: $\tau$ * + * Evaluates the value of $x = a_0 / a$ at a given time $\tau$. */ +gdouble +nc_hipert_igw_eval_x (NcHIPertIGW *igw, const gdouble tau) +{ + return NC_HIPERT_IGW_GET_IFACE (igw)->eval_x (igw, tau); +} /** * nc_hipert_gw_new: @@ -365,48 +316,77 @@ _nc_hipert_igw_eval_powspec_factor (NcHIPertIGW *igw) NcHIPertGW * nc_hipert_gw_new (void) { - NcHIPertGW *pa = g_object_new (NC_TYPE_HIPERT_GW, - "opt", NCM_HOAA_OPT_DLNMNU_ONLY, - NULL); - return pa; + NcHIPertGW *pgw = g_object_new (NC_TYPE_HIPERT_GW, + NULL); + + return pgw; } /** * nc_hipert_gw_ref: - * @pa: a #NcHIPertGW. + * @pgw: a #NcHIPertGW * - * Increases the reference count of @pa. + * Increases the reference count of @pgw. * - * Returns: (transfer full): @pa. + * Returns: (transfer full): @pgw. */ NcHIPertGW * -nc_hipert_gw_ref (NcHIPertGW *pa) +nc_hipert_gw_ref (NcHIPertGW *pgw) { - return g_object_ref (pa); + return g_object_ref (pgw); } /** * nc_hipert_gw_free: - * @pa: a #NcHIPertGW. + * @pgw: a #NcHIPertGW * - * Decreases the reference count of @pa. + * Decreases the reference count of @pgw. * */ void -nc_hipert_gw_free (NcHIPertGW *pa) +nc_hipert_gw_free (NcHIPertGW *pgw) { - g_object_unref (pa); + g_object_unref (pgw); } /** * nc_hipert_gw_clear: - * @pa: a #NcHIPertGW. + * @pgw: a #NcHIPertGW * - * Decreases the reference count of *@pa and sets *@pa to NULL. + * Decreases the reference count of *@pgw and sets *@pgw to NULL. * */ void -nc_hipert_gw_clear (NcHIPertGW **pa) +nc_hipert_gw_clear (NcHIPertGW **pgw) { - g_clear_object (pa); + g_clear_object (pgw); } + +/** + * nc_hipert_gw_set_k: + * @pgw: a #NcHIPertGW + * @k: the mode $k$ + * + * Sets the mode $k$ for the gravitational wave perturbation mode. + * + */ +void +nc_hipert_gw_set_k (NcHIPertGW *pgw, const gdouble k) +{ + pgw->k = k; +} + +/** + * nc_hipert_gw_get_k: + * @pgw: a #NcHIPertGW + * + * Returns the mode $k$ for the gravitational wave perturbation mode. + * + * Returns: the mode $k$. + */ +gdouble +nc_hipert_gw_get_k (NcHIPertGW *pgw) +{ + return pgw->k; +} + diff --git a/numcosmo/perturbations/nc_hipert_gw.h b/numcosmo/perturbations/nc_hipert_gw.h index c614f9a35..f8f10be64 100644 --- a/numcosmo/perturbations/nc_hipert_gw.h +++ b/numcosmo/perturbations/nc_hipert_gw.h @@ -13,12 +13,12 @@ * under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * numcosmo is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License along * with this program. If not, see . */ @@ -31,168 +31,66 @@ #include #include #include -#include +#include G_BEGIN_DECLS -#define NC_TYPE_HIPERT_IGW (nc_hipert_igw_get_type ()) -#define NC_HIPERT_IGW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NC_TYPE_HIPERT_IGW, NcHIPertIGW)) -#define NC_IS_HIPERT_IGW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NC_TYPE_HIPERT_IGW)) -#define NC_HIPERT_IGW_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), NC_TYPE_HIPERT_IGW, NcHIPertIGWInterface)) +#define NC_TYPE_HIPERT_IGW (nc_hipert_igw_get_type ()) +#define NC_TYPE_HIPERT_GW (nc_hipert_gw_get_type ()) -typedef struct _NcHIPertIGW NcHIPertIGW; -typedef struct _NcHIPertIGWInterface NcHIPertIGWInterface; +G_DECLARE_INTERFACE (NcHIPertIGW, nc_hipert_igw, NC, HIPERT_IGW, GObject) +G_DECLARE_FINAL_TYPE (NcHIPertGW, nc_hipert_gw, NC, HIPERT_GW, NcmCSQ1D) struct _NcHIPertIGWInterface { /*< private >*/ GTypeInterface parent; - gdouble (*eval_mnu) (NcHIPertIGW *igw, const gdouble tau, const gdouble k); + gdouble (*eval_xi) (NcHIPertIGW *igw, const gdouble tau, const gdouble k); + gdouble (*eval_F1) (NcHIPertIGW *igw, const gdouble tau, const gdouble k); gdouble (*eval_nu) (NcHIPertIGW *igw, const gdouble tau, const gdouble k); - gdouble (*eval_dlnmnu) (NcHIPertIGW *igw, const gdouble tau, const gdouble k); - void (*eval_system) (NcHIPertIGW *igw, const gdouble tau, const gdouble k, gdouble *nu, gdouble *dlnmnu); - guint (*nsing) (NcHIPertIGW *igw, const gdouble k); - void (*get_sing_info) (NcHIPertIGW *igw, const gdouble k, const guint sing, gdouble *ts, gdouble *dts_i, gdouble *dts_f, NcmHOAASingType *st); - gdouble (*eval_sing_mnu) (NcHIPertIGW *igw, const gdouble tau_m_taus, const gdouble k, const guint sing); - gdouble (*eval_sing_dlnmnu) (NcHIPertIGW *igw, const gdouble tau_m_taus, const gdouble k, const guint sing); - void (*eval_sing_system) (NcHIPertIGW *igw, const gdouble tau_m_taus, const gdouble k, const guint sing, gdouble *nu, gdouble *dlnmnu); - gdouble (*eval_powspec_factor) (NcHIPertIGW *igw); -}; + gdouble (*eval_m) (NcHIPertIGW *igw, const gdouble tau, const gdouble k); + gdouble (*eval_unit) (NcHIPertIGW *igw); + gdouble (*eval_x) (NcHIPertIGW *igw, const gdouble tau); -#define NC_TYPE_HIPERT_GW (nc_hipert_gw_get_type ()) -#define NC_HIPERT_GW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NC_TYPE_HIPERT_GW, NcHIPertGW)) -#define NC_HIPERT_GW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NC_TYPE_HIPERT_GW, NcHIPertGWClass)) -#define NC_IS_HIPERT_GW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NC_TYPE_HIPERT_GW)) -#define NC_IS_HIPERT_GW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NC_TYPE_HIPERT_GW)) -#define NC_HIPERT_GW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NC_TYPE_HIPERT_GW, NcHIPertGWClass)) - -typedef struct _NcHIPertGWClass NcHIPertGWClass; -typedef struct _NcHIPertGW NcHIPertGW; - -struct _NcHIPertGWClass -{ - /*< private >*/ - NcmHOAAClass parent_class; + /* Padding to allow 18 virtual functions without breaking ABI. */ + gpointer padding[12]; }; /** * NcHIPertGWVars: - * @NC_HIPERT_GW_RE_ZETA: $\text{Re}(\zeta)$ - * @NC_HIPERT_GW_IM_ZETA: $\text{Im}(\zeta)$ - * @NC_HIPERT_GW_RE_PZETA: $\text{Re}(P_\zeta)$ - * @NC_HIPERT_GW_IM_PZETA: $\text{Im}(P_\zeta)$ - * + * @NC_HIPERT_GW_RE_H: $\text{Re}(\zeta)$ + * @NC_HIPERT_GW_IM_H: $\text{Im}(\zeta)$ + * @NC_HIPERT_GW_RE_PH: $\text{Re}(P_\zeta)$ + * @NC_HIPERT_GW_IM_PH: $\text{Im}(P_\zeta)$ + * * Perturbation variables enumerator. - * + * */ typedef enum /*< enum,underscore_name=NC_HIPERT_GW_VARS >*/ { - NC_HIPERT_GW_RE_ZETA = 0, - NC_HIPERT_GW_IM_ZETA, - NC_HIPERT_GW_RE_PZETA, - NC_HIPERT_GW_IM_PZETA, + NC_HIPERT_GW_RE_H = 0, + NC_HIPERT_GW_IM_H, + NC_HIPERT_GW_RE_PH, + NC_HIPERT_GW_IM_PH, } NcHIPertGWVars; -struct _NcHIPertGW -{ - /*< private >*/ - NcmHOAA parent_instance; -}; - -GType nc_hipert_igw_get_type (void) G_GNUC_CONST; -GType nc_hipert_gw_get_type (void) G_GNUC_CONST; - -NCM_INLINE gdouble nc_hipert_igw_eval_mnu (NcHIPertIGW *igw, const gdouble tau, const gdouble k); -NCM_INLINE gdouble nc_hipert_igw_eval_nu (NcHIPertIGW *igw, const gdouble tau, const gdouble k); -NCM_INLINE gdouble nc_hipert_igw_eval_dlnmnu (NcHIPertIGW *igw, const gdouble tau, const gdouble k); -NCM_INLINE void nc_hipert_igw_eval_system (NcHIPertIGW *igw, const gdouble tau, const gdouble k, gdouble *nu, gdouble *dlnmnu); -NCM_INLINE guint nc_hipert_igw_nsing (NcHIPertIGW *igw, const gdouble k); -NCM_INLINE void nc_hipert_igw_get_sing_info (NcHIPertIGW *igw, const gdouble k, const guint sing, gdouble *ts, gdouble *dts_i, gdouble *dts_f, NcmHOAASingType *st); -NCM_INLINE gdouble nc_hipert_igw_eval_sing_mnu (NcHIPertIGW *igw, const gdouble tau_m_taus, const gdouble k, const guint sing); -NCM_INLINE gdouble nc_hipert_igw_eval_sing_dlnmnu (NcHIPertIGW *igw, const gdouble tau_m_taus, const gdouble k, const guint sing); -NCM_INLINE void nc_hipert_igw_eval_sing_system (NcHIPertIGW *igw, const gdouble tau_m_taus, const gdouble k, const guint sing, gdouble *nu, gdouble *dlnmnu); - -NCM_INLINE gdouble nc_hipert_igw_eval_powspec_factor (NcHIPertIGW *igw); +gdouble nc_hipert_igw_eval_xi (NcHIPertIGW *igw, const gdouble tau, const gdouble k); +gdouble nc_hipert_igw_eval_F1 (NcHIPertIGW *igw, const gdouble tau, const gdouble k); +gdouble nc_hipert_igw_eval_nu (NcHIPertIGW *igw, const gdouble tau, const gdouble k); +gdouble nc_hipert_igw_eval_m (NcHIPertIGW *igw, const gdouble tau, const gdouble k); +gdouble nc_hipert_igw_eval_unit (NcHIPertIGW *igw); +gdouble nc_hipert_igw_eval_x (NcHIPertIGW *igw, const gdouble tau); NcHIPertGW *nc_hipert_gw_new (void); -NcHIPertGW *nc_hipert_gw_ref (NcHIPertGW *pa); -void nc_hipert_gw_free (NcHIPertGW *pa); -void nc_hipert_gw_clear (NcHIPertGW **pa); +NcHIPertGW *nc_hipert_gw_ref (NcHIPertGW *pgw); +void nc_hipert_gw_free (NcHIPertGW *pgw); +void nc_hipert_gw_clear (NcHIPertGW **pgw); + +void nc_hipert_gw_set_k (NcHIPertGW *pgw, const gdouble k); +gdouble nc_hipert_gw_get_k (NcHIPertGW *pgw); G_END_DECLS #endif /* _NC_HIPERT_GW_H_ */ -#ifndef _NC_HIPERT_GW_INLINE_H_ -#define _NC_HIPERT_GW_INLINE_H_ -#ifdef NUMCOSMO_HAVE_INLINE -#ifndef __GTK_DOC_IGNORE__ - -G_BEGIN_DECLS - -NCM_INLINE gdouble -nc_hipert_igw_eval_mnu (NcHIPertIGW *igw, const gdouble tau, const gdouble k) -{ - return NC_HIPERT_IGW_GET_INTERFACE (igw)->eval_mnu (igw, tau, k); -} - -NCM_INLINE gdouble -nc_hipert_igw_eval_nu (NcHIPertIGW *igw, const gdouble tau, const gdouble k) -{ - return NC_HIPERT_IGW_GET_INTERFACE (igw)->eval_nu (igw, tau, k); -} - -NCM_INLINE gdouble -nc_hipert_igw_eval_dlnmnu (NcHIPertIGW *igw, const gdouble tau, const gdouble k) -{ - return NC_HIPERT_IGW_GET_INTERFACE (igw)->eval_dlnmnu (igw, tau, k); -} - -NCM_INLINE void -nc_hipert_igw_eval_system (NcHIPertIGW *igw, const gdouble tau, const gdouble k, gdouble *nu, gdouble *dlnmnu) -{ - NC_HIPERT_IGW_GET_INTERFACE (igw)->eval_system (igw, tau, k, nu, dlnmnu); -} - -NCM_INLINE guint -nc_hipert_igw_nsing (NcHIPertIGW *igw, const gdouble k) -{ - return NC_HIPERT_IGW_GET_INTERFACE (igw)->nsing (igw, k); -} - -NCM_INLINE void -nc_hipert_igw_get_sing_info (NcHIPertIGW *igw, const gdouble k, const guint sing, gdouble *ts, gdouble *dts_i, gdouble *dts_f, NcmHOAASingType *st) -{ - NC_HIPERT_IGW_GET_INTERFACE (igw)->get_sing_info (igw, k, sing, ts, dts_i, dts_f, st); -} - -NCM_INLINE gdouble -nc_hipert_igw_eval_sing_mnu (NcHIPertIGW *igw, const gdouble tau_m_taus, const gdouble k, const guint sing) -{ - return NC_HIPERT_IGW_GET_INTERFACE (igw)->eval_sing_mnu (igw, tau_m_taus, k, sing); -} - -NCM_INLINE gdouble -nc_hipert_igw_eval_sing_dlnmnu (NcHIPertIGW *igw, const gdouble tau_m_taus, const gdouble k, const guint sing) -{ - return NC_HIPERT_IGW_GET_INTERFACE (igw)->eval_sing_dlnmnu (igw, tau_m_taus, k, sing); -} - -NCM_INLINE void -nc_hipert_igw_eval_sing_system (NcHIPertIGW *igw, const gdouble tau_m_taus, const gdouble k, const guint sing, gdouble *nu, gdouble *dlnmnu) -{ - NC_HIPERT_IGW_GET_INTERFACE (igw)->eval_sing_system (igw, tau_m_taus, k, sing, nu, dlnmnu); -} - -NCM_INLINE gdouble -nc_hipert_igw_eval_powspec_factor (NcHIPertIGW *igw) -{ - return NC_HIPERT_IGW_GET_INTERFACE (igw)->eval_powspec_factor (igw); -} - -G_END_DECLS - -#endif /* __GTK_DOC_IGNORE__ */ -#endif /* NUMCOSMO_HAVE_INLINE */ -#endif /* _NC_HIPERT_GW_INLINE_H_ */ diff --git a/numcosmo_py/datasets/no_perturbations.py b/numcosmo_py/datasets/no_perturbations.py index 6812f4ea5..4b45fc980 100644 --- a/numcosmo_py/datasets/no_perturbations.py +++ b/numcosmo_py/datasets/no_perturbations.py @@ -22,8 +22,10 @@ # with this program. If not, see . -"""Factory functions to generate cosmology likelihoods that do -not depend on perturbations. +"""Factory functions to generate background cosmology likelihoods. + +This module contains factory functions to generate likelihoods for +cosmology observables that do not involve perturbations. """ from enum import Enum @@ -62,7 +64,6 @@ def gen_snia_likelihood( snia_id: SNIaID = SNIaID.COV_PANTHEON_PLUS_SH0ES_SYS_STAT, ) -> None: """Generate a likelihood for SNIa data.""" - assert modelset.peek(Nc.HICosmo.id()) is not None snia_data = Nc.DataSNIACov.new_from_cat_id(snia_id.genum, False) @@ -84,7 +85,6 @@ def gen_bao_likelihood( bao_id: BAOID = BAOID.ALL_COMBINED_JAN_2023, ) -> None: """Generate a likelihood for BAO data.""" - assert modelset.peek(Nc.HICosmo.id()) is not None if bao_id == BAOID.ALL_COMBINED_JAN_2023: @@ -111,7 +111,6 @@ def gen_h_likelihood( h_id: HID = HID.ALL_COMBINED_JAN_2023, ) -> None: """Generate a likelihood for Hubble data.""" - assert modelset.peek(Nc.HICosmo.id()) is not None if h_id == HID.ALL_COMBINED_JAN_2023: diff --git a/numcosmo_py/experiments/planck18.py b/numcosmo_py/experiments/planck18.py index 40a63ba73..8497323da 100644 --- a/numcosmo_py/experiments/planck18.py +++ b/numcosmo_py/experiments/planck18.py @@ -172,9 +172,7 @@ def generate_planck18_tt( massive_nu: bool = False, ) -> tuple[Ncm.ObjDictStr, Ncm.ObjArray]: """Generate Planck 2018 TT baseline experiment dictionary.""" - # Likelihood - cbe_boltzmann = Nc.HIPertBoltzmannCBE.new() b18_lowl_EE = Nc.DataPlanckLKL.full_new_id( @@ -219,9 +217,7 @@ def generate_planck18_ttteee( massive_nu: bool = False, ) -> tuple[Ncm.ObjDictStr, Ncm.ObjArray]: """Generate Planck 2018 TT baseline experiment dictionary.""" - # Likelihood - cbe_boltzmann = Nc.HIPertBoltzmannCBE.new() b18_lowl_EE = Nc.DataPlanckLKL.full_new_id( diff --git a/numcosmo_py/nc.pyi b/numcosmo_py/nc.pyi index 6791ba2b7..dd0584ea2 100644 --- a/numcosmo_py/nc.pyi +++ b/numcosmo_py/nc.pyi @@ -121,6 +121,9 @@ HICOSMO_QGRW_DEFAULT_OMEGA_R: float = 1e-05 HICOSMO_QGRW_DEFAULT_OMEGA_W: int = 0 HICOSMO_QGRW_DEFAULT_W: float = 1e-12 HICOSMO_QGRW_DEFAULT_X_B: float = 1e30 +HICOSMO_QGW_DEFAULT_OMEGA_W: float = 1.0 +HICOSMO_QGW_DEFAULT_W: float = 1e-05 +HICOSMO_QGW_DEFAULT_X_B: float = 1e30 HICOSMO_QLINEAR_DEFAULT_CD: float = 0.0 HICOSMO_QLINEAR_DEFAULT_E: float = 1.0 HICOSMO_QLINEAR_DEFAULT_OMEGA_T: float = 1.0 @@ -145,6 +148,8 @@ HICOSMO_VEXP_DEBUG_EVOL_CL: bool = False HICOSMO_VEXP_DEBUG_EVOL_QT: bool = False HICOSMO_VEXP_DEFAULT_ALPHA_B: float = 0.1 HICOSMO_VEXP_DEFAULT_D_PHI: float = 0.3 +HICOSMO_VEXP_DEFAULT_EM_B: float = 0.0 +HICOSMO_VEXP_DEFAULT_EM_BETA: float = 0.1 HICOSMO_VEXP_DEFAULT_H0: float = 70.0 HICOSMO_VEXP_DEFAULT_OMEGA_C: float = 0.25 HICOSMO_VEXP_DEFAULT_OMEGA_L: float = 0.75 @@ -3311,14 +3316,14 @@ class DECont(NumCosmoMath.CSQ1D): c_s^2 w -> gdouble: w w + k -> gdouble: k + k Properties from NcmCSQ1D: reltol -> gdouble: reltol Relative tolerance abstol -> gdouble: abstol Absolute tolerance tolerance - k -> gdouble: k - Mode k ti -> gdouble: ti The initial time t_i tf -> gdouble: tf @@ -3329,8 +3334,12 @@ class DECont(NumCosmoMath.CSQ1D): The propagator threshold save-evol -> gboolean: save-evol Save the system evolution - max-order-2 -> gboolean: max-order-2 - Whether to always truncate at order 2 + vacuum-type -> NcmCSQ1DInitialStateType: vacuum-type + The vacuum type + vacuum-reltol -> gdouble: vacuum-reltol + The vacuum relative tolerance + vacuum-max-time -> gdouble: vacuum-max-time + The vacuum maximum time Signals from GObject: notify (GParam) @@ -3340,42 +3349,46 @@ class DECont(NumCosmoMath.CSQ1D): OmegaL: float Omegaw: float cs2: float + k: float w: float abstol: float adiab_threshold: float - k: float - max_order_2: bool prop_threshold: float reltol: float save_evol: bool tf: float ti: float + vacuum_max_time: float + vacuum_reltol: float + vacuum_type: NumCosmoMath.CSQ1DInitialStateType props: Props = ... - parent_instance: NumCosmoMath.CSQ1D = ... - priv: DEContPrivate = ... def __init__( self, OmegaL: float = ..., Omegaw: float = ..., cs2: float = ..., + k: float = ..., w: float = ..., abstol: float = ..., adiab_threshold: float = ..., - k: float = ..., - max_order_2: bool = ..., prop_threshold: float = ..., reltol: float = ..., save_evol: bool = ..., tf: float = ..., ti: float = ..., + vacuum_max_time: float = ..., + vacuum_reltol: float = ..., + vacuum_type: NumCosmoMath.CSQ1DInitialStateType = ..., ): ... @staticmethod def clear(dec: DECont) -> None: ... def free(self) -> None: ... + def get_k(self) -> float: ... @classmethod def new(cls, Omegaw: float, OmegaL: float, cs2: float, w: float) -> DECont: ... def ref(self) -> DECont: ... + def set_k(self, k: float) -> None: ... class DEContClass(GObject.GPointer): r""" @@ -3388,8 +3401,6 @@ class DEContClass(GObject.GPointer): parent_class: NumCosmoMath.CSQ1DClass = ... -class DEContPrivate(GObject.GPointer): ... - class DataBaoA(NumCosmoMath.DataGaussDiag): r""" :Constructors: @@ -8885,6 +8896,111 @@ class HICosmoQGRWClass(GObject.GPointer): parent_class: HICosmoClass = ... +class HICosmoQGW(HICosmo, HIPertIAdiab): + r""" + :Constructors: + + :: + + HICosmoQGW(**properties) + new() -> NumCosmo.HICosmoQGW + + Object NcHICosmoQGW + + Properties from NcHICosmoQGW: + H0 -> gdouble: H0 + H_0 + Omegaw -> gdouble: Omegaw + \Omega_{w0} + w -> gdouble: w + w + xb -> gdouble: xb + x_b + H0-fit -> gboolean: H0-fit + H_0:fit + Omegaw-fit -> gboolean: Omegaw-fit + \Omega_{w0}:fit + w-fit -> gboolean: w-fit + w:fit + xb-fit -> gboolean: xb-fit + x_b:fit + + Properties from NcmModel: + name -> gchararray: name + Model's name + nick -> gchararray: nick + Model's nick + scalar-params-len -> guint: scalar-params-len + Number of scalar parameters + vector-params-len -> guint: vector-params-len + Number of vector parameters + implementation -> guint64: implementation + Bitwise specification of functions implementation + sparam-array -> NcmObjDictInt: sparam-array + NcmModel array of NcmSParam + params-types -> GArray: params-types + Parameters' types + reparam -> NcmReparam: reparam + Model reparametrization + submodel-array -> NcmObjArray: submodel-array + NcmModel array of submodels + + Signals from GObject: + notify (GParam) + """ + + class Props: + H0: float + H0_fit: bool + Omegaw: float + Omegaw_fit: bool + w: float + w_fit: bool + xb: float + xb_fit: bool + implementation: int + name: str + nick: str + params_types: list[None] + reparam: NumCosmoMath.Reparam + scalar_params_len: int + sparam_array: NumCosmoMath.ObjDictInt + submodel_array: NumCosmoMath.ObjArray + vector_params_len: int + + props: Props = ... + parent_instance: HICosmo = ... + priv: HICosmoQGWPrivate = ... + def __init__( + self, + H0: float = ..., + H0_fit: bool = ..., + Omegaw: float = ..., + Omegaw_fit: bool = ..., + w: float = ..., + w_fit: bool = ..., + xb: float = ..., + xb_fit: bool = ..., + reparam: NumCosmoMath.Reparam = ..., + sparam_array: NumCosmoMath.ObjDictInt = ..., + submodel_array: NumCosmoMath.ObjArray = ..., + ): ... + @classmethod + def new(cls) -> HICosmoQGW: ... + +class HICosmoQGWClass(GObject.GPointer): + r""" + :Constructors: + + :: + + HICosmoQGWClass() + """ + + parent_class: HICosmoClass = ... + +class HICosmoQGWPrivate(GObject.GPointer): ... + class HICosmoQLinear(HICosmo): r""" :Constructors: @@ -9426,7 +9542,7 @@ class HICosmoQSplineContPriorClass(GObject.GPointer): parent_class: NumCosmoMath.ModelClass = ... -class HICosmoVexp(HICosmo, HIPertIAdiab, HIPertIGW): +class HICosmoVexp(HICosmo, HIPertIAdiab, HIPertIEM, HIPertIGW): r""" :Constructors: @@ -9442,6 +9558,8 @@ class HICosmoVexp(HICosmo, HIPertIAdiab, HIPertIGW): Whether to glue to a DE phase set-xb-max -> gboolean: set-xb-max Whether to use max xb allowed by the matching + em-coupling -> NcHICosmoVexpEMCoupling: em-coupling + Electromagnetic coupling H0 -> gdouble: H0 H_0 Omegac -> gdouble: Omegac @@ -9456,6 +9574,10 @@ class HICosmoVexp(HICosmo, HIPertIAdiab, HIPertIGW): \alpha_b xb -> gdouble: xb x_b + Bem -> gdouble: Bem + B_\mathrm{em} + betaem -> gdouble: betaem + \beta_\mathrm{em} H0-fit -> gboolean: H0-fit H_0:fit Omegac-fit -> gboolean: Omegac-fit @@ -9470,6 +9592,10 @@ class HICosmoVexp(HICosmo, HIPertIAdiab, HIPertIGW): \alpha_b:fit xb-fit -> gboolean: xb-fit x_b:fit + Bem-fit -> gboolean: Bem-fit + B_\mathrm{em}:fit + betaem-fit -> gboolean: betaem-fit + \beta_\mathrm{em}:fit Properties from NcmModel: name -> gchararray: name @@ -9496,6 +9622,8 @@ class HICosmoVexp(HICosmo, HIPertIAdiab, HIPertIGW): """ class Props: + Bem: float + Bem_fit: bool H0: float H0_fit: bool OmegaL: float @@ -9504,8 +9632,11 @@ class HICosmoVexp(HICosmo, HIPertIAdiab, HIPertIGW): Omegac_fit: bool alphab: float alphab_fit: bool + betaem: float + betaem_fit: bool dphi: float dphi_fit: bool + em_coupling: HICosmoVexpEMCoupling glue_de: bool set_xb_max: bool sigmaphi: float @@ -9527,6 +9658,8 @@ class HICosmoVexp(HICosmo, HIPertIAdiab, HIPertIGW): priv: HICosmoVexpPrivate = ... def __init__( self, + Bem: float = ..., + Bem_fit: bool = ..., H0: float = ..., H0_fit: bool = ..., OmegaL: float = ..., @@ -9535,8 +9668,11 @@ class HICosmoVexp(HICosmo, HIPertIAdiab, HIPertIGW): Omegac_fit: bool = ..., alphab: float = ..., alphab_fit: bool = ..., + betaem: float = ..., + betaem_fit: bool = ..., dphi: float = ..., dphi_fit: bool = ..., + em_coupling: HICosmoVexpEMCoupling = ..., glue_de: bool = ..., set_xb_max: bool = ..., sigmaphi: float = ..., @@ -9547,32 +9683,27 @@ class HICosmoVexp(HICosmo, HIPertIAdiab, HIPertIGW): sparam_array: NumCosmoMath.ObjDictInt = ..., submodel_array: NumCosmoMath.ObjArray = ..., ): ... + def E_tau(self, tau: float) -> float: ... def Ricci_scale(self, tau: float) -> float: ... def alpha(self, tau: float) -> float: ... def alpha_0c(self) -> float: ... def alpha_0e(self) -> float: ... - def cauchy_eval_F(self, tau: float, k: float, B: float, beta: float) -> float: ... - def cauchy_eval_F1(self, tau: float, k: float, B: float, beta: float) -> float: ... - def cauchy_eval_m(self, tau: float, B: float, beta: float) -> float: ... - def cauchy_eval_xi(self, tau: float, k: float, B: float, beta: float) -> float: ... - def eval_F(self, tau: float, k: float, B: float, beta: float) -> float: ... - def eval_nu(self, tau: float, k: float) -> float: ... - def gauss_eval_F1(self, tau: float, k: float, B: float, beta: float) -> float: ... - def gauss_eval_m(self, tau: float, B: float, beta: float) -> float: ... - def gauss_eval_xi(self, tau: float, k: float, B: float, beta: float) -> float: ... + def get_em_coupling(self) -> HICosmoVexpEMCoupling: ... @classmethod def new(cls) -> HICosmoVexp: ... def phi(self, tau: float) -> float: ... + def set_em_coupling(self, coupling: HICosmoVexpEMCoupling) -> None: ... def tau_max(self) -> float: ... def tau_min(self) -> float: ... def tau_qt_c(self) -> float: ... def tau_qt_e(self) -> float: ... def tau_xc(self, xc: float) -> float: ... def tau_xe(self, xe: float) -> float: ... - def x_tau(self, tau: float) -> float: ... def x_y(self, tau: float) -> Tuple[float, float]: ... def xbc(self) -> float: ... def xbe(self) -> float: ... + def xc_tau(self, tau: float) -> float: ... + def xe_tau(self, tau: float) -> float: ... class HICosmoVexpClass(GObject.GPointer): r""" @@ -9646,7 +9777,7 @@ class HIPert(GObject.Object): def set_stiff_solver(self, stiff: bool) -> None: ... def set_sys_size(self, sys_size: int) -> None: ... -class HIPertAdiab(NumCosmoMath.HOAA): +class HIPertAdiab(NumCosmoMath.CSQ1D): r""" :Constructors: @@ -9657,53 +9788,92 @@ class HIPertAdiab(NumCosmoMath.HOAA): Object NcHIPertAdiab - Properties from NcmHOAA: + Properties from NcHIPertAdiab: + k -> gdouble: k + Wave number + + Properties from NcmCSQ1D: reltol -> gdouble: reltol Relative tolerance abstol -> gdouble: abstol Absolute tolerance tolerance - k -> gdouble: k - The mode k ti -> gdouble: ti The initial time t_i tf -> gdouble: tf The final time t_f + adiab-threshold -> gdouble: adiab-threshold + The adiabatic threshold + prop-threshold -> gdouble: prop-threshold + The propagator threshold save-evol -> gboolean: save-evol Save the system evolution - opt -> NcmHOAAOpt: opt - Evolution options + vacuum-type -> NcmCSQ1DInitialStateType: vacuum-type + The vacuum type + vacuum-reltol -> gdouble: vacuum-reltol + The vacuum relative tolerance + vacuum-max-time -> gdouble: vacuum-max-time + The vacuum maximum time Signals from GObject: notify (GParam) """ class Props: - abstol: float k: float - opt: NumCosmoMath.HOAAOpt + abstol: float + adiab_threshold: float + prop_threshold: float reltol: float save_evol: bool tf: float ti: float + vacuum_max_time: float + vacuum_reltol: float + vacuum_type: NumCosmoMath.CSQ1DInitialStateType props: Props = ... - parent_instance: NumCosmoMath.HOAA = ... def __init__( self, - abstol: float = ..., k: float = ..., - opt: NumCosmoMath.HOAAOpt = ..., + abstol: float = ..., + adiab_threshold: float = ..., + prop_threshold: float = ..., reltol: float = ..., save_evol: bool = ..., tf: float = ..., ti: float = ..., + vacuum_max_time: float = ..., + vacuum_reltol: float = ..., + vacuum_type: NumCosmoMath.CSQ1DInitialStateType = ..., ): ... @staticmethod def clear(pa: HIPertAdiab) -> None: ... + def eval_cosmic_time(self, model: NumCosmoMath.Model, tau: float) -> float: ... + def eval_delta_critial(self, model: NumCosmoMath.Model, tau: float) -> float: ... + def eval_powspec_Psi( + self, model: NumCosmoMath.Model + ) -> NumCosmoMath.PowspecSpline2d: ... + def eval_powspec_Psi_at(self, model: NumCosmoMath.Model, tau: float) -> float: ... + def eval_powspec_drho( + self, model: NumCosmoMath.Model + ) -> NumCosmoMath.PowspecSpline2d: ... + def eval_powspec_drho_at(self, model: NumCosmoMath.Model, tau: float) -> float: ... + def eval_powspec_zeta( + self, model: NumCosmoMath.Model + ) -> NumCosmoMath.PowspecSpline2d: ... + def eval_powspec_zeta_at(self, model: NumCosmoMath.Model, tau: float) -> float: ... def free(self) -> None: ... + def get_k(self) -> float: ... @classmethod def new(cls) -> HIPertAdiab: ... + def prepare_spectrum( + self, + model: NumCosmoMath.Model, + k_array: Sequence[float], + tau_array: Sequence[float], + ) -> None: ... def ref(self) -> HIPertAdiab: ... + def set_k(self, k: float) -> None: ... class HIPertAdiabClass(GObject.GPointer): r""" @@ -9714,7 +9884,7 @@ class HIPertAdiabClass(GObject.GPointer): HIPertAdiabClass() """ - parent_class: NumCosmoMath.HOAAClass = ... + parent_class: NumCosmoMath.CSQ1DClass = ... class HIPertBGVar(GObject.Object): r""" @@ -10478,6 +10648,98 @@ class HIPertCompPBClass(GObject.GPointer): class HIPertCompPBPrivate(GObject.GPointer): ... class HIPertCompPrivate(GObject.GPointer): ... +class HIPertEM(NumCosmoMath.CSQ1D): + r""" + :Constructors: + + :: + + HIPertEM(**properties) + new() -> NumCosmo.HIPertEM + + Object NcHIPertEM + + Properties from NcHIPertEM: + k -> gdouble: k + Wave number + + Properties from NcmCSQ1D: + reltol -> gdouble: reltol + Relative tolerance + abstol -> gdouble: abstol + Absolute tolerance tolerance + ti -> gdouble: ti + The initial time t_i + tf -> gdouble: tf + The final time t_f + adiab-threshold -> gdouble: adiab-threshold + The adiabatic threshold + prop-threshold -> gdouble: prop-threshold + The propagator threshold + save-evol -> gboolean: save-evol + Save the system evolution + vacuum-type -> NcmCSQ1DInitialStateType: vacuum-type + The vacuum type + vacuum-reltol -> gdouble: vacuum-reltol + The vacuum relative tolerance + vacuum-max-time -> gdouble: vacuum-max-time + The vacuum maximum time + + Signals from GObject: + notify (GParam) + """ + + class Props: + k: float + abstol: float + adiab_threshold: float + prop_threshold: float + reltol: float + save_evol: bool + tf: float + ti: float + vacuum_max_time: float + vacuum_reltol: float + vacuum_type: NumCosmoMath.CSQ1DInitialStateType + + props: Props = ... + def __init__( + self, + k: float = ..., + abstol: float = ..., + adiab_threshold: float = ..., + prop_threshold: float = ..., + reltol: float = ..., + save_evol: bool = ..., + tf: float = ..., + ti: float = ..., + vacuum_max_time: float = ..., + vacuum_reltol: float = ..., + vacuum_type: NumCosmoMath.CSQ1DInitialStateType = ..., + ): ... + @staticmethod + def clear(pem: HIPertEM) -> None: ... + def eval_PE_PB( + self, model: NumCosmoMath.Model, tau: float + ) -> Tuple[float, float]: ... + def free(self) -> None: ... + def get_k(self) -> float: ... + @classmethod + def new(cls) -> HIPertEM: ... + def ref(self) -> HIPertEM: ... + def set_k(self, k: float) -> None: ... + +class HIPertEMClass(GObject.GPointer): + r""" + :Constructors: + + :: + + HIPertEMClass() + """ + + parent_class: NumCosmoMath.CSQ1DClass = ... + class HIPertFirstOrder(HIPertBoltzmann): r""" :Constructors: @@ -10643,7 +10905,7 @@ class HIPertFirstOrderClass(GObject.GPointer): class HIPertFirstOrderPrivate(GObject.GPointer): ... -class HIPertGW(NumCosmoMath.HOAA): +class HIPertGW(NumCosmoMath.CSQ1D): r""" :Constructors: @@ -10654,53 +10916,72 @@ class HIPertGW(NumCosmoMath.HOAA): Object NcHIPertGW - Properties from NcmHOAA: + Properties from NcHIPertGW: + k -> gdouble: k + Wave number + + Properties from NcmCSQ1D: reltol -> gdouble: reltol Relative tolerance abstol -> gdouble: abstol Absolute tolerance tolerance - k -> gdouble: k - The mode k ti -> gdouble: ti The initial time t_i tf -> gdouble: tf The final time t_f + adiab-threshold -> gdouble: adiab-threshold + The adiabatic threshold + prop-threshold -> gdouble: prop-threshold + The propagator threshold save-evol -> gboolean: save-evol Save the system evolution - opt -> NcmHOAAOpt: opt - Evolution options + vacuum-type -> NcmCSQ1DInitialStateType: vacuum-type + The vacuum type + vacuum-reltol -> gdouble: vacuum-reltol + The vacuum relative tolerance + vacuum-max-time -> gdouble: vacuum-max-time + The vacuum maximum time Signals from GObject: notify (GParam) """ class Props: - abstol: float k: float - opt: NumCosmoMath.HOAAOpt + abstol: float + adiab_threshold: float + prop_threshold: float reltol: float save_evol: bool tf: float ti: float + vacuum_max_time: float + vacuum_reltol: float + vacuum_type: NumCosmoMath.CSQ1DInitialStateType props: Props = ... - parent_instance: NumCosmoMath.HOAA = ... def __init__( self, - abstol: float = ..., k: float = ..., - opt: NumCosmoMath.HOAAOpt = ..., + abstol: float = ..., + adiab_threshold: float = ..., + prop_threshold: float = ..., reltol: float = ..., save_evol: bool = ..., tf: float = ..., ti: float = ..., + vacuum_max_time: float = ..., + vacuum_reltol: float = ..., + vacuum_type: NumCosmoMath.CSQ1DInitialStateType = ..., ): ... @staticmethod - def clear(pa: HIPertGW) -> None: ... + def clear(pgw: HIPertGW) -> None: ... def free(self) -> None: ... + def get_k(self) -> float: ... @classmethod def new(cls) -> HIPertGW: ... def ref(self) -> HIPertGW: ... + def set_k(self, k: float) -> None: ... class HIPertGWClass(GObject.GPointer): r""" @@ -10711,7 +10992,7 @@ class HIPertGWClass(GObject.GPointer): HIPertGWClass() """ - parent_class: NumCosmoMath.HOAAClass = ... + parent_class: NumCosmoMath.CSQ1DClass = ... class HIPertGrav(GObject.Object): r""" @@ -11029,26 +11310,18 @@ class HIPertIAdiab(GObject.GInterface): notify (GParam) """ - def eval_dlnmnu(self, tau: float, k: float) -> float: ... - def eval_mnu(self, tau: float, k: float) -> float: ... + def eval_F1(self, tau: float, k: float) -> float: ... + def eval_hubble(self, tau: float) -> float: ... + def eval_lapse(self, tau: float) -> float: ... + def eval_m(self, tau: float, k: float) -> float: ... def eval_nu(self, tau: float, k: float) -> float: ... - def eval_powspec_factor(self) -> float: ... - def eval_sing_dlnmnu(self, tau_m_taus: float, k: float, sing: int) -> float: ... - def eval_sing_mnu(self, tau_m_taus: float, k: float, sing: int) -> float: ... - def eval_sing_system( - self, tau_m_taus: float, k: float, sing: int - ) -> Tuple[float, float]: ... - def eval_system(self, tau: float, k: float) -> Tuple[float, float]: ... - def get_sing_info( - self, - k: float, - sing: int, - ts: float, - dts_i: float, - dts_f: float, - st: NumCosmoMath.HOAASingType, - ) -> None: ... - def nsing(self, k: float) -> int: ... + def eval_p2Psi(self, tau: float, k: float) -> float: ... + def eval_p2drho(self, tau: float, k: float) -> float: ... + def eval_tau_hubble(self, k: float) -> float: ... + def eval_tau_jeans(self, k: float) -> float: ... + def eval_unit(self) -> float: ... + def eval_x(self, tau: float) -> float: ... + def eval_xi(self, tau: float, k: float) -> float: ... class HIPertIAdiabInterface(GObject.GPointer): r""" @@ -11060,20 +11333,53 @@ class HIPertIAdiabInterface(GObject.GPointer): """ parent: GObject.TypeInterface = ... - eval_mnu: Callable[[HIPertIAdiab, float, float], float] = ... + eval_xi: Callable[[HIPertIAdiab, float, float], float] = ... + eval_F1: Callable[[HIPertIAdiab, float, float], float] = ... eval_nu: Callable[[HIPertIAdiab, float, float], float] = ... - eval_dlnmnu: Callable[[HIPertIAdiab, float, float], float] = ... - eval_system: Callable[[HIPertIAdiab, float, float], Tuple[float, float]] = ... - nsing: Callable[[HIPertIAdiab, float], int] = ... - get_sing_info: Callable[ - [HIPertIAdiab, float, int, float, float, float, NumCosmoMath.HOAASingType], None - ] = ... - eval_sing_mnu: Callable[[HIPertIAdiab, float, float, int], float] = ... - eval_sing_dlnmnu: Callable[[HIPertIAdiab, float, float, int], float] = ... - eval_sing_system: Callable[ - [HIPertIAdiab, float, float, int], Tuple[float, float] - ] = ... - eval_powspec_factor: Callable[[HIPertIAdiab], float] = ... + eval_m: Callable[[HIPertIAdiab, float, float], float] = ... + eval_unit: Callable[[HIPertIAdiab], float] = ... + eval_x: Callable[[HIPertIAdiab, float], float] = ... + eval_p2Psi: Callable[[HIPertIAdiab, float, float], float] = ... + eval_p2drho: Callable[[HIPertIAdiab, float, float], float] = ... + eval_lapse: Callable[[HIPertIAdiab, float], float] = ... + eval_tau_hubble: Callable[[HIPertIAdiab, float], float] = ... + eval_tau_jeans: Callable[[HIPertIAdiab, float], float] = ... + eval_hubble: Callable[[HIPertIAdiab, float], float] = ... + padding: list[None] = ... + +class HIPertIEM(GObject.GInterface): + r""" + Interface NcHIPertIEM + + Signals from GObject: + notify (GParam) + """ + + def eval_F1(self, tau: float, k: float) -> float: ... + def eval_m(self, tau: float, k: float) -> float: ... + def eval_nu(self, tau: float, k: float) -> float: ... + def eval_unit(self) -> float: ... + def eval_x(self, tau: float) -> float: ... + def eval_xi(self, tau: float, k: float) -> float: ... + +class HIPertIEMInterface(GObject.GPointer): + r""" + :Constructors: + + :: + + HIPertIEMInterface() + """ + + parent: GObject.TypeInterface = ... + eval_xi: Callable[[HIPertIEM, float, float], float] = ... + eval_F1: Callable[[HIPertIEM, float, float], float] = ... + eval_nu: Callable[[HIPertIEM, float, float], float] = ... + eval_m: Callable[[HIPertIEM, float, float], float] = ... + eval_unit: Callable[[HIPertIEM], float] = ... + eval_x: Callable[[HIPertIEM, float], float] = ... + eval_lapse: Callable[[HIPertIEM, float], float] = ... + padding: list[None] = ... class HIPertIGW(GObject.GInterface): r""" @@ -11083,26 +11389,12 @@ class HIPertIGW(GObject.GInterface): notify (GParam) """ - def eval_dlnmnu(self, tau: float, k: float) -> float: ... - def eval_mnu(self, tau: float, k: float) -> float: ... + def eval_F1(self, tau: float, k: float) -> float: ... + def eval_m(self, tau: float, k: float) -> float: ... def eval_nu(self, tau: float, k: float) -> float: ... - def eval_powspec_factor(self) -> float: ... - def eval_sing_dlnmnu(self, tau_m_taus: float, k: float, sing: int) -> float: ... - def eval_sing_mnu(self, tau_m_taus: float, k: float, sing: int) -> float: ... - def eval_sing_system( - self, tau_m_taus: float, k: float, sing: int - ) -> Tuple[float, float]: ... - def eval_system(self, tau: float, k: float) -> Tuple[float, float]: ... - def get_sing_info( - self, - k: float, - sing: int, - ts: float, - dts_i: float, - dts_f: float, - st: NumCosmoMath.HOAASingType, - ) -> None: ... - def nsing(self, k: float) -> int: ... + def eval_unit(self) -> float: ... + def eval_x(self, tau: float) -> float: ... + def eval_xi(self, tau: float, k: float) -> float: ... class HIPertIGWInterface(GObject.GPointer): r""" @@ -11114,20 +11406,13 @@ class HIPertIGWInterface(GObject.GPointer): """ parent: GObject.TypeInterface = ... - eval_mnu: Callable[[HIPertIGW, float, float], float] = ... + eval_xi: Callable[[HIPertIGW, float, float], float] = ... + eval_F1: Callable[[HIPertIGW, float, float], float] = ... eval_nu: Callable[[HIPertIGW, float, float], float] = ... - eval_dlnmnu: Callable[[HIPertIGW, float, float], float] = ... - eval_system: Callable[[HIPertIGW, float, float], Tuple[float, float]] = ... - nsing: Callable[[HIPertIGW, float], int] = ... - get_sing_info: Callable[ - [HIPertIGW, float, int, float, float, float, NumCosmoMath.HOAASingType], None - ] = ... - eval_sing_mnu: Callable[[HIPertIGW, float, float, int], float] = ... - eval_sing_dlnmnu: Callable[[HIPertIGW, float, float, int], float] = ... - eval_sing_system: Callable[[HIPertIGW, float, float, int], Tuple[float, float]] = ( - ... - ) - eval_powspec_factor: Callable[[HIPertIGW], float] = ... + eval_m: Callable[[HIPertIGW, float, float], float] = ... + eval_unit: Callable[[HIPertIGW], float] = ... + eval_x: Callable[[HIPertIGW, float], float] = ... + padding: list[None] = ... class HIPertITwoFluids(GObject.GInterface): r""" @@ -15726,21 +16011,22 @@ class PowspecMLClass(GObject.GPointer): """ parent_class: NumCosmoMath.PowspecClass = ... + padding: list[None] = ... -class PowspecMLFixSpline(PowspecML): +class PowspecMLSpline(PowspecML): r""" :Constructors: :: - PowspecMLFixSpline(**properties) - new(filename:str) -> NumCosmo.PowspecMLFixSpline + PowspecMLSpline(**properties) + new(Pk:NumCosmoMath.Spline) -> NumCosmo.PowspecMLSpline - Object NcPowspecMLFixSpline + Object NcPowspecMLSpline - Properties from NcPowspecMLFixSpline: - filename -> gchararray: filename - Filename + Properties from NcPowspecMLSpline: + spline -> NcmSpline: spline + Spline representing Pk at z=0 Properties from NcPowspecML: zi -> gdouble: zi @@ -15769,7 +16055,7 @@ class PowspecMLFixSpline(PowspecML): """ class Props: - filename: str + spline: NumCosmoMath.Spline kmax: float kmin: float zf: float @@ -15777,14 +16063,9 @@ class PowspecMLFixSpline(PowspecML): reltol: float props: Props = ... - parent_instance: PowspecML = ... - ser: NumCosmoMath.Serialize = ... - Pk: NumCosmoMath.Spline = ... - gf: GrowthFunc = ... - filename: str = ... def __init__( self, - filename: str = ..., + spline: NumCosmoMath.Spline = ..., kmax: float = ..., kmin: float = ..., zf: float = ..., @@ -15792,16 +16073,17 @@ class PowspecMLFixSpline(PowspecML): reltol: float = ..., ): ... @classmethod - def new(cls, filename: str) -> PowspecMLFixSpline: ... - def set_file(self, filename: str) -> None: ... + def new(cls, Pk: NumCosmoMath.Spline) -> PowspecMLSpline: ... + def peek_spline(self) -> NumCosmoMath.Spline: ... + def set_spline(self, Pk: NumCosmoMath.Spline) -> None: ... -class PowspecMLFixSplineClass(GObject.GPointer): +class PowspecMLSplineClass(GObject.GPointer): r""" :Constructors: :: - PowspecMLFixSplineClass() + PowspecMLSplineClass() """ parent_class: PowspecMLClass = ... @@ -18443,6 +18725,12 @@ class HICosmoQGRWSParams(GObject.GEnum): W: HICosmoQGRWSParams = ... X_B: HICosmoQGRWSParams = ... +class HICosmoQGWSParams(GObject.GEnum): + H0: HICosmoQGWSParams = ... + OMEGA_W: HICosmoQGWSParams = ... + W: HICosmoQGWSParams = ... + X_B: HICosmoQGWSParams = ... + class HICosmoQLinearSParams(GObject.GEnum): CD: HICosmoQLinearSParams = ... E: HICosmoQLinearSParams = ... @@ -18470,9 +18758,17 @@ class HICosmoQSplineSParams(GObject.GEnum): class HICosmoQSplineVParams(GObject.GEnum): Q: HICosmoQSplineVParams = ... +class HICosmoVexpEMCoupling(GObject.GEnum): + CAUCHY: HICosmoVexpEMCoupling = ... + GAUSS: HICosmoVexpEMCoupling = ... + INVALID: HICosmoVexpEMCoupling = ... + NONE: HICosmoVexpEMCoupling = ... + class HICosmoVexpSParams(GObject.GEnum): ALPHA_B: HICosmoVexpSParams = ... D_PHI: HICosmoVexpSParams = ... + EM_B: HICosmoVexpSParams = ... + EM_BETA: HICosmoVexpSParams = ... H0: HICosmoVexpSParams = ... OMEGA_C: HICosmoVexpSParams = ... OMEGA_L: HICosmoVexpSParams = ... @@ -18506,15 +18802,21 @@ class HIPertCompPBVar(GObject.GEnum): V_B: HIPertCompPBVar = ... V_G: HIPertCompPBVar = ... +class HIPertEMVars(GObject.GEnum): + IM_H: HIPertEMVars = ... + IM_PH: HIPertEMVars = ... + RE_H: HIPertEMVars = ... + RE_PH: HIPertEMVars = ... + class HIPertFirstOrderInteg(GObject.GEnum): ARKODE: HIPertFirstOrderInteg = ... CVODE: HIPertFirstOrderInteg = ... class HIPertGWVars(GObject.GEnum): - IM_PZETA: HIPertGWVars = ... - IM_ZETA: HIPertGWVars = ... - RE_PZETA: HIPertGWVars = ... - RE_ZETA: HIPertGWVars = ... + IM_H: HIPertGWVars = ... + IM_PH: HIPertGWVars = ... + RE_H: HIPertGWVars = ... + RE_PH: HIPertGWVars = ... class HIPertGravGauge(GObject.GEnum): CONST_CURV: HIPertGravGauge = ... diff --git a/numcosmo_py/ncm.pyi b/numcosmo_py/ncm.pyi index 1d531b2a2..121a6cfee 100644 --- a/numcosmo_py/ncm.pyi +++ b/numcosmo_py/ncm.pyi @@ -913,6 +913,8 @@ class C(GObject.Object): @staticmethod def eV() -> float: ... @staticmethod + def electric_constant() -> float: ... + @staticmethod def fine_struct() -> float: ... @staticmethod def fine_struct_square() -> float: ... @@ -949,6 +951,8 @@ class C(GObject.Object): @staticmethod def lnpi_4() -> float: ... @staticmethod + def magnetic_constant() -> float: ... + @staticmethod def mass_1H() -> float: ... @staticmethod def mass_1H_u() -> float: ... @@ -1083,8 +1087,6 @@ class CSQ1D(GObject.Object): Relative tolerance abstol -> gdouble: abstol Absolute tolerance tolerance - k -> gdouble: k - Mode k ti -> gdouble: ti The initial time t_i tf -> gdouble: tf @@ -1095,8 +1097,12 @@ class CSQ1D(GObject.Object): The propagator threshold save-evol -> gboolean: save-evol Save the system evolution - max-order-2 -> gboolean: max-order-2 - Whether to always truncate at order 2 + vacuum-type -> NcmCSQ1DInitialStateType: vacuum-type + The vacuum type + vacuum-reltol -> gdouble: vacuum-reltol + The vacuum relative tolerance + vacuum-max-time -> gdouble: vacuum-max-time + The vacuum maximum time Signals from GObject: notify (GParam) @@ -1105,13 +1111,14 @@ class CSQ1D(GObject.Object): class Props: abstol: float adiab_threshold: float - k: float - max_order_2: bool prop_threshold: float reltol: float save_evol: bool tf: float ti: float + vacuum_max_time: float + vacuum_reltol: float + vacuum_type: CSQ1DInitialStateType props: Props = ... parent_instance: GObject.Object = ... @@ -1119,80 +1126,70 @@ class CSQ1D(GObject.Object): self, abstol: float = ..., adiab_threshold: float = ..., - k: float = ..., - max_order_2: bool = ..., prop_threshold: float = ..., reltol: float = ..., save_evol: bool = ..., tf: float = ..., ti: float = ..., + vacuum_max_time: float = ..., + vacuum_reltol: float = ..., + vacuum_type: CSQ1DInitialStateType = ..., ): ... - def alpha_dgamma_to_minkowski_frame( - self, - model: Optional[Model], - adiab_frame: int, - t: float, - alpha: float, - dgamma: float, - ) -> Tuple[float, float]: ... - def alpha_dgamma_to_phi_Pphi( - self, model: Optional[Model], t: float, alpha: float, dgamma: float - ) -> Tuple[list[float], list[float]]: ... - def alpha_gamma_circle( - self, model: Optional[Model], alpha: float, gamma: float, r: float, theta: float - ) -> Tuple[float, float]: ... + def change_frame( + self, model: Optional[Model], state: CSQ1DState, frame: CSQ1DFrame + ) -> CSQ1DState: ... @staticmethod def clear(csq1d: CSQ1D) -> None: ... - def do_eval_F1(self, model: Optional[Model], t: float, k: float) -> float: ... - def do_eval_F2(self, model: Optional[Model], t: float, k: float) -> float: ... - def do_eval_FN( - self, model: Optional[Model], n: int, t: float, k: float - ) -> float: ... - def do_eval_dm(self, model: Optional[Model], t: float, k: float) -> float: ... - def do_eval_dxi(self, model: Optional[Model], t: float, k: float) -> float: ... - def do_eval_int_1_m(self, model: Optional[Model], t: float, k: float) -> float: ... - def do_eval_int_mnu2(self, model: Optional[Model], t: float, k: float) -> float: ... - def do_eval_int_q2mnu2( - self, model: Optional[Model], t: float, k: float - ) -> float: ... - def do_eval_int_qmnu2( - self, model: Optional[Model], t: float, k: float - ) -> float: ... - def do_eval_m(self, model: Optional[Model], t: float, k: float) -> float: ... - def do_eval_nu(self, model: Optional[Model], t: float, k: float) -> float: ... - def do_eval_nu2(self, model: Optional[Model], t: float, k: float) -> float: ... - def do_eval_powspec_factor(self, model: Optional[Model], k: float) -> float: ... - def do_eval_xi(self, model: Optional[Model], t: float, k: float) -> float: ... + def compute_H( + self, model: Optional[Model], t: float, state: CSQ1DState + ) -> CSQ1DState: ... + def compute_adiab( + self, model: Optional[Model], t: float, state: CSQ1DState + ) -> Tuple[CSQ1DState, float, float]: ... + def compute_adiab_frame( + self, model: Optional[Model], frame: CSQ1DFrame, t: float, state: CSQ1DState + ) -> Tuple[CSQ1DState, float, float]: ... + def compute_nonadiab( + self, model: Optional[Model], t: float, state: CSQ1DState + ) -> CSQ1DState: ... + def compute_prop_vector( + self, model: Model, t: float, state: CSQ1DState + ) -> CSQ1DState: ... + def do_eval_F1(self, model: Optional[Model], t: float) -> float: ... + def do_eval_F2(self, model: Optional[Model], t: float) -> float: ... + def do_eval_int_1_m(self, model: Optional[Model], t: float) -> float: ... + def do_eval_int_mnu2(self, model: Optional[Model], t: float) -> float: ... + def do_eval_int_q2mnu2(self, model: Optional[Model], t: float) -> float: ... + def do_eval_int_qmnu2(self, model: Optional[Model], t: float) -> float: ... + def do_eval_m(self, model: Optional[Model], t: float) -> float: ... + def do_eval_nu(self, model: Optional[Model], t: float) -> float: ... + def do_eval_nu2(self, model: Optional[Model], t: float) -> float: ... + def do_eval_xi(self, model: Optional[Model], t: float) -> float: ... def do_prepare(self, model: Optional[Model] = None) -> None: ... - def eval_F1(self, model: Optional[Model], t: float, k: float) -> float: ... - def eval_F2(self, model: Optional[Model], t: float, k: float) -> float: ... - def eval_FN(self, model: Optional[Model], n: int, t: float, k: float) -> float: ... - def eval_adiab_at( - self, model: Optional[Model], t: float - ) -> Tuple[float, float, float, float]: ... - def eval_at(self, t: float) -> Tuple[float, float]: ... - def eval_dm(self, model: Optional[Model], t: float, k: float) -> float: ... - def eval_dxi(self, model: Optional[Model], t: float, k: float) -> float: ... - def eval_int_1_m(self, model: Optional[Model], t: float, k: float) -> float: ... - def eval_int_mnu2(self, model: Optional[Model], t: float, k: float) -> float: ... - def eval_int_q2mnu2(self, model: Optional[Model], t: float, k: float) -> float: ... - def eval_int_qmnu2(self, model: Optional[Model], t: float, k: float) -> float: ... - def eval_m(self, model: Optional[Model], t: float, k: float) -> float: ... - def eval_nonadiab_at( - self, model: Optional[Model], nonadiab_frame: int, t: float - ) -> Tuple[float, float]: ... - def eval_nu(self, model: Optional[Model], t: float, k: float) -> float: ... - def eval_nu2(self, model: Optional[Model], t: float, k: float) -> float: ... - def eval_powspec_factor(self, model: Optional[Model], k: float) -> float: ... - def eval_xi(self, model: Optional[Model], t: float, k: float) -> float: ... - def evolve_prop_vector_chi_Up( + def eval_F1(self, model: Optional[Model], t: float) -> float: ... + def eval_F2(self, model: Optional[Model], t: float) -> float: ... + def eval_at( + self, model: Optional[Model], t: float, state: CSQ1DState + ) -> CSQ1DState: ... + def eval_at_frame( + self, model: Optional[Model], frame: CSQ1DFrame, t: float, state: CSQ1DState + ) -> CSQ1DState: ... + def eval_int_1_m(self, model: Optional[Model], t: float) -> float: ... + def eval_int_mnu2(self, model: Optional[Model], t: float) -> float: ... + def eval_int_q2mnu2(self, model: Optional[Model], t: float) -> float: ... + def eval_int_qmnu2(self, model: Optional[Model], t: float) -> float: ... + def eval_m(self, model: Optional[Model], t: float) -> float: ... + def eval_nu(self, model: Optional[Model], t: float) -> float: ... + def eval_nu2(self, model: Optional[Model], t: float) -> float: ... + def eval_xi(self, model: Optional[Model], t: float) -> float: ... + def evolve_prop_vector( self, model: Optional[Model], + initial_state: CSQ1DState, + frame: CSQ1DFrame, t: float, - nonadiab_frame: int, - chi_i: float, - Up_i: float, - ) -> Tuple[float, float]: ... + state: CSQ1DState, + ) -> CSQ1DState: ... def find_adiab_max( self, model: Optional[Model], t0: float, t1: float, border_eps: float ) -> Tuple[float, float, float, float]: ... @@ -1200,47 +1197,18 @@ class CSQ1D(GObject.Object): self, model: Optional[Model], t0: float, t1: float, reltol: float ) -> Tuple[bool, float]: ... def free(self) -> None: ... - def get_H_poincare_disc( - self, model: Optional[Model], t: float - ) -> Tuple[float, float]: ... - def get_H_poincare_hp( - self, model: Optional[Model], t: float - ) -> Tuple[float, float]: ... - def get_Hadiab_poincare_disc( - self, model: Optional[Model], t: float - ) -> Tuple[float, float]: ... - def get_Hadiab_poincare_hp( - self, model: Optional[Model], t: float - ) -> Tuple[float, float]: ... - def get_J_at( - self, model: Optional[Model], t: float - ) -> Tuple[float, float, float]: ... def get_abstol(self) -> float: ... def get_adiab_threshold(self) -> float: ... - def get_k(self) -> float: ... - def get_max_order_2(self) -> bool: ... - def get_minkowski_frame( - self, model: Optional[Model], adiab_frame: int, t: float - ) -> Tuple[float, float]: ... - def get_poincare_disc( - self, model: Optional[Model], t: float - ) -> Tuple[float, float]: ... - def get_poincare_hp( - self, model: Optional[Model], t: float - ) -> Tuple[float, float]: ... - def get_poincare_hp_frame( - self, model: Optional[Model], adiab_frame: int, t: float - ) -> Tuple[float, float]: ... + def get_initial_condition_type(self) -> CSQ1DInitialStateType: ... def get_prop_threshold(self) -> float: ... - def get_prop_vector_chi_Up( - self, model: Optional[Model], t: float - ) -> Tuple[float, float]: ... def get_reltol(self) -> float: ... def get_save_evol(self) -> bool: ... def get_tf(self) -> float: ... def get_tf_prop(self) -> float: ... def get_ti(self) -> float: ... def get_time_array(self) -> Tuple[list[float], float]: ... + def get_vacuum_max_time(self) -> float: ... + def get_vacuum_reltol(self) -> float: ... def prepare(self, model: Optional[Model] = None) -> None: ... def prepare_prop( self, model: Optional[Model], ti: float, tii: float, tf: float @@ -1249,16 +1217,22 @@ class CSQ1D(GObject.Object): def set_abstol(self, abstol: float) -> None: ... def set_adiab_threshold(self, adiab_threshold: float) -> None: ... def set_init_cond( - self, state: CSQ1DEvolState, ti: float, x: float, y: float + self, + model: Optional[Model], + evol_state: CSQ1DEvolState, + initial_state: CSQ1DState, ) -> None: ... def set_init_cond_adiab(self, model: Optional[Model], ti: float) -> None: ... - def set_k(self, k: float) -> None: ... - def set_max_order_2(self, truncate: bool) -> None: ... + def set_initial_condition_type( + self, initial_condition_type: CSQ1DInitialStateType + ) -> None: ... def set_prop_threshold(self, prop_threshold: float) -> None: ... def set_reltol(self, reltol: float) -> None: ... def set_save_evol(self, save: bool) -> None: ... def set_tf(self, tf: float) -> None: ... def set_ti(self, ti: float) -> None: ... + def set_vacuum_max_time(self, vacuum_max_time: float) -> None: ... + def set_vacuum_reltol(self, vacuum_reltol: float) -> None: ... class CSQ1DClass(GObject.GPointer): r""" @@ -1270,25 +1244,54 @@ class CSQ1DClass(GObject.GPointer): """ parent_class: GObject.ObjectClass = ... - eval_xi: Callable[[CSQ1D, Optional[Model], float, float], float] = ... - eval_dxi: Callable[[CSQ1D, Optional[Model], float, float], float] = ... - eval_nu: Callable[[CSQ1D, Optional[Model], float, float], float] = ... - eval_nu2: Callable[[CSQ1D, Optional[Model], float, float], float] = ... - eval_m: Callable[[CSQ1D, Optional[Model], float, float], float] = ... - eval_int_1_m: Callable[[CSQ1D, Optional[Model], float, float], float] = ... - eval_int_mnu2: Callable[[CSQ1D, Optional[Model], float, float], float] = ... - eval_int_qmnu2: Callable[[CSQ1D, Optional[Model], float, float], float] = ... - eval_int_q2mnu2: Callable[[CSQ1D, Optional[Model], float, float], float] = ... - eval_dm: Callable[[CSQ1D, Optional[Model], float, float], float] = ... - eval_F1: Callable[[CSQ1D, Optional[Model], float, float], float] = ... - eval_F2: Callable[[CSQ1D, Optional[Model], float, float], float] = ... - eval_FN: Callable[[CSQ1D, Optional[Model], int, float, float], float] = ... - eval_powspec_factor: Callable[[CSQ1D, Optional[Model], float], float] = ... + eval_xi: Callable[[CSQ1D, Optional[Model], float], float] = ... + eval_nu: Callable[[CSQ1D, Optional[Model], float], float] = ... + eval_nu2: Callable[[CSQ1D, Optional[Model], float], float] = ... + eval_m: Callable[[CSQ1D, Optional[Model], float], float] = ... + eval_int_1_m: Callable[[CSQ1D, Optional[Model], float], float] = ... + eval_int_mnu2: Callable[[CSQ1D, Optional[Model], float], float] = ... + eval_int_qmnu2: Callable[[CSQ1D, Optional[Model], float], float] = ... + eval_int_q2mnu2: Callable[[CSQ1D, Optional[Model], float], float] = ... + eval_F1: Callable[[CSQ1D, Optional[Model], float], float] = ... + eval_F2: Callable[[CSQ1D, Optional[Model], float], float] = ... prepare: Callable[[CSQ1D, Optional[Model]], None] = ... padding: list[None] = ... -class CSQ1DSingFitUm(GObject.GPointer): ... -class CSQ1DSingFitUp(GObject.GPointer): ... +class CSQ1DState(GObject.GBoxed): + r""" + :Constructors: + + :: + + CSQ1DState() + new() -> NumCosmoMath.CSQ1DState + """ + + frame: CSQ1DFrame = ... + alpha: float = ... + gamma: float = ... + t: float = ... + def compute_distance(self, state1: CSQ1DState) -> float: ... + def copy(self) -> CSQ1DState: ... + def free(self) -> None: ... + def get_J(self) -> Tuple[float, float, float]: ... + def get_ag(self) -> Tuple[float, float]: ... + def get_circle(self, r: float, theta: float) -> CSQ1DState: ... + def get_frame(self) -> CSQ1DFrame: ... + def get_minkowski(self) -> Tuple[float, float]: ... + def get_phi_Pphi(self) -> Tuple[list[float], list[float]]: ... + def get_poincare_disc(self) -> Tuple[float, float]: ... + def get_poincare_half_plane(self) -> Tuple[float, float]: ... + def get_time(self) -> float: ... + def get_um(self) -> Tuple[float, float]: ... + def get_up(self) -> Tuple[float, float]: ... + @classmethod + def new(cls) -> CSQ1DState: ... + def set_ag( + self, frame: CSQ1DFrame, t: float, alpha: float, gamma: float + ) -> None: ... + def set_um(self, frame: CSQ1DFrame, t: float, chi: float, Um: float) -> None: ... + def set_up(self, frame: CSQ1DFrame, t: float, chi: float, Up: float) -> None: ... class Complex(GObject.GBoxed): r""" @@ -2492,6 +2495,8 @@ class Fftlog(GObject.Object): Function log-period N -> guint: N Number of knots + max-n -> guint: max-n + Maximum number of knots padding -> gdouble: padding Padding percentage no-ringing -> gboolean: no-ringing @@ -2520,6 +2525,7 @@ class Fftlog(GObject.Object): eval_r_min: float lnk0: float lnr0: float + max_n: int name: str nderivs: int no_ringing: bool @@ -2538,6 +2544,7 @@ class Fftlog(GObject.Object): eval_r_min: float = ..., lnk0: float = ..., lnr0: float = ..., + max_n: int = ..., nderivs: int = ..., no_ringing: bool = ..., padding: float = ..., @@ -2565,6 +2572,7 @@ class Fftlog(GObject.Object): def get_lnk0(self) -> float: ... def get_lnk_vector(self, lnk: Vector) -> None: ... def get_lnr0(self) -> float: ... + def get_max_size(self) -> int: ... def get_mode_index(self, i: int) -> int: ... def get_nderivs(self) -> int: ... def get_noring(self) -> bool: ... @@ -2585,6 +2593,7 @@ class Fftlog(GObject.Object): def set_length(self, Lk: float) -> None: ... def set_lnk0(self, lnk0: float) -> None: ... def set_lnr0(self, lnr0: float) -> None: ... + def set_max_size(self, max_n: int) -> None: ... def set_nderivs(self, nderivs: int) -> None: ... def set_noring(self, active: bool) -> None: ... def set_padding(self, pad_p: float) -> None: ... @@ -2629,6 +2638,8 @@ class FftlogGausswin2(Fftlog): Function log-period N -> guint: N Number of knots + max-n -> guint: max-n + Maximum number of knots padding -> gdouble: padding Padding percentage no-ringing -> gboolean: no-ringing @@ -2657,6 +2668,7 @@ class FftlogGausswin2(Fftlog): eval_r_min: float lnk0: float lnr0: float + max_n: int name: str nderivs: int no_ringing: bool @@ -2674,6 +2686,7 @@ class FftlogGausswin2(Fftlog): eval_r_min: float = ..., lnk0: float = ..., lnr0: float = ..., + max_n: int = ..., nderivs: int = ..., no_ringing: bool = ..., padding: float = ..., @@ -2723,6 +2736,8 @@ class FftlogSBesselJ(Fftlog): Function log-period N -> guint: N Number of knots + max-n -> guint: max-n + Maximum number of knots padding -> gdouble: padding Padding percentage no-ringing -> gboolean: no-ringing @@ -2753,6 +2768,7 @@ class FftlogSBesselJ(Fftlog): eval_r_min: float lnk0: float lnr0: float + max_n: int name: str nderivs: int no_ringing: bool @@ -2772,6 +2788,7 @@ class FftlogSBesselJ(Fftlog): eval_r_min: float = ..., lnk0: float = ..., lnr0: float = ..., + max_n: int = ..., nderivs: int = ..., no_ringing: bool = ..., padding: float = ..., @@ -2831,6 +2848,8 @@ class FftlogSBesselJLJM(Fftlog): Function log-period N -> guint: N Number of knots + max-n -> guint: max-n + Maximum number of knots padding -> gdouble: padding Padding percentage no-ringing -> gboolean: no-ringing @@ -2862,6 +2881,7 @@ class FftlogSBesselJLJM(Fftlog): eval_r_min: float lnk0: float lnr0: float + max_n: int name: str nderivs: int no_ringing: bool @@ -2882,6 +2902,7 @@ class FftlogSBesselJLJM(Fftlog): eval_r_min: float = ..., lnk0: float = ..., lnr0: float = ..., + max_n: int = ..., nderivs: int = ..., no_ringing: bool = ..., padding: float = ..., @@ -2944,6 +2965,8 @@ class FftlogTophatwin2(Fftlog): Function log-period N -> guint: N Number of knots + max-n -> guint: max-n + Maximum number of knots padding -> gdouble: padding Padding percentage no-ringing -> gboolean: no-ringing @@ -2972,6 +2995,7 @@ class FftlogTophatwin2(Fftlog): eval_r_min: float lnk0: float lnr0: float + max_n: int name: str nderivs: int no_ringing: bool @@ -2989,6 +3013,7 @@ class FftlogTophatwin2(Fftlog): eval_r_min: float = ..., lnk0: float = ..., lnr0: float = ..., + max_n: int = ..., nderivs: int = ..., no_ringing: bool = ..., padding: float = ..., @@ -7763,25 +7788,31 @@ class Powspec(GObject.Object): ): ... @staticmethod def clear(powspec: Powspec) -> None: ... - def corr3d(self, model: Model, reltol: float, z: float, r: float) -> float: ... - def do_eval(self, model: Model, z: float, k: float) -> float: ... - def do_eval_vec(self, model: Model, z: float, k: Vector, Pk: Vector) -> None: ... + def corr3d( + self, model: Optional[Model], reltol: float, z: float, r: float + ) -> float: ... + def do_eval(self, model: Optional[Model], z: float, k: float) -> float: ... + def do_eval_vec( + self, model: Optional[Model], z: float, k: Vector, Pk: Vector + ) -> None: ... def do_get_nknots(self) -> Tuple[int, int]: ... - def do_get_spline_2d(self, model: Model) -> Spline2d: ... - def do_prepare(self, model: Model) -> None: ... - def eval(self, model: Model, z: float, k: float) -> float: ... - def eval_vec(self, model: Model, z: float, k: Vector, Pk: Vector) -> None: ... + def do_get_spline_2d(self, model: Optional[Model] = None) -> Spline2d: ... + def do_prepare(self, model: Optional[Model] = None) -> None: ... + def eval(self, model: Optional[Model], z: float, k: float) -> float: ... + def eval_vec( + self, model: Optional[Model], z: float, k: Vector, Pk: Vector + ) -> None: ... def free(self) -> None: ... def get_kmax(self) -> float: ... def get_kmin(self) -> float: ... def get_nknots(self) -> Tuple[int, int]: ... def get_reltol_spline(self) -> float: ... - def get_spline_2d(self, model: Model) -> Spline2d: ... + def get_spline_2d(self, model: Optional[Model] = None) -> Spline2d: ... def get_zf(self) -> float: ... def get_zi(self) -> float: ... def peek_model_ctrl(self) -> ModelCtrl: ... - def prepare(self, model: Model) -> None: ... - def prepare_if_needed(self, model: Model) -> None: ... + def prepare(self, model: Optional[Model] = None) -> None: ... + def prepare_if_needed(self, model: Optional[Model] = None) -> None: ... def ref(self) -> Powspec: ... def require_kmax(self, kmax: float) -> None: ... def require_kmin(self, kmin: float) -> None: ... @@ -7793,11 +7824,11 @@ class Powspec(GObject.Object): def set_zf(self, zf: float) -> None: ... def set_zi(self, zi: float) -> None: ... def sigma_tophat_R( - self, model: Model, reltol: float, z: float, R: float + self, model: Optional[Model], reltol: float, z: float, R: float ) -> float: ... def sproj( self, - model: Model, + model: Optional[Model], reltol: float, ell: int, z1: float, @@ -7806,7 +7837,7 @@ class Powspec(GObject.Object): xi2: float, ) -> float: ... def var_tophat_R( - self, model: Model, reltol: float, z: float, R: float + self, model: Optional[Model], reltol: float, z: float, R: float ) -> float: ... class PowspecClass(GObject.GPointer): @@ -7819,11 +7850,11 @@ class PowspecClass(GObject.GPointer): """ parent_class: GObject.ObjectClass = ... - prepare: Callable[[Powspec, Model], None] = ... - eval: Callable[[Powspec, Model, float, float], float] = ... - eval_vec: Callable[[Powspec, Model, float, Vector, Vector], None] = ... + prepare: Callable[[Powspec, Optional[Model]], None] = ... + eval: Callable[[Powspec, Optional[Model], float, float], float] = ... + eval_vec: Callable[[Powspec, Optional[Model], float, Vector, Vector], None] = ... get_nknots: Callable[[Powspec], Tuple[int, int]] = ... - get_spline_2d: Callable[[Powspec, Model], Spline2d] = ... + get_spline_2d: Callable[[Powspec, Optional[Model]], Spline2d] = ... padding: list[None] = ... class PowspecCorr3d(GObject.Object): @@ -7929,6 +7960,10 @@ class PowspecFilter(GObject.Object): Relative tolerance for calibration reltol-z -> gdouble: reltol-z Relative tolerance for calibration in the redshift direction + max-k-knots -> guint: max-k-knots + Maximum number of knots in the k direction + max-z-knots -> guint: max-z-knots + Maximum number of knots in the redshift direction powerspectrum -> NcmPowspec: powerspectrum NcmPowspec object @@ -7938,6 +7973,8 @@ class PowspecFilter(GObject.Object): class Props: lnr0: float + max_k_knots: int + max_z_knots: int powerspectrum: Powspec reltol: float reltol_z: float @@ -7949,6 +7986,8 @@ class PowspecFilter(GObject.Object): def __init__( self, lnr0: float = ..., + max_k_knots: int = ..., + max_z_knots: int = ..., powerspectrum: Powspec = ..., reltol: float = ..., reltol_z: float = ..., @@ -8093,6 +8132,75 @@ class PowspecSphereProjClass(GObject.GPointer): parent_class: PowspecClass = ... +class PowspecSpline2d(Powspec): + r""" + :Constructors: + + :: + + PowspecSpline2d(**properties) + new(spline2d:NumCosmoMath.Spline2d) -> NumCosmoMath.PowspecSpline2d + + Object NcmPowspecSpline2d + + Properties from NcmPowspecSpline2d: + spline2d -> NcmSpline2d: spline2d + Spline2d representing the values of the power-spectrum + + Properties from NcmPowspec: + zi -> gdouble: zi + Initial time + zf -> gdouble: zf + Final time + kmin -> gdouble: kmin + Minimum mode value + kmax -> gdouble: kmax + Maximum mode value + reltol -> gdouble: reltol + Relative tolerance on the interpolation error + + Signals from GObject: + notify (GParam) + """ + + class Props: + spline2d: Spline2d + kmax: float + kmin: float + reltol: float + zf: float + zi: float + + props: Props = ... + def __init__( + self, + spline2d: Spline2d = ..., + kmax: float = ..., + kmin: float = ..., + reltol: float = ..., + zf: float = ..., + zi: float = ..., + ): ... + @staticmethod + def clear(ps_s2d: PowspecSpline2d) -> None: ... + def free(self) -> None: ... + @classmethod + def new(cls, spline2d: Spline2d) -> PowspecSpline2d: ... + def peek_spline2d(self) -> Spline2d: ... + def ref(self) -> PowspecSpline2d: ... + def set_spline2d(self, spline2d: Spline2d) -> None: ... + +class PowspecSpline2dClass(GObject.GPointer): + r""" + :Constructors: + + :: + + PowspecSpline2dClass() + """ + + parent_class: PowspecClass = ... + class Prior(MSetFunc): r""" :Constructors: @@ -11710,6 +11818,19 @@ class CSQ1DEvolState(GObject.GEnum): UM: CSQ1DEvolState = ... UP: CSQ1DEvolState = ... +class CSQ1DFrame(GObject.GEnum): + ADIAB1: CSQ1DFrame = ... + ADIAB2: CSQ1DFrame = ... + NONADIAB1: CSQ1DFrame = ... + NONADIAB2: CSQ1DFrame = ... + ORIG: CSQ1DFrame = ... + +class CSQ1DInitialStateType(GObject.GEnum): + ADIABATIC2: CSQ1DInitialStateType = ... + ADIABATIC4: CSQ1DInitialStateType = ... + AD_HOC: CSQ1DInitialStateType = ... + NONADIABATIC2: CSQ1DInitialStateType = ... + class DataPoissonType(GObject.GEnum): INT: DataPoissonType = ... diff --git a/numcosmo_py/plotting/tools.py b/numcosmo_py/plotting/tools.py index c16e321ff..0f969df15 100644 --- a/numcosmo_py/plotting/tools.py +++ b/numcosmo_py/plotting/tools.py @@ -34,8 +34,10 @@ def confidence_ellipse(mu, cov, ax, n_std=1.0, facecolor="none", **kwargs): - """Adds a confidence ellipse to the given axis based on the given - covariance matrix. + """Add confidence ellipse. + + This function adds an confidence ellipse to the given axes, given the mean + and covariance of the data. """ pearson = cov[0, 1] / np.sqrt(cov[0, 0] * cov[1, 1]) # Using a special case to obtain the eigenvalues of this @@ -84,7 +86,7 @@ def latex_float(value: float): if exponent == 0.0: return f"{base}" - return f"{base} \times 10^{{{int(exponent)}}}" + return rf"{base} \times 10^{{{int(exponent)}}}" return float_str @@ -122,7 +124,6 @@ def plot_m2lnp( vmax: float = 1.0, ): """Plot the -2lnp.""" - z = z - np.min(z) z = np.exp(-0.5 * z) exp_z = z.reshape(plotn, plotn) diff --git a/tests/meson.build b/tests/meson.build index 1e697de63..336dbd64e 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -147,6 +147,10 @@ c_tests = [ 'name': 'nc_hicosmo_de', 'sources': ['test_nc_hicosmo_de.c'], }, + { + 'name': 'nc_hicosmo_qgw', + 'sources': ['test_nc_hicosmo_qgw.c'], + }, { 'name': 'nc_window', 'sources': ['test_nc_window.c'], @@ -303,6 +307,22 @@ python_tests = [ 'name': 'py_cluster_abundance_sampling', 'source': 'test_py_cluster_abundance_sampling.py', }, + { + 'name': 'py_hicosmo_Vexp', + 'source': 'test_py_hicosmo_Vexp.py', + }, + { + 'name': 'py_hipert_em', + 'source': 'test_py_hipert_em.py', + }, + { + 'name': 'py_hipert_gw', + 'source': 'test_py_hipert_gw.py', + }, + { + 'name': 'py_de_cont', + 'source': 'test_py_de_cont.py', + }, { 'name': 'py_diff', 'source': 'test_py_diff.py', @@ -347,6 +367,10 @@ python_tests = [ 'name': 'py_data_rosenbrock', 'source': 'test_py_data_rosenbrock.py', }, + { + 'name': 'py_data_snia_cov', + 'source': 'test_py_data_snia_cov.py', + }, { 'name': 'py_dataset', 'source': 'test_py_dataset.py', @@ -383,6 +407,14 @@ python_tests = [ 'name': 'py_fit', 'source': 'test_py_fit.py', }, + { + 'name': 'py_powspec_ml_spline', + 'source': 'test_py_powspec_ml_spline.py', + }, + { + 'name': 'py_powspec_spline2d', + 'source': 'test_py_powspec_spline2d.py', + }, ] if mpi_c_dep.found() @@ -411,6 +443,10 @@ if python_astropy_scipy.found() 'name': 'py_csq1d', 'source': 'test_py_csq1d.py', }, + { + 'name': 'py_hipert_adiab', + 'source': 'test_py_hipert_adiab.py', + }, { 'name': 'py_data_dist1d', 'source': 'test_py_data_dist1d.py', @@ -483,7 +519,7 @@ if enable_gir modules: ['pytest_tap'], required: false, ) - if py_tap.found() + if py_tap.found() and get_option('pytest_tap') r = run_command( python, '-c', @@ -511,7 +547,10 @@ if enable_gir test( python_test['name'], python, - args: pytest_args + join_paths(meson.current_source_dir(), python_test['source']), + args: pytest_args + join_paths( + meson.current_source_dir(), + python_test['source'], + ), depends: [numcosmo_gir, numcosmo_math_gir], env: env, protocol: pytest_protocol, diff --git a/tests/test_nc_hicosmo_qgw.c b/tests/test_nc_hicosmo_qgw.c new file mode 100644 index 000000000..3115f0d29 --- /dev/null +++ b/tests/test_nc_hicosmo_qgw.c @@ -0,0 +1,91 @@ +/*************************************************************************** + * test_nc_hicosmo_qgw.c + * + * Tue Feb 2 16:05:43 2024 + * Copyright 2024 Eduardo Barroso + * + ***************************************************************************/ +/* + * numcosmo + * Copyright (C) Mariana Penna Lima 2017 + * numcosmo is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * numcosmo is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#undef GSL_RANGE_CHECK_OFF +#endif /* HAVE_CONFIG_H */ +#include + +#include +#include +#include + +typedef struct _TestNcHIcosmoQGW +{ + NcHICosmo *cosmo; +} TestNcHIcosmoQGW; + +void test_nc_hicosmo_qgw_new (TestNcHIcosmoQGW *test, gconstpointer pdata); +void test_nc_hicosmo_qgw_units (TestNcHIcosmoQGW *test, gconstpointer pdata); +void test_nc_hicosmo_qgw_free (TestNcHIcosmoQGW *test, gconstpointer pdata); + +gint +main (gint argc, gchar *argv[]) +{ + g_test_init (&argc, &argv, NULL); + ncm_cfg_init_full_ptr (&argc, &argv); + ncm_cfg_enable_gsl_err_handler (); + + g_test_add ("/nc/hicosmo_qgw/units", TestNcHIcosmoQGW, NULL, + &test_nc_hicosmo_qgw_new, + &test_nc_hicosmo_qgw_units, + &test_nc_hicosmo_qgw_free); + + g_test_run (); +} + +void +test_nc_hicosmo_qgw_free (TestNcHIcosmoQGW *test, gconstpointer pdata) +{ + NCM_TEST_FREE (nc_hicosmo_free, test->cosmo); +} + +void +test_nc_hicosmo_qgw_new (TestNcHIcosmoQGW *test, gconstpointer pdata) +{ + test->cosmo = NC_HICOSMO (nc_hicosmo_de_xcdm_new ()); + + g_assert_true (test->cosmo != NULL); + + ncm_model_orig_param_set (NCM_MODEL (test->cosmo), NC_HICOSMO_DE_H0, 70.0); + ncm_model_orig_param_set (NCM_MODEL (test->cosmo), NC_HICOSMO_DE_OMEGA_C, 0.255); + ncm_model_orig_param_set (NCM_MODEL (test->cosmo), NC_HICOSMO_DE_OMEGA_X, 0.7); + ncm_model_orig_param_set (NCM_MODEL (test->cosmo), NC_HICOSMO_DE_T_GAMMA0, 2.7245); + ncm_model_orig_param_set (NCM_MODEL (test->cosmo), NC_HICOSMO_DE_OMEGA_B, 0.045); + ncm_model_orig_param_set (NCM_MODEL (test->cosmo), NC_HICOSMO_DE_XCDM_W, -1.0); + nc_hicosmo_de_omega_x2omega_k (NC_HICOSMO_DE (test->cosmo)); + ncm_model_param_set_by_name (NCM_MODEL (test->cosmo), "Omegak", 0.0); + +} + +void +test_nc_hicosmo_qgw_units (TestNcHIcosmoQGW *test, gconstpointer pdata) +{ + NcHICosmo *cosmo = test->cosmo; + gdouble units = 1.0; + //g_assert_true(NC_IS_HICOSMO_QGW(cosmo)); + /*nc_hicosmo_qgw_set_units(cosmo, units);*/ + +} diff --git a/tests/test_ncm_fftlog.c b/tests/test_ncm_fftlog.c index 8a3702c8f..4959d5553 100644 --- a/tests/test_ncm_fftlog.c +++ b/tests/test_ncm_fftlog.c @@ -65,6 +65,7 @@ void test_ncm_fftlog_setget (TestNcmFftlog *test, gconstpointer pdata); void test_ncm_fftlog_eval (TestNcmFftlog *test, gconstpointer pdata); void test_ncm_fftlog_eval_vector (TestNcmFftlog *test, gconstpointer pdata); void test_ncm_fftlog_eval_calibrate (TestNcmFftlog *test, gconstpointer pdata); +void test_ncm_fftlog_eval_calibrate_fail (TestNcmFftlog *test, gconstpointer pdata); void test_ncm_fftlog_eval_serialized (TestNcmFftlog *test, gconstpointer pdata); void test_ncm_fftlog_eval_deriv (TestNcmFftlog *test, gconstpointer pdata); void test_ncm_fftlog_eval_use_eval_int (TestNcmFftlog *test, gconstpointer pdata); @@ -88,6 +89,7 @@ TestCases tests[] = { {"eval", &test_ncm_fftlog_eval}, {"eval/vector", &test_ncm_fftlog_eval_vector}, {"eval/calibrate", &test_ncm_fftlog_eval_calibrate}, + {"eval/calibrate/fail", &test_ncm_fftlog_eval_calibrate_fail}, {"eval/serialized", &test_ncm_fftlog_eval_serialized}, {"eval/deriv", &test_ncm_fftlog_eval_deriv}, {"eval/use_eval_int", &test_ncm_fftlog_eval_use_eval_int}, @@ -323,12 +325,12 @@ test_ncm_fftlog_gausswin2_new (TestNcmFftlog *test, gconstpointer pdata) void test_ncm_fftlog_sbessel_j_new (TestNcmFftlog *test, gconstpointer pdata) { - const guint N = g_test_rand_int_range (1000, 2000); - const guint ell = g_test_rand_int_range (0, 10); + const guint N = g_test_rand_int_range (3800, 4000); + const guint ell = g_test_rand_int_range (0, 5); NcmFftlog *fftlog = NCM_FFTLOG (ncm_fftlog_sbessel_j_new (ell, 0.0, 0.0, 20.0, N)); TestNcmFftlogK *argK = g_new (TestNcmFftlogK, 1); TestNcmFftlogPlaw *arg = g_new (TestNcmFftlogPlaw, 1); - gdouble Lk = g_test_rand_double_range (log (1.0e+3), log (1.0e+4)); + gdouble Lk = g_test_rand_double_range (log (9.0e+3), log (1.0e+4)); test->fftlog = fftlog; test->Fk.function = &_test_ncm_fftlog_plaw; @@ -337,13 +339,13 @@ test_ncm_fftlog_sbessel_j_new (TestNcmFftlog *test, gconstpointer pdata) test->KFk.params = argK; test->argK = argK; - test->lnk_i = g_test_rand_double_range (log (1.0e-6), log (1.0e-4)); + test->lnk_i = g_test_rand_double_range (log (1.0e-6), log (4.0e-6)); test->lnk_f = test->lnk_i + Lk; test->ntests = NTESTS; arg->lnA = g_test_rand_double_range (log (1.0e-10), log (1.0e+10)); - arg->ns = g_test_rand_double_range (0.5, 1.5); + arg->ns = g_test_rand_double_range (0.5, 0.6); argK->lnr = 0.0; argK->Fk = test->Fk; @@ -363,12 +365,12 @@ test_ncm_fftlog_sbessel_j_new (TestNcmFftlog *test, gconstpointer pdata) void test_ncm_fftlog_sbessel_j_q0_5_new (TestNcmFftlog *test, gconstpointer pdata) { - const guint N = g_test_rand_int_range (1000, 2000); - const guint ell = g_test_rand_int_range (0, 10); + const guint N = g_test_rand_int_range (3800, 4000); + const guint ell = g_test_rand_int_range (0, 5); NcmFftlog *fftlog = NCM_FFTLOG (ncm_fftlog_sbessel_j_new (ell, 0.0, 0.0, 20.0, N)); TestNcmFftlogK *argK = g_new (TestNcmFftlogK, 1); TestNcmFftlogPlaw *arg = g_new (TestNcmFftlogPlaw, 1); - gdouble Lk = g_test_rand_double_range (log (1.0e+3), log (1.0e+4)); + gdouble Lk = g_test_rand_double_range (log (9.0e+3), log (1.0e+4)); test->fftlog = fftlog; test->Fk.function = &_test_ncm_fftlog_plaw; @@ -383,7 +385,7 @@ test_ncm_fftlog_sbessel_j_q0_5_new (TestNcmFftlog *test, gconstpointer pdata) test->ntests = NTESTS; arg->lnA = g_test_rand_double_range (log (1.0e-10), log (1.0e+10)); - arg->ns = g_test_rand_double_range (0.5, 1.5); + arg->ns = g_test_rand_double_range (0.5, 0.6); argK->lnr = 0.0; argK->Fk = test->Fk; @@ -542,7 +544,6 @@ void test_ncm_fftlog_eval (TestNcmFftlog *test, gconstpointer pdata) { NcmFftlog *fftlog = test->fftlog; - guint nerr = 0; gdouble reltol = 1.0e-1; NcmVector *lnr; guint i, len; @@ -569,10 +570,7 @@ test_ncm_fftlog_eval (TestNcmFftlog *test, gconstpointer pdata) test->argK->lnr = lnr_l; ncm_integral_locked_a_b (&test->KFk, test->lnk_i, test->lnk_f, 0.0, 1.0e-3, &res, &err); - if ((fabs (fftlog_res / res - 1.0) > reltol) && (nerr < 15)) - nerr++; - else - ncm_assert_cmpdouble_e (res, ==, fftlog_res, reltol, 0.0); + ncm_assert_cmpdouble_e (res, ==, fftlog_res, reltol, 0.0); /* printf ("%u % 22.15g % 22.15g % 22.15g % 22.15e\n", l, test->argK->lnr, res, fftlog_res, fabs (res / fftlog_res - 1.0)); */ } @@ -582,7 +580,6 @@ void test_ncm_fftlog_eval_vector (TestNcmFftlog *test, gconstpointer pdata) { NcmFftlog *fftlog = test->fftlog; - guint nerr = 0; gdouble reltol = 1.0e-1; guint len = ncm_fftlog_get_size (fftlog); NcmVector *lnk = ncm_vector_new (len); @@ -623,10 +620,7 @@ test_ncm_fftlog_eval_vector (TestNcmFftlog *test, gconstpointer pdata) test->argK->lnr = lnr_l; ncm_integral_locked_a_b (&test->KFk, test->lnk_i, test->lnk_f, 0.0, 1.0e-3, &res, &err); - if ((fabs (fftlog_res / res - 1.0) > reltol) && (nerr < 15)) - nerr++; - else - ncm_assert_cmpdouble_e (res, ==, fftlog_res, reltol, 0.0); + ncm_assert_cmpdouble_e (res, ==, fftlog_res, reltol, 0.0); /* printf ("%u % 22.15g % 22.15g % 22.15g % 22.15e\n", l, test->argK->lnr, res, fftlog_res, fabs (res / fftlog_res - 1.0)); */ } @@ -636,7 +630,6 @@ void test_ncm_fftlog_eval_calibrate (TestNcmFftlog *test, gconstpointer pdata) { NcmFftlog *fftlog = test->fftlog; - guint nerr = 0; gdouble reltol = 1.0e-1; NcmVector *lnr; guint i, len; @@ -657,13 +650,27 @@ test_ncm_fftlog_eval_calibrate (TestNcmFftlog *test, gconstpointer pdata) test->argK->lnr = lnr_l; ncm_integral_locked_a_b (&test->KFk, test->lnk_i, test->lnk_f, 0.0, 1.0e-3, &res, &err); - if ((fabs (fftlog_res / res - 1.0) > reltol) && (nerr < 15)) - nerr++; - else - ncm_assert_cmpdouble_e (res, ==, fftlog_res, reltol, 0.0); + ncm_assert_cmpdouble_e (res, ==, fftlog_res, reltol, 0.0); + } +} - /* printf ("%u % 22.15g % 22.15g % 22.15g % 22.15e\n", l, test->argK->lnr, res, fftlog_res, fabs (res / fftlog_res - 1.0)); */ +void +test_ncm_fftlog_eval_calibrate_fail (TestNcmFftlog *test, gconstpointer pdata) +{ + if (g_test_subprocess ()) + { + NcmFftlog *fftlog = test->fftlog; + + ncm_fftlog_set_max_size (fftlog, 100); + + ncm_fftlog_calibrate_size (fftlog, test->Fk.function, test->Fk.params, 1.0e-1); + + return; /* LCOV_EXCL_LINE */ } + + g_test_trap_subprocess (NULL, 0, 0); + g_test_trap_assert_passed (); + g_test_trap_assert_stdout ("*maximum number of knots reached. Requested precision*"); } void @@ -671,7 +678,6 @@ test_ncm_fftlog_eval_serialized (TestNcmFftlog *test, gconstpointer pdata) { NcmSerialize *ser = ncm_serialize_new (NCM_SERIALIZE_OPT_NONE); NcmFftlog *fftlog = NCM_FFTLOG (ncm_serialize_dup_obj (ser, G_OBJECT (test->fftlog))); - guint nerr = 0; gdouble reltol = 1.0e-1; NcmVector *lnr; guint i, len; @@ -691,10 +697,7 @@ test_ncm_fftlog_eval_serialized (TestNcmFftlog *test, gconstpointer pdata) test->argK->lnr = lnr_l; ncm_integral_locked_a_b (&test->KFk, test->lnk_i, test->lnk_f, 0.0, 1.0e-3, &res, &err); - if ((fabs (fftlog_res / res - 1.0) > reltol) && (nerr < 15)) - nerr++; - else - ncm_assert_cmpdouble_e (res, ==, fftlog_res, reltol, 0.0); + ncm_assert_cmpdouble_e (res, ==, fftlog_res, reltol, 0.0); /* printf ("%u % 22.15g % 22.15g % 22.15g % 22.15e\n", l, test->argK->lnr, res, fftlog_res, fabs (res / fftlog_res - 1.0)); */ } @@ -707,7 +710,6 @@ void test_ncm_fftlog_eval_deriv (TestNcmFftlog *test, gconstpointer pdata) { NcmFftlog *fftlog = test->fftlog; - guint nerr = 0; gdouble reltol = 1.0e-1; NcmVector *lnr; guint i, len; @@ -740,12 +742,7 @@ test_ncm_fftlog_eval_deriv (TestNcmFftlog *test, gconstpointer pdata) test->argK->lnr = lnr_l; ncm_integral_locked_a_b (&test->KFk, test->lnk_i, test->lnk_f, 0.0, 1.0e-3, &res, &err); - if ((fabs (fftlog_res / res - 1.0) > reltol) && (nerr < 15)) - nerr++; - else - ncm_assert_cmpdouble_e (res, ==, fftlog_res, reltol, 0.0); - - /* printf ("%u % 22.15g % 22.15g % 22.15g % 22.15e\n", l, test->argK->lnr, res, fftlog_res, fabs (res / fftlog_res - 1.0)); */ + ncm_assert_cmpdouble_e (res, ==, fftlog_res, reltol, 0.0); } } @@ -753,7 +750,6 @@ void test_ncm_fftlog_eval_use_eval_int (TestNcmFftlog *test, gconstpointer pdata) { NcmFftlog *fftlog = test->fftlog; - guint nerr = 0; gdouble reltol = 1.0e-1; NcmVector *lnr; guint i, len; @@ -790,12 +786,7 @@ test_ncm_fftlog_eval_use_eval_int (TestNcmFftlog *test, gconstpointer pdata) test->argK->lnr = lnr_l; ncm_integral_locked_a_b (&test->KFk, test->lnk_i, test->lnk_f, 0.0, 1.0e-3, &res, &err); - if ((fabs (fftlog_res / res - 1.0) > reltol) && (nerr < 15)) - nerr++; - else - ncm_assert_cmpdouble_e (res, ==, fftlog_res, reltol, 0.0); - - /* printf ("%u % 22.15g % 22.15g % 22.15g % 22.15e\n", l, test->argK->lnr, res, fftlog_res, fabs (res / fftlog_res - 1.0)); */ + ncm_assert_cmpdouble_e (res, ==, fftlog_res, reltol, 0.0); } } diff --git a/tests/test_ncm_generic.c b/tests/test_ncm_generic.c index 9cf55b581..b6aab6e8a 100644 --- a/tests/test_ncm_generic.c +++ b/tests/test_ncm_generic.c @@ -45,6 +45,13 @@ void test_ncm_mpi_job_test_basic (void); void test_ncm_mpi_job_fit_basic (void); void test_ncm_mpi_job_mcmc_basic (void); void test_ncm_mpi_job_feval_basic (void); +void test_ncm_powspec_spline2d_basic (void); + +void test_nc_de_cont_basic (void); +void test_nc_hicosmo_qgw_basic (void); +void test_nc_hipert_adiab_basic (void); +void test_nc_hipert_em_basic (void); +void test_nc_hipert_gw_basic (void); gint main (gint argc, gchar *argv[]) @@ -66,6 +73,14 @@ main (gint argc, gchar *argv[]) g_test_add_func ("/ncm/mpi_job_fit/basic", test_ncm_mpi_job_fit_basic); g_test_add_func ("/ncm/mpi_job_mcmc/basic", test_ncm_mpi_job_mcmc_basic); g_test_add_func ("/ncm/mpi_job_feval/basic", test_ncm_mpi_job_feval_basic); + g_test_add_func ("/ncm/powspec_spline2d/basic", test_ncm_powspec_spline2d_basic); + + g_test_add_func ("/nc/de_cont/basic", test_nc_de_cont_basic); + g_test_add_func ("/nc/hicosmo/qgw/basic", test_nc_hicosmo_qgw_basic); + + g_test_add_func ("/nc/hipert/adiab/basic", test_nc_hipert_adiab_basic); + g_test_add_func ("/nc/hipert/em/basic", test_nc_hipert_em_basic); + g_test_add_func ("/nc/hipert/gw/basic", test_nc_hipert_gw_basic); g_test_run (); } @@ -301,3 +316,135 @@ test_ncm_mpi_job_feval_basic (void) NCM_TEST_FREE (ncm_mset_free, mset); } +void +test_ncm_powspec_spline2d_basic (void) +{ + gdouble x[6] = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0}; + gdouble y[7] = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0}; + gdouble z[42] = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, }; + NcmVector *xv = ncm_vector_new_data_static (x, 6, 1); + NcmVector *yv = ncm_vector_new_data_static (y, 7, 1); + NcmMatrix *zm = ncm_matrix_new_data_static (z, 7, 6); + NcmSpline *sc = ncm_spline_cubic_notaknot_new (); + NcmSpline2d *sb2d = ncm_spline2d_bicubic_new (sc); + + ncm_spline2d_set (NCM_SPLINE2D (sb2d), xv, yv, zm, FALSE); + + { + NcmPowspecSpline2d *ps_s2d = ncm_powspec_spline2d_new (NCM_SPLINE2D (sb2d)); + NcmPowspecSpline2d *ps_s2d2; + + g_assert_true (ps_s2d != NULL); + g_assert_true (NCM_IS_POWSPEC_SPLINE2D (ps_s2d)); + + ps_s2d2 = ncm_powspec_spline2d_ref (ps_s2d); + ncm_powspec_spline2d_clear (&ps_s2d2); + g_assert_true (ps_s2d2 == NULL); + + g_assert_true (NCM_IS_POWSPEC_SPLINE2D (ps_s2d)); + + ncm_vector_free (xv); + ncm_vector_free (yv); + ncm_matrix_free (zm); + ncm_spline_free (NCM_SPLINE (sc)); + + NCM_TEST_FREE (ncm_powspec_spline2d_free, ps_s2d); + NCM_TEST_FREE (ncm_spline2d_free, NCM_SPLINE2D (sb2d)); + } +} + +void +test_nc_hicosmo_qgw_basic (void) +{ + NcHICosmoQGW *qgw = nc_hicosmo_qgw_new (); + + g_assert_true (qgw != NULL); + g_assert_true (NC_IS_HICOSMO_QGW (qgw)); + + NCM_TEST_FREE (nc_hicosmo_free, NC_HICOSMO (qgw)); +} + +void +test_nc_de_cont_basic (void) +{ + NcDECont *dec = nc_de_cont_new (0.3, 0.7, 0.01, 0.01); + NcDECont *dec2; + + g_assert_true (dec != NULL); + g_assert_true (NC_IS_DE_CONT (dec)); + + dec2 = nc_de_cont_ref (dec); + nc_de_cont_clear (&dec2); + g_assert_true (dec2 == NULL); + + g_assert_true (NC_IS_DE_CONT (dec)); + + nc_de_cont_set_k (dec, 0.1); + g_assert_cmpfloat (nc_de_cont_get_k (dec), ==, 0.1); + + NCM_TEST_FREE (nc_de_cont_free, dec); +} + +void +test_nc_hipert_adiab_basic (void) +{ + NcHIPertAdiab *adiab = nc_hipert_adiab_new (); + NcHIPertAdiab *adiab2; + + g_assert_true (adiab != NULL); + g_assert_true (NC_IS_HIPERT_ADIAB (adiab)); + + adiab2 = nc_hipert_adiab_ref (adiab); + nc_hipert_adiab_clear (&adiab2); + g_assert_true (adiab2 == NULL); + + g_assert_true (NC_IS_HIPERT_ADIAB (adiab)); + + nc_hipert_adiab_set_k (adiab, 0.1); + g_assert_cmpfloat (nc_hipert_adiab_get_k (adiab), ==, 0.1); + + NCM_TEST_FREE (nc_hipert_adiab_free, adiab); +} + +void +test_nc_hipert_em_basic (void) +{ + NcHIPertEM *em = nc_hipert_em_new (); + NcHIPertEM *em2; + + g_assert_true (em != NULL); + g_assert_true (NC_IS_HIPERT_EM (em)); + + em2 = nc_hipert_em_ref (em); + nc_hipert_em_clear (&em2); + g_assert_true (em2 == NULL); + + g_assert_true (NC_IS_HIPERT_EM (em)); + + nc_hipert_em_set_k (em, 0.1); + g_assert_cmpfloat (nc_hipert_em_get_k (em), ==, 0.1); + + NCM_TEST_FREE (nc_hipert_em_free, em); +} + +void +test_nc_hipert_gw_basic (void) +{ + NcHIPertGW *gw = nc_hipert_gw_new (); + NcHIPertGW *gw2; + + g_assert_true (gw != NULL); + g_assert_true (NC_IS_HIPERT_GW (gw)); + + gw2 = nc_hipert_gw_ref (gw); + nc_hipert_gw_clear (&gw2); + g_assert_true (gw2 == NULL); + + g_assert_true (NC_IS_HIPERT_GW (gw)); + + nc_hipert_gw_set_k (gw, 0.1); + g_assert_cmpfloat (nc_hipert_gw_get_k (gw), ==, 0.1); + + NCM_TEST_FREE (nc_hipert_gw_free, gw); +} + diff --git a/tests/test_py_constants.py b/tests/test_py_constants.py index e88f54328..076ce706a 100644 --- a/tests/test_py_constants.py +++ b/tests/test_py_constants.py @@ -92,6 +92,7 @@ def test_constants_scipy(): assert_allclose(Ncm.C.G(), constants.G) assert_allclose(Ncm.C.hbar(), constants.hbar) assert_allclose(Ncm.C.thomson_cs(), physical_constants["Thomson cross section"][0]) + assert_allclose(Ncm.C.magnetic_constant(), constants.mu_0) assert_allclose(Ncm.C.mass_p(), constants.m_p) assert_allclose(Ncm.C.mass_e(), constants.m_e) assert_allclose(Ncm.C.mass_n(), constants.m_n) @@ -114,6 +115,7 @@ def test_constants_derived(): assert_allclose(Ncm.C.Glightyear_Mpc(), 1.0e9 * u.lyr.to(u.Mpc)) assert_allclose(Ncm.C.hc(), constants.h * constants.c) assert_allclose(Ncm.C.fine_struct_square(), constants.alpha**2) + assert_allclose(Ncm.C.electric_constant(), constants.epsilon_0) assert_allclose( Ncm.C.AR(), 4.0 * physical_constants["Stefan-Boltzmann constant"][0] / constants.c, @@ -122,9 +124,7 @@ def test_constants_derived(): assert_allclose( Ncm.C.planck_length2(), constants.hbar * constants.G / constants.c**3 ) - assert_allclose( - Ncm.C.rest_energy_atomic(), constants.atomic_mass * constants.c**2 - ) + assert_allclose(Ncm.C.rest_energy_atomic(), constants.atomic_mass * constants.c**2) assert_allclose(Ncm.C.rest_energy_e(), constants.m_e * constants.c**2) assert_allclose(Ncm.C.rest_energy_p(), constants.m_p * constants.c**2) assert_allclose(Ncm.C.rest_energy_n(), constants.m_n * constants.c**2) diff --git a/tests/test_py_csq1d.py b/tests/test_py_csq1d.py index d2a2008d1..bc317d456 100644 --- a/tests/test_py_csq1d.py +++ b/tests/test_py_csq1d.py @@ -23,10 +23,11 @@ # with this program. If not, see . """Tests on NcmCSQ1D class.""" - import math +import pytest + from numpy.testing import assert_allclose -from scipy.special import hankel1e # pylint: disable=no-name-in-module +from scipy.special import hankel1e, jv, yv # pylint: disable=no-name-in-module import numpy as np from numcosmo_py import Ncm @@ -37,42 +38,76 @@ class BesselTest(Ncm.CSQ1D): """Test class for NcmCSQ1D.""" - def __init__(self, alpha=2.0): - """Constructor for BesselTest class.""" + def __init__(self, alpha=2.0, k=1.0, adiab=True): + """Initialize BesselTest.""" Ncm.CSQ1D.__init__(self) self.alpha = alpha + self.k = k + if adiab: + self.t_sign = -1.0 + else: + self.t_sign = 1.0 + + def set_k(self, k): + """Set k parameter.""" + self.k = k - def do_eval_m(self, _model, x, _k): # pylint: disable=arguments-differ + def get_k(self): + """Get k parameter.""" + return self.k + + def do_eval_m(self, _model, x): # pylint: disable=arguments-differ """Evaluate m function, m = (-x)**(1+2alpha).""" - return (-x) ** (1.0 + 2.0 * self.alpha) + return (self.t_sign * x) ** (1.0 + 2.0 * self.alpha) - def do_eval_nu(self, _model, _x, k): # pylint: disable=arguments-differ + def do_eval_nu(self, _model, _x): # pylint: disable=arguments-differ """Evaluate nu2 function, nu = k.""" - return k + return self.k - def do_eval_nu2(self, _model, _x, k): # pylint: disable=arguments-differ + def do_eval_nu2(self, _model, _x): # pylint: disable=arguments-differ """Evaluate nu2 function, nu2 = k**2.""" - return k**2 + return self.k**2 - def do_eval_xi(self, _model, x, k): # pylint: disable=arguments-differ + def do_eval_xi(self, _model, x): # pylint: disable=arguments-differ """Evaluate xi function, xi = ln(m*nu).""" - return math.log(k) + (1.0 + 2.0 * self.alpha) * math.log(-x) + return math.log(self.k) + (1.0 + 2.0 * self.alpha) * math.log(self.t_sign * x) - def do_eval_F1(self, _model, x, k): # pylint: disable=arguments-differ + def do_eval_F1(self, _model, x): # pylint: disable=arguments-differ """Evaluate F1 function, F1 = xi'/(2nu).""" - return 0.5 * (1.0 + 2.0 * self.alpha) / (x * k) + return 0.5 * (1.0 + 2.0 * self.alpha) / (x * self.k) - def do_eval_F2(self, _model, x, k): # pylint: disable=arguments-differ + def do_eval_F2(self, _model, x): # pylint: disable=arguments-differ """Evaluate F2 function, F2 = F1'/(2nu).""" - return -0.25 * (1.0 + 2.0 * self.alpha) / (x * k) ** 2 + return -0.25 * (1.0 + 2.0 * self.alpha) / (x * self.k) ** 2 + + def do_eval_int_1_m(self, _model, t): # pylint: disable=arguments-differ + """Evaluate int_1_m function, int_1_m.""" + return ( + -self.t_sign * (t * self.t_sign) ** (-2.0 * self.alpha) / (2.0 * self.alpha) + ) + + def do_eval_int_mnu2(self, _model, t): # pylint: disable=arguments-differ + """Evaluate int_mnu2 function, int_mnu2.""" + return (self.k**2 * t * (t * self.t_sign) ** (2.0 * self.alpha + 1.0)) / ( + 2.0 * (self.alpha + 1.0) + ) + + def do_eval_int_qmnu2(self, _model, t): # pylint: disable=arguments-differ + """Evaluate int_qmnu2 function, int_qmnu2.""" + return -((self.k * t) ** 2 / (4.0 * self.alpha)) + + def do_eval_int_q2mnu2(self, _model, t): # pylint: disable=arguments-differ + """Evaluate int_q2mnu2 function, int_q2mnu2.""" + return ((self.k * t) ** 2 * (t * self.t_sign) ** (-2.0 * self.alpha)) / ( + 8.0 * self.t_sign * self.alpha**2 * (1.0 - self.alpha) + ) def do_prepare(self, _model): # pylint: disable=arguments-differ - pass + """Prepare method, nothing to do.""" -def test_py_csq1d(): +def test_csq1d(): """Test basic functionality of NcmCSQ1D.""" - bs = BesselTest(alpha=2.0) bs.set_k(1.0) @@ -101,16 +136,21 @@ def test_py_csq1d(): bs.set_save_evol(False) assert not bs.get_save_evol() - bs.set_max_order_2(True) - assert bs.get_max_order_2() + bs.set_initial_condition_type(Ncm.CSQ1DInitialStateType.AD_HOC) + assert bs.get_initial_condition_type() == Ncm.CSQ1DInitialStateType.AD_HOC - bs.set_max_order_2(False) - assert not bs.get_max_order_2() + bs.set_initial_condition_type(Ncm.CSQ1DInitialStateType.ADIABATIC2) + assert bs.get_initial_condition_type() == Ncm.CSQ1DInitialStateType.ADIABATIC2 + bs.set_initial_condition_type(Ncm.CSQ1DInitialStateType.ADIABATIC4) + assert bs.get_initial_condition_type() == Ncm.CSQ1DInitialStateType.ADIABATIC4 + + bs.set_initial_condition_type(Ncm.CSQ1DInitialStateType.NONADIABATIC2) + assert bs.get_initial_condition_type() == Ncm.CSQ1DInitialStateType.NONADIABATIC2 -def test_py_initial_conditions_time(): - """Test initial conditions of NcmCSQ1D.""" +def test_initial_conditions_time(): + """Test initial conditions of NcmCSQ1D.""" bs = BesselTest(alpha=2.0) bs.set_k(1.0) bs.set_ti(-100.0) @@ -124,18 +164,18 @@ def test_py_initial_conditions_time(): t_min, F1_min, t_lb, t_ub = bs.find_adiab_max(None, -1.0e3, -1.0e1, 1.0e-1) - assert_allclose(F1_min, bs.eval_F1(None, t_min, bs.get_k())) - assert math.fabs(F1_min - bs.eval_F1(None, t_lb, bs.get_k())) <= 1.0e-1 - assert math.fabs(F1_min - bs.eval_F1(None, t_ub, bs.get_k())) <= 1.0e-1 + assert_allclose(F1_min, bs.eval_F1(None, t_min)) + assert math.fabs(F1_min - bs.eval_F1(None, t_lb)) <= 1.0e-1 + assert math.fabs(F1_min - bs.eval_F1(None, t_ub)) <= 1.0e-1 -def test_py_initial_conditions_adiabatic(): +def test_initial_conditions_adiabatic(): """Test initial conditions of NcmCSQ1D.""" - bs = BesselTest(alpha=2.0) bs.set_k(1.0) bs.set_ti(-100.0) bs.set_tf(-1.0e-3) + state = Ncm.CSQ1DState.new() for prec in np.geomspace(1.0e-14, 1.0e-6, 100): limit_found, t_adiab = bs.find_adiab_time_limit(None, -1.0e4, -1.0e1, prec) @@ -143,8 +183,9 @@ def test_py_initial_conditions_adiabatic(): assert limit_found # Getting the adiabatic solution - alpha, dgamma, _alpha_reltol, _dgamma_reltol = bs.eval_adiab_at(None, t_adiab) - phi_vec, Pphi_vec = bs.alpha_dgamma_to_phi_Pphi(None, t_adiab, alpha, dgamma) + state, _alpha_reltol, _dgamma_reltol = bs.compute_adiab(None, t_adiab, state) + bs.change_frame(None, state, Ncm.CSQ1DFrame.ORIG) + phi_vec, Pphi_vec = state.get_phi_Pphi() phi = phi_vec[0] + 1.0j * phi_vec[1] Pphi = Pphi_vec[0] + 1.0j * Pphi_vec[1] @@ -162,15 +203,62 @@ def test_py_initial_conditions_adiabatic(): assert_allclose(abs(Pphi), abs(theo_Pphi), rtol=1.0e-6) -def test_py_evolution(): +def test_evolution(): """Test initial conditions of NcmCSQ1D.""" + bs = BesselTest(alpha=2.0) + bs.set_k(1.0) + bs.set_ti(-1.0e4) + bs.set_tf(-1.0e-3) + state = Ncm.CSQ1DState.new() + + bs.set_save_evol(True) + bs.set_reltol(1.0e-10) + bs.set_abstol(0.0) + bs.set_initial_condition_type(Ncm.CSQ1DInitialStateType.ADIABATIC4) + bs.set_vacuum_max_time(-1.0e1) + bs.set_vacuum_reltol(1.0e-8) + bs.prepare(None) + + t_a, _smaller_abst = bs.get_time_array() + + for t in t_a: + state = bs.eval_at(None, t, state) + phi_vec, Pphi_vec = state.get_phi_Pphi() + + phi = phi_vec[0] + 1.0j * phi_vec[1] + Pphi = Pphi_vec[0] + 1.0j * Pphi_vec[1] + + kt = bs.get_k() * t + hfnormm = 0.5 * math.sqrt(math.pi) * (-t) ** (-bs.alpha) + hfnormp = 0.5 * math.sqrt(math.pi) * (-t) ** (+bs.alpha) + + # Analytical solution for phi and Pphi + theo_phi = hfnormm * hankel1e(bs.alpha, kt) + theo_Pphi = kt * hfnormp * hankel1e(1.0 + bs.alpha, kt) + + # Compare with analytical solution + assert_allclose(abs(phi), abs(theo_phi), rtol=1.0e-7) + assert_allclose(abs(Pphi), abs(theo_Pphi), rtol=1.0e-7) + + J11, J12, J22 = state.get_J() + + assert_allclose(J11, 2.0 * abs(phi) ** 2, atol=1.0e-7) + assert_allclose(J22, 2.0 * abs(Pphi) ** 2, atol=1.0e-7) + assert_allclose(J12, (2.0 * phi * Pphi.conjugate()).real, atol=1.0e-7) + +def test_evolution_adiabatic2(): + """Test initial conditions of NcmCSQ1D.""" bs = BesselTest(alpha=2.0) + bs.set_initial_condition_type(Ncm.CSQ1DInitialStateType.ADIABATIC2) bs.set_k(1.0) - bs.set_ti(-100.0) + bs.set_ti(-1.0e5) bs.set_tf(-1.0e-3) + bs.set_vacuum_max_time(-1.0e0) + bs.set_vacuum_reltol(1.0e-3) + state = Ncm.CSQ1DState.new() - limit_found, t_adiab = bs.find_adiab_time_limit(None, -1.0e4, -1.0e1, 1.0e-8) + limit_found, t_adiab = bs.find_adiab_time_limit(None, -1.0e5, -1.0e0, 1.0e-3) assert limit_found @@ -183,8 +271,8 @@ def test_py_evolution(): t_a, _smaller_abst = bs.get_time_array() for t in t_a: - alpha, dgamma = bs.eval_at(t) - phi_vec, Pphi_vec = bs.alpha_dgamma_to_phi_Pphi(None, t, alpha, dgamma) + state = bs.eval_at(None, t, state) + phi_vec, Pphi_vec = state.get_phi_Pphi() phi = phi_vec[0] + 1.0j * phi_vec[1] Pphi = Pphi_vec[0] + 1.0j * Pphi_vec[1] @@ -201,15 +289,357 @@ def test_py_evolution(): assert_allclose(abs(phi), abs(theo_phi), rtol=1.0e-7) assert_allclose(abs(Pphi), abs(theo_Pphi), rtol=1.0e-7) - J11, J12, J22 = bs.get_J_at(None, t) + J11, J12, J22 = state.get_J() assert_allclose(J11, 2.0 * abs(phi) ** 2, atol=1.0e-7) assert_allclose(J22, 2.0 * abs(Pphi) ** 2, atol=1.0e-7) assert_allclose(J12, (2.0 * phi * Pphi.conjugate()).real, atol=1.0e-7) +@pytest.mark.parametrize( + "frame", + [Ncm.CSQ1DFrame.ORIG, Ncm.CSQ1DFrame.ADIAB1, Ncm.CSQ1DFrame.ADIAB2], + ids=["orig", "adiab1", "adiab2"], +) +def test_evolution_frame(frame): + """Test initial conditions of NcmCSQ1D.""" + bs = BesselTest(alpha=2.0) + bs.set_k(1.0) + bs.set_ti(-100.0) + state = Ncm.CSQ1DState.new() + + limit_found, t_adiab = bs.find_adiab_time_limit(None, -1.0e4, -1.0e1, 1.0e-8) + assert limit_found + limit_found, t_adiab_end = bs.find_adiab_time_limit(None, -1.0e4, -1.0e0, 1.0e-1) + assert limit_found + bs.set_tf(t_adiab_end) + + bs.set_save_evol(True) + bs.set_reltol(1.0e-10) + bs.set_abstol(0.0) + bs.set_init_cond_adiab(None, t_adiab) + bs.prepare(None) + + t_a, _smaller_abst = bs.get_time_array() + + for t in t_a: + state = bs.eval_at_frame(None, frame, t, state) + assert state.get_frame() == frame + + +def test_change_frame_orig_adiab1(): + """Test change_frame method of NcmCSQ1D.""" + bs = BesselTest(alpha=2.0) + bs.set_k(1.0) + bs.set_ti(-100.0) + bs.set_tf(-1.0e-3) + + t = -2.0e1 + state = Ncm.CSQ1DState() + state.set_ag(Ncm.CSQ1DFrame.ORIG, t, 0.1, 0.3) + + bs.change_frame(None, state, Ncm.CSQ1DFrame.ORIG) + + assert state.get_frame() == Ncm.CSQ1DFrame.ORIG + assert state.get_ag() == (0.1, 0.3) + + bs.change_frame(None, state, Ncm.CSQ1DFrame.ADIAB1) + assert state.get_frame() == Ncm.CSQ1DFrame.ADIAB1 + assert_allclose(state.get_ag(), (0.1, 0.3 - bs.eval_xi(None, t))) + + bs.change_frame(None, state, Ncm.CSQ1DFrame.ORIG) + assert state.get_frame() == Ncm.CSQ1DFrame.ORIG + assert_allclose(state.get_ag(), (0.1, 0.3)) + + +def test_change_frame_orig_adiab2(): + """Test change_frame method of NcmCSQ1D.""" + bs = BesselTest(alpha=2.0) + bs.set_k(1.0) + bs.set_ti(-100.0) + bs.set_tf(-1.0e-3) + + t = -2.0e1 + state = Ncm.CSQ1DState() + state.set_ag(Ncm.CSQ1DFrame.ORIG, t, 0.1, 0.3) + + bs.change_frame(None, state, Ncm.CSQ1DFrame.ORIG) + + assert state.get_frame() == Ncm.CSQ1DFrame.ORIG + assert state.get_ag() == (0.1, 0.3) + + bs.change_frame(None, state, Ncm.CSQ1DFrame.ADIAB2) + assert state.get_frame() == Ncm.CSQ1DFrame.ADIAB2 + assert not np.allclose(state.get_ag(), (0.1, 0.3 - bs.eval_xi(None, t))) + + bs.change_frame(None, state, Ncm.CSQ1DFrame.ORIG) + assert state.get_frame() == Ncm.CSQ1DFrame.ORIG + assert_allclose(state.get_ag(), (0.1, 0.3)) + + +def test_change_frame_adiab1_adiab2(): + """Test change_frame method of NcmCSQ1D.""" + bs = BesselTest(alpha=2.0) + bs.set_k(1.0) + bs.set_ti(-100.0) + bs.set_tf(-1.0e-3) + + t = -2.0e1 + state = Ncm.CSQ1DState() + state.set_ag(Ncm.CSQ1DFrame.ADIAB1, t, 0.1, 0.3) + + bs.change_frame(None, state, Ncm.CSQ1DFrame.ADIAB1) + assert state.get_frame() == Ncm.CSQ1DFrame.ADIAB1 + assert state.get_ag() == (0.1, 0.3) + + bs.change_frame(None, state, Ncm.CSQ1DFrame.ADIAB2) + assert state.get_frame() == Ncm.CSQ1DFrame.ADIAB2 + assert not np.allclose(state.get_ag(), (0.1, 0.3)) + + bs.change_frame(None, state, Ncm.CSQ1DFrame.ADIAB1) + assert state.get_frame() == Ncm.CSQ1DFrame.ADIAB1 + assert_allclose(state.get_ag(), (0.1, 0.3)) + + +def test_nonadiab_prop(): + """Test basic functionality of NcmCSQ1D.""" + k = 8.0 + alpha = 0.5 + bs = BesselTest(alpha=alpha, adiab=False) + bs.set_k(k) + + ti = 0.0 + tii = 1.0e-7 + tf = 2.0 + + bs.prepare_prop(None, ti, tii, tf) + state0 = Ncm.CSQ1DState.new() + state1 = Ncm.CSQ1DState.new() + state0.set_up(Ncm.CSQ1DFrame.NONADIAB1, ti, 0.0, 0.0) + + def theo_phi(t): + """Theoretical phi.""" + prefactor = 0.5 * (1.0 - 1.0j) * math.sqrt(math.pi / 2.0) * (k * t) ** (-alpha) + return prefactor * ( + jv(alpha, k * t) - 1.0j * k ** (2.0 * alpha) * yv(alpha, k * t) + ) + + test_t = np.geomspace(tii, 1.0e-2, 10) + + prop_J11 = [ + bs.evolve_prop_vector(None, state0, Ncm.CSQ1DFrame.ORIG, t, state1).get_J()[0] + for t in test_t + ] + + analytic_J11 = [2.0 * np.abs(theo_phi(t)) ** 2 for t in test_t] + + assert_allclose(prop_J11, analytic_J11, rtol=1.0e-9) + + +def test_nonadiab_approx(): + """Test basic functionality of NcmCSQ1D.""" + k = 8.0 + alpha = 0.5 + bs = BesselTest(alpha=alpha, adiab=False) + bs.set_k(k) + + ti = 0.0 + tii = 1.0e-7 + tf = 2.0 + + bs.prepare_prop(None, ti, tii, tf) + state0 = Ncm.CSQ1DState.new() + state1 = Ncm.CSQ1DState.new() + state0.set_up(Ncm.CSQ1DFrame.NONADIAB1, ti, 0.0, 0.0) + + def theo_phi(t): + """Theoretical phi.""" + prefactor = 0.5 * (1.0 - 1.0j) * math.sqrt(math.pi / 2.0) * (k * t) ** (-alpha) + return prefactor * ( + jv(alpha, k * t) - 1.0j * k ** (2.0 * alpha) * yv(alpha, k * t) + ) + + test_t = np.geomspace(tii, 1.0e-2, 10) + + prop_J11 = [ + bs.change_frame( + None, bs.compute_nonadiab(None, t, state1), Ncm.CSQ1DFrame.ORIG + ).get_J()[0] + for t in test_t + ] + + analytic_J11 = [2.0 * np.abs(theo_phi(t)) ** 2 for t in test_t] + + assert_allclose(prop_J11, analytic_J11, rtol=1.0e-4) + + +def test_nonadiab_evol(): + """Test basic functionality of NcmCSQ1D.""" + k = 8.0 + alpha = 0.5 + bs = BesselTest(alpha=alpha, adiab=False) + bs.set_k(k) + + ti = 0.0 + tii = 1.0e-7 + tf = 2.0 + + bs.prepare_prop(None, ti, tii, tf) + state0 = Ncm.CSQ1DState.new() + state1 = Ncm.CSQ1DState.new() + state = Ncm.CSQ1DState.new() + state0.set_up(Ncm.CSQ1DFrame.NONADIAB1, ti, 0.0, 0.0) + + def theo_phi(t): + """Theoretical phi.""" + prefactor = 0.5 * (1.0 - 1.0j) * math.sqrt(math.pi / 2.0) * (k * t) ** (-alpha) + return prefactor * ( + jv(alpha, k * t) - 1.0j * k ** (2.0 * alpha) * yv(alpha, k * t) + ) + + bs.evolve_prop_vector(None, state0, Ncm.CSQ1DFrame.ORIG, 1.0e-4, state1) + bs.set_init_cond(None, Ncm.CSQ1DEvolState.UP, state1) + bs.set_tf(10.0) + bs.set_reltol(1.0e-14) + bs.prepare(None) + t_a, _smaller_abst = bs.get_time_array() + + evol_J11 = [bs.eval_at(None, t, state).get_J()[0] for t in t_a] + analytic_J11 = [2.0 * np.abs(theo_phi(t)) ** 2 for t in t_a] + + assert_allclose(evol_J11, analytic_J11, rtol=1.0e-7) + + +def test_state_circle(): + """Test circle functionality of NcmCSQ1DState.""" + state = Ncm.CSQ1DState.new() + state.set_up(Ncm.CSQ1DFrame.ORIG, 1.0, 0.1, 0.2) + + for r in np.geomspace(1.0e-4, 1.0e4, 100): + for theta in np.linspace(-4.0 * math.pi, 4.0 * math.pi, 120): + state1 = state.get_circle(r, theta) + assert_allclose(state.compute_distance(state1), r) + + +def test_state_phi_Pphi(): + """Test phi and Pphi functionality of NcmCSQ1DState.""" + state = Ncm.CSQ1DState.new() + alpha_a = np.linspace(-2.0, 2.0, 100) + gamma_a = np.linspace(-2.0, 2.0, 100) + + for alpha, gamma in zip(alpha_a, gamma_a): + state.set_ag(Ncm.CSQ1DFrame.ORIG, 0.0, alpha, gamma) + + phi_v, Pphi_v = state.get_phi_Pphi() + J11, J12, J22 = state.get_J() + + phi = phi_v[0] + 1.0j * phi_v[1] + Pphi = Pphi_v[0] + 1.0j * Pphi_v[1] + phic = phi_v[0] - 1.0j * phi_v[1] + Pphic = Pphi_v[0] - 1.0j * Pphi_v[1] + + assert_allclose(2.0 * phi * phic, J11) + assert_allclose(2.0 * Pphi * Pphic, J22) + assert_allclose(phi * Pphic + phic * Pphi, J12) + assert_allclose(phi * Pphic - phic * Pphi, 1.0j) + + +def test_state_um(): + """Test um functionality of NcmCSQ1DState.""" + state = Ncm.CSQ1DState.new() + alpha_a = np.linspace(-2.0, 2.0, 100) + gamma_a = np.linspace(-2.0, 2.0, 100) + + for alpha, gamma in zip(alpha_a, gamma_a): + state.set_ag(Ncm.CSQ1DFrame.ORIG, 0.0, alpha, gamma) + + chi, Um = state.get_um() + alpha1, gamma1 = state.get_ag() + + state.set_um(Ncm.CSQ1DFrame.ORIG, 0.0, chi, Um) + alpha2, gamma2 = state.get_ag() + + assert_allclose(alpha, alpha1) + assert_allclose(alpha, alpha2) + assert_allclose(gamma, gamma1) + assert_allclose(gamma, gamma2) + assert_allclose(chi, np.sinh(alpha)) + assert_allclose(Um, -gamma + np.log(np.cosh(alpha))) + + +def test_state_up(): + """Test up functionality of NcmCSQ1DState.""" + state = Ncm.CSQ1DState.new() + alpha_a = np.linspace(-2.0, 2.0, 100) + gamma_a = np.linspace(-2.0, 2.0, 100) + + for alpha, gamma in zip(alpha_a, gamma_a): + state.set_ag(Ncm.CSQ1DFrame.ORIG, 0.0, alpha, gamma) + + chi, Up = state.get_up() + alpha1, gamma1 = state.get_ag() + + state.set_up(Ncm.CSQ1DFrame.ORIG, 0.0, chi, Up) + alpha2, gamma2 = state.get_ag() + + assert_allclose(alpha, alpha1) + assert_allclose(alpha, alpha2) + assert_allclose(gamma, gamma1) + assert_allclose(gamma, gamma2) + assert_allclose(chi, np.sinh(alpha)) + assert_allclose(Up, gamma + np.log(np.cosh(alpha))) + + +def test_state_poincare_half_plane(): + """Test poincare_half_plane functionality of NcmCSQ1DState.""" + state = Ncm.CSQ1DState.new() + alpha_a = np.linspace(-2.0, 2.0, 100) + gamma_a = np.linspace(-2.0, 2.0, 100) + + for alpha, gamma in zip(alpha_a, gamma_a): + state.set_ag(Ncm.CSQ1DFrame.ORIG, 0.0, alpha, gamma) + + x, lny = state.get_poincare_half_plane() + chi, Up = state.get_up() + + assert_allclose(x, chi * np.exp(-Up)) + assert_allclose(lny, -Up) + + +def test_state_poincare_disc(): + """Test poincare_disc functionality of NcmCSQ1DState.""" + state = Ncm.CSQ1DState.new() + alpha_a = np.linspace(-2.0, 2.0, 100) + gamma_a = np.linspace(-2.0, 2.0, 100) + + for alpha, gamma in zip(alpha_a, gamma_a): + state.set_ag(Ncm.CSQ1DFrame.ORIG, 0.0, alpha, gamma) + + x, y = state.get_poincare_disc() + chi, Up = state.get_up() + chi, Um = state.get_um() + + assert_allclose(x, chi / (1.0 + 0.5 * (np.exp(Up) + np.exp(Um)))) + assert_allclose( + y, + -0.5 * (np.exp(Up) - np.exp(Um)) / (1.0 + 0.5 * (np.exp(Up) + np.exp(Um))), + ) + + if __name__ == "__main__": - test_py_csq1d() - test_py_initial_conditions_time() - test_py_initial_conditions_adiabatic() - test_py_evolution() + test_csq1d() + test_initial_conditions_time() + test_initial_conditions_adiabatic() + test_evolution() + test_evolution_adiabatic2() + for frame0 in [Ncm.CSQ1DFrame.ORIG, Ncm.CSQ1DFrame.ADIAB1, Ncm.CSQ1DFrame.ADIAB2]: + test_evolution_frame(frame0) + test_change_frame_orig_adiab1() + test_change_frame_orig_adiab2() + test_change_frame_adiab1_adiab2() + test_nonadiab_prop() + test_nonadiab_evol() + test_state_circle() + test_state_phi_Pphi() + test_state_um() + test_state_up() diff --git a/tests/test_py_data_rosenbrock.py b/tests/test_py_data_rosenbrock.py index 31414105a..dc08a1dbf 100644 --- a/tests/test_py_data_rosenbrock.py +++ b/tests/test_py_data_rosenbrock.py @@ -32,7 +32,6 @@ def test_constructor(): """Test constructor.""" - rosenbrock = Ncm.DataRosenbrock.new() assert rosenbrock is not None assert isinstance(rosenbrock, Ncm.DataRosenbrock) @@ -46,7 +45,6 @@ def test_constructor(): def test_eval(): """Test eval.""" - rosenbrock = Ncm.DataRosenbrock() rosenbrock_model = Ncm.ModelRosenbrock.new() mset = Ncm.MSet.new_array([rosenbrock_model]) diff --git a/tests/test_py_data_snia_cov.py b/tests/test_py_data_snia_cov.py new file mode 100644 index 000000000..218b6803a --- /dev/null +++ b/tests/test_py_data_snia_cov.py @@ -0,0 +1,63 @@ +#!/usr/bin/env python +# +# test_py_data_snia_cov.py +# +# Sun Apr 21 11:15:07 2024 +# Copyright 2024 Sandro Dias Pinto Vitenti +# +# +# test_py_data_snia_cov.py +# Copyright (C) 2024 Sandro Dias Pinto Vitenti +# +# numcosmo is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# numcosmo is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . + +"""Tests on NcmDataSNIACov class.""" + +import pytest + +from numcosmo_py import Ncm, Nc + +Ncm.cfg_init() + + +def test_constructor(): + """Test constructor.""" + snia_cov = Nc.DataSNIACov.new(False, 0) + assert snia_cov is not None + assert isinstance(snia_cov, Nc.DataSNIACov) + + snia_cov2 = snia_cov.ref() + assert snia_cov2 == snia_cov + + +@pytest.mark.parametrize( + "cov_id", + [ + Nc.DataSNIAId.COV_JLA_SNLS3_SDSS_SYS_STAT, + Nc.DataSNIAId.COV_JLA_SNLS3_SDSS_SYS_STAT_CMPL, + Nc.DataSNIAId.COV_PANTHEON, + Nc.DataSNIAId.COV_PANTHEON_PLUS_SH0ES_STAT, + Nc.DataSNIAId.COV_PANTHEON_PLUS_SH0ES_SYS_STAT, + Nc.DataSNIAId.COV_SNLS3_STAT_ONLY, + Nc.DataSNIAId.COV_SNLS3_SYS_STAT, + ], +) +def test_constructor_catalog_id(cov_id): + """Test constructor with catalog id.""" + snia_cov = Nc.DataSNIACov.new_from_cat_id(cov_id, True) + assert snia_cov is not None + assert isinstance(snia_cov, Nc.DataSNIACov) + + assert snia_cov.get_dof() > 0 + assert snia_cov.get_length() > 0 diff --git a/tests/test_py_de_cont.py b/tests/test_py_de_cont.py new file mode 100644 index 000000000..4ee001198 --- /dev/null +++ b/tests/test_py_de_cont.py @@ -0,0 +1,136 @@ +# +# test_py_de_cont.py +# +# Sun Apr 21 21:40:35 2024 +# Copyright 2024 Sandro Dias Pinto Vitenti +# +# +# test_de_cont.py +# Copyright (C) 2024 Sandro Dias Pinto Vitenti +# +# numcosmo is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# numcosmo is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . + +"""Tests on NcDECont class.""" + +from numpy.testing import assert_allclose +import numpy as np + +from numcosmo_py import Ncm, Nc + +Ncm.cfg_init() + + +def test_de_cont_setget(): + """Test basic functionality of NcDECont.""" + de_cont = Nc.DECont.new(Omegaw=0.3, OmegaL=0.7, cs2=1.0e-5, w=1.0e-5) + + de_cont.set_reltol(1.0e-12) + de_cont.set_ti(1.0e-8) + de_cont.set_tf(1.0e10) + de_cont.set_k(1.0) + + assert_allclose(de_cont.get_reltol(), 1.0e-12) + assert_allclose(de_cont.get_ti(), 1.0e-8) + assert_allclose(de_cont.get_tf(), 1.0e10) + assert_allclose(de_cont.get_k(), 1.0) + + +def test_de_cont_serialize(): + """Test serialization of NcDECont.""" + de_cont = Nc.DECont.new(Omegaw=0.3, OmegaL=0.7, cs2=1.0e-5, w=1.0e-5) + + de_cont.set_reltol(1.0e-12) + de_cont.set_ti(1.0e-8) + de_cont.set_tf(1.0e10) + de_cont.set_k(1.0) + + ser = Ncm.Serialize.new(Ncm.SerializeOpt.CLEAN_DUP) + de_cont2 = ser.dup_obj(de_cont) + assert de_cont2 is not None + assert de_cont2 is not de_cont + + assert_allclose(de_cont.get_reltol(), de_cont2.get_reltol()) + assert_allclose(de_cont.get_ti(), de_cont2.get_ti()) + assert_allclose(de_cont.get_tf(), de_cont2.get_tf()) + assert_allclose(de_cont.get_k(), de_cont2.get_k()) + + +def test_de_cont_prepare_prop(): + """Test propagator preparation of NcDECont.""" + de_cont = Nc.DECont.new(Omegaw=0.3, OmegaL=0.7, cs2=1.0e-5, w=1.0e-5) + + de_cont.set_reltol(1.0e-12) + de_cont.set_ti(1.0e-8) + de_cont.set_tf(1.0e10) + de_cont.set_k(1.0) + + de_cont.prepare_prop(None, 0.0, 1.0e-30, 1.0e1) + + +def test_de_cont_nonadiab(): + """Test nonadiabatic vacuum approximation of NcDECont.""" + de_cont = Nc.DECont.new(Omegaw=0.3, OmegaL=0.7, cs2=1.0e-5, w=1.0e-5) + + ti = 1.0e-8 + tf = 1.0e-1 + de_cont.set_reltol(1.0e-12) + de_cont.set_ti(ti) + de_cont.set_tf(tf) + de_cont.set_k(1.0) + + de_cont.prepare_prop(None, 0.0, 1.0e-30, 1.0e1) + + state_prop0 = Ncm.CSQ1DState.new() + state_prop0.set_up(Ncm.CSQ1DFrame.NONADIAB1, 0.0, 0.0, 0.0) + + state_prop = Ncm.CSQ1DState.new() + state_nonadiab = Ncm.CSQ1DState.new() + + N = 100 + t_a = np.geomspace(ti, tf, N) + + for frame in [ + Ncm.CSQ1DFrame.ORIG, + Ncm.CSQ1DFrame.NONADIAB1, + Ncm.CSQ1DFrame.NONADIAB2, + ]: + for t in t_a: + de_cont.evolve_prop_vector(None, state_prop0, frame, t, state_prop) + de_cont.compute_nonadiab(None, t, state_nonadiab) + + de_cont.change_frame(None, state_nonadiab, frame) + + assert_allclose( + state_prop.get_phi_Pphi(), state_nonadiab.get_phi_Pphi(), rtol=1.0e-4 + ) + + +def test_de_cont_eval(): + """Test evaluation of NcDECont.""" + de_cont = Nc.DECont.new(Omegaw=0.3, OmegaL=0.7, cs2=1.0e-5, w=1.0e-5) + + ti = 1.0e0 + tf = 1.0e10 + de_cont.set_reltol(1.0e-12) + de_cont.set_ti(ti) + de_cont.set_tf(tf) + de_cont.set_k(1.0) + + N = 100 + t_a = np.geomspace(ti, tf, N) + + for t in t_a: + assert np.isfinite(de_cont.eval_xi(None, t)) + assert np.isfinite(de_cont.eval_F1(None, t)) + assert np.isfinite(de_cont.eval_F2(None, t)) diff --git a/tests/test_py_hicosmo_Vexp.py b/tests/test_py_hicosmo_Vexp.py new file mode 100644 index 000000000..d9a978ff1 --- /dev/null +++ b/tests/test_py_hicosmo_Vexp.py @@ -0,0 +1,306 @@ +#!/usr/bin/env python +# +# test_py_hicosmo_Vexp.py +# +# Sun Apr 14 17:31:52 2023 +# Copyright 2024 Sandro Dias Pinto Vitenti +# +# +# test_py_hicosmo_Vexp.py +# Copyright (C) 2024 Sandro Dias Pinto Vitenti +# +# numcosmo is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# numcosmo is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . + +"""Tests on NcHICosmoVexp cosmological model.""" + +from itertools import product +import pytest +from numpy.testing import assert_allclose +import numpy as np + +from numcosmo_py import Ncm, Nc + +Ncm.cfg_init() + + +@pytest.fixture(name="vexp", params=[1.0e-1, -1.0e-1], ids=["d>0", "d<0"]) +def fixture_vexp(request) -> Nc.HICosmoVexp: + """Fixture for NcHICosmoVexp.""" + vexp = Nc.HICosmoVexp.new() + vexp.props.dphi = request.param # pylint: disable=no-member + + return vexp + + +def test_init(vexp): + """Test NcHICosmoVexp initialization.""" + assert vexp is not None + assert isinstance(vexp, Nc.HICosmoVexp) + assert isinstance(vexp, Nc.HICosmo) + assert isinstance(vexp, Ncm.Model) + + +def test_init_new(vexp): + """Test NcHICosmoVexp initialization with new.""" + assert vexp is not None + assert isinstance(vexp, Nc.HICosmoVexp) + assert isinstance(vexp, Nc.HICosmo) + assert isinstance(vexp, Ncm.Model) + + +def test_hubble_negative_dphi(vexp): + """Test NcHICosmoVexp.hubble.""" + assert vexp is not None + + # Negative d_phi means matching Omega_L in the expansion + # phase. + if vexp.props.dphi < 0.0: # pylint: disable=no-member + assert_allclose(vexp.Omega_t0(), 1.0) + assert_allclose(vexp.E2(0.0), vexp.props.OmegaL) # pylint: disable=no-member + + +def test_hubble_positive_dphi(vexp): + """Test NcHICosmoVexp.hubble.""" + assert vexp is not None + + # Positive d_phi means matching Omega_c in the expansion + # phase. + if vexp.props.dphi > 0.0: # pylint: disable=no-member + assert_allclose(vexp.Omega_t0(), 1.0) + assert_allclose(vexp.E2(0.0), vexp.props.Omegac) # pylint: disable=no-member + + +def test_tau_min_max(vexp): + """Test NcHICosmoVexp.tau_min and NcHICosmoVexp.tau_max.""" + assert vexp is not None + + tau_min = vexp.tau_min() + tau_max = vexp.tau_max() + + assert tau_min < 0.0 + assert tau_max > 0.0 + assert tau_min < tau_max + + +def test_tau_q(vexp): + """Test NcHICosmoVexp.tau_q.""" + assert vexp is not None + + tau_min = vexp.tau_min() + tau_max = vexp.tau_max() + + # Time of the transition classical to quantum during the contraction phase. + tau_qt_c = vexp.tau_qt_c() + # Time of the transition classical to quantum during the expansion phase. + tau_qt_e = vexp.tau_qt_e() + + assert tau_qt_c > tau_min + assert tau_qt_c < tau_max + assert tau_qt_e > tau_min + assert tau_qt_e < tau_max + + assert tau_qt_c < 0.0 + assert tau_qt_e > 0.0 + + +def test_xb(vexp): + """Test NcHICosmoVexp.xb.""" + assert vexp is not None + + xbc = vexp.xbc() + xbe = vexp.xbe() + + assert xbc > 0.0 + assert xbe > 0.0 + + assert_allclose(vexp.tau_xe(xbe), 0.0, atol=1.0e-6) + assert_allclose(vexp.tau_xc(xbc), 0.0, atol=1.0e-6) + + +def _compute_tau_array(vexp, abs_tau_min=1.0e-10): + """Compute an array of tau values for testing. + + This includes a range from tau_min to -abs_tau_min and from abs_tau_min to tau_max. + This is useful since we want to test the behavior of the model around the bounce. + """ + tau_min = vexp.tau_min() + tau_max = vexp.tau_max() + + tau_a = np.concatenate( + ( + np.geomspace(tau_min, -abs_tau_min, 5000), + np.geomspace(abs_tau_min, tau_max, 5000), + ) + ) + return tau_a + + +def test_E_tau_negative_dphi(vexp): + """Test NcHICosmoVexp.E_tau.""" + assert vexp is not None + + tau_a = _compute_tau_array(vexp) + + for tau in tau_a: + assert np.isfinite(vexp.E_tau(tau)) + + tau0c = vexp.tau_xc(1.0) + tau0e = vexp.tau_xe(1.0) + + # Negative d_phi means matching Omega_L in the expansion phase. + if vexp.props.dphi < 0.0: # pylint: disable=no-member + assert_allclose( + vexp.E_tau(tau0c) ** 2, vexp.props.Omegac # pylint: disable=no-member + ) + assert_allclose( + vexp.E_tau(tau0e) ** 2, vexp.props.OmegaL # pylint: disable=no-member + ) + + +def test_E_tau_positive_dphi(vexp): + """Test NcHICosmoVexp.E_tau.""" + assert vexp is not None + + tau_a = _compute_tau_array(vexp) + + for tau in tau_a: + assert np.isfinite(vexp.E_tau(tau)) + + tau0c = vexp.tau_xc(1.0) + tau0e = vexp.tau_xe(1.0) + + # Positive d_phi means matching Omega_c in the expansion phase. + if vexp.props.dphi > 0.0: # pylint: disable=no-member + assert_allclose( + vexp.E_tau(tau0c) ** 2, vexp.props.OmegaL # pylint: disable=no-member + ) + assert_allclose( + vexp.E_tau(tau0e) ** 2, vexp.props.Omegac # pylint: disable=no-member + ) + + +def test_Ricci_scale(vexp): + """Test NcHICosmoVexp.Ricci_scale.""" + assert vexp is not None + + tau_a = _compute_tau_array(vexp) + + for tau in tau_a: + assert np.isfinite(vexp.Ricci_scale(tau)) + Ricci_in_Hubble = np.abs( + vexp.Ricci_scale(tau) * vexp.E_tau(tau) / vexp.RH_planck() + ) + # Ricci scale is close to the Hubble scale. This works for our parameters and + # the range of tau, since the the Hubble parameter goes through zero at the + # bounce if the tau goes close to zero the first assertion below will fail. + assert Ricci_in_Hubble > 1.0e-12 + assert Ricci_in_Hubble < 1.0e1 + + +def test_tau_x(vexp): + """Test NcHICosmoVexp.tau_x.""" + assert vexp is not None + + xc_a = np.geomspace(1.0e-3, 1.03, 100) + xe_a = np.geomspace(1.0e-3, 1.03, 100) + tau_xc_a = [vexp.tau_xc(xc) for xc in xc_a] + tau_xe_a = [vexp.tau_xe(xe) for xe in xe_a] + + assert_allclose([vexp.xc_tau(tau) for tau in tau_xc_a], xc_a, atol=1.0e-7) + assert_allclose([vexp.xe_tau(tau) for tau in tau_xe_a], xe_a, atol=1.0e-7) + + +def test_serialize(vexp): + """Test NcHICosmoVexp serialization.""" + assert vexp is not None + + vexp.props.dphi = -1.234e-1 # pylint: disable=no-member + vexp.props.Omegac = 0.321 # pylint: disable=no-member + vexp.props.OmegaL = 0.679 # pylint: disable=no-member + + vexp.props.glue_de = True # pylint: disable=no-member + vexp.props.xb = 1.0e30 # pylint: disable=no-member + + ser = Ncm.Serialize.new(Ncm.SerializeOpt.CLEAN_DUP) + + vexp2 = ser.dup_obj(vexp) + + assert vexp2 is not None + assert isinstance(vexp2, Nc.HICosmoVexp) + assert isinstance(vexp2, Nc.HICosmo) + assert isinstance(vexp2, Ncm.Model) + + assert vexp2.props.dphi == vexp.props.dphi # pylint: disable=no-member + assert vexp2.props.Omegac == vexp.props.Omegac # pylint: disable=no-member + assert vexp2.props.OmegaL == vexp.props.OmegaL # pylint: disable=no-member + assert vexp2.props.glue_de == vexp.props.glue_de # pylint: disable=no-member + assert vexp2.props.xb == vexp.props.xb # pylint: disable=no-member + + +def test_eval_at(vexp): + """Evaluate NcHICosmoVexp at a given time.""" + assert vexp is not None + + tau_a = _compute_tau_array(vexp) + + for tau in tau_a: + assert np.isfinite(vexp.xe_tau(tau)) + assert np.isfinite(vexp.xc_tau(tau)) + assert np.isfinite(vexp.alpha(tau)) + assert np.isfinite(vexp.phi(tau)) + assert np.isfinite(vexp.Ricci_scale(tau)) + assert np.all(np.isfinite(vexp.x_y(tau))) + + +def test_iadiab_eval_at(vexp): + """Evaluate NcHICosmoVexp implementation of NcHIPertAdiab at a given time.""" + assert vexp is not None + + tau_a = _compute_tau_array(vexp) + k_a = np.geomspace(1.0e-3, 1.0e3, 5) + + for tau, k in product(tau_a, k_a): + assert np.isfinite(Nc.HIPertIAdiab.eval_F1(vexp, tau, k)) + assert np.isfinite(Nc.HIPertIAdiab.eval_m(vexp, tau, k)) + assert np.isfinite(Nc.HIPertIAdiab.eval_nu(vexp, tau, k)) + assert np.isfinite(Nc.HIPertIAdiab.eval_xi(vexp, tau, k)) + assert np.isfinite(Nc.HIPertIAdiab.eval_x(vexp, tau)) + + +def test_igw_eval_at(vexp): + """Evaluate NcHICosmoVexp implementation of NcHIPertIGW at a given time.""" + assert vexp is not None + + tau_a = _compute_tau_array(vexp) + k_a = np.geomspace(1.0e-3, 1.0e3, 5) + + for tau, k in product(tau_a, k_a): + assert np.isfinite(Nc.HIPertIGW.eval_F1(vexp, tau, k)) + assert np.isfinite(Nc.HIPertIGW.eval_m(vexp, tau, k)) + assert np.isfinite(Nc.HIPertIGW.eval_nu(vexp, tau, k)) + assert np.isfinite(Nc.HIPertIGW.eval_xi(vexp, tau, k)) + + +def test_iem_eval_at(vexp): + """Evaluate NcHICosmoVexp implementation of NcHIPertIEM at a given time.""" + assert vexp is not None + + tau_a = _compute_tau_array(vexp) + k_a = np.geomspace(1.0e-3, 1.0e3, 5) + + for tau, k in product(tau_a, k_a): + assert np.isfinite(Nc.HIPertIEM.eval_F1(vexp, tau, k)) + assert np.isfinite(Nc.HIPertIEM.eval_m(vexp, tau, k)) + assert np.isfinite(Nc.HIPertIEM.eval_nu(vexp, tau, k)) + assert np.isfinite(Nc.HIPertIEM.eval_xi(vexp, tau, k)) diff --git a/tests/test_py_hipert_adiab.py b/tests/test_py_hipert_adiab.py new file mode 100644 index 000000000..78b374209 --- /dev/null +++ b/tests/test_py_hipert_adiab.py @@ -0,0 +1,763 @@ +#!/usr/bin/env python +# +# test_py_hipert_adiab.py +# +# Tue Apr 16 10:24:29 2024 +# Copyright 2024 Sandro Dias Pinto Vitenti +# +# +# test_hipert_adiab.py +# Copyright (C) 2024 Sandro Dias Pinto Vitenti +# +# numcosmo is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# numcosmo is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . + +"""Tests on NcHIPertAdiab class.""" +import math +import pytest + +from numpy.testing import assert_allclose +from scipy.special import hankel1e # pylint: disable=no-name-in-module +import numpy as np + +from numcosmo_py import Ncm, Nc + +Ncm.cfg_init() + + +@pytest.fixture(name="adiab_qgw") +def fixture_adiab_qgw(): + """Fixture for NcHIPertAdiab.""" + adiab = Nc.HIPertAdiab.new() + + adiab.set_k(1.0) + + adiab.set_ti(-300.0) + adiab.set_tf(-10.0) + + return adiab, Nc.HICosmoQGW() + + +@pytest.fixture(name="adiab_vexp") +def fixture_adiab_vexp(): + """Fixture for NcHIPertAdiab.""" + adiab = Nc.HIPertAdiab.new() + vexp = Nc.HICosmoVexp() + + adiab.set_k(1.0) + + adiab.set_ti(vexp.tau_min()) + adiab.set_tf(vexp.tau_max()) + adiab.set_vacuum_max_time(-1.0e-1) + adiab.set_vacuum_reltol(1.0e-8) + + return adiab, vexp + + +def test_hipert_adiab_qgw(adiab_qgw): + """Test basic functionality of NcHIPertAdiab.""" + adiab, _ = adiab_qgw + + assert_allclose(adiab.get_k(), 1.0) + assert_allclose(adiab.get_ti(), -300.0) + # We need to set the final time to a value away from the bounce since our + # theoretical solution is not valid near the bounce. + assert_allclose(adiab.get_tf(), -10.0) + + adiab.set_reltol(1.0e-6) + adiab.set_abstol(1.0e-7) + + assert_allclose(adiab.get_reltol(), 1.0e-6) + assert_allclose(adiab.get_abstol(), 1.0e-7) + + adiab.set_adiab_threshold(1.0e-3) + adiab.set_prop_threshold(1.0e-3) + + assert_allclose(adiab.get_adiab_threshold(), 1.0e-3) + assert_allclose(adiab.get_prop_threshold(), 1.0e-3) + + adiab.set_save_evol(True) + assert adiab.get_save_evol() + + adiab.set_save_evol(False) + assert not adiab.get_save_evol() + + adiab.set_initial_condition_type(Ncm.CSQ1DInitialStateType.AD_HOC) + assert adiab.get_initial_condition_type() == Ncm.CSQ1DInitialStateType.AD_HOC + + adiab.set_initial_condition_type(Ncm.CSQ1DInitialStateType.ADIABATIC2) + assert adiab.get_initial_condition_type() == Ncm.CSQ1DInitialStateType.ADIABATIC2 + + adiab.set_initial_condition_type(Ncm.CSQ1DInitialStateType.ADIABATIC4) + assert adiab.get_initial_condition_type() == Ncm.CSQ1DInitialStateType.ADIABATIC4 + + adiab.set_initial_condition_type(Ncm.CSQ1DInitialStateType.NONADIABATIC2) + assert adiab.get_initial_condition_type() == Ncm.CSQ1DInitialStateType.NONADIABATIC2 + + +def test_hipert_adiab_vexp(adiab_vexp): + """Test basic functionality of NcHIPertAdiab.""" + adiab, vexp = adiab_vexp + + assert_allclose(adiab.get_k(), 1.0) + assert_allclose(adiab.get_ti(), vexp.tau_min()) + assert_allclose(adiab.get_tf(), vexp.tau_max()) + + adiab.set_reltol(1.0e-6) + adiab.set_abstol(1.0e-7) + + assert_allclose(adiab.get_reltol(), 1.0e-6) + assert_allclose(adiab.get_abstol(), 1.0e-7) + + adiab.set_adiab_threshold(1.0e-3) + adiab.set_prop_threshold(1.0e-3) + + assert_allclose(adiab.get_adiab_threshold(), 1.0e-3) + assert_allclose(adiab.get_prop_threshold(), 1.0e-3) + + adiab.set_save_evol(True) + assert adiab.get_save_evol() + + adiab.set_save_evol(False) + assert not adiab.get_save_evol() + + adiab.set_initial_condition_type(Ncm.CSQ1DInitialStateType.AD_HOC) + assert adiab.get_initial_condition_type() == Ncm.CSQ1DInitialStateType.AD_HOC + + adiab.set_initial_condition_type(Ncm.CSQ1DInitialStateType.ADIABATIC2) + assert adiab.get_initial_condition_type() == Ncm.CSQ1DInitialStateType.ADIABATIC2 + + adiab.set_initial_condition_type(Ncm.CSQ1DInitialStateType.ADIABATIC4) + assert adiab.get_initial_condition_type() == Ncm.CSQ1DInitialStateType.ADIABATIC4 + + adiab.set_initial_condition_type(Ncm.CSQ1DInitialStateType.NONADIABATIC2) + assert adiab.get_initial_condition_type() == Ncm.CSQ1DInitialStateType.NONADIABATIC2 + + +def test_initial_conditions_time_qgw(adiab_qgw): + """Test initial conditions of NcHIPertAdiab.""" + adiab, qgw = adiab_qgw + + limit_found, t_adiab = adiab.find_adiab_time_limit(qgw, -300.0, -1.0e-3, 1.0e-6) + + assert limit_found + assert t_adiab >= adiab.get_ti() + assert t_adiab <= adiab.get_tf() + + t_min, F1_min, t_lb, t_ub = adiab.find_adiab_max(qgw, -300.0, -1.0e1, 1.0e-1) + + assert_allclose(F1_min, adiab.eval_F1(qgw, t_min)) + assert math.fabs(F1_min - adiab.eval_F1(qgw, t_lb)) <= 1.0e-1 + assert math.fabs(F1_min - adiab.eval_F1(qgw, t_ub)) <= 1.0e-1 + + +def test_initial_conditions_time_vexp(adiab_vexp): + """Test initial conditions of NcHIPertAdiab.""" + adiab, vexp = adiab_vexp + + limit_found, t_adiab = adiab.find_adiab_time_limit( + vexp, vexp.tau_min(), adiab.get_vacuum_max_time(), 1.0e-6 + ) + + assert limit_found + assert t_adiab >= adiab.get_ti() + assert t_adiab <= adiab.get_tf() + + t_min, F1_min, t_lb, t_ub = adiab.find_adiab_max( + vexp, vexp.tau_min(), vexp.tau_max(), 1.0e-2 + ) + + assert_allclose(F1_min, adiab.eval_F1(vexp, t_min)) + assert math.fabs(F1_min - adiab.eval_F1(vexp, t_lb)) <= 1.0e-1 + assert math.fabs(F1_min - adiab.eval_F1(vexp, t_ub)) <= 1.0e-1 + + +def _compute_analytical_solution_qgw(adiab_qgw, t_adiab): + """Compute analytical solution for NcHIPertAdiab using NcHICosmoQGW.""" + adiab, qgw = adiab_qgw + + w = qgw.props.w + cs2 = w + Omegaw = qgw.props.Omegaw + sqrtOmegaw = np.sqrt(Omegaw) + norma = np.sqrt(np.pi * cs2 / (6.0 * (1.0 + 3.0 * w) * (1.0 + w) * sqrtOmegaw)) + w = qgw.props.w + alpha = 3.0 * (1.0 - w) / (2.0 * (1.0 + 3.0 * w)) + x = qgw.eval_x(t_adiab) + E = np.abs(qgw.eval_hubble(t_adiab)) + eta = 2.0 * x / (E * (1.0 + 3.0 * w)) + cs = np.sqrt(w) + csketa = cs * adiab.get_k() * eta + hfnormm = norma * (2.0 / ((1.0 + 3.0 * w) * eta * sqrtOmegaw)) ** (alpha) + + # Analytical solution for phi and Pphi + theo_phi = hfnormm * hankel1e(alpha, csketa) + theo_Pphi = (csketa / hfnormm) * 0.25 * math.pi * hankel1e(1.0 + alpha, csketa) + + return theo_phi, theo_Pphi + + +def test_initial_conditions_adiabatic_qgw(adiab_qgw): + """Test initial conditions of NcHIPertAdiab.""" + adiab, qgw = adiab_qgw + + state = Ncm.CSQ1DState.new() + + for prec in np.geomspace(1.0e-14, 1.0e-6, 100): + limit_found, t_adiab = adiab.find_adiab_time_limit(qgw, -300.0, -1.0e1, prec) + + assert limit_found + + # Getting the adiabatic solution + state, _alpha_reltol, _dgamma_reltol = adiab.compute_adiab(qgw, t_adiab, state) + adiab.change_frame(qgw, state, Ncm.CSQ1DFrame.ORIG) + phi_vec, Pphi_vec = state.get_phi_Pphi() + + phi = phi_vec[0] + 1.0j * phi_vec[1] + Pphi = Pphi_vec[0] + 1.0j * Pphi_vec[1] + + theo_phi, theo_Pphi = _compute_analytical_solution_qgw(adiab_qgw, t_adiab) + + # Compare with analytical solution + assert_allclose(abs(phi), abs(theo_phi), rtol=1.0e-8) + assert_allclose(abs(Pphi), abs(theo_Pphi), rtol=1.0e-8) + + +def test_initial_conditions_adiabatic_vexp(adiab_vexp): + """Test initial conditions of NcHIPertAdiab.""" + adiab, vexp = adiab_vexp + + state = Ncm.CSQ1DState.new() + + for prec in np.geomspace(1.0e-14, 1.0e-6, 100): + limit_found, t_adiab = adiab.find_adiab_time_limit( + vexp, vexp.tau_min(), adiab.get_vacuum_max_time(), prec + ) + + assert limit_found + + # Getting the adiabatic solution + state, _alpha_reltol, _dgamma_reltol = adiab.compute_adiab(vexp, t_adiab, state) + adiab.change_frame(vexp, state, Ncm.CSQ1DFrame.ORIG) + phi_vec, Pphi_vec = state.get_phi_Pphi() + + phi = phi_vec[0] + 1.0j * phi_vec[1] + Pphi = Pphi_vec[0] + 1.0j * Pphi_vec[1] + + # Compare with analytical solution + assert np.isfinite(abs(phi)) + assert np.isfinite(abs(Pphi)) + + +def test_evolution_qgw(adiab_qgw): + """Test initial conditions of NcHIPertAdiab.""" + adiab, qgw = adiab_qgw + + state = Ncm.CSQ1DState.new() + + adiab.set_save_evol(True) + adiab.set_reltol(1.0e-10) + adiab.set_abstol(0.0) + adiab.set_initial_condition_type(Ncm.CSQ1DInitialStateType.ADIABATIC4) + adiab.set_vacuum_max_time(-1.0e1) + adiab.set_vacuum_reltol(1.0e-8) + adiab.prepare(qgw) + + t_a, _smaller_abst = adiab.get_time_array() + + for t in t_a: + state = adiab.eval_at(qgw, t, state) + phi_vec, Pphi_vec = state.get_phi_Pphi() + + phi = phi_vec[0] + 1.0j * phi_vec[1] + Pphi = Pphi_vec[0] + 1.0j * Pphi_vec[1] + + # Analytical solution for phi and Pphi + theo_phi, theo_Pphi = _compute_analytical_solution_qgw(adiab_qgw, t) + + # Compare with analytical solution + assert_allclose(abs(phi), abs(theo_phi), rtol=1.0e-7) + assert_allclose(abs(Pphi), abs(theo_Pphi), rtol=1.0e-7) + + J11, J12, J22 = state.get_J() + + assert_allclose(J11, 2.0 * abs(phi) ** 2, atol=1.0e-7) + assert_allclose(J22, 2.0 * abs(Pphi) ** 2, atol=1.0e-7) + assert_allclose(J12, (2.0 * phi * Pphi.conjugate()).real, atol=1.0e-7) + + +def test_evolution_vexp(adiab_vexp): + """Test initial conditions of NcHIPertAdiab.""" + adiab, vexp = adiab_vexp + + state = Ncm.CSQ1DState.new() + + adiab.set_save_evol(True) + adiab.set_reltol(1.0e-10) + adiab.set_abstol(0.0) + adiab.set_initial_condition_type(Ncm.CSQ1DInitialStateType.ADIABATIC4) + adiab.set_vacuum_max_time(-1.0e-1) + adiab.set_vacuum_reltol(1.0e-8) + adiab.set_tf(1.0) # We do not want to evolve through the singularity + adiab.prepare(vexp) + + t_a, _smaller_abst = adiab.get_time_array() + + for t in t_a: + state = adiab.eval_at(vexp, t, state) + phi_vec, Pphi_vec = state.get_phi_Pphi() + + phi = phi_vec[0] + 1.0j * phi_vec[1] + Pphi = Pphi_vec[0] + 1.0j * Pphi_vec[1] + + # Compare with analytical solution + assert np.isfinite(abs(phi)) + assert np.isfinite(abs(Pphi)) + + J11, J12, J22 = state.get_J() + + assert np.isfinite(J11) + assert np.isfinite(J22) + assert np.isfinite(J12) + + +def test_evolution_adiabatic2_qgw(adiab_qgw): + """Test initial conditions of NcHIPertAdiab.""" + adiab, qgw = adiab_qgw + + adiab.set_initial_condition_type(Ncm.CSQ1DInitialStateType.ADIABATIC2) + adiab.set_vacuum_max_time(-1.0e0) + adiab.set_vacuum_reltol(1.0e-3) + state = Ncm.CSQ1DState.new() + + adiab.set_save_evol(True) + adiab.set_reltol(1.0e-10) + adiab.set_abstol(0.0) + adiab.prepare(qgw) + + t_a, _smaller_abst = adiab.get_time_array() + + for t in t_a: + state = adiab.eval_at(qgw, t, state) + phi_vec, Pphi_vec = state.get_phi_Pphi() + + phi = phi_vec[0] + 1.0j * phi_vec[1] + Pphi = Pphi_vec[0] + 1.0j * Pphi_vec[1] + + # Analytical solution for phi and Pphi + theo_phi, theo_Pphi = _compute_analytical_solution_qgw(adiab_qgw, t) + + # Compare with analytical solution + assert_allclose(abs(phi), abs(theo_phi), rtol=1.0e-7) + assert_allclose(abs(Pphi), abs(theo_Pphi), rtol=1.0e-7) + + J11, J12, J22 = state.get_J() + + assert_allclose(J11, 2.0 * abs(phi) ** 2, atol=1.0e-7) + assert_allclose(J22, 2.0 * abs(Pphi) ** 2, atol=1.0e-7) + assert_allclose(J12, (2.0 * phi * Pphi.conjugate()).real, atol=1.0e-7) + + +def test_evolution_adiabatic2_vexp(adiab_vexp): + """Test initial conditions of NcHIPertAdiab.""" + adiab, vexp = adiab_vexp + + adiab.set_initial_condition_type(Ncm.CSQ1DInitialStateType.ADIABATIC2) + adiab.set_vacuum_max_time(-1.0e-1) + adiab.set_vacuum_reltol(1.0e-3) + adiab.set_tf(1.0) # We do not want to evolve through the singularity + state = Ncm.CSQ1DState.new() + + adiab.set_save_evol(True) + adiab.set_reltol(1.0e-10) + adiab.set_abstol(0.0) + adiab.prepare(vexp) + + t_a, _smaller_abst = adiab.get_time_array() + + for t in t_a: + state = adiab.eval_at(vexp, t, state) + phi_vec, Pphi_vec = state.get_phi_Pphi() + + phi = phi_vec[0] + 1.0j * phi_vec[1] + Pphi = Pphi_vec[0] + 1.0j * Pphi_vec[1] + + # Compare with analytical solution + assert np.isfinite(abs(phi)) + assert np.isfinite(abs(Pphi)) + + J11, J12, J22 = state.get_J() + + assert np.isfinite(J11) + assert np.isfinite(J22) + assert np.isfinite(J12) + + +def test_evolution_adiabatic4_qgw(adiab_qgw): + """Test initial conditions of NcHIPertAdiab.""" + adiab, qgw = adiab_qgw + + adiab.set_initial_condition_type(Ncm.CSQ1DInitialStateType.ADIABATIC4) + adiab.set_vacuum_max_time(-1.0e0) + adiab.set_vacuum_reltol(1.0e-6) + state = Ncm.CSQ1DState.new() + + adiab.set_save_evol(True) + adiab.set_reltol(1.0e-10) + adiab.set_abstol(0.0) + adiab.prepare(qgw) + + t_a, _smaller_abst = adiab.get_time_array() + + for t in t_a: + state = adiab.eval_at(qgw, t, state) + phi_vec, Pphi_vec = state.get_phi_Pphi() + + phi = phi_vec[0] + 1.0j * phi_vec[1] + Pphi = Pphi_vec[0] + 1.0j * Pphi_vec[1] + + # Analytical solution for phi and Pphi + theo_phi, theo_Pphi = _compute_analytical_solution_qgw(adiab_qgw, t) + + # Compare with analytical solution + assert_allclose(abs(phi), abs(theo_phi), rtol=1.0e-7) + assert_allclose(abs(Pphi), abs(theo_Pphi), rtol=1.0e-7) + + J11, J12, J22 = state.get_J() + + assert_allclose(J11, 2.0 * abs(phi) ** 2, atol=1.0e-7) + assert_allclose(J22, 2.0 * abs(Pphi) ** 2, atol=1.0e-7) + assert_allclose(J12, (2.0 * phi * Pphi.conjugate()).real, atol=1.0e-7) + + +def test_evolution_adiabatic4_vexp(adiab_vexp): + """Test initial conditions of NcHIPertAdiab.""" + adiab, vexp = adiab_vexp + + adiab.set_initial_condition_type(Ncm.CSQ1DInitialStateType.ADIABATIC4) + adiab.set_vacuum_max_time(-1.0e-1) + adiab.set_vacuum_reltol(1.0e-6) + adiab.set_tf(1.0) # We do not want to evolve through the singularity + state = Ncm.CSQ1DState.new() + + adiab.set_save_evol(True) + adiab.set_reltol(1.0e-10) + adiab.set_abstol(0.0) + adiab.prepare(vexp) + + t_a, _smaller_abst = adiab.get_time_array() + + for t in t_a: + state = adiab.eval_at(vexp, t, state) + phi_vec, Pphi_vec = state.get_phi_Pphi() + + phi = phi_vec[0] + 1.0j * phi_vec[1] + Pphi = Pphi_vec[0] + 1.0j * Pphi_vec[1] + + # Compare with analytical solution + assert np.isfinite(abs(phi)) + assert np.isfinite(abs(Pphi)) + + J11, J12, J22 = state.get_J() + + assert np.isfinite(J11) + assert np.isfinite(J22) + assert np.isfinite(J12) + + +@pytest.mark.parametrize( + "frame", + [Ncm.CSQ1DFrame.ORIG, Ncm.CSQ1DFrame.ADIAB1, Ncm.CSQ1DFrame.ADIAB2], + ids=["orig", "adiab1", "adiab2"], +) +def test_evolution_frame_qgw(adiab_qgw, frame): + """Test initial conditions of NcHIPertAdiab.""" + adiab, qgw = adiab_qgw + + state = Ncm.CSQ1DState.new() + ti = adiab.get_ti() + adiab.set_initial_condition_type(Ncm.CSQ1DInitialStateType.ADIABATIC4) + + limit_found, t_adiab_end = adiab.find_adiab_time_limit(qgw, ti, -1.0e0, 1.0e-1) + assert limit_found + adiab.set_tf(t_adiab_end) + + adiab.set_save_evol(True) + adiab.set_reltol(1.0e-10) + adiab.set_abstol(0.0) + adiab.prepare(qgw) + + t_a, _smaller_abst = adiab.get_time_array() + + for t in t_a: + state = adiab.eval_at_frame(qgw, frame, t, state) + assert state.get_frame() == frame + + +@pytest.mark.parametrize( + "frame", + [Ncm.CSQ1DFrame.ORIG, Ncm.CSQ1DFrame.ADIAB1, Ncm.CSQ1DFrame.ADIAB2], + ids=["orig", "adiab1", "adiab2"], +) +def test_evolution_frame_vexp(adiab_vexp, frame): + """Test initial conditions of NcHIPertAdiab.""" + adiab, vexp = adiab_vexp + + state = Ncm.CSQ1DState.new() + ti = adiab.get_ti() + adiab.set_initial_condition_type(Ncm.CSQ1DInitialStateType.ADIABATIC4) + + limit_found, t_adiab_end = adiab.find_adiab_time_limit( + vexp, ti, adiab.get_vacuum_max_time(), 1.0e-1 + ) + assert limit_found + adiab.set_tf(t_adiab_end) + + adiab.set_save_evol(True) + adiab.set_reltol(1.0e-10) + adiab.set_abstol(0.0) + adiab.prepare(vexp) + + t_a, _smaller_abst = adiab.get_time_array() + + for t in t_a: + state = adiab.eval_at_frame(vexp, frame, t, state) + assert state.get_frame() == frame + + +def test_change_frame_orig_adiab1_qgw(adiab_qgw): + """Test change_frame method of NcHIPertAdiab.""" + adiab, qgw = adiab_qgw + + t = -1.4e2 + state = Ncm.CSQ1DState() + state.set_ag(Ncm.CSQ1DFrame.ORIG, t, 0.1, 0.3) + + adiab.change_frame(qgw, state, Ncm.CSQ1DFrame.ORIG) + + assert state.get_frame() == Ncm.CSQ1DFrame.ORIG + assert state.get_ag() == (0.1, 0.3) + + adiab.change_frame(qgw, state, Ncm.CSQ1DFrame.ADIAB1) + assert state.get_frame() == Ncm.CSQ1DFrame.ADIAB1 + assert_allclose(state.get_ag(), (0.1, 0.3 - adiab.eval_xi(qgw, t))) + + adiab.change_frame(qgw, state, Ncm.CSQ1DFrame.ORIG) + assert state.get_frame() == Ncm.CSQ1DFrame.ORIG + assert_allclose(state.get_ag(), (0.1, 0.3)) + + +def test_change_frame_orig_adiab2_qgw(adiab_qgw): + """Test change_frame method of NcHIPertAdiab.""" + adiab, qgw = adiab_qgw + + t = -1.4e2 + + alpha0 = 0.1 + gamma0 = 0.3 + adiab.eval_xi(qgw, t) + + state = Ncm.CSQ1DState() + state.set_ag(Ncm.CSQ1DFrame.ORIG, t, alpha0, gamma0) + + adiab.change_frame(qgw, state, Ncm.CSQ1DFrame.ORIG) + + assert state.get_frame() == Ncm.CSQ1DFrame.ORIG + assert state.get_ag() == (alpha0, gamma0) + + adiab.change_frame(qgw, state, Ncm.CSQ1DFrame.ADIAB2) + assert state.get_frame() == Ncm.CSQ1DFrame.ADIAB2 + assert not np.allclose(state.get_ag(), (alpha0, gamma0)) + + adiab.change_frame(qgw, state, Ncm.CSQ1DFrame.ORIG) + assert state.get_frame() == Ncm.CSQ1DFrame.ORIG + assert_allclose(state.get_ag(), (alpha0, gamma0)) + + +def test_change_frame_adiab1_adiab2_qgw(adiab_qgw): + """Test change_frame method of NcHIPertAdiab.""" + adiab, qgw = adiab_qgw + + t = -1.4e2 + state = Ncm.CSQ1DState() + state.set_ag(Ncm.CSQ1DFrame.ADIAB1, t, 0.1, 0.3) + + adiab.change_frame(qgw, state, Ncm.CSQ1DFrame.ADIAB1) + assert state.get_frame() == Ncm.CSQ1DFrame.ADIAB1 + assert state.get_ag() == (0.1, 0.3) + + adiab.change_frame(qgw, state, Ncm.CSQ1DFrame.ADIAB2) + assert state.get_frame() == Ncm.CSQ1DFrame.ADIAB2 + assert not np.allclose(state.get_ag(), (0.1, 0.3)) + + adiab.change_frame(qgw, state, Ncm.CSQ1DFrame.ADIAB1) + assert state.get_frame() == Ncm.CSQ1DFrame.ADIAB1 + assert_allclose(state.get_ag(), (0.1, 0.3)) + + +def test_evolution_qgw_duplicate(adiab_qgw): + """Test initial conditions of NcHIPertAdiab.""" + adiab, qgw = adiab_qgw + + ser = Ncm.Serialize.new(Ncm.SerializeOpt.CLEAN_DUP) + adiab_dup = ser.dup_obj(adiab) + qgw_dup = ser.dup_obj(qgw) + + test_evolution_qgw((adiab_dup, qgw_dup)) + + +def test_evolution_vexp_duplicate(adiab_vexp): + """Test initial conditions of NcHIPertAdiab.""" + adiab, vexp = adiab_vexp + + ser = Ncm.Serialize.new(Ncm.SerializeOpt.CLEAN_DUP) + adiab_dup = ser.dup_obj(adiab) + vexp_dup = ser.dup_obj(vexp) + + test_evolution_vexp((adiab_dup, vexp_dup)) + + +def test_spectrum_zeta_qgw(adiab_qgw): + """Test spectrum of NcHIPertAdiab.""" + adiab, qgw = adiab_qgw + + k_a = np.geomspace(1.0e-2, 1.0e2, 20) + t_a = np.linspace(-30.0, -10.0, 10) + + adiab.set_initial_condition_type(Ncm.CSQ1DInitialStateType.ADIABATIC4) + adiab.set_vacuum_max_time(-1.0e0) + adiab.set_vacuum_reltol(1.0e-8) + + adiab.set_save_evol(True) + adiab.set_reltol(1.0e-10) + adiab.set_abstol(0.0) + adiab.prepare_spectrum(qgw, k_a, t_a) + + Pzeta = adiab.eval_powspec_zeta(qgw) + + # Interface method should be used this way since different interfaces may have + # implemented a method with the same name + unit = Nc.HIPertIAdiab.eval_unit + + for k in k_a: + adiab.set_k(k) + for t in t_a: + theo_phi, _ = _compute_analytical_solution_qgw(adiab_qgw, t) + assert_allclose( + Pzeta.eval(qgw, t, k), + np.abs(theo_phi * unit(qgw)) ** 2, + rtol=1.0e-7, + ) + + +def test_spectrum_zeta_vexp(adiab_vexp): + """Test spectrum of NcHIPertAdiab.""" + adiab, vexp = adiab_vexp + + k_a = np.geomspace(1.0e-2, 1.0e2, 10) + t_a = np.linspace(-12.0, -10.0, 10) + + adiab.set_initial_condition_type(Ncm.CSQ1DInitialStateType.ADIABATIC4) + adiab.set_vacuum_max_time(-1.0e0) + adiab.set_vacuum_reltol(1.0e-8) + adiab.set_tf(1.0) # We do not want to evolve through the singularity + + adiab.set_save_evol(True) + adiab.set_reltol(1.0e-10) + adiab.set_abstol(0.0) + adiab.prepare_spectrum(vexp, k_a, t_a) + + Pzeta = adiab.eval_powspec_zeta(vexp) + + # Interface method should be used this way since different interfaces may have + # implemented a method with the same name + unit = Nc.HIPertIAdiab.eval_unit + state = Ncm.CSQ1DState.new() + + for k in k_a: + adiab.set_k(k) + adiab.prepare(vexp) + for t in t_a: + phi2 = 0.5 * adiab.eval_at(vexp, t, state).get_J()[0] + assert_allclose( + Pzeta.eval(vexp, t, k), + phi2 * unit(vexp) ** 2, + rtol=1.0e-7, + ) + + +def test_spectrum_Psi_qgw(adiab_qgw): + """Test spectrum of NcHIPertAdiab.""" + adiab, qgw = adiab_qgw + + k_a = np.geomspace(1.0e-2, 1.0e2, 20) + t_a = np.linspace(-30.0, -10.0, 10) + + adiab.set_initial_condition_type(Ncm.CSQ1DInitialStateType.ADIABATIC4) + adiab.set_vacuum_max_time(-1.0e0) + adiab.set_vacuum_reltol(1.0e-8) + + adiab.set_save_evol(True) + adiab.set_reltol(1.0e-10) + adiab.set_abstol(0.0) + adiab.prepare_spectrum(qgw, k_a, t_a) + + PPsi = adiab.eval_powspec_Psi(qgw) + + # Interface method should be used this way since different interfaces may have + # implemented a method with the same name + p2Psi = Nc.HIPertIAdiab.eval_p2Psi + unit = Nc.HIPertIAdiab.eval_unit + + for k in k_a: + adiab.set_k(k) + for t in t_a: + _, theo_Pphi = _compute_analytical_solution_qgw(adiab_qgw, t) + assert_allclose( + PPsi.eval(qgw, t, k), + np.abs(theo_Pphi * unit(qgw) * p2Psi(qgw, t, k)) ** 2, + rtol=1.0e-7, + ) + + +def test_spectrum_drho_qgw(adiab_qgw): + """Test spectrum of NcHIPertAdiab.""" + adiab, qgw = adiab_qgw + + k_a = np.geomspace(1.0e-2, 1.0e2, 20) + t_a = np.linspace(-30.0, -10.0, 10) + + adiab.set_initial_condition_type(Ncm.CSQ1DInitialStateType.ADIABATIC4) + adiab.set_vacuum_max_time(-1.0e0) + adiab.set_vacuum_reltol(1.0e-8) + + adiab.set_save_evol(True) + adiab.set_reltol(1.0e-10) + adiab.set_abstol(0.0) + adiab.prepare_spectrum(qgw, k_a, t_a) + + Pdrho = adiab.eval_powspec_drho(qgw) + + # Interface method should be used this way since different interfaces may have + # implemented a method with the same name + p2drho = Nc.HIPertIAdiab.eval_p2drho + unit = Nc.HIPertIAdiab.eval_unit + + for k in k_a: + adiab.set_k(k) + for t in t_a: + _, theo_Pphi = _compute_analytical_solution_qgw(adiab_qgw, t) + assert_allclose( + Pdrho.eval(qgw, t, k), + np.abs(theo_Pphi * unit(qgw) * p2drho(qgw, t, k)) ** 2, + rtol=1.0e-7, + ) diff --git a/tests/test_py_hipert_em.py b/tests/test_py_hipert_em.py new file mode 100644 index 000000000..7c266c2de --- /dev/null +++ b/tests/test_py_hipert_em.py @@ -0,0 +1,262 @@ +#!/usr/bin/env python +# +# test_py_hipert_em.py +# +# Tue Apr 16 10:24:29 2024 +# Copyright 2024 Sandro Dias Pinto Vitenti +# +# +# test_hipert_em.py +# Copyright (C) 2024 Sandro Dias Pinto Vitenti +# +# numcosmo is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# numcosmo is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . + +"""Tests on NcHIPertEM class.""" +import math +import pytest + +from numpy.testing import assert_allclose +import numpy as np + +from numcosmo_py import Ncm, Nc + +Ncm.cfg_init() + + +@pytest.fixture( + name="pem_vexp", + params=[ + Nc.HICosmoVexpEMCoupling.NONE, + Nc.HICosmoVexpEMCoupling.CAUCHY, + Nc.HICosmoVexpEMCoupling.GAUSS, + ], + ids=["none", "cauchy", "gauss"], +) +def fixture_em(request): + """Fixture for NcHIPertEM.""" + pem = Nc.HIPertEM.new() + vexp = Nc.HICosmoVexp() + + current_set = { + "alphab": 7.4847e-3, # Alpha (# of e-fold\s) at the bounce + "sigmaphi": 100.0, # Width of the Gaussian solution for the WdW equation + "xb": 2.0e36, # Inverse of the scale factor at the bounce (Initial condition) + "dphi": -9.0e-4, # Deviation of the Gaussian solution for the WdW equation + "OmegaL": 1.0, # H²(a when w=-1)/H²(a0). Basically gives the DE-dominated phase + "Omegac": 1.0, # Omega_d??? + "H0": 67.8, # Hubble parameter today given by CMB observations + "Bem": -1.0 / 4.0 + 1.0e-12, # Amplitude of the EM gaussian coupling + "betaem": 3.6e-1, # Width of the EM gaussian coupling + } + + vexp.set_properties(**current_set) + vexp.set_em_coupling(request.param) + + # No coupling has F1 exactly zero, so computing F2 numerically can be problematic + # using ADIABATIC2 avoids this problem. + # Gaussians have a very small F1 (suppressed by the Gaussian term), so it is also + # problematic to compute F2 numerically. + if request.param == Nc.HICosmoVexpEMCoupling.NONE: + pem.set_abstol(1.0e-200) + pem.set_initial_condition_type(Ncm.CSQ1DInitialStateType.ADIABATIC2) + elif request.param == Nc.HICosmoVexpEMCoupling.GAUSS: + pem.set_initial_condition_type(Ncm.CSQ1DInitialStateType.ADIABATIC2) + else: + pem.set_initial_condition_type(Ncm.CSQ1DInitialStateType.ADIABATIC4) + + pem.set_k(1.0) + + pem.set_ti(vexp.tau_min()) + # Warning: this model has a singularity at the expanding phase, the final time + # should be set prior to it. + pem.set_tf(vexp.tau_max()) + pem.set_vacuum_max_time(-1.0e-1) + pem.set_vacuum_reltol(1.0e-8) + + return pem, vexp + + +def test_hipert_em_vexp(pem_vexp): + """Test basic functionality of NcHIPertAdiab.""" + pem, vexp = pem_vexp + + assert_allclose(pem.get_k(), 1.0) + assert_allclose(pem.get_ti(), vexp.tau_min()) + assert_allclose(pem.get_tf(), vexp.tau_max()) + + pem.set_reltol(1.0e-6) + pem.set_abstol(1.0e-7) + + assert_allclose(pem.get_reltol(), 1.0e-6) + assert_allclose(pem.get_abstol(), 1.0e-7) + + pem.set_adiab_threshold(1.0e-3) + pem.set_prop_threshold(1.0e-3) + + assert_allclose(pem.get_adiab_threshold(), 1.0e-3) + assert_allclose(pem.get_prop_threshold(), 1.0e-3) + + pem.set_save_evol(True) + assert pem.get_save_evol() + + pem.set_save_evol(False) + assert not pem.get_save_evol() + + pem.set_initial_condition_type(Ncm.CSQ1DInitialStateType.AD_HOC) + assert pem.get_initial_condition_type() == Ncm.CSQ1DInitialStateType.AD_HOC + + pem.set_initial_condition_type(Ncm.CSQ1DInitialStateType.ADIABATIC2) + assert pem.get_initial_condition_type() == Ncm.CSQ1DInitialStateType.ADIABATIC2 + + pem.set_initial_condition_type(Ncm.CSQ1DInitialStateType.ADIABATIC4) + assert pem.get_initial_condition_type() == Ncm.CSQ1DInitialStateType.ADIABATIC4 + + pem.set_initial_condition_type(Ncm.CSQ1DInitialStateType.NONADIABATIC2) + assert pem.get_initial_condition_type() == Ncm.CSQ1DInitialStateType.NONADIABATIC2 + + +def test_initial_conditions_time_vexp(pem_vexp): + """Test initial conditions of NcHIPertAdiab.""" + pem, vexp = pem_vexp + + limit_found, t_adiab = pem.find_adiab_time_limit( + vexp, vexp.tau_min(), pem.get_vacuum_max_time(), 1.0e-6 + ) + + assert limit_found + assert t_adiab >= pem.get_ti() + assert t_adiab <= pem.get_tf() + + t_min, F1_min, t_lb, t_ub = pem.find_adiab_max( + vexp, vexp.tau_min(), pem.get_vacuum_max_time(), 1.0e-1 + ) + + assert_allclose(F1_min, pem.eval_F1(vexp, t_min)) + assert math.fabs(F1_min - pem.eval_F1(vexp, t_lb)) <= 1.0e-1 + assert math.fabs(F1_min - pem.eval_F1(vexp, t_ub)) <= 1.0e-1 + + +def test_initial_conditions_adiabatic_vexp(pem_vexp): + """Test initial conditions of NcHIPertAdiab.""" + pem, vexp = pem_vexp + + state = Ncm.CSQ1DState.new() + + for prec in np.geomspace(1.0e-14, 1.0e-6, 10): + limit_found, t_adiab = pem.find_adiab_time_limit( + vexp, vexp.tau_min(), pem.get_vacuum_max_time(), prec + ) + + assert limit_found + + # Getting the adiabatic solution + state, _alpha_reltol, _dgamma_reltol = pem.compute_adiab(vexp, t_adiab, state) + pem.change_frame(vexp, state, Ncm.CSQ1DFrame.ORIG) + phi_vec, Pphi_vec = state.get_phi_Pphi() + + phi = phi_vec[0] + 1.0j * phi_vec[1] + Pphi = Pphi_vec[0] + 1.0j * Pphi_vec[1] + + # Compare with analytical solution + assert np.isfinite(phi) + assert np.isfinite(Pphi) + + +def test_evolution_vexp(pem_vexp): + """Test initial conditions of NcHIPertAdiab.""" + pem, vexp = pem_vexp + + state = Ncm.CSQ1DState.new() + + pem.set_tf(1.0) # We do not want to evolve through the singularity + pem.prepare(vexp) + + t_a, _smaller_abst = pem.get_time_array() + + for t in t_a: + state = pem.eval_at(vexp, t, state) + phi_vec, Pphi_vec = state.get_phi_Pphi() + + phi = phi_vec[0] + 1.0j * phi_vec[1] + Pphi = Pphi_vec[0] + 1.0j * Pphi_vec[1] + + # Compare with analytical solution + assert np.isfinite(abs(phi)) + assert np.isfinite(abs(Pphi)) + + J11, J12, J22 = state.get_J() + + assert np.isfinite(J11) + assert np.isfinite(J22) + assert np.isfinite(J12) + + +def test_evolution_vexp_duplicate(pem_vexp): + """Test initial conditions of NcHIPertAdiab.""" + pem, vexp = pem_vexp + + ser = Ncm.Serialize.new(Ncm.SerializeOpt.CLEAN_DUP) + pem_dup = ser.dup_obj(pem) + vexp_dup = ser.dup_obj(vexp) + + test_evolution_vexp((pem_dup, vexp_dup)) + + +def test_evolution_EB_vexp(pem_vexp): + """Test initial conditions of NcHIPertAdiab.""" + pem, vexp = pem_vexp + + pem.set_tf(1.0) # We do not want to evolve through the singularity + pem.prepare(vexp) + + t_a, _smaller_abst = pem.get_time_array() + + for t in t_a: + PE, PB = pem.eval_PE_PB(vexp, t) + + assert np.isfinite(PE) + assert np.isfinite(PB) + + +def _compute_tau_array(vexp, abs_tau_min=1.0e-10): + """Compute an array of tau values for testing. + + This includes a range from tau_min to -abs_tau_min and from abs_tau_min to tau_max. + This is useful since we want to test the behavior of the model around the bounce. + """ + tau_min = vexp.tau_min() + 1.0 + tau_max = vexp.tau_max() + + tau_a = np.concatenate( + ( + np.geomspace(tau_min, -abs_tau_min, 5000), + np.geomspace(abs_tau_min, tau_max, 5000), + ) + ) + return tau_a + + +def test_interface_eval_vexp(pem_vexp): + """Test interface evaluation of NcHIPertAdiab.""" + _, vexp = pem_vexp + + tau_a = _compute_tau_array(vexp) + + assert np.isfinite(Nc.HIPertIGW.eval_unit(vexp)) + for tau in tau_a: + assert np.isfinite(Nc.HIPertIGW.eval_F1(vexp, tau, 1.0)) + assert np.isfinite(Nc.HIPertIGW.eval_m(vexp, tau, 1.0)) + assert np.isfinite(Nc.HIPertIGW.eval_nu(vexp, tau, 1.0)) + assert np.isfinite(Nc.HIPertIGW.eval_xi(vexp, tau, 1.0)) + assert np.isfinite(Nc.HIPertIGW.eval_x(vexp, tau)) diff --git a/tests/test_py_hipert_gw.py b/tests/test_py_hipert_gw.py new file mode 100644 index 000000000..00136ba94 --- /dev/null +++ b/tests/test_py_hipert_gw.py @@ -0,0 +1,207 @@ +#!/usr/bin/env python +# +# test_py_hipert_gw.py +# +# Tue Apr 16 10:24:29 2024 +# Copyright 2024 Sandro Dias Pinto Vitenti +# +# +# test_hipert_gw.py +# Copyright (C) 2024 Sandro Dias Pinto Vitenti +# +# numcosmo is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# numcosmo is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . + +"""Tests on NcHIPertEM class.""" +import math +import pytest + +from numpy.testing import assert_allclose +import numpy as np + +from numcosmo_py import Ncm, Nc + +Ncm.cfg_init() + + +@pytest.fixture(name="pgw_vexp") +def fixture_em(): + """Fixture for NcHIPertEM.""" + pgw = Nc.HIPertGW.new() + vexp = Nc.HICosmoVexp() + + current_set = { + "alphab": 7.4847e-3, # Alpha (# of e-fold\s) at the bounce + "sigmaphi": 100.0, # Width of the Gaussian solution for the WdW equation + "xb": 2.0e36, # Inverse of the scale factor at the bounce (Initial condition) + "dphi": -9.0e-4, # Deviation of the Gaussian solution for the WdW equation + "OmegaL": 1.0, # H²(a when w=-1)/H²(a0). Basically gives the DE-dominated phase + "Omegac": 1.0, # Omega_d??? + "H0": 67.8, # Hubble parameter today given by CMB observations + "Bem": -1.0 / 4.0 + 1.0e-12, # Amplitude of the EM gaussian coupling + "betaem": 3.6e-1, # Width of the EM gaussian coupling + } + + vexp.set_properties(**current_set) + + pgw.set_initial_condition_type(Ncm.CSQ1DInitialStateType.ADIABATIC4) + pgw.set_k(1.0) + pgw.set_ti(vexp.tau_min()) + # Warning: this model has a singularity at the expanding phase, the final time + # should be set prior to it. + pgw.set_tf(vexp.tau_max()) + pgw.set_vacuum_max_time(-1.0e-1) + pgw.set_vacuum_reltol(1.0e-8) + + return pgw, vexp + + +def test_hipert_gw_vexp(pgw_vexp): + """Test basic functionality of NcHIPertAdiab.""" + pgw, vexp = pgw_vexp + + assert_allclose(pgw.get_k(), 1.0) + assert_allclose(pgw.get_ti(), vexp.tau_min()) + assert_allclose(pgw.get_tf(), vexp.tau_max()) + + pgw.set_reltol(1.0e-6) + pgw.set_abstol(1.0e-7) + + assert_allclose(pgw.get_reltol(), 1.0e-6) + assert_allclose(pgw.get_abstol(), 1.0e-7) + + pgw.set_adiab_threshold(1.0e-3) + pgw.set_prop_threshold(1.0e-3) + + assert_allclose(pgw.get_adiab_threshold(), 1.0e-3) + assert_allclose(pgw.get_prop_threshold(), 1.0e-3) + + pgw.set_save_evol(True) + assert pgw.get_save_evol() + + pgw.set_save_evol(False) + assert not pgw.get_save_evol() + + pgw.set_initial_condition_type(Ncm.CSQ1DInitialStateType.AD_HOC) + assert pgw.get_initial_condition_type() == Ncm.CSQ1DInitialStateType.AD_HOC + + pgw.set_initial_condition_type(Ncm.CSQ1DInitialStateType.ADIABATIC2) + assert pgw.get_initial_condition_type() == Ncm.CSQ1DInitialStateType.ADIABATIC2 + + pgw.set_initial_condition_type(Ncm.CSQ1DInitialStateType.ADIABATIC4) + assert pgw.get_initial_condition_type() == Ncm.CSQ1DInitialStateType.ADIABATIC4 + + pgw.set_initial_condition_type(Ncm.CSQ1DInitialStateType.NONADIABATIC2) + assert pgw.get_initial_condition_type() == Ncm.CSQ1DInitialStateType.NONADIABATIC2 + + +def test_initial_conditions_time_vexp(pgw_vexp): + """Test initial conditions of NcHIPertAdiab.""" + pgw, vexp = pgw_vexp + + limit_found, t_adiab = pgw.find_adiab_time_limit( + vexp, vexp.tau_min(), pgw.get_vacuum_max_time(), 1.0e-6 + ) + + assert limit_found + assert t_adiab >= pgw.get_ti() + assert t_adiab <= pgw.get_tf() + + t_min, F1_min, t_lb, t_ub = pgw.find_adiab_max( + vexp, vexp.tau_min(), pgw.get_vacuum_max_time(), 1.0e-1 + ) + + assert_allclose(F1_min, pgw.eval_F1(vexp, t_min)) + assert math.fabs(F1_min - pgw.eval_F1(vexp, t_lb)) <= 1.0e-1 + assert math.fabs(F1_min - pgw.eval_F1(vexp, t_ub)) <= 1.0e-1 + + +def test_initial_conditions_adiabatic_vexp(pgw_vexp): + """Test initial conditions of NcHIPertAdiab.""" + pgw, vexp = pgw_vexp + + state = Ncm.CSQ1DState.new() + + for prec in np.geomspace(1.0e-14, 1.0e-6, 10): + limit_found, t_adiab = pgw.find_adiab_time_limit( + vexp, vexp.tau_min(), pgw.get_vacuum_max_time(), prec + ) + + assert limit_found + + # Getting the adiabatic solution + state, _alpha_reltol, _dgamma_reltol = pgw.compute_adiab(vexp, t_adiab, state) + pgw.change_frame(vexp, state, Ncm.CSQ1DFrame.ORIG) + phi_vec, Pphi_vec = state.get_phi_Pphi() + + phi = phi_vec[0] + 1.0j * phi_vec[1] + Pphi = Pphi_vec[0] + 1.0j * Pphi_vec[1] + + # Compare with analytical solution + assert np.isfinite(phi) + assert np.isfinite(Pphi) + + +def test_evolution_vexp(pgw_vexp): + """Test initial conditions of NcHIPertAdiab.""" + pgw, vexp = pgw_vexp + + state = Ncm.CSQ1DState.new() + + pgw.set_tf(1.0) # We do not want to evolve through the singularity + pgw.prepare(vexp) + + t_a, _smaller_abst = pgw.get_time_array() + + for t in t_a: + state = pgw.eval_at(vexp, t, state) + phi_vec, Pphi_vec = state.get_phi_Pphi() + + phi = phi_vec[0] + 1.0j * phi_vec[1] + Pphi = Pphi_vec[0] + 1.0j * Pphi_vec[1] + + # Compare with analytical solution + assert np.isfinite(abs(phi)) + assert np.isfinite(abs(Pphi)) + + J11, J12, J22 = state.get_J() + + assert np.isfinite(J11) + assert np.isfinite(J22) + assert np.isfinite(J12) + + +def test_evolution_vexp_duplicate(pgw_vexp): + """Test initial conditions of NcHIPertAdiab.""" + pgw, vexp = pgw_vexp + + ser = Ncm.Serialize.new(Ncm.SerializeOpt.CLEAN_DUP) + pgw_dup = ser.dup_obj(pgw) + vexp_dup = ser.dup_obj(vexp) + + test_evolution_vexp((pgw_dup, vexp_dup)) + + +def test_interface_eval_vexp(pgw_vexp): + """Test interface evaluation of NcHIPertAdiab.""" + _, vexp = pgw_vexp + + tau_a = np.linspace(vexp.tau_min() + 1.0, vexp.tau_max(), 1000) + + assert np.isfinite(Nc.HIPertIGW.eval_unit(vexp)) + for tau in tau_a: + assert np.isfinite(Nc.HIPertIGW.eval_F1(vexp, tau, 1.0)) + assert np.isfinite(Nc.HIPertIGW.eval_m(vexp, tau, 1.0)) + assert np.isfinite(Nc.HIPertIGW.eval_xi(vexp, tau, 1.0)) + assert np.isfinite(Nc.HIPertIGW.eval_nu(vexp, tau, 1.0)) + assert np.isfinite(Nc.HIPertIGW.eval_x(vexp, tau)) diff --git a/tests/test_py_numcosmo_app.py b/tests/test_py_numcosmo_app.py index 4e71fb5ef..203f6a2cd 100644 --- a/tests/test_py_numcosmo_app.py +++ b/tests/test_py_numcosmo_app.py @@ -26,6 +26,7 @@ from typing import Tuple from pathlib import Path + import pytest from typer.testing import CliRunner diff --git a/tests/test_py_ode_spline.py b/tests/test_py_ode_spline.py index a54d238b3..375a550f5 100644 --- a/tests/test_py_ode_spline.py +++ b/tests/test_py_ode_spline.py @@ -32,21 +32,26 @@ class RhsF: - """Test function for the ODE, it describes the right-hand - side of the equation $y_x = f(y,x)$.""" + """Test function for the ODE. + + It describes the right-hand side of the equation $y_x = f(y,x)$. + """ def __init__(self, alpha): + """Initialize the test function.""" self.alpha = alpha def rhs(self, y, _x, _data): - r"""Test function for the ODE, it describes the right-hand - side of the equation $y_x = f(y,x)$, here we use $f(y,x) = \alpha y$.""" + r"""Test function for the ODE. + + It describes the right-hand side of the equation $y_x = f(y,x)$, here we use + $f(y,x) = \alpha y$. + """ return self.alpha * y def test_ode_spline() -> None: """Test function for the ODE spline.""" - f = RhsF(2.5) s = Ncm.SplineCubicNotaknot.new() @@ -74,7 +79,6 @@ def test_ode_spline() -> None: def test_ode_spline_copy_props() -> None: """Test function for the ODE spline.""" - f = RhsF(2.5) s = Ncm.SplineCubicNotaknot.new() @@ -92,9 +96,8 @@ def test_ode_spline_copy_props() -> None: os = Ncm.OdeSpline.new(s, f.rhs) for prop in os0.list_properties(): - if prop.name == "dydx" or prop.name == "yf": + if prop.name in ("dydx", "yf"): continue - print(prop.name) os.set_property(prop.name, os0.get_property(prop.name)) assert isinstance(os, Ncm.OdeSpline) diff --git a/tests/test_py_powspec_ml_spline.py b/tests/test_py_powspec_ml_spline.py new file mode 100644 index 000000000..4b9824cba --- /dev/null +++ b/tests/test_py_powspec_ml_spline.py @@ -0,0 +1,198 @@ +#!/usr/bin/env python +# +# test_py_powspec_ml_spline.py +# +# Fri Mar 22 13:44:00 2024 +# Copyright 2023 Sandro Dias Pinto Vitenti +# +# +# test_py_powspec_ml_spline.py +# Copyright (C) 2024 Sandro Dias Pinto Vitenti +# +# numcosmo is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# numcosmo is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . + +"""Unit tests for NumCosmo powwer-spectra.""" + +import pytest + +import numpy as np +from numpy.testing import assert_allclose + +from numcosmo_py import Ncm, Nc + +Ncm.cfg_init() + + +@pytest.fixture(name="Pk") +def fixture_Pk() -> Ncm.Spline: + """Fixture for k array.""" + ka = np.geomspace(1.0e-5, 1.0e1, 1000) + Pk = 1.0e-9 * (ka / 0.05) ** (0.96 - 1.0) + + Pk_spline = Ncm.SplineCubicNotaknot.new() + Pk_spline.set_array(ka.tolist(), Pk.tolist(), True) + + return Pk_spline + + +def test_constructor(Pk: Ncm.Spline) -> None: + """Test the constructor of the power spectrum.""" + assert Pk is not None + + ps = Nc.PowspecMLSpline.new(Pk) + assert ps is not None + + assert Pk == ps.peek_spline() + + +def test_eval_z0(Pk: Ncm.Spline) -> None: + """Test the evaluation of the power spectrum.""" + ps = Nc.PowspecMLSpline.new(Pk) + assert ps is not None + + cosmo = Nc.HICosmoDEXcdm() + prim = Nc.HIPrimPowerLaw() + cosmo.add_submodel(prim) + + ps.prepare(cosmo) + + ka = Pk.peek_xv().dup_array() + + ps_Pka = [ps.eval(cosmo, 0, k) for k in ka] + Pka = [Pk.eval(k) for k in ka] + + assert_allclose(ps_Pka, Pka) + + +def test_eval_vec_z0(Pk: Ncm.Spline) -> None: + """Test the evaluation of the power spectrum.""" + ps = Nc.PowspecMLSpline.new(Pk) + assert ps is not None + + cosmo = Nc.HICosmoDEXcdm() + prim = Nc.HIPrimPowerLaw() + cosmo.add_submodel(prim) + + ps.prepare(cosmo) + + kv = Pk.peek_xv() + ka = Pk.peek_xv().dup_array() + Pkv = kv.dup() + + ps.eval_vec(cosmo, 0, kv, Pkv) + ps_Pka = Pkv.dup_array() + Pka = [Pk.eval(k) for k in ka] + + assert_allclose(ps_Pka, Pka) + + +def test_eval_za(Pk: Ncm.Spline) -> None: + """Test the evaluation of the power spectrum.""" + ps = Nc.PowspecMLSpline.new(Pk) + assert ps is not None + + cosmo = Nc.HICosmoDEXcdm() + prim = Nc.HIPrimPowerLaw() + cosmo.add_submodel(prim) + + gf = Nc.GrowthFunc() + + ps.prepare(cosmo) + gf.prepare(cosmo) + + ka = Pk.peek_xv().dup_array() + za = np.linspace(0, 1, 50) + + ps_Pka = [[ps.eval(cosmo, z, k) for k in ka] for z in za] + Pka = [[Pk.eval(k) * gf.eval(cosmo, z) ** 2 for k in ka] for z in za] + + assert_allclose(ps_Pka, Pka) + + +def test_eval_vec_za(Pk: Ncm.Spline) -> None: + """Test the evaluation of the power spectrum.""" + ps = Nc.PowspecMLSpline.new(Pk) + assert ps is not None + + cosmo = Nc.HICosmoDEXcdm() + prim = Nc.HIPrimPowerLaw() + cosmo.add_submodel(prim) + + gf = Nc.GrowthFunc() + + ps.prepare(cosmo) + gf.prepare(cosmo) + + kv = Pk.peek_xv() + ka = Pk.peek_xv().dup_array() + Pkv = kv.dup() + + za = np.linspace(0, 1, 50) + + ps_Pka = [] + for z in za: + ps.eval_vec(cosmo, z, kv, Pkv) + ps_Pka.append(Pkv.dup_array()) + + Pka = [[Pk.eval(k) * gf.eval(cosmo, z) ** 2 for k in ka] for z in za] + + assert_allclose(ps_Pka, Pka) + + +def test_get_knots(Pk: Ncm.Spline) -> None: + """Test the evaluation of the power spectrum.""" + ps = Nc.PowspecMLSpline.new(Pk) + assert ps is not None + + zi = ps.get_zi() + zf = ps.get_zf() + + assert zf > zi + + assert ps.get_nknots() == ((zf - zi) * 50, Pk.get_len()) + + +def test_serialization(Pk: Ncm.Spline) -> None: + """Test the serialization of the power spectrum.""" + + ps = Nc.PowspecMLSpline.new(Pk) + assert ps is not None + + ser = Ncm.Serialize.new(Ncm.SerializeOpt.CLEAN_DUP) + + ps_dup = ser.dup_obj(ps) + + assert ps_dup is not None + assert isinstance(ps_dup, Nc.PowspecMLSpline) + + cosmo = Nc.HICosmoDEXcdm() + prim = Nc.HIPrimPowerLaw() + cosmo.add_submodel(prim) + + ps.prepare(cosmo) + ps_dup.prepare(cosmo) + + kv = Pk.peek_xv() + Pkv = kv.dup() + + za = np.linspace(0, 1, 50) + ps_Pka = [] + ps_dup_Pka = [] + for z in za: + ps.eval_vec(cosmo, z, kv, Pkv) + ps_Pka.append(Pkv.dup_array()) + ps_dup.eval_vec(cosmo, z, kv, Pkv) + ps_dup_Pka.append(Pkv.dup_array()) + + assert_allclose(ps_Pka, ps_dup_Pka) diff --git a/tests/test_py_powspec_spline2d.py b/tests/test_py_powspec_spline2d.py new file mode 100644 index 000000000..2ab734a35 --- /dev/null +++ b/tests/test_py_powspec_spline2d.py @@ -0,0 +1,199 @@ +#!/usr/bin/env python +# +# test_py_powspec_ml_spline.py +# +# Fri Mar 22 13:44:00 2024 +# Copyright 2023 Sandro Dias Pinto Vitenti +# +# +# test_py_powspec_ml_spline.py +# Copyright (C) 2024 Sandro Dias Pinto Vitenti +# +# numcosmo is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# numcosmo is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see . + +"""Unit tests for NumCosmo powwer-spectra.""" + +import pytest + +import numpy as np +from numpy.testing import assert_allclose + +from numcosmo_py import Ncm + +Ncm.cfg_init() + + +def _f(z, k): + return 1.0e-9 * (k / 0.05) ** (0.96 - 1.0) * (1.0 + z) + + +@pytest.fixture(name="Pk2d") +def fixture_Pk2d() -> Ncm.Spline2d: + """Fixture for k array.""" + ka = np.geomspace(1.0e-5, 1.0e1, 1000) + za = np.linspace(0.0, 1.0, 50) + + za_v, ka_v = np.meshgrid(za, ka) + + Pk = np.log(_f(za_v, ka_v)) + + Pk2d = Ncm.Spline2dBicubic( + spline=Ncm.SplineCubicNotaknot.new(), + x_vector=Ncm.Vector.new_array(za.tolist()), + y_vector=Ncm.Vector.new_array(np.log(ka).tolist()), + z_matrix=Ncm.Matrix.new_array(Pk.flatten().tolist(), len(za)), + ) + + return Pk2d + + +def test_constructor(Pk2d: Ncm.Spline2d) -> None: + """Test the constructor of the power spectrum.""" + assert Pk2d is not None + + ps = Ncm.PowspecSpline2d.new(Pk2d) + assert ps is not None + assert isinstance(ps, Ncm.PowspecSpline2d) + assert isinstance(ps, Ncm.Powspec) + + assert Pk2d == ps.peek_spline2d() + + +def test_eval(Pk2d: Ncm.Spline2d) -> None: + """Test the evaluation of the power spectrum.""" + ps = Ncm.PowspecSpline2d.new(Pk2d) + + ps.prepare() + + assert_allclose(ps.eval(None, 0.0, 1.0), _f(0.0, 1.0)) + + s2d = ps.peek_spline2d() + + za = s2d.peek_xv().dup_array() + ka = np.exp(s2d.peek_yv().dup_array()) + + ps_Pka = np.array([[ps.eval(None, z, k) for k in ka] for z in za]) + Pka = np.array([np.exp([s2d.eval(z, np.log(k)) for k in ka]) for z in za]) + fa = np.array([[_f(z, k) for k in ka] for z in za]) + + assert_allclose(ps_Pka, Pka) + assert_allclose(ps_Pka, fa) + + +def test_eval_vec(Pk2d: Ncm.Spline2d) -> None: + """Test the evaluation of the power spectrum.""" + ps = Ncm.PowspecSpline2d.new(Pk2d) + + ps.prepare() + + assert_allclose(ps.eval(None, 0.0, 1.0), _f(0.0, 1.0)) + + s2d = ps.peek_spline2d() + + za = s2d.peek_xv().dup_array() + ka = np.exp(s2d.peek_yv().dup_array()) + + kv = Ncm.Vector.new_array(ka.tolist()) + Pkv = kv.dup() + + def _evec(z): + ps.eval_vec(None, z, kv, Pkv) + return Pkv.dup_array() + + ps_Pka = np.array([_evec(z) for z in za]) + Pka = np.array([np.exp([s2d.eval(z, np.log(k)) for k in ka]) for z in za]) + fa = np.array([[_f(z, k) for k in ka] for z in za]) + + assert_allclose(ps_Pka, Pka) + assert_allclose(ps_Pka, fa) + + +def test_get_spline2d(Pk2d: Ncm.Spline2d) -> None: + """Test the getter of the power spectrum.""" + ps = Ncm.PowspecSpline2d.new(Pk2d) + + assert ps is not None + + s2d = ps.peek_spline2d() + + assert s2d is not None + assert s2d == Pk2d + + sd2 = ps.get_spline_2d() + + assert sd2 is not None + assert sd2 == Pk2d + + +def test_serialization(Pk2d: Ncm.Spline2d) -> None: + """Test the serialization of the power spectrum.""" + ps = Ncm.PowspecSpline2d.new(Pk2d) + + ser = Ncm.Serialize.new(Ncm.SerializeOpt.CLEAN_DUP) + + ps_dup = ser.dup_obj(ps) + + assert ps_dup is not None + assert isinstance(ps_dup, Ncm.PowspecSpline2d) + + ps.prepare() + ps_dup.prepare() + + zv = Pk2d.peek_xv() + kv = Pk2d.peek_yv() + za = zv.dup_array() + Pkv = kv.dup() + + ps_Pka = [] + ps_dup_Pka = [] + for z in za: + ps.eval_vec(None, z, kv, Pkv) + ps_Pka.append(Pkv.dup_array()) + ps_dup.eval_vec(None, z, kv, Pkv) + ps_dup_Pka.append(Pkv.dup_array()) + + assert_allclose(ps_Pka, ps_dup_Pka) + + +def test_get_nknots(Pk2d: Ncm.Spline2d) -> None: + """Test the getter of the number of knots.""" + ps = Ncm.PowspecSpline2d.new(Pk2d) + + assert ps is not None + + s2d = ps.peek_spline2d() + + assert s2d is not None + assert s2d == Pk2d + + nknots = ps.get_nknots() + + assert nknots == (Pk2d.peek_xv().len(), Pk2d.peek_yv().len()) + + +def test_extrapolation(Pk2d: Ncm.Spline2d) -> None: + """Test the evaluation of the power spectrum.""" + ps = Ncm.PowspecSpline2d.new(Pk2d) + + ps.prepare() + + kmin = ps.get_kmin() + kmax = ps.get_kmax() + + # Test extrapolation, decreasing k, must be smaller than the value at kmin + for k_small in np.geomspace(kmin * 1.0e-5, kmin * 0.99, 100): + assert ps.eval(None, 0.0, k_small) < ps.eval(None, 0.0, kmin) + # Test extrapolation, increasing k, must be smaller than the value at kmax + for k_large in np.geomspace(kmax * 1.01, kmax * 1.0e5, 100): + assert ps.eval(None, 0.0, k_large) < ps.eval(None, 0.0, kmax)