diff --git a/Framework/API/inc/MantidAPI/FunctionFactory.h b/Framework/API/inc/MantidAPI/FunctionFactory.h index 04482c86f7e79344ede9d1ba89e97ecea448b986..ec82e697a71b39bd745a44b24fd390ff89ec4d35 100644 --- a/Framework/API/inc/MantidAPI/FunctionFactory.h +++ b/Framework/API/inc/MantidAPI/FunctionFactory.h @@ -26,6 +26,7 @@ namespace API { class IFunction; class CompositeFunction; class Expression; +class MultiDomainFunction; /** @class FunctionFactoryImpl @@ -52,6 +53,12 @@ public: /// Creates an instance of a function std::shared_ptr<IFunction> createInitialized(const std::string &input) const; + /// Creates an instnce of an inizialised multidomain function where each + /// domain has the same function. + boost::shared_ptr<MultiDomainFunction> + createInitializedMultiDomainFunction(const std::string &input, + size_t domainNumber); + /// Query available functions based on the template type template <typename FunctionType> std::vector<std::string> getFunctionNames() const; diff --git a/Framework/API/src/FunctionFactory.cpp b/Framework/API/src/FunctionFactory.cpp index e9a1ea4e41baaa7525cb6440ed4cc5900ac712b5..26353c71e8cfb7961beb613b948db4b5369425aa 100644 --- a/Framework/API/src/FunctionFactory.cpp +++ b/Framework/API/src/FunctionFactory.cpp @@ -18,6 +18,7 @@ #include "MantidKernel/LibraryManager.h" #include "MantidKernel/StringTokenizer.h" #include <boost/lexical_cast.hpp> +#include <boost/make_shared.hpp> #include <sstream> namespace Mantid { @@ -73,6 +74,37 @@ FunctionFactoryImpl::createInitialized(const std::string &input) const { return createSimple(e, parentAttributes); } +/** + * @param input :: An input string which defines the function and initial values + * for the parameters. + * Parameters of different functions are separated by ';'. Parameters of the + * same function + * are separated by ','. parameterName=value pairs are used to set a parameter + * value. For each function + * "name" parameter must be set to a function name. E.g. + * input = "name=LinearBackground,A0=0,A1=1; name = Gaussian, + * PeakCentre=10.,Sigma=1" + * @param domainNumber :: The number of domains to add to the function. + * @return A pointer to the created function. + */ +boost::shared_ptr<MultiDomainFunction> +FunctionFactoryImpl::createInitializedMultiDomainFunction( + const std::string &input, size_t domainNumber) { + auto singleFunction = createInitialized(input); + auto multiDomainFunction = boost::make_shared<MultiDomainFunction>(); + + if (!singleFunction) { + return multiDomainFunction; + } + + for (size_t i = 0; i < domainNumber; ++i) { + multiDomainFunction->addFunction(singleFunction->clone()); + multiDomainFunction->setDomainIndex(i, i); + } + + return multiDomainFunction; +} + /** * Create a function from an expression. * @param expr :: The input expression