CAMP 1.0.0
Chemistry Across Multiple Phases
camp_solver.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 file for solver functions
6 *
7 */
8/** \file
9 * \brief Header file for solver functions
10 */
11#ifndef CAMP_SOLVER_H_
12#define CAMP_SOLVER_H_
13#include "camp_common.h"
14
15/* Functions called by camp-chem */
16void *solver_new(int n_state_var, int n_cells, int *var_type, int n_rxn,
17 int n_rxn_int_param, int n_rxn_float_param,
18 int n_rxn_env_param, int n_aero_phase,
19 int n_aero_phase_int_param, int n_aero_phase_float_param,
20 int n_aero_rep, int n_aero_rep_int_param,
21 int n_aero_rep_float_param, int n_aero_rep_env_param,
22 int n_sub_model, int n_sub_model_int_param,
23 int n_sub_model_float_param, int n_sub_model_env_param);
24void solver_initialize(void *solver_data, double *abs_tol, double rel_tol,
25 int max_steps, int max_conv_fails);
26#ifdef CAMP_DEBUG
27int solver_set_debug_out(void *solver_data, bool do_output);
28int solver_set_eval_jac(void *solver_data, bool eval_Jac);
29#endif
30int solver_run(void *solver_data, double *state, double *env, double t_initial,
31 double t_final);
32void solver_get_statistics(void *solver_data, int *solver_flag, int *num_steps,
33 int *RHS_evals, int *LS_setups,
34 int *error_test_fails, int *NLS_iters,
35 int *NLS_convergence_fails, int *DLS_Jac_evals,
36 int *DLS_RHS_evals, double *last_time_step__s,
37 double *next_time_step__s, int *Jac_eval_fails,
38 int *RHS_evals_total, int *Jac_evals_total,
39 double *RHS_time__s, double *Jac_time__s,
40 double *max_loss_precision);
41void solver_free(void *solver_data);
42void model_free(ModelData model_data);
43
44#ifdef CAMP_USE_SUNDIALS
45/* Functions called by the solver */
46int f(realtype t, N_Vector y, N_Vector deriv, void *model_data);
47int Jac(realtype t, N_Vector y, N_Vector deriv, SUNMatrix J, void *model_data,
48 N_Vector tmp1, N_Vector tmp2, N_Vector tmp3);
49int guess_helper(const realtype t_n, const realtype h_n, N_Vector y_n,
50 N_Vector y_n1, N_Vector hf, void *solver_data, N_Vector tmp1,
51 N_Vector corr);
52void error_handler(int error_code, const char *module, const char *function,
53 char *msg, void *sd);
54
55/* SUNDIALS support functions */
56int camp_solver_update_model_state(N_Vector solver_state, ModelData *model_data,
57 realtype threshhold,
58 realtype replacement_value);
59SUNMatrix get_jac_init(SolverData *solver_data);
60bool check_Jac(realtype t, N_Vector y, SUNMatrix J, N_Vector deriv,
61 N_Vector tmp, N_Vector tmp1, void *solver_data);
62int check_flag(void *flag_value, char *func_name, int opt);
63void check_flag_fail(void *flag_value, char *func_name, int opt);
64void solver_reset_timers(void *solver_data);
65static void solver_print_stats(void *cvode_mem);
66static void print_data_sizes(ModelData *md);
67static void print_jacobian(SUNMatrix M);
68static void print_derivative(N_Vector deriv);
69bool is_anything_going_on_here(SolverData *sd, realtype t_initial,
70 realtype t_final);
71#endif
72
73#endif
Header file for common constants and structures.
void model_free(ModelData model_data)
Free a ModelData object.
int check_flag(void *flag_value, char *func_name, int opt)
Check the return value of a SUNDIALS function.
void solver_get_statistics(void *solver_data, int *solver_flag, int *num_steps, int *RHS_evals, int *LS_setups, int *error_test_fails, int *NLS_iters, int *NLS_convergence_fails, int *DLS_Jac_evals, int *DLS_RHS_evals, double *last_time_step__s, double *next_time_step__s, int *Jac_eval_fails, int *RHS_evals_total, int *Jac_evals_total, double *RHS_time__s, double *Jac_time__s, double *max_loss_precision)
Get solver statistics after an integration attempt.
int camp_solver_update_model_state(N_Vector solver_state, ModelData *model_data, realtype threshhold, realtype replacement_value)
Update the model state from the current solver state.
int guess_helper(const realtype t_n, const realtype h_n, N_Vector y_n, N_Vector y_n1, N_Vector hf, void *solver_data, N_Vector tmp1, N_Vector corr)
bool is_anything_going_on_here(SolverData *sd, realtype t_initial, realtype t_final)
Determine if there is anything to solve.
void solver_initialize(void *solver_data, double *abs_tol, double rel_tol, int max_steps, int max_conv_fails)
Solver initialization.
SUNMatrix get_jac_init(SolverData *solver_data)
Try to improve guesses of y sent to the linear solver.
static void print_jacobian(SUNMatrix M)
void * solver_new(int n_state_var, int n_cells, int *var_type, int n_rxn, int n_rxn_int_param, int n_rxn_float_param, int n_rxn_env_param, int n_aero_phase, int n_aero_phase_int_param, int n_aero_phase_float_param, int n_aero_rep, int n_aero_rep_int_param, int n_aero_rep_float_param, int n_aero_rep_env_param, int n_sub_model, int n_sub_model_int_param, int n_sub_model_float_param, int n_sub_model_env_param)
Get a new solver object.
Definition camp_solver.c:73
void check_flag_fail(void *flag_value, char *func_name, int opt)
Check the return value of a SUNDIALS function and exit on failure.
int Jac(realtype t, N_Vector y, N_Vector deriv, SUNMatrix J, void *model_data, N_Vector tmp1, N_Vector tmp2, N_Vector tmp3)
Compute the Jacobian.
int f(realtype t, N_Vector y, N_Vector deriv, void *model_data)
Compute the time derivative f(t,y)
void solver_free(void *solver_data)
Free a SolverData object.
static void print_derivative(N_Vector deriv)
static void solver_print_stats(void *cvode_mem)
void error_handler(int error_code, const char *module, const char *function, char *msg, void *sd)
Custom error handling function.
bool check_Jac(realtype t, N_Vector y, SUNMatrix J, N_Vector deriv, N_Vector tmp, N_Vector tmp1, void *solver_data)
Check a Jacobian for accuracy.
static void print_data_sizes(ModelData *md)
void solver_reset_timers(void *solver_data)
Reset the timers for solver functions.
int solver_run(void *solver_data, double *state, double *env, double t_initial, double t_final)
Solve for a given timestep.