diff --git a/Base/Const/PhysicalConstants.h b/Base/Const/PhysicalConstants.h index a1b8861001605b7dc39ff15e626ed71b8da8081a..557c8366ee46b3ef79ab7c44970cf59fd8bb10fb 100644 --- a/Base/Const/PhysicalConstants.h +++ b/Base/Const/PhysicalConstants.h @@ -15,8 +15,11 @@ #ifndef BORNAGAIN_BASE_CONST_PHYSICALCONSTANTS_H #define BORNAGAIN_BASE_CONST_PHYSICALCONSTANTS_H +//! Physical constants. + namespace PhysConsts { + constexpr double m_n = 1.67492749804e-27; //!< Neutron mass, kg constexpr double h_bar = 1.054571817e-34; //!< Reduced Plank constant, J s constexpr double mu_N = 5.0507837461e-27; //!< Nuclear magneton (\f$ \mu_N \f$), J/T @@ -25,6 +28,7 @@ constexpr double r_e = 2.8179403262e-15; //!< Thomson scattering length (\f$ r constexpr double gamma_n = 1.91304272; //!< \f$\gamma\f$ factor for neutron magnetic moment, //!< \f$\mu_n = \gamma \cdot \mu_N\f$ constexpr double g_factor_n = -3.82608545; //!< neutron g-factor + } // namespace PhysConsts #endif // BORNAGAIN_BASE_CONST_PHYSICALCONSTANTS_H diff --git a/Base/Math/Numeric.cpp b/Base/Math/Numeric.cpp index 55f48c22a19f8b207e93ca297df28ed0fa84324c..2f0e69690c74220244bb9c95733eb356911feeda 100644 --- a/Base/Math/Numeric.cpp +++ b/Base/Math/Numeric.cpp @@ -17,8 +17,6 @@ #include <cmath> #include <limits> -//! Floating-point epsilon, tolerances, almost-equal. - namespace Numeric { diff --git a/Base/Math/Numeric.h b/Base/Math/Numeric.h index 1311f2a32b2aa4433d170030e56362ba31478d5c..5effb0950f52267148e27ad79f543d1dd9e74bb4 100644 --- a/Base/Math/Numeric.h +++ b/Base/Math/Numeric.h @@ -17,7 +17,7 @@ #include <limits> -//! Floating-point epsilon, tolerances, almost-equal. +//! Floating-point approximations. namespace Numeric { diff --git a/Base/Math/Precomputed.h b/Base/Math/Precomputed.h index e3ed871351758161f038c679db3e1fca5c6d556a..070591016246e7c0fdd93585a35c9a3fe2631c35 100644 --- a/Base/Math/Precomputed.h +++ b/Base/Math/Precomputed.h @@ -3,7 +3,7 @@ // BornAgain: simulate and fit scattering at grazing incidence // //! @file Base/Math/Precomputed.h -//! @brief Defines namespace Precomputed, providing precomputed constants +//! @brief Defines namespace Math::Precomputed, providing precomputed constants //! //! @homepage http://www.bornagainproject.org //! @license GNU General Public License v3 or higher (see COPYING) @@ -19,9 +19,8 @@ #include <utility> #include <vector> -//! Compile-time generated std::array of reciprocal factorials -namespace Precomputed -{ +namespace Math::internal { + template <size_t N> struct ReciprocalFactorial { static constexpr double value = ReciprocalFactorial<N - 1>::value / N; }; @@ -31,16 +30,22 @@ template <> struct ReciprocalFactorial<0> { }; template <template <size_t> class F, size_t... I> -constexpr std::array<double, sizeof...(I)> GenerateArrayHelper(std::index_sequence<I...>) +constexpr std::array<double, sizeof...(I)> generateArrayHelper(std::index_sequence<I...>) { return {F<I>::value...}; }; +} // namespace Math::internal +namespace Math +{ + +//! Returns a compile-time generated std::array of reciprocal factorials. + template <size_t N, typename Indices = std::make_index_sequence<N>> -constexpr std::array<double, N> GenerateReciprocalFactorialArray() +constexpr std::array<double, N> generateReciprocalFactorialArray() { - return GenerateArrayHelper<ReciprocalFactorial>(Indices{}); + return internal::generateArrayHelper<internal::ReciprocalFactorial>(Indices{}); }; -} // namespace Precomputed +} // namespace Math #endif // BORNAGAIN_BASE_MATH_PRECOMPUTED_H diff --git a/Fit/Adapter/MinimizerAdapter.cpp b/Fit/Adapter/MinimizerAdapter.cpp index 5039c04405860374e17e35ce7296c451f6dc337e..ec9865cd0d2f0683a3c7f66ebc0ca15ada1e203b 100644 --- a/Fit/Adapter/MinimizerAdapter.cpp +++ b/Fit/Adapter/MinimizerAdapter.cpp @@ -56,7 +56,7 @@ MinimizerResult MinimizerAdapter::minimize(Parameters parameters) MinimizerResult result; result.setParameters(parameters); result.setMinValue(minValue()); - result.setReport(report::reportToString(*this)); + result.setReport(internal::reportToString(*this)); result.setNumberOfCalls(m_adapter->numberOfCalls()); result.setNumberOfGradientCalls(m_adapter->numberOfGradientCalls()); diff --git a/Fit/Adapter/Report.cpp b/Fit/Adapter/Report.cpp index 6eee327a8601200c2116e21e09b17ea1ed2f7f42..297a6e1647d75b27ec649ada3b2b77e9278604e3 100644 --- a/Fit/Adapter/Report.cpp +++ b/Fit/Adapter/Report.cpp @@ -71,10 +71,10 @@ std::string reportStatus(const MinimizerAdapter& minimizer) } // namespace // ************************************************************************************************ -// namespace report +// implement API // ************************************************************************************************ -std::string report::reportToString(const MinimizerAdapter& minimizer) +std::string mumufit::internal::reportToString(const MinimizerAdapter& minimizer) { std::ostringstream result; diff --git a/Fit/Adapter/Report.h b/Fit/Adapter/Report.h index eecd0e7aa9b0b4440646942d7f77430757a6420f..bfde8ad29cb3e8e2c346b111a7056d0f4d6fce8a 100644 --- a/Fit/Adapter/Report.h +++ b/Fit/Adapter/Report.h @@ -21,7 +21,7 @@ class MinimizerAdapter; //! Utility functions to generate reports -namespace report +namespace mumufit::internal { //! Reports results of minimization in the form of multi-line string diff --git a/Sample/HardParticle/PolyhedralComponents.cpp b/Sample/HardParticle/PolyhedralComponents.cpp index dcb0d8834fbfad4f76fab684b1488950364d056f..50f59f63beba1036e3a5174c18b1b7edaa8bfacf 100644 --- a/Sample/HardParticle/PolyhedralComponents.cpp +++ b/Sample/HardParticle/PolyhedralComponents.cpp @@ -21,7 +21,7 @@ namespace { const double eps = 2e-16; -constexpr auto ReciprocalFactorialArray = Precomputed::GenerateReciprocalFactorialArray<171>(); +constexpr auto ReciprocalFactorialArray = Math::generateReciprocalFactorialArray<171>(); } // namespace // ************************************************************************************************ diff --git a/Sample/Lattice/BakeLattice.h b/Sample/Lattice/BakeLattice.h index beb7ea75ea2e4eb686fc56e4d21c73a3d642bdb2..4ebbf577cc7157bb21af91002ed8028f75fcd5cb 100644 --- a/Sample/Lattice/BakeLattice.h +++ b/Sample/Lattice/BakeLattice.h @@ -17,6 +17,8 @@ class Lattice3D; +//! Functions that instantiate objects. To be used like constructors. + namespace bake { diff --git a/Tests/UnitTests/Core/Detector/PrecomputedTest.cpp b/Tests/UnitTests/Core/Detector/PrecomputedTest.cpp index f78d12df4f72a879d636e7822eb3eeef985e54f6..4bb6e29dae3f63c92f86ad4700e0bccedaaacbde 100644 --- a/Tests/UnitTests/Core/Detector/PrecomputedTest.cpp +++ b/Tests/UnitTests/Core/Detector/PrecomputedTest.cpp @@ -4,7 +4,7 @@ namespace { -constexpr auto ReciprocalFactorialArray = Precomputed::GenerateReciprocalFactorialArray<171>(); +constexpr auto ReciprocalFactorialArray = Math::generateReciprocalFactorialArray<171>(); } class PrecomputedTest : public ::testing::Test diff --git a/auto/Wrap/doxygenBase.i b/auto/Wrap/doxygenBase.i index a22bbd50c6cd346cd12b2dcca9c4a22e6c6ab156..b76bdda5c1eaf0245845e762cfc116187269b249 100644 --- a/auto/Wrap/doxygenBase.i +++ b/auto/Wrap/doxygenBase.i @@ -884,12 +884,12 @@ C++ includes: Integrator.h "; -// File: structPrecomputed_1_1ReciprocalFactorial.xml -%feature("docstring") Precomputed::ReciprocalFactorial ""; +// File: structMath_1_1internal_1_1ReciprocalFactorial.xml +%feature("docstring") Math::internal::ReciprocalFactorial ""; -// File: structPrecomputed_1_1ReciprocalFactorial_3_010_01_4.xml -%feature("docstring") Precomputed::ReciprocalFactorial< 0 > " +// File: structMath_1_1internal_1_1ReciprocalFactorial_3_010_01_4.xml +%feature("docstring") Math::internal::ReciprocalFactorial< 0 > " "; @@ -1354,6 +1354,11 @@ Error function of real-valued argument. %feature("docstring") Math::Bessel::GeneratePoissonRandom "double Math::GeneratePoissonRandom(double average) "; +%feature("docstring") Math::Bessel::generateReciprocalFactorialArray "constexpr std::array<double, N> Math::generateReciprocalFactorialArray() + +Returns a compile-time generated std::array of reciprocal factorials. +"; + // File: namespaceMath_1_1Bessel.xml %feature("docstring") Math::Bessel::J0 "double Math::Bessel::J0(double x) @@ -1392,6 +1397,11 @@ Complex Bessel function J1(x)/x. "; +// File: namespaceMath_1_1internal.xml +%feature("docstring") Math::internal::generateArrayHelper "constexpr std::array<double, sizeof...(I)> Math::internal::generateArrayHelper(std::index_sequence< I... >) +"; + + // File: namespaceNumeric.xml %feature("docstring") Numeric::GetAbsoluteDifference "double Numeric::GetAbsoluteDifference(double a, double b) @@ -1412,14 +1422,6 @@ Returns the difference of the logarithm; input values are truncated at the minim // File: namespacePhysConsts.xml -// File: namespacePrecomputed.xml -%feature("docstring") Precomputed::GenerateArrayHelper "constexpr std::array<double, sizeof...(I)> Precomputed::GenerateArrayHelper(std::index_sequence< I... >) -"; - -%feature("docstring") Precomputed::GenerateReciprocalFactorialArray "constexpr std::array<double, N> Precomputed::GenerateReciprocalFactorialArray() -"; - - // File: namespacePyEmbeddedUtils.xml %feature("docstring") PyEmbeddedUtils::toString "std::string PyEmbeddedUtils::toString(PyObject *obj) diff --git a/auto/Wrap/doxygenFit.i b/auto/Wrap/doxygenFit.i index ecb39797ef5fd06cc7a210fc1f0ab067ecf67be3..e0a95658f88214c3f200623796c46ed5be41fb23 100644 --- a/auto/Wrap/doxygenFit.i +++ b/auto/Wrap/doxygenFit.i @@ -1399,6 +1399,13 @@ Internal state of a WallclockTimer object. // File: namespacemumufit.xml +// File: namespacemumufit_1_1internal.xml +%feature("docstring") mumufit::internal::reportToString "std::string mumufit::internal::reportToString(const MinimizerAdapter &minimizer) + +Reports results of minimization in the form of multi-line string. +"; + + // File: namespacemumufit_1_1stringUtils.xml %feature("docstring") mumufit::stringUtils::matchesPattern "bool mumufit::stringUtils::matchesPattern(const std::string &text, const std::string &wildcardPattern) @@ -1458,13 +1465,6 @@ Returns horizontal line of 80 characters length with section name in it. "; -// File: namespacereport.xml -%feature("docstring") report::reportToString "std::string report::reportToString(const MinimizerAdapter &minimizer) - -Reports results of minimization in the form of multi-line string. -"; - - // File: namespaceROOT.xml