Skip to content

Commit e8fc949

Browse files
committed
some code formatting tweaks
mainly reordered member functions according to order in base classes
1 parent d9e0ac8 commit e8fc949

File tree

4 files changed

+92
-90
lines changed

4 files changed

+92
-90
lines changed

examples/advection_diffusion/advection_diffusion_sweeper.hpp

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -73,60 +73,6 @@ class AdvectionDiffusionSweeper
7373
}
7474
//! @}
7575

76-
//! @{
77-
void exact(shared_ptr<Encapsulation<time>> q, time t)
78-
{
79-
this->exact(as_vector<double, time>(q), t);
80-
}
81-
82-
void exact(DVectorT& q, time t)
83-
{
84-
size_t n = q.size();
85-
double a = 1.0 / sqrt(4 * PI * nu * (t + t0));
86-
87-
for (size_t i = 0; i < n; i++) {
88-
q[i] = 0.0;
89-
}
90-
91-
for (int ii = -2; ii < 3; ii++) {
92-
for (size_t i = 0; i < n; i++) {
93-
double x = double(i) / n - 0.5 + ii - t * v;
94-
q[i] += a * exp(-x * x / (4 * nu * (t + t0)));
95-
}
96-
}
97-
}
98-
99-
void echo_error(time t, bool predict = false)
100-
{
101-
auto& qend = as_vector<double, time>(this->get_end_state());
102-
DVectorT qex(qend.size());
103-
104-
this->exact(qex, t);
105-
106-
double max = 0.0;
107-
for (size_t i = 0; i < qend.size(); i++) {
108-
double d = abs(qend[i] - qex[i]);
109-
if (d > max) { max = d; }
110-
}
111-
112-
auto n = this->get_controller()->get_step();
113-
auto k = this->get_controller()->get_iteration();
114-
cout << "err: " << n << " " << k << " " << scientific << max
115-
<< " (" << qend.size() << ", " << predict << ")"
116-
<< endl;
117-
118-
this->errors.insert(pair<pair<size_t, size_t>, double>(pair<size_t, size_t>(n, k), max));
119-
}
120-
121-
/**
122-
* retrieve errors at iterations and time nodes
123-
*/
124-
error_map get_errors()
125-
{
126-
return this->errors;
127-
}
128-
//! @}
129-
13076
//! @{
13177
/**
13278
* @copybrief pfasst::encap::IMEXSweeper::predict()
@@ -220,6 +166,60 @@ class AdvectionDiffusionSweeper
220166
}
221167
}
222168
//! @}
169+
170+
//! @{
171+
void exact(shared_ptr<Encapsulation<time>> q, time t)
172+
{
173+
this->exact(as_vector<double, time>(q), t);
174+
}
175+
176+
void exact(DVectorT& q, time t)
177+
{
178+
size_t n = q.size();
179+
double a = 1.0 / sqrt(4 * PI * nu * (t + t0));
180+
181+
for (size_t i = 0; i < n; i++) {
182+
q[i] = 0.0;
183+
}
184+
185+
for (int ii = -2; ii < 3; ii++) {
186+
for (size_t i = 0; i < n; i++) {
187+
double x = double(i) / n - 0.5 + ii - t * v;
188+
q[i] += a * exp(-x * x / (4 * nu * (t + t0)));
189+
}
190+
}
191+
}
192+
193+
void echo_error(time t, bool predict = false)
194+
{
195+
auto& qend = as_vector<double, time>(this->get_end_state());
196+
DVectorT qex(qend.size());
197+
198+
this->exact(qex, t);
199+
200+
double max = 0.0;
201+
for (size_t i = 0; i < qend.size(); i++) {
202+
double d = abs(qend[i] - qex[i]);
203+
if (d > max) { max = d; }
204+
}
205+
206+
auto n = this->get_controller()->get_step();
207+
auto k = this->get_controller()->get_iteration();
208+
cout << "err: " << n << " " << k << " " << scientific << max
209+
<< " (" << qend.size() << ", " << predict << ")"
210+
<< endl;
211+
212+
this->errors.insert(pair<pair<size_t, size_t>, double>(pair<size_t, size_t>(n, k), max));
213+
}
214+
215+
/**
216+
* retrieve errors at iterations and time nodes
217+
*/
218+
error_map get_errors()
219+
{
220+
return this->errors;
221+
}
222+
//! @}
223223
};
224224

225225
#endif

include/pfasst/encap/encap_sweeper.hpp

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -42,38 +42,6 @@ namespace pfasst
4242
{}
4343
//! @}
4444

45-
//! @{
46-
virtual void spread() override
47-
{
48-
for (size_t m = 1; m < nodes.size(); m++) {
49-
this->get_state(m)->copy(this->get_state(0));
50-
}
51-
}
52-
53-
virtual void post(ICommunicator* comm, int tag) override
54-
{
55-
this->get_state(0)->post(comm, tag);
56-
}
57-
58-
virtual void send(ICommunicator* comm, int tag, bool blocking) override
59-
{
60-
this->get_state(this->get_nodes().size() - 1)->send(comm, tag, blocking);
61-
}
62-
63-
virtual void recv(ICommunicator* comm, int tag, bool blocking) override
64-
{
65-
this->get_state(0)->recv(comm, tag, blocking);
66-
}
67-
68-
virtual void broadcast(ICommunicator* comm) override
69-
{
70-
if (comm->rank() == comm->size() - 1) {
71-
this->get_state(0)->copy(this->get_state(this->get_nodes().size() - 1));
72-
}
73-
this->get_state(0)->broadcast(comm);
74-
}
75-
//! @}
76-
7745
//! @{
7846
virtual void set_nodes(vector<time> nodes)
7947
{
@@ -175,6 +143,13 @@ namespace pfasst
175143
throw NotImplementedYet("sweeper");
176144
}
177145

146+
virtual void spread() override
147+
{
148+
for (size_t m = 1; m < nodes.size(); m++) {
149+
this->get_state(m)->copy(this->get_state(0));
150+
}
151+
}
152+
178153
/**
179154
* evaluates the right hand side at given time node
180155
*
@@ -206,6 +181,31 @@ namespace pfasst
206181
throw NotImplementedYet("sweeper");
207182
}
208183
//! @}
184+
185+
//! @{
186+
virtual void post(ICommunicator* comm, int tag) override
187+
{
188+
this->get_state(0)->post(comm, tag);
189+
}
190+
191+
virtual void send(ICommunicator* comm, int tag, bool blocking) override
192+
{
193+
this->get_state(this->get_nodes().size() - 1)->send(comm, tag, blocking);
194+
}
195+
196+
virtual void recv(ICommunicator* comm, int tag, bool blocking) override
197+
{
198+
this->get_state(0)->recv(comm, tag, blocking);
199+
}
200+
201+
virtual void broadcast(ICommunicator* comm) override
202+
{
203+
if (comm->rank() == comm->size() - 1) {
204+
this->get_state(0)->copy(this->get_state(this->get_nodes().size() - 1));
205+
}
206+
this->get_state(0)->broadcast(comm);
207+
}
208+
//! @}
209209
};
210210

211211

include/pfasst/encap/imex_sweeper.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ namespace pfasst
242242
* @param[in] initial if `true` the explicit and implicit part of the right hand side of the
243243
* ODE get evaluated with the initial value
244244
*/
245-
virtual void predict(bool initial)
245+
virtual void predict(bool initial) override
246246
{
247247
const auto nodes = this->get_nodes();
248248
const size_t nnodes = nodes.size();
@@ -268,7 +268,7 @@ namespace pfasst
268268
if (this->last_node_is_virtual()) { this->integrate_end_state(dt); }
269269
}
270270

271-
virtual void sweep()
271+
virtual void sweep() override
272272
{
273273
const auto nodes = this->get_nodes();
274274
const size_t nnodes = nodes.size();

include/pfasst/interfaces.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ namespace pfasst
3131
* Used by PFASST to mark methods that are required for a particular algorithm (SDC/MLSDC/PFASST)
3232
* that may not be necessary for all others.
3333
*/
34-
class NotImplementedYet : public exception
34+
class NotImplementedYet
35+
: public exception
3536
{
3637
string msg;
3738
public:
@@ -51,7 +52,8 @@ namespace pfasst
5152
*
5253
* Thrown when a PFASST routine is passed an invalid value.
5354
*/
54-
class ValueError : public exception
55+
class ValueError
56+
: public exception
5557
{
5658
string msg;
5759
public:

0 commit comments

Comments
 (0)