19#include <boost/algorithm/string/predicate.hpp>
38 int nlevels = ham.len1();
40 for (
size_t iT = 0; iT < nData; iT++) {
43 const double beta = 1 / (k_B * xValues[iT]);
44 for (
auto iE = 1; iE <= nlevels; iE++) {
45 double expfact = exp(-beta * en(iE));
47 M += moment(iE) * expfact;
49 out[iT] = convfact * M /
Z;
54void calculate_powder(
double *out,
const double *xValues,
const size_t nData,
const ComplexFortranMatrix &ham,
55 const int nre,
const double Hmag,
const double convfact) {
56 for (
size_t j = 0; j < nData; j++) {
60 std::vector<double>
tmp(nData, 0.);
61 for (
int i = 1; i <= 3; i++) {
64 calculate(&
tmp[0], xValues, nData, ham, nre, Hd, Hmag, convfact);
65 for (
size_t j = 0; j < nData; j++) {
69 for (
size_t j = 0; j < nData; j++) {
87 if (Hdir.size() != 3) {
88 throw std::invalid_argument(
"Hdir must be a three-element vector.");
92 double Hnorm = sqrt(Hdir[0] * Hdir[0] + Hdir[1] * Hdir[1] + Hdir[2] * Hdir[2]);
94 if (
fabs(Hnorm) > 1.e-6) {
95 for (
auto i = 0; i < 3; i++) {
96 H(i + 1) = Hdir[i] / Hnorm;
100 const double NAMUB = 5.5849397;
104 double convfact = boost::iequals(unit,
"SI") ? NAMUB : (boost::iequals(unit,
"cgs") ? NAMUB * 1000. : 1.);
105 if (boost::iequals(unit,
"cgs")) {
109 calculate_powder(out, xValues, nData,
m_ham,
m_nre, Hmag, convfact);
111 calculate(out, xValues, nData,
m_ham,
m_nre, H, Hmag, convfact);
114 for (
size_t i = 0; i < nData; i++) {
115 out[i] = 1. / out[i];
120 for (
size_t i = 0; i < nData; i++) {
#define DECLARE_FUNCTION(classname)
Macro for declaring a new type of function to be used with the FunctionFactory.
This is a specialization of IFunction for functions of one real argument.
Attribute is a non-fitting parameter.
std::vector< double > asVector() const
Returns vector<double> if attribute is vector<double>, throws exception otherwise.
std::string asString() const
Returns string value if attribute is a string, throws exception otherwise.
double asDouble() const
Returns double value if attribute is a double, throws exception otherwise.
bool asBool() const
Returns bool value if attribute is a bool, throws exception otherwise.
virtual Attribute getAttribute(const std::string &name) const
Return a value of attribute attName.
void declareAttribute(const std::string &name, const API::IFunction::Attribute &defaultValue)
Declare a single attribute.
Implements the part of IFunction interface dealing with parameters.
CrystalFieldMoment is a function that calculates the induced magnetic moment (in bohr magnetons per i...
ComplexFortranMatrix m_ham
void function1D(double *out, const double *xValues, const size_t nData) const override
Function you want to fit to.
CrystalFieldMomentCalculation()
void setHamiltonian(const ComplexFortranMatrix &ham, const int nre)
void function1D(double *out, const double *xValues, const size_t nData) const override
Function you want to fit to.
void setHamiltonian(const ComplexFortranMatrix &ham, const int nre)
CrystalFieldPeaks is a function that calculates crystal field peak positions and intensities.
void calculateEigenSystem(DoubleFortranVector &en, ComplexFortranMatrix &wf, ComplexFortranMatrix &ham, ComplexFortranMatrix &hz, int &nre) const
Calculate the crystal field eigensystem.
void MANTID_CURVEFITTING_DLL calculateMagneticMoment(const ComplexFortranMatrix &ev, const DoubleFortranVector &Hmag, const int nre, DoubleFortranVector &moment)
Calculate the diagonal matrix elements of the magnetic moment operator in a particular eigenvector ba...
void MANTID_CURVEFITTING_DLL calculateZeemanEigensystem(DoubleFortranVector &eigenvalues, ComplexFortranMatrix &eigenvectors, const ComplexFortranMatrix &hamiltonian, int nre, const DoubleFortranVector &bext)
Calculates the eigenvalues/vectors of a crystal field Hamiltonian in a specified external magnetic fi...
FortranMatrix< ComplexMatrix > ComplexFortranMatrix
FortranVector< EigenVector > DoubleFortranVector
MANTID_GEOMETRY_DLL Raster calculate(const Kernel::V3D &beamDirection, const IObject &shape, const double cubeSizeInMetre)
static constexpr double BoltzmannConstant
Boltzmann Constant in meV/K Taken from http://physics.nist.gov/cuu/Constants on 10/07/2012.