Reference documentation for deal.II version 8.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
polynomials_piecewise.h
1 // ---------------------------------------------------------------------
2 // @f$Id: polynomials_piecewise.h 30040 2013-07-18 17:06:48Z maier @f$
3 //
4 // Copyright (C) 2000 - 2013 by the deal.II authors
5 //
6 // This file is part of the deal.II library.
7 //
8 // The deal.II library is free software; you can use it, redistribute
9 // it, and/or modify it under the terms of the GNU Lesser General
10 // Public License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 // The full text of the license can be found in the file LICENSE at
13 // the top level of the deal.II distribution.
14 //
15 // ---------------------------------------------------------------------
16 
17 #ifndef __deal2__polynomials_piecewise_h
18 #define __deal2__polynomials_piecewise_h
19 
20 
21 
22 #include <deal.II/base/config.h>
24 #include <deal.II/base/subscriptor.h>
25 #include <deal.II/base/polynomial.h>
26 #include <deal.II/base/point.h>
27 
28 #include <vector>
29 
31 
41 namespace Polynomials
42 {
43 
55  template <typename number>
57  {
58  public:
70  PiecewisePolynomial (const Polynomial<number> &coefficients_on_interval,
71  const unsigned int n_intervals,
72  const unsigned int interval,
73  const bool spans_next_interval);
74 
81  number value (const number x) const;
82 
97  void value (const number x,
98  std::vector<number> &values) const;
99 
104  unsigned int degree () const;
105 
110  template <class Archive>
111  void serialize (Archive &ar, const unsigned int version);
112 
113  protected:
114 
120 
124  unsigned int n_intervals;
125 
130  unsigned int interval;
131 
137  };
138 
139 
140 
146  std::vector<PiecewisePolynomial<double> >
147  generate_complete_Lagrange_basis_on_subdivisions (const unsigned int n_subdivisions,
148  const unsigned int base_degree);
149 
150 }
151 
152 
155 /* -------------------------- inline functions --------------------- */
156 
157 namespace Polynomials
158 {
159  template <typename number>
160  inline
161  unsigned int
163  {
164  return polynomial.degree();
165  }
166 
167 
168 
169  template <typename number>
170  inline
171  number
172  PiecewisePolynomial<number>::value (const number x) const
173  {
174  AssertIndexRange (interval, n_intervals);
175  number y = x;
176  // shift polynomial if necessary
177  if (n_intervals > 1)
178  {
179  const number step = 1./n_intervals;
180 
181  // polynomial spans over two intervals
182  if (spans_two_intervals == true)
183  {
184  const number offset = step * interval;
185  if (x<offset)
186  return 0;
187  else if (x>offset+step+step)
188  return 0;
189  else if (x<offset+step)
190  y = x-offset;
191  else
192  y = offset+step+step-x;
193  }
194  else
195  {
196  const number offset = step * interval;
197  if (x<offset || x>offset+step)
198  return 0;
199  else
200  y = x-offset;
201  }
202 
203  return polynomial.value(y);
204  }
205  else
206  return polynomial.value(x);
207  }
208 
209 
210 
211  template <typename number>
212  template <class Archive>
213  inline
214  void
215  PiecewisePolynomial<number>::serialize (Archive &ar, const unsigned int)
216  {
217  // forward to serialization function in the base class.
218  ar &static_cast<Subscriptor &>(*this);
219  ar &polynomial;
220  ar &n_intervals;
221  ar &interval;
222  ar &spans_two_intervals;
223  }
224 
225 }
226 
227 DEAL_II_NAMESPACE_CLOSE
228 
229 #endif
number value(const number x) const
#define AssertIndexRange(index, range)
Definition: exceptions.h:888
void serialize(Archive &ar, const unsigned int version)
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)