Skip to content

Commit 281ad15

Browse files
committed
examples: scalar: a few little cleanups
Signed-off-by: Torbjörn Klatt <[email protected]>
1 parent 80e5b9d commit 281ad15

File tree

2 files changed

+29
-37
lines changed

2 files changed

+29
-37
lines changed

examples/scalar/scalar_sdc.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* explicitly.
1010
*
1111
*/
12-
12+
1313
#include<complex>
1414

1515
#include<pfasst.hpp>
@@ -23,26 +23,22 @@ double run_scalar_sdc(const size_t nsteps, const double dt, const size_t nnodes,
2323
const pfasst::QuadratureType nodetype)
2424
{
2525
pfasst::SDC<> sdc;
26-
27-
/*
28-
* For test equation, set initial value to \\( 1+0i )\\
29-
*/
26+
27+
// For test equation, set initial value to \\( 1+0i \\)
3028
const complex<double> y0 = complex<double>(1.0, 0.0);
3129

3230
auto nodes = pfasst::compute_nodes(nnodes, nodetype);
33-
34-
/*
35-
* This is a scalar example, so we use the encap::VectorFactory with fixed
36-
* length of 1 and complex type.
37-
*/
31+
32+
// This is a scalar example, so we use the encap::VectorFactory with fixed length of 1 and
33+
// complex type.
3834
auto factory = make_shared<pfasst::encap::VectorFactory<complex<double>>>(1);
3935
auto sweeper = make_shared<ScalarSweeper<>>(lambda, y0);
4036

4137
sweeper->set_nodes(nodes);
4238
sweeper->set_factory(factory);
4339

4440
sdc.add_level(sweeper);
45-
41+
4642
// Final time Tend = dt*nsteps
4743
sdc.set_duration(0.0, dt*nsteps, dt, niters);
4844
sdc.setup();
@@ -67,7 +63,7 @@ int main(int /*argc*/, char** /*argv*/)
6763
const size_t niters = 6;
6864
const complex<double> lambda = complex<double>(-1.0, 1.0);
6965
const pfasst::QuadratureType nodetype = pfasst::QuadratureType::GaussLobatto;
70-
66+
7167
run_scalar_sdc(nsteps, dt, nnodes, niters, lambda, nodetype);
7268
}
7369
#endif

examples/scalar/scalar_sweeper.hpp

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
using namespace std;
1111

12-
template<typename time = pfasst::time_precision>
13-
1412
/**
1513
* Sweeper for scalar test equation
1614
*
@@ -19,42 +17,41 @@ template<typename time = pfasst::time_precision>
1917
* with complex lambda using an IMEX scheme. Derived from the generic imex_sweeper.
2018
*
2119
*/
20+
template<typename time = pfasst::time_precision>
2221
class ScalarSweeper
2322
: public pfasst::encap::IMEXSweeper<time>
2423
{
25-
2624
private:
2725
typedef pfasst::encap::Encapsulation<time> encap_type;
28-
26+
2927
//! Define a type for a complex PFASST vector encapsulation.
3028
typedef pfasst::encap::VectorEncapsulation<complex<double>> complex_vector_type;
31-
32-
//! Parameter lambda and initial value u0
29+
30+
//! Parameter lambda and initial value \\( u_0 \\)
3331
complex<double> lambda, u0;
34-
35-
//! The complex unit i = sqrt(-1)
36-
complex<double> i_complex = complex<double>(0, 1);
37-
32+
33+
//! The complex unit \\( i = \\sqrt{-1} \\)
34+
const complex<double> i_complex = complex<double>(0, 1);
35+
3836
//! Error at the final time. For the scalar example, an analytical solution is known.
3937
double error;
40-
41-
//! Counters for how often f_expl_eval, f_impl_eval and impl_solve are called.
38+
39+
//! Counters for how often `f_expl_eval`, `f_impl_eval` and `impl_solve` are called.
4240
size_t n_f_expl_eval, n_f_impl_eval, n_impl_solve;
4341

4442
public:
45-
4643
/**
4744
* Generic constructor; initialize all function call counters with zero.
4845
* @param[in] lambda coefficient in test equation
49-
* @param[in] u0initial value at \\( t=0 \\)
46+
* @param[in] u0 initial value at \\( t=0 \\)
5047
*/
51-
ScalarSweeper(const complex<double> lambda, const complex<double> u0)
48+
ScalarSweeper(const complex<double>& lambda, const complex<double>& u0)
5249
: lambda(lambda)
5350
, u0(u0)
51+
, error(0.0)
5452
, n_f_expl_eval(0)
5553
, n_f_impl_eval(0)
5654
, n_impl_solve(0)
57-
, error(0.0)
5855
{}
5956

6057
/**
@@ -70,7 +67,8 @@ class ScalarSweeper
7067

7168
/**
7269
* Compute error between last state and exact solution at time tand print it to cout
73-
* @param[in] Time t
70+
*
71+
* @param[in] t Time
7472
*/
7573
void echo_error(time t)
7674
{
@@ -115,9 +113,9 @@ class ScalarSweeper
115113
}
116114

117115
/**
118-
* Computes the exact solution \\( u_0 \\exp \\left( \\lambda*t \\right) \\)
119-
* at a given time t.
120-
* @param[in] Time t
116+
* Computes the exact solution \\( u_0 \\exp \\left( \\lambda*t \\right) \\) at a given time t.
117+
*
118+
* @param[in] t Time
121119
*/
122120
void exact(complex_vector_type& q, time t)
123121
{
@@ -131,8 +129,7 @@ class ScalarSweeper
131129
}
132130

133131
/**
134-
* Evaluate the explicit part of the right hand side: Multiply with
135-
* \\( \\text{imag}(\\lambda) \\)
132+
* Evaluate the explicit part of the right hand side: Multiply with \\( \\text{imag}(\\lambda) \\)
136133
*/
137134
void f_expl_eval(shared_ptr<encap_type> f_encap,
138135
shared_ptr<encap_type> q_encap, time t) override
@@ -148,8 +145,7 @@ class ScalarSweeper
148145
}
149146

150147
/**
151-
* Evaluate the implicit part of the right hand side: Multiply with
152-
* \\( \\text{real}(\\lambda) \\)
148+
* Evaluate the implicit part of the right hand side: Multiply with \\( \\text{real}(\\lambda) \\)
153149
*/
154150
void f_impl_eval(shared_ptr<encap_type> f_encap,
155151
shared_ptr<encap_type> q_encap, time t) override
@@ -181,7 +177,7 @@ class ScalarSweeper
181177
// invert f_impl = multiply with inverse of real part of lambda
182178
double inv = 1.0 / (1.0 - double(dt) * real(this->lambda));
183179
q[0] = inv * rhs[0];
184-
180+
185181
// compute f_impl_eval of q[0], i.e. multiply with real(lambda)
186182
f[0] = real(this->lambda) * q[0];
187183

0 commit comments

Comments
 (0)