Mantid
Loading...
Searching...
No Matches
FunctionParameterDecorator.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 +
13
14namespace Mantid::API {
15
16void FunctionParameterDecorator::setDecoratedFunction(const std::string &wrappedFunctionName) {
17 IFunction_sptr fn = FunctionFactory::Instance().createFunction(wrappedFunctionName);
18
20
22}
23
25
28 std::dynamic_pointer_cast<FunctionParameterDecorator>(FunctionFactory::Instance().createFunction(name()));
29
30 if (!cloned) {
31 throw std::runtime_error("Cloned function is not of type FunctionParameterDecorator, aborting.");
32 }
33
35
36 if (decoratedFn) {
37 cloned->setDecoratedFunctionPrivate(decoratedFn->clone());
38 }
39
40 return cloned;
41}
42
43void FunctionParameterDecorator::setWorkspace(std::shared_ptr<const Workspace> ws) {
45
46 m_wrappedFunction->setWorkspace(ws);
47}
48
49void FunctionParameterDecorator::setMatrixWorkspace(std::shared_ptr<const MatrixWorkspace> workspace, size_t wi,
50 double startX, double endX) {
52
53 m_wrappedFunction->setMatrixWorkspace(workspace, wi, startX, endX);
54}
55
56void FunctionParameterDecorator::setParameter(size_t i, const double &value, bool explicitlySet) {
58
59 m_wrappedFunction->setParameter(i, value, explicitlySet);
60}
61
62void FunctionParameterDecorator::setParameterDescription(size_t i, const std::string &description) {
64
65 m_wrappedFunction->setParameterDescription(i, description);
66}
67
70
71 return m_wrappedFunction->getParameter(i);
72}
73
74void FunctionParameterDecorator::setParameter(const std::string &name, const double &value, bool explicitlySet) {
76
77 m_wrappedFunction->setParameter(name, value, explicitlySet);
78}
79
80void FunctionParameterDecorator::setParameterDescription(const std::string &name, const std::string &description) {
82
83 m_wrappedFunction->setParameterDescription(name, description);
84}
85
88
89 return m_wrappedFunction->activeParameter(i);
90}
91
94
95 m_wrappedFunction->setActiveParameter(i, value);
96}
97
98double FunctionParameterDecorator::getParameter(const std::string &name) const {
100
101 return m_wrappedFunction->getParameter(name);
102}
103
104bool FunctionParameterDecorator::hasParameter(const std::string &name) const {
106 return m_wrappedFunction->hasParameter(name);
107}
108
110 if (!m_wrappedFunction) {
111 return 0;
112 }
113
114 return m_wrappedFunction->nParams();
115}
116
117size_t FunctionParameterDecorator::parameterIndex(const std::string &name) const {
119
120 return m_wrappedFunction->parameterIndex(name);
121}
122
123std::string FunctionParameterDecorator::parameterName(size_t i) const {
125
126 return m_wrappedFunction->parameterName(i);
127}
128
131
132 return m_wrappedFunction->parameterDescription(i);
133}
134
137
138 return m_wrappedFunction->isExplicitlySet(i);
139}
140
143
144 return m_wrappedFunction->getError(i);
145}
146
147double FunctionParameterDecorator::getError(const std::string &name) const {
148 auto index = parameterIndex(name);
149 return getError(index);
150}
151
152void FunctionParameterDecorator::setError(size_t i, double err) {
154
155 return m_wrappedFunction->setError(i, err);
156}
157
158void FunctionParameterDecorator::setError(const std::string &name, double err) {
159 auto index = parameterIndex(name);
160 setError(index, err);
161}
162
165
166 if (std::dynamic_pointer_cast<CompositeFunction>(m_wrappedFunction)) {
167 return m_wrappedFunction->getParameterIndex(ref);
168 }
169
170 if (ref.getLocalFunction() == this && ref.getLocalIndex() < nParams()) {
171 return ref.getLocalIndex();
172 }
173
174 return nParams();
175}
176
178 if (!m_wrappedFunction) {
179 return 0;
180 }
181
182 return m_wrappedFunction->nAttributes();
183}
184
185std::vector<std::string> FunctionParameterDecorator::getAttributeNames() const {
187
188 return m_wrappedFunction->getAttributeNames();
189}
190
193
194 return m_wrappedFunction->getAttribute(attName);
195}
196
197void FunctionParameterDecorator::setAttribute(const std::string &attName, const IFunction::Attribute &attValue) {
199
200 m_wrappedFunction->setAttribute(attName, attValue);
201}
202
203bool FunctionParameterDecorator::hasAttribute(const std::string &attName) const {
205
206 return m_wrappedFunction->hasAttribute(attName);
207}
208
211 m_wrappedFunction->setParameterStatus(i, status);
212}
213
216 return m_wrappedFunction->getParameterStatus(i);
217}
218
221
222 m_wrappedFunction->applyTies();
223}
224
227
228 m_wrappedFunction->clearTies();
229}
230
231void FunctionParameterDecorator::removeTie(const std::string &parName) {
233
234 m_wrappedFunction->removeTie(parName);
235}
236
239
240 return m_wrappedFunction->removeTie(i);
241}
242
245
246 return m_wrappedFunction->getTie(i);
247}
248
249void FunctionParameterDecorator::addConstraint(std::unique_ptr<IConstraint> ic) {
251
252 m_wrappedFunction->addConstraint(std::move(ic));
253}
254
257
258 return m_wrappedFunction->getConstraint(i);
259}
260
261void FunctionParameterDecorator::removeConstraint(const std::string &parName) {
263
264 m_wrappedFunction->removeConstraint(parName);
265}
266
269
270 m_wrappedFunction->setUpForFit();
271}
272
275 if (!m_wrappedFunction) {
276 throw std::runtime_error("No wrapped function set, aborting.");
277 }
278}
279
281void FunctionParameterDecorator::declareParameter(const std::string &name, double initValue,
282 const std::string &description) {
284 UNUSED_ARG(initValue);
285 UNUSED_ARG(description);
286}
287
288void FunctionParameterDecorator::tie(const std::string &parName, const std::string &expr, bool isDefault) {
290 m_wrappedFunction->tie(parName, expr, isDefault);
291}
292
294void FunctionParameterDecorator::addTie(std::unique_ptr<ParameterTie> tie) {
296
297 m_wrappedFunction->addTie(std::move(tie));
298}
299
311
313
314} // namespace Mantid::API
double value
The value of the point.
Definition: FitMW.cpp:51
IPeaksWorkspace_sptr workspace
Definition: IndexPeaks.cpp:114
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
Definition: System.h:64
double activeParameter(size_t i) const override
Value of i-th active parameter of the decorated function.
bool hasParameter(const std::string &name) const override
Check if the decorated function has a parameter with this name.
void setDecoratedFunction(const std::string &wrappedFunctionName)
IFunction_sptr clone() const override
Virtual copy constructor.
ParameterStatus getParameterStatus(size_t i) const override
Get status of parameter.
void addTie(std::unique_ptr< ParameterTie >) override
Forwads addTie-call to the decorated function.
void removeConstraint(const std::string &parName) override
Remove a constraint of decorated function.
void setMatrixWorkspace(std::shared_ptr< const MatrixWorkspace > workspace, size_t wi, double startX, double endX) override
Set matrix workspace.
void setAttribute(const std::string &attName, const IFunction::Attribute &attValue) override
Set a value to attribute attName of decorated function.
void throwIfNoFunctionSet() const
Throws std::runtime_error when m_wrappedFunction is not set.
void setActiveParameter(size_t i, double value) override
Set new value of i-th active parameter of the decorated function.
void removeTie(const std::string &parName) override
Removes the tie off a parameter.
ParameterTie * getTie(size_t i) const override
Get the tie of i-th parameter of decorated function.
size_t nAttributes() const override
Returns the number of attributes associated with the decorated function.
void setUpForFit() override
Set parameters of decorated function to satisfy constraints.
std::string parameterName(size_t i) const override
Returns the name of parameter i of decorated function.
void setParameterStatus(size_t i, ParameterStatus status) override
Change status of parameter.
bool hasAttribute(const std::string &attName) const override
Check if attribute attName exists in decorated function.
virtual void beforeDecoratedFunctionSet(const IFunction_sptr &fn)
Function that is called before the decorated function is set.
void setDecoratedFunctionPrivate(const IFunction_sptr &fn)
size_t parameterIndex(const std::string &name) const override
Returns the index of parameter of decorated function name.
std::string parameterDescription(size_t i) const override
Returns the description of parameter i of decorated function.
size_t nParams() const override
Total number of parameters of decorated function.
void setParameterDescription(size_t i, const std::string &description) override
Set i-th parameter description of decorated function.
void declareParameter(const std::string &name, double initValue, const std::string &description) override
Does nothing, function does not have parameters.
void tie(const std::string &parName, const std::string &expr, bool isDefault=false) override
Tie a parameter of decorated function to other parameters (or a constant).
void setParameter(size_t i, const double &value, bool explicitlySet=true) override
Set i-th parameter of decorated function.
void addConstraint(std::unique_ptr< IConstraint > ic) override
Add a constraint to decorated function.
bool isExplicitlySet(size_t i) const override
Checks if a parameter of decorated function has been set explicitly.
double getParameter(size_t i) const override
Get i-th parameter of decorated function.
void setError(size_t i, double err) override
Set the fitting error for a parameter of decorated function.
void setWorkspace(std::shared_ptr< const Workspace > ws) override
Set the workspace.
std::vector< std::string > getAttributeNames() const override
Returns a list of attribute names of decorated function.
IConstraint * getConstraint(size_t i) const override
Get constraint of i-th parameter of decorated function.
double getError(size_t i) const override
Get the fitting error for a parameter of decorated function.
IFunction::Attribute getAttribute(const std::string &attName) const override
Return a value of attribute attName of decorated function-.
size_t getParameterIndex(const ParameterReference &ref) const override
Return parameter index of decorated function from a parameter reference.
void clearTies() override
Remove all ties of decorated function.
void applyTies() override
Apply the ties in decorated function.
An interface to a constraint.
Definition: IConstraint.h:26
Attribute is a non-fitting parameter.
Definition: IFunction.h:282
ParameterStatus
Describe parameter status in relation to fitting: Active: Fit varies such parameter directly.
Definition: IFunction.h:649
virtual std::string name() const =0
Returns the function's name.
A reference to a parameter in a function.
std::size_t getLocalIndex() const
Return parameter index in the local function.
IFunction * getLocalFunction() const
Return pointer to the local function.
Ties fitting parameters.
Definition: ParameterTie.h:35
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< FunctionParameterDecorator > FunctionParameterDecorator_sptr
std::shared_ptr< IFunction > IFunction_sptr
shared pointer to the function base class
Definition: IFunction.h:732