1#ifndef PROJECTS_DPG_DPG_TOOLS_H
2#define PROJECTS_DPG_DPG_TOOLS_H
13#include <lf/base/base.h>
15#include <lf/geometry/geometry.h>
16#include <lf/mesh/mesh.h>
17#include <lf/mesh/utils/utils.h>
18#include <lf/quad/quad.h>
24#include "product_dofhandler.h"
25#include "product_element_matrix_provider.h"
26#include "product_element_vector_provider.h"
27#include "product_fe_space.h"
99 std::shared_ptr<const
lf::mesh::Mesh> mesh_ptr)
102 lf::mesh::utils::make_CodimMeshDataSet(
mesh_ptr_, 1, -1))) {
154template <
typename CONVECTION_COEFF>
156 const std::shared_ptr<const lf::mesh::Mesh>& mesh_p,
157 CONVECTION_COEFF beta) {
165 for (
const auto*
const cell : mesh_p->Entities(0)) {
167 auto geo_ptr = cell->Geometry();
168 auto sub_entities = cell->SubEntities(1);
174 for (
int i = 0; i < cell->RefEl().NumSubEntities(1); ++i) {
175 const auto*
const edge = sub_entities[i];
178 bool inflow = normals.col(i).transpose() *
179 beta(*(sub_entities[i]),
180 (Eigen::MatrixXd(1, 1) << 0.5).finished())[0] <
182 inflow_boundary(*edge) = bd_flags(*edge) && inflow;
185 return inflow_boundary;
203template <
typename CONVECTION_COEFF>
205 const std::shared_ptr<const lf::mesh::Mesh>& mesh_p,
206 CONVECTION_COEFF beta) {
219 for (
const auto*
const edge : mesh_p->Entities(1)) {
220 outflow_boundary(*edge) = bd_flags(*edge) && (!inflow_boundary(*edge));
222 return outflow_boundary;
269template <
typename SCALAR,
typename EDGESELECTOR_DIRICHLET,
270 typename EDGESELECTOR_NEUMANN,
typename FUNCTION_G,
274 size_type flux_component, EDGESELECTOR_DIRICHLET&& dirichletcondflag,
275 EDGESELECTOR_NEUMANN&& neumanncondflag, FUNCTION_G&& g, FUNCTION_H&& h) {
277 LF_ASSERT_MSG(trace_component != flux_component,
278 "Boundary conditions imposed on same component");
285 std::vector<std::pair<bool, SCALAR>> componentTraceConditions =
288 std::vector<std::pair<bool, SCALAR>> componentFluxConditions =
296 std::vector<std::pair<bool, SCALAR>> EssentialConditions(
300 for (size_type dof = 0; dof < trace_fes->LocGlobMap().NumDofs(); dof++) {
301 EssentialConditions[trace_offset + dof] = componentTraceConditions[dof];
305 for (size_type dof = 0; dof < flux_fes->LocGlobMap().NumDofs(); dof++) {
306 EssentialConditions[flux_offset + dof] = componentFluxConditions[dof];
309 return EssentialConditions;
326template <
typename SCALAR>
333 const Eigen::Matrix<SCALAR, Eigen::Dynamic, 1>& sol_vec) {
335 auto mesh_p = trial_dofh.
Mesh();
341 for (
const auto*
const cell : mesh_p->Entities(0)) {
343 auto G = gramian_provider->Eval(*cell);
344 auto B = stiffness_provider->Eval(*cell);
345 auto l = load_provider->Eval(*cell);
348 Eigen::Matrix<SCALAR, Eigen::Dynamic, 1> local_solution(
352 local_solution(i) = sol_vec(global_dofs[i]);
356 Eigen::Matrix<SCALAR, Eigen::Dynamic, 1> r = l - B * local_solution;
358 SCALAR e = std::sqrt(r.transpose() * G.ldlt().solve(r));
359 element_errors(*cell) = e;
361 return element_errors;
373template <
typename SCALAR>
375 const std::shared_ptr<const lf::mesh::Mesh>& mesh_p,
378 for (
const auto*
const cell : mesh_p->Entities(0)) {
379 error += local_errors(*cell) * local_errors(*cell);
381 return std::sqrt(error);
Represents a reference element with all its properties.
Interface class for shape information on a mesh cell in the spirit of parametric finite element metho...
Interface class representing a topological entity in a cellular complex
A MeshDataSet that attaches data of type T to every entity of a mesh that has a specified codimension...
Represents a Quadrature Rule over one of the Reference Elements.
Class which allows evaluation of the function.
PrescribedSignProvider()=default
int PrescribedSign(const lf::mesh::Entity &element, const lf::mesh::Entity &edge) const
evaluates the the function at the midpoint of the edge of cell
std::shared_ptr< const lf::mesh::Mesh > mesh_ptr_
PrescribedSignProvider(PrescribedSignProvider &&) noexcept=default
std::shared_ptr< lf::mesh::utils::CodimMeshDataSet< int > > maxElement_ptr_
PrescribedSignProvider(const PrescribedSignProvider &)=delete
Class providing element matrices associated with bilinear forms between cartesian/product spaces.
Class providing element vectors associated with linear forms on cartesian/product spaces.
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 ...
CodimMeshDataSet< bool > flagEntitiesOnBoundary(const std::shared_ptr< const Mesh > &mesh_p, lf::base::dim_t codim)
flag entities of a specific co-dimension located on the boundary
Contains functionality for the implementation of DPG methods.
std::vector< lf::quad::QuadRule > BoundaryQuadRule(lf::base::RefEl ref_el, const lf::quad::QuadRule &qr)
Constructs a quadrature rule on the boundary of a reference element.
lf::mesh::utils::CodimMeshDataSet< bool > flagEntitiesOnOutflowBoundary(const std::shared_ptr< const lf::mesh::Mesh > &mesh_p, CONVECTION_COEFF beta)
flag all edges located on the outflow boundary
lf::mesh::utils::CodimMeshDataSet< SCALAR > ElementErrorEstimators(const ProductUniformFEDofHandler &trial_dofh, std::shared_ptr< ProductElementMatrixProvider< SCALAR > > stiffness_provider, std::shared_ptr< ProductElementMatrixProvider< SCALAR > > gramian_provider, std::shared_ptr< ProductElementVectorProvider< SCALAR > > load_provider, const Eigen::Matrix< SCALAR, Eigen::Dynamic, 1 > &sol_vec)
Evaluation of the local DPG error estimators on a mesh.
SCALAR EvalPosteriorError(const std::shared_ptr< const lf::mesh::Mesh > &mesh_p, const lf::mesh::utils::CodimMeshDataSet< SCALAR > &local_errors)
Evaluation of the DPG error estimator.
lf::mesh::utils::CodimMeshDataSet< bool > flagEntitiesOnInflowBoundary(const std::shared_ptr< const lf::mesh::Mesh > &mesh_p, CONVECTION_COEFF beta)
flag all edges located on the inflow boundary
std::vector< std::pair< bool, SCALAR > > InitEssentialConditionsFromFunctions(const ProductUniformFESpace< SCALAR > &fes, size_type trace_component, size_type flux_component, EDGESELECTOR_DIRICHLET &&dirichletcondflag, EDGESELECTOR_NEUMANN &&neumanncondflag, FUNCTION_G &&g, FUNCTION_H &&h)
Initialization of flags/values for dofs of fluxes and traces of a on a product finite element space w...
lf::uscalfe::size_type size_type
Type for vector length/matrix sizes.
Eigen::MatrixXd OuterNormals(const lf::geometry::Geometry &geometry)
Compute the outer normals of a geometry object.