Reference documentation for deal.II version GIT relicensing-860-g3e6195f9ee 2024-06-20 00:40:01+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
polynomials_piecewise.h
Go to the documentation of this file.
1// ------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4// Copyright (C) 2013 - 2023 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15#ifndef dealii_polynomials_piecewise_h
16#define dealii_polynomials_piecewise_h
17
18
19
20#include <deal.II/base/config.h>
21
23#include <deal.II/base/point.h>
26
27#include <vector>
28
30
40namespace Polynomials
41{
62 template <typename number>
64 {
65 public:
77 PiecewisePolynomial(const Polynomial<number> &coefficients_on_interval,
78 const unsigned int n_intervals,
79 const unsigned int interval,
80 const bool spans_next_interval);
81
89 const unsigned int index);
90
97 number
98 value(const number x) const;
99
114 void
115 value(const number x, std::vector<number> &values) const;
116
132 void
133 value(const number x,
134 const unsigned int n_derivatives,
135 number *values) const;
136
141 unsigned int
142 degree() const;
143
149 template <class Archive>
150 void
151 serialize(Archive &ar, const unsigned int version);
152
156 virtual std::size_t
157 memory_consumption() const;
158
159 protected:
165
170 unsigned int n_intervals;
171
176 unsigned int interval;
177
183
188 std::vector<number> points;
189
194 std::vector<number> one_over_lengths;
195
200 unsigned int index;
201 };
202
203
204
210 std::vector<PiecewisePolynomial<double>>
212 const unsigned int n_subdivisions,
213 const unsigned int base_degree);
214
219 std::vector<PiecewisePolynomial<double>>
221 const std::vector<Point<1>> &points);
222
223} // namespace Polynomials
224
225
228/* -------------------------- inline functions --------------------- */
229
230namespace Polynomials
231{
232 template <typename number>
233 inline unsigned int
235 {
236 if (points.size() > 0)
237 return 1;
238 return polynomial.degree();
239 }
240
241
242
243 template <typename number>
244 inline number
246 {
247 if (points.size() > 0)
248 {
249 if (x > points[index])
250 return std::max<number>(0.0,
251 1.0 - (x - points[index]) *
252 one_over_lengths[index]);
253 else if (x < points[index])
254 return std::max<number>(0.0,
255 0.0 + (x - points[index - 1]) *
256 one_over_lengths[index - 1]);
257 else
258 return 1.0;
259 }
260
261 AssertIndexRange(interval, n_intervals);
262 number y = x;
263 // shift polynomial if necessary
264 if (n_intervals > 1)
265 {
266 const number step = 1. / n_intervals;
267
268 // polynomial spans over two intervals
269 if (spans_two_intervals == true)
270 {
271 const number offset = step * interval;
272 if (x < offset)
273 return 0;
274 else if (x > offset + step + step)
275 return 0;
276 else if (x < offset + step)
277 y = x - offset;
278 else
279 y = offset + step + step - x;
280 }
281 else
282 {
283 const number offset = step * interval;
284 if (x < offset || x > offset + step)
285 return 0;
286 else
287 y = x - offset;
288 }
289
290 return polynomial.value(y);
291 }
292 else
293 return polynomial.value(x);
294 }
295
296
297
298 template <typename number>
299 template <class Archive>
300 inline void
301 PiecewisePolynomial<number>::serialize(Archive &ar, const unsigned int)
302 {
303 // forward to serialization function in the base class.
304 ar &static_cast<Subscriptor &>(*this);
305 ar &polynomial;
306 ar &n_intervals;
307 ar &interval;
308 ar &spans_two_intervals;
309 ar &points;
310 ar &one_over_lengths;
311 ar &index;
312 }
313} // namespace Polynomials
314
316
317#endif
Definition point.h:111
void serialize(Archive &ar, const unsigned int version)
number value(const number x) const
virtual std::size_t memory_consumption() const
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:502
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:503
#define AssertIndexRange(index, range)
std::vector< PiecewisePolynomial< double > > generate_complete_linear_basis_on_subdivisions(const std::vector< Point< 1 > > &points)
std::vector< PiecewisePolynomial< double > > generate_complete_Lagrange_basis_on_subdivisions(const unsigned int n_subdivisions, const unsigned int base_degree)