Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
They all live in a namespace called "Lorentzians".
- Loading branch information
Michael Wedel
committed
Aug 13, 2014
1 parent
5e7de3e
commit a20c5fc
Showing
4 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
Code/Mantid/Framework/CurveFitting/inc/MantidCurveFitting/LorentzianFamily.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ¶meters) const; | ||
|
||
protected: | ||
void init(); | ||
|
||
}; | ||
|
||
} // namespace LorentzianFamily | ||
} // namespace CurveFitting | ||
} // namespace Mantid | ||
|
||
#endif /* MANTID_CURVEFITTING_LORENTZIANFAMILY_H_ */ |
93 changes: 93 additions & 0 deletions
93
Code/Mantid/Framework/CurveFitting/src/LorentzianFamily.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ¶meters) 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
29
Code/Mantid/Framework/CurveFitting/test/LorentzianFamilyTest.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_ */ |