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);
52 if constexpr (base::is_eigen_matrix<MfType>) {
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];
107template <
class MF,
class QR_SELECTOR,
109 class = std::enable_if_t<
110 std::is_invocable_v<QR_SELECTOR, const mesh::Entity &>>>
112 const QR_SELECTOR &qr_selector,
116 static_assert(mesh::utils::isMeshFunction<MF>);
119 auto entities = mesh.
Entities(codim);
120 auto result = internal::LocalIntegral(**entities.begin(), qr_selector, mf);
121 for (
const auto *i = entities.begin() + 1; i != entities.end(); ++i) {
125 result = result + internal::LocalIntegral(**i, qr_selector, mf);
156template <
class MF,
class ENTITY_PREDICATE = base::PredicateTrue>
161 std::array<quad::QuadRule, 5> qrs;
167 mesh, mf, [&](
const mesh::Entity &e) {
return qrs[e.RefEl().Id()]; }, ep,
198template <
typename SCALAR,
typename MF,
typename SELECTOR = base::PredicateTrue>
201 static_assert(mesh::utils::isMeshFunction<std::remove_reference_t<MF>>);
206 using scalar_t =
decltype(SCALAR(0) * scalarMF_t(0));
208 using dof_vec_t = Eigen::Matrix<scalar_t, Eigen::Dynamic, 1>;
216 dof_vec_t glob_dofvec(dofh.NumDofs());
217 glob_dofvec.setZero();
229 LF_ASSERT_MSG(ref_shape_fns,
"reference shape function for "
230 << ref_el <<
" not available.");
232 const Eigen::MatrixXd ref_nodes(ref_shape_fns->EvaluationNodes());
235 auto uvalvec = u(*cell, ref_nodes);
238 auto dofvec(ref_shape_fns->NodalValuesToDofs(
239 Eigen::Map<Eigen::Matrix<scalar_t, 1, Eigen::Dynamic>>(
240 &uvalvec[0], 1, uvalvec.size())));
245 const size_type num_loc_dofs = dofh.NumLocalDofs(*cell);
247 dofvec.size() == num_loc_dofs,
248 "Size mismatch: " << dofvec.size() <<
" <-> " << num_loc_dofs);
251 dofh.GlobalDofIndices(*cell));
253 for (
int j = 0; j < num_loc_dofs; ++j) {
254 glob_dofvec[ldof_gidx[j]] = dofvec[j];
300template <
typename SCALAR,
typename EDGE
SELECTOR,
typename FUNCTION>
304 static_assert(mesh::utils::isMeshFunction<std::remove_reference_t<FUNCTION>>);
314 std::vector<std::pair<bool, SCALAR>> flag_val_vec(num_coeffs,
322 if (esscondflag(*edge)) {
325 LF_ASSERT_MSG(fe !=
nullptr,
326 "No ScalarReferenceFiniteElement for this edge!");
327 auto ref_eval_pts = fe->EvaluationNodes();
331 auto g_vals = g(*edge, ref_eval_pts);
335 auto dof_vals = fe->NodalValuesToDofs(
336 Eigen::Map<Eigen::Matrix<SCALAR, 1, Eigen::Dynamic>>(&g_vals[0], 1,
338 LF_ASSERT_MSG(dof_vals.size() == fe->NumRefShapeFunctions(),
339 "Mismatch " << dof_vals.size() <<
" <-> "
340 << fe->NumRefShapeFunctions());
343 <<
" <-> " << dof_vals.size());
350 flag_val_vec[gdof_idx] = {
true, dof_vals[k++]};
A general (interface) class for DOF handling, see Lecture Document Paragraph 2.7.4....
virtual nonstd::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 hybrid 2D 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 nonstd::span< const Entity *const > Entities(unsigned codim) const =0
All entities of a given codimension.
Collects data structures and algorithms designed for scalar finite element methods primarily meant fo...
std::vector< std::pair< bool, SCALAR > > InitEssentialConditionFromFunction(const lf::fe::ScalarFESpace< SCALAR > &fes, EDGESELECTOR &&esscondflag, FUNCTION &&g)
Initialization of flags/values for dofs of a Scalar finite element space whose values are imposed by ...
auto NodalProjection(const lf::fe::ScalarFESpace< SCALAR > &fe_space, MF &&u, SELECTOR &&pred=base::PredicateTrue{})
Computes nodal projection of a mesh function and returns the finite element basis expansion coefficie...
static const unsigned int kout_l2_qr
lf::assemble::size_type size_type
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_rsfvals
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.