Mantid
Loading...
Searching...
No Matches
ImmutableCompositeFunction.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 +
7//----------------------------------------------------------------------
8// Includes
9//----------------------------------------------------------------------
12
13#include <algorithm>
14
15namespace Mantid::API {
16
17using std::size_t;
18
19//-----------------------------------------------------------------------------------------------
24std::string ImmutableCompositeFunction::writeToString(const std::string &parentLocalAttributesStr) const {
25 return IFunction::writeToString(parentLocalAttributesStr);
26}
27
33
40void ImmutableCompositeFunction::setParameter(const std::string &name, const double &value, bool explicitlySet) {
41 auto alias = m_aliases.find(name);
42 if (alias != m_aliases.end()) {
43 CompositeFunction::setParameter(alias->second, value, explicitlySet);
44 } else {
46 }
47}
48
54void ImmutableCompositeFunction::setParameterDescription(const std::string &name, const std::string &description) {
55 auto alias = m_aliases.find(name);
56 if (alias != m_aliases.end()) {
57 CompositeFunction::setParameterDescription(alias->second, description);
58 } else {
60 }
61}
62
68double ImmutableCompositeFunction::getParameter(const std::string &name) const {
69 auto alias = m_aliases.find(name);
70 if (alias != m_aliases.end()) {
71 return CompositeFunction::getParameter(alias->second);
72 }
74}
75
80size_t ImmutableCompositeFunction::parameterIndex(const std::string &name) const {
81 auto alias = m_aliases.find(name);
82 if (alias != m_aliases.end()) {
83 return alias->second;
84 }
86}
87
91std::string ImmutableCompositeFunction::parameterName(size_t i) const {
92 const auto found =
93 std::find_if(m_aliases.cbegin(), m_aliases.cend(), [i](const auto &element) { return element.second == i; });
94 if (found == m_aliases.cend()) {
96 } else {
97 return found->first;
98 }
99}
100
101//-----------------------------------------------------------------------------------------------
108void ImmutableCompositeFunction::setAlias(const std::string &parName, const std::string &alias) {
109 // make sure the alias is unique
110 if (m_aliases.count(alias) > 0) {
111 throw Kernel::Exception::ExistsError("ImmutableCompositeFunction", alias);
112 }
114}
115
124void ImmutableCompositeFunction::addDefaultTies(const std::string &ties) { CompositeFunction::addTies(ties, true); }
125
133void ImmutableCompositeFunction::addDefaultConstraints(const std::string &constraints) {
134 CompositeFunction::addConstraints(constraints, true);
135}
136
137} // namespace Mantid::API
double value
The value of the point.
Definition: FitMW.cpp:51
void setParameter(size_t, const double &value, bool explicitlySet=true) override
Set i-th parameter.
size_t parameterIndex(const std::string &name) const override
Returns the index of parameter name.
void setParameterDescription(size_t, const std::string &description) override
Set i-th parameter description.
double getParameter(size_t i) const override
Get i-th parameter.
std::string parameterName(size_t i) const override
Returns the name of parameter i.
This is an interface to a fitting function - a semi-abstarct class.
Definition: IFunction.h:163
virtual std::string writeToString(const std::string &parentLocalAttributesStr="") const
Writes itself into a string.
Definition: IFunction.cpp:471
virtual void addTies(const std::string &ties, bool isDefault=false)
Add several ties.
Definition: IFunction.cpp:233
virtual void addConstraints(const std::string &str, bool isDefault=false)
Add a list of conatraints from a string.
Definition: IFunction.cpp:521
void addDefaultTies(const std::string &ties)
Add default ties.
void setParameter(size_t i, const double &value, bool explicitlySet=true) override
Set i-th parameter.
std::string writeToString(const std::string &parentLocalAttributesStr="") const override
Writes itself into a string.
void setParameterDescription(size_t i, const std::string &description) override
Set i-th parameter description.
void setAlias(const std::string &parName, const std::string &alias)
Define an alias for a parameter.
std::map< std::string, size_t > m_aliases
Keep paramater aliases.
std::string name() const override
Returns the function's name.
size_t parameterIndex(const std::string &name) const override
Returns the index of parameter name.
void addDefaultConstraints(const std::string &constraints)
Add default constraints.
void addFunction(IFunction *fun)
Overload addFunction to take a bare pointer.
std::string parameterName(size_t i) const override
Returns the name of parameter i.
double getParameter(size_t i) const override
Get i-th parameter.
Exception for when an item is already in a collection.
Definition: Exception.h:164
std::shared_ptr< IFunction > IFunction_sptr
shared pointer to the function base class
Definition: IFunction.h:732