PFASST++
quadrature.hpp
Go to the documentation of this file.
1 
5 #ifndef _PFASST__QUADRATURE_HPP_
6 #define _PFASST__QUADRATURE_HPP_
7 
8 #include <cmath>
9 #include <exception>
10 #include <vector>
11 using namespace std;
12 
13 #include <Eigen/Dense>
14 template<typename scalar>
15 using Matrix = Eigen::Matrix<scalar, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
16 
17 #include <boost/math/constants/constants.hpp>
18 
19 #include "pfasst/config.hpp"
20 #include "pfasst/interfaces.hpp"
28 
29 template<typename scalar>
30 using Matrix = Eigen::Matrix<scalar, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
31 
32 
33 namespace pfasst
34 {
40  namespace quadrature
41  {
52  template<typename precision = pfasst::time_precision>
53  shared_ptr<IQuadrature<precision>> quadrature_factory(const size_t nnodes,
54  const QuadratureType qtype)
55  {
56  if (qtype == QuadratureType::GaussLegendre) {
57  return make_shared<GaussLegendre<precision>>(nnodes);
58  } else if (qtype == QuadratureType::GaussLobatto) {
59  return make_shared<GaussLobatto<precision>>(nnodes);
60  } else if (qtype == QuadratureType::GaussRadau) {
61  return make_shared<GaussRadau<precision>>(nnodes);
62  } else if (qtype == QuadratureType::ClenshawCurtis) {
63  return make_shared<ClenshawCurtis<precision>>(nnodes);
64  } else if (qtype == QuadratureType::Uniform) {
65  return make_shared<Uniform<precision>>(nnodes);
66  } else {
67  throw ValueError("invalid node type passed to compute_nodes.");
68  return nullptr;
69  }
70  }
71 
83  template<typename precision = pfasst::time_precision>
84  vector<precision> compute_nodes(size_t nnodes, QuadratureType qtype)
85  {
86  return quadrature_factory<precision>(nnodes, qtype)->get_nodes();
87  }
88 
94  template<typename precision = time_precision>
95  Matrix<precision> compute_interp(vector<precision> dst, vector<precision> src)
96  {
97  const size_t ndst = dst.size();
98  const size_t nsrc = src.size();
99 
100  Matrix<precision> mat(ndst, nsrc);
101 
102  for (size_t i = 0; i < ndst; i++) {
103  for (size_t j = 0; j < nsrc; j++) {
104  precision den = 1.0;
105  precision num = 1.0;
106 
107  for (size_t k = 0; k < nsrc; k++) {
108  if (k == j) { continue; }
109  den *= src[j] - src[k];
110  num *= dst[i] - src[k];
111  }
112 
113  if (abs(num) > 1e-32) {
114  mat(i, j) = num / den;
115  } else {
116  mat(i, j) = 0.0;
117  }
118  }
119  }
120 
121  return mat;
122  }
123  } // ::pfasst::quadrature
124 } // ::pfasst
125 
126 #endif // _PFASST__QUADRATURE_HPP_
QuadratureType
Quadrature type descriptors.
Definition: interface.hpp:32
STL namespace.
Value exception.
Definition: interfaces.hpp:50
vector< precision > compute_nodes(size_t nnodes, QuadratureType qtype)
Compute quadrature nodes for given quadrature type descriptor.
Definition: quadrature.hpp:84
Matrix< precision > compute_interp(vector< precision > dst, vector< precision > src)
Definition: quadrature.hpp:95
shared_ptr< IQuadrature< precision > > quadrature_factory(const size_t nnodes, const QuadratureType qtype)
Instantiates quadrature handler for given number of nodes and type descriptor.
Definition: quadrature.hpp:53
interfaces for SDC/MLSDC/PFASST algorithms.
Eigen::Matrix< scalar, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > Matrix