Newer
Older
Gigg, Martyn Anthony
committed
// Includes
#include "MantidKernel/MagneticFormFactorTable.h"
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
namespace Mantid {
namespace PhysicalConstants {
/**
* Constructs the table for the given ion, J & L
* @param length :: scattering length
* @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$
* @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) {
const double fraction = nintervals - static_cast<double>(index);
return (1.0 - fraction) * m_lookup[index] + fraction * m_lookup[index + 1];
} 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
Gigg, Martyn Anthony
committed
} // namespace Mantid