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
+
1
11
#ifndef PBAT_FEM_MASS_MATRIX_H
2
12
#define PBAT_FEM_MASS_MATRIX_H
3
13
15
25
namespace pbat {
16
26
namespace fem {
17
27
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
+ */
18
37
template <CMesh TMesh, int QuadratureOrder>
19
38
struct MassMatrix
20
39
{
21
40
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
28
48
29
49
/* *
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
33
53
* points
34
54
* @param rho Uniform mass density
55
+ * @param dims Dimensionality of image of FEM function space. Should have `dims >= 1`.
35
56
*/
36
57
MassMatrix (
37
58
MeshType const & mesh,
@@ -40,12 +61,13 @@ struct MassMatrix
40
61
int dims = 1 );
41
62
42
63
/* *
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
47
68
* 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`.
49
71
*/
50
72
template <class TDerived >
51
73
MassMatrix (
@@ -59,47 +81,64 @@ struct MassMatrix
59
81
/* *
60
82
* @brief Applies this mass matrix as a linear operator on x, adding result to y.
61
83
*
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`
66
90
*/
67
91
template <class TDerivedIn , class TDerivedOut >
68
92
void Apply (Eigen::MatrixBase<TDerivedIn> const & x, Eigen::DenseBase<TDerivedOut>& y) const ;
69
93
70
94
/* *
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
73
98
*/
74
99
CSCMatrix ToMatrix () const ;
75
100
76
101
/* *
77
- * @brief
78
- * @return
102
+ * @brief Diagonalizes (via mass lumping) this mass matrix into vector representation.
103
+ * @return VectorX Vector of lumped masses
79
104
*/
80
105
VectorX ToLumpedMasses () const ;
81
106
107
+ /* *
108
+ * @brief Number of input dimensions.
109
+ *
110
+ * @return Index
111
+ */
82
112
Index InputDimensions () const { return dims * mesh.X .cols (); }
113
+ /* *
114
+ * @brief Number of output dimensions.
115
+ *
116
+ * @return Index
117
+ */
83
118
Index OutputDimensions () const { return InputDimensions (); }
84
119
85
120
/* *
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
89
124
*/
90
125
template <class TDerived >
91
126
void ComputeElementMassMatrices (Eigen::DenseBase<TDerived> const & rho);
92
127
128
+ /* *
129
+ * @brief Checks if this mass matrix is in a valid state.
130
+ */
93
131
void CheckValidState () const ;
94
132
95
133
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
97
135
// /< 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
99
137
// /< 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$.
101
140
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` .
103
142
};
104
143
105
144
template <CMesh TMesh, int QuadratureOrder>
0 commit comments