Skip to content

Commit 98f0a75

Browse files
committed
Document mass matrix
1 parent 02236ff commit 98f0a75

File tree

1 file changed

+68
-29
lines changed

1 file changed

+68
-29
lines changed

source/pbat/fem/MassMatrix.h

Lines changed: 68 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/**
2+
* @file MassMatrix.h
3+
* @author Quoc-Minh Ton-That ([email protected])
4+
* @brief MassMatrix API and implementation.
5+
* @date 2025-02-11
6+
*
7+
* @copyright Copyright (c) 2025
8+
*
9+
*/
10+
111
#ifndef PBAT_FEM_MASS_MATRIX_H
212
#define PBAT_FEM_MASS_MATRIX_H
313

@@ -15,23 +25,34 @@
1525
namespace pbat {
1626
namespace fem {
1727

28+
/**
29+
* @brief A matrix-free representation of a finite element mass matrix \f$ \mathbf{M}_{ij} =
30+
* \int_\Omega \rho(X) \phi_i(X) \phi_j(X) \f$.
31+
*
32+
* \note Link to my higher-level FEM crash course doc.
33+
*
34+
* @tparam TMesh Type satisfying concept CMesh
35+
* @tparam QuadratureOrder Quadrature order for integrating the mass matrix
36+
*/
1837
template <CMesh TMesh, int QuadratureOrder>
1938
struct MassMatrix
2039
{
2140
public:
22-
using SelfType = MassMatrix<TMesh, QuadratureOrder>;
23-
using MeshType = TMesh;
24-
using ElementType = typename TMesh::ElementType;
25-
using QuadratureRuleType = typename ElementType::template QuadratureType<QuadratureOrder>;
26-
static int constexpr kOrder = 2 * ElementType::kOrder;
27-
static int constexpr kQuadratureOrder = QuadratureOrder;
41+
using SelfType = MassMatrix<TMesh, QuadratureOrder>; ///< Self type
42+
using MeshType = TMesh; ///< Mesh type
43+
using ElementType = typename TMesh::ElementType; ///< Element type
44+
using QuadratureRuleType =
45+
typename ElementType::template QuadratureType<QuadratureOrder>; ///< Quadrature rule type
46+
static int constexpr kOrder = 2 * ElementType::kOrder; ///< Polynomial order of the mass matrix
47+
static int constexpr kQuadratureOrder = QuadratureOrder; ///< Quadrature order
2848

2949
/**
30-
* @brief
31-
* @param mesh
32-
* @param detJe |#quad.pts.|x|#elements| affine element jacobian determinants at quadrature
50+
* @brief Construct a MassMatrix
51+
* @param mesh Finite element mesh
52+
* @param detJe `|# quad.pts.|x|# elements|` affine element jacobian determinants at quadrature
3353
* points
3454
* @param rho Uniform mass density
55+
* @param dims Dimensionality of image of FEM function space. Should have `dims >= 1`.
3556
*/
3657
MassMatrix(
3758
MeshType const& mesh,
@@ -40,12 +61,13 @@ struct MassMatrix
4061
int dims = 1);
4162

4263
/**
43-
* @brief
44-
* @tparam TDerived
45-
* @param mesh
46-
* @param detJe |#quad.pts.|x|#elements| affine element jacobian determinants at quadrature
64+
* @brief Construct a MassMatrix
65+
* @tparam TDerived Eigen dense expression type
66+
* @param mesh Finite element mesh
67+
* @param detJe `|# quad.pts.|x|# elements|` affine element jacobian determinants at quadrature
4768
* points
48-
* @param rho |#quad.pts.|x|#elements| mass density per quadrature point
69+
* @param rho `|# quad.pts.|x|# elements|` mass density per quadrature point
70+
* @param dims Dimensionality of image of FEM function space. Should have `dims >= 1`.
4971
*/
5072
template <class TDerived>
5173
MassMatrix(
@@ -59,47 +81,64 @@ struct MassMatrix
5981
/**
6082
* @brief Applies this mass matrix as a linear operator on x, adding result to y.
6183
*
62-
* @tparam TDerivedIn
63-
* @tparam TDerivedOut
64-
* @param x
65-
* @param y
84+
* @tparam TDerivedIn Eigen dense expression type
85+
* @tparam TDerivedOut Eigen dense expression type
86+
* @param x Input vector/matrix
87+
* @param y Output vector/matrix
88+
* @pre `x.rows() == |#nodes*dims|` and `y.rows() == |#nodes*dims|` and `x.cols() == y.cols()`
89+
* and `dims >= 1`
6690
*/
6791
template <class TDerivedIn, class TDerivedOut>
6892
void Apply(Eigen::MatrixBase<TDerivedIn> const& x, Eigen::DenseBase<TDerivedOut>& y) const;
6993

7094
/**
71-
* @brief Transforms this matrix-free mass matrix representation into sparse compressed format.
72-
* @return
95+
* @brief Transforms this matrix-free mass matrix representation into sparse compressed column
96+
* format.
97+
* @return CSCMatrix Sparse compressed column matrix representation of this mass matrix
7398
*/
7499
CSCMatrix ToMatrix() const;
75100

76101
/**
77-
* @brief
78-
* @return
102+
* @brief Diagonalizes (via mass lumping) this mass matrix into vector representation.
103+
* @return VectorX Vector of lumped masses
79104
*/
80105
VectorX ToLumpedMasses() const;
81106

107+
/**
108+
* @brief Number of input dimensions.
109+
*
110+
* @return Index
111+
*/
82112
Index InputDimensions() const { return dims * mesh.X.cols(); }
113+
/**
114+
* @brief Number of output dimensions.
115+
*
116+
* @return Index
117+
*/
83118
Index OutputDimensions() const { return InputDimensions(); }
84119

85120
/**
86-
* @brief
87-
* @tparam TDerived
88-
* @param rho |#quad.pts.|x|#elements| piecewise constant mass density
121+
* @brief Computes element mass matrices.
122+
* @tparam TDerived Eigen dense expression type
123+
* @param rho `|# quad.pts.|x|# elements|` piecewise constant mass density
89124
*/
90125
template <class TDerived>
91126
void ComputeElementMassMatrices(Eigen::DenseBase<TDerived> const& rho);
92127

128+
/**
129+
* @brief Checks if this mass matrix is in a valid state.
130+
*/
93131
void CheckValidState() const;
94132

95133
MeshType const& mesh; ///< The finite element mesh
96-
Eigen::Ref<MatrixX const> detJe; ///< |# element quadrature points| x |# elements| matrix of
134+
Eigen::Ref<MatrixX const> detJe; ///< `|# element quadrature points| x |# elements|` matrix of
97135
///< jacobian determinants at element quadrature points
98-
MatrixX Me; ///< |#element nodes|x|#element nodes * #elements| element mass matrices
136+
MatrixX Me; ///< `|# element nodes|x|# element nodes * # elements|` element mass matrices
99137
///< for 1-dimensional problems. For d-dimensional problems, these mass matrices
100-
///< should be Kroneckered with the d-dimensional identity matrix.
138+
///< should be Kroneckered with the \f$ d \f$-dimensional identity matrix
139+
///< \f$ \mathbf{I}_d \f$.
101140
int dims; ///< Dimensionality of image of FEM function space, i.e. this mass matrix is actually
102-
///< M \kronecker I_{dims \times dims}. Should be >= 1.
141+
///< \f$ \mathbf{M} \otimes \mathbf{I}_{d} \f$. Should have `dims >= 1`.
103142
};
104143

105144
template <CMesh TMesh, int QuadratureOrder>

0 commit comments

Comments
 (0)