17#include "strangsplitting.h"
22double getMeshSize(
const std::shared_ptr<const lf::mesh::Mesh> &mesh_p) {
23 double mesh_size = 0.0;
29 edge_length = (endpoints.col(0) - endpoints.col(1)).norm();
30 if (mesh_size < edge_length) {
31 mesh_size = edge_length;
37int main(
int ,
char ** ) {
39 auto c = [](
const Eigen::Vector2d & ) ->
double {
return 1.2; };
44 auto mesh_factory = std::make_unique<lf::mesh::hybrid2d::MeshFactory>(2);
45 std::filesystem::path here = __FILE__;
46 auto mesh_file = (here.parent_path() /
"/meshes/test4.msh").
string();
48 std::shared_ptr<lf::mesh::Mesh> mesh_p = reader.mesh();
51 std::shared_ptr<lf::uscalfe::UniformScalarFESpace<double>> fe_space =
52 std::make_shared<lf::uscalfe::FeSpaceLagrangeO1<double>>(mesh_p);
57 std::cout <<
"Num of dofs " << N_dofs << std::endl;
60 Eigen::VectorXd u0(N_dofs);
68 auto boundary_nodes = [&bd_flags, &dofh](
unsigned int idx) ->
bool {
69 return bd_flags(dofh.Entity(idx));
75 return bd_flags_edge(edge);
81 auto h = [fe_space, mesh_p, edge_pred](
const Eigen::Vector2d &x) ->
double {
84 auto g = [&x](
const Eigen::Vector2d &y) ->
double {
86 if ((x - y).norm() >= 15 && (x - y).norm() <= 35) {
104 Eigen::MatrixXd L(N_dofs, N_dofs);
105 for (
int j = 0; j < N_dofs; j++) {
106 if (boundary_nodes(j)) {
107 auto L_j = [fe_space, &dofh, N_dofs, edge_pred,
108 j](
const Eigen::Vector2d &x) ->
double {
109 auto g_j = [&x](
const Eigen::Vector2d &y) ->
double {
110 double tmp_res = 0.0;
111 if ((x - y).norm() >= 15 && (x - y).norm() <= 35) {
117 Eigen::VectorXd L1(N_dofs);
123 edgeVec_y(fe_space, mf_g, edge_pred);
129 Eigen::VectorXd L2(N_dofs);
135 edgeVec_x(fe_space, mf_L, edge_pred);
142 L.col(j) = Eigen::VectorXd::Zero(N_dofs);
152 Eigen::VectorXd numSteps(6);
154 Eigen::VectorXd tau(6);
158 for (
int i = 0; i < 6; i++) {
159 numSteps(i) = 80 * std::pow(2, i);
160 tau(i) = T / numSteps(i);
164 Eigen::VectorXd cap(N_dofs);
166 cap = 0.8 * Eigen::VectorXd::Ones(N_dofs);
168 StrangSplit StrangSplitter1(fe_space, T, numSteps(0), lambda, c, h, L);
169 StrangSplit StrangSplitter2(fe_space, T, numSteps(1), lambda, c, h, L);
170 StrangSplit StrangSplitter3(fe_space, T, numSteps(2), lambda, c, h, L);
171 StrangSplit StrangSplitter4(fe_space, T, numSteps(3), lambda, c, h, L);
172 StrangSplit StrangSplitter5(fe_space, T, numSteps(4), lambda, c, h, L);
173 StrangSplit StrangSplitter6(fe_space, T, numSteps(5), lambda, c, h, L);
175 Eigen::VectorXd sol1(N_dofs);
177 sol1 = StrangSplitter1.Evolution(cap, u0);
178 std::cout <<
"sol1 " << std::endl;
180 Eigen::VectorXd sol2(N_dofs);
182 sol2 = StrangSplitter2.Evolution(cap, u0);
183 std::cout <<
"sol2 " << std::endl;
185 Eigen::VectorXd sol3(N_dofs);
187 sol3 = StrangSplitter3.Evolution(cap, u0);
188 std::cout <<
"sol3 " << std::endl;
190 Eigen::VectorXd sol4(N_dofs);
192 sol4 = StrangSplitter4.Evolution(cap, u0);
193 std::cout <<
"sol4 " << std::endl;
195 Eigen::VectorXd sol5(N_dofs);
197 sol5 = StrangSplitter5.Evolution(cap, u0);
198 std::cout <<
"sol5 " << std::endl;
200 Eigen::VectorXd sol6(N_dofs);
202 sol6 = StrangSplitter6.Evolution(cap, u0);
203 std::cout <<
"sol6 " << std::endl;
205 Eigen::VectorXd eL2(5);
207 eL2(0) = (sol6 - sol1).lpNorm<2>();
208 eL2(1) = (sol6 - sol2).lpNorm<2>();
209 eL2(2) = (sol6 - sol3).lpNorm<2>();
210 eL2(3) = (sol6 - sol4).lpNorm<2>();
211 eL2(4) = (sol6 - sol5).lpNorm<2>();
212 std::cout <<
"errors computed" << std::endl;
214 for (
int l = 0; l < 6; l++) {
216 std::cout <<
"errorL2 solcol0 for l = " << l <<
" : " << eL2(l)
220 std::cout <<
"number of timesteps for l = " << l <<
" : " << numSteps(l)
222 std::cout <<
"tau for l = " << l <<
" : " << tau(l) << std::endl;
226 const static Eigen::IOFormat CSVFormat(Eigen::StreamPrecision,
227 Eigen::DontAlignCols,
", ",
"\n");
231 file.open(
"eL2.csv");
232 file << eL2.format(CSVFormat);
235 file.open(
"tau.csv");
236 file << tau.format(CSVFormat);
239 file.open(
"numSteps.csv");
240 file << numSteps.format(CSVFormat);
243 file.open(
"sol1.csv");
244 file << sol1.format(CSVFormat);
247 file.open(
"sol2.csv");
248 file << sol2.format(CSVFormat);
251 file.open(
"sol3.csv");
252 file << sol3.format(CSVFormat);
255 file.open(
"sol4.csv");
256 file << sol4.format(CSVFormat);
259 file.open(
"sol5.csv");
260 file << sol5.format(CSVFormat);
263 file.open(
"sol6.csv");
264 file << sol6.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.
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.
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)
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