Skip to content

Commit c204060

Browse files
committed
quad: Use Boost matrix.
Signed-off-by: Matthew Emmett <[email protected]>
1 parent 853c0ea commit c204060

File tree

3 files changed

+28
-39
lines changed

3 files changed

+28
-39
lines changed

src/pfasst-encapsulated.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ namespace pfasst {
114114
auto* dst = dynamic_cast<EncapsulatedSweeperMixin<scalar>*>(DST);
115115
auto* src = dynamic_cast<const EncapsulatedSweeperMixin<scalar>*>(SRC);
116116

117-
if (tmat.size() == 0)
117+
if (tmat.size1() == 0)
118118
tmat = pfasst::compute_interp<scalar>(dst->get_nodes(), src->get_nodes());
119119

120120
int ndst = dst->get_nodes().size();

src/pfasst-quadrature.hpp

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,15 @@
88
#include <limits>
99
#include <vector>
1010

11-
using namespace std;
11+
#include <boost/numeric/ublas/matrix.hpp>
12+
13+
using boost::numeric::ublas::matrix;
14+
using std::vector;
1215

1316
namespace pfasst {
1417

1518
typedef unsigned int uint;
1619

17-
template<typename T>
18-
class matrix : public vector<T> {
19-
public:
20-
unsigned int n, m;
21-
matrix() { }
22-
matrix(unsigned int n, unsigned int m) {
23-
zeros(n, m);
24-
}
25-
void zeros(unsigned int n, unsigned int m) {
26-
this->n = n; this->m = m;
27-
this->resize(n*m);
28-
fill(this->begin(), this->end(), 0.0);
29-
}
30-
T& operator()(unsigned int i, unsigned int j) {
31-
return (*this)[i*m+j];
32-
}
33-
};
34-
3520
template<typename coeffT>
3621
class polynomial {
3722
vector<coeffT> c;
@@ -156,23 +141,23 @@ namespace pfasst {
156141

157142
//#define pi 3.1415926535897932384626433832795028841971693993751
158143

159-
template<typename nodeT>
160-
vector<nodeT> compute_nodes(int nnodes, string qtype)
144+
template<typename time>
145+
vector<time> compute_nodes(int nnodes, string qtype)
161146
{
162-
vector<nodeT> nodes(nnodes);
147+
vector<time> nodes(nnodes);
163148

164149
if (qtype == "gauss-legendre") {
165-
auto roots = polynomial<nodeT>::legendre(nnodes).roots();
150+
auto roots = polynomial<time>::legendre(nnodes).roots();
166151
for (int j=0; j<nnodes; j++)
167152
nodes[j] = 0.5 * (1.0 + roots[j]);
168153
} else if (qtype == "gauss-lobatto") {
169-
auto roots = polynomial<nodeT>::legendre(nnodes-1).differentiate().roots();
154+
auto roots = polynomial<time>::legendre(nnodes-1).differentiate().roots();
170155
for (int j=0; j<nnodes-2; j++)
171156
nodes[j+1] = 0.5 * (1.0 + roots[j]);
172157
nodes[0] = 0.0; nodes[nnodes-1] = 1.0;
173158
} else if (qtype == "gauss-radau") {
174-
auto l = polynomial<nodeT>::legendre(nnodes);
175-
auto lm1 = polynomial<nodeT>::legendre(nnodes-1);
159+
auto l = polynomial<time>::legendre(nnodes);
160+
auto lm1 = polynomial<time>::legendre(nnodes-1);
176161
for (int i=0; i<nnodes; i++)
177162
l[i] += lm1[i];
178163
auto roots = l.roots();
@@ -184,18 +169,18 @@ namespace pfasst {
184169
return nodes;
185170
}
186171

187-
template<typename nodeT>
188-
matrix<nodeT> compute_quadrature(vector<nodeT> dst, vector<nodeT> src, char type)
172+
template<typename time>
173+
matrix<time> compute_quadrature(vector<time> dst, vector<time> src, char type)
189174
{
190175
const int ndst = dst.size();
191176
const int nsrc = src.size();
192177

193-
matrix<nodeT> mat(ndst-1, nsrc);
178+
matrix<time> mat(ndst-1, nsrc);
194179

195180
// /* for (int n=0; n<(ndst-1)*nsrc; n++) */
196181
// /* smat[n] = 0.0; */
197182

198-
polynomial<nodeT> p(nsrc+1), p1(nsrc+1);
183+
polynomial<time> p(nsrc+1), p1(nsrc+1);
199184

200185
for (int i=0; i<nsrc; i++) {
201186
// if ((flags[i] & SDC_NODE_PROPER) == 0) continue;
@@ -216,7 +201,7 @@ namespace pfasst {
216201
auto den = p.evaluate(src[i]);
217202
auto P = p.integrate();
218203
for (int j=1; j<ndst; j++) {
219-
nodeT q = 0.0;
204+
time q = 0.0;
220205
if (type == 's')
221206
q = P.evaluate(dst[j]) - P.evaluate(dst[j-1]);
222207
else

src/pfasst-vector.hpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,23 @@ namespace pfasst {
5050
void mat_apply(vector<Encapsulation<scalar>*> DST, time a, matrix<time> mat,
5151
vector<Encapsulation<scalar>*> SRC, bool zero=true) {
5252

53-
vector<VectorEncapsulation<scalar,time>*> dst(mat.n), src(mat.m);
54-
for (int n=0; n<mat.n; n++)
53+
int ndst = DST.size();
54+
int nsrc = SRC.size();
55+
56+
vector<VectorEncapsulation<scalar,time>*> dst(ndst), src(nsrc);
57+
for (int n=0; n<ndst; n++)
5558
dst[n] = dynamic_cast<VectorEncapsulation*>(DST[n]);
56-
for (int m=0; m<mat.m; m++)
59+
for (int m=0; m<nsrc; m++)
5760
src[m] = dynamic_cast<VectorEncapsulation*>(SRC[m]);
5861

5962
if (zero)
60-
for (int n=0; n<mat.n; n++)
63+
for (int n=0; n<ndst; n++)
6164
dst[n]->setval(0.0);
6265

63-
for (int i=0; i<(*dst[0]).size(); i++)
64-
for (int n=0; n<mat.n; n++)
65-
for (int m=0; m<mat.m; m++)
66+
int ndofs = (*dst[0]).size();
67+
for (int i=0; i<ndofs; i++)
68+
for (int n=0; n<ndst; n++)
69+
for (int m=0; m<nsrc; m++)
6670
(*dst[n])[i] += a * mat(n,m) * (*src[m])[i];
6771
}
6872

0 commit comments

Comments
 (0)