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