Reference documentation for deal.II version Git 5546c7f774 2020-10-25 14:46:39 +0100
\(\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\}}\)
polynomials_piecewise.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2000 - 2020 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 
41 namespace Polynomials
42 {
52  template <typename number>
54  {
55  public:
67  PiecewisePolynomial(const Polynomial<number> &coefficients_on_interval,
68  const unsigned int n_intervals,
69  const unsigned int interval,
70  const bool spans_next_interval);
71 
78  number
79  value(const number x) const;
80 
95  void
96  value(const number x, std::vector<number> &values) const;
97 
113  void
114  value(const number x,
115  const unsigned int n_derivatives,
116  number * values) const;
117 
122  unsigned int
123  degree() const;
124 
129  template <class Archive>
130  void
131  serialize(Archive &ar, const unsigned int version);
132 
136  virtual std::size_t
137  memory_consumption() const;
138 
139  protected:
145 
150  unsigned int n_intervals;
151 
156  unsigned int interval;
157 
163  };
164 
165 
166 
172  std::vector<PiecewisePolynomial<double>>
174  const unsigned int n_subdivisions,
175  const unsigned int base_degree);
176 
177 } // namespace Polynomials
178 
179 
182 /* -------------------------- inline functions --------------------- */
183 
184 namespace Polynomials
185 {
186  template <typename number>
187  inline unsigned int
189  {
190  return polynomial.degree();
191  }
192 
193 
194 
195  template <typename number>
196  inline number
198  {
200  number y = x;
201  // shift polynomial if necessary
202  if (n_intervals > 1)
203  {
204  const number step = 1. / n_intervals;
205 
206  // polynomial spans over two intervals
207  if (spans_two_intervals == true)
208  {
209  const number offset = step * interval;
210  if (x < offset)
211  return 0;
212  else if (x > offset + step + step)
213  return 0;
214  else if (x < offset + step)
215  y = x - offset;
216  else
217  y = offset + step + step - x;
218  }
219  else
220  {
221  const number offset = step * interval;
222  if (x < offset || x > offset + step)
223  return 0;
224  else
225  y = x - offset;
226  }
227 
228  return polynomial.value(y);
229  }
230  else
231  return polynomial.value(x);
232  }
233 
234 
235 
236  template <typename number>
237  template <class Archive>
238  inline void
239  PiecewisePolynomial<number>::serialize(Archive &ar, const unsigned int)
240  {
241  // forward to serialization function in the base class.
242  ar &static_cast<Subscriptor &>(*this);
243  ar &polynomial;
244  ar &n_intervals;
245  ar &interval;
247  }
248 
249 } // namespace Polynomials
250 
252 
253 #endif
virtual std::size_t memory_consumption() const
#define AssertIndexRange(index, range)
Definition: exceptions.h:1648
void serialize(Archive &ar, const unsigned int version)
number value(const number x) const
std::vector< PiecewisePolynomial< double > > generate_complete_Lagrange_basis_on_subdivisions(const unsigned int n_subdivisions, const unsigned int base_degree)
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:369
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:368
PiecewisePolynomial(const Polynomial< number > &coefficients_on_interval, const unsigned int n_intervals, const unsigned int interval, const bool spans_next_interval)