hummingbird
Solving the self-adjoint angular flux transport equation using spectral elements on Cartesian geometry
Loading...
Searching...
No Matches
quadrature_base.h
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-3-Clause
2// Copyright (c) 2026, Liam Pohlmann
3
4#ifndef HUMMINGBIRD_QUADRATURE_QUADRATURE_BASE_H_
5#define HUMMINGBIRD_QUADRATURE_QUADRATURE_BASE_H_
6
7#include <map>
8#include <vector>
9
10namespace hummingbird {
11
12/**
13 * @brief Simple struct holding a function value evaluated at the supplied
14 * abscissa value
15 *
16 */
18 /// @brief Index of the abscissa the function was evaluated at
20
21 /// @brief Function value at the abscissa
23};
24
25/**
26 * @brief Base class for defining a quadrature set
27 *
28 * @tparam T Type of ordinates to be used
29 */
30template <typename T>
32 public:
33 QuadratureBase() = default;
34
35 /**
36 * @brief Construct a new Quadrature object
37 *
38 * @param abscissas Vector of abscissa values for the quadrature
39 */
40 QuadratureBase(const std::vector<T> abscissas) : abscissas_(abscissas) {};
41
42 /**
43 * @brief Get the weight value corresponding to a given abscissa value
44 *
45 * @param abscissa_index Abscissa index
46 * @return Weight value
47 */
48 double GetWeight(const unsigned int abscissa_index) const {
49 return weight_map_.at(abscissa_index);
50 };
51
52 /**
53 * @brief Get the abscissa corresponding to the index
54 *
55 * @param index Abscissa index
56 * @return T Abscissa object at index
57 */
58 T GetAbscissa(const unsigned int index) const { return abscissas_.at(index); }
59
60 /**
61 * @brief Integrate the function using the function value and its location on
62 * the quadrature grid
63 *
64 * @param quad_pairs QuadraturePair object
65 * @return Approximated integral using the quadrature set
66 */
67 double Integrate(const std::vector<QuadraturePair>& quad_pairs) const {
68 double sum = 0;
69 for (auto& pair : quad_pairs) {
70 auto weight = GetWeight(pair.abscissa_index);
71 sum += pair.function_value * weight;
72 }
73 return sum;
74 };
75
76 /**
77 * @brief Getter for the abscissas in the quadrature set
78 *
79 * @return const std::vector<T>&
80 */
81 const std::vector<T>& abscissas() const { return abscissas_; }
82
83 /**
84 * @brief Get total number of abscissas
85 *
86 * @return size_t
87 */
88 size_t n_points() const { return abscissas_.size(); }
89
90 protected:
91 /// @brief Abscissa values
92 std::vector<T> abscissas_;
93
94 /// @brief Map to store the weights of the quadrature set where the keys are
95 /// the indices corresponding to abscissa values
96 std::map<unsigned int, double> weight_map_;
97
98 /**
99 * @brief Create the weight map
100 *
101 */
103 int order = abscissas_.size();
104 for (auto i = 0; i < order; i++) {
105 double weight = ComputeWeight(i, order);
106 weight_map_.insert({i, weight});
107 }
108 }
109
110 /**
111 * @brief Compute the weight for the k-th abscissa for n total points
112 *
113 * @param k Abscissa index
114 * @param n Total number of points
115 * @return Quadrature weight
116 */
117 virtual double ComputeWeight(const size_t k, const size_t n) { return 0; }
118};
119} // namespace hummingbird
120
121#endif // HUMMINGBIRD_QUADRATURE_QUADRATURE_BASE_H_
const std::vector< T > & abscissas() const
Getter for the abscissas in the quadrature set.
void CreateWeightMap()
Create the weight map.
std::map< unsigned int, double > weight_map_
Map to store the weights of the quadrature set where the keys are the indices corresponding to abscis...
virtual double ComputeWeight(const size_t k, const size_t n)
Compute the weight for the k-th abscissa for n total points.
T GetAbscissa(const unsigned int index) const
Get the abscissa corresponding to the index.
size_t n_points() const
Get total number of abscissas.
double Integrate(const std::vector< QuadraturePair > &quad_pairs) const
Integrate the function using the function value and its location on the quadrature grid.
double GetWeight(const unsigned int abscissa_index) const
Get the weight value corresponding to a given abscissa value.
QuadratureBase(const std::vector< T > abscissas)
Construct a new Quadrature object.
std::vector< T > abscissas_
Abscissa values.
Simple struct holding a function value evaluated at the supplied abscissa value.
double function_value
Function value at the abscissa.
int abscissa_index
Index of the abscissa the function was evaluated at.