9#ifndef PROJECTS_DPG_CS_PRIMAL_DPG_AN_H
10#define PROJECTS_DPG_CS_PRIMAL_DPG_AN_H
12#include <lf/base/base.h>
15#include <lf/mesh/test_utils/test_meshes.h>
16#include <lf/mesh/utils/utils.h>
17#include <lf/refinement/refinement.h>
18#include <lf/uscalfe/uscalfe.h>
20#include "../dpg_element_matrix_provider.h"
21#include "../dpg_element_vector_provider.h"
22#include "../product_element_matrix_provider_builder.h"
23#include "../product_element_vector_provider_builder.h"
24#include "../product_fe_space.h"
25#include "../product_fe_space_factory.h"
26#include "../test/convection_diffusion_ell_bvp.h"
30using energy_vector = std::vector<std::tuple<int, double, double>>;
54template <
typename SOLFUNC,
typename SOLGRAD,
typename ALPHAFUNC,
55 typename BETAFUNC,
typename FFUNC,
typename GFUNC>
58 size_type reflevels, SOLFUNC solution, SOLGRAD sol_grad, ALPHAFUNC alpha,
59 BETAFUNC beta, FFUNC f, GFUNC g,
int degree_p,
int enrichement,
61 std::vector<std::tuple<int, double, double>> errnorms{};
62 std::cout <<
"Approximation order: " << degree_p
63 <<
", Enrichement: " << enrichement << std::endl;
66 int degree_r = degree_p + enrichement;
69 std::shared_ptr<lf::mesh::Mesh> top_mesh;
70 std::unique_ptr<lf::mesh::MeshFactory> mesh_factory_ptr =
71 std::make_unique<lf::mesh::hybrid2d::MeshFactory>(2);
77 .setTopRightCorner(Eigen::Vector2d{1.0, 1.0})
80 top_mesh = builder.
Build();
87 .setTopRightCorner(Eigen::Vector2d{1.0, 1.0})
90 top_mesh = builder.
Build();
94 LF_ASSERT_MSG(
false,
"unsupported reference element:" << ref_el);
100 std::shared_ptr<lf::refinement::MeshHierarchy> multi_mesh_p =
112 std::shared_ptr<const lf::mesh::Mesh> mesh_p{multi_mesh.getMesh(l)};
118 auto fe_space_trial = factory_trial.
Build();
123 auto fe_space_test = factory_test.
Build();
140 auto stiffness_provider = stiffness_builder.
Build();
144 [alpha](
const Eigen::Vector2d& x) {
return alpha(x) * alpha(x); });
147 gramian_builder.AddDiffusionElementMatrixProvider(v, v, alpha_squared_mf);
148 gramian_builder.AddReactionElementMatrixProvider(v, v, one_mf);
149 auto gramian_provider = gramian_builder.Build();
154 auto rhs_provider = rhs_builder.
Build();
157 auto element_matrix_provider =
158 std::make_shared<DpgElementMatrixProvider<double>>(stiffness_provider,
160 auto element_vector_provider =
161 std::make_shared<DpgElementVectorProvider<double>>(
162 rhs_provider, stiffness_provider, gramian_provider);
165 auto h = [](
const Eigen::Vector2d & ) ->
double {
return 0.0; };
167 auto bvp = std::make_shared<FullConvectionDiffusionBVP<
168 decltype(alpha),
decltype(beta),
decltype(f),
decltype(g),
decltype(h),
169 decltype(dirichlet_selector)>>(
170 FullConvectionDiffusionBVP(alpha, beta, f, g, h,
171 std::move(dirichlet_selector)));
174 auto [A, phi] = ConvectionDiffusionDPGLinSys<double>(
175 fe_space_trial, element_matrix_provider, element_vector_provider, bvp,
179 Eigen::SimplicialLDLT<Eigen::SparseMatrix<double>> solver;
181 Eigen::VectorXd sol_vec = solver.solve(phi);
184 auto& dofh = fe_space_trial->LocGlobMap();
185 auto fe_space_u = fe_space_trial->ComponentFESpace(u);
186 Eigen::VectorXd sol_vec_u = sol_vec.head(dofh.NumDofs(u));
197 lf::mesh::utils::squaredNorm(mf_fe_u - mf_solution) +
198 lf::mesh::utils::squaredNorm(mf_fe_grad_u - mf_solution_grad),
204 gramian_provider, rhs_provider, sol_vec);
206 std::cout <<
"Level " << l <<
" ( " << dofh.NumDofs() <<
")"
207 <<
", H1 error: " << H1_err <<
", post:" << posteriorError
209 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.
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 TestConververgencePrimalDPGAdaptedNormConvectionDiffusionDirichletBVP(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.