-
Notifications
You must be signed in to change notification settings - Fork 121
/
ThermalNeutronBk2BkExpSigma.cpp
82 lines (65 loc) · 2.44 KB
/
ThermalNeutronBk2BkExpSigma.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
71
72
73
74
75
76
77
78
79
80
81
82
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#include "MantidCurveFitting/Functions/ThermalNeutronBk2BkExpSigma.h"
#include "MantidAPI/FunctionFactory.h"
#include "MantidKernel/System.h"
#include <cmath>
#include <gsl/gsl_sf_erf.h>
using namespace std;
using namespace Mantid;
using namespace Mantid::API;
using namespace Mantid::CurveFitting;
namespace Mantid {
namespace CurveFitting {
namespace Functions {
using namespace CurveFitting;
DECLARE_FUNCTION(ThermalNeutronBk2BkExpSigma)
//----------------------------------------------------------------------------------------------
/** Defintion of parameter
*/
void ThermalNeutronBk2BkExpSigma::init() {
declareParameter("Sig0", 0.0);
declareParameter("Sig1", 0.0);
declareParameter("Sig2", 0.0);
}
//----------------------------------------------------------------------------------------------
/** Function 1D
*/
void ThermalNeutronBk2BkExpSigma::function1D(double *out, const double *xValues,
const size_t nData) const {
double sig0 = getParameter("Sig0");
double sig1 = getParameter("Sig1");
double sig2 = getParameter("Sig2");
double sig0sq = sig0 * sig0;
double sig1sq = sig1 * sig1;
double sig2sq = sig2 * sig2;
for (size_t i = 0; i < nData; ++i) {
out[i] = corefunction(xValues[i], sig0sq, sig1sq, sig2sq);
}
}
/** Derivative: use numerical derivative
*/
void ThermalNeutronBk2BkExpSigma::functionDeriv(const FunctionDomain &domain,
Jacobian &jacobian) {
calNumericalDeriv(domain, jacobian);
}
//----------------------------------------------------------------------------------------------
/** Core function
*/
double ThermalNeutronBk2BkExpSigma::corefunction(double dh, double sig0sq,
double sig1sq,
double sig2sq) const {
double sigma2 = sig0sq + sig1sq * dh * dh + sig2sq * pow(dh, 4);
if (sigma2 <= 0.0) {
throw runtime_error("Sigma^2 cannot be equal to or less than Zero!");
}
double sigma = sqrt(sigma2);
return sigma;
}
} // namespace Functions
} // namespace CurveFitting
} // namespace Mantid