Reference documentation for deal.II version 9.5.0
\(\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// Copyright (C) 2000 - 2023 by the deal.II authors
4//
5// This file is part of the deal.II library.
6//
7// The deal.II library is free software; you can use it, redistribute
8// it, and/or modify it under the terms of the GNU Lesser General
9// Public License as published by the Free Software Foundation; either
10// version 2.1 of the License, or (at your option) any later version.
11// The full text of the license can be found in the file LICENSE.md at
12// the top level directory of deal.II.
13//
14// ---------------------------------------------------------------------
15
16#ifndef dealii_polynomials_piecewise_h
17#define dealii_polynomials_piecewise_h
18
19
20
21#include <deal.II/base/config.h>
22
24#include <deal.II/base/point.h>
27
28#include <vector>
29
31
41namespace Polynomials
42{
63 template <typename number>
65 {
66 public:
78 PiecewisePolynomial(const Polynomial<number> &coefficients_on_interval,
79 const unsigned int n_intervals,
80 const unsigned int interval,
81 const bool spans_next_interval);
82
90 const unsigned int index);
91
98 number
99 value(const number x) const;
100
115 void
116 value(const number x, std::vector<number> &values) const;
117
133 void
134 value(const number x,
135 const unsigned int n_derivatives,
136 number * values) const;
137
142 unsigned int
143 degree() const;
144
150 template <class Archive>
151 void
152 serialize(Archive &ar, const unsigned int version);
153
157 virtual std::size_t
158 memory_consumption() const;
159
160 protected:
166
171 unsigned int n_intervals;
172
177 unsigned int interval;
178
184
189 std::vector<number> points;
190
195 std::vector<number> one_over_lengths;
196
201 unsigned int index;
202 };
203
204
205
211 std::vector<PiecewisePolynomial<double>>
213 const unsigned int n_subdivisions,
214 const unsigned int base_degree);
215
220 std::vector<PiecewisePolynomial<double>>
222 const std::vector<Point<1>> &points);
223
224} // namespace Polynomials
225
226
229/* -------------------------- inline functions --------------------- */
230
231namespace Polynomials
232{
233 template <typename number>
234 inline unsigned int
236 {
237 if (points.size() > 0)
238 return 1;
239 return polynomial.degree();
240 }
241
242
243
244 template <typename number>
245 inline number
247 {
248 if (points.size() > 0)
249 {
250 if (x > points[index])
251 return std::max<number>(0.0,
252 1.0 - (x - points[index]) *
253 one_over_lengths[index]);
254 else if (x < points[index])
255 return std::max<number>(0.0,
256 0.0 + (x - points[index - 1]) *
257 one_over_lengths[index - 1]);
258 else
259 return 1.0;
260 }
261
262 AssertIndexRange(interval, n_intervals);
263 number y = x;
264 // shift polynomial if necessary
265 if (n_intervals > 1)
266 {
267 const number step = 1. / n_intervals;
268
269 // polynomial spans over two intervals
270 if (spans_two_intervals == true)
271 {
272 const number offset = step * interval;
273 if (x < offset)
274 return 0;
275 else if (x > offset + step + step)
276 return 0;
277 else if (x < offset + step)
278 y = x - offset;
279 else
280 y = offset + step + step - x;
281 }
282 else
283 {
284 const number offset = step * interval;
285 if (x < offset || x > offset + step)
286 return 0;
287 else
288 y = x - offset;
289 }
290
291 return polynomial.value(y);
292 }
293 else
294 return polynomial.value(x);
295 }
296
297
298
299 template <typename number>
300 template <class Archive>
301 inline void
302 PiecewisePolynomial<number>::serialize(Archive &ar, const unsigned int)
303 {
304 // forward to serialization function in the base class.
305 ar &static_cast<Subscriptor &>(*this);
306 ar &polynomial;
307 ar &n_intervals;
308 ar &interval;
309 ar &spans_two_intervals;
310 ar &points;
311 ar &one_over_lengths;
312 ar &index;
313 }
314} // namespace Polynomials
315
317
318#endif
Definition point.h:112
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:472
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:473
#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)