CAMP 1.0.0
Chemistry Across Multiple Phases
time_derivative.h
Go to the documentation of this file.
1/* Copyright (C) 2021 Barcelona Supercomputing Center and University of
2 * Illinois at Urbana-Champaign
3 * SPDX-License-Identifier: MIT
4 *
5 * Header for the time derivative structure and related functions
6 *
7 */
8/** \file
9 * \brief Header for the time derivative structure and related functions
10 */
11#ifndef TIME_DERIVATIVE_H
12#define TIME_DERIVATIVE_H
13
14#include <math.h>
15#include <stdlib.h>
16
17// Threshhold for precisition loss in rate calculations
18#define MAX_PRECISION_LOSS 1.0e-14
19
20/* Time derivative for solver species */
21typedef struct {
22 unsigned int num_spec; // Number of species in the derivative
23 long double *production_rates; // Production rates for all species
24 long double *loss_rates; // Loss rates for all species
25#ifdef CAMP_DEBUG
26 double last_max_loss_precision; // Maximum loss of precision at last output
27#endif
29
30/** \brief Initialize the derivative
31 *
32 * \param time_deriv Pointer to the TimeDerivative object
33 * \param num_spec Number of species to include in the derivative
34 * \return Flag indicating whether the derivative was sucessfully initialized
35 * (0 = false; 1 = true)
36 */
38 unsigned int num_spec);
39
40/** \brief Reset the derivative
41 *
42 * \param time_deriv TimeDerivative object
43 */
45
46/** \brief Output the current derivative array
47 *
48 * \param time_deriv TimeDerivative object
49 * \param dest_array Pointer to the destination array
50 * \param deriv_est Pointer to an estimate of the derivative array (optional)
51 * \param output_precision Output the estimated loss of precision for each
52 * species if output_precision == 1
53 */
54void time_derivative_output(TimeDerivative time_deriv, double *dest_array,
55 double *deriv_est, unsigned int output_precision);
56
57/** \brief Add a contribution to the time derivative
58 *
59 * \param time_deriv TimeDerivative object
60 * \param spec_id Index of the species to update rates for
61 * \param rate_contribution Value to add to the time derivative for speces
62 * spec_id
63 */
64void time_derivative_add_value(TimeDerivative time_deriv, unsigned int spec_id,
65 long double rate_contribution);
66
67#ifdef CAMP_DEBUG
68/** \brief Maximum loss of precision at the last output of the derivative
69 * in bits
70 *
71 * \param time_deriv TimeDerivative object
72 * \return maximum loss of precision
73 */
74double time_derivative_max_loss_precision(TimeDerivative time_deriv);
75#endif
76
77/** \brief Free memory associated with a TimeDerivative
78 *
79 * \param time_deriv TimeDerivative object
80 */
82
83#endif
unsigned int num_spec
long double * loss_rates
long double * production_rates
void time_derivative_free(TimeDerivative time_deriv)
Free memory associated with a TimeDerivative.
int time_derivative_initialize(TimeDerivative *time_deriv, unsigned int num_spec)
Initialize the derivative.
void time_derivative_reset(TimeDerivative time_deriv)
Reset the derivative.
void time_derivative_output(TimeDerivative time_deriv, double *dest_array, double *deriv_est, unsigned int output_precision)
Output the current derivative array.
void time_derivative_add_value(TimeDerivative time_deriv, unsigned int spec_id, long double rate_contribution)
Add a contribution to the time derivative.