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 +
11#include "MantidKernel/Logger.h"
12
13#include <cmath>
14#include <limits>
15
17
18namespace {
19Mantid::Kernel::Logger g_log("ElasticDiffRotDiscreteCircle");
20}
21
23
24DECLARE_FUNCTION(ElasticDiffRotDiscreteCircle)
25
26
30 // declareParameter("Height", 1.0); //parameter "Height" already declared in
31 // constructor of base class DeltaFunction
32 this->declareParameter("Radius", 1.0, "Circle radius [Angstroms] ");
33 this->declareAttribute("N", API::IFunction::Attribute(3));
35}
36
41 // Ensure positive values for Height and Radius
42 auto HeightConstraint = std::make_unique<BConstraint>(this, "Height", std::numeric_limits<double>::epsilon(), true);
43 this->addConstraint(std::move(HeightConstraint));
44
45 auto RadiusConstraint = std::make_unique<BConstraint>(this, "Radius", std::numeric_limits<double>::epsilon(), true);
46 this->addConstraint(std::move(RadiusConstraint));
47}
48
53 auto R = this->getParameter("Radius");
54 auto Q = this->getAttribute("Q").asDouble();
55 auto N = this->getAttribute("N").asInt();
56 double aN = 0;
57 for (int k = 1; k < N; k++) {
58 double x = 2 * Q * R * sin(M_PI * k / N);
59 aN += sin(x) / x; // spherical Besell function of order zero j0==sin(x)/x
60 }
61 aN += 1; // limit for j0 when k==N, or x==0
62 return aN / N;
63}
64
65} // 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:286
int asInt() const
Returns int value if attribute is a int, throws exception otherwise.
double asDouble() const
Returns double value if attribute is a double, throws exception otherwise.
virtual Attribute getAttribute(const std::string &name) const
Return a value of attribute attName.
virtual void addConstraint(std::unique_ptr< IConstraint > ic)
Add a constraint to function.
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:51