10#ifndef PROJECTS_DPG_CS_PRIMAL_DPG_H
11#define PROJECTS_DPG_CS_PRIMAL_DPG_H
13#include <lf/base/base.h>
16#include <lf/mesh/test_utils/test_meshes.h>
17#include <lf/mesh/utils/utils.h>
18#include <lf/refinement/refinement.h>
19#include <lf/uscalfe/uscalfe.h>
21#include "../dpg_element_matrix_provider.h"
22#include "../dpg_element_vector_provider.h"
23#include "../product_element_matrix_provider_builder.h"
24#include "../product_element_vector_provider_builder.h"
25#include "../product_fe_space.h"
26#include "../product_fe_space_factory.h"
27#include "../test/convection_diffusion_ell_bvp.h"
31using energy_vector = std::vector<std::tuple<int, double, double>>;
56template <
typename SOLFUNC,
typename SOLGRAD,
typename ALPHAFUNC,
57 typename BETAFUNC,
typename FFUNC,
typename GFUNC>
59 size_type reflevels, SOLFUNC solution, SOLGRAD sol_grad, ALPHAFUNC alpha,
60 BETAFUNC beta, FFUNC f, GFUNC g,
int degree_p,
int enrichement,
62 std::vector<std::tuple<int, double, double>> errnorms{};
63 std::cout <<
"Approximation order: " << degree_p
64 <<
", Enrichement: " << enrichement << std::endl;
67 int degree_r = degree_p + enrichement;
70 std::shared_ptr<lf::mesh::Mesh> top_mesh;
71 std::unique_ptr<lf::mesh::MeshFactory> mesh_factory_ptr =
72 std::make_unique<lf::mesh::hybrid2d::MeshFactory>(2);
78 .setTopRightCorner(Eigen::Vector2d{1.0, 1.0})
81 top_mesh = builder.
Build();
88 .setTopRightCorner(Eigen::Vector2d{1.0, 1.0})
91 top_mesh = builder.
Build();
95 LF_ASSERT_MSG(
false,
"unsupported reference element:" << ref_el);
101 std::shared_ptr<lf::refinement::MeshHierarchy> multi_mesh_p =
113 std::shared_ptr<const lf::mesh::Mesh> mesh_p{multi_mesh.getMesh(l)};
119 auto fe_space_trial = factory_trial.
Build();
124 auto fe_space_test = factory_test.
Build();
141 auto stiffness_provider = stiffness_builder.
Build();
148 auto gramian_provider = gramian_builder.
Build();
153 auto rhs_provider = rhs_builder.
Build();
156 auto element_matrix_provider =
157 std::make_shared<DpgElementMatrixProvider<double>>(stiffness_provider,
159 auto element_vector_provider =
160 std::make_shared<DpgElementVectorProvider<double>>(
161 rhs_provider, stiffness_provider, gramian_provider);
164 auto h = [](
const Eigen::Vector2d & ) ->
double {
return 0.0; };
166 auto bvp = std::make_shared<FullConvectionDiffusionBVP<
167 decltype(alpha),
decltype(beta),
decltype(f),
decltype(g),
decltype(h),
168 decltype(dirichlet_selector)>>(
169 FullConvectionDiffusionBVP(alpha, beta, f, g, h,
170 std::move(dirichlet_selector)));
173 auto [A, phi] = ConvectionDiffusionDPGLinSys<double>(
174 fe_space_trial, element_matrix_provider, element_vector_provider, bvp,
178 Eigen::SimplicialLDLT<Eigen::SparseMatrix<double>> solver;
180 Eigen::VectorXd sol_vec = solver.solve(phi);
183 auto& dofh = fe_space_trial->LocGlobMap();
184 auto fe_space_u = fe_space_trial->ComponentFESpace(u);
185 Eigen::VectorXd sol_vec_u = sol_vec.head(dofh.NumDofs(u));
196 lf::mesh::utils::squaredNorm(mf_fe_u - mf_solution) +
197 lf::mesh::utils::squaredNorm(mf_fe_grad_u - mf_solution_grad),
203 gramian_provider, rhs_provider, sol_vec);
205 std::cout <<
"Level " << l <<
" ( " << dofh.NumDofs() <<
")"
206 <<
", H1 error: " << H1_err <<
", post:" << posteriorError
208 errnorms.emplace_back(dofh.NumDofs(), H1_err, posteriorError);
Represents a reference element with all its properties.
static constexpr RefEl kTria()
Returns the reference triangle.
static constexpr RefEl kQuad()
Returns the reference quadrilateral.
A MeshFunction which takes the same constant value on the whole mesh.
MeshFunction wrapper for a simple function of physical coordinates.
StructuredMeshBuilder & setBottomLeftCorner(const VECTOR &blc)
StructuredMeshBuilder & setNumYCells(size_type nyc)
Implements a Builder for a tensor product grid (with rectangular cells)
std::shared_ptr< mesh::Mesh > Build() override
actual construction of the mesh
Implements a MeshBuilder that generates a triangular structured mesh.
std::shared_ptr< mesh::Mesh > Build() override
actual construction of the mesh
A hierarchy of nested 2D hybrid meshes created by refinement.
std::ostream & PrintInfo(std::ostream &o, unsigned ctrl=0) const
Output of information about the mesh hierarchy.
Builder class to build a ProductElementMatrixProvider.
ProductElementMatrixProviderBuilder & AddReactionElementMatrixProvider(size_type trial_component, size_type test_component, REACTION_COEFF gamma)
std::shared_ptr< ProductElementMatrixProvider< SCALAR > > Build()
Build the ProdcutElementMatrixProvider for the bilinear form based on the provided bilinear forms .
ProductElementMatrixProviderBuilder & AddFluxElementMatrixProvider(size_type trial_component, size_type test_component, DIFF_COEFF alpha)
ProductElementMatrixProviderBuilder & AddConvectionElementMatrixProvider(size_type trial_component, size_type test_component, CONVECTION_COEFF_1 beta_1, CONVECTION_COEFF_2 beta_2)
ProductElementMatrixProviderBuilder & AddDiffusionElementMatrixProvider(size_type trial_component, size_type test_component, DIFF_COEFF alpha)
Builder class to build a ProductElementVectorProvider.
ProductElementVectorProviderBuilder & AddLoadElementVectorProvider(size_type test_component, FUNCTOR f)
Adds a linear form to representing a simple load linear form.
std::shared_ptr< ProductElementVectorProvider< SCALAR > > Build()
Build the ProductElementVectorProvider based on the provided linear forms.
MeshFunctionGradFE(std::shared_ptr< T >, const Eigen::Matrix< SCALAR_COEFF, Eigen::Dynamic, 1 > &) -> MeshFunctionGradFE< typename T::Scalar, SCALAR_COEFF >
MeshFunctionFE(std::shared_ptr< T >, const Eigen::Matrix< SCALAR_COEFF, Eigen::Dynamic, 1 > &) -> MeshFunctionFE< typename T::Scalar, SCALAR_COEFF >
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)
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
std::shared_ptr< MeshHierarchy > GenerateMeshHierarchyByUniformRefinemnt(const std::shared_ptr< lf::mesh::Mesh > &mesh_p, lf::base::size_type ref_lev, RefPat ref_pat)
Generated a sequence of nested 2D hybrid mehes by regular or barycentric refinement.
energy_vector TestConververgencePrimalDPGConvectionDiffusionDirichletBVP(size_type reflevels, SOLFUNC solution, SOLGRAD sol_grad, ALPHAFUNC alpha, BETAFUNC beta, FFUNC f, GFUNC g, int degree_p, int enrichement, lf::base::RefEl ref_el)
Examines the convergence behaviour of the primal DPG method for a pure Dirichlet convection-diffusion...
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::uscalfe::size_type size_type
Type for vector length/matrix sizes.