Astrochem C API reference

This document gives a comprehensive list of the types and functions that are defined in Astrochem C API. These types and functions are defined in the libastrochem.h header file. For an example of how to use the C API, see calling Astrochem from C.

Warning

Astrochem C API is recent and it is subject to change in future releases.

Types

species_name_t

Character array containing the species name

astrochem_mem_t

Astrochem memory structure

cell_t

Structure containing the parameters of a gas cell

double av

Visual extinction in the cell, in magnitudes

double nh

H nuclei density in the cell, in \(\mathrm{cm^{-3}}\)

double tgas

Gas temperature in the cell, in K

double tdust

Dust temperature in the cell, in K

net_t

Structure containing a chemical network

int n_species

Number of species in the network

int n_alloc_species

Number of allocated species in the network structure

species_t *species

Structure containing the species in the network

int n_reactions

Number of reactions

react_t *reactions

Structure containing the reactions in the network

phys_t
Structure containing the physical parameters
double chi

External UV radiation field, in Draine units

double cosmic

Cosmic ray ionization rate of molecular hydrogen, in \(\mathrm{s^{-1}}\)

double grain_size

The grain radius, in micron

double grain_abundance

The grain abundance

double grain_gas_mass_ratio

The grain-to-gas mass ratio

double grain_mass_density

The grain mass density in \(\mathrm{kg \, m^{-3}}\)

Functions

int alloc_abundances(const net_t* network, double** abundances)

Allocate an array to store the abundances for all species in a network

Parameters:
  • network (net_t*) – Network structure
  • abundances (double**) – Pointer on the abundance array
Returns:

EXIT_SUCCESS if the allocation was successful, EXIT_FAILURE otherwise

void free_abundances(double* abundances)

Free the array containing the abundances

Parameters:
  • abundances (double**) – Pointer on the abundance array
int find_species(const species_name_t specie, const net_t * network)

Find the index of a species

Parameters:
  • species_name_t species (const) – The species name
  • net_t network (const) – The network
Returns:

-1 if the species is “”, -2 if the species is not found, or the species index.

int set_initial_abundances(const char** species, int n_initialized_abundances, const double* initial_abundances, const net_t* network, double* abundances)

Set the initial abundances

Parameters:
  • species (char**) – Array containing the species name
  • n_initialized_abundances (int) – Number of initial abundances
  • initial_abundances (double*) – Array containing the initial abundances
  • network (net_t*) – Network structure
  • abundances (double*) – Array containing the abundances of all species
Returns:

0

int solver_init(const cell_t* cell, const net_t* network, const phys_t* phys, const double* abundances, double density, double abs_err, double rel_err, astrochem_mem_t* astrochem_mem)

Initialize the solver

Parameters:
  • cell (cell_t*) – Cell structure
  • network (net_t*) – Network structure
  • phys (phys_t*) – Physical parameters structure
  • abundances (double*) – Array containing the abundances of all species
  • density (double) – Initial density, in \(\mathrm{cm^{-3}}\)
  • abs_err (double) – Solver absolute error on the abundances
  • rel_err (double) – Solver relative error on the abundances
  • astrochem_mem (astrochem_mem_t*) – Astrochem memory structure
Returns:

0 if the initialization was successful, -1 otherwise.

int solve(astrochem_mem_t* astrochem_mem, const net_t* network, double* abundances, double time, const cell_t* new_cell, int verbose)

Solve the system of ODE

This function solve the system of ODE up to a given time, and update the abundance array. If the physical parameters in the gas cell have changed since the last call, a pointer to cell structure must be passed to the function; if not, a null pointer must be passed instead.

Parameters:
  • astrochem_mem (astrochem_mem_t*) – Astrochem memory structure
  • network (net_t*) – Network structure
  • abundances (double*) – Array containing the abundances of all species
  • time (double) – Time, in seconds
  • new_cell (cell_t*) – New cell structure if the physical parameters have changed since the last call
  • verbose (int) – Verbosity (0 for quiet, 1 for verbose)
Returns:

0

void solver_close(astrochem_mem_t* astrochem_mem)

Close the solver

Parameters:
int read_network(const char* chem_file, net_t* network, const int verbose)

Read a chemical network

This function reads a chemical network in Astrochem format (.chm) and creates a network structure containing all the reactions.

Parameters:
  • chem_file (char*) – Network filename
  • network (net_t*) – Network structure
  • verbose (int) – Verbosity (0 for quiet, 1 for verbose)
Returns:

EXIT_SUCCESS after a successful call, EXIT_FAILURE otherwise

void free_network(net_t * network)

Free a chemical network structure

Parameters:
  • network (net_t*) – Network structure