Reference documentation for deal.II version 9.2.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\}}\)
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 {
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 
138  virtual std::size_t
139  memory_consumption() const;
140 
141  protected:
147 
152  unsigned int n_intervals;
153 
158  unsigned int interval;
159 
165  };
166 
167 
168 
174  std::vector<PiecewisePolynomial<double>>
176  const unsigned int n_subdivisions,
177  const unsigned int base_degree);
178 
179 } // namespace Polynomials
180 
181 
184 /* -------------------------- inline functions --------------------- */
185 
186 namespace Polynomials
187 {
188  template <typename number>
189  inline unsigned int
191  {
192  return polynomial.degree();
193  }
194 
195 
196 
197  template <typename number>
198  inline number
200  {
201  AssertIndexRange(interval, n_intervals);
202  number y = x;
203  // shift polynomial if necessary
204  if (n_intervals > 1)
205  {
206  const number step = 1. / n_intervals;
207 
208  // polynomial spans over two intervals
209  if (spans_two_intervals == true)
210  {
211  const number offset = step * interval;
212  if (x < offset)
213  return 0;
214  else if (x > offset + step + step)
215  return 0;
216  else if (x < offset + step)
217  y = x - offset;
218  else
219  y = offset + step + step - x;
220  }
221  else
222  {
223  const number offset = step * interval;
224  if (x < offset || x > offset + step)
225  return 0;
226  else
227  y = x - offset;
228  }
229 
230  return polynomial.value(y);
231  }
232  else
233  return polynomial.value(x);
234  }
235 
236 
237 
238  template <typename number>
239  template <class Archive>
240  inline void
241  PiecewisePolynomial<number>::serialize(Archive &ar, const unsigned int)
242  {
243  // forward to serialization function in the base class.
244  ar &static_cast<Subscriptor &>(*this);
245  ar &polynomial;
246  ar &n_intervals;
247  ar &interval;
248  ar &spans_two_intervals;
249  }
250 
251 } // namespace Polynomials
252 
254 
255 #endif
Polynomials::PiecewisePolynomial::degree
unsigned int degree() const
Definition: polynomials_piecewise.h:190
Polynomials
Definition: polynomial.h:41
polynomial.h
Polynomials::PiecewisePolynomial::polynomial
Polynomial< number > polynomial
Definition: polynomials_piecewise.h:146
Polynomials::PiecewisePolynomial
Definition: polynomials_piecewise.h:55
AssertIndexRange
#define AssertIndexRange(index, range)
Definition: exceptions.h:1649
Polynomials::PiecewisePolynomial::PiecewisePolynomial
PiecewisePolynomial(const Polynomial< number > &coefficients_on_interval, const unsigned int n_intervals, const unsigned int interval, const bool spans_next_interval)
Definition: polynomials_piecewise.cc:27
Subscriptor
Definition: subscriptor.h:62
subscriptor.h
Polynomials::PiecewisePolynomial::spans_two_intervals
bool spans_two_intervals
Definition: polynomials_piecewise.h:164
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
Polynomials::PiecewisePolynomial::memory_consumption
virtual std::size_t memory_consumption() const
Definition: polynomials_piecewise.cc:123
Polynomials::generate_complete_Lagrange_basis_on_subdivisions
std::vector< PiecewisePolynomial< double > > generate_complete_Lagrange_basis_on_subdivisions(const unsigned int n_subdivisions, const unsigned int base_degree)
Definition: polynomials_piecewise.cc:134
Polynomials::Polynomial
Definition: polynomial.h:62
exceptions.h
Polynomials::PiecewisePolynomial::value
number value(const number x) const
Definition: polynomials_piecewise.h:199
config.h
Polynomials::PiecewisePolynomial::n_intervals
unsigned int n_intervals
Definition: polynomials_piecewise.h:152
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
Polynomials::PiecewisePolynomial::serialize
void serialize(Archive &ar, const unsigned int version)
Definition: polynomials_piecewise.h:241
Polynomials::PiecewisePolynomial::interval
unsigned int interval
Definition: polynomials_piecewise.h:158
point.h