Mantid
Loading...
Searching...
No Matches
CrystalFieldHeatCapacity.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
13#include "MantidAPI/Jacobian.h"
18#include <cmath>
19
21
22namespace {
23
24// Does the actual calculation of the heat capacity
25void calculate(double *out, const double *xValues, const size_t nData, const DoubleFortranVector &en) {
26 const double k_B = PhysicalConstants::BoltzmannConstant; // in meV/K
27 // Want output in J/K/mol
28 const double convfact = PhysicalConstants::N_A * PhysicalConstants::meV;
29 int nlevels = en.len();
30 for (size_t iT = 0; iT < nData; iT++) {
31 double Z = 0.;
32 double U = 0.;
33 double U2 = 0.;
34 const double beta = 1 / (k_B * xValues[iT]);
35 // Using fortran indexing...
36 for (auto iE = 1; iE <= nlevels; iE++) {
37 double expfact = exp(-beta * en(iE));
38 Z += expfact;
39 U += en(iE) * expfact;
40 U2 += en(iE) * en(iE) * expfact;
41 }
42 U /= Z;
43 U2 /= Z;
44 out[iT] = ((U2 - U * U) / (k_B * xValues[iT] * xValues[iT])) * convfact;
45 }
46}
47} // namespace
48
50 declareAttribute("ScaleFactor", Attribute(1.0));
51}
52
53void CrystalFieldHeatCapacityBase::function1D(double *out, const double *xValues, const size_t nData) const {
54 // Use stored values
55 calculate(out, xValues, nData, m_en);
56 auto fact = getAttribute("ScaleFactor").asDouble();
57 if (fact != 1.0) {
58 for (size_t i = 0; i < nData; i++) {
59 out[i] *= fact;
60 }
61 }
62}
63
65
67 : CrystalFieldPeaksBase(), CrystalFieldHeatCapacityBase(), m_setDirect(false) {}
68
69// Sets the eigenvectors / values directly
71 m_setDirect = true;
72 m_en = en;
73}
74
75void CrystalFieldHeatCapacity::function1D(double *out, const double *xValues, const size_t nData) const {
76 if (!m_setDirect) {
78 int nre = 0;
79 calculateEigenSystem(m_en, wf, nre);
80 }
82}
83
86
87// Sets the eigenvectors / values directly
89
90} // namespace Mantid::CurveFitting::Functions
#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.
Definition: IFunction1D.h:43
Attribute is a non-fitting parameter.
Definition: IFunction.h:282
double asDouble() const
Returns double value if attribute is a double, throws exception otherwise.
Definition: IFunction.cpp:739
virtual Attribute getAttribute(const std::string &name) const
Return a value of attribute attName.
Definition: IFunction.cpp:1394
void declareAttribute(const std::string &name, const API::IFunction::Attribute &defaultValue)
Declare a single attribute.
Definition: IFunction.cpp:1418
Implements the part of IFunction interface dealing with parameters.
Definition: ParamFunction.h:33
CrystalFieldHeatCapacity is a function that calculates the molar magnetic heat capacity (in J/K/mol) ...
void function1D(double *out, const double *xValues, const size_t nData) const override
Function you want to fit to.
void function1D(double *out, const double *xValues, const size_t nData) const override
Function you want to fit to.
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.
FortranVector< EigenVector > DoubleFortranVector
MANTID_GEOMETRY_DLL Raster calculate(const Kernel::V3D &beamDirection, const IObject &shape, const double cubeSizeInMetre)
Definition: Rasterize.cpp:181
static constexpr double BoltzmannConstant
Boltzmann Constant in meV/K Taken from http://physics.nist.gov/cuu/Constants on 10/07/2012.
static constexpr double N_A
Avagodro constant in mol-1.
static constexpr double meV
1 meV in Joules.