Skip to content

Commit

Permalink
refs #5634. Template for new Product function.
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Jul 23, 2012
1 parent 3ec922f commit 83b754d
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Code/Mantid/Framework/CurveFitting/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
set ( SRC_FILES
# src/CostFuncIgnorePosPeaks.cpp
# src/SCDPanelErrors.cpp
# src/ChebyshevPolynomialBackground.cpp
src/Abragam.cpp
src/BFGS_Minimizer.cpp
src/BackToBackExponential.cpp
Expand All @@ -9,7 +10,6 @@ set ( SRC_FILES
src/Bk2BkExpConvPV.cpp
src/BoundaryConstraint.cpp
src/Chebyshev.cpp
# src/ChebyshevPolynomialBackground.cpp
src/Convolution.cpp
src/CostFuncFitting.cpp
src/CostFuncLeastSquares.cpp
Expand Down Expand Up @@ -53,6 +53,7 @@ set ( SRC_FILES
src/PlotPeakByLogValue.cpp
src/ProductFunction.cpp
src/ProductLinearExp.cpp
src/ProductQuadraticExp.cpp
src/Quadratic.cpp
src/QuadraticBackground.cpp
src/Resolution.cpp
Expand All @@ -74,6 +75,7 @@ set ( SRC_UNITY_IGNORE_FILES src/Fit1D.cpp src/GSLFunctions.cpp )
set ( INC_FILES
# inc/MantidCurveFitting/CostFuncIgnorePosPeaks.h
# inc/MantidCurveFitting/SCDPanelErrors.h
# inc/MantidCurveFitting/ChebyshevPolynomialBackground.h
inc/MantidCurveFitting/Abragam.h
inc/MantidCurveFitting/BFGS_Minimizer.h
inc/MantidCurveFitting/BackToBackExponential.h
Expand All @@ -82,7 +84,6 @@ set ( INC_FILES
inc/MantidCurveFitting/Bk2BkExpConvPV.h
inc/MantidCurveFitting/BoundaryConstraint.h
inc/MantidCurveFitting/Chebyshev.h
# inc/MantidCurveFitting/ChebyshevPolynomialBackground.h
inc/MantidCurveFitting/CompositeValues.h
inc/MantidCurveFitting/Convolution.h
inc/MantidCurveFitting/CostFuncFitting.h
Expand Down Expand Up @@ -133,6 +134,7 @@ set ( INC_FILES
inc/MantidCurveFitting/PlotPeakByLogValue.h
inc/MantidCurveFitting/ProductFunction.h
inc/MantidCurveFitting/ProductLinearExp.h
inc/MantidCurveFitting/ProductQuadraticExp.h
inc/MantidCurveFitting/Quadratic.h
inc/MantidCurveFitting/QuadraticBackground.h
inc/MantidCurveFitting/Resolution.h
Expand All @@ -150,13 +152,13 @@ set ( INC_FILES
)

set ( TEST_FILES
# test/ChebyshevPolynomialBackgroundTest.h
#test/SCDPanelErrorsTest.h
test/AbragamTest.h
test/BFGSTest.h
test/BivariateNormalTest.h
test/Bk2BkExpConvPVTest.h
test/BoundaryConstraintTest.h
# test/ChebyshevPolynomialBackgroundTest.h
test/ChebyshevTest.h
test/CompositeFunctionTest.h
test/ConvolutionTest.h
Expand Down Expand Up @@ -196,6 +198,7 @@ set ( TEST_FILES
test/PlotPeakByLogValueTest.h
test/ProductFunctionTest.h
test/ProductLinearExpTest.h
test/ProductQuadraticExpTest.h
test/QuadraticBackgroundTest.h
test/QuadraticTest.h
test/ResolutionTest.h
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#ifndef MANTID_CURVEFITTING_PRODUCTQUADRATICEXP_H_
#define MANTID_CURVEFITTING_PRODUCTQUADRATICEXP_H_

#include "MantidKernel/System.h"
#include "MantidAPI/ParamFunction.h"
#include "MantidAPI/IFunction1D.h"

namespace Mantid
{
namespace CurveFitting
{

/** ProductQuadraticExp : Function that evauates the product of an exponential and quadratic function.
Copyright © 2012 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class DLLExport ProductQuadraticExp : public API::ParamFunction, public API::IFunction1D
{
public:
ProductQuadraticExp();
virtual ~ProductQuadraticExp();

std::string name()const{return "ProductQuadraticExp";}

virtual const std::string category() const { return "Calibrate";}

protected:
virtual void functionDeriv1D(API::Jacobian* out, const double* xValues, const size_t nData);
virtual void function1D(double* out, const double* xValues, const size_t nData) const;
};


} // namespace CurveFitting
} // namespace Mantid

#endif /* MANTID_CURVEFITTING_PRODUCTQUADRATICEXP_H_ */
49 changes: 49 additions & 0 deletions Code/Mantid/Framework/CurveFitting/src/ProductQuadraticExp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "MantidCurveFitting/ProductQuadraticExp.h"

namespace Mantid
{
namespace CurveFitting
{
//----------------------------------------------------------------------------------------------
/** Constructor
*/
ProductQuadraticExp::ProductQuadraticExp()
{
declareParameter("A0", 0.0);
declareParameter("A1", 0.0);
declareParameter("A2", 0.0);
declareParameter("Height", 1.0);
declareParameter("Lifetime", 1.0);
}

//----------------------------------------------------------------------------------------------
/** Destructor
*/
ProductQuadraticExp::~ProductQuadraticExp()
{
}

void ProductQuadraticExp::functionDeriv1D(API::Jacobian* out, const double* xValues, const size_t nData)
{
throw std::runtime_error("Not Implemented");
}

void ProductQuadraticExp::function1D(double* out, const double* xValues, const size_t nData) const
{
double A0 = getParameter("A0");
double A1 = getParameter("A1");
double A2 = getParameter("A2");
double Height = getParameter("Height");
double Lifetime = getParameter("Lifetime");

UNUSED_ARG(A0);
UNUSED_ARG(A1);
UNUSED_ARG(A2);
UNUSED_ARG(Height);
UNUSED_ARG(Lifetime);

throw std::runtime_error("Not Implemented");
}

} // namespace CurveFitting
} // namespace Mantid
58 changes: 58 additions & 0 deletions Code/Mantid/Framework/CurveFitting/test/ProductQuadraticExpTest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#ifndef MANTID_CURVEFITTING_PRODUCTQUADRATICEXPTEST_H_
#define MANTID_CURVEFITTING_PRODUCTQUADRATICEXPTEST_H_

#include <cxxtest/TestSuite.h>

#include "MantidCurveFitting/ProductQuadraticExp.h"

using Mantid::CurveFitting::ProductQuadraticExp;

class ProductQuadraticExpTest : public CxxTest::TestSuite
{
public:
// This pair of boilerplate methods prevent the suite being created statically
// This means the constructor isn't called when running other tests
static ProductQuadraticExpTest *createSuite() { return new ProductQuadraticExpTest(); }
static void destroySuite( ProductQuadraticExpTest *suite ) { delete suite; }


void test_name()
{
ProductQuadraticExp func;
TS_ASSERT_EQUALS("ProductQuadraticExp", func.name());
}

void test_catagory()
{
ProductQuadraticExp func;
TS_ASSERT_EQUALS("Calibrate", func.category());
}

void test_set_parameters()
{
const double A0 = 1;
const double A1 = 2;
const double A2 = 3;
const double Height = 4;
const double Lifetime = 0.1;

ProductQuadraticExp func;
func.setParameter("A0", A0);
func.setParameter("A1", A1);
func.setParameter("A2", A2);
func.setParameter("Height", Height);
func.setParameter("Lifetime", Lifetime);

TS_ASSERT_EQUALS(A0, func.getParameter("A0"));
TS_ASSERT_EQUALS(A1, func.getParameter("A1"));
TS_ASSERT_EQUALS(A2, func.getParameter("A2"));
TS_ASSERT_EQUALS(Height, func.getParameter("Height"));
TS_ASSERT_EQUALS(Lifetime, func.getParameter("Lifetime"));
}



};


#endif /* MANTID_CURVEFITTING_PRODUCTQUADRATICEXPTEST_H_ */

0 comments on commit 83b754d

Please sign in to comment.