Mantid
Loading...
Searching...
No Matches
CriticalPeakRelaxationRate.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2021 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin
6// SPDX - License - Identifier: GPL - 3.0 +
7//----------------------------------------------------------------------
8// Includes
9//----------------------------------------------------------------------
12
13#include <cmath>
14
16
17using namespace CurveFitting;
18
19using namespace Kernel;
20
21using namespace API;
22
23DECLARE_FUNCTION(CriticalPeakRelaxationRate)
24
26 declareParameter("Scaling", 1.0, "coefficient for scaling");
27 declareParameter("CriticalTemp", 0.01, "coefficient for critical temperature");
28 declareParameter("Exponent", 1.0, "coefficient for critical exponent");
29 declareParameter("Background1", 0.0, "coefficient for non-critical background when x < Critical Temperature");
30 declareParameter("Background2", 0.0, "coefficient for non-critical background when x > Critical Temperature");
31 declareAttribute("Delta", Attribute(0.01));
32}
33
34void CriticalPeakRelaxationRate::function1D(double *out, const double *xValues, const size_t nData) const {
35
36 const double Scale = getParameter("Scaling");
37 const double Tc = getParameter("CriticalTemp");
38 const double Exp = getParameter("Exponent");
39 const double Bg1 = getParameter("Background1");
40 const double Bg2 = getParameter("Background2");
41 const double Delta = getAttribute("Delta").asDouble();
42
43 for (size_t i = 0; i < nData; i++) {
44 auto denom = pow(fabs(xValues[i] - Tc), Exp);
45 if (xValues[i] + Delta < Tc || xValues[i] - Delta > Tc) {
46 if (xValues[i] < Tc) {
47 out[i] = Bg1 + Scale / denom;
48 } else {
49 out[i] = Bg2 + Scale / denom;
50 }
51 } else {
52 out[i] = 1e6;
53 }
54 }
55}
56
57} // namespace Mantid::CurveFitting::Functions
#define DECLARE_FUNCTION(classname)
Macro for declaring a new type of function to be used with the FunctionFactory.
Mantid::API::IFunction::Attribute Attribute
Definition: IsoRotDiff.cpp:25
#define fabs(x)
Definition: Matrix.cpp:22
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
double getParameter(size_t i) const override
Get i-th parameter.
Provide Critical peak of relaxation rate for fitting interface to IFunction.
void function1D(double *out, const double *xValues, const size_t nData) const override
Function you want to fit to.