Reference documentation for deal.II version 8.5.1
polynomials_piecewise.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2000 - 2016 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 at
12 // the top level of the deal.II distribution.
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 #include <deal.II/base/exceptions.h>
23 #include <deal.II/base/subscriptor.h>
24 #include <deal.II/base/polynomial.h>
25 #include <deal.II/base/point.h>
26 
27 #include <vector>
28 
29 DEAL_II_NAMESPACE_OPEN
30 
40 namespace Polynomials
41 {
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 value (const number x) const;
81 
96  void value (const number x,
97  std::vector<number> &values) const;
98 
114  void value (const number x,
115  const unsigned int n_derivatives,
116  number *values) const;
117 
122  unsigned int degree () const;
123 
128  template <class Archive>
129  void serialize (Archive &ar, const unsigned int version);
130 
131  protected:
132 
138 
142  unsigned int n_intervals;
143 
147  unsigned int interval;
148 
154  };
155 
156 
157 
163  std::vector<PiecewisePolynomial<double> >
164  generate_complete_Lagrange_basis_on_subdivisions (const unsigned int n_subdivisions,
165  const unsigned int base_degree);
166 
167 }
168 
169 
172 /* -------------------------- inline functions --------------------- */
173 
174 namespace Polynomials
175 {
176  template <typename number>
177  inline
178  unsigned int
180  {
181  return polynomial.degree();
182  }
183 
184 
185 
186  template <typename number>
187  inline
188  number
189  PiecewisePolynomial<number>::value (const number x) const
190  {
191  AssertIndexRange (interval, n_intervals);
192  number y = x;
193  // shift polynomial if necessary
194  if (n_intervals > 1)
195  {
196  const number step = 1./n_intervals;
197 
198  // polynomial spans over two intervals
199  if (spans_two_intervals == true)
200  {
201  const number offset = step * interval;
202  if (x<offset)
203  return 0;
204  else if (x>offset+step+step)
205  return 0;
206  else if (x<offset+step)
207  y = x-offset;
208  else
209  y = offset+step+step-x;
210  }
211  else
212  {
213  const number offset = step * interval;
214  if (x<offset || x>offset+step)
215  return 0;
216  else
217  y = x-offset;
218  }
219 
220  return polynomial.value(y);
221  }
222  else
223  return polynomial.value(x);
224  }
225 
226 
227 
228  template <typename number>
229  template <class Archive>
230  inline
231  void
232  PiecewisePolynomial<number>::serialize (Archive &ar, const unsigned int)
233  {
234  // forward to serialization function in the base class.
235  ar &static_cast<Subscriptor &>(*this);
236  ar &polynomial;
237  ar &n_intervals;
238  ar &interval;
239  ar &spans_two_intervals;
240  }
241 
242 }
243 
244 DEAL_II_NAMESPACE_CLOSE
245 
246 #endif
#define AssertIndexRange(index, range)
Definition: exceptions.h:1170
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)