PolyFEM
Loading...
Searching...
No Matches
Basis.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include <Eigen/Dense>
7#include <functional>
8
9#include <vector>
10
11namespace polyfem
12{
13 namespace basis
14 {
22 {
23 public:
24 int index;
25 double val;
26
28
30 : index(-1), val(0)
31 {
32 }
33
34 Local2Global(const int _index, const RowVectorNd &_node, const double _val)
35 : index(_index), val(_val), node(_node)
36 {
37 }
38 };
39
43 class Basis
44 {
45
46 public:
47 typedef std::function<void(const Eigen::MatrixXd &uv, Eigen::MatrixXd &val)> Fun;
48
49 Basis();
50
58 void init(const int order, const int global_index, const int local_index, const RowVectorNd &node);
59
63 inline bool is_complete() const { return !global_.empty(); }
64
72 void eval_basis(const Eigen::MatrixXd &uv, Eigen::MatrixXd &val) const
73 {
74 assert(basis_);
75 basis_(uv, val);
76 }
77
84 Eigen::MatrixXd operator()(const Eigen::MatrixXd &uv) const
85 {
86 Eigen::MatrixXd val;
87 eval_basis(uv, val);
88 return val;
89 }
90
97 void eval_grad(const Eigen::MatrixXd &uv, Eigen::MatrixXd &val) const
98 {
99 assert(grad_);
100 grad_(uv, val);
101 }
102
103 // list of local to global mappings
104 inline const std::vector<Local2Global> &global() const { return global_; }
105 inline std::vector<Local2Global> &global() { return global_; }
106
107 // setting the basis lambda and its gradient
108 inline void set_basis(const Fun &fun) { basis_ = fun; }
109 inline void set_grad(const Fun &fun) { grad_ = fun; }
110
111 inline bool is_defined() const { return (basis_ ? true : false); }
112 inline int order() const { return order_; }
113
114 // output
115 friend std::ostream &operator<<(std::ostream &os, const Basis &obj)
116 {
117 os << obj.local_index_ << ":\n";
118 for (auto l2g : obj.global_)
119 os << "\tl2g: " << l2g.index << " (" << l2g.node << ") " << l2g.val << "\n";
120
121 return os;
122 }
123
124 private:
125 std::vector<Local2Global> global_;
128
131 };
132 } // namespace basis
133} // namespace polyfem
double val
Definition Assembler.cpp:86
Represents one basis function and its gradient.
Definition Basis.hpp:44
friend std::ostream & operator<<(std::ostream &os, const Basis &obj)
Definition Basis.hpp:115
int order() const
Definition Basis.hpp:112
bool is_complete() const
Checks if global is empty or not.
Definition Basis.hpp:63
bool is_defined() const
Definition Basis.hpp:111
Fun basis_
basis and gadient
Definition Basis.hpp:129
void eval_basis(const Eigen::MatrixXd &uv, Eigen::MatrixXd &val) const
Evaluates the basis function over a set of uv parameters.
Definition Basis.hpp:72
void set_grad(const Fun &fun)
Definition Basis.hpp:109
void set_basis(const Fun &fun)
Definition Basis.hpp:108
const std::vector< Local2Global > & global() const
Definition Basis.hpp:104
std::vector< Local2Global > & global()
Definition Basis.hpp:105
void init(const int order, const int global_index, const int local_index, const RowVectorNd &node)
Initialize a basis function within an element.
Definition Basis.cpp:14
void eval_grad(const Eigen::MatrixXd &uv, Eigen::MatrixXd &val) const
Evaluate the gradient of the basis function.
Definition Basis.hpp:97
std::function< void(const Eigen::MatrixXd &uv, Eigen::MatrixXd &val)> Fun
Definition Basis.hpp:47
std::vector< Local2Global > global_
list of real nodes influencing the basis
Definition Basis.hpp:125
Eigen::MatrixXd operator()(const Eigen::MatrixXd &uv) const
Evaluate the basis function over a set of uv parameters.
Definition Basis.hpp:84
int local_index_
local index inside the element (for debugging purposes)
Definition Basis.hpp:126
Represents a virtual node of the FEM mesh as a weighted sum of real (unknown) nodes.
Definition Basis.hpp:22
RowVectorNd node
node position
Definition Basis.hpp:27
int index
global index of the actual node
Definition Basis.hpp:24
Local2Global(const int _index, const RowVectorNd &_node, const double _val)
Definition Basis.hpp:34
Eigen::Matrix< double, 1, Eigen::Dynamic, Eigen::RowMajor, 1, 3 > RowVectorNd
Definition Types.hpp:13