hummingbird
Solving the self-adjoint angular flux transport equation using spectral elements on Cartesian geometry
Loading...
Searching...
No Matches
segment.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_MESH_SEGMENT_H_
5#define HUMMINGBIRD_MESH_SEGMENT_H_
6
7#include <array>
8
10#include "mesh/element.h"
11#include "mesh/mesh.h"
12#include "mesh/node.h"
13
14namespace hummingbird {
15/**
16 * @brief 1D line element defined by two boundary nodes, with interior nodes
17 * placed at Gauss-Lobatto-Legendre points
18 *
19 */
20class Segment : public Element {
21 public:
22 /**
23 * @brief Construct a new Segment object
24 *
25 * @param boundary_node_ids Node IDs defining the Segment bounds
26 * @param material_id Material ID
27 * @param source_id Source ID
28 * @param mesh Mesh
29 */
30 Segment(const std::array<size_t, 2> boundary_node_ids, const int material_id,
31 const int source_id, const Mesh& mesh);
32
33 /**
34 * @brief Create interior Node objects using the Gauss-Lobatto-Legendre
35 * quadrature set. The mapping from the reference to the real domain was based
36 * on the equations provided by the book Computational Seismology by Heiner
37 * Igel
38 * (https://www.google.com/url?sa=t&source=web&rct=j&opi=89978449&url=https://www.geokniga.org/bookfiles/geokniga-computationalseismologyapracticalintroductionbyigelheinerz-liborg.pdf&ved=2ahUKEwiMuanq7_OVAxXVN4YAHVgAD1QQFnoECBUQAQ&usg=AOvVaw35g1Tl3ZSFUMusz8LKQxHk).
39 * For a line segment defined by two endpoints, the mapping is:
40 *
41 * \f[
42 * \mathbf{r}(\xi) = \mathbf{r}_1+\left( \frac{\xi+1}{2} \right)\left(
43 * \mathbf{r}_2-\mathbf{r}_1 \right) \f]
44 *
45 * where \f$x\in[-1,1]\f$.
46 *
47 * @param existing_nodes Nodes already existing in Mesh
48 * @param gll_quadrature Gauss-Lobatto-Legendre quadrature set
49 * @return Additional nodes to be defined along the GLL quadrature set. Will
50 * be of length N-2 (the two endpoint account for the remaining two nodes)
51 */
52 std::vector<Node> CreateInteriorNodes(
53 const std::vector<Node>& existing_nodes,
54 const GaussLobattoLegendre& gll_quadrature) override;
55
56 /**
57 * @brief Construct the local forcing vector, which is:
58 *
59 * \f[
60 * f_i = \frac{h_e}{2}\int_{-1}^1Q_n(\xi)\ell_i (\xi)d\xi +
61 * \frac{\hat{\Omega}_x}{\Sigma_t^e}\int_{-1}^1Q_n(\xi)\frac{d\ell_i}{d\xi}d\xi
62 * \f]
63 * which the integrals are again approximated using the GLL quadrature set:
64 * \f[
65 * f_i \approx \sum_{k=0}^{N_x}\rho_k Q_n(\xi_k)\left[ \frac{h_e}{2}\ell_i
66 * (\xi_k) +\frac{\hat{\Omega}_x}{\Sigma_t^e}\frac{d\ell_i}{d\xi}(\xi_k)\right]
67 * \f]
68 *
69 * @param gll_quad GaussLobattoLegendre quadrature set
70 * @param mesh Mesh
71 * @param material_bank Material bank
72 * @param ordinate Ordinate (direction)
73 * @param ordinate_index Index of the ordinate in the angular quadrature
74 * @return arma::Col<double>
75 */
76 arma::Col<double> LocalForcingVector(const GaussLobattoLegendre& gll_quad,
77 const Mesh& mesh,
78 const MaterialBank& material_bank,
79 const Ordinate& ordinate,
80 const size_t ordinate_index) override;
81
82 /**
83 * @brief Construct the dense local stiffness matrix using spectral elements
84 * on a Gauss-Lobatto-Legendre grid, defined as:
85 *
86 * \f[
87 * K_{ij}=\frac{\hat{\Omega}_x^2}{\Sigma_t^e}\frac{2}{h_e}\sum_{k=0}^{N_x}\rho_k
88 * \frac{d\ell_i}{d\xi}(\xi_k)\frac{d\ell_j}{d\xi}(\xi_k)
89 * \f]
90 *
91 * @param gll_quad GaussLobattoLegendre set
92 * @param material_bank MaterialBank
93 * @param ordinate Ordinate (direction)
94 * @return arma::Mat<double>
95 * @todo See about cutting the loops in half by leveraging symmetry.
96 */
97 arma::Mat<double> LocalStiffnessMatrix(const GaussLobattoLegendre& gll_quad,
98 const MaterialBank& material_bank,
99 const Ordinate& ordinate) override;
100
101 /**
102 * @brief Construct the sparse *diagonal* local mass matrix using spectral
103 * elements on a Gauss-Lobatto-Legendre grid, defined as:
104 *
105 * \f[
106 * M_{ij}=\Sigma_t^e\frac{h_e}{2}\sum_{k=0}^{N_x}\rho_k\ell_i(\xi_k)\ell_j(\xi_k)
107 * \f]
108 * Which, using the cardinality of Lagrange polynomials, greatly simplifies
109 * to:
110 * \f[
111 * \Sigma_t^eM_{ij}=\begin{cases}
112 * 0, & i\neq j \\
113 * \Sigma_t^e\frac{h_e}{2}\rho_i, &i=j
114 * \end{cases}
115 * \f]
116 *
117 * @param gll_quad GaussLobattoLegendre set
118 * @param material_bank MaterialBank
119 * @return arma::SpMat<double>
120 */
121 arma::SpMat<double> LocalMassMatrix(
122 const GaussLobattoLegendre& gll_quad,
123 const MaterialBank& material_bank) override;
124
125 /**
126 * @brief Get the spatial dimension of a Segment (always 1)
127 *
128 * @return unsigned int
129 */
130 unsigned int dimension() const override;
131
132 private:
133 /// @brief Node IDs defining the Segment bounds
134 std::array<size_t, 2> boundary_node_ids_;
135
136 /// @brief Length of the element
137 const double length_;
138
139 /**
140 * @brief Compute the length of the element on construction
141 *
142 * @param boundary_node_ids Boundary node IDs
143 * @param mesh Mesh
144 * @return double
145 */
146 double ComputeLength(const std::array<size_t, 2> boundary_node_ids,
147 const Mesh& mesh);
148};
149} // namespace hummingbird
150
151#endif // HUMMINGBIRD_MESH_SEGMENT_H_
int material_id() const
Get Material ID.
Definition element.h:68
Element(const int material_id, const int source_id)
Construct a new Element object.
Definition element.cc:9
int source_id() const
Get Source ID.
Definition element.h:75
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
Segment(const std::array< size_t, 2 > boundary_node_ids, const int material_id, const int source_id, const Mesh &mesh)
Construct a new Segment object.
Definition segment.cc:4
std::array< size_t, 2 > boundary_node_ids_
Node IDs defining the Segment bounds.
Definition segment.h:134
double ComputeLength(const std::array< size_t, 2 > boundary_node_ids, const Mesh &mesh)
Compute the length of the element on construction.
Definition segment.cc:10
arma::Col< double > LocalForcingVector(const GaussLobattoLegendre &gll_quad, const Mesh &mesh, const MaterialBank &material_bank, const Ordinate &ordinate, const size_t ordinate_index) override
Construct the local forcing vector, which is:
Definition segment.cc:52
std::vector< Node > CreateInteriorNodes(const std::vector< Node > &existing_nodes, const GaussLobattoLegendre &gll_quadrature) override
Create interior Node objects using the Gauss-Lobatto-Legendre quadrature set. The mapping from the re...
Definition segment.cc:18
unsigned int dimension() const override
Get the spatial dimension of a Segment (always 1).
Definition segment.cc:107
arma::Mat< double > LocalStiffnessMatrix(const GaussLobattoLegendre &gll_quad, const MaterialBank &material_bank, const Ordinate &ordinate) override
Construct the dense local stiffness matrix using spectral elements on a Gauss-Lobatto-Legendre grid,...
Definition segment.cc:77
arma::SpMat< double > LocalMassMatrix(const GaussLobattoLegendre &gll_quad, const MaterialBank &material_bank) override
Construct the sparse diagonal local mass matrix using spectral elements on a Gauss-Lobatto-Legendre g...
Definition segment.cc:97
const double length_
Length of the element.
Definition segment.h:137