PolyFEM
Loading...
Searching...
No Matches
LocalHessian.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <Eigen/Core>
4
5#include <cassert>
6#include <utility>
7
8namespace polyfem::assembler
9{
13 {
14 public:
15 // Covers quadratic tetrahedra without putting high-order blocks on the stack.
16 static constexpr int SmallDofs = 30;
17 using SmallMatrix = Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic,
18 Eigen::ColMajor, SmallDofs, SmallDofs>;
19
20 void resize(const Eigen::Index rows, const Eigen::Index cols)
21 {
22 assert(rows >= 0 && cols >= 0);
24 if (use_small_)
25 small_.resize(rows, cols);
26 else
27 large_.resize(rows, cols);
28 }
29
30 Eigen::Index rows() const { return use_small_ ? small_.rows() : large_.rows(); }
31 Eigen::Index cols() const { return use_small_ ? small_.cols() : large_.cols(); }
32
33 template <typename Derived>
34 void assign(const Eigen::MatrixBase<Derived> &matrix)
35 {
36 resize(matrix.rows(), matrix.cols());
37 visit([&](auto &H) { H = matrix; });
38 }
39
40 template <typename F>
41 decltype(auto) visit(F &&f)
42 {
43 if (use_small_)
44 return std::forward<F>(f)(small_);
45 return std::forward<F>(f)(large_);
46 }
47
48 template <typename F>
49 decltype(auto) visit(F &&f) const
50 {
51 if (use_small_)
52 return std::forward<F>(f)(small_);
53 return std::forward<F>(f)(large_);
54 }
55
56 private:
58 // Keep this buffer when selecting small_ so mixed-order meshes can reuse it.
59 Eigen::MatrixXd large_;
60 bool use_small_ = true;
61 };
62} // namespace polyfem::assembler
Reusable element matrix with inline storage for small blocks and a dynamic fallback for high-order el...
void assign(const Eigen::MatrixBase< Derived > &matrix)
decltype(auto) visit(F &&f) const
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor, SmallDofs, SmallDofs > SmallMatrix
void resize(const Eigen::Index rows, const Eigen::Index cols)
Used for test only.