"git@code.ornl.gov:pnb/ADIOS2.git" did not exist on "78c57400b9acd9cea6a7114e98a8630045264ce9"
Newer
Older
Gigg, Martyn Anthony
committed
// Includes
#include "MantidKernel/MagneticFormFactorTable.h"
namespace Mantid
{
namespace PhysicalConstants
{
/**
* Constructs the table for the given ion, J & L
Gigg, Martyn Anthony
committed
* @param ion :: A reference to the required ion
* @param j :: The total angular momentum
* @param l :: The orbital angular momentum
*/
MagneticFormFactorTable::MagneticFormFactorTable(const size_t length, const MagneticIon & ion,
const uint16_t j, const uint16_t l)
: m_length(length), m_lookup(length, 0.0), m_delta(0.0)
{
setup(ion, j, l);
}
/**
* Returns an interpolated form factor for the given \f$Q^2\f$ value
* @param qsqr :: \f$Q^2\f$ in \f$\mbox{\AA}^{-2}\f$
Gigg, Martyn Anthony
committed
* @return The interpolated value
*/
double MagneticFormFactorTable::value(const double qsqr) const
{
const double nintervals = qsqr/m_delta;
const size_t index = static_cast<size_t>(nintervals);
if(index < m_length)
Gigg, Martyn Anthony
committed
{
const double fraction = nintervals - static_cast<double>(index);
return (1.0 - fraction)*m_lookup[index] + fraction*m_lookup[index+1];
Gigg, Martyn Anthony
committed
}
else return 0.0;
}
//-------------------------------------------------------------------------------------------------------
// Private methods
//-------------------------------------------------------------------------------------------------------
/**
* Setup the table with the values for the given ion, J & L.
* @param ion :: A reference to the required ion
* @param j :: The total angular momentum
* @param l :: The orbital angular momentum
*/
void MagneticFormFactorTable::setup(const MagneticIon & ion, const uint16_t j, const uint16_t l)
{
const size_t length = m_length;
const double qsqrMax = MagneticIon::formFactorCutOff(j,l);
m_delta = qsqrMax/static_cast<double>(length);
for(size_t i = 0; i < length; ++i)
{
const double qsqr = m_delta*static_cast<double>(i);
m_lookup[i] = ion.analyticalFormFactor(qsqr, j, l);
}
}
} // namespace Kernel
} // namespace Mantid