Mantid
Loading...
Searching...
No Matches
ParameterReference.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
9
10namespace Mantid::API {
11
13ParameterReference::ParameterReference() : m_owner(), m_function(), m_index(0), m_isDefault(false) {}
14
23ParameterReference::ParameterReference(IFunction *fun, std::size_t index, bool isDefault)
24 : m_owner(fun), m_function(fun), m_index(index), m_isDefault(isDefault) {
25 reset(fun, index, isDefault);
26}
27
30
32std::size_t ParameterReference::getLocalIndex() const { return m_index; }
33
35std::size_t ParameterReference::parameterIndex() const { return m_owner->getParameterIndex(*this); }
36
39
48void ParameterReference::reset(IFunction *fun, std::size_t index, bool isDefault) {
49 m_owner = fun;
50 IFunction *fLocal = fun;
51 size_t iLocal = index;
52 auto *cf = dynamic_cast<CompositeFunction *>(fun);
53 while (cf) {
54 size_t iFun = cf->functionIndex(iLocal); // TODO squashing the warning breaks the code
55 fLocal = cf->getFunction(iFun).get();
56 iLocal = fLocal->parameterIndex(cf->parameterLocalName(iLocal));
57 cf = dynamic_cast<CompositeFunction *>(fLocal);
58 }
59
60 m_function = fLocal;
61 m_index = iLocal;
63}
64
71void ParameterReference::setParameter(const double &value, bool isExplicitlySet) {
72 m_function->setParameter(m_index, value, isExplicitlySet);
73}
74
77
79
82
87 if (fun == m_function) {
88 return true;
89 }
90 size_t iLocal = m_index;
91 auto cf = dynamic_cast<const CompositeFunction *>(m_function);
92 while (cf) {
93 size_t iFun = cf->functionIndex(iLocal);
94 const auto fLocal = cf->getFunction(iFun).get();
95 if (fLocal == fun) {
96 return true;
97 }
98 iLocal = fLocal->parameterIndex(cf->parameterLocalName(iLocal));
99 cf = dynamic_cast<CompositeFunction *>(fLocal);
100 }
101 return false;
102}
103
104} // namespace Mantid::API
double value
The value of the point.
Definition: FitMW.cpp:51
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
A composite function is a function containing other functions.
std::size_t functionIndex(const std::string &functionName) const
Get the first function index with a matching function name.
This is an interface to a fitting function - a semi-abstarct class.
Definition: IFunction.h:163
virtual double getParameter(size_t i) const =0
Get i-th parameter.
virtual void setParameter(size_t, const double &value, bool explicitlySet=true)=0
Set i-th parameter.
virtual size_t getParameterIndex(const ParameterReference &ref) const =0
Return parameter index from a parameter reference.
virtual std::string parameterName(size_t i) const =0
Returns the name of parameter i.
virtual std::shared_ptr< IFunction > getFunction(size_t i) const
Returns the pointer to i-th child function.
Definition: IFunction.cpp:1363
virtual size_t parameterIndex(const std::string &name) const =0
Returns the index of parameter name.
ParameterReference()
Default constructor.
bool isDefault() const
Returns the default value flag.
double getParameter() const
Get the value of the parameter.
std::size_t getLocalIndex() const
Return parameter index in the local function.
bool isParameterOf(const IFunction *fun) const
Find out if this refers to a parameter of a function: direct or via composite function member.
IFunction * m_function
Function that together with m_index uniquely identify the parameter.
std::size_t parameterIndex() const
Return parameter index in the owning function.
void reset(IFunction *fun, std::size_t index, bool isDefault=false)
Reset the reference.
bool m_isDefault
Flag to mark as default the value of an object associated with this reference: a tie or a constraint.
void setParameter(const double &value, bool isExplicitlySet=true)
Set the parameter.
IFunction * m_owner
Function-owner of this reference.
std::string parameterName() const
Return parameter name in the owning function.
std::size_t m_index
Index of the parameter in m_function.
IFunction * getLocalFunction() const
Return pointer to the local function.