/
ElasticDiffSphere.cpp
63 lines (51 loc) · 2.05 KB
/
ElasticDiffSphere.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#include "MantidCurveFitting/Functions/ElasticDiffSphere.h"
#include "MantidAPI/FunctionFactory.h"
#include "MantidAPI/IFunction.h"
#include "MantidCurveFitting/Constraints/BoundaryConstraint.h"
#include <boost/math/special_functions/bessel.hpp>
#include <cmath>
#include <limits>
using BConstraint = Mantid::CurveFitting::Constraints::BoundaryConstraint;
namespace {
Mantid::Kernel::Logger g_log("ElasticDiffSphere");
}
namespace Mantid::CurveFitting::Functions {
DECLARE_FUNCTION(ElasticDiffSphere)
/**
* @brief Constructor where fitting parameters are declared
*/
ElasticDiffSphere::ElasticDiffSphere() {
// parameter "Height" declared in parent DeltaFunction constructor
// declareParameter("Height", 1.0);
declareParameter("Radius", 2.0, "Sphere radius");
FunctionQDepends::declareAttributes();
}
/**
* @brief Set constraints on fitting parameters
*/
void ElasticDiffSphere::init() {
// Ensure positive values for Height and Radius
auto HeightConstraint = std::make_unique<BConstraint>(this, "Height", std::numeric_limits<double>::epsilon(), true);
this->addConstraint(std::move(HeightConstraint));
auto RadiusConstraint = std::make_unique<BConstraint>(this, "Radius", std::numeric_limits<double>::epsilon(), true);
this->addConstraint(std::move(RadiusConstraint));
}
/**
* @brief Calculate intensity of the elastic signal
*/
double ElasticDiffSphere::HeightPrefactor() const {
const double R = this->getParameter("Radius");
const double Q = this->getAttribute("Q").asDouble();
// Penalize negative parameters
if (R < std::numeric_limits<double>::epsilon()) {
return std::numeric_limits<double>::infinity();
}
return pow(3 * boost::math::sph_bessel(1, Q * R) / (Q * R), 2);
}
} // namespace Mantid::CurveFitting::Functions