Skip to content
Snippets Groups Projects
Commit c9974cd5 authored by Matthew Andrew's avatar Matthew Andrew
Browse files

Add createInitializedMultiDomainFunction to functionFactory Re #28057

By far the most common type of multidomain function you want to create is one where each domain has the same functional form and has a domain index equal to it's place in the function. This adds a method to cover this case to function factory.
parent a76721f4
No related branches found
No related tags found
No related merge requests found
...@@ -26,6 +26,7 @@ namespace API { ...@@ -26,6 +26,7 @@ namespace API {
class IFunction; class IFunction;
class CompositeFunction; class CompositeFunction;
class Expression; class Expression;
class MultiDomainFunction;
/** @class FunctionFactoryImpl /** @class FunctionFactoryImpl
...@@ -52,6 +53,12 @@ public: ...@@ -52,6 +53,12 @@ public:
/// Creates an instance of a function /// Creates an instance of a function
std::shared_ptr<IFunction> createInitialized(const std::string &input) const; 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 /// Query available functions based on the template type
template <typename FunctionType> template <typename FunctionType>
std::vector<std::string> getFunctionNames() const; std::vector<std::string> getFunctionNames() const;
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "MantidKernel/LibraryManager.h" #include "MantidKernel/LibraryManager.h"
#include "MantidKernel/StringTokenizer.h" #include "MantidKernel/StringTokenizer.h"
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <boost/make_shared.hpp>
#include <sstream> #include <sstream>
namespace Mantid { namespace Mantid {
...@@ -73,6 +74,37 @@ FunctionFactoryImpl::createInitialized(const std::string &input) const { ...@@ -73,6 +74,37 @@ FunctionFactoryImpl::createInitialized(const std::string &input) const {
return createSimple(e, parentAttributes); 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. * Create a function from an expression.
* @param expr :: The input expression * @param expr :: The input expression
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment