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