Skip to content

Commit e4ae6fb

Browse files
committed
internals: splitting up decls/defs for quadrature classes
towards fixing #84
1 parent f089690 commit e4ae6fb

14 files changed

+520
-319
lines changed

include/pfasst/quadrature/clenshaw_curtis.hpp

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,41 +30,24 @@ namespace pfasst
3030

3131
public:
3232
//! @{
33-
explicit ClenshawCurtis(const size_t num_nodes)
34-
: IQuadrature<precision>(num_nodes)
35-
{
36-
if (this->num_nodes < 2) {
37-
throw invalid_argument("Clenshaw-Curtis quadrature requires at least two quadrature nodes.");
38-
}
39-
this->compute_nodes();
40-
this->compute_weights();
41-
}
42-
33+
explicit ClenshawCurtis(const size_t num_nodes);
4334
ClenshawCurtis() = default;
44-
4535
virtual ~ClenshawCurtis() = default;
4636
//! @}
4737

4838
//! @{
49-
virtual bool left_is_node() const { return LEFT_IS_NODE; }
50-
51-
virtual bool right_is_node() const { return RIGHT_IS_NODE; }
39+
virtual bool left_is_node() const override;
40+
virtual bool right_is_node() const override;
5241
//! @}
5342

5443
protected:
5544
//! @{
56-
virtual void compute_nodes()
57-
{
58-
this->nodes = vector<precision>(this->num_nodes, precision(0.0));
59-
auto roots = Polynomial<precision>::legendre(this->num_nodes).roots();
60-
61-
for (size_t j = 0; j < this->num_nodes; j++) {
62-
this->nodes[j] = 0.5 * (1.0 - cos(j * pi<precision>() / (this->num_nodes - 1)));
63-
}
64-
}
45+
virtual void compute_nodes() override;
6546
//! @}
6647
};
6748
} // ::pfasst::quadrature
6849
} // ::pfasst
6950

51+
#include "clenshaw_curtis_impl.hpp"
52+
7053
#endif // _PFASST__QUADRATURE__CLENSHAW_CURTIS_HPP_
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include "clenshaw_curtis.hpp"
2+
3+
#include <stdexcept>
4+
using namespace std;
5+
6+
7+
namespace pfasst
8+
{
9+
namespace quadrature
10+
{
11+
template<typename precision>
12+
ClenshawCurtis<precision>::ClenshawCurtis(const size_t num_nodes)
13+
: IQuadrature<precision>(num_nodes)
14+
{
15+
if (this->num_nodes < 2) {
16+
throw invalid_argument("Clenshaw-Curtis quadrature requires at least two quadrature nodes.");
17+
}
18+
this->compute_nodes();
19+
this->compute_weights();
20+
}
21+
22+
template<typename precision>
23+
bool ClenshawCurtis<precision>::left_is_node() const
24+
{
25+
return LEFT_IS_NODE;
26+
}
27+
28+
template<typename precision>
29+
bool ClenshawCurtis<precision>::right_is_node() const
30+
{
31+
return RIGHT_IS_NODE;
32+
}
33+
34+
template<typename precision>
35+
void ClenshawCurtis<precision>::compute_nodes()
36+
{
37+
this->nodes = vector<precision>(this->num_nodes, precision(0.0));
38+
auto roots = Polynomial<precision>::legendre(this->num_nodes).roots();
39+
40+
for (size_t j = 0; j < this->num_nodes; j++) {
41+
this->nodes[j] = 0.5 * (1.0 - cos(j * pi<precision>() / (this->num_nodes - 1)));
42+
}
43+
}
44+
} // ::pfasst::quadrature
45+
} // ::pfasst
Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
#ifndef _PFASST__QUADRATURE__GAUSS_LEGENDRE_HPP_
22
#define _PFASST__QUADRATURE__GAUSS_LEGENDRE_HPP_
33

4-
#include <cassert>
5-
#include <vector>
6-
7-
#include "../interfaces.hpp"
8-
#include "polynomial.hpp"
94
#include "interface.hpp"
105

11-
using namespace std;
12-
136

147
namespace pfasst
158
{
@@ -27,38 +20,24 @@ namespace pfasst
2720

2821
public:
2922
//! @{
30-
explicit GaussLegendre(const size_t num_nodes)
31-
: IQuadrature<precision>(num_nodes)
32-
{
33-
this->compute_nodes();
34-
this->compute_weights();
35-
}
36-
23+
explicit GaussLegendre(const size_t num_nodes);
3724
GaussLegendre() = default;
38-
3925
virtual ~GaussLegendre() = default;
4026
//! @}
4127

4228
//! @{
43-
virtual bool left_is_node() const { return LEFT_IS_NODE; }
44-
45-
virtual bool right_is_node() const { return RIGHT_IS_NODE; }
29+
virtual bool left_is_node() const override;
30+
virtual bool right_is_node() const override;
4631
//! @}
4732

4833
protected:
4934
//! @{
50-
virtual void compute_nodes() override
51-
{
52-
this->nodes = vector<precision>(this->num_nodes, precision(0.0));
53-
auto roots = Polynomial<precision>::legendre(this->num_nodes).roots();
54-
55-
for (size_t j = 0; j < this->num_nodes; j++) {
56-
this->nodes[j] = 0.5 * (1.0 + roots[j]);
57-
}
58-
}
35+
virtual void compute_nodes() override;
5936
//! @}
6037
};
6138
} // ::pfasst::quadrature
6239
} // ::pfasst
6340

41+
#include "gauss_legendre_impl.hpp"
42+
6443
#endif // _PFASST__QUADRATURE__GAUSS_LEGENDRE_HPP_
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include "gauss_legendre.hpp"
2+
3+
#include <vector>
4+
using namespace std;
5+
6+
#include "polynomial.hpp"
7+
8+
9+
namespace pfasst
10+
{
11+
namespace quadrature
12+
{
13+
template<typename precision>
14+
GaussLegendre<precision>::GaussLegendre(const size_t num_nodes)
15+
: IQuadrature<precision>(num_nodes)
16+
{
17+
this->compute_nodes();
18+
this->compute_weights();
19+
}
20+
21+
template<typename precision>
22+
bool GaussLegendre<precision>::left_is_node() const
23+
{
24+
return LEFT_IS_NODE;
25+
}
26+
27+
template<typename precision>
28+
bool GaussLegendre<precision>::right_is_node() const
29+
{
30+
return RIGHT_IS_NODE;
31+
}
32+
33+
template<typename precision>
34+
void GaussLegendre<precision>::compute_nodes()
35+
{
36+
this->nodes = vector<precision>(this->num_nodes, precision(0.0));
37+
auto roots = Polynomial<precision>::legendre(this->num_nodes).roots();
38+
39+
for (size_t j = 0; j < this->num_nodes; j++) {
40+
this->nodes[j] = 0.5 * (1.0 + roots[j]);
41+
}
42+
}
43+
} // ::pfasst::quadrature
44+
} // ::pfasst
Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
#ifndef _PFASST__QUADRATURE__GAUSS_LOBATTO_HPP_
22
#define _PFASST__QUADRATURE__GAUSS_LOBATTO_HPP_
33

4-
#include <cassert>
5-
#include <vector>
6-
7-
#include "../interfaces.hpp"
8-
#include "polynomial.hpp"
94
#include "interface.hpp"
105

11-
using namespace std;
12-
136

147
namespace pfasst
158
{
@@ -27,43 +20,24 @@ namespace pfasst
2720

2821
public:
2922
//! @{
30-
explicit GaussLobatto(const size_t num_nodes)
31-
: IQuadrature<precision>(num_nodes)
32-
{
33-
if (this->num_nodes < 2) {
34-
throw invalid_argument("Gauss-Lobatto quadrature requires at least two quadrature nodes.");
35-
}
36-
this->compute_nodes();
37-
this->compute_weights();
38-
}
39-
23+
explicit GaussLobatto(const size_t num_nodes);
4024
GaussLobatto() = default;
41-
4225
virtual ~GaussLobatto() = default;
4326
//! @}
4427

4528
//! @{
46-
virtual bool left_is_node() const { return LEFT_IS_NODE; }
47-
48-
virtual bool right_is_node() const { return RIGHT_IS_NODE; }
29+
virtual bool left_is_node() const override;
30+
virtual bool right_is_node() const override;
4931
//! @}
5032

5133
protected:
5234
//! @{
53-
virtual void compute_nodes() override
54-
{
55-
this->nodes = vector<precision>(this->num_nodes, precision(0.0));
56-
auto roots = Polynomial<precision>::legendre(this->num_nodes - 1).differentiate().roots();
57-
58-
for (size_t j = 0; j < this->num_nodes - 2; j++) {
59-
this->nodes[j + 1] = 0.5 * (1.0 + roots[j]);
60-
}
61-
this->nodes.front() = 0.0;
62-
this->nodes.back() = 1.0;
63-
}
35+
virtual void compute_nodes() override;
6436
//! @}
6537
};
6638
} // ::pfasst::quadrature
6739
} // ::pfasst
6840

41+
#include "gauss_lobatto_impl.hpp"
42+
6943
#endif // _PFASST__QUADRATURE__GAUSS_LOBATTO_HPP_
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include "gauss_lobatto.hpp"
2+
3+
#include <stdexcept>
4+
#include <vector>
5+
using namespace std;
6+
7+
#include "polynomial.hpp"
8+
9+
10+
namespace pfasst
11+
{
12+
namespace quadrature
13+
{
14+
template<typename precision>
15+
GaussLobatto<precision>::GaussLobatto(const size_t num_nodes)
16+
: IQuadrature<precision>(num_nodes)
17+
{
18+
if (this->num_nodes < 2) {
19+
throw invalid_argument("Gauss-Lobatto quadrature requires at least two quadrature nodes.");
20+
}
21+
this->compute_nodes();
22+
this->compute_weights();
23+
}
24+
25+
template<typename precision>
26+
bool GaussLobatto<precision>::left_is_node() const
27+
{
28+
return LEFT_IS_NODE;
29+
}
30+
31+
template<typename precision>
32+
bool GaussLobatto<precision>::right_is_node() const
33+
{
34+
return RIGHT_IS_NODE;
35+
}
36+
37+
template<typename precision>
38+
void GaussLobatto<precision>::compute_nodes()
39+
{
40+
this->nodes = vector<precision>(this->num_nodes, precision(0.0));
41+
auto roots = Polynomial<precision>::legendre(this->num_nodes - 1).differentiate().roots();
42+
43+
for (size_t j = 0; j < this->num_nodes - 2; j++) {
44+
this->nodes[j + 1] = 0.5 * (1.0 + roots[j]);
45+
}
46+
this->nodes.front() = 0.0;
47+
this->nodes.back() = 1.0;
48+
}
49+
} // ::pfasst::quadrature
50+
} // ::pfasst
Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
#ifndef _PFASST__QUADRATURE__GAUSS_RADAU_HPP_
22
#define _PFASST__QUADRATURE__GAUSS_RADAU_HPP_
33

4-
#include <cassert>
5-
#include <vector>
6-
7-
#include "../interfaces.hpp"
8-
#include "polynomial.hpp"
94
#include "interface.hpp"
105

11-
using namespace std;
12-
136

147
namespace pfasst
158
{
@@ -27,47 +20,24 @@ namespace pfasst
2720

2821
public:
2922
//! @{
30-
explicit GaussRadau(const size_t num_nodes)
31-
: IQuadrature<precision>(num_nodes)
32-
{
33-
if (this->num_nodes < 2) {
34-
throw invalid_argument("Gauss-Radau quadrature requires at least two quadrature nodes.");
35-
}
36-
this->compute_nodes();
37-
this->compute_weights();
38-
}
39-
23+
explicit GaussRadau(const size_t num_nodes);
4024
GaussRadau() = default;
41-
4225
virtual ~GaussRadau() = default;
4326
//! @}
4427

4528
//! @{
46-
virtual bool left_is_node() const { return LEFT_IS_NODE; }
47-
48-
virtual bool right_is_node() const { return RIGHT_IS_NODE; }
29+
virtual bool left_is_node() const override;
30+
virtual bool right_is_node() const override;
4931
//! @}
5032

5133
protected:
5234
//! @{
53-
virtual void compute_nodes() override
54-
{
55-
this->nodes = vector<precision>(this->num_nodes, precision(0.0));
56-
auto l = Polynomial<precision>::legendre(this->num_nodes);
57-
auto lm1 = Polynomial<precision>::legendre(this->num_nodes - 1);
58-
59-
for (size_t i = 0; i < this->num_nodes; i++) {
60-
l[i] += lm1[i];
61-
}
62-
auto roots = l.roots();
63-
for (size_t j = 1; j < this->num_nodes; j++) {
64-
this->nodes[j - 1] = 0.5 * (1.0 - roots[this->num_nodes - j]);
65-
}
66-
this->nodes.back() = 1.0;
67-
}
35+
virtual void compute_nodes() override;
6836
//! @}
6937
};
7038
} // ::pfasst::quadrature
7139
} // ::pfasst
7240

41+
#include "gauss_radau_impl.hpp"
42+
7343
#endif // _PFASST__QUADRATURE__GAUSS_RADAU_HPP_

0 commit comments

Comments
 (0)