CLASSpp Manual
Cosmology reference and developer manual
Loading...
Searching...
No Matches
evolver_ndf15.h
1#ifndef __EVO__
2#define __EVO__
3#include "common.h"
4// #include "perturbations.h"
5#include <memory>
6#include <vector>
7
8#include "sparse.h"
9#define TINY 1e-50
10/**************************************************************/
11
12struct jacobian {
13 /*Stuff for normal method: */
14 std::vector<double*> dfdy; /* row pointers into dfdy_data_vec */
15 std::vector<double> jacvec; /*Stores experience gained from subsequent calls */
16 std::vector<double*> LU; /* row pointers into LU_data_vec */
17 std::vector<double> LUw;
18 std::vector<int> luidx;
19 /*Sparse stuff:*/
20 int use_sparse;
21 int sparse_stuff_initialized;
22 int max_nonzero; /*Maximal number of non-zero entries to be considered sparse */
23 int repeated_pattern;
24 int trust_sparse; /* Number of times a pattern is repeated (actually included) before we trust it. */
25 int has_grouping;
26 int has_pattern;
27 int new_jacobian; /* True if sp_ludcmp has not been run on the current jacobian. */
28 int cnzmax;
29 std::vector<int> col_group; /* Column grouping. Groups go from 0 to max_group*/
30 std::vector<int> col_wi; /* Workarray for column grouping*/
31 int max_group; /*Number of columngroups -1 */
32 std::unique_ptr<sp_mat> spJ; /* Stores the matrix we want to decompose */
33 std::vector<double> xjac; /*Stores the values of the sparse jacobian. (Same pattern as spJ) */
34 std::unique_ptr<sp_num> Numerical; /*Stores the LU decomposition.*/
35 std::vector<int> Cp; /* Stores the column pointers of the spJ+spJ' sparsity pattern. */
36 std::vector<int> Ci; /* Stores the row indices of the spJ+spJ' sparsity pattern. */
37
38 /* Contiguous flat backing for the 2D row-pointer arrays above */
39 std::vector<double> dfdy_data_vec;
40 std::vector<double> LU_data_vec;
41};
42
43struct numjac_workspace {
44 std::vector<double> yscale;
45 std::vector<double> del;
46 std::vector<double> Difmax;
47 std::vector<double> absFdelRm;
48 std::vector<double> absFvalue;
49 std::vector<double> absFvalueRm;
50 std::vector<double> Fscale;
51 std::vector<double> ffdel;
52 std::vector<double> yydel;
53 std::vector<double> tmp;
54
55 std::vector<double*> ydel_Fdel; /* row pointers into ydel_Fdel_data_vec */
56
57 std::vector<int> logj;
58 std::vector<int> Rowmax;
59
60 /* Contiguous flat backing for ydel_Fdel */
61 std::vector<double> ydel_Fdel_data_vec;
62};
63
64void initialize_jacobian(struct jacobian* jac, int neq);
65void uninitialize_jacobian(struct jacobian* jac);
66void initialize_numjac_workspace(struct numjac_workspace* nj_ws, int neq);
67void uninitialize_numjac_workspace(struct numjac_workspace* nj_ws);
68void calc_C(struct jacobian* jac);
69void interp_from_dif(double tinterp,
70 double tnew,
71 double* ynew,
72 double h,
73 double** dif,
74 int k,
75 double* yinterp,
76 double* ypinterp,
77 double* yppinterp,
78 int* index,
79 int neq,
80 int output);
81void new_linearisation(struct jacobian* jac, double hinvGak, int neq);
82void adjust_stepsize(double** dif, double abshdivabshlast, int neq, int k);
83void eqvec(double* datavec, double* emptyvec, int n);
84void lubksb(double** a, int n, int* indx, double b[]);
85bool ludcmp(double** a, int n, int* indx, double* d, double* vv);
86void fzero_Newton(void (*func)(double* x, int x_size, void* param, double* F),
87 double* x_inout,
88 double* dxdF,
89 int x_size,
90 double tolx,
91 double tolF,
92 void* param,
93 int* fevals);
94
95void numjac(void (*derivs)(double x, double* y, double* dy, void* parameters_and_workspace),
96 double t,
97 double* y,
98 double* fval,
99 struct jacobian* jac,
100 struct numjac_workspace* nj_ws,
101 double thresh,
102 int neq,
103 int* nfe,
104 void* parameters_and_workspace_for_derivs);
105
106void evolver_ndf15(
107 void (*derivs)(double x, double* y, double* dy, void* parameters_and_workspace),
108 double x_ini,
109 double x_final,
110 double* y_inout,
111 int* used_in_output,
112 int neq,
113 void* parameters_and_workspace_for_derivs,
114 double rtol,
115 double minimum_variation,
116 void (*timescale_and_approximation)(double x,
117 void* parameters_and_workspace,
118 double* timescales),
119 double timestep_over_timescale,
120 double* t_vec,
121 int t_res,
122 void (*output)(double x, double y[], double dy[], int index_x, void* parameters_and_workspace),
123 void (*print_variables)(double x, double y[], double dy[], void* parameters_and_workspace));
124
125/**************************************************************/
126
127#endif
Definition output.h:24