LehrFEM++ 1.0.0
A simple Finite Element Library for teaching
dirac_operator_debug_only_two.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 = 0;
66 return ret;
67 };
68
69 // righthandside for the one form
70 auto f_one = [&](const Eigen::Vector3d &x_vec) -> Eigen::VectorXcd {
71 // first scale to the circle
72 Eigen::Vector3d x_ = x_vec;
73 double x = x_(0);
74 double y = x_(1);
75 double z = x_(2);
76
77 // autogenerated by mathematica
78 Eigen::VectorXcd ret(3);
79 ret << (y * Cos(z) + z * Sin(y)) /
80 Sqrt(Power(x, 2) + Power(y, 2) + Power(z, 2)),
81 (z * Cos(x) - x * Cos(z)) /
82 Sqrt(Power(x, 2) + Power(y, 2) + Power(z, 2)),
83 -((y * Cos(x) + x * Sin(y)) /
84 Sqrt(Power(x, 2) + Power(y, 2) + Power(z, 2)));
85 return ret;
86 };
87
88 // righthandside for the two form
89 auto f_two = [&](const Eigen::Vector3d &x_vec) -> complex {
90 // first scale to the circle
91 Eigen::Vector3d x_ = x_vec;
92 double x = x_(0);
93 double y = x_(1);
94 double z = x_(2);
95
96 // autogenerated by mathematica
97 complex ret = Complex(0, 1) * k * (Cos(y) + Sin(x) + Sin(z));
98 return ret;
99 };
100
101 // Compute the analytic solution of the problem
102 auto u_zero = [&](const Eigen::Vector3d x_vec) -> complex {
103 // first scale to the circle
104 Eigen::Vector3d x_ = x_vec;
105 double x = x_(0);
106 double y = x_(1);
107 double z = x_(2);
108
109 return 0;
110 };
111
112 // Compute the analytic solution of the problem
113 auto u_one = [&](const Eigen::Vector3d x_vec) -> Eigen::Vector3cd {
114 // first scale to the circle
115 Eigen::Vector3d x_ = x_vec;
116 double x = x_(0);
117 double y = x_(1);
118 double z = x_(2);
119
120 Eigen::VectorXcd ret(3);
121
122 // autogenerated by mathematica
123 ret << 0, 0, 0;
124 return ret;
125 };
126
127 // Compute the analytic solution of the problem
128 auto u_two = [&](const Eigen::Vector3d x_vec) -> complex {
129 // first scale to the circle
130 Eigen::Vector3d x_ = x_vec;
131 double x = x_(0);
132 double y = x_(1);
133 double z = x_(2);
134
135 // mathematica autocompute
136 return Sin(x) + Cos(y) + Sin(z);
137 };
138
140 u_zero, u_one, u_two, f_zero, f_one, f_two, k, "debug_only_two");
141
142 experiment.Compute(refinement_levels, ks);
143
144 return 0;
145}
Creates and solves the discretised Dirac Operator source problems for a given list of levels and valu...