/
IsoRotDiff.cpp
81 lines (70 loc) · 2.85 KB
/
IsoRotDiff.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
// 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/IsoRotDiff.h"
#include "MantidAPI/FunctionFactory.h"
#include "MantidAPI/IFunction.h"
#include "MantidAPI/ImmutableCompositeFunction.h"
#include "MantidCurveFitting/Functions/ElasticIsoRotDiff.h"
#include "MantidCurveFitting/Functions/InelasticIsoRotDiff.h"
#include <boost/math/special_functions/bessel.hpp>
#include <cmath>
#include <limits>
using Mantid::API::IFunction;
using Mantid::API::ImmutableCompositeFunction;
using Attribute = Mantid::API::IFunction::Attribute;
namespace {
Mantid::Kernel::Logger g_log("IsoRotDiff");
}
namespace Mantid::CurveFitting::Functions {
DECLARE_FUNCTION(IsoRotDiff)
/**
* @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 IsoRotDiff::trickleDownAttribute(const std::string &name) {
for (size_t iFun = 0; iFun < this->nFunctions(); iFun++) {
auto fun = this->getFunction(iFun);
if (fun->hasAttribute(name)) {
fun->setAttribute(name, this->getAttribute(name));
}
}
}
/**
* @brief Overwrite attributes of member functions with same name
*/
void IsoRotDiff::declareAttribute(const std::string &name, const Attribute &defaultValue) {
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 IsoRotDiff::setAttribute(const std::string &name, const Attribute &att) {
ImmutableCompositeFunction::setAttribute(name, att);
this->trickleDownAttribute(name);
}
/**
* @brief Initialize elastic and inelastic parts, aliases, attributes, and ties
*/
void IsoRotDiff::init() {
m_elastic = std::dynamic_pointer_cast<ElasticIsoRotDiff>(
API::FunctionFactory::Instance().createFunction("ElasticIsoRotDiff"));
this->addFunction(m_elastic);
m_inelastic = std::dynamic_pointer_cast<InelasticIsoRotDiff>(
API::FunctionFactory::Instance().createFunction("InelasticIsoRotDiff"));
this->addFunction(m_inelastic);
this->declareAttribute("Q", API::IFunction::Attribute(0.3));
this->declareAttribute("N", API::IFunction::Attribute(25));
// Set the ties between Elastic and Inelastic parameters
this->addDefaultTies("f1.Height=f0.Height,f1.Radius=f0.Radius,f1.Centre=f0.Centre");
this->applyTies();
}
} // namespace Mantid::CurveFitting::Functions