From cb41496e28d523a3b0d493056b7305c2ad03325a Mon Sep 17 00:00:00 2001 From: Sebastian Eibl <sebastian.eibl@fau.de> Date: Fri, 11 Dec 2020 10:39:09 +0100 Subject: [PATCH] enable clang-tidy 11 --- .clang-tidy | 7 ++++++- .gitlab-ci.yml | 4 ++-- .../NonUniformGrid/NonUniformGrid.cpp | 2 +- .../PoiseuilleChannel/PoiseuilleChannel.cpp | 4 +--- .../SchaeferTurek/SchaeferTurek.cpp | 4 ++-- .../CombinedResolvedUnresolved.cpp | 5 +---- src/blockforest/SetupBlock.cpp | 2 +- src/core/cell/CellInterval.cpp | 11 ++++------ src/core/grid_generator/HCPIterator.cpp | 9 +------- src/core/grid_generator/SCIterator.cpp | 9 +------- src/mesa_pd/collision_detection/EPA.cpp | 19 +++-------------- src/mesa_pd/domain/BlockForestDomain.cpp | 20 ++++++++---------- src/mesh/pe/rigid_body/ConvexPolyhedron.cpp | 21 ++++++++++--------- src/pe/collision/EPA.cpp | 19 +++-------------- src/pe/raytracing/Raytracer.cpp | 2 +- src/vtk/VTKOutput.cpp | 4 ++-- 16 files changed, 49 insertions(+), 93 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 935443d1e..910df6702 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -11,6 +11,7 @@ bugprone-*, misc-*, -misc-misplaced-const, +-misc-no-recursion, -misc-non-private-member-variables-in-classes, modernize-*, @@ -43,17 +44,21 @@ readability-deleted-default, readability-isolate-declaration, readability-misleading-indentation, readability-misplaced-array-index, +readability-non-const-parameter, +readability-redundant-access-specifiers, readability-redundant-control-flow, readability-redundant-declaration, readability-redundant-function-ptr-dereference, readability-redundant-preprocessor, readability-redundant-smartptr-get, readability-redundant-string-cstr, +readability-simplify-boolean-expr, readability-simplify-subscript-expr, readability-static-accessed-through-instance, readability-static-definition-in-anonymous-namespace, readability-string-compare, -readability-uniqueptr-delete-release +readability-uniqueptr-delete-release, +readability-use-anyofallof ' WarningsAsErrors: '*' diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5c7bc78b1..ceef61aeb 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1959,7 +1959,7 @@ doc: ############################################################################### clang-tidy: - image: i10git.cs.fau.de:5005/walberla/buildenvs/clang:10.0 + image: i10git.cs.fau.de:5005/walberla/buildenvs/clang:11.0 script: - $CXX --version - clang-tidy -version @@ -2481,4 +2481,4 @@ benchmark_ClangBuildAnalyzer: - docker-benchmark only: variables: - - $ENABLE_NIGHTLY_BUILDS \ No newline at end of file + - $ENABLE_NIGHTLY_BUILDS diff --git a/apps/benchmarks/NonUniformGrid/NonUniformGrid.cpp b/apps/benchmarks/NonUniformGrid/NonUniformGrid.cpp index c5f1df93e..631625909 100644 --- a/apps/benchmarks/NonUniformGrid/NonUniformGrid.cpp +++ b/apps/benchmarks/NonUniformGrid/NonUniformGrid.cpp @@ -308,7 +308,7 @@ void createSetupBlockForest( blockforest::SetupBlockForest & sforest, const Conf const memory_t memoryLimit = configBlock.getParameter< memory_t >( "memoryLimit", numeric_cast< memory_t >(256) ); sforest.balanceLoad( blockforest::StaticLevelwiseCurveBalance(true), numberOfProcesses, bufferProcesses, memoryLimit, true, - (bufferProcesses != uint_t(0)) ? true : false ); + bufferProcesses != uint_t(0) ); WALBERLA_LOG_INFO_ON_ROOT( "SetupBlockForest created successfully:\n" << sforest ); } diff --git a/apps/benchmarks/PoiseuilleChannel/PoiseuilleChannel.cpp b/apps/benchmarks/PoiseuilleChannel/PoiseuilleChannel.cpp index b72efbdcb..f5695a0f5 100644 --- a/apps/benchmarks/PoiseuilleChannel/PoiseuilleChannel.cpp +++ b/apps/benchmarks/PoiseuilleChannel/PoiseuilleChannel.cpp @@ -265,9 +265,7 @@ private: { const auto d = block.getAABB().sqSignedDistance( forest.getDomain().center() ); const real_t r = setup_.radius_L + bufferDistance_; - if( d > (r * r) ) - return true; - return false; + return d > (r * r); } return false; diff --git a/apps/benchmarks/SchaeferTurek/SchaeferTurek.cpp b/apps/benchmarks/SchaeferTurek/SchaeferTurek.cpp index 50c3a9244..c49dafff0 100644 --- a/apps/benchmarks/SchaeferTurek/SchaeferTurek.cpp +++ b/apps/benchmarks/SchaeferTurek/SchaeferTurek.cpp @@ -1318,9 +1318,9 @@ public: "cD (real area) [5], cL (real area) [6], cD (discrete area) [7], cL (discrete area) [8], " "pressure difference (in lattice units) [9], pressure difference (in Pa) [10], vortex velocity (in lattice units) [11], " "Strouhal number (real D) [12], Strouhal number (discrete D) [13]" << std::endl; - if( setup_.evaluatePressure == false ) + if( !setup_.evaluatePressure ) file << "# ATTENTION: pressure was not evaluated, pressure difference is set to zero!" << std::endl; - if( setup_.evaluateStrouhal == false ) + if( !setup_.evaluateStrouhal ) file << "# ATTENTION: vortex velocities were not evaluated, Strouhal number is set to zero!" << std::endl; file.close(); } diff --git a/apps/showcases/CombinedResolvedUnresolved/CombinedResolvedUnresolved.cpp b/apps/showcases/CombinedResolvedUnresolved/CombinedResolvedUnresolved.cpp index 8b0779629..5f4336e49 100644 --- a/apps/showcases/CombinedResolvedUnresolved/CombinedResolvedUnresolved.cpp +++ b/apps/showcases/CombinedResolvedUnresolved/CombinedResolvedUnresolved.cpp @@ -265,10 +265,7 @@ bool selectDPMBodies(pe::BodyID bodyID) { pe::SphereID sphere = static_cast< pe::SphereID >(bodyID); real_t radius = sphere->getRadius(); - if (radius <= real_t(0.5)) - return true; - else - return false; + return radius <= real_t(0.5); } bool selectMEMBodies(pe::BodyID bodyID) { return !selectDPMBodies(bodyID); } diff --git a/src/blockforest/SetupBlock.cpp b/src/blockforest/SetupBlock.cpp index 391012997..5b822acc1 100644 --- a/src/blockforest/SetupBlock.cpp +++ b/src/blockforest/SetupBlock.cpp @@ -37,7 +37,7 @@ void SetupBlock::assembleNeighborhood() { for( uint_t n = 0; n != 26; ++n ) for( uint_t i = 0; i != neighborhoodSection_[n].size(); ++i ) - if( neighborhood.insert( neighborhoodSection_[n][i] ).second == true ) + if( neighborhood.insert( neighborhoodSection_[n][i] ).second ) neighborhood_.push_back( neighborhoodSection_[n][i] ); } diff --git a/src/core/cell/CellInterval.cpp b/src/core/cell/CellInterval.cpp index 83ab0e33d..c4df1ea31 100644 --- a/src/core/cell/CellInterval.cpp +++ b/src/core/cell/CellInterval.cpp @@ -49,13 +49,10 @@ bool CellInterval::overlaps( const CellVector& cellVector ) const if( empty() ) return false; - for( const Cell & cell : cellVector ) - { - if( this->contains( cell ) ) - return true; - } - - return false; + return std::any_of(cellVector.begin(), + cellVector.end(), + [&](const Cell & cell) + {return contains( cell );}); } diff --git a/src/core/grid_generator/HCPIterator.cpp b/src/core/grid_generator/HCPIterator.cpp index 6be206c66..7d136ef42 100644 --- a/src/core/grid_generator/HCPIterator.cpp +++ b/src/core/grid_generator/HCPIterator.cpp @@ -168,14 +168,7 @@ bool HCPIterator::operator==(const HCPIterator &rhs) const { if (ended_ || rhs.ended_) { - if (ended_ == rhs.ended_) - { - return true; - } - else - { - return false; - } + return ended_ == rhs.ended_; } // WALBERLA_ASSERT_FLOAT_EQUAL(aabb_, rhs.aabb_, "Comparing iterators for different starting configurations!"); diff --git a/src/core/grid_generator/SCIterator.cpp b/src/core/grid_generator/SCIterator.cpp index 6c4399a64..254f97214 100644 --- a/src/core/grid_generator/SCIterator.cpp +++ b/src/core/grid_generator/SCIterator.cpp @@ -115,14 +115,7 @@ bool SCIterator::operator==(const SCIterator &rhs) const { if (ended_ || rhs.ended_) { - if (ended_ == rhs.ended_) - { - return true; - } - else - { - return false; - } + return ended_ == rhs.ended_; } // WALBERLA_ASSERT_FLOAT_EQUAL(aabb_, rhs.aabb_, "Comparing iterators for different starting configurations!"); diff --git a/src/mesa_pd/collision_detection/EPA.cpp b/src/mesa_pd/collision_detection/EPA.cpp index 3fb4ced43..ef5f21780 100644 --- a/src/mesa_pd/collision_detection/EPA.cpp +++ b/src/mesa_pd/collision_detection/EPA.cpp @@ -362,11 +362,7 @@ bool EPA::doEPA( Support &geom1, penetrationDepth = -supp_dist + real_t(2.0) * margin; retNormal = -ctr; - if(penetrationDepth < contactThreshold){ - return true; - }else{ - return false; - } + return penetrationDepth < contactThreshold; } else { //Reject sphere removeSupportMargin(epaVolume, supportA, supportB); @@ -500,12 +496,7 @@ bool EPA::doEPA( Support &geom1, std::cerr << "entryHeap[0]->getSqrDist()=" << entryHeap[0]->getSqrDist() << std::endl;*/ //std::cout << "EPA penetration depth: " << penetrationDepth << std::endl; - if(penetrationDepth < contactThreshold) { - return true; - } - - //no intersection found! - return false; + return penetrationDepth < contactThreshold; } //************************************************************************************************* @@ -722,11 +713,7 @@ inline bool EPA::originInTetrahedron( const Vec3& p0, const Vec3& p1, const Vec3 return false; } Vec3 normal3T = (p0 -p3) % (p1-p3); - if( (normal3T*p3 > real_t(0.0)) == (normal3T*p2 > real_t(0.0)) ) { - return false; - } - - return true; + return (normal3T*p3 > real_t(0.0)) != (normal3T*p2 > real_t(0.0)); } //************************************************************************************************* diff --git a/src/mesa_pd/domain/BlockForestDomain.cpp b/src/mesa_pd/domain/BlockForestDomain.cpp index cf5305270..c4d15778d 100644 --- a/src/mesa_pd/domain/BlockForestDomain.cpp +++ b/src/mesa_pd/domain/BlockForestDomain.cpp @@ -127,11 +127,10 @@ bool BlockForestDomain::isContainedInProcessSubdomain(const uint_t rank, const V bool BlockForestDomain::isContainedInLocalSubdomain(const Vec3& pt, const real_t& radius) const { - for (auto& aabb : localAABBs_) - { - if (isInsideAABB(pt, radius, aabb)) return true; - } - return false; + return std::any_of(localAABBs_.begin(), + localAABBs_.end(), + [&](auto& aabb) + {return isInsideAABB(pt, radius, aabb);}); } bool BlockForestDomain::isContainedInProcessSubdomain(const Vec3& pt, const real_t& radius) const @@ -153,12 +152,11 @@ bool BlockForestDomain::isContainedInProcessSubdomain(const Vec3& pt, const real } //intersects one of the neighboring subdomains? - for (auto& subdomain : neighborSubdomains_) - { - if (sqDistancePointToAABB(pt, subdomain.aabb) < radius*radius) return false; - } - - return true; + return std::none_of(neighborSubdomains_.begin(), + neighborSubdomains_.end(), + [&](const auto &subdomain) { + return sqDistancePointToAABB(pt, subdomain.aabb) < radius * radius; + }); } int BlockForestDomain::findContainingProcessRank(const Vec3& pt) const diff --git a/src/mesh/pe/rigid_body/ConvexPolyhedron.cpp b/src/mesh/pe/rigid_body/ConvexPolyhedron.cpp index ed500565e..2b505e09b 100644 --- a/src/mesh/pe/rigid_body/ConvexPolyhedron.cpp +++ b/src/mesh/pe/rigid_body/ConvexPolyhedron.cpp @@ -297,16 +297,17 @@ bool ConvexPolyhedron::containsRelPointImpl( real_t px, real_t py, real_t pz ) c if( px * px + py * py + pz * pz > boundingSphereRadius_ * boundingSphereRadius_ ) return false; - for(auto fh : mesh_.faces()) - { - const TriangleMesh::Normal & n = mesh_.normal(fh); // Plane normal - const TriangleMesh::Point & pp = mesh_.point(mesh_.to_vertex_handle(mesh_.halfedge_handle(fh))); // Point on plane - - if( n[0] * (px - pp[0]) + n[1] * (py - pp[1]) + n[2] * (pz - pp[2]) >= real_t(0) ) - return false; - } - - return true; + return std::none_of(mesh_.faces().begin(), + mesh_.faces().end(), + [&](auto fh) + { + //check if point is on positive side of the face + const TriangleMesh::Normal &n = mesh_.normal(fh); // Plane normal + const TriangleMesh::Point &pp = mesh_.point( + mesh_.to_vertex_handle(mesh_.halfedge_handle(fh))); // Point on plane + + return (n[0] * (px - pp[0]) + n[1] * (py - pp[1]) + n[2] * (pz - pp[2]) >= real_t(0)); + }); } //************************************************************************************************* diff --git a/src/pe/collision/EPA.cpp b/src/pe/collision/EPA.cpp index 6e7eb9755..171dc8594 100644 --- a/src/pe/collision/EPA.cpp +++ b/src/pe/collision/EPA.cpp @@ -350,11 +350,7 @@ bool EPA::doEPA( GeomPrimitive &geom1, GeomPrimitive &geom2, const GJK& gjk, Vec penetrationDepth = -supp_dist + real_t(2.0) * margin; retNormal = -ctr; - if(penetrationDepth < contactThreshold){ - return true; - }else{ - return false; - } + return penetrationDepth < contactThreshold; } else { //Reject sphere removeSupportMargin(epaVolume, supportA, supportB); @@ -488,12 +484,7 @@ bool EPA::doEPA( GeomPrimitive &geom1, GeomPrimitive &geom2, const GJK& gjk, Vec std::cerr << "entryHeap[0]->getSqrDist()=" << entryHeap[0]->getSqrDist() << std::endl;*/ //std::cout << "EPA penetration depth: " << penetrationDepth << std::endl; - if(penetrationDepth < contactThreshold) { - return true; - } - - //no intersection found! - return false; + return penetrationDepth < contactThreshold; } //************************************************************************************************* @@ -705,11 +696,7 @@ inline bool EPA::originInTetrahedron( const Vec3& p0, const Vec3& p1, const Vec3 return false; } Vec3 normal3T = (p0 -p3) % (p1-p3); - if( (normal3T*p3 > real_t(0.0)) == (normal3T*p2 > real_t(0.0)) ) { - return false; - } - - return true; + return (normal3T*p3 > real_t(0.0)) != (normal3T*p2 > real_t(0.0)); } //************************************************************************************************* diff --git a/src/pe/raytracing/Raytracer.cpp b/src/pe/raytracing/Raytracer.cpp index 631a5dfd3..344b8af99 100644 --- a/src/pe/raytracing/Raytracer.cpp +++ b/src/pe/raytracing/Raytracer.cpp @@ -31,7 +31,7 @@ namespace walberla { namespace pe { namespace raytracing { -void BodyIntersectionInfo_Comparator_MPI_OP( BodyIntersectionInfo *in, BodyIntersectionInfo *inout, int *len, MPI_Datatype *dptr) { +void BodyIntersectionInfo_Comparator_MPI_OP( BodyIntersectionInfo *in, BodyIntersectionInfo *inout, const int *len, MPI_Datatype *dptr) { WALBERLA_UNUSED(dptr); for (int i = 0; i < *len; ++i) { if (in->bodySystemID != 0 && inout->bodySystemID != 0) { diff --git a/src/vtk/VTKOutput.cpp b/src/vtk/VTKOutput.cpp index 8d8cf88f1..345d4fda3 100644 --- a/src/vtk/VTKOutput.cpp +++ b/src/vtk/VTKOutput.cpp @@ -458,7 +458,7 @@ void VTKOutput::computeOutputPoints( std::vector<Vector3<real_t> > & points, std outputPoint.assign( points.size(), true ); for( uint_t i = 0; i != points.size(); ++i ) { - bool included = ( aabbInclusionFilters_.empty() ) ? true : false; + bool included = aabbInclusionFilters_.empty(); for( auto aabb = aabbInclusionFilters_.begin(); aabb != aabbInclusionFilters_.end() && !included; ++aabb ) if( aabb->contains( points[ i ][ 0 ], points[ i ][ 1 ], points[ i ][ 2 ] ) ) included = true; if( !included ) @@ -665,7 +665,7 @@ void VTKOutput::computeOutputPolylines( std::vector< std::vector< Vector3< real_ auto outputPointIt = outputPolylinePointIt->begin(); for( auto pointIt = polylineIt->begin(); pointIt != polylineIt->end(); ++pointIt, ++outputPointIt ) { - bool included = ( aabbInclusionFilters_.empty() ) ? true : false; + bool included = aabbInclusionFilters_.empty(); for( auto aabb = aabbInclusionFilters_.begin(); aabb != aabbInclusionFilters_.end() && !included; ++aabb ) if( aabb->contains( ( *pointIt )[ 0 ], ( *pointIt )[ 1 ], ( *pointIt )[ 2 ] ) ) included = true; if( !included ) -- GitLab