Skip to content

Commit

Permalink
Testing interface implementation for Vexp.
Browse files Browse the repository at this point in the history
  • Loading branch information
vitenti committed Apr 18, 2024
1 parent c9fb9e8 commit b3c4333
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 33 deletions.
34 changes: 1 addition & 33 deletions numcosmo/model/nc_hicosmo_qgw.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,36 +72,6 @@ nc_hicosmo_qgw_init (NcHICosmoQGW *cosmo_qgw)
self->place_holder = 0;
}

static void
_nc_hicosmo_qgw_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
{
NcHICosmoQGW *qgw = NC_HICOSMO_QGW (object);

g_return_if_fail (NC_IS_HICOSMO_QGW (object));

switch (prop_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}

static void
_nc_hicosmo_qgw_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
{
NcHICosmoQGW *qgw = NC_HICOSMO_QGW (object);

g_return_if_fail (NC_IS_HICOSMO_QGW (object));

switch (prop_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}

static void
nc_hicosmo_qgw_finalize (GObject *object)
{
Expand All @@ -127,9 +97,7 @@ nc_hicosmo_qgw_class_init (NcHICosmoQGWClass *klass)
NcHICosmoClass *parent_class = NC_HICOSMO_CLASS (klass);
NcmModelClass *model_class = NCM_MODEL_CLASS (klass);

model_class->set_property = &_nc_hicosmo_qgw_set_property;
model_class->get_property = &_nc_hicosmo_qgw_get_property;
object_class->finalize = nc_hicosmo_qgw_finalize;
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);
Expand Down
73 changes: 73 additions & 0 deletions tests/test_py_hicosmo_Vexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

"""Tests on NcHICosmoVexp cosmological model."""

from itertools import product
from numpy.testing import assert_allclose
import numpy as np

Expand Down Expand Up @@ -165,6 +166,78 @@ def test_serialize():
assert vexp2.props.xb == vexp.props.xb # pylint: disable=no-member


def test_eval_at():
"""Evaluate NcHICosmoVexp at a given time."""
vexp = Nc.HICosmoVexp()
assert vexp is not None

tau_min = vexp.tau_min()
tau_max = vexp.tau_max()

tau_a = np.linspace(tau_min, tau_max, 1000)

for tau in tau_a:
assert np.isfinite(vexp.x_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():
"""Evaluate NcHICosmoVexp implementation of NcHIPertAdiab at a given time."""
vexp = Nc.HICosmoVexp()
assert vexp is not None

tau_min = vexp.tau_min()
tau_max = vexp.tau_max()

tau_a = np.linspace(tau_min, tau_max, 1000)
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))


def test_igw_eval_at():
"""Evaluate NcHICosmoVexp implementation of NcHIPertIGW at a given time."""
vexp = Nc.HICosmoVexp()
assert vexp is not None

tau_min = vexp.tau_min()
tau_max = vexp.tau_max()

tau_a = np.linspace(tau_min, tau_max, 1000)
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():
"""Evaluate NcHICosmoVexp implementation of NcHIPertIEM at a given time."""
vexp = Nc.HICosmoVexp()
assert vexp is not None

tau_min = vexp.tau_min()
tau_max = vexp.tau_max()

tau_a = np.linspace(tau_min, tau_max, 1000)
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))


if __name__ == "__main__":
test_init()
test_hubble_negative_dphi()
Expand Down

0 comments on commit b3c4333

Please sign in to comment.