Simple C

A very simple example in C

Compiling

If you installed NumCosmo in your system, compile the example using:

gcc -Wall example_simple.c -o example_simple `pkg-config glib-2.0 numcosmo --libs --cflags`

If you followed the instructions on how to use the library without installing it described here, compile using:

libtool --mode=link gcc -Wall example_simple.c -o example_simple  \
  ${NUMCOSMO_BUILD_DIR}/numcosmo/libnumcosmo.la -I${NUMCOSMO_DIR} \
  -I${NUMCOSMO_BUILD_DIR} `pkg-config --cflags glib-2.0`

example_simple.c:

#include <glib.h>
#include <numcosmo/numcosmo.h>

gint
main (gint argc, gchar *argv[])
{
  NcHICosmo *cosmo;
  NcDistance *dist;

  /**************************************************************************** 
   * Initializing the library objects, this must be called before 
   * any other library function.
   ****************************************************************************/  
  ncm_cfg_init ();
  
  /**************************************************************************** 
   * New homogeneous and isotropic cosmological model NcHICosmoDEXcdm.
   ****************************************************************************/  
  cosmo = nc_hicosmo_new_from_name (NC_TYPE_HICOSMO, "NcHICosmoDEXcdm");

  /**************************************************************************** 
   * New cosmological distance objects optimizied to perform calculations
   * up to redshift 2.0.
   ****************************************************************************/  
  dist = nc_distance_new (2.0);
 
  /**************************************************************************** 
   * Setting values for the cosmological model, those not set stay in the
   * default values. Remeber to use the _orig_ version to set the original
   * parameters in case when a reparametrization is used.
   ****************************************************************************/ 
  ncm_model_orig_param_set (NCM_MODEL (cosmo), NC_HICOSMO_DE_H0,       70.00);
  ncm_model_orig_param_set (NCM_MODEL (cosmo), NC_HICOSMO_DE_OMEGA_C,   0.25);
  ncm_model_orig_param_set (NCM_MODEL (cosmo), NC_HICOSMO_DE_OMEGA_X,   0.70);
  ncm_model_orig_param_set (NCM_MODEL (cosmo), NC_HICOSMO_DE_T_GAMMA0,  2.72);
  ncm_model_orig_param_set (NCM_MODEL (cosmo), NC_HICOSMO_DE_OMEGA_B,   0.05);
  ncm_model_orig_param_set (NCM_MODEL (cosmo), NC_HICOSMO_DE_XCDM_W,   -1.10);

  /**************************************************************************** 
   * Printing the parameters used.
   ****************************************************************************/
  printf ("# Model parameters:\n"); 
  ncm_model_params_log_all (NCM_MODEL (cosmo));

  /**************************************************************************** 
   * Printing some distances up to redshift 1.0.
   ****************************************************************************/ 
  {
    const guint N        = 20;
    const gdouble RH_Mpc = nc_hicosmo_RH_Mpc (cosmo); /* Hubble radius in Mpc */
    gint i;
    
    for (i = 0; i < N; i++)
    {
      const gdouble z  = 1.0 / (N - 1.0) * i;
      const gdouble Dc = nc_distance_comoving (dist, cosmo, z); /* Comoving distance in Hubble radius */
      const gdouble dc = RH_Mpc * Dc;                           /* Comoving distance in Mpc           */
      printf ("% 10.8f % 22.15g [c/H0] % 22.15g [Mpc]\n", z, Dc, dc);
    }
  }

  /**************************************************************************** 
   * Freeing objects.
   ****************************************************************************/ 
  nc_distance_free (dist);
  nc_hicosmo_free (cosmo);

  return 0;
}

example_simple.out:

# Model parameters:
                    70                  0.25                   0.7                  2.72                  0.24                 3.046                  0.05                  -1.1
 0.00000000                      0 [c/H0]                      0 [Mpc]
 0.05263158     0.0521377559298115 [c/H0]       223.292942925747 [Mpc]
 0.10526316      0.103229633958573 [c/H0]       442.106652898297 [Mpc]
 0.15789474      0.153200085698555 [c/H0]       656.117575105436 [Mpc]
 0.21052632      0.201989077468175 [c/H0]       865.068600333381 [Mpc]
 0.26315789       0.24955145898559 [c/H0]       1068.76636123966 [Mpc]
 0.31578947      0.295855978251394 [c/H0]       1267.07701334257 [Mpc]
 0.36842105      0.340884045742703 [c/H0]       1459.92094237414 [Mpc]
 0.42105263      0.384628341975792 [c/H0]       1647.26680081982 [Mpc]
 0.47368421      0.427091357468411 [c/H0]       1829.12525494302 [Mpc]
 0.52631579      0.468283936506924 [c/H0]       2005.54274810467 [Mpc]
 0.57894737      0.508223879715267 [c/H0]       2176.59551591623 [Mpc]
 0.63157895      0.546934643883322 [c/H0]       2342.38401793051 [Mpc]
 0.68421053      0.584444162901236 [c/H0]       2503.02788799877 [Mpc]
 0.73684211       0.62078380163305 [c/H0]       2658.66145397367 [Mpc]
 0.78947368      0.655987445322446 [c/H0]       2809.42983786224 [Mpc]
 0.84210526      0.690090720482999 [c/H0]       2955.48561909413 [Mpc]
 0.89473684      0.723130338819152 [c/H0]       3096.98602469952 [Mpc]
 0.94736842        0.7551435532122 [c/H0]       3234.09059943342 [Mpc]
 1.00000000      0.786167713053817 [c/H0]       3366.95930138061 [Mpc]

Example Directory