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 #include <cmath>
14 
15 #pragma GCC diagnostic push
16 #pragma GCC diagnostic ignored "-Wunused-parameter"
17 #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
18 
19 using namespace dealii;
20 
21 ExactSolutionSSOLI_B::ExactSolutionSSOLI_B()
22  : Function<3>(3)
23  , B_0(2.0 * mu_0 * K_0 / 3.0)
24 {
25 }
26 
27 void
28 ExactSolutionSSOLI_B::vector_value_list(
29  const std::vector<Point<3>>& r,
30  std::vector<Vector<double>>& values) const
31 {
32  Assert(values.size() == r.size(),
33  ExcDimensionMismatch(values.size(), r.size()));
34 
35  double cos_theta;
36  double sin_theta;
37 
38  double cos_phi;
39  double sin_phi;
40 
41  Tensor<1, 3> r_hat;
42  Tensor<1, 3> theta_hat;
43 
44  Tensor<1, 3> B;
45 
46  auto v = values.begin();
47  for (auto p : r) {
48  cos_theta = p(2) / p.norm();
49  sin_theta = sqrt(pow(p(0), 2) + pow(p(1), 2)) / p.norm();
50 
51  cos_phi = p(0) / sqrt(pow(p(0), 2) + pow(p(1), 2));
52  sin_phi = p(1) / sqrt(pow(p(0), 2) + pow(p(1), 2));
53 
54  r_hat[0] = p(0) / p.norm();
55  r_hat[1] = p(1) / p.norm();
56  r_hat[2] = p(2) / p.norm();
57 
58  theta_hat[0] = cos_theta * cos_phi;
59  theta_hat[1] = cos_theta * sin_phi;
60  theta_hat[2] = -sin_theta;
61 
62  if (p.norm() < a) {
63  B = B_0 * a * (cos_theta * r_hat - sin_theta * theta_hat);
64  } else {
65  B = B_0 * (pow(a, 4) / pow(p.norm(), 3)) *
66  (cos_theta * r_hat + 0.5 * sin_theta * theta_hat);
67  }
68 
69  (*v)[0] = B[0];
70  (*v)[1] = B[1];
71  (*v)[2] = B[2];
72 
73  v++;
74  }
75 }
76 
77 #pragma GCC diagnostic pop
const double a
The radius of the coil.
Definition: settings.hpp:56