LehrFEM++ 1.0.0
A simple Finite Element Library for teaching
Loading...
Searching...
No Matches
mesh_function_global.h
1
10#ifndef INCG1323b89d2f584608940fcb37657142cc
11#define INCG1323b89d2f584608940fcb37657142cc
12#include <lf/mesh/mesh.h>
13
14#include <vector>
15
16namespace lf::mesh::utils {
17
54template <class F>
57 decltype(std::declval<F>()(std::declval<Eigen::Vector2d>()));
58
59 // The following is needed because otherwise
60 // MeshFunctionGlobal(MeshFunctionGlobal&&) is not noexcept!
61 // Once http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1286r2.html
62 // has been implemented by compilers, we can drop this requirement.
63 static_assert(std::is_nothrow_move_constructible_v<F>,
64 "The functor F must be noexcept move constructible!");
65
66 public:
69 MeshFunctionGlobal& operator=(const MeshFunctionGlobal&) = delete;
70 MeshFunctionGlobal& operator=(MeshFunctionGlobal&&) = delete;
71
72 explicit MeshFunctionGlobal(F f) : f_(std::move(f)) {}
73
77 std::vector<F_return_type> operator()(const mesh::Entity& e,
78 const Eigen::MatrixXd& local) const {
79 LF_ASSERT_MSG(e.RefEl().Dimension() == local.rows(),
80 "mismatch between entity dimension and local.rows()");
81 std::vector<F_return_type> result;
82 result.reserve(local.cols());
83 auto global_points = e.Geometry()->Global(local);
84 for (long i = 0; i < local.cols(); ++i) {
85 result.push_back(f_(global_points.col(i)));
86 }
87 return result;
88 }
89
90 virtual ~MeshFunctionGlobal() = default;
91
92 private:
93 F f_;
94};
95
96} // namespace lf::mesh::utils
97
98#endif // INCG1323b89d2f584608940fcb37657142cc
constexpr dim_t Dimension() const
Return the dimension of this reference element.
Definition ref_el.h:204
virtual Eigen::MatrixXd Global(const Eigen::MatrixXd &local) const =0
Map a number of points in local coordinates into the global coordinate system.
Interface class representing a topological entity in a cellular complex
Definition entity.h:42
virtual const geometry::Geometry * Geometry() const =0
Describes the geometry of this entity.
virtual base::RefEl RefEl() const =0
Describes the reference element type of this entity.
MeshFunction wrapper for a simple function of physical coordinates.
MeshFunctionGlobal(MeshFunctionGlobal &&) noexcept=default
MeshFunctionGlobal(const MeshFunctionGlobal &)=default
std::vector< F_return_type > operator()(const mesh::Entity &e, const Eigen::MatrixXd &local) const
MeshFunction compliant evaluation operator.
decltype(std::declval< F >()(std::declval< Eigen::Vector2d >())) F_return_type
Contains helper functions and classes that all operate on the interface classes defined in lf::mesh.