Mantid
Loading...
Searching...
No Matches
InelasticIsoRotDiff.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
12#include <boost/math/special_functions/bessel.hpp>
13#include <cmath>
14#include <limits>
15
17
18namespace {
19Mantid::Kernel::Logger g_log("IsoRotDiff");
20}
21
23
24DECLARE_FUNCTION(InelasticIsoRotDiff)
25
26
30 this->declareParameter("Height", 1.0, "scaling factor");
31 this->declareParameter("Radius", 0.98, "radius of rotation (Angstroms)");
32 this->declareParameter("Tau", 10.0, "Relaxation time, inverse of the rotational diffusion coefficient (ps)");
33 this->declareParameter("Centre", 0.0, "Shift along the X-axis");
34
35 this->declareAttribute("Q", API::IFunction::Attribute(0.3));
36 this->declareAttribute("N", API::IFunction::Attribute(25));
37}
38
43 // Ensure positive values for Height, Radius, and Diffusion constant
44 auto HeightConstraint = std::make_unique<BConstraint>(this, "Height", std::numeric_limits<double>::epsilon(), true);
45 this->addConstraint(std::move(HeightConstraint));
46 auto RadiusConstraint = std::make_unique<BConstraint>(this, "Radius", std::numeric_limits<double>::epsilon(), true);
47 this->addConstraint(std::move(RadiusConstraint));
48 auto DiffusionConstraint = std::make_unique<BConstraint>(this, "Tau", std::numeric_limits<double>::epsilon(), true);
49 this->addConstraint(std::move(DiffusionConstraint));
50}
51
58void InelasticIsoRotDiff::function1D(double *out, const double *xValues, const size_t nData) const {
59 double hbar(0.658211626); // ps*meV
60 auto H = this->getParameter("Height");
61 auto R = this->getParameter("Radius");
62 auto T = this->getParameter("Tau");
63 auto C = this->getParameter("Centre");
64 auto Q = this->getAttribute("Q").asDouble();
65 auto N = static_cast<size_t>(this->getAttribute("N").asInt()); // Number of Lorentzians
66
67 // Penalize negative parameters
68 if (R < std::numeric_limits<double>::epsilon()) {
69 for (size_t j = 0; j < nData; j++) {
70 out[j] = std::numeric_limits<double>::infinity();
71 }
72 return;
73 }
74
75 // Lorentzian intensities and HWHM
76 std::vector<double> al(N);
77 std::vector<double> HWHM(N);
78 for (size_t i = 0; i < N; i++) {
79 auto l = static_cast<unsigned int>(i + 1); // avoid annoying warnings from implicit type conversion
80 auto ld = static_cast<double>(l); // avoid annoying warnings from implicit type conversion
81 al[i] = (2 * ld + 1) * pow(boost::math::sph_bessel(l, Q * R), 2);
82 HWHM[i] = ld * (ld + 1) * hbar / T;
83 }
84
85 for (size_t j = 0; j < nData; j++) {
86 out[j] = 0.0;
87 auto E = xValues[j] - C;
88 for (size_t i = 0; i < N; i++) {
89 auto G = HWHM[i];
90 out[j] += H * al[i] * G / (G * G + E * E) / M_PI;
91 }
92 }
93}
94
95} // 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:285
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...
Inelastic part of the IsoRotDiff function.
void init() override
overwrite IFunction base class methods
void function1D(double *out, const double *xValues, const size_t nData) const override
Calculate function values on an energy domain.
The Logger class is in charge of the publishing messages from the framework through various channels.
Definition Logger.h:51