From 24ce4bfeefea9da242f8f17c9aa881a7f0528f14 Mon Sep 17 00:00:00 2001
From: Sebastian Eibl <sebastian.eibl@fau.de>
Date: Mon, 27 Aug 2018 13:46:20 +0200
Subject: [PATCH] clang-tidy
 -checks=-*,performance-unnecessary-copy-initialization

---
 .clang-tidy                                          |  2 +-
 .../PeriodicGranularGas/PeriodicGranularGas.cpp      |  2 +-
 apps/benchmarks/SchaeferTurek/SchaeferTurek.cpp      | 12 ++++++------
 apps/tutorials/pe/01_ConfinedGas.cpp                 |  2 +-
 apps/tutorials/pe/02_ConfinedGasExtended.cpp         |  2 +-
 src/blockforest/loadbalancing/DynamicParMetis.cpp    |  2 +-
 src/pe/collision/EPA.cpp                             |  2 +-
 src/pe/collision/GJK.cpp                             |  8 ++++----
 src/pe_coupling/geometry/PeIntersectionRatio.cpp     |  6 +++---
 tests/core/math/GenericAABBTest.cpp                  |  7 +++++--
 tests/field/FieldTiming.cpp                          |  4 ++--
 tests/mesh/PeVTKMeshWriterTest.cpp                   |  2 +-
 .../SettlingSphereMEMDynamicRefinement.cpp           |  2 +-
 .../momentum_exchange_method/SquirmerTest.cpp        |  2 +-
 tests/pe_coupling/utility/PeSubCyclingTest.cpp       | 10 +++++-----
 15 files changed, 34 insertions(+), 31 deletions(-)

diff --git a/.clang-tidy b/.clang-tidy
index f56e5b4e9..09c0280df 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -1,5 +1,5 @@
 ---
-Checks:          '-*,bugprone-*,misc-string-compare,modernize-*,performance-faster-string-find,-modernize-use-auto,-modernize-loop-convert,-modernize-pass-by-value,-modernize-raw-string-literal,-modernize-use-using,-modernize-avoid-bind,-modernize-return-braced-init-list,-modernize-use-transparent-functors,-modernize-redundant-void-arg'
+Checks:          '-*,bugprone-*,misc-string-compare,modernize-*,performance-faster-string-find,performance-unnecessary-copy-initialization,-modernize-use-auto,-modernize-loop-convert,-modernize-pass-by-value,-modernize-raw-string-literal,-modernize-use-using,-modernize-avoid-bind,-modernize-return-braced-init-list,-modernize-use-transparent-functors,-modernize-redundant-void-arg'
 WarningsAsErrors: '*'
 HeaderFilterRegex: ''
 AnalyzeTemporaryDtors: false
diff --git a/apps/benchmarks/PeriodicGranularGas/PeriodicGranularGas.cpp b/apps/benchmarks/PeriodicGranularGas/PeriodicGranularGas.cpp
index db8edbea7..1866ca5c5 100644
--- a/apps/benchmarks/PeriodicGranularGas/PeriodicGranularGas.cpp
+++ b/apps/benchmarks/PeriodicGranularGas/PeriodicGranularGas.cpp
@@ -182,7 +182,7 @@ int main( int argc, char ** argv )
    MaterialID     material = createMaterial( "granular", real_t( 1.0 ), 0, static_cof, dynamic_cof, real_t( 0.5 ), 1, 1, 0, 0 );
 
    auto simulationDomain = forest->getDomain();
-   auto generationDomain = simulationDomain; // simulationDomain.getExtended(-real_c(0.5) * spacing);
+   const auto& generationDomain = simulationDomain; // simulationDomain.getExtended(-real_c(0.5) * spacing);
 
    const real_t spacing(1.0);
    const real_t radius(0.5);
diff --git a/apps/benchmarks/SchaeferTurek/SchaeferTurek.cpp b/apps/benchmarks/SchaeferTurek/SchaeferTurek.cpp
index 6dfb5a2a8..09d3a5a51 100644
--- a/apps/benchmarks/SchaeferTurek/SchaeferTurek.cpp
+++ b/apps/benchmarks/SchaeferTurek/SchaeferTurek.cpp
@@ -1125,12 +1125,12 @@ void VorticityRefinement< VectorField_T, Filter_T, Pseudo2D >::operator()( std::
          if( filter_(x,y,z) && filter_(x+one,y,z) && filter_(x-one,y,z) && filter_(x,y+one,z) && filter_(x,y-one,z) &&
                   ( Pseudo2D || (filter_(x,y,z+one) && filter_(x,y,z-one)) ) )
          {
-            const Vector3< real_t > xa = u->get(x+one,y,z);
-            const Vector3< real_t > xb = u->get(x-one,y,z);
-            const Vector3< real_t > ya = u->get(x,y+one,z);
-            const Vector3< real_t > yb = u->get(x,y-one,z);
-            const Vector3< real_t > za = Pseudo2D ? Vector3< real_t >(0) : u->get(x,y,z+one);
-            const Vector3< real_t > zb = Pseudo2D ? Vector3< real_t >(0) : u->get(x,y,z-one);
+            const Vector3< real_t >& xa = u->get(x+one,y,z);
+            const Vector3< real_t >& xb = u->get(x-one,y,z);
+            const Vector3< real_t >& ya = u->get(x,y+one,z);
+            const Vector3< real_t >& yb = u->get(x,y-one,z);
+            const Vector3< real_t >  za = Pseudo2D ? Vector3< real_t >(0) : u->get(x,y,z+one);
+            const Vector3< real_t >  zb = Pseudo2D ? Vector3< real_t >(0) : u->get(x,y,z-one);
 
             // ATTENTION: dx/y/z is assumed to be equal to '1'!
             const real_t duzdy = half * ( ya[2] - yb[2] );
diff --git a/apps/tutorials/pe/01_ConfinedGas.cpp b/apps/tutorials/pe/01_ConfinedGas.cpp
index ad29563e6..e674e83a6 100644
--- a/apps/tutorials/pe/01_ConfinedGas.cpp
+++ b/apps/tutorials/pe/01_ConfinedGas.cpp
@@ -101,7 +101,7 @@ int main( int argc, char ** argv )
    //! [Material]
 
    auto simulationDomain = forest->getDomain();
-   auto generationDomain = simulationDomain; // simulationDomain.getExtended(-real_c(0.5) * spacing);
+   const auto& generationDomain = simulationDomain; // simulationDomain.getExtended(-real_c(0.5) * spacing);
    //! [Planes]
    createPlane(*globalBodyStorage, 0, Vec3(1,0,0), simulationDomain.minCorner(), material );
    createPlane(*globalBodyStorage, 0, Vec3(-1,0,0), simulationDomain.maxCorner(), material );
diff --git a/apps/tutorials/pe/02_ConfinedGasExtended.cpp b/apps/tutorials/pe/02_ConfinedGasExtended.cpp
index 014bda1a8..7e0e027a7 100644
--- a/apps/tutorials/pe/02_ConfinedGasExtended.cpp
+++ b/apps/tutorials/pe/02_ConfinedGasExtended.cpp
@@ -199,7 +199,7 @@ int main( int argc, char ** argv )
    MaterialID     material = createMaterial( "granular", real_t( 1.0 ), 0, static_cof, dynamic_cof, real_t( 0.5 ), 1, 1, 0, 0 );
 
    auto simulationDomain = forest->getDomain();
-   auto generationDomain = simulationDomain; // simulationDomain.getExtended(-real_c(0.5) * spacing);
+   const auto& generationDomain = simulationDomain; // simulationDomain.getExtended(-real_c(0.5) * spacing);
    createPlane(*globalBodyStorage, 0, Vec3(1,0,0), simulationDomain.minCorner(), material );
    createPlane(*globalBodyStorage, 0, Vec3(-1,0,0), simulationDomain.maxCorner(), material );
    createPlane(*globalBodyStorage, 0, Vec3(0,1,0), simulationDomain.minCorner(), material );
diff --git a/src/blockforest/loadbalancing/DynamicParMetis.cpp b/src/blockforest/loadbalancing/DynamicParMetis.cpp
index 369339eee..59d43a364 100644
--- a/src/blockforest/loadbalancing/DynamicParMetis.cpp
+++ b/src/blockforest/loadbalancing/DynamicParMetis.cpp
@@ -70,7 +70,7 @@ std::map< blockforest::BlockID, uint_t > getBlockIdToSequenceMapping( const Phan
       mapping.insert( std::make_pair( it->first->getId(), sequenceId++ ) );
    WALBERLA_ASSERT_EQUAL( sequenceId, blockSequenceRange.second );
 
-   const std::vector<uint_t> neighborProcesses = phantomForest.getNeighboringProcesses();
+   const std::vector<uint_t>& neighborProcesses = phantomForest.getNeighboringProcesses();
    
    mpi::BufferSystem bs( comm );
 
diff --git a/src/pe/collision/EPA.cpp b/src/pe/collision/EPA.cpp
index e8a200048..b2738d903 100644
--- a/src/pe/collision/EPA.cpp
+++ b/src/pe/collision/EPA.cpp
@@ -715,7 +715,7 @@ inline bool EPA::originInTetrahedron( const Vec3& p0, const Vec3& p1, const Vec3
 inline bool EPA::originInTetrahedronVolumeMethod( const Vec3& A, const Vec3& B, const Vec3& C,
                                                   const Vec3& D )
 {
-   Vec3 aoT = A;
+   const Vec3& aoT = A;
    if((aoT * (B % C)) <= real_t(0.0)) {
       //if volume of ABC and Origin <0.0 than the origin is on the wrong side of ABC
       //http://mathworld.wolfram.com/Tetrahedron.html volume formula
diff --git a/src/pe/collision/GJK.cpp b/src/pe/collision/GJK.cpp
index b681b7805..e25c62b5e 100644
--- a/src/pe/collision/GJK.cpp
+++ b/src/pe/collision/GJK.cpp
@@ -341,7 +341,7 @@ inline real_t GJK::calcDistance( Vec3& normal, Vec3& contactPoint )
       //Vec3 ac= C - A;
       //Vec3 bc= C - B;
       Vec3& n = d_; //we already know the normal
-      Vec3  nT = n;
+      const Vec3&  nT = n;
 
       real_t vc = nT * (A % B);
       real_t va = nT * (B % C);
@@ -395,7 +395,7 @@ bool GJK::simplex2(Vec3& d)
    const Vec3& A = simplex_[1];  //The Point last added to the simplex
    const Vec3& B = simplex_[0];  //The Point that was already in the simplex
    const Vec3  AO  = -A;         //The vector A->O with 0 the origin
-   const Vec3  AOt = AO;         //The transposed vector A->O with O the origin
+   const Vec3&  AOt = AO;         //The transposed vector A->O with O the origin
    const Vec3  AB  = B-A;        //The vector A->B
 
    if( sameDirection(AOt, AB) ) {
@@ -437,7 +437,7 @@ bool GJK::simplex3(Vec3& d)
    //ABC is a conterclockwise triangle
 
    const Vec3  AO  = -A;        //The vector A->O with 0 the origin
-   const Vec3  AOt = AO;        //The transposed vector A->O with O the origin
+   const Vec3&  AOt = AO;        //The transposed vector A->O with O the origin
    const Vec3  AB  = B-A;       //The vector A->B
    const Vec3  AC  = C-A;       //The vector A->C
    const Vec3  ABC = AB%AC;     //The the normal pointing towards the viewer if he sees a CCW triangle ABC
@@ -566,7 +566,7 @@ bool GJK::simplex4(Vec3& d)
    //BCD is a clockwise triangle wenn seen from A
 
    const Vec3  AO  = -A;      //The vector A->O with 0 the origin
-   const Vec3  AOt = AO;      //The transposed vector A->O with O the origin
+   const Vec3&  AOt = AO;      //The transposed vector A->O with O the origin
    const Vec3  AB  = B-A;     //The vector A->B
    const Vec3  AC  = C-A;     //The vector A->C
    const Vec3  AD  = D-A;     //The vector A-D
diff --git a/src/pe_coupling/geometry/PeIntersectionRatio.cpp b/src/pe_coupling/geometry/PeIntersectionRatio.cpp
index bd5518724..8d9fde471 100644
--- a/src/pe_coupling/geometry/PeIntersectionRatio.cpp
+++ b/src/pe_coupling/geometry/PeIntersectionRatio.cpp
@@ -35,7 +35,7 @@ real_t intersectionRatioSpherePe( const pe::Sphere & sphere,
    WALBERLA_ASSERT(  walberla::geometry::contains( sphere, fluidPoint + direction ), "fluidPoint + direction: " << fluidPoint + direction );
 
    // get the physical sphere center
-   Vector3< real_t > sphereCenter( sphere.getPosition() );
+   const Vector3< real_t >& sphereCenter( sphere.getPosition() );
 
    real_t dirLength = direction.length();
    Vector3< real_t > l = sphereCenter - fluidPoint;
@@ -62,8 +62,8 @@ real_t intersectionRatioPlanePe( const pe::Plane & plane,
    WALBERLA_ASSERT(  walberla::geometry::contains<pe::RigidBody>( plane, fluidPoint + direction ), "fluidPoint + direction: " << fluidPoint + direction );
 
 
-   Vector3<real_t> planeCenter( plane.getPosition() );
-   Vector3<real_t> planeNormal( plane.getNormal() );
+   const Vector3<real_t>& planeCenter( plane.getPosition() );
+   const Vector3<real_t>& planeNormal( plane.getNormal() );
 
    real_t denom = planeNormal * direction;
 
diff --git a/tests/core/math/GenericAABBTest.cpp b/tests/core/math/GenericAABBTest.cpp
index e27731aae..e78e6890d 100644
--- a/tests/core/math/GenericAABBTest.cpp
+++ b/tests/core/math/GenericAABBTest.cpp
@@ -364,7 +364,7 @@ void testConstructors( const T x0, const T y0, const T z0, const T x1, const T y
 
    {
       GenericAABB< T > toBeCopied( x0, y0, z0, x1, y1, z1 );
-      GenericAABB< T > refAABB( toBeCopied );
+      const GenericAABB< T > refAABB( toBeCopied );
       WALBERLA_CHECK_IDENTICAL( refAABB.minCorner()[0], std::min( x0, x1 ) );
       WALBERLA_CHECK_IDENTICAL( refAABB.minCorner()[1], std::min( y0, y1 ) );
       WALBERLA_CHECK_IDENTICAL( refAABB.minCorner()[2], std::min( z0, z1 ) );
@@ -645,7 +645,10 @@ int main(int argc, char**argv)
    GenericAABB< double > doubleAABB( 1.0, 1.0, 1.0, 2.0, 2.0 ,2.0 );
    
    GenericAABB< double > copiedAABB0( floatAABB );
-   GenericAABB< double > copiedAABB1( doubleAABB );
+   const GenericAABB< double > copiedAABB1( doubleAABB );
+
+   WALBERLA_UNUSED(copiedAABB0);
+   WALBERLA_UNUSED(copiedAABB1);
    
    randomTest<float>();
    randomTest<double>();
diff --git a/tests/field/FieldTiming.cpp b/tests/field/FieldTiming.cpp
index 4eea53a33..283f0dc5f 100644
--- a/tests/field/FieldTiming.cpp
+++ b/tests/field/FieldTiming.cpp
@@ -111,7 +111,7 @@ double sumIteratorCachedEnd(const DoubleField & field)
    //WALBERLA_CHECK_EQUAL(field.layout() == fzyx );
    double sum = 0;
 
-   const DoubleField::const_iterator myEnd = field.end();
+   const DoubleField::const_iterator& myEnd = field.end();
    for(DoubleField::const_iterator i = field.begin(); i != myEnd; ++i)
       sum += *i;
 
@@ -173,7 +173,7 @@ double xyzfTest ( const DoubleField & field )
 {
    double sum = 0;
    double sum2 = 0;
-   const DoubleField::const_iterator myEnd = field.end();
+   const DoubleField::const_iterator& myEnd = field.end();
    for(DoubleField::const_iterator i = field.begin(); i != myEnd; ++i)
    {
       sum += *i;
diff --git a/tests/mesh/PeVTKMeshWriterTest.cpp b/tests/mesh/PeVTKMeshWriterTest.cpp
index 0c56132e3..147b3d456 100644
--- a/tests/mesh/PeVTKMeshWriterTest.cpp
+++ b/tests/mesh/PeVTKMeshWriterTest.cpp
@@ -166,7 +166,7 @@ int main( int argc, char ** argv )
    MaterialID     material = createMaterial( "granular", real_t( 1.0 ), 0, static_cof, dynamic_cof, real_t( 0.5 ), 1, 1, 0, 0 );
 
    auto simulationDomain = forest->getDomain();
-   auto generationDomain = simulationDomain; // simulationDomain.getExtended(-real_c(0.5) * spacing);
+   const auto& generationDomain = simulationDomain; // simulationDomain.getExtended(-real_c(0.5) * spacing);
    createPlane(*globalBodyStorage, 0, Vec3(1,0,0), simulationDomain.minCorner(), material );
    createPlane(*globalBodyStorage, 0, Vec3(-1,0,0), simulationDomain.maxCorner(), material );
    createPlane(*globalBodyStorage, 0, Vec3(0,1,0), simulationDomain.minCorner(), material );
diff --git a/tests/pe_coupling/momentum_exchange_method/SettlingSphereMEMDynamicRefinement.cpp b/tests/pe_coupling/momentum_exchange_method/SettlingSphereMEMDynamicRefinement.cpp
index 3104a3c88..4357e587d 100644
--- a/tests/pe_coupling/momentum_exchange_method/SettlingSphereMEMDynamicRefinement.cpp
+++ b/tests/pe_coupling/momentum_exchange_method/SettlingSphereMEMDynamicRefinement.cpp
@@ -175,7 +175,7 @@ private:
       // add bodies of all neighboring blocks
       for(uint_t i = 0; i < block->getNeighborhoodSize(); ++i)
       {
-         BlockID neighborBlockID = block->getNeighborId(i);
+         const BlockID& neighborBlockID = block->getNeighborId(i);
          const auto infoItNeighbor = infoCollection_->find(neighborBlockID);
          numBodies += infoItNeighbor->second.numberOfLocalBodies;
          numBodies += infoItNeighbor->second.numberOfShadowBodies;
diff --git a/tests/pe_coupling/momentum_exchange_method/SquirmerTest.cpp b/tests/pe_coupling/momentum_exchange_method/SquirmerTest.cpp
index ecc2e6642..adca45086 100644
--- a/tests/pe_coupling/momentum_exchange_method/SquirmerTest.cpp
+++ b/tests/pe_coupling/momentum_exchange_method/SquirmerTest.cpp
@@ -420,7 +420,7 @@ int main(int argc, char **argv) {
    auto b2 = beta * b1;
    auto e = q.rotate(up).getNormalized();
    auto radius = R;
-   auto squirmer_pos = position;
+   const auto& squirmer_pos = position;
 
    real_t abs_tolerance = real_c(0.0026);
    real_t rel_tolerance = real_c(0.10);
diff --git a/tests/pe_coupling/utility/PeSubCyclingTest.cpp b/tests/pe_coupling/utility/PeSubCyclingTest.cpp
index fb869661f..54268c111 100644
--- a/tests/pe_coupling/utility/PeSubCyclingTest.cpp
+++ b/tests/pe_coupling/utility/PeSubCyclingTest.cpp
@@ -124,7 +124,7 @@ int main( int argc, char **argv )
    Vector3<real_t> expectedAngularVel(real_t(0));
    {
 
-      Vector3<real_t> startPos = positionInsideBlock;
+      const Vector3<real_t>& startPos = positionInsideBlock;
 
       pe::createSphere(*globalBodyStorage, blocks->getBlockStorage(), bodyStorageID, 0,
                        startPos, radius, sphereMaterialID, false, true, false);
@@ -185,7 +185,7 @@ int main( int argc, char **argv )
       std::string testIdentifier("Test: sphere inside block");
       WALBERLA_LOG_DEVEL_ON_ROOT(testIdentifier << " - started");
 
-      Vector3<real_t> startPos = positionInsideBlock;
+      const Vector3<real_t>& startPos = positionInsideBlock;
 
       pe::createSphere(*globalBodyStorage, blocks->getBlockStorage(), bodyStorageID, 0,
                        startPos, radius, sphereMaterialID, false, true, false);
@@ -252,7 +252,7 @@ int main( int argc, char **argv )
       std::string testIdentifier("Test: sphere at block border 1");
       WALBERLA_LOG_DEVEL_ON_ROOT(testIdentifier << " - started");
 
-      Vector3<real_t> startPos = positionAtBlockBorder;
+      const Vector3<real_t>& startPos = positionAtBlockBorder;
 
       pe::createSphere(*globalBodyStorage, blocks->getBlockStorage(), bodyStorageID, 0,
                        startPos, radius, sphereMaterialID, false, true, false);
@@ -318,7 +318,7 @@ int main( int argc, char **argv )
       std::string testIdentifier("Test: sphere at block border 1 mod");
       WALBERLA_LOG_DEVEL_ON_ROOT(testIdentifier << " - started");
 
-      Vector3<real_t> startPos = positionAtBlockBorder;
+      const Vector3<real_t>& startPos = positionAtBlockBorder;
 
       pe::createSphere(*globalBodyStorage, blocks->getBlockStorage(), bodyStorageID, 0,
                        startPos, radius, sphereMaterialID, false, true, false);
@@ -385,7 +385,7 @@ int main( int argc, char **argv )
       std::string testIdentifier("Test: sphere at block border 2");
       WALBERLA_LOG_DEVEL_ON_ROOT(testIdentifier << " - started");
 
-      Vector3<real_t> startPos = positionAtBlockBorder2;
+      const Vector3<real_t>& startPos = positionAtBlockBorder2;
 
       pe::createSphere(*globalBodyStorage, blocks->getBlockStorage(), bodyStorageID, 0,
                        startPos, radius, sphereMaterialID, false, true, false);
-- 
GitLab