From ab778d253010cb9890ad3291f347113d383bf517 Mon Sep 17 00:00:00 2001 From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de> Date: Wed, 14 Jul 2021 17:07:49 +0200 Subject: [PATCH] make iffHardDisk thread safe --- .../InterferenceFunctionHardDisk.cpp | 27 +++++++++---------- .../Aggregate/InterferenceFunctionHardDisk.h | 3 --- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/Sample/Aggregate/InterferenceFunctionHardDisk.cpp b/Sample/Aggregate/InterferenceFunctionHardDisk.cpp index 98541377081..fa4381cdde1 100644 --- a/Sample/Aggregate/InterferenceFunctionHardDisk.cpp +++ b/Sample/Aggregate/InterferenceFunctionHardDisk.cpp @@ -82,16 +82,19 @@ double InterferenceFunctionHardDisk::density() const double InterferenceFunctionHardDisk::iff_without_dw(const kvector_t q) const { - double qx = q.x(); - double qy = q.y(); - m_q = 2.0 * std::sqrt(qx * qx + qy * qy) * m_radius; - m_packing = packingRatio(); - m_c_zero = Czero(m_packing); - m_s2 = S2(m_packing); - double c_q = + const double qx = q.x(); + const double qy = q.y(); + const double q2r = 2.0 * std::sqrt(qx * qx + qy * qy) * m_radius; + const double packing = packingRatio(); + const double c_zero = Czero(packing); + const double s2 = S2(packing); + const double c_q = 2.0 * M_PI - * RealIntegrator().integrate([&](double x) -> double { return integrand(x); }, 0.0, 1.0); - double rho = 4.0 * m_packing / M_PI; + * RealIntegrator().integrate([=](double x) -> double { + double cx = c_zero * (1.0 + 4.0 * packing * (W2(x / 2.0) - 1.0) + s2 * x); + return x * cx * Math::Bessel::J0(q2r * x); + }, 0.0, 1.0); + const double rho = 4.0 * packing / M_PI; return 1.0 / (1.0 - rho * c_q); } @@ -99,9 +102,3 @@ double InterferenceFunctionHardDisk::packingRatio() const { return M_PI * m_radius * m_radius * m_density; } - -double InterferenceFunctionHardDisk::integrand(double x) const -{ - double cx = m_c_zero * (1.0 + 4.0 * m_packing * (W2(x / 2.0) - 1.0) + m_s2 * x); - return x * cx * Math::Bessel::J0(m_q * x); -} diff --git a/Sample/Aggregate/InterferenceFunctionHardDisk.h b/Sample/Aggregate/InterferenceFunctionHardDisk.h index 6d5c6093978..db36bf72ab3 100644 --- a/Sample/Aggregate/InterferenceFunctionHardDisk.h +++ b/Sample/Aggregate/InterferenceFunctionHardDisk.h @@ -41,12 +41,9 @@ public: private: double iff_without_dw(const kvector_t q) const override; double packingRatio() const; - double integrand(double x) const; double m_radius; double m_density; - - mutable double m_q, m_c_zero, m_s2, m_packing; }; #endif // BORNAGAIN_SAMPLE_AGGREGATE_INTERFERENCEFUNCTIONHARDDISK_H -- GitLab