testCosmology.c 2.42 KB
Newer Older
lhausamm's avatar
lhausamm committed
1 2
/*******************************************************************************
 * This file is part of SWIFT.
Matthieu Schaller's avatar
Matthieu Schaller committed
3
 * Copyright (c) 2018 Loic Hausamman (loic.hausammann@epfl.ch)
lhausamm's avatar
lhausamm committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program 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 Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 ******************************************************************************/

/* Some standard headers. */
21
#include "../config.h"
lhausamm's avatar
lhausamm committed
22 23 24 25

/* Includes. */
#include "swift.h"

26 27
#define N_CHECK 20
#define TOLERANCE 1e-7
lhausamm's avatar
lhausamm committed
28 29 30 31 32 33 34

void test_params_init(struct swift_params *params) {
  parser_init("", params);
  parser_set_param(params, "Cosmology:Omega_m:0.3075");
  parser_set_param(params, "Cosmology:Omega_lambda:0.6910");
  parser_set_param(params, "Cosmology:Omega_b:0.0486");
  parser_set_param(params, "Cosmology:h:0.6774");
35
  parser_set_param(params, "Cosmology:a_begin:0.1");
lhausamm's avatar
lhausamm committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
  parser_set_param(params, "Cosmology:a_end:1.0");
}

int main(int argc, char *argv[]) {

  message("Initialization...");

  /* pseudo initialization of params */
  struct swift_params params;
  test_params_init(&params);

  /* initialization of unit system */
  struct unit_system us;
  units_init_cgs(&us);

Matthieu Schaller's avatar
Matthieu Schaller committed
51
  /* initialization of phys_const */
lhausamm's avatar
lhausamm committed
52 53 54 55 56 57 58 59 60
  struct phys_const phys_const;
  phys_const_init(&us, &params, &phys_const);

  /* initialization of cosmo */
  struct cosmology cosmo;
  cosmology_init(&params, &us, &phys_const, &cosmo);

  message("Start checking computation...");

Matthieu Schaller's avatar
Matthieu Schaller committed
61
  for (int i = 0; i < N_CHECK; i++) {
62
    double a = 0.1 + 0.9 * i / (N_CHECK - 1.);
lhausamm's avatar
lhausamm committed
63
    /* Compute a(t(a)) and check if same results */
64 65
    double tmp = cosmology_get_time_since_big_bang(&cosmo, a);
    tmp = cosmology_get_scale_factor(&cosmo, tmp);
lhausamm's avatar
lhausamm committed
66 67

    /* check accuracy */
68 69 70
    tmp = (tmp - a) / a;
    message("Accuracy of %g at a=%g", tmp, a);
    assert(fabs(tmp) < TOLERANCE);
lhausamm's avatar
lhausamm committed
71 72 73 74
  }

  message("Everything seems fine with cosmology.");

Loic Hausammann's avatar
Loic Hausammann committed
75
  cosmology_clean(&cosmo);
lhausamm's avatar
lhausamm committed
76 77
  return 0;
}