/
EndErfc.cpp
60 lines (48 loc) · 1.52 KB
/
EndErfc.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
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidCurveFitting/Functions/EndErfc.h"
#include "MantidAPI/FunctionFactory.h"
#include <cmath>
#include <gsl/gsl_sf_erf.h>
namespace Mantid {
namespace CurveFitting {
namespace Functions {
using namespace CurveFitting;
using namespace Kernel;
using namespace API;
DECLARE_FUNCTION(EndErfc)
void EndErfc::init() {
declareParameter(
"A", 2000.0,
"Half value at minus infinity minus half value at plus infinity");
declareParameter("B", 50.0, "Mid x value");
declareParameter("C", 6.0, "Width parameter");
declareParameter("D", 0.0, "Minimum value - must not be negative");
}
void EndErfc::function1D(double *out, const double *xValues,
const size_t nData) const {
const double gA = getParameter("A");
const double gB = getParameter("B");
const double gC = getParameter("C");
const double gD = getParameter("D");
for (size_t i = 0; i < nData; i++) {
double x = xValues[i];
out[i] = gA * gsl_sf_erfc((gB - x) / gC) + gD;
}
if (gA < 0) {
for (size_t i = 0; i < nData; i++) {
out[i] = -2 * gA;
}
}
}
void EndErfc::setActiveParameter(size_t i, double value) {
size_t j = i;
if (parameterName(j) == "D" && value < 0.0)
setParameter(j, 0.0, false); // Don't let D become negative
else
setParameter(j, value, false);
}
} // namespace Functions
} // namespace CurveFitting
} // namespace Mantid