1#include "dirac_convergence_test.h"
20 std::vector<std::shared_ptr<const lf::mesh::Mesh>> meshs =
21 std::vector<std::shared_ptr<const lf::mesh::Mesh>>(refinement_levels);
31 std::unique_ptr<lf::mesh::MeshFactory> factory =
32 std::make_unique<lf::mesh::hybrid2d::MeshFactory>(3);
41 std::chrono::steady_clock::time_point start_time_total =
42 std::chrono::steady_clock::now();
45 solutions.
mu_zero.resize(refinement_levels);
46 solutions.
mu_one.resize(refinement_levels);
47 solutions.
mu_two.resize(refinement_levels);
49 for (
unsigned il = 0; il < refinement_levels; ++il) {
50 std::cout <<
"\nStart computation of refinement_level " << il << std::flush;
53 std::chrono::steady_clock::time_point start_time =
54 std::chrono::steady_clock::now();
58 const std::shared_ptr<lf::mesh::Mesh> mesh = sphere.
Build();
62 std::chrono::steady_clock::time_point end_time =
63 std::chrono::steady_clock::now();
64 double elapsed_sec = std::chrono::duration_cast<std::chrono::milliseconds>(
65 end_time - start_time)
69 std::cout <<
" -> Built Mesh " << elapsed_sec <<
" [s] " << std::flush;
72 lse_builder.SetMesh(mesh);
75 start_time = std::chrono::steady_clock::now();
78 lse_builder.Compute();
81 end_time = std::chrono::steady_clock::now();
82 elapsed_sec = std::chrono::duration_cast<std::chrono::milliseconds>(
83 end_time - start_time)
87 std::cout <<
" -> Computed LSE " << elapsed_sec <<
" [s] " << std::flush;
90 start_time = std::chrono::steady_clock::now();
96 end_time = std::chrono::steady_clock::now();
98 elapsed_sec = std::chrono::duration_cast<std::chrono::milliseconds>(
99 end_time - start_time)
103 std::cout <<
" -> Solved System " << elapsed_sec <<
" [s] " << std::flush;
106 solutions.
mu_zero[il] = lse_builder.GetMu(0);
107 solutions.
mu_one[il] = lse_builder.GetMu(1);
108 solutions.
mu_two[il] = lse_builder.GetMu(2);
112 std::chrono::steady_clock::time_point end_time_total =
113 std::chrono::steady_clock::now();
114 double elapsed_sec_total =
115 std::chrono::duration_cast<std::chrono::milliseconds>(end_time_total -
120 std::cout <<
"\nTotal computation time for all levels " << elapsed_sec_total
129 std::string main_dir =
"results";
130 std::filesystem::create_directory(main_dir);
133 int table_width = 13;
137 std::ofstream csv_file;
138 std::string csv_name =
concat(
"result_dirac_convergence_", refinement_levels);
139 std::replace(csv_name.begin(), csv_name.end(),
'.',
'_');
140 csv_file.open(
concat(main_dir,
"/", csv_name,
".csv"));
141 csv_file <<
"numCells,"
147 auto square_scalar = [](
complex a) ->
double {
148 return std::abs(a) * std::abs(a);
151 [](Eigen::Matrix<complex, Eigen::Dynamic, 1> a) ->
double {
152 return a.squaredNorm();
158 Eigen::VectorXd L2ErrorZero = Eigen::VectorXd::Zero(refinement_levels);
159 Eigen::VectorXd L2ErrorOne = Eigen::VectorXd::Zero(refinement_levels);
160 Eigen::VectorXd L2ErrorTwo = Eigen::VectorXd::Zero(refinement_levels);
161 Eigen::VectorXd hMax = Eigen::VectorXd::Zero(refinement_levels);
164 csv_file <<
",L2ErrorZero,DiffOfL2Zero,L2ErrorOne,DiffOfL2One,"
165 "L2ErrorTwo,DiffOfL2Two";
166 csv_file << std::endl;
171 auto &sol_mesh = meshs[lvl];
176 if (h > hMax(lvl)) hMax(lvl) = h;
180 csv_file << sol_mesh->NumEntities(0) <<
"," << sol_mesh->NumEntities(1)
181 <<
"," << sol_mesh->NumEntities(2) <<
"," << hMax(lvl);
184 solutions.
mu_zero[lvl], sol_mesh);
186 solutions.
mu_one[lvl], sol_mesh);
188 solutions.
mu_two[lvl], sol_mesh);
191 const std::pair<double, lf::mesh::utils::CodimMeshDataSet<double>> L2_zero =
194 L2ErrorZero(lvl) = std::get<0>(L2_zero);
197 const std::pair<double, lf::mesh::utils::CodimMeshDataSet<double>> L2_one =
200 L2ErrorOne(lvl) = std::get<0>(L2_one);
203 const std::pair<double, lf::mesh::utils::CodimMeshDataSet<double>> L2_two =
206 L2ErrorTwo(lvl) = std::get<0>(L2_two);
208 double l2RateZero = 0;
209 double l2RateOne = 0;
210 double l2RateTwo = 0;
214 l2RateZero = abs(L2ErrorZero(lvl) - L2ErrorZero(lvl - 1));
215 l2RateOne = abs(L2ErrorOne(lvl) - L2ErrorOne(lvl - 1));
216 l2RateTwo = abs(L2ErrorTwo(lvl) - L2ErrorTwo(lvl - 1));
223 csv_file <<
"," << L2ErrorZero(lvl) <<
"," << l2RateZero <<
","
224 << L2ErrorOne(lvl) <<
"," << l2RateOne <<
"," << L2ErrorTwo(lvl)
static constexpr RefEl kTria()
Returns the reference triangle.
Interface class representing a topological entity in a cellular complex
Represents a Quadrature Rule over one of the Reference Elements.
std::function< complex(const Eigen::Matrix< double, 3, 1 > &)> f_zero_
std::function< Eigen::Matrix< complex, 3, 1 >(const Eigen::Matrix< double, 3, 1 > &)> f_one_
std::function< complex(const Eigen::Matrix< double, 3, 1 > &)> f_two_
void Compute(unsigned refinement_levels)
Solves the dirac opeartor source problems up to the given refinement_level.
A mesh builder for regular 3-Sphere.
void setRefinementLevel(lf::base::size_type n)
Set the refinement level.
void setRadius(double r)
Sets the radius.
std::shared_ptr< lf::mesh::Mesh > Build()
Build the mesh.
Computes the Galerkin LSE for the Dirac Operator source problem.
void SetLoadFunctions(std::function< complex(const Eigen::Matrix< double, 3, 1 > &)> f0, std::function< Eigen::Matrix< complex, 3, 1 >(const Eigen::Matrix< double, 3, 1 > &)> f1, std::function< complex(const Eigen::Matrix< double, 3, 1 > &)> f2)
Sets the load functions.
Provides Mesh Function for given basis expansion coefficients.
Provides Mesh Function for Whitney two basis expansion coefficients.
Provides Mesh Function for basis expansion coefficients of the zero form.
unsigned int size_type
general type for variables related to size of arrays
double Volume(const Geometry &geo)
Compute the (approximate) volume (area) of a shape.
QuadRule make_QuadRule(base::RefEl ref_el, unsigned degree)
Returns a QuadRule object for the given Reference Element and Degree.
static std::string concat(Args &&...args)
Concatenate objects defining an operator<<(std::ostream&)
std::complex< double > complex
std::pair< double, lf::mesh::utils::CodimMeshDataSet< double > > L2norm(const std::shared_ptr< const lf::mesh::Mesh > &mesh_p, const MF &f, const SQ_F &sq_f, const lf::quad::QuadRule &quadrule)
Computes the L2Norm of some MeshFunction (type MF) f.
Implementation of the thesis Hogde Laplacians and Dirac Operators on the surface of the 3-Sphere.
stores solutions for a number of refinement levels
std::vector< Eigen::Matrix< complex, Eigen::Dynamic, 1 > > mu_one
std::vector< Eigen::Matrix< complex, Eigen::Dynamic, 1 > > mu_zero
std::vector< Eigen::Matrix< complex, Eigen::Dynamic, 1 > > mu_two