SpECTRE
v2024.12.16
|
Functionality associated with a particular choice of basis functions and quadrature for spectral operations. More...
Namespaces | |
namespace | filtering |
Matrices for filtering spectral coefficients. | |
namespace | Swsh |
Namespace for spin-weighted spherical harmonic utilities. | |
Classes | |
struct | MortarSizeHash |
Typedefs | |
using | MortarSize = ChildSize |
The portion of an element covered by a mortar. | |
Enumerations | |
enum class | Basis : uint8_t { Uninitialized = 0 << basis_shift , Chebyshev = 1 << basis_shift , Legendre = 2 << basis_shift , FiniteDifference = 3 << basis_shift , SphericalHarmonic = 4 << basis_shift } |
Either the basis functions used by a spectral or discontinuous Galerkin (DG) method, or the value FiniteDifference when a finite difference method is used. More... | |
enum class | ChildSize : uint8_t { Uninitialized = 0 , Full = 1 , UpperHalf = 2 , LowerHalf = 3 } |
The portion of a mesh covered by a child mesh. | |
enum class | Quadrature : uint8_t { Uninitialized = 0 , Gauss , GaussLobatto , CellCentered , FaceCentered , Equiangular } |
Either the choice of quadrature method to compute integration weights for a spectral or discontinuous Galerkin (DG) method, or the locations of grid points when a finite difference method is used. More... | |
Functions | |
std::array< Basis, 5 > | all_bases () |
All possible values of Basis. | |
Basis | to_basis (const std::string &basis) |
Convert a string to a Basis enum. | |
std::ostream & | operator<< (std::ostream &os, const Basis &basis) |
Output operator for a Basis. | |
template<typename CoefficientDataType , typename DataType > | |
DataType | evaluate_clenshaw (const std::vector< CoefficientDataType > &coefficients, const DataType &alpha, const DataType &beta, const DataType &f0_of_x, const DataType &f1_of_x) |
Clenshaw's algorithm for evaluating linear combinations of basis functions obeying a given three term recurrence relation. See numerical recipes 3rd edition 5.4.2 for details. alpha and beta define the recursion f0_of_x and f1_of_x are | |
std::ostream & | operator<< (std::ostream &os, ChildSize mortar_size) |
template<size_t Dim> | |
bool | needs_projection (const Mesh< Dim > &mesh1, const Mesh< Dim > &mesh2, const std::array< ChildSize, Dim > &child_sizes) |
Determine whether data needs to be projected between a child mesh and its parent mesh. If no projection is necessary the data may be used as-is. Projection is necessary if the child is either p-refined or h-refined relative to its parent, or both. This operation is symmetric, i.e. it is irrelevant in which order the child and the parent mesh are passed in. | |
const Matrix & | projection_matrix_child_to_parent (const Mesh< 1 > &child_mesh, const Mesh< 1 > &parent_mesh, ChildSize size, bool operand_is_massive=false) |
The projection matrix from a child mesh to its parent. More... | |
template<size_t Dim> | |
std::array< std::reference_wrapper< const Matrix >, Dim > | projection_matrix_child_to_parent (const Mesh< Dim > &child_mesh, const Mesh< Dim > &parent_mesh, const std::array< ChildSize, Dim > &child_sizes, bool operand_is_massive=false) |
The projection matrix from a child mesh to its parent, in Dim dimensions. | |
const Matrix & | projection_matrix_parent_to_child (const Mesh< 1 > &parent_mesh, const Mesh< 1 > &child_mesh, ChildSize size) |
The projection matrix from a parent mesh to one of its children. More... | |
template<size_t Dim> | |
std::array< std::reference_wrapper< const Matrix >, Dim > | projection_matrix_parent_to_child (const Mesh< Dim > &parent_mesh, const Mesh< Dim > &child_mesh, const std::array< ChildSize, Dim > &child_sizes) |
The projection matrix from a parent mesh to one of its children, in Dim dimensions. | |
template<size_t Dim> | |
std::array< std::reference_wrapper< const Matrix >, Dim > | p_projection_matrices (const Mesh< Dim > &source_mesh, const Mesh< Dim > &target_mesh) |
The projection matrices from a source mesh to a target mesh where the meshes cover the same physical volume. | |
std::array< Quadrature, 6 > | all_quadratures () |
All possible values of Quadrature. | |
Quadrature | to_quadrature (const std::string &quadrature) |
Convert a string to a Quadrature enum. | |
std::ostream & | operator<< (std::ostream &os, const Quadrature &quadrature) |
Output operator for a Quadrature. | |
template<Basis BasisType, typename T > | |
T | compute_basis_function_value (size_t k, const T &x) |
Compute the function values of the basis function | |
template<Basis > | |
DataVector | compute_inverse_weight_function_values (const DataVector &) |
Compute the inverse of the weight function quadrature_weights(size_t) for details. This is arbitrarily set to 1 for FiniteDifference basis, to integrate using the midpoint method (see quadrature_weights (size_t) for details). | |
template<Basis BasisType> | |
double | compute_basis_function_normalization_square (size_t k) |
Compute the normalization square of the basis function | |
template<Basis BasisType, Quadrature QuadratureType> | |
std::pair< DataVector, DataVector > | compute_collocation_points_and_weights (size_t num_points) |
Compute the collocation points and weights associated to the basis and quadrature. More... | |
template<Basis BasisType, Quadrature QuadratureType> | |
const DataVector & | collocation_points (size_t num_points) |
Collocation points. More... | |
const DataVector & | collocation_points (const Mesh< 1 > &mesh) |
Collocation points for a one-dimensional mesh. More... | |
template<Basis BasisType, Quadrature QuadratureType> | |
const DataVector & | quadrature_weights (size_t num_points) |
Weights to compute definite integrals. More... | |
const DataVector & | quadrature_weights (const Mesh< 1 > &mesh) |
Quadrature weights for a one-dimensional mesh. More... | |
template<Basis BasisType, Quadrature QuadratureType> | |
const Matrix & | weak_flux_differentiation_matrix (size_t num_points) |
Matrix used to compute the divergence of the flux in weak form. More... | |
const Matrix & | weak_flux_differentiation_matrix (const Mesh< 1 > &mesh) |
Matrix used to compute the divergence of the flux in weak form. More... | |
template<Basis BasisType, Quadrature QuadratureType> | |
const Matrix & | integration_matrix (size_t num_points) |
Matrix used to perform an indefinite integral of a function over the logical grid. The left boundary condition is such that the integral is 0 at | |
const Matrix & | integration_matrix (const Mesh< 1 > &mesh) |
Indefinite integration matrix for a one-dimensional mesh. More... | |
template<Basis BasisType, Quadrature QuadratureType, typename T > | |
Matrix | interpolation_matrix (size_t num_points, const T &target_points) |
Matrix used to interpolate to the target_points . More... | |
template<typename T > | |
Matrix | interpolation_matrix (const Mesh< 1 > &mesh, const T &target_points) |
Interpolation matrix to the target_points for a one-dimensional mesh. More... | |
template<Basis BasisType, Quadrature QuadratureType> | |
const Matrix & | modal_to_nodal_matrix (size_t num_points) |
Matrix used to transform from the spectral coefficients (modes) of a function to its nodal coefficients. Also referred to as the Vandermonde matrix. More... | |
const Matrix & | modal_to_nodal_matrix (const Mesh< 1 > &mesh) |
Transformation matrix from modal to nodal coefficients for a one-dimensional mesh. More... | |
template<Basis BasisType, Quadrature QuadratureType> | |
const Matrix & | nodal_to_modal_matrix (size_t num_points) |
Matrix used to transform from the nodal coefficients of a function to its spectral coefficients (modes). Also referred to as the inverse Vandermonde matrix. More... | |
const Matrix & | nodal_to_modal_matrix (const Mesh< 1 > &mesh) |
Transformation matrix from nodal to modal coefficients for a one-dimensional mesh. More... | |
template<Basis BasisType, Quadrature QuadratureType> | |
const Matrix & | linear_filter_matrix (size_t num_points) |
Matrix used to linearize a function. More... | |
const Matrix & | linear_filter_matrix (const Mesh< 1 > &mesh) |
Linear filter matrix for a one-dimensional mesh. More... | |
template<size_t DimMinusOne> | |
size_t | hash (const std::array< Spectral::ChildSize, DimMinusOne > &mortar_size) |
Performs a perfect hash of the mortars into | |
template<Basis BasisType, Quadrature QuadratureType> | |
const Matrix & | differentiation_matrix (size_t num_points) |
Matrix used to compute the derivative of a function. More... | |
template<Basis BasisType, Quadrature QuadratureType> | |
const Matrix & | differentiation_matrix_transpose (size_t num_points) |
Matrix used to compute the derivative of a function. More... | |
const Matrix & | differentiation_matrix (const Mesh< 1 > &mesh) |
Differentiation matrix for a one-dimensional mesh. More... | |
const Matrix & | differentiation_matrix_transpose (const Mesh< 1 > &mesh) |
Differentiation matrix for a one-dimensional mesh. More... | |
const std::pair< Matrix, Matrix > & | boundary_interpolation_matrices (const Mesh< 1 > &mesh) |
Matrices that interpolate to the lower and upper boundaries of the element. More... | |
template<Basis BasisType, Quadrature QuadratureType> | |
const std::pair< Matrix, Matrix > & | boundary_interpolation_matrices (size_t num_points) |
Matrices that interpolate to the lower and upper boundaries of the element. More... | |
const std::pair< DataVector, DataVector > & | boundary_interpolation_term (const Mesh< 1 > &mesh) |
Interpolates values from the boundary into the volume, which is needed when applying time derivative or Bjorhus-type boundary conditions in a discontinuous Galerkin scheme using Gauss points. More... | |
template<Basis BasisType, Quadrature QuadratureType> | |
const std::pair< DataVector, DataVector > & | boundary_interpolation_term (size_t num_points) |
Interpolates values from the boundary into the volume, which is needed when applying time derivative or Bjorhus-type boundary conditions in a discontinuous Galerkin scheme using Gauss points. More... | |
const std::pair< DataVector, DataVector > & | boundary_lifting_term (const Mesh< 1 > &mesh) |
Terms used during the lifting portion of a discontinuous Galerkin scheme when using Gauss points. More... | |
template<Basis BasisType, Quadrature QuadratureType> | |
const std::pair< DataVector, DataVector > & | boundary_lifting_term (size_t num_points) |
Terms used during the lifting portion of a discontinuous Galerkin scheme when using Gauss points. More... | |
Variables | |
constexpr uint8_t | basis_shift = 4 |
The amount we left-shift the basis integers by. More... | |
template<Basis basis, Quadrature quadrature> | |
constexpr size_t | minimum_number_of_points |
Minimum number of possible collocation points for a quadrature type. More... | |
template<Basis basis> | |
constexpr size_t | maximum_number_of_points |
Maximum number of allowed collocation points. More... | |
Functionality associated with a particular choice of basis functions and quadrature for spectral operations.
The functions in this namespace provide low-level access to collocation points, quadrature weights and associated matrices, such as for differentiation and interpolation. They are available in two versions: either templated directly on the enum cases of the Spectral::Basis and Spectral::Quadrature types, or taking a one-dimensional Mesh as their argument.
Most algorithms in this namespace are adapted from [113].
|
strong |
Either the basis functions used by a spectral or discontinuous Galerkin (DG) method, or the value FiniteDifference
when a finite difference method is used.
The particular choices of Basis and Quadrature determine where the collocation points of a Mesh are located in an Element. For a spectral or DG method, the Basis also represents the choice of basis functions used to represent a function on an Element, which then provides a convenient choice for the operators used for differentiation, interpolation, etc. For a finite difference method, one needs to choose the order of the scheme (and hence the weights, differentiation matrix, integration weights, and interpolant) locally in space and time to handle discontinuous solutions.
Legendre
for a general-purpose spectral or DG mesh, unless you have a particular reason for choosing Chebyshev
.SphericalHarmonic
to choose a spherical harmonic basis. By convention, the first dimension represents the polar/zentith angle (or colatitude), while the second dimension represents the azimuthal angle (or longitude)Uninitialized
value. The number of bits to shift is encoded in the variable Spectral::detail::basis_shift
.
|
strong |
Either the choice of quadrature method to compute integration weights for a spectral or discontinuous Galerkin (DG) method, or the locations of grid points when a finite difference method is used.
The particular choices of Basis and Quadrature determine where the collocation points of a Mesh are located in an Element. For a spectral or DG method, integrals using
Gauss
or GaussLobatto
when using Basis::Legendre or Basis::Chebyshev.CellCentered
or FaceCentered
when using Basis::FiniteDifference.Gauss
for the first dimension and Equiangular
in the second dimension.Uninitialized
value. const std::pair< Matrix, Matrix > & Spectral::boundary_interpolation_matrices | ( | const Mesh< 1 > & | mesh | ) |
Matrices that interpolate to the lower and upper boundaries of the element.
Assumes that the logical coordinates are
const std::pair< Matrix, Matrix > & Spectral::boundary_interpolation_matrices | ( | size_t | num_points | ) |
Matrices that interpolate to the lower and upper boundaries of the element.
Assumes that the logical coordinates are
const std::pair< DataVector, DataVector > & Spectral::boundary_interpolation_term | ( | const Mesh< 1 > & | mesh | ) |
Interpolates values from the boundary into the volume, which is needed when applying time derivative or Bjorhus-type boundary conditions in a discontinuous Galerkin scheme using Gauss points.
Assumes that the logical coordinates are DataVector
s stores
This is a different correction from lifting. Lifting is done using the mass matrix, which is an integral over the basis functions, while here we use interpolation.
const std::pair< DataVector, DataVector > & Spectral::boundary_interpolation_term | ( | size_t | num_points | ) |
Interpolates values from the boundary into the volume, which is needed when applying time derivative or Bjorhus-type boundary conditions in a discontinuous Galerkin scheme using Gauss points.
Assumes that the logical coordinates are DataVector
s stores
This is a different correction from lifting. Lifting is done using the mass matrix, which is an integral over the basis functions, while here we use interpolation.
const std::pair< DataVector, DataVector > & Spectral::boundary_lifting_term | ( | const Mesh< 1 > & | mesh | ) |
Terms used during the lifting portion of a discontinuous Galerkin scheme when using Gauss points.
Assumes that the logical coordinates are
const std::pair< DataVector, DataVector > & Spectral::boundary_lifting_term | ( | size_t | num_points | ) |
Terms used during the lifting portion of a discontinuous Galerkin scheme when using Gauss points.
Assumes that the logical coordinates are
const DataVector & Spectral::collocation_points | ( | const Mesh< 1 > & | mesh | ) |
Collocation points for a one-dimensional mesh.
const DataVector & Spectral::collocation_points | ( | size_t | num_points | ) |
Collocation points.
num_points | The number of collocation points |
std::pair< DataVector, DataVector > Spectral::compute_collocation_points_and_weights | ( | size_t | num_points | ) |
Compute the collocation points and weights associated to the basis and quadrature.
This function is expected to return the tuple quadrature_weights(size_t)
.
FiniteDifference
basis or CellCentered
and FaceCentered
quadratures, the weights are defined to integrate with the midpoint method Differentiation matrix for a one-dimensional mesh.
const Matrix & Spectral::differentiation_matrix | ( | size_t | num_points | ) |
Matrix used to compute the derivative of a function.
For a function represented by the nodal coefficients
The finite difference matrix uses summation by parts operators,
num_points | The number of collocation points |
Differentiation matrix for a one-dimensional mesh.
const Matrix & Spectral::differentiation_matrix_transpose | ( | size_t | num_points | ) |
Matrix used to compute the derivative of a function.
For a function represented by the nodal coefficients
The finite difference matrix uses summation by parts operators,
num_points | The number of collocation points |
size_t Spectral::hash | ( | const std::array< Spectral::ChildSize, DimMinusOne > & | mortar_size | ) |
Performs a perfect hash of the mortars into
This is particularly useful when hashing into statically-sized maps based on the number of dimensions.
Indefinite integration matrix for a one-dimensional mesh.
const Matrix & Spectral::integration_matrix | ( | size_t | num_points | ) |
Matrix used to perform an indefinite integral of a function over the logical grid. The left boundary condition is such that the integral is 0 at
Currently only Legendre and Chebyshev polynomials are implemented, but we provide a derivation for how to compute the indefinite integration matrix for general Jacobi polynomials.
The Legendre polynomials have the identity:
The goal is to evaluate the integral of a function
We similarly expand the indefinite integral of
Thus we get that for
and
The matrix returned by this function is the product of the tridiagonal matrix for the
A similar derivation leads to the relations:
We again have:
These are then used to define the indefinite integration matrix.
For general Jacobi polynomials
we have that
where
Following the same derivation we get that
and the boundary condition is
where
Matrix Spectral::interpolation_matrix | ( | const Mesh< 1 > & | mesh, |
const T & | target_points | ||
) |
Interpolation matrix to the target_points
for a one-dimensional mesh.
Matrix Spectral::interpolation_matrix | ( | size_t | num_points, |
const T & | target_points | ||
) |
Matrix used to interpolate to the target_points
.
BasisType
(often num_points
).num_points | The number of collocation points |
target_points | The points to interpolate to |
Linear filter matrix for a one-dimensional mesh.
const Matrix & Spectral::linear_filter_matrix | ( | size_t | num_points | ) |
Matrix used to linearize a function.
Filters out all except the lowest two modes by applying modal_to_nodal_matrix(size_t)
.
num_points | The number of collocation points |
Transformation matrix from modal to nodal coefficients for a one-dimensional mesh.
const Matrix & Spectral::modal_to_nodal_matrix | ( | size_t | num_points | ) |
Matrix used to transform from the spectral coefficients (modes) of a function to its nodal coefficients. Also referred to as the Vandermonde matrix.
The Vandermonde matrix is computed as
num_points | The number of collocation points |
Transformation matrix from nodal to modal coefficients for a one-dimensional mesh.
const Matrix & Spectral::nodal_to_modal_matrix | ( | size_t | num_points | ) |
Matrix used to transform from the nodal coefficients of a function to its spectral coefficients (modes). Also referred to as the inverse Vandermonde matrix.
This is the inverse to the Vandermonde matrix
num_points | The number of collocation points |
const Matrix & Spectral::projection_matrix_child_to_parent | ( | const Mesh< 1 > & | child_mesh, |
const Mesh< 1 > & | parent_mesh, | ||
ChildSize | size, | ||
bool | operand_is_massive = false |
||
) |
The projection matrix from a child mesh to its parent.
The projection matrices returned by this function (and by projection_matrix_parent_to_child()) define orthogonal projection operators between the spaces of functions on a parent mesh and its children. These projections are usually the correct way to transfer data between meshes in a mesh-refinement hierarchy, as well as between an element face and its adjacent mortars.
These functions assume that the child_mesh
is at least as fine as the parent_mesh
, i.e. functions on the parent_mesh
can be represented exactly on the child_mesh
. In practice this means that functions can be projected to a mortar (the child_mesh
) from both adjacent element faces (the parent_mesh
) without losing accuracy. Similarly, functions in a mesh-refinement hierarchy don't lose accuracy when an element is split (h-refined). For this reason, the projection_matrix_child_to_parent
is sometimes referred to as a "restriction operator" and the projection_matrix_parent_to_child
as a "prolongation operator".
true
for the parameter operand_is_massive
(default is false
). The restriction operator for this case is just the transpose of the prolongation operator, i.e. just an interpolation matrix transpose. Note that the "massive" residual already takes the difference in element size between parent and children into account by including a Jacobian in the volume element of the integral.
const Matrix & Spectral::projection_matrix_parent_to_child | ( | const Mesh< 1 > & | parent_mesh, |
const Mesh< 1 > & | child_mesh, | ||
ChildSize | size | ||
) |
The projection matrix from a parent mesh to one of its children.
const DataVector & Spectral::quadrature_weights | ( | const Mesh< 1 > & | mesh | ) |
Quadrature weights for a one-dimensional mesh.
const DataVector & Spectral::quadrature_weights | ( | size_t | num_points | ) |
Weights to compute definite integrals.
These are the coefficients to contract with the nodal function values
Note that the term quadrature also often refers to the quantity
For a FiniteDifference
basis or CellCentered
and FaceCentered
quadratures, the interpretation of the quadrature weights in term of an approximation to
num_points | The number of collocation points |
Matrix used to compute the divergence of the flux in weak form.
const Matrix & Spectral::weak_flux_differentiation_matrix | ( | size_t | num_points | ) |
Matrix used to compute the divergence of the flux in weak form.
This is the transpose of the differentiation matrix multiplied by quadrature weights that appear in DG integrals:
num_points | The number of collocation points |
|
constexpr |
The amount we left-shift the basis integers by.
We do this to be able to represent the combined Basis and Quadrature as one 8-bit integer.
|
constexpr |
Maximum number of allowed collocation points.
We choose a limit of 24 FD grid points because for DG-subcell the number of points in an element is 2 * number_dg_points - 1
for cell centered, and 2 * number_dg_points
for face-centered. Because there is no way of generically retrieving the maximum number of grid points for a non-FD basis, we need to hard-code both values here. If the number of grid points is increased for the non-FD bases, it should also be increased for the FD basis. Note that for good task-based parallelization 24 grid points is already a fairly large number.
|
constexpr |
Minimum number of possible collocation points for a quadrature type.
Since Gauss-Lobatto quadrature has points on the domain boundaries it must have at least two collocation points. Gauss quadrature can have only one collocation point.
For CellCentered
the minimum number of points is 1, while for FaceCentered
it is 2.