CLASSpp Manual
Cosmology reference and developer manual
Loading...
Searching...
No Matches
evolver_options.h
Go to the documentation of this file.
1#ifndef CLASS_EVOLVER_OPTIONS_H
2#define CLASS_EVOLVER_OPTIONS_H
3
19#include <initializer_list>
20#include <optional>
21
22#include "evolver_erk.h" // ErkControllerConfig
23#include "function_ref.h"
24
25/* Callback shapes, each spelled once. A callback carries its own context -- a
26 lambda capturing the module and its workspace -- so none of them takes a
27 void*; see function_ref.h. Derivs, Print and Diagonal share one type, so the
28 names are for the reader: the compiler cannot catch a transposition of those
29 three. */
30using EvolverDerivs = FunctionRef<void(double x, double* y, double* dy)>;
31using EvolverOutput = FunctionRef<void(double x, double* y, double* dy, int index_x)>;
32using EvolverPrint = FunctionRef<void(double x, double* y, double* dy)>;
33using EvolverDiagonal = FunctionRef<void(double x, double* y, double* diag)>;
34
42inline constexpr double kEvolverDefaultAbsTol = 1.0e-15;
43
44struct EvolverStats {
45 /* Filled by every evolver. */
46 long long steps_accepted = 0;
47 long long steps_rejected = 0;
48 long long derivs_evaluations = 0;
49
50 /* Implicit methods only; left at zero by the explicit ones. */
51 long long jacobians = 0;
52 long long lu_decompositions = 0;
53 long long linear_solves = 0;
54
55 /* Evolvers with a continuous extension only; left at zero by the others.
56 `dense` counts output points served by interpolation, `exact` those that
57 landed on a step end. */
58 long long dense_points = 0;
59 long long exact_points = 0;
60
62 void Add(const EvolverStats& other) {
63 steps_accepted += other.steps_accepted;
64 steps_rejected += other.steps_rejected;
65 derivs_evaluations += other.derivs_evaluations;
66 jacobians += other.jacobians;
67 lu_decompositions += other.lu_decompositions;
68 linear_solves += other.linear_solves;
69 dense_points += other.dense_points;
70 exact_points += other.exact_points;
71 }
72};
73
76enum class EvolverFeature {
77 Diagonal,
78 MaxOrder,
80 AbsTol,
81 Stats,
83};
84
85struct EvolverOptions {
86 /* ---- honoured by every evolver ---------------------------------------- */
87
89 double rtol = 1.0e-6;
90
97 double abstol = kEvolverDefaultAbsTol;
98
99 /* ---- dense output, honoured by every evolver --------------------------- */
100
109 const double* x_sampling = nullptr;
110 int x_sampling_size = 0;
111
116 const int* used_in_output = nullptr;
117
122 std::optional<EvolverOutput> output;
123 std::optional<EvolverPrint> print_variables;
124
125 /* ---- evolver-specific; unset at the default, validated ----------------- */
126
128 std::optional<EvolverDiagonal> derivs_diagonal;
129
133 int max_order = 0;
134
138 std::optional<ErkControllerConfig> erk;
139
146 EvolverStats* stats = nullptr;
147
152 ErkHistograms* histograms = nullptr;
153};
154
158void EvolverOptionsCheck(const EvolverOptions& options,
159 const char* evolver_name,
160 double x_ini,
161 std::initializer_list<EvolverFeature> honoured);
162
163using Evolver = void (*)(EvolverDerivs derivs,
164 double x_ini,
165 double x_end,
166 double* y,
167 int y_size,
168 const EvolverOptions& options);
169
171void evolver_rkdp45(EvolverDerivs derivs,
172 double x_ini,
173 double x_end,
174 double* y,
175 int y_size,
176 const EvolverOptions& options);
177void evolver_tsit5(EvolverDerivs derivs,
178 double x_ini,
179 double x_end,
180 double* y,
181 int y_size,
182 const EvolverOptions& options);
183
184enum class evolver_type; // precision.h
185
189 EvolverOptions& options,
190 const ErkControllerConfig& erk,
191 const EvolverDiagonal* diagonal);
192
193#endif // CLASS_EVOLVER_OPTIONS_H
EvolverFeature
Definition evolver_options.h:76
Evolver SelectEvolver(evolver_type type, EvolverOptions &options, const ErkControllerConfig &erk, const EvolverDiagonal *diagonal)
constexpr double kEvolverDefaultAbsTol
Definition evolver_options.h:42
void EvolverOptionsCheck(const EvolverOptions &options, const char *evolver_name, double x_ini, std::initializer_list< EvolverFeature > honoured)
void evolver_rkdp45(EvolverDerivs derivs, double x_ini, double x_end, double *y, int y_size, const EvolverOptions &options)
Definition output.h:24
evolver_type
Definition precision.h:19
Definition evolver_erk.h:241