hummingbird
Solving the self-adjoint angular flux transport equation using spectral elements on Cartesian geometry
Loading...
Searching...
No Matches
element.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_ELEMENT_H_
5#define HUMMINGBIRD_MESH_ELEMENT_H_
6
7#include <armadillo>
8#include <memory>
9#include <vector>
10
11#include "banks/material_bank.h"
12#include "node.h"
13#include "physics/material.h"
16
17namespace hummingbird {
18class Mesh;
19class SourceBank;
20
21/**
22 * @brief Defines a subset of the domain (an "element")
23 *
24 */
25class Element {
26 public:
27 /**
28 * @brief Construct a new Element object
29 *
30 * @param material_id Material ID
31 * @param source_id Source ID
32 */
33 Element(const int material_id, const int source_id);
34
35 /**
36 * @brief Destroy the Element object. Virtual because Element is used
37 * polymorphically through std::unique_ptr<Element> (see Mesh::elements_).
38 *
39 */
40 virtual ~Element() = default;
41
42 /**
43 * @brief Create nodes by mapping the Gauss-Lobatto-Legendre quadrature set
44 * from the reference to the real domain
45 *
46 * @param existing_nodes Vector of nodes that already exist in the mesh.
47 * Starting ID for new nodes will be equal to the number of nodes that already
48 * exist to ensure no duplicates
49 * @param gll_quadrature GaussLobattoLegendre quadrature set
50 */
51 virtual std::vector<Node> CreateInteriorNodes(
52
53 const std::vector<Node>& existing_nodes,
54 const GaussLobattoLegendre& gll_quadrature) = 0;
55
56 /**
57 * @brief Get node IDs
58 *
59 * @return std::vector<size_t>
60 */
61 std::vector<size_t> node_ids() const { return node_ids_; }
62
63 /**
64 * @brief Get Material ID
65 *
66 * @return int
67 */
68 int material_id() const { return material_id_; }
69
70 /**
71 * @brief Get Source ID
72 *
73 * @return int
74 */
75 int source_id() const { return source_id_; }
76
77 /**
78 * @brief Set the Material ID, e.g. once it has been resolved from a raw
79 * gmsh tag to a MaterialBank-assigned ID (see Mesh::ResolveIDs)
80 *
81 * @param material_id Material ID
82 */
84
85 /**
86 * @brief Set the Source ID, e.g. once it has been resolved from a raw
87 * gmsh tag to a SourceBank-assigned ID (see Mesh::ResolveIDs)
88 *
89 * @param source_id Source ID
90 */
92
93 /**
94 * @brief Set the new Node ID
95 *
96 * @param prev_id Previous ID (currently stored in object)
97 * @param new_id New ID
98 */
99 void SetNewNodeID(const size_t prev_id, const size_t new_id);
100
101 /**
102 * @brief Replace all node IDs at once, e.g. when renumbering. Unlike
103 * SetNewNodeID, this does not search by value, so it is safe to use when
104 * remapped IDs could otherwise collide with not-yet-remapped IDs.
105 *
106 * @param node_ids New node IDs, in the same order as the existing ones
107 */
108 void SetNodeIDs(std::vector<size_t> node_ids) {
109 node_ids_ = std::move(node_ids);
110 }
111
112 /**
113 * @brief Compute and set the source flux values on this element's nodes
114 * using this element's material and source IDs
115 *
116 * @param mesh Mesh
117 * @param material_bank Material bank
118 * @param source_bank Source bank
119 * @param angular_quadrature Angular quadrature set
120 */
121 void SetNodeSourceFluxes(Mesh& mesh, const MaterialBank& material_bank,
122 const SourceBank& source_bank,
123 const QuadratureBase<Ordinate>& angular_quadrature);
124
125 /**
126 * @brief Construct the local forcing vector for this element at a given
127 * ordinate
128 *
129 * @param gll_quad GaussLobattoLegendre quadrature set
130 * @param mesh Mesh
131 * @param material_bank Material bank
132 * @param ordinate Ordinate (direction)
133 * @param ordinate_index Index of the ordinate in the angular quadrature
134 * @return arma::Col<double>
135 */
136 virtual arma::Col<double> LocalForcingVector(
137 const GaussLobattoLegendre& gll_quad, const Mesh& mesh,
138 const MaterialBank& material_bank, const Ordinate& ordinate,
139 const size_t ordinate_index) = 0;
140
141 /**
142 * @brief Construct the local stiffness matrix for this element at a given
143 * ordinate
144 *
145 * @param gll_quad GaussLobattoLegendre quadrature set
146 * @param material_bank Material bank
147 * @param ordinate Ordinate (direction)
148 * @return arma::Mat<double>
149 */
150 virtual arma::Mat<double> LocalStiffnessMatrix(
151 const GaussLobattoLegendre& gll_quad, const MaterialBank& material_bank,
152 const Ordinate& ordinate) = 0;
153
154 /**
155 * @brief Construct the local mass matrix for this element
156 *
157 * @param gll_quad GaussLobattoLegendre quadrature set
158 * @param material_bank Material bank
159 * @return arma::SpMat<double>
160 */
161 virtual arma::SpMat<double> LocalMassMatrix(
162 const GaussLobattoLegendre& gll_quad,
163 const MaterialBank& material_bank) = 0;
164
165 /**
166 * @brief Get the spatial dimension of this element type (e.g. 1 for a
167 * line segment)
168 *
169 * @return unsigned int
170 */
171 virtual unsigned int dimension() const = 0;
172
173 protected:
174 /// @brief Material ID to access Material Bank. Auto initialized to -1. Value
175 /// must be set to a positive value (including 0) to map into the MaterialBank
176 int material_id_ = -1;
177
178 /// @brief Source ID to access Source Bank. ID of 0 is always NONE, meaning
179 /// the element has no external source.
180 int source_id_ = 0;
181
182 /// @brief IDs of nodes defining the element
183 std::vector<size_t> node_ids_;
184};
185} // namespace hummingbird
186
187#endif // HUMMINGBIRD_MESH_ELEMENT_H_
void SetNodeSourceFluxes(Mesh &mesh, const MaterialBank &material_bank, const SourceBank &source_bank, const QuadratureBase< Ordinate > &angular_quadrature)
Compute and set the source flux values on this element's nodes using this element's material and sour...
Definition element.cc:23
int material_id() const
Get Material ID.
Definition element.h:68
std::vector< size_t > node_ids_
IDs of nodes defining the element.
Definition element.h:183
virtual arma::Mat< double > LocalStiffnessMatrix(const GaussLobattoLegendre &gll_quad, const MaterialBank &material_bank, const Ordinate &ordinate)=0
Construct the local stiffness matrix for this element at a given ordinate.
virtual arma::SpMat< double > LocalMassMatrix(const GaussLobattoLegendre &gll_quad, const MaterialBank &material_bank)=0
Construct the local mass matrix for this element.
virtual arma::Col< double > LocalForcingVector(const GaussLobattoLegendre &gll_quad, const Mesh &mesh, const MaterialBank &material_bank, const Ordinate &ordinate, const size_t ordinate_index)=0
Construct the local forcing vector for this element at a given ordinate.
void SetNodeIDs(std::vector< size_t > node_ids)
Replace all node IDs at once, e.g. when renumbering. Unlike SetNewNodeID, this does not search by val...
Definition element.h:108
int material_id_
Material ID to access Material Bank. Auto initialized to -1. Value must be set to a positive value (i...
Definition element.h:176
virtual std::vector< Node > CreateInteriorNodes(const std::vector< Node > &existing_nodes, const GaussLobattoLegendre &gll_quadrature)=0
Create nodes by mapping the Gauss-Lobatto-Legendre quadrature set from the reference to the real doma...
virtual ~Element()=default
Destroy the Element object. Virtual because Element is used polymorphically through std::unique_ptr<E...
void SetSourceID(const int source_id)
Set the Source ID, e.g. once it has been resolved from a raw gmsh tag to a SourceBank-assigned ID (se...
Definition element.h:91
std::vector< size_t > node_ids() const
Get node IDs.
Definition element.h:61
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
int source_id_
Source ID to access Source Bank. ID of 0 is always NONE, meaning the element has no external source.
Definition element.h:180
void SetMaterialID(const int material_id)
Set the Material ID, e.g. once it has been resolved from a raw gmsh tag to a MaterialBank-assigned ID...
Definition element.h:83
void SetNewNodeID(const size_t prev_id, const size_t new_id)
Set the new Node ID.
Definition element.cc:12
virtual unsigned int dimension() const =0
Get the spatial dimension of this element type (e.g. 1 for a line segment).
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
Base class for defining a quadrature set.
Bank holding the volumetric sources defined in the input file.
Definition source_bank.h:25