Mantid
Loading...
Searching...
No Matches
ElasticDiffRotDiscreteCircle.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7// Mantid Coding standards <http://www.mantidproject.org/Coding_Standards>
8// Main Module Header
10// Mantid Headers from the same project
12// Mantid headers from other projects
14#include "MantidAPI/IFunction.h"
15
16// 3rd party library headers (N/A)
17// standard library headers
18#include <cmath>
19#include <limits>
20
22
23namespace {
24Mantid::Kernel::Logger g_log("ElasticDiffRotDiscreteCircle");
25}
26
28
29DECLARE_FUNCTION(ElasticDiffRotDiscreteCircle)
30
31
35 // declareParameter("Height", 1.0); //parameter "Height" already declared in
36 // constructor of base class DeltaFunction
37 this->declareParameter("Radius", 1.0, "Circle radius [Angstroms] ");
38 this->declareAttribute("N", API::IFunction::Attribute(3));
40}
41
46 // Ensure positive values for Height and Radius
47 auto HeightConstraint = std::make_unique<BConstraint>(this, "Height", std::numeric_limits<double>::epsilon(), true);
48 this->addConstraint(std::move(HeightConstraint));
49
50 auto RadiusConstraint = std::make_unique<BConstraint>(this, "Radius", std::numeric_limits<double>::epsilon(), true);
51 this->addConstraint(std::move(RadiusConstraint));
52}
53
58 auto R = this->getParameter("Radius");
59 auto Q = this->getAttribute("Q").asDouble();
60 auto N = this->getAttribute("N").asInt();
61 double aN = 0;
62 for (int k = 1; k < N; k++) {
63 double x = 2 * Q * R * sin(M_PI * k / N);
64 aN += sin(x) / x; // spherical Besell function of order zero j0==sin(x)/x
65 }
66 aN += 1; // limit for j0 when k==N, or x==0
67 return aN / N;
68}
69
70} // namespace Mantid::CurveFitting::Functions
#define DECLARE_FUNCTION(classname)
Macro for declaring a new type of function to be used with the FunctionFactory.
Attribute is a non-fitting parameter.
Definition: IFunction.h:282
int asInt() const
Returns int value if attribute is a int, throws exception otherwise.
Definition: IFunction.cpp:726
double asDouble() const
Returns double value if attribute is a double, throws exception otherwise.
Definition: IFunction.cpp:739
virtual Attribute getAttribute(const std::string &name) const
Return a value of attribute attName.
Definition: IFunction.cpp:1394
virtual void addConstraint(std::unique_ptr< IConstraint > ic)
Add a constraint to function.
Definition: IFunction.cpp:376
double getParameter(size_t i) const override
Get i-th parameter.
A boundary constraint is designed to be used to set either upper or lower (or both) boundaries on a s...
void init() override
overwrite IFunction base class method, which declare function parameters
double HeightPrefactor() const override
A rescaling of the peak intensity.
virtual void declareAttributes() override
declare commonattributes Q and WorkspaceIndex.
The Logger class is in charge of the publishing messages from the framework through various channels.
Definition: Logger.h:52