Skip to content

Commit 4016a8d

Browse files
committed
Merge pull request #181 from torbjoernk/feature/fix-cppcheck-warns
fixing a couple of CppCheck warnings related to style and performance
2 parents 9238cba + d4c8232 commit 4016a8d

File tree

9 files changed

+15
-19
lines changed

9 files changed

+15
-19
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ htmlcov/
242242
.cache
243243
nosetests.xml
244244
coverage.xml
245+
cppcheck.xml
246+
/cppcheck
245247

246248
# Translations
247249
*.mo

examples/boris/boris_sweeper.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ namespace pfasst
182182
const scalar energy, const scalar drift, const scalar residual,
183183
const bool with_center = true);
184184
void update_position(const size_t m, const time dt, const time ds);
185-
void update_velocity(const size_t m, const time ds, const vector<time> nodes);
185+
void update_velocity(const size_t m, const time ds, const vector<time>& nodes);
186186

187187
public:
188188
//! @{

examples/boris/boris_sweeper_impl.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ namespace pfasst
139139
BCVLOG(9) << "writing center particle to file";
140140
this->data_stream_fmt % (iter+1) % sweep % -1
141141
% center[0] % center[1] % center[2]
142+
// cppcheck-suppress zerodiv
142143
% 0 % 0 % 0
143144
% energy % drift % residual;
144145
this->data_stream << this->data_stream_fmt << endl;
@@ -154,6 +155,7 @@ namespace pfasst
154155
this->log_indent->increment(9);
155156
for (size_t p = 0; p < cloud->size(); ++p) {
156157
BCVLOG(9) << "writing cloud particle " << p << " to file";
158+
// cppcheck-suppress zerodiv
157159
this->data_stream_fmt % (iter+1) % sweep % p
158160
% cloud->positions()[p * cloud->dim()] % cloud->positions()[p * cloud->dim() + 1] % cloud->positions()[p * cloud->dim() + 2]
159161
% cloud->velocities()[p * cloud->dim()] % cloud->velocities()[p * cloud->dim() + 1] % cloud->velocities()[p * cloud->dim() + 2]
@@ -194,7 +196,7 @@ namespace pfasst
194196
}
195197

196198
template<typename scalar, typename time>
197-
void BorisSweeper<scalar, time>::update_velocity(const size_t m, const time ds, const vector<time> nodes)
199+
void BorisSweeper<scalar, time>::update_velocity(const size_t m, const time ds, const vector<time>& nodes)
198200
{
199201
BCVLOG(4) << "updating velocity (" << m << "->" << m+1 << ") with ds=" << ds;
200202
this->log_indent->increment(4);

examples/boris/particle.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace pfasst
3030
* @ingroup Boris
3131
*/
3232
template<typename T>
33-
inline el::base::type::ostream_t& operator<<(el::base::type::ostream_t& os, const vector<T> vec);
33+
inline el::base::type::ostream_t& operator<<(el::base::type::ostream_t& os, const vector<T>& vec);
3434

3535

3636
/**

examples/boris/particle_impl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace pfasst
1212
namespace boris
1313
{
1414
template<typename T>
15-
inline el::base::type::ostream_t& operator<<(el::base::type::ostream_t& os, const vector<T> vec) {
15+
inline el::base::type::ostream_t& operator<<(el::base::type::ostream_t& os, const vector<T>& vec) {
1616
os << "[";
1717
for (auto iter = vec.cbegin(); iter != vec.cend(); ++iter) {
1818
os << *iter;

examples/vanderpol/vdp_sweeper.hpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -271,18 +271,15 @@ namespace pfasst
271271
double residual = this->newton_tol + 1.0;
272272
size_t iter = 0.0;
273273

274-
// initialize temporary variables for use in loop
275-
double a, b, c, f0, f1;
276-
277274
// Initial value for q is just rhs: For small dt, P is approximately the identity
278275
q[0] = rhs[0];
279276
q[1] = rhs[1];
280277

281278
// NEWTON ITERATION: q_new = q + inv(J(q))*(-f(q))
282279
do {
283280
// Store -P(q) in f0, f1
284-
f0 = -( q[0] - dt*q[1] - rhs[0] );
285-
f1 = -( q[1] - dt*( this->nu*(1-q[0]*q[0])*q[1]-q[0]) - rhs[1] );
281+
double f0 = -( q[0] - dt*q[1] - rhs[0] );
282+
double f1 = -( q[1] - dt*( this->nu*(1-q[0]*q[0])*q[1]-q[0]) - rhs[1] );
286283

287284
/**
288285
* The Jacobian of the right hand side of the van der Pol oscillator for \\( q=[x;y] \\)
@@ -307,9 +304,9 @@ namespace pfasst
307304
*
308305
* with \\( c:=2*\\nu*x*y*dt^2 + dt^2 + dt*x^2 - dt + 1 \\)
309306
*/
310-
a = dt*q[0]*q[0]-dt+1.0;
311-
b = -2.0*dt*this->nu*q[0]*q[1]-dt;
312-
c = 2.0*this->nu*q[0]*q[1]*dt*dt + dt*dt + dt*q[0]*q[0] - dt + 1.0;
307+
double a = dt * q[0] * q[0] - dt + 1.0;
308+
double b = -2.0 * dt * this->nu * q[0] * q[1] - dt;
309+
double c = 2.0 * this->nu * q[0] * q[1] * dt * dt + dt * dt + dt * q[0] * q[0] - dt + 1.0;
313310

314311
// Compute inv(J(q))*(-f(q)) and store it in f
315312
f[0] = (1.0/c)*( a*f0 + dt*f1 );

include/pfasst/encap/implicit_sweeper.hpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,6 @@ namespace pfasst
8181
*/
8282
vector<shared_ptr<Encapsulation<time>>> s_integrals;
8383

84-
/**
85-
* FAS corrections \\( \\tau \\) at all time nodes of the current iteration.
86-
*/
87-
vector<shared_ptr<Encapsulation<time>>> fas_corrections;
88-
8984
/**
9085
* Values of the implicit part of the right hand side \\( F_{impl}(t,u) \\) at all time nodes of the current
9186
* iteration.

tests/examples/advection_diffusion/test_mpi_advection_diffusion.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ int main(int argc, char** argv)
7373
pfasst::examples::advection_diffusion::AdvectionDiffusionSweeper<>::init_opts,
7474
pfasst::examples::advection_diffusion::AdvectionDiffusionSweeper<>::init_logs);
7575
int result = 1, max_result; // GTest return value 1 (failure), 0 (success)
76+
// cppcheck-suppress redundantAssignment
7677
result = RUN_ALL_TESTS();
7778
MPI_Allreduce(&result, &max_result, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD);
7879
MPI_Finalize();

tests/test_quadrature.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,8 @@ class QmatTest
293293

294294
TEST_P(QmatTest, AllNodes)
295295
{
296-
long double qsum;
297296
for (int m = 0; m < this->quad->get_q_mat().rows(); ++m) {
298-
qsum = 0;
297+
long double qsum = 0;
299298
for (int j = 0; j < this->quad->get_q_mat().cols(); ++j) {
300299
qsum += this->quad->get_q_mat()(m,j);
301300
}

0 commit comments

Comments
 (0)