Skip to content

Commit 91f5dca

Browse files
committed
Tidy VectorEncapsulation, remove nbytes().
1 parent 1fa228e commit 91f5dca

File tree

3 files changed

+12
-21
lines changed

3 files changed

+12
-21
lines changed

examples/ad/main.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,8 @@ class ADIMEX : public pfasst::imex::IMEX<time> {
5656

5757
public:
5858

59-
ADIMEX(vector<time> nodes, pfasst::encap::VectorFactory<time> *factory)
59+
ADIMEX(int nvars)
6060
{
61-
this->set_nodes(nodes);
62-
this->set_factory(factory);
63-
64-
int nvars = factory->dofs();
65-
6661
// XXX: this fft stuff almost certainly DOES NOT work when 'scalar' is not 'double'
6762
wk = fftw_alloc_complex(nvars);
6863
ffft = fftw_plan_dft_1d(nvars, wk, wk, FFTW_FORWARD, FFTW_ESTIMATE);
@@ -115,7 +110,7 @@ class ADIMEX : public pfasst::imex::IMEX<time> {
115110
if (d > max)
116111
max = d;
117112
}
118-
cout << "err: " << max << endl;
113+
cout << "err: " << scientific << max << endl;
119114
}
120115

121116
void f1eval(Encapsulation *F, Encapsulation *Q, time t)
@@ -192,7 +187,10 @@ int main(int argc, char **argv)
192187

193188
auto nodes = pfasst::compute_nodes<scalar>(nnodes, "gauss-lobatto");
194189
auto* factory = new pfasst::encap::VectorFactory<scalar>(ndofs);
195-
auto* sweeper = new ADIMEX<scalar>(nodes, factory);
190+
auto* sweeper = new ADIMEX<scalar>(ndofs);
191+
192+
sweeper->set_nodes(nodes);
193+
sweeper->set_factory(factory);
196194

197195
sdc.add_level(sweeper);
198196
sdc.set_duration(dt, nsteps, 4);

src/pfasst-encapsulated.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ namespace pfasst {
3434
}
3535

3636
// required for time-parallel communications
37-
virtual unsigned int nbytes() {
38-
throw NotImplementedYet("pfasst");
39-
}
4037
virtual void send() {
4138
throw NotImplementedYet("pfasst");
4239
}

src/pfasst-vector.hpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,18 @@ namespace pfasst {
1818
template<typename scalar>
1919
struct VectorEncapsulation : public vector<scalar>, public Encapsulation {
2020
VectorEncapsulation(int size) : vector<scalar>(size) { }
21-
virtual unsigned int nbytes() const {
22-
return sizeof(scalar) * this->size();
23-
}
2421
void setval(scalar v) {
25-
for (int i=0; i<this->size(); i++)
26-
(*this)[i] = v;
22+
std::fill(this->begin(), this->end(), v);
2723
}
2824
void copy(const Encapsulation* X) {
2925
const auto* x = dynamic_cast<const VectorEncapsulation*>(X);
30-
for (int i=0; i<this->size(); i++)
31-
(*this)[i] = (*x)[i];
26+
std::copy(x->begin(), x->end(), this->begin());
3227
}
3328
void saxpy(double a, const Encapsulation *X) {
34-
const auto* x = dynamic_cast<const VectorEncapsulation*>(X);
35-
for (int i=0; i<this->size(); i++)
36-
(*this)[i] += a * (*x)[i];
29+
const auto& x = *dynamic_cast<const VectorEncapsulation*>(X);
30+
auto& y = *this;
31+
for (int i=0; i<y.size(); i++)
32+
y[i] += a * x[i];
3733
}
3834
};
3935

0 commit comments

Comments
 (0)