From 2779b2521f41df0484a729bba790f117f346ac46 Mon Sep 17 00:00:00 2001
From: Christof Metzger-Kraus <christof.j.metzger@gmail.com>
Date: Sat, 2 Dec 2017 15:01:45 +0100
Subject: [PATCH] fixing nans in distribution tests, adding silencer to all
 tests

---
 .../AbsBeamline/DipoleFieldTest.cpp           | 37 ++++---
 .../AbsBeamline/MultipoleTTest.cpp            | 33 ++++---
 tests/classic_src/AbsBeamline/SBend3DTest.cpp |  5 +-
 .../AbsBeamline/ScalingFFAGMagnetTest.cpp     | 26 +++--
 .../Fields/Interpolation/NDGridTest.cpp       | 97 ++++++++++++-------
 .../Interpolation/PPSolveFactoryTest.cpp      |  8 +-
 tests/opal_src/Distribution/BinomialTest.cpp  |  2 +
 tests/opal_src/Distribution/GaussTest.cpp     |  2 +
 8 files changed, 131 insertions(+), 79 deletions(-)

diff --git a/tests/classic_src/AbsBeamline/DipoleFieldTest.cpp b/tests/classic_src/AbsBeamline/DipoleFieldTest.cpp
index aee6e6555..47110b76f 100644
--- a/tests/classic_src/AbsBeamline/DipoleFieldTest.cpp
+++ b/tests/classic_src/AbsBeamline/DipoleFieldTest.cpp
@@ -8,17 +8,20 @@
 #include "Algorithms/PartBunch.h"
 #include "BeamlineCore/MultipoleRep.h"
 #include "AbsBeamline/ElementBase.h"
+
+#include "opal_test_utilities/SilenceTest.h"
+
 #include <fstream>
 using namespace std;
 
 vector< vector<double> > partialsDerivB(const Vector_t &R,const Vector_t B, double stepSize, SBendRep* dummyField)
-{  
-    // builds a matrix of all partial derivatives of B -> dx_i B_j 
+{
+    // builds a matrix of all partial derivatives of B -> dx_i B_j
     vector< vector<double> > allPartials(3, vector<double>(3));
     double t = 0 ;
     Vector_t P, E;
     for(int i = 0; i < 3; i++)
-	{ 
+	{
 	  // B at the previous and next grid points R_prev,  R_next
 	  Vector_t R_prev = R, R_next = R;
 	  R_prev[i] -= stepSize;
@@ -33,13 +36,13 @@ vector< vector<double> > partialsDerivB(const Vector_t &R,const Vector_t B, doub
 }
 
 vector< vector<double> > partialsDerivB_5(const Vector_t &R,const Vector_t B, double stepSize, SBendRep* dummyField)
-{  
-    // builds a matrix of all partial derivatives of B -> dx_i B_j 
+{
+    // builds a matrix of all partial derivatives of B -> dx_i B_j
     vector< vector<double> > allPartials(3, vector<double>(3));
     double t = 0 ;
     Vector_t P, E;
     for(int i = 0; i < 3; i++)
-	{ 
+	{
 	  // B at the previous and next grid points R_prev,  R_next
 	  Vector_t R_pprev = R, R_prev = R, R_next = R, R_nnext = R;
 	  R_pprev(i) -= 2 * stepSize;
@@ -50,13 +53,13 @@ vector< vector<double> > partialsDerivB_5(const Vector_t &R,const Vector_t B, do
 	  dummyField->apply(R_prev, P, t, E, B_prev);
 	  dummyField->apply(R_next, P, t, E, B_next);
 	  dummyField->apply(R_pprev, P, t, E, B_pprev);
-	  dummyField->apply(R_nnext, P, t, E, B_nnext); 
+	  dummyField->apply(R_nnext, P, t, E, B_nnext);
 	  for(int j = 0; j < 3; j++)
 	    allPartials[i][j] = (B_pprev[j] - 8 * B_prev[j] + 8 * B_next[j] - B_nnext[j]) / (12 * stepSize);
 	}
      return allPartials;
 }
-    
+
 double calcDivB(Vector_t &R, Vector_t B, double stepSize, SBendRep* dummyField )
 {
     double div = 0;
@@ -65,7 +68,7 @@ double calcDivB(Vector_t &R, Vector_t B, double stepSize, SBendRep* dummyField )
     for(int i = 0; i < 3; i++)
         div += partials[i][i];
     return div;
-}   
+}
 
 vector<double> calcCurlB(Vector_t &R, Vector_t B, double stepSize, SBendRep* dummyField)
 {
@@ -81,6 +84,8 @@ vector<double> calcCurlB(Vector_t &R, Vector_t B, double stepSize, SBendRep* dum
 
 TEST(Maxwell, Zeros)
 {
+    OpalTestUtilities::SilenceTest silencer;
+
     SBendRep* myMagnet = new SBendRep("myMagnet");
     myMagnet->BendBase::setFieldMapFN("1DPROFILE1-DEFAULT");
     myMagnet->BendBase::setLength(0.2);
@@ -96,7 +101,7 @@ TEST(Maxwell, Zeros)
     PartBunch* bunch = new PartBunch(partData);
     bunch->resetM(0.938);
     bunch->setdT(1.0e-12);//time step
-    double startField = 2.0, endField = 10.0 ;   
+    double startField = 2.0, endField = 10.0 ;
     myMagnet->Bend::initialise(bunch, startField, endField);
     delete partData;
     delete bunch;
@@ -108,9 +113,9 @@ TEST(Maxwell, Zeros)
     int counter = 0;
     //ofstream fout("some_data");
     for(z = 0.0; z <0.0015; z+= 0.0015)
-        for(x = 0.; x<0.04; x += 0.04)   
+        for(x = 0.; x<0.04; x += 0.04)
 	  for(double phi = -Physics::pi / 7.1 ; phi < 2/3. * Physics::pi; phi += Physics::pi/2000.)
-                { 
+                {
 		  // step = phi/(Physics::pi/20);
 		  //std::cout<<"Step #"<<step<<endl;
 		  counter ++;
@@ -139,7 +144,7 @@ TEST(Maxwell, Zeros)
 		  EXPECT_NEAR(curl[0], 0, 0.15);
 		  EXPECT_NEAR(curl[1], 0, 0.15);
 		  EXPECT_NEAR(curl[2], 0, 0.15);
-      	  
+
 	        }
     //fout.close();
     cout<<"bending radius: "<<myMagnet->Bend::designRadius_m<<endl;
@@ -165,6 +170,8 @@ TEST(Maxwell, Zeros)
 
 TEST(Quad, Quadrupole)
 {
+    OpalTestUtilities::SilenceTest silencer;
+
     MultipoleRep* quad = new MultipoleRep();
     //the following are used to initialise myMagnet
     PartData* partData = new PartData();
@@ -199,6 +206,4 @@ TEST(Quad, Quadrupole)
     gout.close();
     cout<<"length: "<<quad->getElementLength()<<endl;
 
-}
-
-
+}
\ No newline at end of file
diff --git a/tests/classic_src/AbsBeamline/MultipoleTTest.cpp b/tests/classic_src/AbsBeamline/MultipoleTTest.cpp
index 6b30fafbd..25d485530 100644
--- a/tests/classic_src/AbsBeamline/MultipoleTTest.cpp
+++ b/tests/classic_src/AbsBeamline/MultipoleTTest.cpp
@@ -1,24 +1,27 @@
 #include "gtest/gtest.h"
 #include "AbsBeamline/MultipoleT.h"
+
+#include "opal_test_utilities/SilenceTest.h"
+
 #include<fstream>
 
 using namespace std;
 
 vector< vector<double> > partialsDerivB(const Vector_t &R,const Vector_t B, double stepSize, MultipoleT* dummyField)
-{  
-    // builds a matrix of all partial derivatives of B -> dx_i B_j 
+{
+    // builds a matrix of all partial derivatives of B -> dx_i B_j
     vector< vector<double> > allPartials(3, vector<double>(3));
     double t = 0 ;
     Vector_t P, E;
     for(int i = 0; i < 3; i++)
-    { 
+    {
       // B at the previous and next grid points R_prev,  R_next
       Vector_t R_prev = R, R_next = R;
       R_prev[i] -= stepSize;
       R_next[i] += stepSize;
       Vector_t B_prev, B_next;
       dummyField->apply(R_prev, P, t, E, B_prev);
-      dummyField->apply(R_next, P, t, E, B_next); 
+      dummyField->apply(R_next, P, t, E, B_next);
       for(int j = 0; j < 3; j++)
         allPartials[i][j] = (B_next[j] - B_prev[j]) / (2 * stepSize);
     }
@@ -26,13 +29,13 @@ vector< vector<double> > partialsDerivB(const Vector_t &R,const Vector_t B, doub
 }
 
 vector< vector<double> > partialsDerivB_5(const Vector_t &R,const Vector_t B, double stepSize, MultipoleT* dummyField)
-{  
-    // builds a matrix of all partial derivatives of B -> dx_i B_j 
+{
+    // builds a matrix of all partial derivatives of B -> dx_i B_j
     vector< vector<double> > allPartials(3, vector<double>(3));
     double t = 0 ;
     Vector_t P, E;
     for(int i = 0; i < 3; i++)
-    { 
+    {
       // B at the previous and next grid points R_prev,  R_next
       Vector_t R_pprev = R, R_prev = R, R_next = R, R_nnext = R;
       R_pprev(i) -= 2 * stepSize;
@@ -49,7 +52,7 @@ vector< vector<double> > partialsDerivB_5(const Vector_t &R,const Vector_t B, do
     }
     return allPartials;
 }
-    
+
 double calcDivB(Vector_t &R, Vector_t B, double stepSize, MultipoleT* dummyField )
 {
     double div = 0;
@@ -58,7 +61,7 @@ double calcDivB(Vector_t &R, Vector_t B, double stepSize, MultipoleT* dummyField
     for(int i = 0; i < 3; i++)
         div += partials[i][i];
     return div;
-}   
+}
 
 vector<double> calcCurlB(Vector_t &R, Vector_t B, double stepSize, MultipoleT* dummyField)
 {
@@ -73,6 +76,8 @@ vector<double> calcCurlB(Vector_t &R, Vector_t B, double stepSize, MultipoleT* d
 
 TEST(MultipoleTTest, Field)
 {
+    OpalTestUtilities::SilenceTest silencer;
+
     MultipoleT* myMagnet = new MultipoleT("Quadrupole");
     double centralField = 5;
     double fringeLength = 0.5;
@@ -107,6 +112,8 @@ TEST(MultipoleTTest, Field)
 }
 
 TEST(MultipoleTTest, Maxwell) {
+    OpalTestUtilities::SilenceTest silencer;
+
     MultipoleT* myMagnet = new MultipoleT("Quadrupole");
     double centralField = 5;
     double fringeLength = 0.5;
@@ -145,11 +152,13 @@ TEST(MultipoleTTest, Maxwell) {
 }
 
 TEST(MultipoleTTest, CurvedMagnet) {
+    OpalTestUtilities::SilenceTest silencer;
+
     MultipoleT* myMagnet = new MultipoleT("Combined function");
     myMagnet->setLength(4.0);
     myMagnet->setBendAngle(0.0); // BUG small, non-zero bend angle ruins the convergence
     myMagnet->setAperture(0.4, 0.4);
-    myMagnet->setFringeField(2, 0.5, 0.5); 
+    myMagnet->setFringeField(2, 0.5, 0.5);
     myMagnet->setVarRadius();
     myMagnet->setVarStep(0.1);
     myMagnet->setTransMaxOrder(1);
@@ -185,6 +194,6 @@ TEST(MultipoleTTest, CurvedMagnet) {
                      << " Del: " << div << " " << curlMag << std::endl;
             }
         }
-    }  
+    }
 
-}
+}
\ No newline at end of file
diff --git a/tests/classic_src/AbsBeamline/SBend3DTest.cpp b/tests/classic_src/AbsBeamline/SBend3DTest.cpp
index 8b623e341..ca7df0378 100644
--- a/tests/classic_src/AbsBeamline/SBend3DTest.cpp
+++ b/tests/classic_src/AbsBeamline/SBend3DTest.cpp
@@ -270,6 +270,8 @@ TEST(SBend3DTest, SBend3DPolyPatchTest) {
 
 
 TEST(SBend3DTest, GeometryTest2) {
+    OpalTestUtilities::SilenceTest silencer;
+
     // Sucked geometry information from
     //     Classic/AbsBeamline/Ring.cpp::appendElement
     // Transform in OPAL-T coords
@@ -293,5 +295,4 @@ TEST(SBend3DTest, GeometryTest2) {
 
     std::cerr << 24.*(1-cos(M_PI/12.)) << " " << 24.*sin(M_PI/12.) << " ** " << cos(M_PI/12.) << " " << sin(M_PI/12.) << " ** " << M_PI/12. << std::endl;
     std::cerr << deltaPos << " ** " << deltaNorm << " ** " << endRot << std::endl;
-}
-
+}
\ No newline at end of file
diff --git a/tests/classic_src/AbsBeamline/ScalingFFAGMagnetTest.cpp b/tests/classic_src/AbsBeamline/ScalingFFAGMagnetTest.cpp
index 099631db0..9f186faf1 100644
--- a/tests/classic_src/AbsBeamline/ScalingFFAGMagnetTest.cpp
+++ b/tests/classic_src/AbsBeamline/ScalingFFAGMagnetTest.cpp
@@ -36,12 +36,12 @@
 #include "Classic/AbsBeamline/ScalingFFAGMagnet.h"
 #include "Classic/AbsBeamline/Offset.h"
 
-class ScalingFFAGMagnetTest : public ::testing::Test { 
-public: 
-    ScalingFFAGMagnetTest() : sector_m(NULL), fout_m() { 
+class ScalingFFAGMagnetTest : public ::testing::Test {
+public:
+    ScalingFFAGMagnetTest() : sector_m(NULL), fout_m(), silencer_m() {
     }
- 
-    void SetUp( ) { 
+
+    void SetUp( ) {
         sector_m = new ScalingFFAGMagnet("test");
         // characteristic length is R*dphi => 0.6545 m
         endfieldmodel::Tanh* tanh = new endfieldmodel::Tanh(psi0_m, psi0_m/5., 20);
@@ -59,8 +59,8 @@ public:
         sector_m->setVerticalExtent(1.); // 1 m
         sector_m->initialise();
     }
- 
-    void TearDown( ) { 
+
+    void TearDown( ) {
         delete sector_m;
         sector_m = NULL;
     }
@@ -173,7 +173,7 @@ public:
         Vector_t B(0., 0., 0.);
         Vector_t BCart(0., 0., 0.);
         double t = 0;
-        
+
         sector_m->getFieldValueCylindrical(posCyl, B);
         bool outsideFieldMap = sector_m->apply(posCart, mom, t, E, BCart);
         double delta = y/1000.;
@@ -208,7 +208,7 @@ public:
     }
 
 private:
-
+    OpalTestUtilities::SilenceTest silencer_m;
 };
 
 TEST_F(ScalingFFAGMagnetTest, ConstructorTest) {
@@ -332,7 +332,6 @@ TEST_F(ScalingFFAGMagnetTest, DFCoefficientsTanDeltaTest) {
 }
 
 TEST_F(ScalingFFAGMagnetTest, TanhTest) {
-    OpalTestUtilities::SilenceTest silence;
     double numericalDerivative = sector_m->getEndField()->function(-psi0_m, 0);
     for (size_t order = 0; order < 5; ++order) {
         double analyticalDerivative = sector_m->getEndField()->function(-psi0_m, order);
@@ -372,7 +371,6 @@ TEST_F(ScalingFFAGMagnetTest, ConvergenceYTest) {
 }
 
 TEST_F(ScalingFFAGMagnetTest, ConvergenceOrderTest) {
-    OpalTestUtilities::SilenceTest silence;
     for (double y = 0.5; y > 0.2; y /= 10.) { // 50 cm off midplane
         std::cout << "order y divB |curlB| curlB" << std::endl;
         std::vector<double> divBVec(13);
@@ -406,14 +404,13 @@ TEST_F(ScalingFFAGMagnetTest, ConvergenceOrderTest) {
 }
 
 TEST_F(ScalingFFAGMagnetTest, ConvergenceOrderHackedTest) {
-    OpalTestUtilities::SilenceTest silence;
     double y = 0.05;
     bool cylindrical = false;
     int maxOrder = 10;
     // nb: if tan delta is 0., convergence reached at i = 7
     for (double td = 0.2; td < 1.1; td += 0.2) { // 50 cm off midplane
         std::cout << "order y     B     divB     |curlB|     curlB" << std::endl;
-        
+
         std::vector<double> divBVec(maxOrder);
         std::vector<double> curlBVec(maxOrder);
         double delta = y/100.;
@@ -534,5 +531,4 @@ TEST_F(ScalingFFAGMagnetTest, GeometryTest) {
     EXPECT_EQ(rot(0), 0.);
     EXPECT_EQ(rot(1), -psi0_m*4);
     EXPECT_EQ(rot(2), 0.);
-}
-
+}
\ No newline at end of file
diff --git a/tests/classic_src/Fields/Interpolation/NDGridTest.cpp b/tests/classic_src/Fields/Interpolation/NDGridTest.cpp
index 1f2fa8d37..5811a3157 100644
--- a/tests/classic_src/Fields/Interpolation/NDGridTest.cpp
+++ b/tests/classic_src/Fields/Interpolation/NDGridTest.cpp
@@ -1,27 +1,27 @@
-/* 
+/*
  *  Copyright (c) 2017, Chris Rogers
  *  All rights reserved.
- *  Redistribution and use in source and binary forms, with or without 
- *  modification, are permitted provided that the following conditions are met: 
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are met:
  *  1. Redistributions of source code must retain the above copyright notice,
- *     this list of conditions and the following disclaimer. 
- *  2. Redistributions in binary form must reproduce the above copyright notice, 
- *     this list of conditions and the following disclaimer in the documentation 
+ *     this list of conditions and the following disclaimer.
+ *  2. Redistributions in binary form must reproduce the above copyright notice,
+ *     this list of conditions and the following disclaimer in the documentation
  *     and/or other materials provided with the distribution.
- *  3. Neither the name of STFC nor the names of its contributors may be used to 
- *     endorse or promote products derived from this software without specific 
+ *  3. Neither the name of STFC nor the names of its contributors may be used to
+ *     endorse or promote products derived from this software without specific
  *     prior written permission.
  *
- *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
- *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
- *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
- *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
- *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
- *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
- *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
- *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
- *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
- *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  *  POSSIBILITY OF SUCH DAMAGE.
  */
 
@@ -29,26 +29,28 @@
 #include "Fields/Interpolation/NDGrid.h"
 #include "Fields/Interpolation/Mesh.h"
 
+#include "opal_test_utilities/SilenceTest.h"
+
 namespace ndgridtest {
 
-class NDGridTest : public ::testing::Test { 
-public: 
-    NDGridTest() : grid_m(NULL) { 
+class NDGridTest : public ::testing::Test {
+public:
+    NDGridTest() : grid_m(NULL) {
     }
- 
-    void SetUp( ) { 
+
+    void SetUp( ) {
         std::vector< std::vector<double> > gridCoordinates(2);
         gridCoordinates[0] = std::vector<double>(2, 0.);
-        gridCoordinates[0][1] = 3.;	
+        gridCoordinates[0][1] = 3.;
         gridCoordinates[1] = std::vector<double>(3, 1.);
-        gridCoordinates[1][1] = 5.;	
+        gridCoordinates[1][1] = 5.;
         gridCoordinates[1][2] = 9.;
         grid_m = new interpolation::NDGrid(gridCoordinates);
         gridCoordinates[1][2] = 10.; // force it to not be regular
         grid2_m = new interpolation::NDGrid(gridCoordinates);
     }
- 
-    void TearDown( ) { 
+
+    void TearDown( ) {
         delete grid_m;
         grid_m = NULL;
         delete grid2_m;
@@ -66,12 +68,16 @@ private:
 };
 
 TEST_F(NDGridTest, DefaultConstructorTest) {
+    OpalTestUtilities::SilenceTest silencer;
+
     interpolation::NDGrid grid;
     EXPECT_EQ(grid.begin(), grid.end());
 }
 
 // also tests size
 TEST_F(NDGridTest, Constructor1Test) {
+    OpalTestUtilities::SilenceTest silencer;
+
     int size[] = {5, 6, 7, 8};
     double spacing[] = {1., 2., 3., 4.};
     double min[] = {-1., -2., -3., -4.};
@@ -86,6 +92,8 @@ TEST_F(NDGridTest, Constructor1Test) {
 }
 
 TEST_F(NDGridTest, Constructor2Test) {
+    OpalTestUtilities::SilenceTest silencer;
+
     std::vector<int> size(2);
     size[0] = 2;
     size[1] = 3;
@@ -100,10 +108,12 @@ TEST_F(NDGridTest, Constructor2Test) {
         ASSERT_EQ(grid1.size(i), size[i]);
         EXPECT_NEAR(grid1.coord(1, i), gridCoordinates[i][0], 1e-12) << "Failed for i " << i;
         EXPECT_NEAR(grid1.coord(i+2, i), gridCoordinates[i][size[i]-1], 1e-12) << "Failed for i " << i;
-    }   
+    }
 }
 
 TEST_F(NDGridTest, Constructor3Test) {
+    OpalTestUtilities::SilenceTest silencer;
+
     std::vector< std::vector<double> > gridCoordinates(2);
     gridCoordinates[0] = std::vector<double>(2, 0.);
     gridCoordinates[1] = std::vector<double>(3, 1.);
@@ -115,10 +125,12 @@ TEST_F(NDGridTest, Constructor3Test) {
         ASSERT_EQ(grid1.size(i), size);
         EXPECT_NEAR(grid1.coord(1, i), gridCoordinates[i][0], 1e-12) << "Failed for i " << i;
         EXPECT_NEAR(grid1.coord(i+2, i), gridCoordinates[i][size-1], 1e-12) << "Failed for i " << i;
-    }   
+    }
 }
 
 TEST_F(NDGridTest, CoordTest) {
+    OpalTestUtilities::SilenceTest silencer;
+
     std::vector< std::vector<double> > gridCoordinates(2);
     gridCoordinates[0] = std::vector<double>(2, 0.);
     gridCoordinates[1] = std::vector<double>(3, 1.);
@@ -128,14 +140,16 @@ TEST_F(NDGridTest, CoordTest) {
     for (int i = 0; i < 2; ++i) {
             EXPECT_NEAR(grid_var.coord(1, i), gridCoordinates[i][0], 1e-12) << "Failed for i " << i;
             EXPECT_NEAR(grid_const.coord(1, i), gridCoordinates[i][0], 1e-12) << "Failed for i " << i;
-    }   
+    }
 }
 
 TEST_F(NDGridTest, CoordVectorTest) {  // and newCoordArray
+    OpalTestUtilities::SilenceTest silencer;
+
     std::vector< std::vector<double> > gridCoordinates(2);
     gridCoordinates[0] = std::vector<double>(2, 0.);
     gridCoordinates[1] = std::vector<double>(3, 1.);
-    gridCoordinates[1][2] = 9.;	
+    gridCoordinates[1][2] = 9.;
     interpolation::NDGrid grid(gridCoordinates);
     for (int i = 0; i < 2; ++i) {
         std::vector<double> coords_v = grid.coordVector(i);
@@ -150,6 +164,8 @@ TEST_F(NDGridTest, CoordVectorTest) {  // and newCoordArray
 }
 
 TEST_F(NDGridTest, CoordLowerBoundTest) {
+    OpalTestUtilities::SilenceTest silencer;
+
     // first dimension ... 0., 3.;
     int index = -1;
     grid_m->coordLowerBound(-1., 0, index);
@@ -186,6 +202,8 @@ TEST_F(NDGridTest, CoordLowerBoundTest) {
 }
 
 TEST_F(NDGridTest, LowerBoundTest) {
+    OpalTestUtilities::SilenceTest silencer;
+
     // first dimension ... 0., 3.;
     // second dimension ...  1., 5., 9.
     std::vector<int> index1(2, -2);
@@ -208,6 +226,8 @@ TEST_F(NDGridTest, LowerBoundTest) {
 }
 
 TEST_F(NDGridTest, MinMaxTest) {
+    OpalTestUtilities::SilenceTest silencer;
+
     EXPECT_EQ(grid_m->min(0), 0.);
     EXPECT_EQ(grid_m->min(1), 1.);
     EXPECT_EQ(grid_m->max(0), 3.);
@@ -215,6 +235,8 @@ TEST_F(NDGridTest, MinMaxTest) {
 }
 
 TEST_F(NDGridTest, SetCoordTest) {
+    OpalTestUtilities::SilenceTest silencer;
+
     double xNew[] = {5., 10., 12., 15.};
     grid_m->setCoord(0, 4, xNew);
     std::vector<double> xTest = grid_m->coordVector(0);
@@ -225,6 +247,8 @@ TEST_F(NDGridTest, SetCoordTest) {
 }
 
 TEST_F(NDGridTest, BeginEndTest) {
+    OpalTestUtilities::SilenceTest silencer;
+
     ASSERT_EQ(grid_m->begin().getState().size(), 2);
     EXPECT_EQ(grid_m->begin().getState()[0], 1);
     EXPECT_EQ(grid_m->begin().getState()[1], 1);
@@ -234,6 +258,8 @@ TEST_F(NDGridTest, BeginEndTest) {
 }
 
 TEST_F(NDGridTest, GetPositionTest) {
+    OpalTestUtilities::SilenceTest silencer;
+
     std::vector<double> position(3, -1);
     interpolation::Mesh::Iterator it = grid_m->begin();
     grid_m->getPosition(it, &position[0]);
@@ -248,6 +274,8 @@ TEST_F(NDGridTest, GetPositionTest) {
 }
 
 TEST_F(NDGridTest, GetSetConstantSpacingTest) {
+    OpalTestUtilities::SilenceTest silencer;
+
     EXPECT_TRUE(grid_m->getConstantSpacing());
     grid_m->setConstantSpacing(false);
     EXPECT_FALSE(grid_m->getConstantSpacing());
@@ -270,6 +298,8 @@ TEST_F(NDGridTest, GetSetConstantSpacingTest) {
 }
 
 TEST_F(NDGridTest, ToIntegerTest) {
+    OpalTestUtilities::SilenceTest silencer;
+
     interpolation::Mesh::Iterator it = grid_m->begin();
     EXPECT_EQ(grid_m->toInteger(it), 0);
     it[0] = 2;
@@ -278,6 +308,8 @@ TEST_F(NDGridTest, ToIntegerTest) {
 }
 
 TEST_F(NDGridTest, GetNearestTest) {
+    OpalTestUtilities::SilenceTest silencer;
+
     // first dimension ... 0., 3.;
     // second dimension ...  1., 5., 9.
 
@@ -303,5 +335,4 @@ TEST_F(NDGridTest, GetNearestTest) {
     EXPECT_EQ(it[1], 3);
 }
 
-} // namespace ndgridtest
-
+} // namespace ndgridtest
\ No newline at end of file
diff --git a/tests/classic_src/Fields/Interpolation/PPSolveFactoryTest.cpp b/tests/classic_src/Fields/Interpolation/PPSolveFactoryTest.cpp
index 84bf7766f..f3cd81da5 100644
--- a/tests/classic_src/Fields/Interpolation/PPSolveFactoryTest.cpp
+++ b/tests/classic_src/Fields/Interpolation/PPSolveFactoryTest.cpp
@@ -123,6 +123,8 @@ class PPSolveFactoryTestFixture : public ::testing::Test {
 
 // check linear fit exactly reproduces data on grid points
 TEST_F(PPSolveFactoryTestFixture, TestSolvePolynomialLinear) {
+    OpalTestUtilities::SilenceTest silencer;
+
     PPSolveFactory fac1(grid->clone(),
                        values,
                        1,
@@ -140,6 +142,8 @@ TEST_F(PPSolveFactoryTestFixture, TestSolvePolynomialLinear) {
 // check quadratic fit exactly reproduces data on and off grid points (data
 // comes from a quadratic polynomial as source)
 TEST_F(PPSolveFactoryTestFixture, TestSolvePolynomialQuadratic) {
+    OpalTestUtilities::SilenceTest silencer;
+
     PPSolveFactory fac2(grid->clone(),
                        values,
                        2,
@@ -179,6 +183,8 @@ TEST_F(PPSolveFactoryTestFixture, TestSolvePolynomialQuadratic) {
 // check smoothed quadratic fit exactly reproduces data on and off grid points
 // except near to the boundary
 TEST_F(PPSolveFactoryTestFixture, DISABLED_TestSolvePolynomialQuadraticSmoothed) {
+    OpalTestUtilities::SilenceTest silencer;
+
     PPSolveFactory fac2(grid->clone(),
                        values,
                        1,
@@ -379,4 +385,4 @@ TEST(PPSolveFactoryTest, TestThreeDSolveSinCos) {
         }
         std::cout << std::endl;
     }
-}
+}
\ No newline at end of file
diff --git a/tests/opal_src/Distribution/BinomialTest.cpp b/tests/opal_src/Distribution/BinomialTest.cpp
index b9cf6634c..7128adc04 100644
--- a/tests/opal_src/Distribution/BinomialTest.cpp
+++ b/tests/opal_src/Distribution/BinomialTest.cpp
@@ -56,6 +56,7 @@ TEST(BinomialTest, FullSigmaTest1) {
     dist.setDistType();
     dist.checkIfEmitted();
     size_t numParticles = 1000000;
+    dist.totalNumberParticles_m = numParticles;
     dist.create(numParticles, Physics::m_p);
 
     double R11 = sqrt(gsl_stats_variance(&(dist.xDist_m[0]), 1, dist.xDist_m.size())) * 1e3;
@@ -137,6 +138,7 @@ TEST(BinomialTest, FullSigmaTest2) {
     dist.checkIfEmitted();
 
     size_t numParticles = 1000000;
+    dist.totalNumberParticles_m = numParticles;
     dist.create(numParticles, Physics::m_p);
 
     double R11 = sqrt(gsl_stats_variance(&(dist.xDist_m[0]), 1, dist.xDist_m.size())) * 1e3;
diff --git a/tests/opal_src/Distribution/GaussTest.cpp b/tests/opal_src/Distribution/GaussTest.cpp
index 0c69d9bfc..5c049ae5c 100644
--- a/tests/opal_src/Distribution/GaussTest.cpp
+++ b/tests/opal_src/Distribution/GaussTest.cpp
@@ -54,6 +54,7 @@ TEST(GaussTest, FullSigmaTest1) {
     dist.setDistType();
     dist.checkIfEmitted();
     size_t numParticles = 1000000;
+    dist.totalNumberParticles_m = numParticles;
     dist.create(numParticles, Physics::m_p);
 
     double R11 = sqrt(gsl_stats_variance(&(dist.xDist_m[0]), 1, dist.xDist_m.size())) * 1e3;
@@ -138,6 +139,7 @@ TEST(GaussTest, FullSigmaTest2) {
     dist.checkIfEmitted();
 
     size_t numParticles = 1000000;
+    dist.totalNumberParticles_m = numParticles;
     dist.create(numParticles, Physics::m_p);
 
     double R11 = sqrt(gsl_stats_variance(&(dist.xDist_m[0]), 1, dist.xDist_m.size())) * 1e3;
-- 
GitLab