-
Notifications
You must be signed in to change notification settings - Fork 122
/
ThermalNeutronBk2BkExpAlpha.cpp
75 lines (59 loc) · 2.42 KB
/
ThermalNeutronBk2BkExpAlpha.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
// 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/ThermalNeutronBk2BkExpAlpha.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::CurveFitting::Functions {
using namespace CurveFitting;
DECLARE_FUNCTION(ThermalNeutronBk2BkExpAlpha)
//----------------------------------------------------------------------------------------------
/** Defintion of parameter
*/
void ThermalNeutronBk2BkExpAlpha::init() {
// Geometry related
declareParameter("Width", 1.0);
declareParameter("Tcross", 1.0);
declareParameter("Alph0", 0.0);
declareParameter("Alph1", 0.0);
declareParameter("Alph0t", 0.0);
declareParameter("Alph1t", 0.0);
}
//----------------------------------------------------------------------------------------------
/** Function 1D
*/
void ThermalNeutronBk2BkExpAlpha::function1D(double *out, const double *xValues, const size_t nData) const {
double width = getParameter("Width");
double tcross = getParameter("Tcross");
double alph0 = getParameter("Alph0");
double alph1 = getParameter("Alph1");
double alph0t = getParameter("Alph0t");
double alph1t = getParameter("Alph1t");
for (size_t i = 0; i < nData; ++i) {
out[i] = corefunction(xValues[i], width, tcross, alph0, alph1, alph0t, alph1t);
}
}
/** Derivative: use numerical derivative
*/
void ThermalNeutronBk2BkExpAlpha::functionDeriv(const FunctionDomain &domain, Jacobian &jacobian) {
calNumericalDeriv(domain, jacobian);
}
//----------------------------------------------------------------------------------------------
/** Core function
*/
double ThermalNeutronBk2BkExpAlpha::corefunction(double dh, double width, double tcross, double alph0, double alph1,
double alph0t, double alph1t) const {
double n = 0.5 * gsl_sf_erfc(width * (tcross - 1.0 / dh));
double alpha = 1.0 / (n * (alph0 + alph1 * dh) + (1.0 - n) * (alph0t - alph1t / dh));
return alpha;
}
} // namespace Mantid::CurveFitting::Functions