LehrFEM++ 1.0.0
A simple Finite Element Library for teaching
dirac_operator_debug_only_one.cc
1
9#include <dirac_operator_experiment.h>
10
11using lf::uscalfe::operator-;
12using complex = std::complex<double>;
13
18int main(int argc, char *argv[]) {
19 if (argc != 4 && argc != 5) {
20 std::cerr << "Usage: " << argv[0]
21 << " max_refinement_level min_k max_k step=0.1 " << std::endl;
22 exit(1);
23 }
24
25 double min_k;
26 double max_k;
27 double step = 0.1;
28 const unsigned refinement_level = atoi(argv[1]);
29 sscanf(argv[2], "%lf", &min_k);
30 sscanf(argv[3], "%lf", &max_k);
31 if (argc == 5) sscanf(argv[4], "%lf", &step);
32 std::cout << "max_refinement_level : " << refinement_level << std::endl;
33 std::cout << "min_k : " << min_k << ", max_k = " << max_k
34 << " step = " << step << std::endl;
35
36 // needs to be a reference such that it can be reassigned
37 double &k = min_k;
38
39 std::vector<unsigned> refinement_levels(refinement_level + 1);
40 for (int i = 0; i < refinement_level + 1; i++) {
41 refinement_levels[i] = i;
42 }
43
44 std::vector<double> ks;
45 for (double i = min_k; i <= max_k; i += step) {
46 ks.push_back(i);
47 }
48
49 // mathematica function output requries the following helpers
50 auto Power = [](complex a, complex b) -> complex { return std::pow(a, b); };
51 auto Complex = [](double a, double b) -> complex { return complex(a, b); };
52 auto Sin = [](complex a) -> complex { return std::sin(a); };
53 auto Cos = [](complex a) -> complex { return std::cos(a); };
54 auto Sqrt = [](complex a) -> complex { return std::sqrt(a); };
55
56 // righthandside for the zero and two form
57 auto f_zero = [&](const Eigen::Vector3d &x_vec) -> complex {
58 // first scale to the circle
59 Eigen::Vector3d x_ = x_vec;
60 double x = x_(0);
61 double y = x_(1);
62 double z = x_(2);
63
64 // autogenerated by mathematica
65 complex ret = (x * z * Cos(x) + x * y * Cos(y) + y * z * Cos(z) +
66 2 * z * Sin(x) + 2 * x * Sin(y) + 2 * y * Sin(z)) /
67 (Power(x, 2) + Power(y, 2) + Power(z, 2));
68 return ret;
69 };
70
71 // righthandside for the one form
72 auto f_one = [&](const Eigen::Vector3d &x_vec) -> Eigen::VectorXcd {
73 // first scale to the circle
74 Eigen::Vector3d x_ = x_vec;
75 double x = x_(0);
76 double y = x_(1);
77 double z = x_(2);
78
79 // autogenerated by mathematica
80 Eigen::VectorXcd ret(3);
81 ret << (Complex(0, 1) * k *
82 (-(x * z * Sin(x)) + (Power(y, 2) + Power(z, 2)) * Sin(y) -
83 x * y * Sin(z))) /
84 (Power(x, 2) + Power(y, 2) + Power(z, 2)),
85 (Complex(0, 1) * k *
86 (-(y * z * Sin(x)) - x * y * Sin(y) +
87 (Power(x, 2) + Power(z, 2)) * Sin(z))) /
88 (Power(x, 2) + Power(y, 2) + Power(z, 2)),
89 (Complex(0, 1) * k *
90 ((Power(x, 2) + Power(y, 2)) * Sin(x) -
91 z * (x * Sin(y) + y * Sin(z)))) /
92 (Power(x, 2) + Power(y, 2) + Power(z, 2));
93 return ret;
94 };
95
96 // righthandside for the two form
97 auto f_two = [&](const Eigen::Vector3d &x_vec) -> complex {
98 // first scale to the circle
99 Eigen::Vector3d x_ = x_vec;
100 double x = x_(0);
101 double y = x_(1);
102 double z = x_(2);
103
104 // autogenerated by mathematica
105 complex ret = (y * Cos(x) + z * Cos(y) + x * Cos(z)) /
106 Sqrt(Power(x, 2) + Power(y, 2) + Power(z, 2));
107 return ret;
108 };
109
110 // Compute the analytic solution of the problem
111 auto u_zero = [&](const Eigen::Vector3d x_vec) -> complex {
112 // first scale to the circle
113 Eigen::Vector3d x_ = x_vec;
114 double x = x_(0);
115 double y = x_(1);
116 double z = x_(2);
117
118 return 0;
119 };
120
121 // Compute the analytic solution of the problem
122 auto u_one = [&](const Eigen::Vector3d x_vec) -> Eigen::Vector3cd {
123 // first scale to the circle
124 Eigen::Vector3d x_ = x_vec;
125 double x = x_(0);
126 double y = x_(1);
127 double z = x_(2);
128
129 Eigen::VectorXcd ret(3);
130
131 // autogenerated by mathematica
132 ret << (-(x * z * Sin(x)) + (Power(y, 2) + Power(z, 2)) * Sin(y) -
133 x * y * Sin(z)) /
134 (Power(x, 2) + Power(y, 2) + Power(z, 2)),
135 (-(y * z * Sin(x)) - x * y * Sin(y) +
136 (Power(x, 2) + Power(z, 2)) * Sin(z)) /
137 (Power(x, 2) + Power(y, 2) + Power(z, 2)),
138 ((Power(x, 2) + Power(y, 2)) * Sin(x) - z * (x * Sin(y) + y * Sin(z))) /
139 (Power(x, 2) + Power(y, 2) + Power(z, 2));
140 return ret;
141 };
142
143 // Compute the analytic solution of the problem
144 auto u_two = [&](const Eigen::Vector3d x_vec) -> complex {
145 // first scale to the circle
146 Eigen::Vector3d x_ = x_vec;
147 double x = x_(0);
148 double y = x_(1);
149 double z = x_(2);
150
151 return 0;
152 };
153
155 u_zero, u_one, u_two, f_zero, f_one, f_two, k, "debug_only_one");
156
157 experiment.Compute(refinement_levels, ks);
158
159 return 0;
160}
Creates and solves the discretised Dirac Operator source problems for a given list of levels and valu...