Skip to content

Commit

Permalink
Refs #9782. Added Lorentz-profiles
Browse files Browse the repository at this point in the history
They all live in a namespace called "Lorentzians".
  • Loading branch information
Michael Wedel committed Aug 13, 2014
1 parent 5e7de3e commit a20c5fc
Show file tree
Hide file tree
Showing 4 changed files with 210 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Code/Mantid/Framework/CurveFitting/CMakeLists.txt
Expand Up @@ -60,6 +60,7 @@ set ( SRC_FILES
src/LogNormal.cpp
src/Lorentzian.cpp
src/Lorentzian1D.cpp
src/LorentzianFamily.cpp
src/MultiDomainCreator.cpp
src/MuonFInteraction.cpp
src/NeutronBk2BkExpConvPVoigt.cpp
Expand Down Expand Up @@ -169,6 +170,7 @@ set ( INC_FILES
inc/MantidCurveFitting/LogNormal.h
inc/MantidCurveFitting/Lorentzian.h
inc/MantidCurveFitting/Lorentzian1D.h
inc/MantidCurveFitting/LorentzianFamily.h
inc/MantidCurveFitting/MultiDomainCreator.h
inc/MantidCurveFitting/MuonFInteraction.h
inc/MantidCurveFitting/NeutronBk2BkExpConvPVoigt.h
Expand Down Expand Up @@ -266,6 +268,7 @@ set ( TEST_FILES
LinearBackgroundTest.h
LogNormalTest.h
Lorentzian1DTest.h
LorentzianFamilyTest.h
LorentzianTest.h
MultiDomainCreatorTest.h
MultiDomainFunctionTest.h
Expand Down
@@ -0,0 +1,85 @@
#ifndef MANTID_CURVEFITTING_LORENTZIANFAMILY_H_
#define MANTID_CURVEFITTING_LORENTZIANFAMILY_H_

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


namespace Mantid
{
namespace CurveFitting
{

/** LorentzianFamily : TODO: DESCRIPTION
Copyright © 2014 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://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/

namespace Lorentzians {

class DLLExport LorentzianHandCoded : public API::IFunction1D, public API::ParamFunction
{
public:
virtual ~LorentzianHandCoded() {}

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

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

protected:
void init();
};

class DLLExport LorentzianNumDiff : public API::IFunction1D, public API::ParamFunction
{
public:
virtual ~LorentzianNumDiff() {}

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

void function1D(double *out, const double *xValues, const size_t nData) const;

protected:
void init();
};

class DLLExport LorentzianAutoDiff : virtual public API::IFunction1DAutoDiff, virtual public API::ParamFunction
{
public:
virtual ~LorentzianAutoDiff() {}

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

void function1DAutoDiff(const API::FunctionDomain1D &domain, std::vector<adept::adouble> &y, const API::AutoDiffParameterAdapter &parameters) const;

protected:
void init();

};

} // namespace LorentzianFamily
} // namespace CurveFitting
} // namespace Mantid

#endif /* MANTID_CURVEFITTING_LORENTZIANFAMILY_H_ */
93 changes: 93 additions & 0 deletions Code/Mantid/Framework/CurveFitting/src/LorentzianFamily.cpp
@@ -0,0 +1,93 @@
#include "MantidCurveFitting/LorentzianFamily.h"

namespace Mantid
{
namespace CurveFitting
{

namespace Lorentzians {

using namespace API;

void LorentzianHandCoded::function1D(double *out, const double *xValues, const size_t nData) const
{
double h = getParameter("Height");
double x0 = getParameter("Centre");
double s = getParameter("Gamma");

for(size_t i = 0; i < nData; ++i) {
double diff = xValues[i] - x0;
out[i] = h * s * s / (diff*diff + s * s);
}
}

void LorentzianHandCoded::functionDeriv1D(Jacobian *out, const double *xValues, const size_t nData)
{
double h = getParameter("Height");
double x0 = getParameter("Centre");
double s = getParameter("Gamma");

for(size_t i = 0; i < nData; ++i) {
double diff = xValues[i] - x0;
double num = diff*diff + s * s;
double ssquared = s * s;

out->set(i, 0, ssquared / (num));
out->set(i, 1, 2 * h * ssquared * diff / (num * num));
out->set(i, 2, 2 * h * s / num * (1 - ssquared / num));
}
}

void LorentzianHandCoded::init()
{
declareParameter("Height");
declareParameter("Centre");
declareParameter("Gamma");
}


void LorentzianNumDiff::function1D(double *out, const double *xValues, const size_t nData) const
{
double h = getParameter("Height");
double x0 = getParameter("Centre");
double s = getParameter("Gamma");

for(size_t i = 0; i < nData; ++i) {
double diff = xValues[i] - x0;
out[i] = h * s * s / (diff*diff + s * s);
}
}

void LorentzianNumDiff::init()
{
declareParameter("Height");
declareParameter("Centre");
declareParameter("Gamma");
}

void LorentzianAutoDiff::function1DAutoDiff(const FunctionDomain1D &domain, std::vector<adept::adouble> &y, const AutoDiffParameterAdapter &parameters) const
{
adept::adouble h = parameters.getParameter("Height");
adept::adouble x0 = parameters.getParameter("Centre");
adept::adouble s = parameters.getParameter("Gamma");

for(size_t i = 0; i < domain.size(); ++i) {
adept::adouble diff = domain[i] - x0;
y[i] = h * s * s / (diff*diff + s * s);
}
}


void LorentzianAutoDiff::init()
{
declareParameter("Height");
declareParameter("Centre");
declareParameter("Gamma");
}

}



} // namespace CurveFitting
} // namespace Mantid
29 changes: 29 additions & 0 deletions Code/Mantid/Framework/CurveFitting/test/LorentzianFamilyTest.h
@@ -0,0 +1,29 @@
#ifndef MANTID_CURVEFITTING_LORENTZIANFAMILYTEST_H_
#define MANTID_CURVEFITTING_LORENTZIANFAMILYTEST_H_

#include <cxxtest/TestSuite.h>

#include "MantidCurveFitting/LorentzianFamily.h"

using Mantid::CurveFitting::LorentzianFamily;
using namespace Mantid::API;

class LorentzianFamilyTest : 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 LorentzianFamilyTest *createSuite() { return new LorentzianFamilyTest(); }
static void destroySuite( LorentzianFamilyTest *suite ) { delete suite; }


void test_Something()
{
TSM_ASSERT( "You forgot to write a test!", 0);
}


};


#endif /* MANTID_CURVEFITTING_LORENTZIANFAMILYTEST_H_ */

0 comments on commit a20c5fc

Please sign in to comment.