Skip to content

Commit c807217

Browse files
author
Matthew Emmett
committed
Merge branch 'development' into feature/scalar2
2 parents 64f54e5 + d5494a0 commit c807217

23 files changed

+833
-296
lines changed

examples/advection_diffusion/advection_diffusion_sweeper.hpp

Lines changed: 96 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
#ifndef _ADVECTION_DIFFUSION_SWEEPER_HPP_
66
#define _ADVECTION_DIFFUSION_SWEEPER_HPP_
77

8+
#include <cstdlib>
89
#include <cassert>
910
#include <complex>
1011
#include <map>
1112
#include <ostream>
1213
#include <vector>
14+
#include <utility>
1315

16+
#include <pfasst/globals.hpp>
1417
#include <pfasst/encap/imex_sweeper.hpp>
1518

1619
#include "fft.hpp"
@@ -24,42 +27,56 @@ using pfasst::encap::Encapsulation;
2427
using pfasst::encap::as_vector;
2528

2629

30+
/**
31+
* errors at different iterations and time nodes
32+
*
33+
* Mapping a pair of step/iteration indices onto the error of the solution.
34+
*/
2735
typedef map<pair<size_t, size_t>, double> error_map;
2836

2937
template<typename time = pfasst::time_precision>
3038
class AdvectionDiffusionSweeper
3139
: public pfasst::encap::IMEXSweeper<time>
3240
{
41+
//! @{
3342
FFT fft;
34-
3543
vector<complex<double>> ddx, lap;
44+
//! @}
45+
46+
//! @{
3647
error_map errors;
48+
//! @}
3749

50+
//! @{
3851
double v = 1.0;
3952
time t0 = 1.0;
4053
double nu = 0.02;
4154
size_t nf1evals = 0;
55+
//! @}
4256

4357
public:
58+
//! @{
4459
AdvectionDiffusionSweeper(size_t nvars)
4560
{
46-
ddx.resize(nvars);
47-
lap.resize(nvars);
61+
this->ddx.resize(nvars);
62+
this->lap.resize(nvars);
4863
for (size_t i = 0; i < nvars; i++) {
4964
double kx = 2 * PI * ((i <= nvars / 2) ? int(i) : int(i) - int(nvars));
50-
ddx[i] = complex<double>(0.0, 1.0) * kx;
51-
lap[i] = (kx * kx < 1e-13) ? 0.0 : -kx * kx;
65+
this->ddx[i] = complex<double>(0.0, 1.0) * kx;
66+
this->lap[i] = (kx * kx < 1e-13) ? 0.0 : -kx * kx;
5267
}
5368
}
5469

55-
~AdvectionDiffusionSweeper()
70+
virtual ~AdvectionDiffusionSweeper()
5671
{
57-
cout << "number of f1 evals: " << nf1evals << endl;
72+
cout << "number of f1 evals: " << this->nf1evals << endl;
5873
}
74+
//! @}
5975

76+
//! @{
6077
void exact(shared_ptr<Encapsulation<time>> q, time t)
6178
{
62-
this->exact(as_vector<double,time>(q), t);
79+
this->exact(as_vector<double, time>(q), t);
6380
}
6481

6582
void exact(DVectorT& q, time t)
@@ -81,10 +98,10 @@ class AdvectionDiffusionSweeper
8198

8299
void echo_error(time t, bool predict = false)
83100
{
84-
auto& qend = as_vector<double,time>(this->get_end_state());
101+
auto& qend = as_vector<double, time>(this->get_end_state());
85102
DVectorT qex(qend.size());
86103

87-
exact(qex, t);
104+
this->exact(qex, t);
88105

89106
double max = 0.0;
90107
for (size_t i = 0; i < qend.size(); i++) {
@@ -98,80 +115,111 @@ class AdvectionDiffusionSweeper
98115
<< " (" << qend.size() << ", " << predict << ")"
99116
<< endl;
100117

101-
errors.insert(pair<pair<size_t, size_t>, double>
102-
(pair<size_t, size_t>(n, k), max));
118+
this->errors.insert(pair<pair<size_t, size_t>, double>(pair<size_t, size_t>(n, k), max));
103119
}
104120

121+
/**
122+
* retrieve errors at iterations and time nodes
123+
*/
105124
error_map get_errors()
106125
{
107-
return errors;
126+
return this->errors;
108127
}
128+
//! @}
109129

110-
void predict(bool initial)
130+
//! @{
131+
/**
132+
* @copybrief pfasst::encap::IMEXSweeper::predict()
133+
*/
134+
void predict(bool initial) override
111135
{
112136
pfasst::encap::IMEXSweeper<time>::predict(initial);
113137
time t = this->get_controller()->get_time();
114138
time dt = this->get_controller()->get_time_step();
115-
echo_error(t + dt, true);
139+
this->echo_error(t + dt, true);
116140
}
117141

118-
void sweep()
142+
/**
143+
* @copybrief pfasst::encap::IMEXSweeper::sweep()
144+
*/
145+
void sweep() override
119146
{
120147
pfasst::encap::IMEXSweeper<time>::sweep();
121148
time t = this->get_controller()->get_time();
122149
time dt = this->get_controller()->get_time_step();
123-
echo_error(t + dt);
150+
this->echo_error(t + dt);
124151
}
125-
126-
void f1eval(shared_ptr<Encapsulation<time>> _f, shared_ptr<Encapsulation<time>> _q, time /*t*/)
152+
//! @}
153+
154+
//! @{
155+
/**
156+
* @copybrief pfasst::encap::IMEXSweeper::f_expl_eval()
157+
*/
158+
void f_expl_eval(shared_ptr<Encapsulation<time>> f_expl_encap,
159+
shared_ptr<Encapsulation<time>> u_encap,
160+
time t) override
127161
{
128-
auto& q = as_vector<double,time>(_q);
129-
auto& f = as_vector<double,time>(_f);
162+
UNUSED(t);
163+
auto& u = as_vector<double, time>(u_encap);
164+
auto& f_expl = as_vector<double, time>(f_expl_encap);
130165

131-
double c = -v / double(q.size());
166+
double c = -v / double(u.size());
132167

133-
auto* z = fft.forward(q);
134-
for (size_t i = 0; i < q.size(); i++) {
135-
z[i] *= c * ddx[i];
168+
auto* z = this->fft.forward(u);
169+
for (size_t i = 0; i < u.size(); i++) {
170+
z[i] *= c * this->ddx[i];
136171
}
137-
fft.backward(f);
172+
this->fft.backward(f_expl);
138173

139-
nf1evals++;
174+
this->nf1evals++;
140175
}
141176

142-
void f2eval(shared_ptr<Encapsulation<time>> _f, shared_ptr<Encapsulation<time>> _q, time /*t*/)
177+
/**
178+
* @copybrief pfasst::encap::IMEXSweeper::f_impl_eval()
179+
*/
180+
void f_impl_eval(shared_ptr<Encapsulation<time>> f_impl_encap,
181+
shared_ptr<Encapsulation<time>> u_encap,
182+
time t) override
143183
{
144-
auto& q = as_vector<double,time>(_q);
145-
auto& f = as_vector<double,time>(_f);
184+
UNUSED(t);
185+
auto& u = as_vector<double, time>(u_encap);
186+
auto& f_impl = as_vector<double, time>(f_impl_encap);
146187

147-
double c = nu / double(q.size());
188+
double c = nu / double(u.size());
148189

149-
auto* z = fft.forward(q);
150-
for (size_t i = 0; i < q.size(); i++) {
151-
z[i] *= c * lap[i];
190+
auto* z = this->fft.forward(u);
191+
for (size_t i = 0; i < u.size(); i++) {
192+
z[i] *= c * this->lap[i];
152193
}
153-
fft.backward(f);
194+
this->fft.backward(f_impl);
154195
}
155196

156-
void f2comp(shared_ptr<Encapsulation<time>> _f, shared_ptr<Encapsulation<time>> _q, time /*t*/, time dt,
157-
shared_ptr<Encapsulation<time>> _rhs)
197+
/**
198+
* @copybrief pfasst::encap::IMEXSweeper::impl_solve()
199+
*/
200+
void impl_solve(shared_ptr<Encapsulation<time>> f_impl_encap,
201+
shared_ptr<Encapsulation<time>> u_encap,
202+
time t, time dt,
203+
shared_ptr<Encapsulation<time>> rhs_encap) override
158204
{
159-
auto& q = as_vector<double,time>(_q);
160-
auto& f = as_vector<double,time>(_f);
161-
auto& rhs = as_vector<double,time>(_rhs);
205+
UNUSED(t);
206+
auto& u = as_vector<double, time>(u_encap);
207+
auto& f_impl = as_vector<double, time>(f_impl_encap);
208+
auto& rhs = as_vector<double, time>(rhs_encap);
162209

163-
auto* z = fft.forward(rhs);
164-
for (size_t i = 0; i < q.size(); i++) {
165-
z[i] /= (1.0 - nu * double(dt) * lap[i]) * double(q.size());
166-
}
167-
fft.backward(q);
210+
double c = nu * double(dt);
168211

169-
for (size_t i = 0; i < q.size(); i++) {
170-
f[i] = (q[i] - rhs[i]) / double(dt);
212+
auto* z = this->fft.forward(rhs);
213+
for (size_t i = 0; i < u.size(); i++) {
214+
z[i] /= (1.0 - c * this->lap[i]) * double(u.size());
171215
}
216+
this->fft.backward(u);
172217

218+
for (size_t i = 0; i < u.size(); i++) {
219+
f_impl[i] = (u[i] - rhs[i]) / double(dt);
220+
}
173221
}
174-
222+
//! @}
175223
};
176224

177225
#endif

examples/advection_diffusion/fft.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ class FFT
7272
x[i] = real(wk->z[i]);
7373
}
7474
}
75-
7675
};
7776

7877
#endif

examples/advection_diffusion/mpi_pfasst.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@ using namespace pfasst;
2424
using namespace pfasst::encap;
2525
using namespace pfasst::mpi;
2626

27-
int main(int argc, char** argv)
27+
error_map run_mpi_pfasst()
2828
{
29-
MPI_Init(&argc, &argv);
30-
3129
const size_t nsteps = 4;
3230
const double dt = 0.01;
3331
const size_t niters = 4;
@@ -64,7 +62,16 @@ int main(int argc, char** argv)
6462
pf.set_nsweeps({2, 1});
6563
pf.run();
6664

67-
fftw_cleanup();
65+
auto fine = pf.get_finest<AdvectionDiffusionSweeper<>>();
66+
return fine->get_errors();
67+
}
6868

69+
#ifndef PFASST_UNIT_TESTING
70+
int main(int argc, char** argv)
71+
{
72+
MPI_Init(&argc, &argv);
73+
run_mpi_pfasst();
74+
fftw_cleanup();
6975
MPI_Finalize();
7076
}
77+
#endif

examples/advection_diffusion/serial_mlsdc_autobuild.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
* controller.
88
*/
99

10-
#include <memory>
10+
#include <cstdlib>
1111
#include <cassert>
12+
#include <memory>
13+
#include <vector>
14+
#include <string>
1215

1316
#include <fftw3.h>
1417

@@ -24,6 +27,7 @@ using namespace std;
2427
using namespace pfasst;
2528
using namespace pfasst::encap;
2629

30+
2731
int main(int /*argc*/, char** /*argv*/)
2832
{
2933
MLSDC<> mlsdc;

examples/advection_diffusion/spectral_transfer_1d.hpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@
66
#define _SPECTRAL_TRANSFER_1D_HPP_
77

88
#include <cassert>
9+
#include <cstdlib>
910
#include <memory>
1011

1112
#include <pfasst/encap/vector.hpp>
1213
#include <pfasst/encap/poly_interp.hpp>
1314

1415
#include "fft.hpp"
1516

17+
using namespace std;
18+
19+
1620
template<typename time = pfasst::time_precision>
1721
class SpectralTransfer1D
1822
: public pfasst::encap::PolyInterpMixin<time>
@@ -22,14 +26,13 @@ class SpectralTransfer1D
2226
FFT fft;
2327

2428
public:
25-
26-
void interpolate(shared_ptr<Encapsulation> dst, shared_ptr<const Encapsulation> src)
29+
void interpolate(shared_ptr<Encapsulation> dst, shared_ptr<const Encapsulation> src) override
2730
{
28-
auto& fine = as_vector<double,time>(dst);
29-
auto& crse = as_vector<double,time>(src);
31+
auto& fine = pfasst::encap::as_vector<double, time>(dst);
32+
auto& crse = pfasst::encap::as_vector<double, time>(src);
3033

31-
auto* crse_z = fft.forward(crse);
32-
auto* fine_z = fft.get_workspace(fine.size())->z;
34+
auto* crse_z = this->fft.forward(crse);
35+
auto* fine_z = this->fft.get_workspace(fine.size())->z;
3336

3437
for (size_t i = 0; i < fine.size(); i++) {
3538
fine_z[i] = 0.0;
@@ -45,21 +48,20 @@ class SpectralTransfer1D
4548
fine_z[fine.size() - crse.size() / 2 + i] = c * crse_z[crse.size() / 2 + i];
4649
}
4750

48-
fft.backward(fine);
51+
this->fft.backward(fine);
4952
}
5053

51-
void restrict(shared_ptr<Encapsulation> dst, shared_ptr<const Encapsulation> src)
54+
void restrict(shared_ptr<Encapsulation> dst, shared_ptr<const Encapsulation> src) override
5255
{
53-
auto& fine = as_vector<double,time>(src);
54-
auto& crse = as_vector<double,time>(dst);
56+
auto& fine = pfasst::encap::as_vector<double, time>(src);
57+
auto& crse = pfasst::encap::as_vector<double, time>(dst);
5558

5659
size_t xrat = fine.size() / crse.size();
5760

5861
for (size_t i = 0; i < crse.size(); i++) {
5962
crse[i] = fine[xrat*i];
6063
}
6164
}
62-
6365
};
6466

6567
#endif

examples/advection_diffusion/vanilla_sdc.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* This example uses a vanilla SDC sweeper.
55
*/
66

7+
#include <cstdlib>
78
#include <memory>
89

910
#include <fftw3.h>

0 commit comments

Comments
 (0)