Logbook  (07-04-2025)
Static problems
exact_solution.cpp
1 /******************************************************************************
2  * Copyright (C) Siarhei Uzunbajakau, 2023.
3  *
4  * This program is free software. You can use, modify, and redistribute it under
5  * the terms of the GNU Lesser General Public License as published by the Free
6  * Software Foundation, either version 3 or (at your option) any later version.
7  * This program is distributed without any warranty.
8  *
9  * Refer to COPYING.LESSER for more details.
10  ******************************************************************************/
11 
12 #include "exact_solution.hpp"
13 
14 #pragma GCC diagnostic push
15 #pragma GCC diagnostic ignored "-Wunused-parameter"
16 
17 using namespace dealii;
18 using namespace std;
19 
20 double
21 ExactSolutionSSOLIAXI_A::value(const Point<2>& p,
22  const unsigned int component) const
23 {
24  double s = p.norm();
25  double r = p[0];
26  double M = mu_0 * K_0 * a * pow(r, 2) / 3.0;
27 
28  if (s < a) {
29  return M;
30  } else {
31  return M * pow(a, 3) / pow(s, 3);
32  }
33 }
34 
35 Tensor<1, 2>
36 ExactSolutionSSOLIAXI_A::gradient(const Point<2>& p,
37  const unsigned int component) const
38 {
39 
40  double s = p.norm();
41  double r = p[0];
42  double z = p[1];
43  double M1 = mu_0 * K_0 * a / 3.0;
44  double M2 = M1 * pow(a, 3);
45 
46  Point<2> grad_A;
47 
48  if (s < a) {
49  grad_A(0) = 2.0 * M1 * r;
50  grad_A(1) = 0.0;
51  } else {
52  grad_A(0) = M2 * (2.0 * r / pow(s, 3) - 3.0 * pow(r, 3) / pow(s, 5));
53  grad_A(1) = -M2 * (3.0 * z * pow(r, 2) / pow(s, 5));
54  }
55 
56  return grad_A;
57 }
58 
59 void
60 ExactSolutionSSOLIAXI_B::vector_value_list(
61  const std::vector<Point<2>>& r,
62  std::vector<Vector<double>>& values) const
63 {
64  double cos_theta;
65  double sin_theta;
66 
67  double cos_phi;
68  double sin_phi;
69 
70  Tensor<1, 3> r_hat;
71  Tensor<1, 3> theta_hat;
72 
73  Tensor<1, 3> B;
74 
75  auto v = values.begin();
76  for (auto pp : r) {
77  Point<3> p(0.0, pp(0), pp(1));
78 
79  cos_theta = p(2) / p.norm();
80  sin_theta = sqrt(pow(p(0), 2) + pow(p(1), 2)) / p.norm();
81 
82  cos_phi = p(0) / sqrt(pow(p(0), 2) + pow(p(1), 2));
83  sin_phi = p(1) / sqrt(pow(p(0), 2) + pow(p(1), 2));
84 
85  r_hat[0] = p(0) / p.norm();
86  r_hat[1] = p(1) / p.norm();
87  r_hat[2] = p(2) / p.norm();
88 
89  theta_hat[0] = cos_theta * cos_phi;
90  theta_hat[1] = cos_theta * sin_phi;
91  theta_hat[2] = -sin_theta;
92 
93  if (p.norm() < a) {
94  B = B_0 * a * (cos_theta * r_hat - sin_theta * theta_hat);
95  } else {
96  B = B_0 * (pow(a, 4) / pow(p.norm(), 3)) *
97  (cos_theta * r_hat + 0.5 * sin_theta * theta_hat);
98  }
99 
100  (*v)[0] = pp[0] * B[1];
101  (*v)[1] = pp[0] * B[2];
102 
103  v++;
104  }
105 }
106 
107 #pragma GCC diagnostic pop