hummingbird
Solving the self-adjoint angular flux transport equation using spectral elements on Cartesian geometry
Loading...
Searching...
No Matches
problem_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_PROBLEM_PROBLEM_BASE_H_
5#define HUMMINGBIRD_PROBLEM_PROBLEM_BASE_H_
6
7#include <armadillo>
8#include <vector>
9
10#include "banks/bc_bank.h"
11#include "banks/material_bank.h"
12#include "mesh/mesh.h"
14
15namespace hummingbird {
16/**
17 * @brief Convenience struct for holding the contribution for an entry in a
18 * single element to the global matrix.
19 *
20 */
22 /// @brief Global matrix row ID
23 size_t row_id;
24
25 /// @brief Global matrix column ID
26 size_t col_id;
27
28 /// @brief Value to be placed in the global matrix. This could be an entry
29 /// from a local stiffness or mass matrix, or other depending on the
30 /// formulation
31 double value;
32};
33
34/**
35 * @brief Convenience struct for hold the contribution for an entry in a single
36 * element to the global forcing vector.
37 *
38 */
40 /// @brief Global forcing vector row ID
41 size_t row_id;
42
43 /// @brief Value to be placed in the global vector
44 double value;
45};
46
47/**
48 * @brief Base class defining a formulation of the transport equation to be
49 * solved
50 *
51 */
53 public:
54 /**
55 * @brief Construct a new Problem Base object
56 *
57 * @param n_dofs Number of Degrees of Freedom
58 * @param n_ordinates Number of ordinates in angular mesh
59 */
60 ProblemBase(const size_t n_dofs, const size_t n_ordinates);
61
62 /**
63 * @brief Destroy the Problem Base object
64 *
65 */
66 virtual ~ProblemBase() = default;
67
68 /**
69 * @brief Assemble the global element system. That is, form the matrix \f$A\f$
70 * in \f$ Ax=b\f$. This only should be called once per ordinate per
71 * simulation. The global matrix is sized from the n_dofs supplied at
72 * construction, not from global_matrix_data; row_id/col_id pairs are
73 * expected to repeat (shared nodes get summed contributions from multiple
74 * elements) and are summed via Armadillo's batch SpMat constructor's
75 * add_values=true overload (the default overload errors on duplicate
76 * locations instead of summing them).
77 *
78 * @param global_matrix_data Vector of GlobalMatrixData structs
79 * @param ordinate_index Ordinate index within the angular quadrature set
80 * (i.e. the direction number)
81 */
83 const std::vector<GlobalMatrixData>& global_matrix_data,
84 const size_t ordinate_index);
85
86 /**
87 * @brief Assemble the global forcing vector for a given ordinate index. The
88 * global vector is sized from the n_dofs supplied at construction, not from
89 * global_forcing_data; row_id values are expected to repeat (shared nodes
90 * get summed contributions from multiple elements).
91 *
92 * @param global_forcing_data Vector of GlobalForcingData structs
93 * @param ordinate_index Ordinate index
94 */
96 const std::vector<GlobalForcingData>& global_forcing_data,
97 const size_t ordinate_index);
98
99 /**
100 * @brief Solve the linear system using Armadillo's sparse matrix solver.
101 * Stores the results in the solution_vectors_ member at the ordinate_index
102 * index
103 *
104 */
105 void Solve(const size_t ordinate_index);
106
107 /**
108 * @brief Assemble the vector of GlobalMatrixData structs that will be used in
109 * AssembleGlobalSystem to create the global system matrix.
110 *
111 * @param mesh Mesh
112 * @param gll_quad GaussLobattoLegendre quadrature set
113 * @param material_bank Material bank
114 * @param ordinate Ordinate for equation
115 * @return std::vector<GlobalMatrixData>
116 */
117 virtual std::vector<GlobalMatrixData> AssembleGlobalMatrixData(
118 const Mesh& mesh, const GaussLobattoLegendre& gll_quad,
119 const MaterialBank& material_bank, const Ordinate& ordinate) = 0;
120
121 /**
122 * @brief Assemble the vector of GlobalForcingData structs that will be using
123 * in AssembleGlobalForcing to create the global forcing vector.
124 * Implementations may overwrite Node::source_fluxes on the mesh, which is
125 * why mesh is non-const.
126 *
127 * @param gll_quad GaussLobattoLegendre quadrature set
128 * @param mesh Mesh
129 * @param material_bank Material bank
130 * @param source_bank Source bank
131 * @param ordinate Ordinate (direction)
132 * @param ordinate_index Index in the angular quadrature
133 * @param angular_quad_set Angular quadrature set
134 * @return std::vector<GlobalForcingData>
135 */
136 virtual std::vector<GlobalForcingData> AssembleGlobalForcingData(
137 const GaussLobattoLegendre& gll_quad, Mesh& mesh,
138 const MaterialBank& material_bank, const SourceBank& source_bank,
139 const Ordinate& ordinate, const size_t ordinate_index,
140 const QuadratureBase<Ordinate>& angular_quad_set) = 0;
141
142 /**
143 * @brief Apply boundary conditions by adding in values needed at boundary
144 * nodes. Internally, a switch calls the correct methods depending on the mesh
145 * dimension.
146 *
147 * @param mesh Mesh
148 * @param ordinate Ordinate (direction)
149 * @param bc_bank BCBank object
150 * @param ordinate_index Index of the ordinate in the angular quadrature
151 */
152 void ApplyBCs(const Mesh& mesh, const Ordinate& ordinate,
153 const BCBank& bc_bank, const size_t ordinate_index);
154
155 /**
156 * @brief Get the solution vectors
157 *
158 * @return const std::vector<arma::Col<double>>&
159 */
160 const std::vector<arma::Col<double>>& solution_vectors() const {
161 return solution_vectors_;
162 }
163
164 /**
165 * @brief Get the number of degrees of freedom
166 *
167 * @return size_t
168 */
169 size_t n_dofs() const { return n_dofs_; }
170
171 protected:
172 /// @brief Number of degrees of freedom in simulation
173 const size_t n_dofs_;
174
175 /// @brief Global system matrices in order of ordinates in angular
176 /// quadrature set
177 std::vector<arma::SpMat<double>> global_system_matrices_;
178
179 /// @brief Global forcing vectors in order of ordinates in angular quadrature
180 /// set
181 std::vector<arma::Col<double>> global_forcing_vectors_;
182
183 /// @brief Column vector of the angular flux at the nodes in order of
184 /// ordinates in angular quadrature set
185 std::vector<arma::Col<double>> solution_vectors_;
186
187 /**
188 * @brief Validate a vector of GlobalMatrixData before it is used to
189 * assemble the global system matrix. row_id/col_id pairs are expected to
190 * repeat (shared nodes get summed contributions from multiple elements),
191 * so unique (row_id, col_id) pairs are not required. Instead, this checks
192 * that the set of distinct row/col IDs referenced is contiguous starting
193 * from 0, i.e. no node ID is missing from the data.
194 *
195 * @param gmd Vector of GlobalMatrixData structs
196 */
197 void CheckGlobalMatrixData(const std::vector<GlobalMatrixData>& gmd);
198
199 /**
200 * @brief Validate a vector of GlobalForcingData before it is used to
201 * assemble the global forcing vector. row_id values are expected to repeat
202 * (shared nodes get summed contributions from multiple elements), so
203 * unique row_ids are not required. Instead, this checks that the set of
204 * distinct row IDs referenced is contiguous starting from 0, i.e. no DOF
205 * is missing from the data.
206 *
207 * @param gfd Vector of GlobalForcingData structs
208 */
209 void CheckGlobalForcingData(const std::vector<GlobalForcingData>& gfd);
210
211 /**
212 * @brief Apply boundary conditions to a 1D problem.
213 *
214 * @param mesh Mesh
215 * @param Ordinate Ordinate (direction)
216 * @param bc_bank BCBank object
217 * @param ordinate_index Index of the ordinate in the angular quadrature
218 */
219 virtual void Apply1DBCs(const Mesh& mesh, const Ordinate& Ordinate,
220 const BCBank& bc_bank,
221 const size_t ordinate_index) = 0;
222};
223} // namespace hummingbird
224
225#endif // HUMMINGBIRD_PROBLEM_PROBLEM_BASE_H_
Bank holding the boundary conditions defined in the input file.
Definition bc_bank.h:21
Class defining a 1D Gauss-Legendre-Lobatto quadrature set on [-1,1]. The quadrature set approximates ...
Bank holding the materials defined in the input file.
Class defing a mesh.
Definition mesh.h:27
Defines a solid angle, or ordinate, in spherical geometry.
Definition ordinate.h:15
virtual void Apply1DBCs(const Mesh &mesh, const Ordinate &Ordinate, const BCBank &bc_bank, const size_t ordinate_index)=0
Apply boundary conditions to a 1D problem.
std::vector< arma::SpMat< double > > global_system_matrices_
Global system matrices in order of ordinates in angular quadrature set.
std::vector< arma::Col< double > > solution_vectors_
Column vector of the angular flux at the nodes in order of ordinates in angular quadrature set.
std::vector< arma::Col< double > > global_forcing_vectors_
Global forcing vectors in order of ordinates in angular quadrature set.
const std::vector< arma::Col< double > > & solution_vectors() const
Get the solution vectors.
void Solve(const size_t ordinate_index)
Solve the linear system using Armadillo's sparse matrix solver. Stores the results in the solution_ve...
virtual std::vector< GlobalForcingData > AssembleGlobalForcingData(const GaussLobattoLegendre &gll_quad, Mesh &mesh, const MaterialBank &material_bank, const SourceBank &source_bank, const Ordinate &ordinate, const size_t ordinate_index, const QuadratureBase< Ordinate > &angular_quad_set)=0
Assemble the vector of GlobalForcingData structs that will be using in AssembleGlobalForcing to creat...
ProblemBase(const size_t n_dofs, const size_t n_ordinates)
Construct a new Problem Base object.
void CheckGlobalMatrixData(const std::vector< GlobalMatrixData > &gmd)
Validate a vector of GlobalMatrixData before it is used to assemble the global system matrix....
virtual std::vector< GlobalMatrixData > AssembleGlobalMatrixData(const Mesh &mesh, const GaussLobattoLegendre &gll_quad, const MaterialBank &material_bank, const Ordinate &ordinate)=0
Assemble the vector of GlobalMatrixData structs that will be used in AssembleGlobalSystem to create t...
virtual ~ProblemBase()=default
Destroy the Problem Base object.
const size_t n_dofs_
Number of degrees of freedom in simulation.
void ApplyBCs(const Mesh &mesh, const Ordinate &ordinate, const BCBank &bc_bank, const size_t ordinate_index)
Apply boundary conditions by adding in values needed at boundary nodes. Internally,...
size_t n_dofs() const
Get the number of degrees of freedom.
void CheckGlobalForcingData(const std::vector< GlobalForcingData > &gfd)
Validate a vector of GlobalForcingData before it is used to assemble the global forcing vector....
void AssembleGlobalSystem(const std::vector< GlobalMatrixData > &global_matrix_data, const size_t ordinate_index)
Assemble the global element system. That is, form the matrix in . This only should be called once pe...
void AssembleGlobalForcing(const std::vector< GlobalForcingData > &global_forcing_data, const size_t ordinate_index)
Assemble the global forcing vector for a given ordinate index. The global vector is sized from the n_...
Base class for defining a quadrature set.
Bank holding the volumetric sources defined in the input file.
Definition source_bank.h:25
Convenience struct for hold the contribution for an entry in a single element to the global forcing v...
size_t row_id
Global forcing vector row ID.
double value
Value to be placed in the global vector.
Convenience struct for holding the contribution for an entry in a single element to the global matrix...
double value
Value to be placed in the global matrix. This could be an entry from a local stiffness or mass matrix...
size_t row_id
Global matrix row ID.
size_t col_id
Global matrix column ID.