hummingbird
Solving the self-adjoint angular flux transport equation using spectral elements on Cartesian geometry
Loading...
Searching...
No Matches
segment.cc
Go to the documentation of this file.
1#include "mesh/segment.h"
2
3namespace hummingbird {
4Segment::Segment(const std::array<size_t, 2> boundary_node_ids,
5 const int material_id, const int source_id, const Mesh& mesh)
6 : boundary_node_ids_(boundary_node_ids),
7 length_(ComputeLength(boundary_node_ids, mesh)),
9
10double Segment::ComputeLength(const std::array<size_t, 2> boundary_node_ids,
11 const Mesh& mesh) {
12 auto left_node = mesh.GetNode(boundary_node_ids.front());
13 auto right_node = mesh.GetNode(boundary_node_ids.back());
14 auto distance = DistanceBetweenNodes(left_node, right_node);
15 return distance;
16}
17
19
20 const std::vector<Node>& existing_nodes,
21 const GaussLobattoLegendre& gll_quadrature) {
22 node_ids_.reserve(gll_quadrature.n_points());
23 size_t id = existing_nodes.size();
24
25 Node left_node = existing_nodes.at(boundary_node_ids_.at(0));
26 Node right_node = existing_nodes.at(boundary_node_ids_.at(1));
27 double direction_x = right_node.x - left_node.x;
28 double direction_y = right_node.y - left_node.y;
29 double direction_z = right_node.z - left_node.z;
30
31 unsigned int interior_bc_id =
32 (left_node.bc_id == right_node.bc_id) ? left_node.bc_id : 0;
33 node_ids_.push_back(left_node.id);
34 std::vector<Node> nodes(gll_quadrature.n_points() - 2);
35 for (auto i = 1; i < gll_quadrature.n_points() - 1; i++) {
36 double xi = gll_quadrature.GetAbscissa(i);
37 double fraction = (xi + 1.0) / 2.0;
38 Node new_node;
39 new_node.id = id;
40 node_ids_.push_back(id);
41 new_node.x = left_node.x + fraction * direction_x;
42 new_node.y = left_node.y + fraction * direction_y;
43 new_node.z = left_node.z + fraction * direction_z;
44 new_node.bc_id = interior_bc_id;
45 nodes.at(i - 1) = std::move(new_node);
46 id++;
47 }
48 node_ids_.push_back(right_node.id);
49 return nodes;
50}
51
53 const GaussLobattoLegendre& gll_quad, const Mesh& mesh,
54 const MaterialBank& material_bank, const Ordinate& ordinate,
55 const size_t ordinate_index) {
56 arma::Col<double> forcing_vec(gll_quad.n_points(), arma::fill::zeros);
57 double sigma_t = material_bank.GetByID(material_id_).total_xs;
58 double left_x = mesh.GetNode(node_ids_.at(0)).x;
59 double right_x = mesh.GetNode(node_ids_.at(node_ids_.size() - 1)).x;
60 double orientation = (right_x >= left_x) ? 1.0 : -1.0;
61 double streaming_coeff = orientation * ordinate.x() / sigma_t;
62 for (auto i = 0; i < gll_quad.n_points(); i++) {
63 double sum = 0.0;
64 for (auto k = 0; k < gll_quad.n_points(); k++) {
65 double node_source =
66 mesh.GetNode(node_ids_.at(k)).source_fluxes.at(ordinate_index);
67 double weight = gll_quad.GetWeight(k);
68 if (i == k) sum += weight * node_source * length_ / 2.0;
69 sum += streaming_coeff * weight * node_source *
70 gll_quad.GetLagrangeDerivative(k, i);
71 }
72 forcing_vec(i) = sum;
73 }
74 return forcing_vec;
75}
76
78 const GaussLobattoLegendre& gll_quad, const MaterialBank& material_bank,
79 const Ordinate& ordinate) {
80 arma::Mat<double> stiffness_mat(gll_quad.n_points(), gll_quad.n_points(),
81 arma::fill::zeros);
82 double sigma_t = material_bank.GetByID(material_id_).total_xs;
83 double front_coeff = ordinate.x() * ordinate.x() / sigma_t * 2.0 / length_;
84 for (auto i = 0; i < gll_quad.n_points(); i++) {
85 for (auto j = 0; j < gll_quad.n_points(); j++) {
86 double sum = 0.0;
87 for (auto k = 0; k < gll_quad.n_points(); k++) {
88 sum += gll_quad.GetLagrangeDerivative(k, i) *
89 gll_quad.GetLagrangeDerivative(k, j) * gll_quad.GetWeight(k);
90 }
91 stiffness_mat(i, j) = front_coeff * sum;
92 }
93 }
94 return stiffness_mat;
95}
96
97arma::SpMat<double> Segment::LocalMassMatrix(
98 const GaussLobattoLegendre& gll_quad, const MaterialBank& material_bank) {
99 auto sigma_t = material_bank.GetByID(material_id_).total_xs;
100 arma::SpMat<double> material_matrix = arma::speye<arma::SpMat<double>>(
101 gll_quad.n_points(), gll_quad.n_points());
102 for (auto k = 0; k < gll_quad.n_points(); k++)
103 material_matrix(k, k) = gll_quad.GetWeight(k) * length_ / 2.0 * sigma_t;
104 return material_matrix;
105}
106
107unsigned int Segment::dimension() const { return 1; }
108} // namespace hummingbird
const T & GetByID(const int id) const
Get the object by its ID.
Definition bank_base.h:29
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
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
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 ...
double GetLagrangeDerivative(const size_t node_idx, const size_t polynomial_idx) const
Get the derivative of the specific Lagrange polynomial at the specified node. Note that both the node...
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
Defines a solid angle, or ordinate, in spherical geometry.
Definition ordinate.h:15
double x() const
Evaluate the x-direction cosine.
Definition ordinate.cc:32
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 GetWeight(const unsigned int abscissa_index) const
Get the weight value corresponding to a given abscissa value.
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
double DistanceBetweenNodes(const Node &node_1, const Node &node_2)
Compute the Euclidean distance between two nodes.
Definition node.cc:8
double total_xs
Total macroscopic cross section in 1/cm.
Definition material.h:15
A point in the mesh holding its coordinates, boundary info, and flux solution values.
Definition node.h:26
double x
X-coordinate of the node.
Definition node.h:31
double z
Z-coordinate of the node.
Definition node.h:37
std::vector< double > source_fluxes
Source flux values in order of the SN quadrature set. These are scratch values: they are overwritten ...
Definition node.h:57
int bc_id
BC ID to access the boundary condition (BC) bank. ID of 0 is always NONE, meaning the node is interna...
Definition node.h:41
double y
Y-coordinate of the node.
Definition node.h:34
size_t id
Unique identifier for the node.
Definition node.h:28