Skip to content

Commit

Permalink
Add functions related to thermal neutron peak. Refs #6018.
Browse files Browse the repository at this point in the history
  • Loading branch information
wdzhou committed Nov 27, 2012
1 parent 7cb84d9 commit d6a5ecc
Show file tree
Hide file tree
Showing 10 changed files with 683 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Code/Mantid/Framework/CurveFitting/CMakeLists.txt
Expand Up @@ -66,6 +66,9 @@ set ( SRC_FILES
src/StretchExp.cpp
src/StretchExpMuon.cpp
src/TabulatedFunction.cpp
src/ThermalNeutronBk2BkExpAlpha.cpp
src/ThermalNeutronBk2BkExpBeta.cpp
src/ThermalNeutronBk2BkExpSigma.cpp
src/ThermalNeutronBk2BkExpConvPV.cpp
src/ThermalNeutronDtoTOFFunction.cpp
src/UserFunction.cpp
Expand Down Expand Up @@ -149,6 +152,9 @@ set ( INC_FILES
inc/MantidCurveFitting/StretchExp.h
inc/MantidCurveFitting/StretchExpMuon.h
inc/MantidCurveFitting/TabulatedFunction.h
inc/MantidCurveFitting/ThermalNeutronBk2BkExpAlpha.h
inc/MantidCurveFitting/ThermalNeutronBk2BkExpBeta.h
inc/MantidCurveFitting/ThermalNeutronBk2BkExpSigma.h
inc/MantidCurveFitting/ThermalNeutronBk2BkExpConvPV.h
inc/MantidCurveFitting/ThermalNeutronDtoTOFFunction.h
inc/MantidCurveFitting/UserFunction.h
Expand Down Expand Up @@ -215,6 +221,9 @@ set ( TEST_FILES
StretchExpMuonTest.h
StretchExpTest.h
TabulatedFunctionTest.h
ThermalNeutronBk2BkExpAlphaTest.h
ThermalNeutronBk2BkExpBetaTest.h
ThermalNeutronBk2BkExpSigmaTest.h
ThermalNeutronBk2BkExpConvPVTest.h
ThermalNeutronDtoTOFFunctionTest.h
UserFunction1DTest.h
Expand Down
@@ -0,0 +1,77 @@
#ifndef MANTID_CURVEFITTING_THERMALNEUTRONBK2BKEXPALPHA_H_
#define MANTID_CURVEFITTING_THERMALNEUTRONBK2BKEXPALPHA_H_

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

using namespace Mantid;
using namespace Mantid::API;

namespace Mantid
{
namespace CurveFitting
{

/** ThermalNeutronBk2BkExpAlpha : Function to calculate Alpha of Bk2Bk Exponential function from
Thermal Neutron Function's Alph0, Alph1, Alph0t, Alph1t, Dtt1, and etc.
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 ThermalNeutronBk2BkExpAlpha : virtual public IFunction1D, public ParamFunction
{
public:
ThermalNeutronBk2BkExpAlpha();
virtual ~ThermalNeutronBk2BkExpAlpha();

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

/// overwrite IFunction base class methods
std::string name()const{return "ThermalNeutronBk2BkExpAlpha";}

/// Overwrite IFunction
virtual const std::string category() const { return "General";}

protected:
/// overwrite IFunction base class method, which declare function parameters
virtual void init();

private:
/// Derivative
void functionDerivLocal(API::Jacobian* , const double* , const size_t );

/// Derivative to overwrite
void functionDeriv(const API::FunctionDomain& domain, API::Jacobian& jacobian);

/// Core function (inline) to calcualte TOF_h from d-spacing
inline double corefunction(double dh, double width, double tcross, double alph0,
double alph1, double alph0t, double alph1t) const;

};

typedef boost::shared_ptr<ThermalNeutronBk2BkExpAlpha> ThermalNeutronBk2BkExpAlpha_sptr;


} // namespace CurveFitting
} // namespace Mantid

#endif /* MANTID_CURVEFITTING_THERMALNEUTRONBK2BKEXPALPHA_H_ */
@@ -0,0 +1,77 @@
#ifndef MANTID_CURVEFITTING_THERMALNEUTRONBK2BKEXPBETA_H_
#define MANTID_CURVEFITTING_THERMALNEUTRONBK2BKEXPBETA_H_

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

using namespace Mantid;
using namespace Mantid::API;

namespace Mantid
{
namespace CurveFitting
{

/** ThermalNeutronBk2BkExpBETA : Function to calculate Beta of Bk2Bk Exponential function from
Thermal Neutron Function's beta0, Alph1, Alph0t, Alph1t, Dtt1, and etc.
Copyright &copy; 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 ThermalNeutronBk2BkExpBeta : virtual public IFunction1D, public ParamFunction
{
public:
ThermalNeutronBk2BkExpBeta();
virtual ~ThermalNeutronBk2BkExpBeta();

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

/// overwrite IFunction base class methods
std::string name()const{return "ThermalNeutronBk2BkExpBeta";}

/// Overwrite IFunction
virtual const std::string category() const { return "General";}

protected:
/// overwrite IFunction base class method, which declare function parameters
virtual void init();

private:
/// Derivative
void functionDerivLocal(API::Jacobian* , const double* , const size_t );

/// Derivative to overwrite
void functionDeriv(const API::FunctionDomain& domain, API::Jacobian& jacobian);

/// Core function (inline) to calcualte TOF_h from d-spacing
inline double corefunction(double dh, double width, double tcross, double beta0,
double beta1, double beta0t, double beta1t) const;

};

typedef boost::shared_ptr<ThermalNeutronBk2BkExpBeta> ThermalNeutronBk2BkExpBeta_sptr;


} // namespace CurveFitting
} // namespace Mantid

#endif /* MANTID_CURVEFITTING_THERMALNEUTRONBK2BKEXPBETA_H_ */
@@ -0,0 +1,76 @@
#ifndef MANTID_CURVEFITTING_THERMALNEUTRONBK2BKEXPSIGMA_H_
#define MANTID_CURVEFITTING_THERMALNEUTRONBK2BKEXPSIGMA_H_

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

using namespace Mantid;
using namespace Mantid::API;

namespace Mantid
{
namespace CurveFitting
{

/** ThermalNeutronBk2BkExpSIGMA : Function to calculate Sigma of Bk2Bk Exponential function from
Thermal Neutron Function's Sig0, Sig1, Sig2, Width and etc.
Copyright &copy; 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 ThermalNeutronBk2BkExpSigma : virtual public IFunction1D, public ParamFunction
{
public:
ThermalNeutronBk2BkExpSigma();
virtual ~ThermalNeutronBk2BkExpSigma();

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

/// overwrite IFunction base class methods
std::string name()const{return "ThermalNeutronBk2BkExpSigma";}

/// Overwrite IFunction
virtual const std::string category() const { return "General";}

protected:
/// overwrite IFunction base class method, which declare function parameters
virtual void init();

private:
/// Derivative
void functionDerivLocal(API::Jacobian* , const double* , const size_t );

/// Derivative to overwrite
void functionDeriv(const API::FunctionDomain& domain, API::Jacobian& jacobian);

/// Core function (inline) to calcualte TOF_h from d-spacing
inline double corefunction(double dh, double sig0sq, double sig1sq, double sig2sq) const;

};

typedef boost::shared_ptr<ThermalNeutronBk2BkExpSigma> ThermalNeutronBk2BkExpSigma_sptr;


} // namespace CurveFitting
} // namespace Mantid

#endif /* MANTID_CURVEFITTING_THERMALNEUTRONBK2BKEXPSIGMA_H_ */
@@ -0,0 +1,89 @@
#include "MantidCurveFitting/ThermalNeutronBk2BkExpAlpha.h"
#include "MantidKernel/System.h"
#include "MantidAPI/FunctionFactory.h"

#include <gsl/gsl_sf_erf.h>
#include <cmath>

using namespace std;
using namespace Mantid;
using namespace Mantid::CurveFitting;

namespace Mantid
{
namespace CurveFitting
{

DECLARE_FUNCTION(ThermalNeutronBk2BkExpAlpha)

//----------------------------------------------------------------------------------------------
/** Constructor
*/
ThermalNeutronBk2BkExpAlpha::ThermalNeutronBk2BkExpAlpha()
{
}

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

//----------------------------------------------------------------------------------------------
/** Defintion of parameter
*/
void ThermalNeutronBk2BkExpAlpha::init()
{
// Geometry related
declareParameter("Width", 1.0);
declareParameter("Tcross", 1.0);

declareParameter("Alph0", 0.0);
declareParameter("Alph1", 0.0);
declareParameter("Alph0t", 0.0);
declareParameter("Alph1t", 0.0);
}

//----------------------------------------------------------------------------------------------
/** Function 1D
*/
void ThermalNeutronBk2BkExpAlpha::function1D(double *out, const double *xValues, const size_t nData) const
{
double width = getParameter("Width");
double tcross = getParameter("Tcross");
double alph0 = getParameter("Alph0");
double alph1 = getParameter("Alph1");
double alph0t = getParameter("Alph0t");
double alph1t = getParameter("Alph1t");

for (size_t i = 0; i < nData; ++i)
{
out[i] = corefunction(xValues[i], width, tcross, alph0, alph1, alph0t, alph1t);
}

return;
}

/** Derivative: use numerical derivative
*/
void ThermalNeutronBk2BkExpAlpha::functionDeriv(const FunctionDomain &domain, Jacobian &jacobian)
{
calNumericalDeriv(domain, jacobian);
}

//----------------------------------------------------------------------------------------------
/** Core function
*/
double ThermalNeutronBk2BkExpAlpha::corefunction(double dh, double width, double tcross, double alph0,
double alph1, double alph0t, double alph1t) const
{
double n = 0.5*gsl_sf_erfc(width*(tcross-1.0/dh));
double alpha = 1.0/( n*(alph0+alph1*dh) + (1.0-n)*(alph0t-alph1t/dh) );

return alpha;
}


} // namespace CurveFitting
} // namespace Mantid

0 comments on commit d6a5ecc

Please sign in to comment.