From 29cca6fc73b70a1d623b6ff84cca0c6a57bebb00 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de>
Date: Thu, 10 Dec 2020 12:57:29 +0100
Subject: [PATCH] ongoing corrections

---
 Device/Data/DataUtils.cpp                     |  6 +-
 Device/Data/DataUtils.h                       |  6 +-
 Device/Histo/HistoUtils.cpp                   |  2 +-
 .../Core/CoreSpecial/BatchSimulation.cpp      |  2 +-
 .../Core/CoreSpecial/CoreIOPathTest.cpp       |  2 +-
 .../CoreSpecial/FourierTransformationTest.cpp |  2 +-
 .../Python/PyPersistence/CMakeLists.txt       | 85 +++++++++----------
 .../Python/PyPersistence/PyPersistence.py.in  |  2 +-
 Tests/UnitTests/GUI/Utils.cpp                 |  2 +-
 auto/Wrap/doxygenDevice.i                     | 10 +--
 auto/Wrap/libBornAgainDevice.py               | 10 +++
 auto/Wrap/libBornAgainDevice_wrap.cpp         | 43 ++++++++++
 12 files changed, 109 insertions(+), 63 deletions(-)

diff --git a/Device/Data/DataUtils.cpp b/Device/Data/DataUtils.cpp
index 9bcd7511e55..9b67b58d4b0 100644
--- a/Device/Data/DataUtils.cpp
+++ b/Device/Data/DataUtils.cpp
@@ -30,8 +30,8 @@ std::vector<std::vector<double>> FT2DArray(const std::vector<std::vector<double>
 } // namespace
 
 //! Returns relative difference between two data sets sum(dat[i] - ref[i])/ref[i]).
-double DataUtils::getRelativeDifference(const OutputData<double>& dat,
-                                        const OutputData<double>& ref) {
+double DataUtils::relativeDataDifference(const OutputData<double>& dat,
+                                         const OutputData<double>& ref) {
     if (!dat.hasSameDimensions(ref))
         throw std::runtime_error("OutputData dimension differs from reference");
 
@@ -47,7 +47,7 @@ double DataUtils::getRelativeDifference(const OutputData<double>& dat,
 //! Returns true is relative difference is below threshold; prints informative output
 bool DataUtils::checkRelativeDifference(const OutputData<double>& dat,
                                         const OutputData<double>& ref, const double threshold) {
-    const double diff = getRelativeDifference(dat, ref);
+    const double diff = relativeDataDifference(dat, ref);
     if (diff > threshold) {
         std::cerr << "FAILED: relative deviation of dat from ref is " << diff
                   << ", above given threshold " << threshold << "\n";
diff --git a/Device/Data/DataUtils.h b/Device/Data/DataUtils.h
index 3b05ea509d4..efdd2c008fd 100644
--- a/Device/Data/DataUtils.h
+++ b/Device/Data/DataUtils.h
@@ -20,6 +20,9 @@
 
 namespace DataUtils {
 
+//! Returns relative difference between two data sets sum(dat[i] - ref[i])/ref[i]).
+double relativeDataDifference(const OutputData<double>& dat, const OutputData<double>& ref);
+
 //! Returns true is relative difference is below threshold; prints informative output
 bool checkRelativeDifference(const OutputData<double>& dat, const OutputData<double>& ref,
                              const double threshold);
@@ -41,9 +44,6 @@ std::vector<std::vector<double>> create2DArrayfromOutputData(const OutputData<do
 
 #ifndef SWIG
 
-//! Returns relative difference between two data sets sum(dat[i] - ref[i])/ref[i]).
-double getRelativeDifference(const OutputData<double>& dat, const OutputData<double>& ref);
-
 std::unique_ptr<OutputData<double>>
 createRelativeDifferenceData(const OutputData<double>& data, const OutputData<double>& reference);
 
diff --git a/Device/Histo/HistoUtils.cpp b/Device/Histo/HistoUtils.cpp
index 30a4428f684..e2ed7f7e71d 100644
--- a/Device/Histo/HistoUtils.cpp
+++ b/Device/Histo/HistoUtils.cpp
@@ -67,7 +67,7 @@ double HistoUtils::RelativeDifference(const SimulationResult& dat, const Simulat
 }
 
 double HistoUtils::getRelativeDifference(const IHistogram& dat, const IHistogram& ref) {
-    return DataUtils::getRelativeDifference(
+    return DataUtils::relativeDataDifference(
         *std::unique_ptr<OutputData<double>>(dat.getData().meanValues()),
         *std::unique_ptr<OutputData<double>>(ref.getData().meanValues()));
 }
diff --git a/Tests/Functional/Core/CoreSpecial/BatchSimulation.cpp b/Tests/Functional/Core/CoreSpecial/BatchSimulation.cpp
index 1b21254f9f7..46940579d4d 100644
--- a/Tests/Functional/Core/CoreSpecial/BatchSimulation.cpp
+++ b/Tests/Functional/Core/CoreSpecial/BatchSimulation.cpp
@@ -49,7 +49,7 @@ TEST_F(BatchSimulation, BatchSimulation) {
         *result += *batchResult;
     }
 
-    double diff = DataUtils::getRelativeDifference(*result, *reference);
+    double diff = DataUtils::relativeDataDifference(*result, *reference);
 
     EXPECT_LE(diff, threshold);
 }
diff --git a/Tests/Functional/Core/CoreSpecial/CoreIOPathTest.cpp b/Tests/Functional/Core/CoreSpecial/CoreIOPathTest.cpp
index ba89ef97adb..580f3f30a3e 100644
--- a/Tests/Functional/Core/CoreSpecial/CoreIOPathTest.cpp
+++ b/Tests/Functional/Core/CoreSpecial/CoreIOPathTest.cpp
@@ -33,7 +33,7 @@ std::unique_ptr<OutputData<double>> createTestData() {
 bool test_io(const OutputData<double>* data, const std::string& file_name) {
     IntensityDataIOFactory::writeOutputData(*data, file_name);
     std::unique_ptr<OutputData<double>> loaded(IntensityDataIOFactory::readOutputData(file_name));
-    return DataUtils::getRelativeDifference(*data, *loaded) <= 1e-06;
+    return DataUtils::relativeDataDifference(*data, *loaded) <= 1e-06;
 }
 
 } // namespace
diff --git a/Tests/Functional/Core/CoreSpecial/FourierTransformationTest.cpp b/Tests/Functional/Core/CoreSpecial/FourierTransformationTest.cpp
index e99b636fd63..33a1175367c 100644
--- a/Tests/Functional/Core/CoreSpecial/FourierTransformationTest.cpp
+++ b/Tests/Functional/Core/CoreSpecial/FourierTransformationTest.cpp
@@ -62,7 +62,7 @@ bool test_fft(const std::string& input_image_name, const std::string& reference_
     std::cout << "comparing" << std::endl;
     bool success(false);
     if (reference_fft)
-        success = DataUtils::getRelativeDifference(*fft, *reference_fft) <= threshold;
+        success = DataUtils::relativeDataDifference(*fft, *reference_fft) <= threshold;
 
     if (!success) {
         FileSystemUtils::createDirectory(BATesting::TestOutDir_Core());
diff --git a/Tests/Functional/Python/PyPersistence/CMakeLists.txt b/Tests/Functional/Python/PyPersistence/CMakeLists.txt
index 00a6defb321..4df473168a4 100644
--- a/Tests/Functional/Python/PyPersistence/CMakeLists.txt
+++ b/Tests/Functional/Python/PyPersistence/CMakeLists.txt
@@ -22,50 +22,43 @@ function(test_example example tolerance)
     add_test(${test_name} ${Python3_EXECUTABLE} -B ${example_mod})
 endfunction()
 
-test_example(sim01_Particles/CylindersAndPrisms 2e-10)
-test_example(sim01_Particles/CylindersInBA 2e-10)
-test_example(sim01_Particles/CylindersInDWBA 2e-10)
-test_example(sim01_Particles/CylindersWithSizeDistribution 2e-10)
-test_example(sim01_Particles/RotatedPyramids 2e-10)
-test_example(sim01_Particles/TwoTypesOfCylindersWithSizeDistribution 2e-10)
+test_example(scatter2d/ApproximationDA 2e-10)
+test_example(scatter2d/ApproximationLMA 2e-10)
+test_example(scatter2d/ApproximationSSCA 2e-10)
+test_example(scatter2d/BeamDivergence 2e-10)
+test_example(scatter2d/BuriedParticles 2e-10)
+test_example(scatter2d/ConstantBackground 2e-10)
+test_example(scatter2d/CoreShellNanoparticles 2e-10)
+test_example(scatter2d/CorrelatedRoughness 2e-10)
+test_example(scatter2d/CosineRipplesAtRectLattice 2e-10)
+test_example(scatter2d/CylindersAndPrisms 2e-10)
+test_example(scatter2d/CylindersInAverageLayer 2e-10)
+test_example(scatter2d/CylindersInBA 2e-10)
+test_example(scatter2d/CylindersInDWBA 2e-10)
+test_example(scatter2d/CylindersWithSizeDistribution 2e-10)
+test_example(scatter2d/DetectorResolutionFunction 2e-10)
+test_example(scatter2d/HalfSpheresInAverageTopLayer 2e-10)
+test_example(scatter2d/HexagonalLatticesWithBasis 2e-10)
+test_example(scatter2d/Interference1DRadialParaCrystal 2e-10)
+test_example(scatter2d/Interference2DCenteredSquareLattice 2e-10)
+test_example(scatter2d/Interference2DLatticeSumOfRotated 2e-10)
+test_example(scatter2d/Interference2DParaCrystal 2e-10)
+test_example(scatter2d/Interference2DRotatedSquareLattice 2e-10)
+test_example(scatter2d/Interference2DSquareLattice 2e-10)
+test_example(scatter2d/MagneticSpheres 2e-10)
+test_example(scatter2d/RectangularGrating 0.5)
+test_example(scatter2d/RotatedPyramids 2e-10)
+test_example(scatter2d/SpheresAtHexLattice 2e-10)
+test_example(scatter2d/TriangularRipple 2e-10)
+test_example(scatter2d/TwoTypesOfCylindersWithSizeDistribution 2e-10)
 
-test_example(sim02_Complexes/CoreShellNanoparticles 2e-10)
-test_example(sim02_Complexes/CustomFormFactor 2e-10)
-test_example(sim02_Complexes/HexagonalLatticesWithBasis 2e-10)
-
-test_example(sim03_Structures/ApproximationDA 2e-10)
-test_example(sim03_Structures/ApproximationLMA 2e-10)
-test_example(sim03_Structures/ApproximationSSCA 2e-10)
-test_example(sim03_Structures/CosineRipplesAtRectLattice 2e-10)
-test_example(sim03_Structures/Interference1DLattice 1.5)
-test_example(sim03_Structures/Interference1DRadialParaCrystal 2e-10)
-test_example(sim03_Structures/Interference2DCenteredSquareLattice 2e-10)
-test_example(sim03_Structures/Interference2DParaCrystal 2e-10)
-test_example(sim03_Structures/Interference2DRotatedSquareLattice 2e-10)
-test_example(sim03_Structures/Interference2DSquareLattice 2e-10)
-test_example(sim03_Structures/Interference2DLatticeSumOfRotated 2e-10)
-test_example(sim03_Structures/RectangularGrating 0.5)
-test_example(sim03_Structures/SpheresAtHexLattice 2e-10)
-test_example(sim03_Structures/TriangularRipple 2e-10)
-
-test_example(sim04_Multilayers/BuriedParticles 2e-10)
-test_example(sim04_Multilayers/CorrelatedRoughness 2e-10)
-test_example(sim04_Multilayers/CylindersInAverageLayer 2e-10)
-test_example(sim04_Multilayers/HalfSpheresInAverageTopLayer 2e-10)
-
-test_example(sim05_Magnetism/MagneticSpheres 2e-10)
-
-test_example(sim11_Device/BeamDivergence 2e-10)
-test_example(sim11_Device/DetectorResolutionFunction 2e-10)
-test_example(sim11_Device/OffSpecularSimulation 2e-10)
-test_example(sim11_Device/ConstantBackground 2e-10)
-
-test_example(sim21_Reflectometry/BasicSpecularSimulation 2e-10)
-test_example(sim21_Reflectometry/BeamAngularDivergence 2e-10)
-test_example(sim21_Reflectometry/BeamFullDivergence 2e-10)
-test_example(sim21_Reflectometry/TimeOfFlightReflectometry 2e-10)
-test_example(sim21_Reflectometry/TOFRWithResolution 2e-10)
-
-test_example(special40_DepthProbe/DepthProbe 2e-10)
-
-test_example(sim31_Parameterization/SimulationParameters 2e-10)
+test_example(varia/BasicSpecularSimulation 2e-10)
+test_example(varia/BeamAngularDivergence 2e-10)
+test_example(varia/BeamFullDivergence 2e-10)
+test_example(varia/CustomFormFactor 2e-10)
+test_example(varia/DepthProbe 2e-10)
+test_example(varia/Interference1DLattice 1.5)
+test_example(varia/OffSpecularSimulation 2e-10)
+test_example(varia/SimulationParameters 2e-10)
+test_example(varia/TOFRWithResolution 2e-10)
+test_example(varia/TimeOfFlightReflectometry 2e-10)
diff --git a/Tests/Functional/Python/PyPersistence/PyPersistence.py.in b/Tests/Functional/Python/PyPersistence/PyPersistence.py.in
index 51a877e2002..a2b1d365be5 100644
--- a/Tests/Functional/Python/PyPersistence/PyPersistence.py.in
+++ b/Tests/Functional/Python/PyPersistence/PyPersistence.py.in
@@ -149,7 +149,7 @@ def check_result(result, example_name):
     print("Loading reference file '{}'".format(reffile))
     reference = ba.IntensityDataIOFactory.readOutputData(reffile)
 
-    diff = ba.getRelativeDifference(ba.importArrayToOutputData(result.array()), reference)
+    diff = ba.relativeDataDifference(ba.importArrayToOutputData(result.array()), reference)
 
     if diff > TOLERANCE:
         print("Failure - Difference {0} is above tolerance level {1}".format(diff, TOLERANCE))
diff --git a/Tests/UnitTests/GUI/Utils.cpp b/Tests/UnitTests/GUI/Utils.cpp
index b61db960f8d..9b53cef3ec4 100644
--- a/Tests/UnitTests/GUI/Utils.cpp
+++ b/Tests/UnitTests/GUI/Utils.cpp
@@ -54,7 +54,7 @@ RealDataItem* GuiUnittestUtils::createRealData(const QString& name, SessionModel
 }
 
 bool GuiUnittestUtils::isTheSame(const OutputData<double>& data1, const OutputData<double>& data2) {
-    double diff = DataUtils::getRelativeDifference(data1, data2);
+    double diff = DataUtils::relativeDataDifference(data1, data2);
     return diff < 1e-10;
 }
 
diff --git a/auto/Wrap/doxygenDevice.i b/auto/Wrap/doxygenDevice.i
index c5ed4c48cb0..00765ed9352 100644
--- a/auto/Wrap/doxygenDevice.i
+++ b/auto/Wrap/doxygenDevice.i
@@ -3093,6 +3093,11 @@ Parse double values from string to vector of double.
 
 
 // File: namespaceDataUtils.xml
+%feature("docstring")  DataUtils::relativeDataDifference "double DataUtils::relativeDataDifference(const OutputData< double > &dat, const OutputData< double > &ref)
+
+Returns relative difference between two data sets sum(dat[i] - ref[i])/ref[i]). 
+";
+
 %feature("docstring")  DataUtils::checkRelativeDifference "bool DataUtils::checkRelativeDifference(const OutputData< double > &dat, const OutputData< double > &ref, const double threshold)
 
 Returns true is relative difference is below threshold; prints informative output. 
@@ -3123,11 +3128,6 @@ Transforms x,y coordinate from bin-fraction-coordinates to  OutputData's axes co
 Creates a vector of vectors of double (2D Array) from  OutputData. 
 ";
 
-%feature("docstring")  DataUtils::getRelativeDifference "double DataUtils::getRelativeDifference(const OutputData< double > &dat, const OutputData< double > &ref)
-
-Returns relative difference between two data sets sum(dat[i] - ref[i])/ref[i]). 
-";
-
 %feature("docstring")  DataUtils::createRelativeDifferenceData "std::unique_ptr< OutputData< double > > DataUtils::createRelativeDifferenceData(const OutputData< double > &data, const OutputData< double > &reference)
 ";
 
diff --git a/auto/Wrap/libBornAgainDevice.py b/auto/Wrap/libBornAgainDevice.py
index 3ffa4ce078f..2f65ed26775 100644
--- a/auto/Wrap/libBornAgainDevice.py
+++ b/auto/Wrap/libBornAgainDevice.py
@@ -2616,6 +2616,16 @@ class IntensityData(object):
 _libBornAgainDevice.IntensityData_swigregister(IntensityData)
 
 
+def relativeDataDifference(dat, ref):
+    r"""
+    relativeDataDifference(IntensityData dat, IntensityData ref) -> double
+    double DataUtils::relativeDataDifference(const OutputData< double > &dat, const OutputData< double > &ref)
+
+    Returns relative difference between two data sets sum(dat[i] - ref[i])/ref[i]). 
+
+    """
+    return _libBornAgainDevice.relativeDataDifference(dat, ref)
+
 def checkRelativeDifference(dat, ref, threshold):
     r"""
     checkRelativeDifference(IntensityData dat, IntensityData ref, double const threshold) -> bool
diff --git a/auto/Wrap/libBornAgainDevice_wrap.cpp b/auto/Wrap/libBornAgainDevice_wrap.cpp
index 6ecaa195c40..39d3b01cb6d 100644
--- a/auto/Wrap/libBornAgainDevice_wrap.cpp
+++ b/auto/Wrap/libBornAgainDevice_wrap.cpp
@@ -30489,6 +30489,42 @@ SWIGINTERN PyObject *IntensityData_swiginit(PyObject *SWIGUNUSEDPARM(self), PyOb
   return SWIG_Python_InitShadowInstance(args);
 }
 
+SWIGINTERN PyObject *_wrap_relativeDataDifference(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
+  PyObject *resultobj = 0;
+  OutputData< double > *arg1 = 0 ;
+  OutputData< double > *arg2 = 0 ;
+  void *argp1 = 0 ;
+  int res1 = 0 ;
+  void *argp2 = 0 ;
+  int res2 = 0 ;
+  PyObject *swig_obj[2] ;
+  double result;
+  
+  if (!SWIG_Python_UnpackTuple(args, "relativeDataDifference", 2, 2, swig_obj)) SWIG_fail;
+  res1 = SWIG_ConvertPtr(swig_obj[0], &argp1, SWIGTYPE_p_OutputDataT_double_t,  0  | 0);
+  if (!SWIG_IsOK(res1)) {
+    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "relativeDataDifference" "', argument " "1"" of type '" "OutputData< double > const &""'"); 
+  }
+  if (!argp1) {
+    SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "relativeDataDifference" "', argument " "1"" of type '" "OutputData< double > const &""'"); 
+  }
+  arg1 = reinterpret_cast< OutputData< double > * >(argp1);
+  res2 = SWIG_ConvertPtr(swig_obj[1], &argp2, SWIGTYPE_p_OutputDataT_double_t,  0  | 0);
+  if (!SWIG_IsOK(res2)) {
+    SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "relativeDataDifference" "', argument " "2"" of type '" "OutputData< double > const &""'"); 
+  }
+  if (!argp2) {
+    SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "relativeDataDifference" "', argument " "2"" of type '" "OutputData< double > const &""'"); 
+  }
+  arg2 = reinterpret_cast< OutputData< double > * >(argp2);
+  result = (double)DataUtils::relativeDataDifference((OutputData< double > const &)*arg1,(OutputData< double > const &)*arg2);
+  resultobj = SWIG_From_double(static_cast< double >(result));
+  return resultobj;
+fail:
+  return NULL;
+}
+
+
 SWIGINTERN PyObject *_wrap_checkRelativeDifference(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
   PyObject *resultobj = 0;
   OutputData< double > *arg1 = 0 ;
@@ -45683,6 +45719,13 @@ static PyMethodDef SwigMethods[] = {
 	 { "IntensityData___setitem__", _wrap_IntensityData___setitem__, METH_VARARGS, "IntensityData___setitem__(IntensityData self, unsigned int i, double value) -> double"},
 	 { "IntensityData_swigregister", IntensityData_swigregister, METH_O, NULL},
 	 { "IntensityData_swiginit", IntensityData_swiginit, METH_VARARGS, NULL},
+	 { "relativeDataDifference", _wrap_relativeDataDifference, METH_VARARGS, "\n"
+		"relativeDataDifference(IntensityData dat, IntensityData ref) -> double\n"
+		"double DataUtils::relativeDataDifference(const OutputData< double > &dat, const OutputData< double > &ref)\n"
+		"\n"
+		"Returns relative difference between two data sets sum(dat[i] - ref[i])/ref[i]). \n"
+		"\n"
+		""},
 	 { "checkRelativeDifference", _wrap_checkRelativeDifference, METH_VARARGS, "\n"
 		"checkRelativeDifference(IntensityData dat, IntensityData ref, double const threshold) -> bool\n"
 		"bool DataUtils::checkRelativeDifference(const OutputData< double > &dat, const OutputData< double > &ref, const double threshold)\n"
-- 
GitLab