Fast Methods for Cosmological Simulations
FastSim serves as a tool for quick N-body simulations in modified gravity.
ccl_error.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <math.h>
#include <gsl/gsl_errno.h>
#include "ccl.h"
Include dependency graph for ccl_error.c:

Go to the source code of this file.

Functions

void ccl_set_error_policy (CCLErrorPolicy error_policy)
 
void ccl_set_debug_policy (CCLDebugModePolicy debug_policy)
 
void ccl_raise_exception (int err, const char *msg,...)
 
void ccl_raise_warning (int err, const char *msg,...)
 
void ccl_raise_gsl_warning (int gslstatus, const char *msg,...)
 
void ccl_check_status (ccl_cosmology *cosmo, int *status)
 
void ccl_check_status_nocosmo (int *status)
 

Variables

static CCLErrorPolicy _ccl_error_policy = CCL_ERROR_POLICY_EXIT
 
static CCLDebugModePolicy _ccl_debug_mode_policy = CCL_DEBUG_MODE_WARNING
 

Function Documentation

void ccl_check_status ( ccl_cosmology cosmo,
int *  status 
)

Check the error status Given a status, check if any errors have occurred, based on the CCL_ERRORs defined so far.

Returns
void

Definition at line 88 of file ccl_error.c.

References CCL_ERROR_COMPUTECHI, CCL_ERROR_HMF_INTERP, CCL_ERROR_LINSPACE, CCL_ERROR_NU_INT, CCL_ERROR_NU_SOLVE, CCL_ERROR_SPLINE, ccl_raise_exception(), and ccl_cosmology::status_message.

Referenced by ccl_angular_cl_native(), ccl_angular_cls(), ccl_cl_tracer(), ccl_comoving_angular_distance(), ccl_comoving_radial_distance(), ccl_correlation(), ccl_correlation_3d(), ccl_cosmology_compute_power(), ccl_distance_modulus(), ccl_dlninvsig_dlogm(), ccl_growth_factor(), ccl_growth_factor_unnorm(), ccl_growth_rate(), ccl_h_over_h0(), ccl_halo_bias(), ccl_omega_x(), ccl_scale_factor_of_chi(), ccl_sigmaM(), h_over_h0(), and massfunc_f().

89 {
90 
91  switch (*status) {
92  case 0: // all good, nothing to do
93  return;
94  case CCL_ERROR_LINSPACE: // spacing allocation error, always terminate
96  case CCL_ERROR_SPLINE: // spline allocation error, always terminate
98  case CCL_ERROR_COMPUTECHI: // compute_chi error //RH
100  case CCL_ERROR_HMF_INTERP: // terminate if hmf definition not supported
102  case CCL_ERROR_NU_INT: // error in getting the neutrino integral spline: exit. No status_message in cosmo because can't pass cosmology to the function.
103  ccl_raise_exception(*status, "Error, in ccl_neutrinos.c. ccl_calculate_nu_phasespace_spline(): Error in setting neutrino phasespace spline.");
104  case CCL_ERROR_NU_SOLVE: // error in converting Omeganuh2-> Mnu: exit. No status_message in cosmo because can't pass cosmology to the function.
105  ccl_raise_exception(*status, "Error, in ccl_neutrinos.c. Omeganuh2_to_Mnu(): Root finding did not converge.");
106  // TODO: Implement softer error handling, e.g. for integral convergence here
107  default:
109  }
110 }
void ccl_raise_exception(int err, const char *msg,...)
Definition: ccl_error.c:35
#define CCL_ERROR_NU_SOLVE
Definition: ccl_error.h:24
#define CCL_ERROR_HMF_INTERP
Definition: ccl_error.h:20
#define CCL_ERROR_NU_INT
Definition: ccl_error.h:22
#define CCL_ERROR_SPLINE
Definition: ccl_error.h:13
#define CCL_ERROR_LINSPACE
Definition: ccl_error.h:11
#define CCL_ERROR_COMPUTECHI
Definition: ccl_error.h:18
char status_message[500]
Definition: ccl_core.h:136
void ccl_check_status_nocosmo ( int *  status)

Check the error status - no cosmology Given a status, check if any errors have occurred, based on the CCL_ERRORs defined so far.

Returns
void

Definition at line 116 of file ccl_error.c.

References CCL_ERROR_COMPUTECHI, CCL_ERROR_HMF_INTERP, CCL_ERROR_LINSPACE, CCL_ERROR_MNU_UNPHYSICAL, CCL_ERROR_NOT_IMPLEMENTED, CCL_ERROR_NU_INT, CCL_ERROR_NU_SOLVE, CCL_ERROR_SPLINE, and ccl_raise_exception().

Referenced by ccl_nu_masses(), ccl_parameters_create(), ccl_parameters_fill_initial(), and nu_phasespace_intg().

117 {
118  switch (*status) {
119  case 0: // Nothing to do
120  return;
121  case CCL_ERROR_LINSPACE:
122  // Spacing allocation error, always terminate
123  ccl_raise_exception(*status, "CCL_ERROR_LINSPACE: Spacing allocation error.");
124  case CCL_ERROR_SPLINE:
125  // Spline allocation error, always terminate
126  ccl_raise_exception(*status, "CCL_ERROR_SPLINE: Spline allocation error.");
128  // Compute_chi error
130  "CCL_ERROR_COMPUTECHI: Comoving distance chi computation failed.");
132  // Terminate if hmf definition not supported
134  "CCL_ERROR_HMF_INTERP: Halo mass function definition not supported.");
135  case CCL_ERROR_NU_INT:
136  // Error in getting the neutrino integral spline: exit. No status_message
137  // in cosmo because can't pass cosmology to the function.
139  "CCL_ERROR_NU_INT: Error getting the neutrino phase-space integral spline.");
140  case CCL_ERROR_NU_SOLVE:
141  // Error in converting Omeganuh2-> Mnu: exit. No status_message in cosmo
142  // because can't pass cosmology to the function.
144  "CCL_ERROR_NU_SOLVE: Error converting Omeganuh2 -> Mnu.");
146  // Error in the sum of mnu or Omeganu passed for the hierarchy requested.
148  "CCL_ERROR_MNU_UNPHYSICAL: Sum of neutrinos masses for this Omeganu value is incompatible with the requested mass hierarchy.");
151  "CCL_ERROR_NOT_IMPLEMENTED: the type of m_nu specified is not supported.");
152  default:
154  "Unrecognized error code (see gsl_errno.h for error codes 1-32).");
155  }
156 }
void ccl_raise_exception(int err, const char *msg,...)
Definition: ccl_error.c:35
#define CCL_ERROR_NOT_IMPLEMENTED
Definition: ccl_error.h:25
#define CCL_ERROR_NU_SOLVE
Definition: ccl_error.h:24
#define CCL_ERROR_HMF_INTERP
Definition: ccl_error.h:20
#define CCL_ERROR_NU_INT
Definition: ccl_error.h:22
#define CCL_ERROR_SPLINE
Definition: ccl_error.h:13
#define CCL_ERROR_LINSPACE
Definition: ccl_error.h:11
#define CCL_ERROR_MNU_UNPHYSICAL
Definition: ccl_error.h:26
#define CCL_ERROR_COMPUTECHI
Definition: ccl_error.h:18
void ccl_raise_exception ( int  err,
const char *  msg,
  ... 
)

Raise an exception Given a status, give an error message.

Returns
void

Definition at line 35 of file ccl_error.c.

References _ccl_debug_mode_policy, _ccl_error_policy, CCL_DEBUG_MODE_ON, and CCL_ERROR_POLICY_EXIT.

Referenced by calculate_nu_phasespace_spline(), ccl_check_status(), ccl_check_status_nocosmo(), ccl_cosmology_read_config(), ccl_dNdz_tomog(), ccl_halo_concentration(), ccl_norm_integrand(), ccl_parameters_read_yaml(), ccl_pkemu(), and window_function().

36 {
37  char message[256];
38 
39  va_list va;
40  va_start(va, msg);
41  vsnprintf(message, 250, msg, va);
42  va_end(va);
43 
44  // Print error message and exit if fatal errors are enabled
45  if ((_ccl_error_policy == CCL_ERROR_POLICY_EXIT) && (err)) {
46  fprintf(stderr, "ERROR %d: %s\n", err, message);
47  exit(1);
48  }
49  // Print error message and exit if debug output is enabled
50  else if ((_ccl_debug_mode_policy == CCL_DEBUG_MODE_ON) && (err)){
51  fprintf(stderr, "ERROR %d: %s\n", err, message);
52  }
53 }
static CCLErrorPolicy _ccl_error_policy
Definition: ccl_error.c:12
static CCLDebugModePolicy _ccl_debug_mode_policy
Definition: ccl_error.c:20
void ccl_raise_gsl_warning ( int  gslstatus,
const char *  msg,
  ... 
)

Raise a warning based on a GSL error message Given a GSL status, give a warning message.

Returns
void

Definition at line 75 of file ccl_error.c.

References ccl_raise_warning().

Referenced by a_of_chi(), calculate_nu_phasespace_spline(), ccl_angular_cl_native(), ccl_comoving_angular_distance(), ccl_comoving_radial_distance(), ccl_cosmology_compute_growth(), ccl_cosmology_compute_sigma(), ccl_dlninvsig_dlogm(), ccl_dNdz_tomog(), ccl_growth_factor(), ccl_growth_rate(), ccl_h_over_h0(), ccl_linear_matter_power(), ccl_nonlin_matter_power(), ccl_norm_integrand(), ccl_power_extrapol_highk(), ccl_power_extrapol_lowk(), ccl_scale_factor_of_chi(), ccl_sigmaM(), ccl_sigmaR(), ccl_sigmaV(), ccl_spline_eval(), ccl_tracer_corr_bessel(), clt_init_nz(), compute_chi(), growth_factor_and_growth_rate(), massfunc_f(), nu_phasespace_intg(), one_halo_integral(), two_halo_integral(), window_lensing(), and window_magnification().

76 {
77  char message[256];
78 
79  va_list va;
80  va_start(va, msg);
81  vsnprintf(message, 250, msg, va);
82  va_end(va);
83 
84  ccl_raise_warning(gslstatus, "%s GSL error: %s", message, gsl_strerror(gslstatus));
85  return;
86 }
void ccl_raise_warning(int err, const char *msg,...)
Definition: ccl_error.c:56
void ccl_raise_warning ( int  err,
const char *  msg,
  ... 
)

Raise a warning Given a status, give a warning message.

Returns
void

Definition at line 56 of file ccl_error.c.

References _ccl_debug_mode_policy, CCL_DEBUG_MODE_ON, and CCL_DEBUG_MODE_WARNING.

Referenced by ccl_linear_spacing(), ccl_linlog_spacing(), ccl_log_spacing(), ccl_nonlin_matter_power(), and ccl_raise_gsl_warning().

57 {
58  char message[256];
59 
60  va_list va;
61  va_start(va, msg);
62  vsnprintf(message, 250, msg, va);
63  va_end(va);
64 
65  // For now just print warning to stderr if debug is enabled.
66  // TODO: Implement some kind of error stack that can be passed on to, e.g.,
67  // the python binding.
70  fprintf(stderr, "WARNING: %s\n", message);
71  }
72 }
static CCLDebugModePolicy _ccl_debug_mode_policy
Definition: ccl_error.c:20
void ccl_set_debug_policy ( CCLDebugModePolicy  debug_policy)

Set the error policy debug_policy the debug mode policy

Returns
void

Definition at line 29 of file ccl_error.c.

References _ccl_debug_mode_policy.

Referenced by compare_cls(), compare_corr(), and Cosmo_Param::init().

30 {
31  _ccl_debug_mode_policy = debug_policy;
32 }
static CCLDebugModePolicy _ccl_debug_mode_policy
Definition: ccl_error.c:20
void ccl_set_error_policy ( CCLErrorPolicy  error_policy)

Set the error policy error_policy the error policy

Returns
void

Definition at line 23 of file ccl_error.c.

References _ccl_error_policy.

Referenced by Cosmo_Param::init().

24 {
25  _ccl_error_policy = error_policy;
26 }
static CCLErrorPolicy _ccl_error_policy
Definition: ccl_error.c:12

Variable Documentation

CCLDebugModePolicy _ccl_debug_mode_policy = CCL_DEBUG_MODE_WARNING
static

Definition at line 20 of file ccl_error.c.

Referenced by ccl_raise_exception(), ccl_raise_warning(), and ccl_set_debug_policy().

CCLErrorPolicy _ccl_error_policy = CCL_ERROR_POLICY_EXIT
static

Definition at line 12 of file ccl_error.c.

Referenced by ccl_raise_exception(), and ccl_set_error_policy().