/
DiffSphere.cpp
79 lines (67 loc) · 2.76 KB
/
DiffSphere.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
// 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/DiffSphere.h"
#include "MantidAPI/FunctionFactory.h"
#include "MantidAPI/IFunction.h"
#include "MantidAPI/ImmutableCompositeFunction.h"
#include "MantidCurveFitting/Functions/ElasticDiffSphere.h"
#include "MantidCurveFitting/Functions/InelasticDiffSphere.h"
#include <boost/math/special_functions/bessel.hpp>
#include <cmath>
#include <limits>
namespace {
Mantid::Kernel::Logger g_log("DiffSphere");
}
namespace Mantid::CurveFitting::Functions {
DECLARE_FUNCTION(DiffSphere)
/**
* @brief Propagate the attribute to its member functions.
* NOTE: we pass this->getAttribute(name) by reference, thus the same
* object is shared by the composite function and its members.
* @param name Name of the attribute
*/
void DiffSphere::trickleDownAttribute(const std::string &name) {
for (size_t iFun = 0; iFun < this->nFunctions(); iFun++) {
API::IFunction_sptr fun = this->getFunction(iFun);
if (fun->hasAttribute(name)) {
fun->setAttribute(name, this->getAttribute(name));
}
}
}
/**
* @brief Overwrite attributes of member functions with same name
*/
void DiffSphere::declareAttribute(const std::string &name, const API::IFunction::Attribute &defaultValue) {
API::ImmutableCompositeFunction::declareAttribute(name, defaultValue);
this->trickleDownAttribute(name);
}
/**
* @brief Overwrite attributes of member functions with same name
* @param name Name of the attribute
* @param att the attribute to be propagated to elastic and inelastic parts
*/
void DiffSphere::setAttribute(const std::string &name, const API::IFunction::Attribute &att) {
API::ImmutableCompositeFunction::setAttribute(name, att);
this->trickleDownAttribute(name);
}
/**
* @brief Initialize elastic and inelastic parts, aliases, attributes, and ties
*/
void DiffSphere::init() {
m_elastic = std::dynamic_pointer_cast<ElasticDiffSphere>(
API::FunctionFactory::Instance().createFunction("ElasticDiffSphere"));
this->addFunction(m_elastic);
m_inelastic = std::dynamic_pointer_cast<InelasticDiffSphere>(
API::FunctionFactory::Instance().createFunction("InelasticDiffSphere"));
this->addFunction(m_inelastic);
this->setAttributeValue("NumDeriv", true);
this->declareAttribute("Q", API::IFunction::Attribute(1.0));
// Set the ties between Elastic and Inelastic parameters
this->addDefaultTies("f0.Height=f1.Intensity,f0.Radius=f1.Radius,f0.Centre=0");
this->applyTies();
}
} // namespace Mantid::CurveFitting::Functions