LehrFEM++ 1.0.0
A simple Finite Element Library for teaching
product_element_matrix_provider.h
1#ifndef PROJECTS_DPG_PRODUCT_ELEMENT_MATRIX_PROVIDER
2#define PROJECTS_DPG_PRODUCT_ELEMENT_MATRIX_PROVIDER
3
13#include <lf/base/base.h>
14#include <lf/quad/quad.h>
15#include <lf/uscalfe/uscalfe.h>
16
17#include <iostream>
18#include <vector>
19
20#include "dpg.h"
21#include "product_fe_space.h"
22#include "sub_element_matrix_provider.h"
23
24namespace projects::dpg {
25
59template <typename SCALAR>
61 public:
66
70 default;
72 delete;
74 delete;
75
87 std::shared_ptr<ProductUniformFESpace<SCALAR>> fe_space_trial,
88 std::shared_ptr<ProductUniformFESpace<SCALAR>> fe_space_test,
89 std::vector<std::shared_ptr<SubElementMatrixProvider<SCALAR>>>
90 subproviders)
91 : fe_space_trial_(std::move(fe_space_trial)),
92 fe_space_test_(std::move(fe_space_test)),
93 subproviders_(std::move(subproviders)) {}
94
101 virtual bool isActive(const lf::mesh::Entity& /*cell*/) { return true; }
102
109 ElemMat Eval(const lf::mesh::Entity& cell);
110
112 virtual ~ProductElementMatrixProvider() = default;
113
114 private:
116 std::shared_ptr<ProductUniformFESpace<SCALAR>> fe_space_trial_;
118 std::shared_ptr<ProductUniformFESpace<SCALAR>> fe_space_test_;
121 std::vector<std::shared_ptr<SubElementMatrixProvider<SCALAR>>> subproviders_;
122};
123
124// template deduction hint
125template <typename ptr, typename vector>
126ProductElementMatrixProvider(ptr fe_space_tiral, ptr fe_space_test,
127 vector subproviders)
129
130// evaluation method
131template <typename SCALAR>
134 // retrive dofhandlers (for local assembly with the LocalStartIndex method
135 LF_ASSERT_MSG(fe_space_trial_ != nullptr && fe_space_test_ != nullptr,
136 "missing description of trial or test space");
137 const ProductUniformFEDofHandler& dof_h_trial{fe_space_trial_->LocGlobMap()};
138 const ProductUniformFEDofHandler& dof_h_test{fe_space_test_->LocGlobMap()};
139
140 // initialize the element matrix:
141 elem_mat_t mat(dof_h_test.NumLocalDofs(cell), dof_h_trial.NumLocalDofs(cell));
142 mat.setZero();
143
144 // build the element matrix from the "building block" sub element matrizes
145 for (const auto& provider : subproviders_) {
146 LF_ASSERT_MSG(provider != nullptr,
147 "invalid submatrix provider, is nullptr");
148 if (provider->isActive(cell)) {
149 // extract the involved components
150 size_type trial_component = provider->TrialComponent();
151 size_type test_component = provider->TestComponent();
152 // evaluate the submatrix
153 elem_mat_t sub_mat = provider->Eval(cell);
154 // add it to the correct place in the element matrix.
155 mat.block(dof_h_test.LocalStartIndex(cell, test_component),
156 dof_h_trial.LocalStartIndex(cell, trial_component),
157 sub_mat.rows(), sub_mat.cols()) += sub_mat;
158 }
159 }
160 return mat;
161}
162
163} // namespace projects::dpg
164
165#endif // PROJECTS_DPG_PRODUCT_ELEMENT_MATRIX_PROVIDER
Interface class representing a topological entity in a cellular complex
Definition: entity.h:39
Class providing element matrices associated with bilinear forms between cartesian/product spaces.
ElemMat Eval(const lf::mesh::Entity &cell)
main routine for the computation of element matrices
std::shared_ptr< ProductUniformFESpace< SCALAR > > fe_space_test_
virtual bool isActive(const lf::mesh::Entity &)
All cells are considered active in the default implementation.
std::shared_ptr< ProductUniformFESpace< SCALAR > > fe_space_trial_
ProductElementMatrixProvider(ProductElementMatrixProvider &&) noexcept=default
typename SubElementMatrixProvider< SCALAR >::ElemMat ElemMat
typename SubElementMatrixProvider< SCALAR >::elem_mat_t elem_mat_t
internal type for element matrices
virtual ~ProductElementMatrixProvider()=default
virtual destructor
ProductElementMatrixProvider(const ProductElementMatrixProvider &)=delete
standard constructors
std::vector< std::shared_ptr< SubElementMatrixProvider< SCALAR > > > subproviders_
Dofhandler for uniform finite element spaces that discretizes a cartesian/product space.
cartesian/prodcut space of finite element functions on a hybrid 2D mesh.
Interface class providing sub element matrices associated with bilinear forms between components of C...
Eigen::Matrix< SCALAR, Eigen::Dynamic, Eigen::Dynamic > elem_mat_t
internal type for element matrices
Contains functionality for the implementation of DPG methods.
Definition: primal_dpg.h:33
lf::uscalfe::size_type size_type
Type for vector length/matrix sizes.
Definition: dpg.h:17
ProductElementMatrixProvider(ptr fe_space_tiral, ptr fe_space_test, vector subproviders) -> ProductElementMatrixProvider< typename ptr::element_type::SCALAR >