LehrFEM++ 1.0.0
A simple Finite Element Library for teaching
hodge_laplacian_constant.cc
1
8#include <hodge_laplacian_experiment.h>
9
19int main(int argc, char *argv[]) {
20 if (argc != 4 && argc != 5) {
21 std::cerr << "Usage: " << argv[0]
22 << " max_refinement_level min_k max_k step=0.1 " << std::endl;
23 exit(1);
24 }
25
26 double min_k;
27 double max_k;
28 double step = 0.1;
29 const unsigned refinement_level = atoi(argv[1]);
30 sscanf(argv[2], "%lf", &min_k);
31 sscanf(argv[3], "%lf", &max_k);
32 if (argc == 5) sscanf(argv[4], "%lf", &step);
33 std::cout << "max_refinement_level : " << refinement_level << std::endl;
34 std::cout << "min_k : " << min_k << ", max_k = " << max_k
35 << " step = " << step << std::endl;
36
37 // needs to be a reference such that it can be reassigned
38 double &k = min_k;
39
40 std::vector<unsigned> refinement_levels(refinement_level + 1);
41 for (int i = 0; i < refinement_level + 1; i++) {
42 refinement_levels[i] = i;
43 }
44
45 std::vector<double> ks;
46 for (double i = min_k; i <= max_k; i += step) {
47 ks.push_back(i);
48 }
49
50 // mathematica function output requries the following helpers auto Power =
51 // [](double a, double b) -> double { return std::pow(a, b); };
52 auto Sin = [](double a) -> double { return std::sin(a); };
53 auto Cos = [](double a) -> double { return std::cos(a); };
54 auto Sqrt = [](double a) -> double { return std::sqrt(a); };
55 auto Power = [](double a, double b) -> double { return std::pow(a, b); };
56
57 double r = 1.;
58
59 // righthandside for the zero and two form
60 auto f_zero = [&](const Eigen::Vector3d &x_vec) -> double {
61 return k * k * 5.2;
62 };
63
64 // righthandside for the one form
65 auto f_one = [&](const Eigen::Vector3d &x_vec) -> Eigen::VectorXd {
66 // first scale to the sphere
67 Eigen::Vector3d x_ = x_vec / x_vec.norm();
68 double x = x_(0);
69 double y = x_(1);
70 double z = x_(2);
71
72 Eigen::VectorXd ret(3);
73
74 ret << -(Power(k, 2) * y) -
75 (2 * y) / (Power(x, 2) + Power(y, 2) + Power(z, 2)),
76 x * (Power(k, 2) + 2 / (Power(x, 2) + Power(y, 2) + Power(z, 2))), 0;
77 return ret;
78 };
79
80 // Compute the analytic solution of the problem
81 auto u_zero = [&](const Eigen::Vector3d x_vec) -> double { return 5.2; };
82
83 // Compute the analytic solution of the problem
84 auto u_one = [&](const Eigen::Vector3d x_vec) -> Eigen::Vector3d {
85 // first scale to the sphere
86 Eigen::Vector3d x_ = x_vec / x_vec.norm();
87 double x = x_(0);
88 double y = x_(1);
89 double z = x_(2);
90
91 Eigen::VectorXd ret(3);
92
93 ret << -y, x, 0;
94
95 return ret;
96 };
97
99 experiment(u_zero, u_one, u_zero, f_zero, f_one, f_zero, k, "constant");
100
101 experiment.Compute(refinement_levels, ks);
102
103 return 0;
104}
Creates and solves the discretised Hodge Laplacian source problems for a given list of levels and val...