integraal/parameters.rs
1//! integral parameterization code
2
3use crate::Scalar;
4
5/// Domain description enum
6///
7/// This represents a discretization of the integrated space.
8///
9/// Only 1D domains are currently supported. the type used for values must implement [`Scalar`]; the trait
10/// is automatially implemented for types satisfying its requirements. In the future, adding support for
11/// higher dimension can be considered.
12#[derive(Debug, Clone)]
13pub enum DomainDescriptor<X: Scalar> {
14 /// List of values taken by the variable on which we integrate.
15 Explicit(Vec<X>),
16 /// Description of a uniform discretization over a certain range of values.
17 Uniform {
18 /// First value of the range
19 start: X,
20 /// Step between each value of the range
21 step: X,
22 /// Total number of values
23 n_step: usize,
24 },
25}
26
27/// Function description enum
28///
29/// This holds information about the function's values, as either explicit values or a closure that
30/// can be used to compute those.
31pub enum FunctionDescriptor<X>
32where
33 X: Scalar,
34{
35 /// Direct expression of the function, taking a value of the domain as input & returning the
36 /// image of that value.
37 Closure(Box<dyn Fn(X) -> X>),
38 /// List of values taken by the function. An error will be raised at computation if the length
39 /// of the list isn't consistent with the domain descriptor.
40 Values(Vec<X>),
41}
42
43/// Numerical integration method enum
44///
45/// # Note on computations
46///
47/// For the considered integral to be consistent across compute methods for a given description,
48/// the left-rectangle (resp. right-rectangle) has to ignore the last (resp. first) value given
49/// in the descriptors. This can be visualized in the following example:
50///
51/// 
52///
53/// Out of 11 samples, both methods compute the area of 10 polygons. In the case where the domain
54/// is uniform & described using a step, the eleventh sample value is useless (for a left-rectangle
55/// method).
56///
57/// The crate assumes that the first and last samples making up your domain corresponds to the
58/// limits of the integral. Therefore, these values will be ignored when computing the integral
59/// using rectangles.
60#[derive(Debug, Clone, Copy)]
61pub enum ComputeMethod {
62 /// Rectangle method, using the left rule --
63 /// [reference](https://en.wikipedia.org/wiki/Riemann_sum#Left_rule)
64 RectangleLeft,
65 /// Rectangle method, using the right rule --
66 /// [reference](https://en.wikipedia.org/wiki/Riemann_sum#Right_rule)
67 RectangleRight,
68 /// Trapezoid method -- [reference](https://en.wikipedia.org/wiki/Trapezoidal_rule)
69 Trapezoid,
70 /// Simpson's rule(s), the exact rule applied depends on integral definition --
71 /// [reference](https://en.wikipedia.org/wiki/Simpson%27s_rule)
72 Simpson,
73 /// Boole's method -- [reference](https://en.wikipedia.org/wiki/Boole%27s_rule#Composite_Boole's_Rule)
74 #[cfg(feature = "boole")]
75 Boole {
76 /// Force the computation by truncating inputs to fit method requirements
77 force: bool,
78 },
79 /// Romberg's method -- [reference](https://en.wikipedia.org/wiki/Romberg%27s_method#Implementation)
80 #[cfg(feature = "romberg")]
81 Romberg {
82 /// Maximum number of iteration done by the algorithm
83 max_steps: usize,
84 },
85 #[cfg(feature = "montecarlo")]
86 /// Monte-Carlo method -- [reference](https://en.wikipedia.org/wiki/Monte_Carlo_integration)
87 MonteCarlo {
88 /// Number of samples per step computation.
89 n_sample: usize,
90 },
91}