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 * (pow(p[0], 2) * pow(p[1], 2) + 1);
36  v++;
37  }
38 }
39 
40 template<>
41 void
42 TheCoefficient<3>::value_list(const std::vector<Point<3>>& r,
43  types::material_id mid,
44  unsigned int cuid,
45  std::vector<double>& values) const
46 {
47  Assert(r.size() == values.size(),
48  ExcDimensionMismatch(r.size(), values.size()));
49 
50  auto v = values.begin();
51  for (auto p : r) {
52  *v = ep_0 * (pow(p[0], 2) * pow(p[1], 2) * pow(p[2], 2) + 1);
53  v++;
54  }
55 }
56 
57 template<>
58 void
59 PdeRhs<2>::value_list(const std::vector<Point<2>>& r,
60  types::material_id mid,
61  unsigned int cuid,
62  std::vector<double>& values) const
63 {
64  Assert(r.size() == values.size(),
65  ExcDimensionMismatch(r.size(), values.size()));
66 
67  auto v = values.begin();
68  for (auto p : r) {
69  *v =
70  ep_0 * k *
71  (2 * p[0] * pow(p[1], 2) * sin(k * p[0]) +
72  2 * p[1] * pow(p[0], 2) * sin(k * p[1]) +
73  k * (pow(p[0], 2) * pow(p[1], 2) + 1) * (cos(k * p[0]) + cos(k * p[1])));
74  v++;
75  }
76 }
77 
78 template<>
79 void
80 PdeRhs<3>::value_list(const std::vector<Point<3>>& r,
81  types::material_id mid,
82  unsigned int cuid,
83  std::vector<double>& values) const
84 {
85  Assert(r.size() == values.size(),
86  ExcDimensionMismatch(r.size(), values.size()));
87 
88  auto v = values.begin();
89  for (auto p : r) {
90  *v = ep_0 * k *
91  (2 * p[0] * pow(p[1], 2) * pow(p[2], 2) * sin(k * p[0]) +
92  2 * p[1] * pow(p[0], 2) * pow(p[2], 2) * sin(k * p[1]) +
93  2 * p[2] * pow(p[1], 2) * pow(p[0], 2) * sin(k * p[2]) +
94  k * (pow(p[0], 2) * pow(p[1], 2) * pow(p[2], 2) + 1) *
95  (cos(k * p[0]) + cos(k * p[1]) + cos(k * p[2])));
96  v++;
97  }
98 }
99 
100 template<>
101 void
102 PdeRhsCvp<2>::value_list(const std::vector<Point<2>>& r,
103  types::material_id mid,
104  unsigned int cuid,
105  std::vector<Tensor<1, 2>>& values) const
106 {
107  Assert(r.size() == values.size(),
108  ExcDimensionMismatch(r.size(), values.size()));
109 
110  for (unsigned int i = 0; i < values.size(); i++) {
111  values[i][0] = 0.0;
112  values[i][1] = 0.0;
113  }
114 }
115 
116 template<>
117 void
118 PdeRhsCvp<3>::value_list(const std::vector<Point<3>>& r,
119  types::material_id mid,
120  unsigned int cuid,
121  std::vector<Tensor<1, 3>>& values) const
122 {
123  Assert(r.size() == values.size(),
124  ExcDimensionMismatch(r.size(), values.size()));
125 
126  for (unsigned int i = 0; i < values.size(); i++) {
127  values[i][0] = 0.0;
128  values[i][1] = 0.0;
129  values[i][2] = 0.0;
130  }
131 }
132 
133 template<>
134 void
135 Gamma<2>::value_list(const std::vector<Point<2>>& r,
136  const std::vector<Tensor<1, 2>>& n,
137  types::boundary_id bid,
138  types::material_id mid,
139  unsigned int cuid,
140  unsigned int fuid,
141  std::vector<double>& values) const
142 {
143  Assert(r.size() == values.size(),
144  ExcDimensionMismatch(r.size(), values.size()));
145 
146  auto v = values.begin();
147  for (auto p : r) {
148  *v = (ep_0 * (pow(p[0], 2) * pow(p[1], 2) + 1)) * (p.norm() + 2);
149  v++;
150  }
151 }
152 
153 template<>
154 void
155 Gamma<3>::value_list(const std::vector<Point<3>>& r,
156  const std::vector<Tensor<1, 3>>& n,
157  types::boundary_id bid,
158  types::material_id mid,
159  unsigned int cuid,
160  unsigned int fuid,
161  std::vector<double>& values) const
162 {
163  Assert(r.size() == values.size(),
164  ExcDimensionMismatch(r.size(), values.size()));
165 
166  auto v = values.begin();
167  for (auto p : r) {
168  *v = (ep_0 * (pow(p[0], 2) * pow(p[1], 2) * pow(p[2], 2) + 1)) *
169  (p.norm() + 2);
170  v++;
171  }
172 }
173 
174 template<>
175 void
176 RobinRhs<2>::value_list(const std::vector<Point<2>>& r,
177  const std::vector<Tensor<1, 2>>& n,
178  types::boundary_id bid,
179  types::material_id mid,
180  unsigned int cuid,
181  unsigned int fuid,
182  std::vector<double>& values) const
183 {
184 
185  Assert(r.size() == values.size(),
186  ExcDimensionMismatch(r.size(), values.size()));
187 
188  double epsilon;
189  double gamma;
190  double phi;
191  Tensor<1, 2> grad_phi;
192 
193  auto v = values.begin();
194  auto nn = n.begin();
195  for (auto p : r) {
196  epsilon = ep_0 * (pow(p[0], 2) * pow(p[1], 2) + 1);
197  phi = cos(k * p[0]) + cos(k * p[1]);
198  grad_phi[0] = -k * sin(k * p[0]);
199  grad_phi[1] = -k * sin(k * p[1]);
200  gamma = epsilon * (p.norm() + 2);
201 
202  *v = epsilon * (*nn * grad_phi) + gamma * phi;
203  v++;
204  nn++;
205  }
206 }
207 
208 template<>
209 void
210 RobinRhs<3>::value_list(const std::vector<Point<3>>& r,
211  const std::vector<Tensor<1, 3>>& n,
212  types::boundary_id bid,
213  types::material_id mid,
214  unsigned int cuid,
215  unsigned int fuid,
216  std::vector<double>& values) const
217 {
218 
219  Assert(r.size() == values.size(),
220  ExcDimensionMismatch(r.size(), values.size()));
221 
222  double epsilon;
223  double gamma;
224  double phi;
225  Tensor<1, 3> grad_phi;
226 
227  auto v = values.begin();
228  auto nn = n.begin();
229  for (auto p : r) {
230  epsilon = ep_0 * (pow(p[0], 2) * pow(p[1], 2) * pow(p[2], 2) + 1);
231  phi = (cos(k * p[0]) + cos(k * p[1]) + cos(k * p[2]));
232  grad_phi[0] = -k * sin(k * p[0]);
233  grad_phi[1] = -k * sin(k * p[1]);
234  grad_phi[2] = -k * sin(k * p[2]);
235  gamma = epsilon * (p.norm() + 2);
236  *v = epsilon * (*nn * grad_phi) + gamma * phi;
237  v++;
238  nn++;
239  }
240 }
241 
242 template<>
243 void
244 FreeSurfaceCharge<2>::value_list(const std::vector<Point<2>>& r,
245  const std::vector<Tensor<1, 2>>& n,
246  types::material_id mid,
247  unsigned int cuid,
248  unsigned int fuid,
249  std::vector<double>& values) const
250 {
251  Assert(r.size() == values.size(),
252  ExcDimensionMismatch(r.size(), values.size()));
253 
254  for (unsigned int i = 0; i < values.size(); i++)
255  values[i] = 0.0;
256 }
257 
258 template<>
259 void
260 FreeSurfaceCharge<3>::value_list(const std::vector<Point<3>>& r,
261  const std::vector<Tensor<1, 3>>& n,
262  types::material_id mid,
263  unsigned int cuid,
264  unsigned int fuid,
265  std::vector<double>& values) const
266 {
267  Assert(r.size() == values.size(),
268  ExcDimensionMismatch(r.size(), values.size()));
269 
270  for (unsigned int i = 0; i < values.size(); i++)
271  values[i] = 0.0;
272 }
273 
274 template<>
275 double
276 Weight<2>::value(const Point<2>& r, const unsigned int component) const
277 {
278  return 1.0;
279 }
280 
281 template<>
282 double
283 Weight<3>::value(const Point<3>& r, const unsigned int component) const
284 {
285  return 1.0;
286 }
287 #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...