18#include <lf/assemble/assemble.h>
19#include <lf/mesh/utils/utils.h>
20#include <lf/quad/quad.h>
22#include "scalar_fe_space.h"
35template <
class MF,
class QR_
SELECTOR>
36auto LocalIntegral(
const mesh::Entity &e,
const QR_SELECTOR &qr_selector,
39 auto qr = qr_selector(e);
40 auto values = mf(e, qr.Points());
44 LF_ASSERT_MSG(values.size() == qr.NumPoints(),
45 "mf returns vector with wrong size.");
46 if constexpr (std::is_arithmetic_v<MfType>) {
47 auto value_m = Eigen::Map<Eigen::Matrix<MfType, 1, Eigen::Dynamic>>(
48 &values[0], 1, values.size());
49 return (value_m * weights_ie)(0);
53 constexpr int size = MfType::SizeAtCompileTime;
54 if constexpr (size != Eigen::Dynamic) {
55 auto value_m = Eigen::Map<
56 Eigen::Matrix<typename MfType::Scalar, size, Eigen::Dynamic>>(
57 &values[0](0, 0), size, values.size());
60 Eigen::Map<Eigen::Matrix<typename MfType::Scalar, size, 1>>(
62 result_m = value_m * weights_ie;
67 MfType temp = weights_ie(0) * values[0];
68 for (Eigen::Index i = 1; i < qr.NumPoints(); ++i) {
69 temp = temp + weights_ie(i) * values[i];
109 requires std::is_invocable_v<QR_SELECTOR, const mesh::Entity &>
111 const lf::mesh::Mesh &mesh,
const MF &mf,
const QR_SELECTOR &qr_selector,
116 auto entities = mesh.
Entities(codim);
117 auto result = internal::LocalIntegral(**entities.begin(), qr_selector, mf);
118 for (
auto i = entities.begin() + 1; i != entities.end(); ++i) {
122 result = result + internal::LocalIntegral(**i, qr_selector, mf);
153template <mesh::utils::MeshFunction MF,
154 class ENTITY_PREDICATE = base::PredicateTrue>
159 std::array<quad::QuadRule, 5> qrs;
165 mesh, mf, [&](
const mesh::Entity &e) {
return qrs[e.RefEl().Id()]; }, ep,
196template <
typename SCALAR, mesh::utils::MeshFunction MF,
197 typename SELECTOR = base::PredicateTrue>
201 std::remove_reference_t<MF>>{0}),
206 mesh::utils::MeshFunctionReturnType<std::remove_reference_t<MF>>;
207 using scalar_t =
decltype(SCALAR(0) * scalarMF_t(0));
209 using dof_vec_t = Eigen::Matrix<scalar_t, Eigen::Dynamic, 1>;
217 dof_vec_t glob_dofvec(dofh.NumDofs());
218 glob_dofvec.setZero();
230 LF_ASSERT_MSG(ref_shape_fns,
"reference shape function for "
231 << ref_el <<
" not available.");
233 const Eigen::MatrixXd ref_nodes(ref_shape_fns->EvaluationNodes());
236 auto uvalvec = u(*cell, ref_nodes);
239 auto dofvec(ref_shape_fns->NodalValuesToDofs(
240 Eigen::Map<Eigen::Matrix<scalar_t, 1, Eigen::Dynamic>>(
241 &uvalvec[0], 1, uvalvec.size())));
246 const size_type num_loc_dofs = dofh.NumLocalDofs(*cell);
248 dofvec.size() == num_loc_dofs,
249 "Size mismatch: " << dofvec.size() <<
" <-> " << num_loc_dofs);
251 const std::span<const lf::assemble::gdof_idx_t> ldof_gidx(
252 dofh.GlobalDofIndices(*cell));
254 for (
int j = 0; j < num_loc_dofs; ++j) {
255 glob_dofvec[ldof_gidx[j]] = dofvec[j];
301template <
typename SCALAR,
typename EDGESELECTOR,
302 mesh::utils::MeshFunction FUNCTION>
315 std::vector<std::pair<bool, SCALAR>> flag_val_vec(num_coeffs,
323 if (esscondflag(*edge)) {
326 LF_ASSERT_MSG(fe !=
nullptr,
327 "No ScalarReferenceFiniteElement for this edge!");
328 auto ref_eval_pts = fe->EvaluationNodes();
332 auto g_vals = g(*edge, ref_eval_pts);
336 auto dof_vals = fe->NodalValuesToDofs(
337 Eigen::Map<Eigen::Matrix<SCALAR, 1, Eigen::Dynamic>>(&g_vals[0], 1,
339 LF_ASSERT_MSG(dof_vals.size() == fe->NumRefShapeFunctions(),
340 "Mismatch " << dof_vals.size() <<
" <-> "
341 << fe->NumRefShapeFunctions());
344 <<
" <-> " << dof_vals.size());
351 flag_val_vec[gdof_idx] = {
true, dof_vals[k++]};
A general (interface) class for DOF handling, see Lecture Document Paragraph 2.7.4....
virtual std::span< const gdof_idx_t > GlobalDofIndices(const lf::mesh::Entity &entity) const =0
access to indices of global dof's belonging to an entity
virtual size_type NumLocalDofs(const lf::mesh::Entity &entity) const =0
tells the number of degrees of freedom subordinate/_belonging_ to to an entity
virtual size_type NumDofs() const =0
total number of dof's handled by the object
A Function Object that can be invoked with any arguments and that always returns the value true.
Represents a reference element with all its properties.
static constexpr RefEl kSegment()
Returns the (1-dimensional) reference segment.
constexpr RefEl(RefElType type) noexcept
Create a RefEl from a lf::base::RefElType enum.
static constexpr RefEl kTria()
Returns the reference triangle.
static constexpr RefEl kQuad()
Returns the reference quadrilateral.
Space of scalar valued finite element functions on a Mesh.
virtual ScalarReferenceFiniteElement< SCALAR > const * ShapeFunctionLayout(const lf::mesh::Entity &entity) const =0
access to shape function layout for mesh entities
virtual std::shared_ptr< const lf::mesh::Mesh > Mesh() const =0
acess to underlying mesh
virtual const lf::assemble::DofHandler & LocGlobMap() const =0
access to associated local-to-global map
virtual Eigen::VectorXd IntegrationElement(const Eigen::MatrixXd &local) const =0
The integration element (factor appearing in integral transformation formula, see below) at number of...
Interface class representing a topological entity in a cellular complex
virtual const geometry::Geometry * Geometry() const =0
Describes the geometry of this entity.
Abstract interface for objects representing a single mesh.
virtual std::span< const Entity *const > Entities(unsigned codim) const =0
All entities of a given codimension.
Check if a given type T is an Eigen::Matrix.
A MeshFunction is a function object that can be evaluated at any point on the mesh.
Collects data structures and algorithms designed for scalar finite element methods primarily meant fo...
auto IntegrateMeshFunction(const lf::mesh::Mesh &mesh, const MF &mf, const QR_SELECTOR &qr_selector, const ENTITY_PREDICATE &ep=base::PredicateTrue{}, int codim=0) -> mesh::utils::MeshFunctionReturnType< MF >
Integrate a MeshFunction over a mesh (with quadrature rules)
static const unsigned int kout_l2_qr
lf::assemble::size_type size_type
std::vector< std::pair< bool, SCALAR > > InitEssentialConditionFromFunction(const lf::fe::ScalarFESpace< SCALAR > &fes, EDGESELECTOR &&esscondflag, FUNCTION const &g)
Initialization of flags/values for dofs of a Scalar finite element space whose values are imposed by ...
static const unsigned int kout_l2_rsfvals
auto NodalProjection(const lf::fe::ScalarFESpace< SCALAR > &fe_space, MF const &u, SELECTOR &&pred=base::PredicateTrue{}) -> Eigen::Vector< decltype(SCALAR{0} *mesh::utils::MeshFunctionReturnType< std::remove_reference_t< MF > >{0}), Eigen::Dynamic >
Computes nodal projection of a mesh function and returns the finite element basis expansion coefficie...
internal::VectorElement_t< internal::MeshFunctionReturnType_t< R > > MeshFunctionReturnType
Determine the type of objects returned by a MeshFunction.
QuadRule make_QuadRule(base::RefEl ref_el, unsigned degree)
Returns a QuadRule object for the given Reference Element and Degree.