8#include <lf/assemble/dofhandler.h>
11#include <lf/mesh/hybrid2d/hybrid2d.h>
12#include <lf/mesh/utils/utils.h>
13#include <lf/refinement/mesh_function_transfer.h>
14#include <lf/refinement/mesh_hierarchy.h>
15#include <lf/refinement/refinement.h>
16#include <lf/uscalfe/uscalfe.h>
25#include "strangsplitting.h"
30double getMeshSize(
const std::shared_ptr<const lf::mesh::Mesh> &mesh_p) {
31 double mesh_size = 0.0;
37 edge_length = (endpoints.col(0) - endpoints.col(1)).norm();
38 if (mesh_size < edge_length) {
39 mesh_size = edge_length;
45int main(
int ,
char ** ) {
47 std::unique_ptr<lf::mesh::hybrid2d::MeshFactory> mesh_factory =
48 std::make_unique<lf::mesh::hybrid2d::MeshFactory>(2);
49 std::filesystem::path here = __FILE__;
50 auto mesh_file = (here.parent_path() /
"/meshes/test1.msh").
string();
52 std::shared_ptr<lf::mesh::Mesh> mesh_p = reader.mesh();
54 std::unique_ptr<lf::mesh::hybrid2d::MeshFactory> mesh_factory2 =
55 std::make_unique<lf::mesh::hybrid2d::MeshFactory>(2);
58 std::shared_ptr<lf::uscalfe::UniformScalarFESpace<double>> fe_space_fine;
60 Eigen::VectorXd numDofs(5);
62 Eigen::VectorXd meshsizes(5);
65 Eigen::VectorXd mu1(39);
67 Eigen::VectorXd mu2(125);
69 Eigen::VectorXd mu3(444);
71 Eigen::VectorXd mu4(1670);
73 Eigen::VectorXd mu5(6474);
76 Eigen::VectorXd mu1_ipol(39);
78 Eigen::VectorXd mu2_ipol(125);
80 Eigen::VectorXd mu3_ipol(444);
82 Eigen::VectorXd mu4_ipol(1670);
86 auto c = [](
const Eigen::Vector2d & ) ->
double {
return 1.2; };
94 hierarchy.RefineRegular();
95 hierarchy.RefineRegular();
96 hierarchy.RefineRegular();
97 hierarchy.RefineRegular();
99 for (
int l = 4; l >= 0; l--) {
100 mesh_p = hierarchy.getMesh(l);
103 std::shared_ptr<lf::uscalfe::UniformScalarFESpace<double>> fe_space =
104 std::make_shared<lf::uscalfe::FeSpaceLagrangeO1<double>>(mesh_p);
110 meshsizes(l) = getMeshSize(mesh_p);
112 std::cout <<
"Num of Dofs " << N_dofs << std::endl;
115 Eigen::VectorXd u0(N_dofs);
134 auto boundary_nodes = [&bd_flags, &dofh](
unsigned int idx) ->
bool {
135 return bd_flags(dofh.Entity(idx));
141 return bd_flags_edge(edge);
147 auto h = [fe_space, mesh_p, edge_pred](
const Eigen::Vector2d &x) ->
double {
150 auto g = [&x](
const Eigen::Vector2d &y) ->
double {
151 double tmp_res = 0.0;
152 if ((x - y).norm() >= 15 && (x - y).norm() <= 35) {
172 Eigen::MatrixXd L(N_dofs, N_dofs);
173 for (
int j = 0; j < N_dofs; j++) {
174 if (boundary_nodes(j)) {
175 auto L_j = [fe_space, &dofh, N_dofs, edge_pred,
176 j](
const Eigen::Vector2d &x) ->
double {
177 auto g_j = [&x](
const Eigen::Vector2d &y) ->
double {
178 double tmp_res = 0.0;
179 if ((x - y).norm() >= 15 && (x - y).norm() <= 35) {
185 Eigen::VectorXd L1(N_dofs);
191 edgeVec_y(fe_space, mf_g, edge_pred);
197 Eigen::VectorXd L2(N_dofs);
203 edgeVec_x(fe_space, mf_L, edge_pred);
210 L.col(j) = Eigen::VectorXd::Zero(N_dofs);
213 std::cout <<
"L norm " << L.norm() << std::endl;
221 StrangSplit StrangSplitter(fe_space, T, m, lambda, c, h, L);
224 Eigen::VectorXd cap(N_dofs);
226 cap = 0.8 * Eigen::VectorXd::Ones(N_dofs);
228 Eigen::VectorXd sol(N_dofs);
229 sol = StrangSplitter.Evolution(cap, u0);
261 fe_space_fine = fe_space;
268 eL2(0) = (mu1_ipol - mu5).lpNorm<2>();
269 eL2(1) = (mu2_ipol - mu5).lpNorm<2>();
270 eL2(2) = (mu3_ipol - mu5).lpNorm<2>();
271 eL2(3) = (mu4_ipol - mu5).lpNorm<2>();
273 for (
int l = 0; l < 4; l++) {
274 std::cout <<
"numdofs for l = " << l <<
" : " << numDofs(l) << std::endl;
275 std::cout <<
"meshsize for l = " << l <<
" : " << meshsizes(l) << std::endl;
277 std::cout <<
"L2 error of solution with respect to reference solution on "
278 "finest mesh, for l = "
279 << l <<
" : " << eL2(l) << std::endl;
283 const static Eigen::IOFormat CSVFormat(Eigen::StreamPrecision,
284 Eigen::DontAlignCols,
", ",
"\n");
288 file.open(
"errorL2.csv");
289 file << eL2.format(CSVFormat);
292 file.open(
"NumDofs.csv");
293 file << numDofs.format(CSVFormat);
296 file.open(
"meshsizes.csv");
297 file << meshsizes.format(CSVFormat);
301 file.open(
"mu1.csv");
302 file << mu1.format(CSVFormat);
305 file.open(
"mu2.csv");
306 file << mu2.format(CSVFormat);
309 file.open(
"mu3.csv");
310 file << mu3.format(CSVFormat);
313 file.open(
"mu4.csv");
314 file << mu4.format(CSVFormat);
317 file.open(
"mu5.csv");
318 file << mu5.format(CSVFormat);
322 file.open(
"mu1_ipol.csv");
323 file << mu1_ipol.format(CSVFormat);
326 file.open(
"mu2_ipol.csv");
327 file << mu2_ipol.format(CSVFormat);
330 file.open(
"mu3_ipol.csv");
331 file << mu3_ipol.format(CSVFormat);
334 file.open(
"mu4_ipol.csv");
335 file << mu4_ipol.format(CSVFormat);
A general (interface) class for DOF handling, see Lecture Document Paragraph 2.7.4....
static constexpr RefEl kSegment()
Returns the (1-dimensional) reference segment.
static constexpr RefEl kTria()
Returns the reference triangle.
A MeshFunction representing an element from a ScalarUniformFESpace (e.g. solution of BVP)
Reads a Gmsh *.msh file into a mesh::MeshFactory and provides a link between mesh::Entity objects and...
Interface class representing a topological entity in a cellular complex
MeshFunction wrapper for a simple function of physical coordinates.
auto squaredNorm(const A &a)
Pointwise squared norm of another mesh function.
A MeshFunction representing interpolation on a lf::refinement::MeshHierarchy.
A hierarchy of nested 2D hybrid meshes created by refinement.
Local edge contributions to element vector.
void AssembleVectorLocally(dim_t codim, const DofHandler &dof_handler, ENTITY_VECTOR_PROVIDER &entity_vector_provider, VECTOR &resultvector)
entity-local assembly of (right-hand-side) vectors from element vectors
QuadRule make_TriaQR_EdgeMidpointRule()
edge midpoint quadrature rule for reference triangles
auto localQuadFunction(const lf::mesh::Mesh &mesh, std::map< lf::base::RefEl, lf::quad::QuadRule > quadrules, FUNCTOR &&f, unsigned int codim, const std::function< bool(const lf::mesh::Entity &)> &pred)
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...
Eigen::MatrixXd Corners(const Geometry &geo)
The corners of a shape with piecewise smooth boundary.
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
QuadRule make_QuadRule(base::RefEl ref_el, unsigned degree)
Returns a QuadRule object for the given Reference Element and Degree.
lf::assemble::size_type size_type