LehrFEM++ 1.0.0
A simple Finite Element Library for teaching
dirac_convergence_test.cc
1
5#include <dirac_convergence_test.h>
6
7using lf::uscalfe::operator-;
8using complex = std::complex<double>;
9
13int main(int argc, char *argv[]) {
14 if (argc != 3) {
15 std::cerr << "Usage: " << argv[0] << " max_refinement_level k" << std::endl;
16 exit(1);
17 }
18
19 double kt = 0.5;
20 double &k = kt;
21 unsigned refinement_level = atoi(argv[1]);
22 std::sscanf(argv[2], "%lf", &k);
23 std::cout << "max_refinement_level : " << refinement_level << std::endl;
24 std::cout << "k : " << k << std::endl;
25
26 // mathematica function output requries the following helpers
27 auto Power = [](complex a, complex b) -> complex { return std::pow(a, b); };
28 auto Complex = [](double a, double b) -> complex { return complex(a, b); };
29 auto Sin = [](complex a) -> complex { return std::sin(a); };
30 auto Cos = [](complex a) -> complex { return std::cos(a); };
31 auto Sqrt = [](complex a) -> complex { return std::sqrt(a); };
32
33 // righthandside for the zero and two form
34 auto f_zero = [&](const Eigen::Vector3d &x_vec) -> complex {
35 // first scale to the circle
36 Eigen::Vector3d x_ = x_vec / x_vec.norm();
37 double x = x_(0);
38 double y = x_(1);
39 double z = x_(2);
40
41 // autogenerated by mathematica
42 complex ret = Complex(0, 1) * k * (Cos(y) + Sin(x) + Sin(z)) +
43 (x * z * Cos(x) + x * y * Cos(y) + y * z * Cos(z) +
44 2 * z * Sin(x) + 2 * x * Sin(y) + 2 * y * Sin(z)) /
45 (Power(x, 2) + Power(y, 2) + Power(z, 2));
46 return ret;
47 };
48
49 // righthandside for the one form
50 auto f_one = [&](const Eigen::Vector3d &x_vec) -> Eigen::VectorXcd {
51 // first scale to the circle
52 Eigen::Vector3d x_ = x_vec / x_vec.norm();
53 double x = x_(0);
54 double y = x_(1);
55 double z = x_(2);
56
57 // autogenerated by mathematica
58 Eigen::VectorXcd ret(3);
59 ret << ((Power(y, 2) + Power(z, 2)) * Cos(x) - x * z * Cos(z) +
60 x * y * Sin(y) +
61 Sqrt(Power(x, 2) + Power(y, 2) + Power(z, 2)) *
62 (y * Cos(z) + z * Sin(y)) -
63 Complex(0, 1) * k *
64 (x * z * Sin(x) - (Power(y, 2) + Power(z, 2)) * Sin(y) +
65 x * y * Sin(z))) /
66 (Power(x, 2) + Power(y, 2) + Power(z, 2)),
67 -((x * y * Cos(x) + y * z * Cos(z) +
68 Sqrt(Power(x, 2) + Power(y, 2) + Power(z, 2)) *
69 (-(z * Cos(x)) + x * Cos(z)) +
70 (Power(x, 2) + Power(z, 2)) * Sin(y) +
71 Complex(0, 1) * k *
72 (y * z * Sin(x) + x * y * Sin(y) -
73 (Power(x, 2) + Power(z, 2)) * Sin(z))) /
74 (Power(x, 2) + Power(y, 2) + Power(z, 2))),
75 (-(x * z * Cos(x)) + (Power(x, 2) + Power(y, 2)) * Cos(z) +
76 y * z * Sin(y) -
77 Sqrt(Power(x, 2) + Power(y, 2) + Power(z, 2)) *
78 (y * Cos(x) + x * Sin(y)) +
79 Complex(0, 1) * k *
80 ((Power(x, 2) + Power(y, 2)) * Sin(x) -
81 z * (x * Sin(y) + y * Sin(z)))) /
82 (Power(x, 2) + Power(y, 2) + Power(z, 2));
83 return ret;
84 };
85
86 // righthandside for the two form
87 auto f_two = [&](const Eigen::Vector3d &x_vec) -> complex {
88 // first scale to the circle
89 Eigen::Vector3d x_ = x_vec / x_vec.norm();
90 double x = x_(0);
91 double y = x_(1);
92 double z = x_(2);
93
94 // autogenerated by mathematica
95 complex ret = (y * Cos(x) + z * Cos(y) + x * Cos(z)) /
96 Sqrt(Power(x, 2) + Power(y, 2) + Power(z, 2)) +
97 Complex(0, 1) * k * (Cos(y) + Sin(x) + Sin(z));
98 return ret;
99 };
100
102 f_two, k);
103
104 test.Compute(refinement_level);
105
106 return 0;
107}
Class to test the convergence of the Dirac operator.