TEST(FunctionFactoryTest, CreateFitFunction_with_brackets_Test) { IFunction_sptr fun = FunctionFactory::instance().createFitFunction("FunctionFactoryTestFunction()"); EXPECT_TRUE( fun.get() != nullptr ); //Function1DTestFunction fun; FunctionDomain1DVector domain(0.0,1.0,10); FunctionValues values(domain); fun->function(domain,values); for(size_t i = 0; i < domain.size(); ++i) { double x = domain[i]; EXPECT_EQ( 1.0 * x - 3.0, values.getCalculated(i)); } }
Workspace_sptr SeqDomainSpectrumCreator::createOutputWorkspace( const std::string &baseName, IFunction_sptr function, boost::shared_ptr<FunctionDomain> domain, boost::shared_ptr<FunctionValues> values, const std::string &outputWorkspacePropertyName) { // don't need values, since the values need to be calculated spectrum by // spectrum (see loop below). UNUSED_ARG(values); boost::shared_ptr<SeqDomain> seqDomain = boost::dynamic_pointer_cast<SeqDomain>(domain); if (!seqDomain) { throw std::invalid_argument("CreateOutputWorkspace requires SeqDomain."); } if (!m_matrixWorkspace) { throw std::invalid_argument("No MatrixWorkspace assigned. Cannot construct " "proper output workspace."); } MatrixWorkspace_sptr outputWs = boost::dynamic_pointer_cast<MatrixWorkspace>( WorkspaceFactory::Instance().create(m_matrixWorkspace)); // Assign y-values, taking into account masked detectors for (size_t i = 0; i < seqDomain->getNDomains(); ++i) { FunctionDomain_sptr localDomain; FunctionValues_sptr localValues; seqDomain->getDomainAndValues(i, localDomain, localValues); function->function(*localDomain, *localValues); boost::shared_ptr<FunctionDomain1DSpectrum> spectrumDomain = boost::dynamic_pointer_cast<FunctionDomain1DSpectrum>(localDomain); if (spectrumDomain) { size_t wsIndex = spectrumDomain->getWorkspaceIndex(); auto &yValues = outputWs->mutableY(wsIndex); for (size_t j = 0; j < yValues.size(); ++j) { yValues[j] = localValues->getCalculated(j); } } } // Assign x-values on all histograms for (size_t i = 0; i < m_matrixWorkspace->getNumberHistograms(); ++i) { outputWs->setSharedX(i, m_matrixWorkspace->sharedX(i)); } if (m_manager && !outputWorkspacePropertyName.empty()) { declareProperty( new WorkspaceProperty<MatrixWorkspace>(outputWorkspacePropertyName, "", Kernel::Direction::Output), "Result workspace"); m_manager->setPropertyValue(outputWorkspacePropertyName, baseName + "Workspace"); m_manager->setProperty(outputWorkspacePropertyName, outputWs); } // If the input is a not an EventWorkspace and is a distrubution, then convert // the output also to a distribution if (!boost::dynamic_pointer_cast<Mantid::API::IEventWorkspace>( m_matrixWorkspace)) { if (m_matrixWorkspace->isDistribution()) { outputWs->setDistribution(true); } } return outputWs; }