Reference documentation for deal.II version 9.1.1
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
polynomials_piecewise.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2000 - 2018 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 
23 #include <deal.II/base/exceptions.h>
24 #include <deal.II/base/point.h>
25 #include <deal.II/base/polynomial.h>
26 #include <deal.II/base/subscriptor.h>
27 
28 #include <vector>
29 
30 DEAL_II_NAMESPACE_OPEN
31 
41 namespace Polynomials
42 {
54  template <typename number>
56  {
57  public:
69  PiecewisePolynomial(const Polynomial<number> &coefficients_on_interval,
70  const unsigned int n_intervals,
71  const unsigned int interval,
72  const bool spans_next_interval);
73 
80  number
81  value(const number x) const;
82 
97  void
98  value(const number x, std::vector<number> &values) const;
99 
115  void
116  value(const number x,
117  const unsigned int n_derivatives,
118  number * values) const;
119 
124  unsigned int
125  degree() const;
126 
131  template <class Archive>
132  void
133  serialize(Archive &ar, const unsigned int version);
134 
135  protected:
141 
146  unsigned int n_intervals;
147 
152  unsigned int interval;
153 
159  };
160 
161 
162 
168  std::vector<PiecewisePolynomial<double>>
170  const unsigned int n_subdivisions,
171  const unsigned int base_degree);
172 
173 } // namespace Polynomials
174 
175 
178 /* -------------------------- inline functions --------------------- */
179 
180 namespace Polynomials
181 {
182  template <typename number>
183  inline unsigned int
185  {
186  return polynomial.degree();
187  }
188 
189 
190 
191  template <typename number>
192  inline number
194  {
195  AssertIndexRange(interval, n_intervals);
196  number y = x;
197  // shift polynomial if necessary
198  if (n_intervals > 1)
199  {
200  const number step = 1. / n_intervals;
201 
202  // polynomial spans over two intervals
203  if (spans_two_intervals == true)
204  {
205  const number offset = step * interval;
206  if (x < offset)
207  return 0;
208  else if (x > offset + step + step)
209  return 0;
210  else if (x < offset + step)
211  y = x - offset;
212  else
213  y = offset + step + step - x;
214  }
215  else
216  {
217  const number offset = step * interval;
218  if (x < offset || x > offset + step)
219  return 0;
220  else
221  y = x - offset;
222  }
223 
224  return polynomial.value(y);
225  }
226  else
227  return polynomial.value(x);
228  }
229 
230 
231 
232  template <typename number>
233  template <class Archive>
234  inline void
235  PiecewisePolynomial<number>::serialize(Archive &ar, const unsigned int)
236  {
237  // forward to serialization function in the base class.
238  ar &static_cast<Subscriptor &>(*this);
239  ar &polynomial;
240  ar &n_intervals;
241  ar &interval;
242  ar &spans_two_intervals;
243  }
244 
245 } // namespace Polynomials
246 
247 DEAL_II_NAMESPACE_CLOSE
248 
249 #endif
#define AssertIndexRange(index, range)
Definition: exceptions.h:1637
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)
PiecewisePolynomial(const Polynomial< number > &coefficients_on_interval, const unsigned int n_intervals, const unsigned int interval, const bool spans_next_interval)