Reference documentation for deal.II version 8.4.2
polynomials_piecewise.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2000 - 2015 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 
103  unsigned int degree () const;
104 
109  template <class Archive>
110  void serialize (Archive &ar, const unsigned int version);
111 
112  protected:
113 
119 
123  unsigned int n_intervals;
124 
128  unsigned int interval;
129 
135  };
136 
137 
138 
144  std::vector<PiecewisePolynomial<double> >
145  generate_complete_Lagrange_basis_on_subdivisions (const unsigned int n_subdivisions,
146  const unsigned int base_degree);
147 
148 }
149 
150 
153 /* -------------------------- inline functions --------------------- */
154 
155 namespace Polynomials
156 {
157  template <typename number>
158  inline
159  unsigned int
161  {
162  return polynomial.degree();
163  }
164 
165 
166 
167  template <typename number>
168  inline
169  number
170  PiecewisePolynomial<number>::value (const number x) const
171  {
173  number y = x;
174  // shift polynomial if necessary
175  if (n_intervals > 1)
176  {
177  const number step = 1./n_intervals;
178 
179  // polynomial spans over two intervals
180  if (spans_two_intervals == true)
181  {
182  const number offset = step * interval;
183  if (x<offset)
184  return 0;
185  else if (x>offset+step+step)
186  return 0;
187  else if (x<offset+step)
188  y = x-offset;
189  else
190  y = offset+step+step-x;
191  }
192  else
193  {
194  const number offset = step * interval;
195  if (x<offset || x>offset+step)
196  return 0;
197  else
198  y = x-offset;
199  }
200 
201  return polynomial.value(y);
202  }
203  else
204  return polynomial.value(x);
205  }
206 
207 
208 
209  template <typename number>
210  template <class Archive>
211  inline
212  void
213  PiecewisePolynomial<number>::serialize (Archive &ar, const unsigned int)
214  {
215  // forward to serialization function in the base class.
216  ar &static_cast<Subscriptor &>(*this);
217  ar &polynomial;
218  ar &n_intervals;
219  ar &interval;
221  }
222 
223 }
224 
225 DEAL_II_NAMESPACE_CLOSE
226 
227 #endif
#define AssertIndexRange(index, range)
Definition: exceptions.h:1081
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)