Skip to content

Commit

Permalink
Tests for de_cont.
Browse files Browse the repository at this point in the history
  • Loading branch information
vitenti committed Apr 22, 2024
1 parent 9d29314 commit 639a6f7
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,10 @@ python_tests = [
'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',
Expand Down
116 changes: 116 additions & 0 deletions tests/test_py_de_cont.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#
# test_py_de_cont.py
#
# Sun Apr 21 21:40:35 2024
# Copyright 2024 Sandro Dias Pinto Vitenti
# <vitenti@uel.br>
#
# test_de_cont.py
# Copyright (C) 2024 Sandro Dias Pinto Vitenti <vitenti@uel.br>
#
# 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 <http://www.gnu.org/licenses/>.

"""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
)
15 changes: 15 additions & 0 deletions tests/test_py_hipert_gw.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,18 @@ def test_evolution_vexp_duplicate(pgw_vexp):
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))

0 comments on commit 639a6f7

Please sign in to comment.