Skip to content

Commit 6e62617

Browse files
committed
Merge branch 'release/v0.1.0' into feature/state
Signed-off-by: Matthew Emmett <[email protected]> Conflicts: examples/advection_diffusion/advection_diffusion_sweeper.hpp examples/advection_diffusion/serial_mlsdc.cpp examples/advection_diffusion/vanilla_sdc.cpp include/pfasst/encap/imex_sweeper.hpp
2 parents 98f4431 + 8fe2b6b commit 6e62617

File tree

11 files changed

+126
-145
lines changed

11 files changed

+126
-145
lines changed

examples/advection_diffusion/advection_diffusion_sweeper.hpp

Lines changed: 39 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,21 @@
1515

1616
#include "fft.hpp"
1717

18-
#define PI 3.1415926535897932385
19-
#define TWO_PI 6.2831853071795864769
18+
#ifndef PI
19+
#define PI 3.1415926535897932385
20+
#endif
2021

2122
using namespace std;
23+
using pfasst::encap::Encapsulation;
24+
using pfasst::encap::as_vector;
25+
2226

2327
typedef map<pair<size_t, size_t>, double> error_map;
2428

2529
template<typename time = pfasst::time_precision>
2630
class AdvectionDiffusionSweeper
2731
: public pfasst::encap::IMEXSweeper<time>
2832
{
29-
typedef pfasst::encap::Encapsulation<time> Encapsulation;
30-
typedef pfasst::encap::VectorEncapsulation<double> DVectorT;
31-
3233
FFT fft;
3334

3435
vector<complex<double>> ddx, lap;
@@ -45,7 +46,7 @@ class AdvectionDiffusionSweeper
4546
ddx.resize(nvars);
4647
lap.resize(nvars);
4748
for (size_t i = 0; i < nvars; i++) {
48-
double kx = TWO_PI * ((i <= nvars / 2) ? int(i) : int(i) - int(nvars));
49+
double kx = 2 * PI * ((i <= nvars / 2) ? int(i) : int(i) - int(nvars));
4950
ddx[i] = complex<double>(0.0, 1.0) * kx;
5051
lap[i] = (kx * kx < 1e-13) ? 0.0 : -kx * kx;
5152
}
@@ -56,48 +57,45 @@ class AdvectionDiffusionSweeper
5657
cout << "number of f1 evals: " << nf1evals << endl;
5758
}
5859

59-
void exact(shared_ptr<Encapsulation> q, time t)
60+
void exact(shared_ptr<Encapsulation<time>> q, time t)
6061
{
61-
shared_ptr<DVectorT> q_cast = dynamic_pointer_cast<DVectorT>(q);
62-
assert(q_cast);
63-
this->exact(q_cast, t);
62+
this->exact(as_vector<double,time>(q), t);
6463
}
6564

66-
void exact(shared_ptr<DVectorT> q, time t)
65+
void exact(DVectorT& q, time t)
6766
{
68-
size_t n = q->size();
67+
size_t n = q.size();
6968
double a = 1.0 / sqrt(4 * PI * nu * (t + t0));
7069

7170
for (size_t i = 0; i < n; i++) {
72-
q->data()[i] = 0.0;
71+
q[i] = 0.0;
7372
}
7473

7574
for (int ii = -2; ii < 3; ii++) {
7675
for (size_t i = 0; i < n; i++) {
7776
double x = double(i) / n - 0.5 + ii - t * v;
78-
q->data()[i] += a * exp(-x * x / (4 * nu * (t + t0)));
77+
q[i] += a * exp(-x * x / (4 * nu * (t + t0)));
7978
}
8079
}
8180
}
8281

8382
void echo_error(time t, bool predict = false)
8483
{
85-
shared_ptr<DVectorT> qend = dynamic_pointer_cast<DVectorT>(this->get_state(this->get_nodes().size() - 1));
86-
assert(qend);
87-
shared_ptr<DVectorT> qex = make_shared<DVectorT>(qend->size());
84+
auto& qend = as_vector<double,time>(this->get_end_state());
85+
DVectorT qex(qend.size());
8886

8987
exact(qex, t);
9088

9189
double max = 0.0;
92-
for (size_t i = 0; i < qend->size(); i++) {
93-
double d = abs(qend->data()[i] - qex->data()[i]);
90+
for (size_t i = 0; i < qend.size(); i++) {
91+
double d = abs(qend[i] - qex[i]);
9492
if (d > max) { max = d; }
9593
}
9694

9795
auto n = this->get_controller()->get_step();
9896
auto k = this->get_controller()->get_iteration();
9997
cout << "err: " << n << " " << k << " " << scientific << max
100-
<< " (" << qend->size() << ", " << predict << ")"
98+
<< " (" << qend.size() << ", " << predict << ")"
10199
<< endl;
102100

103101
errors.insert(pair<pair<size_t, size_t>, double>
@@ -125,76 +123,55 @@ class AdvectionDiffusionSweeper
125123
echo_error(t + dt);
126124
}
127125

128-
void f1eval(shared_ptr<Encapsulation> f, shared_ptr<Encapsulation> q, time t)
126+
void f1eval(shared_ptr<Encapsulation<time>> _f, shared_ptr<Encapsulation<time>> _q, time /*t*/)
129127
{
130-
shared_ptr<DVectorT> f_cast = dynamic_pointer_cast<DVectorT>(f);
131-
assert(f_cast);
132-
shared_ptr<DVectorT> q_cast = dynamic_pointer_cast<DVectorT>(q);
133-
assert(q_cast);
128+
auto& q = as_vector<double,time>(_q);
129+
auto& f = as_vector<double,time>(_f);
134130

135-
this->f1eval(f_cast, q_cast, t);
136-
}
137-
138-
void f1eval(shared_ptr<DVectorT> f, shared_ptr<DVectorT> q, time t)
139-
{
140-
double c = -v / double(q->size());
131+
double c = -v / double(q.size());
141132

142133
auto* z = fft.forward(q);
143-
for (size_t i = 0; i < q->size(); i++) {
134+
for (size_t i = 0; i < q.size(); i++) {
144135
z[i] *= c * ddx[i];
145136
}
146137
fft.backward(f);
147138

148139
nf1evals++;
149140
}
150141

151-
void f2eval(shared_ptr<Encapsulation> f, shared_ptr<Encapsulation> q, time t)
142+
void f2eval(shared_ptr<Encapsulation<time>> _f, shared_ptr<Encapsulation<time>> _q, time /*t*/)
152143
{
153-
shared_ptr<DVectorT> f_cast = dynamic_pointer_cast<DVectorT>(f);
154-
assert(f_cast);
155-
shared_ptr<DVectorT> q_cast = dynamic_pointer_cast<DVectorT>(q);
156-
assert(q_cast);
144+
auto& q = as_vector<double,time>(_q);
145+
auto& f = as_vector<double,time>(_f);
157146

158-
this->f2eval(f_cast, q_cast, t);
159-
}
160-
161-
void f2eval(shared_ptr<DVectorT> f, shared_ptr<DVectorT> q, time t)
162-
{
163-
double c = nu / double(q->size());
147+
double c = nu / double(q.size());
164148

165149
auto* z = fft.forward(q);
166-
for (size_t i = 0; i < q->size(); i++) {
150+
for (size_t i = 0; i < q.size(); i++) {
167151
z[i] *= c * lap[i];
168152
}
169153
fft.backward(f);
170154
}
171155

172-
void f2comp(shared_ptr<Encapsulation> f, shared_ptr<Encapsulation> q, time t, time dt,
173-
shared_ptr<Encapsulation> rhs)
156+
void f2comp(shared_ptr<Encapsulation<time>> _f, shared_ptr<Encapsulation<time>> _q, time /*t*/, time dt,
157+
shared_ptr<Encapsulation<time>> _rhs)
174158
{
175-
shared_ptr<DVectorT> f_cast = dynamic_pointer_cast<DVectorT>(f);
176-
assert(f_cast);
177-
shared_ptr<DVectorT> q_cast = dynamic_pointer_cast<DVectorT>(q);
178-
assert(q_cast);
179-
shared_ptr<DVectorT> rhs_cast = dynamic_pointer_cast<DVectorT>(rhs);
180-
assert(rhs_cast);
181-
182-
this->f2comp(f_cast, q_cast, t, dt, rhs_cast);
183-
}
159+
auto& q = as_vector<double,time>(_q);
160+
auto& f = as_vector<double,time>(_f);
161+
auto& rhs = as_vector<double,time>(_rhs);
184162

185-
void f2comp(shared_ptr<DVectorT> f, shared_ptr<DVectorT> q, time t, time dt,
186-
shared_ptr<DVectorT> rhs)
187-
{
188163
auto* z = fft.forward(rhs);
189-
for (size_t i = 0; i < q->size(); i++) {
190-
z[i] /= (1.0 - nu * double(dt) * lap[i]) * double(q->size());
164+
for (size_t i = 0; i < q.size(); i++) {
165+
z[i] /= (1.0 - nu * double(dt) * lap[i]) * double(q.size());
191166
}
192167
fft.backward(q);
193168

194-
for (size_t i = 0; i < q->size(); i++) {
195-
f->data()[i] = (q->data()[i] - rhs->data()[i]) / double(dt);
169+
for (size_t i = 0; i < q.size(); i++) {
170+
f[i] = (q[i] - rhs[i]) / double(dt);
196171
}
172+
197173
}
174+
198175
};
199176

200177
#endif

examples/advection_diffusion/fft.hpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515

1616
#include <fftw3.h>
1717

18+
typedef pfasst::encap::VectorEncapsulation<double> DVectorT;
19+
1820
class FFT
1921
{
20-
typedef pfasst::encap::VectorEncapsulation<double> DVectorT;
21-
2222
struct workspace {
2323
fftw_plan ffft;
2424
fftw_plan ifft;
@@ -36,7 +36,6 @@ class FFT
3636
fftw_free(wk->wk);
3737
fftw_destroy_plan(wk->ffft);
3838
fftw_destroy_plan(wk->ifft);
39-
// delete wk;
4039
}
4140
workspaces.clear();
4241
}
@@ -55,22 +54,22 @@ class FFT
5554
return workspaces[ndofs];
5655
}
5756

58-
complex<double>* forward(shared_ptr<const DVectorT> x)
57+
complex<double>* forward(const DVectorT& x)
5958
{
60-
shared_ptr<workspace> wk = get_workspace(x->size());
61-
for (size_t i = 0; i < x->size(); i++) {
62-
wk->z[i] = x->data()[i];
59+
shared_ptr<workspace> wk = get_workspace(x.size());
60+
for (size_t i = 0; i < x.size(); i++) {
61+
wk->z[i] = x[i];
6362
}
6463
fftw_execute_dft(wk->ffft, wk->wk, wk->wk);
6564
return wk->z;
6665
}
6766

68-
void backward(shared_ptr<DVectorT> x)
67+
void backward(DVectorT& x)
6968
{
70-
shared_ptr<workspace> wk = get_workspace(x->size());
69+
shared_ptr<workspace> wk = get_workspace(x.size());
7170
fftw_execute_dft(wk->ifft, wk->wk, wk->wk);
72-
for (size_t i = 0; i < x->size(); i++) {
73-
x->data()[i] = real(wk->z[i]);
71+
for (size_t i = 0; i < x.size(); i++) {
72+
x[i] = real(wk->z[i]);
7473
}
7574
}
7675

examples/advection_diffusion/serial_mlsdc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ error_map run_serial_mlsdc()
7979
}
8080

8181
#ifndef PFASST_UNIT_TESTING
82-
int main(int argc, char** argv)
82+
int main(int /*argc*/, char** /*argv*/)
8383
{
8484
run_serial_mlsdc();
8585
}

examples/advection_diffusion/serial_mlsdc_autobuild.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ using namespace std;
2424
using namespace pfasst;
2525
using namespace pfasst::encap;
2626

27-
int main(int argc, char** argv)
27+
int main(int /*argc*/, char** /*argv*/)
2828
{
2929
MLSDC<> mlsdc;
3030

examples/advection_diffusion/spectral_transfer_1d.hpp

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,63 +14,49 @@
1414
#include "fft.hpp"
1515

1616
template<typename time = pfasst::time_precision>
17-
class SpectralTransfer1D
17+
class SpectralTransfer1D
1818
: public pfasst::encap::PolyInterpMixin<time>
1919
{
2020
typedef pfasst::encap::Encapsulation<double> Encapsulation;
21-
typedef pfasst::encap::VectorEncapsulation<double> DVectorT;
2221

2322
FFT fft;
2423

2524
public:
25+
2626
void interpolate(shared_ptr<Encapsulation> dst, shared_ptr<const Encapsulation> src)
2727
{
28-
shared_ptr<DVectorT> fine = dynamic_pointer_cast<DVectorT>(dst);
29-
assert(fine);
30-
shared_ptr<const DVectorT> crse = dynamic_pointer_cast<const DVectorT>(src);
31-
assert(crse);
32-
33-
this->interpolate(fine, crse);
34-
}
28+
auto& fine = as_vector<double,time>(dst);
29+
auto& crse = as_vector<double,time>(src);
3530

36-
void interpolate(shared_ptr<DVectorT> fine, shared_ptr<const DVectorT> crse)
37-
{
3831
auto* crse_z = fft.forward(crse);
39-
auto* fine_z = fft.get_workspace(fine->size())->z;
32+
auto* fine_z = fft.get_workspace(fine.size())->z;
4033

41-
for (size_t i = 0; i < fine->size(); i++) {
34+
for (size_t i = 0; i < fine.size(); i++) {
4235
fine_z[i] = 0.0;
4336
}
4437

45-
double c = 1.0 / crse->size();
38+
double c = 1.0 / crse.size();
4639

47-
for (size_t i = 0; i < crse->size() / 2; i++) {
40+
for (size_t i = 0; i < crse.size() / 2; i++) {
4841
fine_z[i] = c * crse_z[i];
4942
}
5043

51-
for (size_t i = 1; i < crse->size() / 2; i++) {
52-
fine_z[fine->size() - crse->size() / 2 + i] = c * crse_z[crse->size() / 2 + i];
44+
for (size_t i = 1; i < crse.size() / 2; i++) {
45+
fine_z[fine.size() - crse.size() / 2 + i] = c * crse_z[crse.size() / 2 + i];
5346
}
5447

5548
fft.backward(fine);
5649
}
5750

5851
void restrict(shared_ptr<Encapsulation> dst, shared_ptr<const Encapsulation> src)
5952
{
60-
shared_ptr<DVectorT> crse = dynamic_pointer_cast<DVectorT>(dst);
61-
assert(crse);
62-
shared_ptr<const DVectorT> fine = dynamic_pointer_cast<const DVectorT>(src);
63-
assert(fine);
53+
auto& fine = as_vector<double,time>(src);
54+
auto& crse = as_vector<double,time>(dst);
6455

65-
this->restrict(crse, fine);
66-
}
67-
68-
void restrict(shared_ptr<DVectorT> crse, shared_ptr<const DVectorT> fine)
69-
{
70-
size_t xrat = fine->size() / crse->size();
56+
size_t xrat = fine.size() / crse.size();
7157

72-
for (size_t i = 0; i < crse->size(); i++) {
73-
crse->data()[i] = fine->at(xrat * i);
58+
for (size_t i = 0; i < crse.size(); i++) {
59+
crse[i] = fine[xrat*i];
7460
}
7561
}
7662

include/pfasst/encap/encap_sweeper.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace pfasst
1717
{
1818

1919
template<typename time = time_precision>
20-
class EncapSweeper
20+
class EncapSweeper
2121
: public ISweeper<time>
2222
{
2323
vector<time> nodes;
@@ -45,24 +45,24 @@ namespace pfasst
4545
return factory;
4646
}
4747

48-
virtual void set_state(shared_ptr<const Encapsulation<time>> q0, size_t m)
48+
virtual void set_state(shared_ptr<const Encapsulation<time>> /*q0*/, size_t /*m*/)
4949
{
5050
throw NotImplementedYet("sweeper");
5151
}
5252

53-
virtual shared_ptr<Encapsulation<time>> get_state(size_t m) const
53+
virtual shared_ptr<Encapsulation<time>> get_state(size_t /*m*/) const
5454
{
5555
throw NotImplementedYet("sweeper");
5656
return NULL;
5757
}
5858

59-
virtual shared_ptr<Encapsulation<time>> get_tau(size_t m) const
59+
virtual shared_ptr<Encapsulation<time>> get_tau(size_t /*m*/) const
6060
{
6161
throw NotImplementedYet("sweeper");
6262
return NULL;
6363
}
6464

65-
virtual shared_ptr<Encapsulation<time>> get_saved_state(size_t m) const
65+
virtual shared_ptr<Encapsulation<time>> get_saved_state(size_t /*m*/) const
6666
{
6767
throw NotImplementedYet("sweeper");
6868
return NULL;
@@ -73,7 +73,7 @@ namespace pfasst
7373
return this->get_state(this->get_nodes().size() - 1);
7474
}
7575

76-
virtual void evaluate(size_t m)
76+
virtual void evaluate(size_t /*m*/)
7777
{
7878
throw NotImplementedYet("sweeper");
7979
}
@@ -83,7 +83,7 @@ namespace pfasst
8383
throw NotImplementedYet("sweeper");
8484
}
8585

86-
virtual void integrate(time dt, vector<shared_ptr<Encapsulation<time>>> dst) const
86+
virtual void integrate(time /*dt*/, vector<shared_ptr<Encapsulation<time>>> /*dst*/) const
8787
{
8888
throw NotImplementedYet("sweeper");
8989
}

0 commit comments

Comments
 (0)