Mantid
Loading...
Searching...
No Matches
UserFunction.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2007 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#pragma once
8
9//----------------------------------------------------------------------
10// Includes
11//----------------------------------------------------------------------
14#include "MantidCurveFitting/DllConfig.h"
15#include <memory>
16
17namespace mu {
18class Parser;
19}
20
21namespace Mantid {
22namespace CurveFitting {
23namespace Functions {
30class MANTID_CURVEFITTING_DLL UserFunction : public API::ParamFunction, public API::IFunction1D {
31public:
35 ~UserFunction() override;
36
38 std::string name() const override { return "UserFunction"; }
39 // Returns Category
40 const std::string category() const override { return "General"; }
41
43 void function1D(double *out, const double *xValues, const size_t nData) const override;
45 void functionDeriv(const API::FunctionDomain &domain, API::Jacobian &jacobian) override;
46
48 size_t nAttributes() const override { return 1; }
50 std::vector<std::string> getAttributeNames() const override { return std::vector<std::string>(1, "Formula"); }
52 Attribute getAttribute(const std::string &attName) const override {
53 return attName == "Formula" ? Attribute(m_formula) : getAttribute(attName);
54 }
56 void setAttribute(const std::string &attName, const Attribute &value) override;
58 bool hasAttribute(const std::string &attName) const override { return attName == "Formula"; }
59
60private:
62 std::string m_formula;
64 mu::Parser *m_parser;
66 mutable double m_x;
68 bool m_x_set;
70 mutable std::vector<double> m_tmp;
72 mutable std::vector<double> m_tmp1;
73
75 static double *AddVariable(const char *varName, void *pufun);
76};
77
78} // namespace Functions
79} // namespace CurveFitting
80} // namespace Mantid
double value
The value of the point.
Definition: FitMW.cpp:51
Mantid::API::IFunction::Attribute Attribute
Definition: IsoRotDiff.cpp:25
Base class that represents the domain of a function.
This is a specialization of IFunction for functions of one real argument.
Definition: IFunction1D.h:43
Attribute is a non-fitting parameter.
Definition: IFunction.h:282
Represents the Jacobian in IFitFunction::functionDeriv.
Definition: Jacobian.h:22
Implements the part of IFunction interface dealing with parameters.
Definition: ParamFunction.h:33
bool hasAttribute(const std::string &attName) const override
Check if attribute attName exists.
Definition: UserFunction.h:58
std::vector< std::string > getAttributeNames() const override
Returns a list of attribute names.
Definition: UserFunction.h:50
std::string name() const override
Returns the function's name.
Definition: UserFunction.h:38
std::vector< double > m_tmp1
Temporary data storage used in functionDeriv.
Definition: UserFunction.h:72
bool m_x_set
True indicates that input formula contains 'x' variable.
Definition: UserFunction.h:68
double m_x
Used as 'x' variable in m_parser.
Definition: UserFunction.h:66
std::vector< double > m_tmp
Temporary data storage used in functionDeriv.
Definition: UserFunction.h:70
Attribute getAttribute(const std::string &attName) const override
Return a value of attribute attName.
Definition: UserFunction.h:52
const std::string category() const override
The categories the Fit function belong to.
Definition: UserFunction.h:40
mu::Parser * m_parser
extended muParser instance
Definition: UserFunction.h:64
size_t nAttributes() const override
Returns the number of attributes associated with the function.
Definition: UserFunction.h:48
Helper class which provides the Collimation Length for SANS instruments.