Logbook  (07-04-2025)
Static problems
static_scalar_input.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 #define BOOST_ALLOW_DEPRECATED_HEADERS
13 
14 #include "static_scalar_input.hpp"
15 #include <math.h>
16 
17 using namespace StaticScalarSolver;
18 using namespace std;
19 
20 #pragma GCC diagnostic push
21 #pragma GCC diagnostic ignored "-Wunused-parameter"
22 
23 template<>
24 void
25 TheCoefficient<2>::value_list(const std::vector<Point<2>>& r,
26  types::material_id mid,
27  unsigned int cuid,
28  std::vector<double>& values) const
29 {
30  Assert(r.size() == values.size(),
31  ExcDimensionMismatch(r.size(), values.size()));
32 
33  auto v = values.begin();
34  for (auto p : r) {
35  *v = ep_0 * (p[0] * pow(p[1], 2) + 1.0);
36  v++;
37  }
38 }
39 
40 template<>
41 void
42 TheCoefficient<3>::value_list(const std::vector<Point<3>>& rr,
43  types::material_id mid,
44  unsigned int cuid,
45  std::vector<double>& values) const
46 {
47  Assert(rr.size() == values.size(),
48  ExcDimensionMismatch(rr.size(), values.size()));
49 
50  auto v = values.begin();
51  for (auto p : rr) {
52  double r = sqrt(pow(p[0], 2.0) + pow(p[1], 2.0));
53  *v = ep_0 * (r * pow(p[2], 2.0) + 1.0);
54  v++;
55  }
56 }
57 
58 template<>
59 void
60 PdeRhs<2>::value_list(const std::vector<Point<2>>& r,
61  types::material_id mid,
62  unsigned int cuid,
63  std::vector<double>& values) const
64 {
65  Assert(r.size() == values.size(),
66  ExcDimensionMismatch(r.size(), values.size()));
67 
68  auto v = values.begin();
69  for (auto p : r) {
70  *v = ep_0 * k *
71  ((2.0 * pow(p[1], 2) + (1.0 / p[0])) * sin(k * p[0]) +
72  k * (p[0] * pow(p[1], 2) + 1.0) * cos(k * p[0]) +
73  (2.0 * p[0] * p[1]) * sin(k * p[1]) +
74  k * (p[0] * pow(p[1], 2) + 1.0) * cos(k * p[1]));
75  v++;
76  }
77 }
78 
79 template<>
80 void
81 PdeRhs<3>::value_list(const std::vector<Point<3>>& rr,
82  types::material_id mid,
83  unsigned int cuid,
84  std::vector<double>& values) const
85 {
86  Assert(rr.size() == values.size(),
87  ExcDimensionMismatch(rr.size(), values.size()));
88 
89  auto v = values.begin();
90  for (auto p : rr) {
91  double r = sqrt(pow(p[0], 2) + pow(p[1], 2));
92 
93  *v = ep_0 * k *
94  ((1.0 / r) * (2.0 * r * pow(p[2], 2.0) + 1.0) * sin(k * r) +
95  k * (r * pow(p[2], 2.0) + 1.0) * cos(k * r) +
96  (2.0 * r * p[2]) * sin(k * p[2]) +
97  k * (r * pow(p[2], 2.0) + 1.0) * cos(k * p[2]));
98  v++;
99  }
100 }
101 
102 template<>
103 void
104 PdeRhsCvp<2>::value_list(const std::vector<Point<2>>& r,
105  types::material_id mid,
106  unsigned int cuid,
107  std::vector<Tensor<1, 2>>& values) const
108 {
109  Assert(r.size() == values.size(),
110  ExcDimensionMismatch(r.size(), values.size()));
111 
112  for (unsigned int i = 0; i < values.size(); i++) {
113  values[i][0] = 0.0;
114  values[i][1] = 0.0;
115  }
116 }
117 
118 template<>
119 void
120 PdeRhsCvp<3>::value_list(const std::vector<Point<3>>& r,
121  types::material_id mid,
122  unsigned int cuid,
123  std::vector<Tensor<1, 3>>& values) const
124 {
125  Assert(r.size() == values.size(),
126  ExcDimensionMismatch(r.size(), values.size()));
127 
128  for (unsigned int i = 0; i < values.size(); i++) {
129  values[i][0] = 0.0;
130  values[i][1] = 0.0;
131  values[i][2] = 0.0;
132  }
133 }
134 
135 template<>
136 void
137 Gamma<2>::value_list(const std::vector<Point<2>>& r,
138  const std::vector<Tensor<1, 2>>& n,
139  types::boundary_id bid,
140  types::material_id mid,
141  unsigned int cuid,
142  unsigned int fuid,
143  std::vector<double>& values) const
144 {
145  Assert(r.size() == values.size(),
146  ExcDimensionMismatch(r.size(), values.size()));
147 
148  auto v = values.begin();
149  for (auto p : r) {
150  *v = ep_0 * (sqrt(pow(p[0], 2) + pow(p[1], 2)) + 2.0);
151  v++;
152  }
153 }
154 
155 template<>
156 void
157 Gamma<3>::value_list(const std::vector<Point<3>>& r,
158  const std::vector<Tensor<1, 3>>& n,
159  types::boundary_id bid,
160  types::material_id mid,
161  unsigned int cuid,
162  unsigned int fuid,
163  std::vector<double>& values) const
164 {
165  Assert(r.size() == values.size(),
166  ExcDimensionMismatch(r.size(), values.size()));
167 
168  auto v = values.begin();
169  for (auto p : r) {
170  double r = sqrt(pow(p[0], 2) + pow(p[1], 2));
171 
172  *v = ep_0 * (sqrt(pow(r, 2) + pow(p[2], 2)) + 2.0);
173  v++;
174  }
175 }
176 
177 template<>
178 void
179 RobinRhs<2>::value_list(const std::vector<Point<2>>& r,
180  const std::vector<Tensor<1, 2>>& n,
181  types::boundary_id bid,
182  types::material_id mid,
183  unsigned int cuid,
184  unsigned int fuid,
185  std::vector<double>& values) const
186 {
187 
188  Assert(r.size() == values.size(),
189  ExcDimensionMismatch(r.size(), values.size()));
190 
191  double epsilon;
192  double gamma;
193  double phi;
194  Tensor<1, 2> grad_phi;
195 
196  auto v = values.begin();
197  auto nn = n.begin();
198  for (auto p : r) {
199  epsilon = ep_0 * (p[0] * pow(p[1], 2) + 1.0);
200  phi = cos(k * p[0]) + cos(k * p[1]);
201 
202  grad_phi[0] = -k * sin(k * p[0]);
203  grad_phi[1] = -k * sin(k * p[0]);
204 
205  gamma = ep_0 * (sqrt(pow(p[0], 2) + pow(p[1], 2)) + 2.0);
206 
207  *v = epsilon * (*nn * grad_phi) + gamma * phi;
208  v++;
209  nn++;
210  }
211 }
212 
213 template<>
214 void
215 RobinRhs<3>::value_list(const std::vector<Point<3>>& rr,
216  const std::vector<Tensor<1, 3>>& n,
217  types::boundary_id bid,
218  types::material_id mid,
219  unsigned int cuid,
220  unsigned int fuid,
221  std::vector<double>& values) const
222 {
223 
224  Assert(rr.size() == values.size(),
225  ExcDimensionMismatch(rr.size(), values.size()));
226 
227  double epsilon;
228  double gamma;
229  double phi;
230  Tensor<1, 3> grad_phi;
231 
232  auto v = values.begin();
233  auto nn = n.begin();
234  for (auto p : rr) {
235  double r = sqrt(pow(p[0], 2) + pow(p[1], 2));
236  double cos_phi = p[0] / sqrt(pow(p[0], 2) + pow(p[1], 2));
237  double sin_phi = p[1] / sqrt(pow(p[0], 2) + pow(p[1], 2));
238 
239  epsilon = ep_0 * (r * pow(p[2], 2.0) + 1.0);
240 
241  phi = cos(k * r) + cos(k * p[2]);
242 
243  grad_phi[0] = -k * cos_phi * sin(k * r);
244  grad_phi[1] = -k * sin_phi * sin(k * r);
245  grad_phi[2] = -k * sin(k * p[2]);
246 
247  gamma = ep_0 * (sqrt(pow(r, 2) + pow(p[2], 2)) + 2.0);
248 
249  *v = epsilon * (*nn * grad_phi) + gamma * phi;
250  v++;
251  nn++;
252  }
253 }
254 
255 template<>
256 void
257 FreeSurfaceCharge<2>::value_list(const std::vector<Point<2>>& r,
258  const std::vector<Tensor<1, 2>>& n,
259  types::material_id mid,
260  unsigned int cuid,
261  unsigned int fuid,
262  std::vector<double>& values) const
263 {
264  Assert(r.size() == values.size(),
265  ExcDimensionMismatch(r.size(), values.size()));
266 
267  for (unsigned int i = 0; i < values.size(); i++)
268  values[i] = 0.0;
269 }
270 
271 template<>
272 void
273 FreeSurfaceCharge<3>::value_list(const std::vector<Point<3>>& r,
274  const std::vector<Tensor<1, 3>>& n,
275  types::material_id mid,
276  unsigned int cuid,
277  unsigned int fuid,
278  std::vector<double>& values) const
279 {
280  Assert(r.size() == values.size(),
281  ExcDimensionMismatch(r.size(), values.size()));
282 
283  for (unsigned int i = 0; i < values.size(); i++)
284  values[i] = 0.0;
285 }
286 
287 template<>
288 double
289 Weight<2>::value(const Point<2>& r, const unsigned int component) const
290 {
291  return 1.0;
292 }
293 
294 template<>
295 double
296 Weight<3>::value(const Point<3>& r, const unsigned int component) const
297 {
298  return 1.0;
299 }
300 
301 #pragma GCC diagnostic pop
void value_list(const std::vector< Point< dim >> &r, const std::vector< Tensor< 1, dim >> &n, types::material_id mid, unsigned int cuid, unsigned int fuid, std::vector< double > &values) const
Computes the right-hand side of the second continuity condition ( , , , or ).
void value_list(const std::vector< Point< dim >> &r, const std::vector< Tensor< 1, dim >> &n, types::boundary_id bid, types::material_id mid, unsigned int cuid, unsigned int fuid, std::vector< double > &values) const
Computes the coefficient at quadrature points.
void value_list(const std::vector< Point< dim >> &r, types::material_id mid, unsigned int cuid, std::vector< Tensor< 1, dim >> &values) const
Computes the two-dimensional free-current density on the right-hand side of the partial differential...
void value_list(const std::vector< Point< dim >> &r, types::material_id mid, unsigned int cuid, std::vector< double > &values) const
Computes the right-hand side of the div-grad partial differential equation at quadrature points.
void value_list(const std::vector< Point< dim >> &r, const std::vector< Tensor< 1, dim >> &n, types::boundary_id bid, types::material_id mid, unsigned int cuid, unsigned int fuid, std::vector< double > &values) const
Computes the right-hand side of the Robin boundary condition ( or ).
void value_list(const std::vector< Point< dim >> &r, types::material_id mid, unsigned int cuid, std::vector< double > &values) const
Computes the values of the coefficient at quadrature points.
virtual double value(const Point< dim > &r, const unsigned int component=0) const override final
Returns the value of weight at point r. All error norms, , , and , at point r will be multiplied by t...