24#ifndef VULPES_FE_FE_EXPRESSIONS_FE_EXPR_BASE_HPP_
25#define VULPES_FE_FE_EXPRESSIONS_FE_EXPR_BASE_HPP_
40template <std::
size_t Dim>
43template <std::
size_t Dim>
44using CellsType = std::vector<std::unique_ptr<CellType<Dim>>>;
46template <std::
size_t Dim,
typename FeExpression>
69 using TypeU = std::decay_t<
decltype(u)>;
70 using PolyTypeU =
typename TypeU::Scalar;
71 using TypeV = std::decay_t<
decltype(v)>;
72 using PolyTypeV =
typename TypeV::Scalar;
73 static_assert(std::is_same_v<PolyTypeU, PolyTypeV>);
74 assert(u.rows() == v.rows());
75 return Eigen::Matrix<PolyTypeU, -1, -1>{
76 (Eigen::Matrix<PolyTypeU, -1, -1>(u.rows(), u.cols() + v.cols()) << u, v)
89template <
typename FromMat,
typename ToPoly>
91 constexpr Eigen::Index Rows = FromMat::RowsAtCompileTime;
92 constexpr Eigen::Index Cols = FromMat::ColsAtCompileTime;
93 using Lifted = Eigen::Matrix<ToPoly, Rows, Cols>;
97 const typename ToPoly::ScalarType one_scalar(1);
98 const ToPoly one_poly(one_scalar);
100 for (Eigen::Index i = 0; i < m.rows(); ++i) {
101 for (Eigen::Index j = 0; j < m.cols(); ++j) {
102 assert(m(i, j) == 1.0);
103 out(i, j) = one_poly;
118template <
typename FromMat,
typename ToPoly>
120 constexpr Eigen::Index Rows = FromMat::RowsAtCompileTime;
121 constexpr Eigen::Index Cols = FromMat::ColsAtCompileTime;
122 using Lifted = Eigen::Matrix<ToPoly, Rows, Cols>;
125 for (Eigen::Index i = 0; i < m.rows(); ++i) {
126 for (Eigen::Index j = 0; j < m.cols(); ++j) {
142 const auto& u,
const auto& v) {
143 using TypeU = std::decay_t<
decltype(u)>;
144 using PolyU =
typename TypeU::Scalar;
145 using TypeV = std::decay_t<
decltype(v)>;
146 using PolyV =
typename TypeV::Scalar;
148 if constexpr (std::is_same_v<PolyU, PolyV>) {
149 return std::pair<TypeU, TypeV>{u, v};
150 }
else if constexpr (std::is_same_v<PolyU, double>) {
154 }
else if constexpr (std::is_same_v<PolyV, double>) {
158 }
else if constexpr (PolyU::dim < PolyV::dim) {
160 }
else if constexpr (PolyU::dim > PolyV::dim) {
163 static_assert(
false,
"unhandled combination of polynomial types");
181 const auto& u,
const auto& v) {
182 using TypeU = std::decay_t<
decltype(u)>;
183 using PolyTypeU =
typename TypeU::Scalar;
184 using TypeV = std::decay_t<
decltype(v)>;
185 using PolyTypeV =
typename TypeV::Scalar;
187 static_assert(std::is_same_v<PolyTypeU, PolyTypeV>);
188 assert(u.rows() == v.rows());
189 Eigen::Matrix<PolyTypeU, -1, -1> result(u.rows(), u.cols() * v.cols());
190 Eigen::Index idx = 0;
191 for (Eigen::Index i = 0; i < u.cols(); ++i) {
192 for (Eigen::Index j = 0; j < v.cols(); ++j) {
193 for (Eigen::Index k = 0; k < u.rows(); ++k) {
194 result(k, idx) = u(k, i) * v(k, j);
209template <std::
size_t Dim,
typename FeExpression>
225 constexpr const auto&
feSpace()
const {
return self().feSpace(); }
239 template <std::
size_t J = 0, std::
size_t I = 0>
244 std::size_t q)
const {
245 return self().evaluate(fe_values, j, i, q);
270 std::size_t bj)
const {
271 return self().evaluatePoly(fe_values, j, i, bi, bj);
292 const auto& fe_values,
294 std::size_t bj)
const {
295 return self().evaluatePolyCoef(mapping, fe_values, bi, bj);
305 return self().computeUpdateFlags();
325 return self().precompute(fe_values, cells);
338 const FeExpression&
self()
const {
339 return static_cast<FeExpression const&
>(*this);
Base class for Finite Element Expressions.
Definition fe_expr_base.hpp:210
decltype(auto) evaluate(const FeValues< Dim > &fe_values, std::size_t j, std::size_t i, std::size_t q) const
Evaluate the finite element expression evaluated at function basis i and j and at quadrature point q.
Definition fe_expr_base.hpp:240
static constexpr uint8_t is_bilinear
Indicates the appearance of trial/test functions in the expression.
Definition fe_expr_base.hpp:215
static constexpr std::size_t k_index_begin
Index the block of the expression starts from (for vectorial problems).
Definition fe_expr_base.hpp:218
constexpr UpdateFlagsType computeUpdateFlags() const
Compute the update flags required by the expression for the update in the FeValues.
Definition fe_expr_base.hpp:304
static constexpr bool is_leaf
Indicates if the expression is a leaf node in the expression tree.
Definition fe_expr_base.hpp:213
static constexpr std::size_t k_index_end
Index the block of the expression ends to (for vectorial problems).
Definition fe_expr_base.hpp:220
constexpr std::size_t computeOrder() const
Compute the polynomial order required by the expression.
Definition fe_expr_base.hpp:313
constexpr FeExpressionUnaryMinus< Dim, FeExpression > operator-() const
Unary minus operator for the FE expression.
Definition fe_expr_base.hpp:333
decltype(auto) evaluatePoly(const FeValues< Dim > &fe_values, std::size_t j, std::size_t i, std::size_t bi, std::size_t bj) const
Compute the polynomial associated to the expression for basis i and j and block bi and bj.
Definition fe_expr_base.hpp:265
void FeSpaceType
Type of the associated Finite Element Space.
Definition fe_expr_base.hpp:223
decltype(auto) evaluatePolyCoef(const auto &mapping, const auto &fe_values, std::size_t bi, std::size_t bj) const
Compute the coefficients of the polynomial associated to the expression for basis i and j and block b...
Definition fe_expr_base.hpp:290
constexpr bool precompute(const FeValues< Dim > &fe_values, const CellsType< Dim > &cells) const
Precompute any necessary data for the expression based on the FE values and the cells.
Definition fe_expr_base.hpp:323
const FeExpression & self() const
Definition fe_expr_base.hpp:338
constexpr const auto & feSpace() const
Get the associated Finite Element Space.
Definition fe_expr_base.hpp:225
Definition fe_expr_unary.hpp:40
This class works as a cache table for computing efficiently the value of the basis function and its d...
Definition fe_values.hpp:94
#define VULPES_ALWAYS_INLINE
Force the compiler to inline the annotated function.
Definition macros.hpp:30
Definition fe_expr_base.hpp:58
auto liftDimension(const FromMat &m)
Convert a matrix of polynomials of lower dimension into a matrix of polynomials of higher dimension (...
Definition fe_expr_base.hpp:119
static VULPES_ALWAYS_INLINE auto cartesian_hcat(const auto &u, const auto &v)
Horizontal concatenation of the cartesian product of the columns of two matrices.
Definition fe_expr_base.hpp:180
static VULPES_ALWAYS_INLINE auto lift_to_same_space(const auto &u, const auto &v)
Given two matrices of polynomials u and v, lift the one with lower dimension to the higher dimension,...
Definition fe_expr_base.hpp:141
static VULPES_ALWAYS_INLINE auto hcat(const auto &u, const auto &v)
Horizontally concatenate two matrices that have the same number of rows.
Definition fe_expr_base.hpp:68
auto liftConstant(const FromMat &m)
Convert a matrix of scalars into a matrix of polynomials (constant polynomials).
Definition fe_expr_base.hpp:90
Definition dof_policy.hpp:45
geometry::Cell< Dim, double, int32_t > CellType
Definition fe_expr_base.hpp:41
std::underlying_type_t< UpdateFlags > UpdateFlagsType
Definition fe_values.hpp:65
std::vector< std::unique_ptr< CellType< Dim > > > CellsType
Definition fe_expr_base.hpp:44
IntegrationForm
Enumeration for the type of integration form (presence of test/trial functions).
Definition fe_expr_base.hpp:51
@ IsLinearTest
Definition fe_expr_base.hpp:53
@ IsNothing
Definition fe_expr_base.hpp:52
@ IsLinearTrial
Definition fe_expr_base.hpp:54
@ IsBilinear
Definition fe_expr_base.hpp:55
std::conditional_t< Dim==2, Cell2D< FloatType, IndexType >, Cell3D< FloatType, IndexType > > Cell
Definition cell.hpp:267
Definition cell_manager.hpp:38