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 template<>
21 double
22 ExactSolutionMMSAXI_PHI<2>::value(const Point<2>& p,
23  unsigned int component) const
24 {
25  return (cos(k * p[0]) + cos(k * p[1]));
26 }
27 
28 template<>
29 Tensor<1, 2>
30 ExactSolutionMMSAXI_PHI<2>::gradient(const Point<2>& p,
31  unsigned int component) const
32 {
33  Tensor<1, 2> g;
34 
35  g[0] = -k * sin(k * p[0]);
36  g[1] = -k * sin(k * p[1]);
37 
38  return g;
39 }
40 
41 template<>
42 double
43 ExactSolutionMMSAXI_PHI<3>::value(const Point<3>& p,
44  unsigned int componet) const
45 {
46  double r = sqrt(pow(p[0], 2) + pow(p[1], 2));
47 
48  return (cos(k * r) + cos(k * p[2]));
49 }
50 
51 template<>
52 Tensor<1, 3>
53 ExactSolutionMMSAXI_PHI<3>::gradient(const Point<3>& p,
54  unsigned int component) const
55 {
56  Tensor<1, 3> g;
57 
58  double r = sqrt(pow(p[0], 2) + pow(p[1], 2));
59 
60  if (r < eps) {
61  g[0] = 0.0;
62  g[1] = 0.0;
63  } else {
64  double cos_phi = p[0] / r;
65  double sin_phi = p[1] / r;
66  g[0] = -k * cos_phi * sin(k * r);
67  g[1] = -k * sin_phi * sin(k * r);
68  }
69 
70  g[2] = -k * sin(k * p[2]);
71 
72  return g;
73 }
74 
75 template<>
76 void
78  const std::vector<Point<2>>& p,
79  std::vector<Vector<double>>& values) const
80 {
81  Assert(values.size() == p.size(),
82  ExcDimensionMismatch(values.size(), p.size()));
83 
84  auto v = values.begin();
85  for (auto q : p) {
86  (*v)(0) = k * sin(k * q[0]);
87  (*v)(1) = k * sin(k * q[1]);
88  v++;
89  }
90 }
91 
92 template<>
93 void
95  const std::vector<Point<3>>& p,
96  std::vector<Vector<double>>& values) const
97 {
98  Assert(values.size() == p.size(),
99  ExcDimensionMismatch(values.size(), p.size()));
100 
101  double r;
102  double cos_phi;
103  double sin_phi;
104 
105  auto v = values.begin();
106 
107  for (auto q : p) {
108  r = sqrt(pow(q[0], 2) + pow(q[1], 2));
109 
110  if (r < eps) {
111  (*v)(0) = 0.0;
112  (*v)(1) = 0.0;
113  } else {
114  cos_phi = q[0] / r;
115  sin_phi = q[1] / r;
116  (*v)(0) = k * cos_phi * sin(k * r);
117  (*v)(1) = k * sin_phi * sin(k * r);
118  }
119 
120  (*v)(2) = k * sin(k * q[2]);
121 
122  v++;
123  }
124 }
125 
126 template<>
127 void
129  const std::vector<Point<2>>& p,
130  std::vector<Vector<double>>& values) const
131 {
132  Assert(values.size() == p.size(),
133  ExcDimensionMismatch(values.size(), p.size()));
134 
135  double epsilon;
136 
137  auto v = values.begin();
138  for (auto q : p) {
139  epsilon = ep_0 * (q[0] * pow(q[1], 2) + 1.0);
140  (*v)(0) = epsilon * k * sin(k * q[0]);
141  (*v)(1) = epsilon * k * sin(k * q[1]);
142  v++;
143  }
144 }
145 
146 template<>
147 void
149  const std::vector<Point<3>>& p,
150  std::vector<Vector<double>>& values) const
151 {
152  Assert(values.size() == p.size(),
153  ExcDimensionMismatch(values.size(), p.size()));
154 
155  double r;
156  double epsilon;
157  double cos_phi;
158  double sin_phi;
159 
160  auto v = values.begin();
161  for (auto q : p) {
162  r = sqrt(pow(q[0], 2) + pow(q[1], 2));
163  epsilon = ep_0 * (r * pow(q[2], 2) + 1.0);
164 
165  if (r < eps) {
166  (*v)(0) = 0.0;
167  (*v)(1) = 0.0;
168  } else {
169  cos_phi = q[0] / r;
170  sin_phi = q[1] / r;
171  (*v)(0) = epsilon * k * cos_phi * sin(k * r);
172  (*v)(1) = epsilon * k * sin_phi * sin(k * r);
173  }
174 
175  (*v)(2) = epsilon * k * sin(k * q[2]);
176 
177  v++;
178  }
179 }
180 #pragma GCC diagnostic pop
Describes the exact solution, , of the Axisymmetric - method of manufactured solutions (mms-axi/) num...
Describes the exact solution, , of the Axisymmetric - method of manufactured solutions (mms-axi/) num...
Describes the exact solution, , of the Axisymmetric - method of manufactured solutions (mms-axi/) num...