hummingbird
Solving the self-adjoint angular flux transport equation using spectral elements on Cartesian geometry
Loading...
Searching...
No Matches
cg_problem.cc
Go to the documentation of this file.
2
3namespace hummingbird {
4
5CGProblem::CGProblem(const size_t n_dofs, const size_t n_ordinates)
6 : ProblemBase(n_dofs, n_ordinates) {}
7
8std::vector<GlobalMatrixData> CGProblem::AssembleGlobalMatrixData(
9 const Mesh& mesh, const GaussLobattoLegendre& gll_quad,
10 const MaterialBank& material_bank, const Ordinate& ordinate) {
11 std::vector<GlobalMatrixData> global_matrix_data;
12
13 for (const auto& elem : mesh.elements()) {
14 auto local_mass_matrix = elem->LocalMassMatrix(gll_quad, material_bank);
15 auto local_stiffness_matrix =
16 elem->LocalStiffnessMatrix(gll_quad, material_bank, ordinate);
17 for (auto i = 0; i < gll_quad.n_points(); i++) {
18 for (auto j = 0; j < gll_quad.n_points(); j++) {
20 gmd.value = local_mass_matrix(i, j) + local_stiffness_matrix(i, j);
21 gmd.row_id = elem->node_ids().at(i);
22 gmd.col_id = elem->node_ids().at(j);
23 global_matrix_data.push_back(std::move(gmd));
24 }
25 }
26 }
27 return global_matrix_data;
28}
29
30std::vector<GlobalForcingData> CGProblem::AssembleGlobalForcingData(
31 const GaussLobattoLegendre& gll_quad, Mesh& mesh,
32 const MaterialBank& material_bank, const SourceBank& source_bank,
33 const Ordinate& ordinate, const size_t ordinate_index,
34 const QuadratureBase<Ordinate>& angular_quad_set) {
35 std::vector<GlobalForcingData> assembled_global_forcing_data;
36
37 for (const auto& elem : mesh.elements()) {
38 elem->SetNodeSourceFluxes(mesh, material_bank, source_bank,
39 angular_quad_set);
40 auto local_forcing_vector = elem->LocalForcingVector(
41 gll_quad, mesh, material_bank, ordinate, ordinate_index);
42 for (auto i = 0; i < gll_quad.n_points(); i++) {
44 gfd.row_id = elem->node_ids().at(i);
45 gfd.value = local_forcing_vector(i);
46 assembled_global_forcing_data.push_back(std::move(gfd));
47 }
48 }
49 return assembled_global_forcing_data;
50}
51
52void CGProblem::Apply1DBCs(const Mesh& mesh, const Ordinate& ordinate,
53 const BCBank& bc_bank, const size_t ordinate_index) {
54 const auto& boundary_node_ids = mesh.boundary_node_ids();
55
56 for (const auto boundary_node_id : boundary_node_ids) {
57 auto& node = mesh.GetNode(boundary_node_id);
58 switch (bc_bank.GetByID(node.bc_id)) {
59 case BC::VACUUM: {
60 double direction_dot_product =
61 arma::norm_dot(node.outward_normal, ordinate.CartesianUnitVector());
62
63 if (direction_dot_product > 0)
64 global_system_matrices_.at(ordinate_index)(
65 boundary_node_id, boundary_node_id) += direction_dot_product;
66 break;
67 }
68 case BC::REFLECTIVE:
69 throw std::runtime_error(
70 "Reflective BCs have not been implemented for 1D yet.");
71 break;
72
73 default:
74 throw std::runtime_error(
75 "Invalid or unsupported BC type passed to Apply1D BCs");
76 break;
77 }
78 }
79}
80} // namespace hummingbird
Bank holding the boundary conditions defined in the input file.
Definition bc_bank.h:21
const T & GetByID(const int id) const
Get the object by its ID.
Definition bank_base.h:29
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) override
See ProblemBase::AssembleGlobalForcingData. For each element, the element's node source fluxes are fi...
Definition cg_problem.cc:30
CGProblem(const size_t n_dofs, const size_t n_ordinates)
Construct a new CGProblem object.
Definition cg_problem.cc:5
void Apply1DBCs(const Mesh &mesh, const Ordinate &ordinate, const BCBank &bc_bank, const size_t ordinate_index) override
See ProblemBase::Apply1DBCs. Only vacuum BCs are currently supported.
Definition cg_problem.cc:52
std::vector< GlobalMatrixData > AssembleGlobalMatrixData(const Mesh &mesh, const GaussLobattoLegendre &gll_quad, const MaterialBank &material_bank, const Ordinate &ordinate) override
See ProblemBase::AssembleGlobalMatrixData. For each element, the local mass and stiffness matrices ar...
Definition cg_problem.cc:8
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
const Node & GetNode(const size_t id) const
Get Node by ID.
Definition mesh.h:93
const std::vector< size_t > & boundary_node_ids() const
Get the boundary node IDs.
Definition mesh.h:123
const std::vector< std::unique_ptr< Element > > & elements() const
Get the elements in the mesh.
Definition mesh.h:83
Defines a solid angle, or ordinate, in spherical geometry.
Definition ordinate.h:15
arma::vec3 CartesianUnitVector() const
Returns the Ordinate as a Cartesian unit vector.
Definition ordinate.cc:38
std::vector< arma::SpMat< double > > global_system_matrices_
Global system matrices in order of ordinates in angular quadrature set.
ProblemBase(const size_t n_dofs, const size_t n_ordinates)
Construct a new Problem Base object.
size_t n_dofs() const
Get the number of degrees of freedom.
Base class for defining a quadrature set.
size_t n_points() const
Get total number of abscissas.
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.