diff --git a/Code/Mantid/Framework/Algorithms/src/PDFFT.cpp b/Code/Mantid/Framework/Algorithms/src/PDFFT.cpp index 772fb0f1165cb57b600821be1c60544eb04d2d0b..264f8579a7b41fc1324e518b66773fcf72739086 100644 --- a/Code/Mantid/Framework/Algorithms/src/PDFFT.cpp +++ b/Code/Mantid/Framework/Algorithms/src/PDFFT.cpp @@ -209,6 +209,15 @@ void PDFFT::exec() { return; } + +/** + * Fourier transform to a specific r value in G(r) + * @param r:: atomic distance vlaue + * @param egr: error of G(r) + * @param qmin: mininum value of Q + * @param qmax: maximum value of Q + * @param sofq: true if input is S(Q), false if input is S(Q)-1 + */ double PDFFT::CalculateGrFromD(double r, double& egr, double qmin, double qmax, bool sofq) { double gr = 0; diff --git a/Code/Mantid/Framework/Algorithms/test/PDFFTTest.h b/Code/Mantid/Framework/Algorithms/test/PDFFTTest.h index 62206872ffab3c6704aa521acdb3d47ab94fdd8e..0f53a9accdc2f5b525b677bba4a2d9497c1e79d5 100644 --- a/Code/Mantid/Framework/Algorithms/test/PDFFTTest.h +++ b/Code/Mantid/Framework/Algorithms/test/PDFFTTest.h @@ -4,12 +4,21 @@ #include <cxxtest/TestSuite.h> #include "MantidKernel/Timer.h" #include "MantidKernel/System.h" +#include "MantidKernel/UnitFactory.h" +#include "MantidDataObjects/Workspace2D.h" +#include "MantidAPI/MatrixWorkspace.h" +#include "MantidAPI/FrameworkManager.h" +#include "MantidAPI/WorkspaceFactory.h" +#include "MantidAPI/AnalysisDataService.h" +#include "MantidAPI/IAlgorithm.h" #include <iostream> #include <iomanip> #include "MantidAlgorithms/PDFFT.h" using namespace Mantid::Algorithms; +using namespace Mantid::Kernel; +using namespace Mantid; class PDFFTTest : public CxxTest::TestSuite { @@ -23,8 +32,84 @@ public: TS_ASSERT( alg.isInitialized() ) } - void test_Something() + void test_Execute() { + + API::Workspace_sptr ws = createWS(20, 0.1, "TestInput1", "MomentumTransfer"); + + PDFFT pdfft; + pdfft.initialize(); + pdfft.setProperty("InputWorkspace", ws); + pdfft.setProperty("OutputWorkspace", "PDFGofR"); + pdfft.setProperty("InputSofQType", "S(Q)"); + pdfft.setProperty("RMax", 20.0); + pdfft.setProperty("DeltaR", 0.01); + pdfft.setProperty("Qmin", 0.0); + pdfft.setProperty("Qmax", 30.0); + pdfft.setProperty("PDFType", "G(r)=4pi*r[rho(r)-rho_0]"); + + pdfft.execute(); + + TS_ASSERT(pdfft.isExecuted()); + + } + + void test_CheckResult(){ + + API::Workspace_sptr ws = createWS(20, 0.1, "TestInput2", "MomentumTransfer"); + + // 1. Run PDFFT + API::IAlgorithm* pdfft = Mantid::API::FrameworkManager::Instance().createAlgorithm("PDFFourierTransform"); + + pdfft->initialize(); + pdfft->setProperty("InputWorkspace", ws); + pdfft->setProperty("OutputWorkspace", "PDFGofR"); + pdfft->setProperty("InputSofQType", "S(Q)"); + pdfft->setProperty("RMax", 20.0); + pdfft->setProperty("DeltaR", 0.01); + pdfft->setProperty("Qmin", 0.0); + pdfft->setProperty("Qmax", 30.0); + pdfft->setProperty("PDFType", "G(r)=4pi*r[rho(r)-rho_0]"); + + pdfft->execute(); + + DataObjects::Workspace2D_sptr pdfws = boost::dynamic_pointer_cast<DataObjects::Workspace2D>(API::AnalysisDataService::Instance().retrieve("PDFGofR")); + MantidVec& R = pdfws->dataX(0); + MantidVec& GofR = pdfws->dataY(0); + + TS_ASSERT_DELTA(R[0], 0.01, 0.0001); + TS_ASSERT_DELTA(R[249], 2.5, 0.0001); + TS_ASSERT_DELTA(GofR[0], 0.022981, 0.0001); + TS_ASSERT_DELTA(GofR[249], -0.616449, 0.0001); + + } + +private: + /** + * Create Workspacespace from 0 to N*dx + */ + Mantid::API::MatrixWorkspace_sptr createWS(size_t n, double dx, const std::string& name, const std::string unitlabel) + { + + Mantid::API::FrameworkManager::Instance(); + Mantid::DataObjects::Workspace2D_sptr ws = boost::dynamic_pointer_cast<Mantid::DataObjects::Workspace2D> + (Mantid::API::WorkspaceFactory::Instance().create("Workspace2D",1, n, n)); + + Mantid::MantidVec& X = ws->dataX(0); + Mantid::MantidVec& Y = ws->dataY(0); + Mantid::MantidVec& E = ws->dataE(0); + + for (size_t i = 0; i < n; i ++){ + X[i] = double(i)*dx; + Y[i] = X[i]+1.0; + E[i] = sqrt(fabs(X[i])); + } + + ws->getAxis(0)->unit() = Mantid::Kernel::UnitFactory::Instance().create(unitlabel); + + Mantid::API::AnalysisDataService::Instance().add(name, ws); + + return ws; }