-
Notifications
You must be signed in to change notification settings - Fork 121
/
ElasticDiffRotDiscreteCircle.cpp
70 lines (61 loc) · 2.27 KB
/
ElasticDiffRotDiscreteCircle.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
64
65
66
67
68
69
70
// Mantid Coding standards <http://www.mantidproject.org/Coding_Standards>
// Main Module Header
#include "MantidCurveFitting/Functions/ElasticDiffRotDiscreteCircle.h"
// Mantid Headers from the same project
#include "MantidCurveFitting/Constraints/BoundaryConstraint.h"
// Mantid headers from other projects
#include "MantidAPI/FunctionFactory.h"
#include "MantidAPI/IFunction.h"
#include "MantidKernel/make_unique.h"
// 3rd party library headers (N/A)
// standard library headers
#include <cmath>
#include <limits>
using BConstraint = Mantid::CurveFitting::Constraints::BoundaryConstraint;
namespace {
Mantid::Kernel::Logger g_log("ElasticDiffRotDiscreteCircle");
}
namespace Mantid {
namespace CurveFitting {
namespace Functions {
DECLARE_FUNCTION(ElasticDiffRotDiscreteCircle)
/**
* @brief Constructor where fitting parameters are declared
*/
ElasticDiffRotDiscreteCircle::ElasticDiffRotDiscreteCircle() {
// declareParameter("Height", 1.0); //parameter "Height" already declared in
// constructor of base class DeltaFunction
this->declareParameter("Radius", 1.0, "Circle radius [Angstroms] ");
this->declareAttribute("Q", API::IFunction::Attribute(0.5));
this->declareAttribute("N", API::IFunction::Attribute(3));
}
/**
* @brief Set constraints on fitting parameters
*/
void ElasticDiffRotDiscreteCircle::init() {
// Ensure positive values for Height and Radius
auto HeightConstraint = Kernel::make_unique<BConstraint>(
this, "Height", std::numeric_limits<double>::epsilon(), true);
this->addConstraint(std::move(HeightConstraint));
auto RadiusConstraint = Kernel::make_unique<BConstraint>(
this, "Radius", std::numeric_limits<double>::epsilon(), true);
this->addConstraint(std::move(RadiusConstraint));
}
/**
* @brief Calculate intensity of the elastic signal
*/
double ElasticDiffRotDiscreteCircle::HeightPrefactor() const {
auto R = this->getParameter("Radius");
auto Q = this->getAttribute("Q").asDouble();
auto N = this->getAttribute("N").asInt();
double aN = 0;
for (int k = 1; k < N; k++) {
double x = 2 * Q * R * sin(M_PI * k / N);
aN += sin(x) / x; // spherical Besell function of order zero j0==sin(x)/x
}
aN += 1; // limit for j0 when k==N, or x==0
return aN / N;
}
} // namespace Functions
} // namespace CurveFitting
} // namespace Mantid