Skip to content
Snippets Groups Projects
Unverified Commit c5f3d845 authored by Simon Heybrock's avatar Simon Heybrock Committed by GitHub
Browse files

Merge pull request #23126 from mantidproject/22694_chudley_elliot_hbar

chudley-elliot fit function should contain hbar
parents 2d6f20f5 77aac209
No related branches found
No related tags found
No related merge requests found
......@@ -24,13 +24,16 @@ File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
'''
from __future__ import (absolute_import, division, print_function)
import math
import numpy as np
from mantid.api import IFunction1D, FunctionFactory
from scipy import constants
class ChudleyElliot(IFunction1D):
planck_constant = constants.Planck / constants.e * 1E15 # meV*psec
hbar = planck_constant / (2 * np.pi) # meV * ps = ueV * ns
def category(self):
return "QuasiElastic"
......@@ -42,23 +45,13 @@ class ChudleyElliot(IFunction1D):
def function1D(self, xvals):
tau = self.getParameterValue("Tau")
length = self.getParameterValue("L")
xvals = np.array(xvals)
hwhm = (1.0 - np.sin(xvals * length) / (xvals * length)) / tau
with np.errstate(divide='ignore'):
hwhm = self.hbar*(1.0 - np.sin(xvals * length)
/ (xvals * length))/tau
return hwhm
def functionDeriv1D(self, xvals, jacobian):
tau = self.getParameterValue("Tau")
length = self.getParameterValue("L")
i = 0
for x in xvals:
s = math.sin(x*length)/(x*length)
h = (1.0-s)/tau
jacobian.set(i,0,-h/tau)
jacobian.set(i,1,(math.cos(x*length)-s)/(length*tau))
i += 1
# Required to have Mantid recognise the new function
FunctionFactory.subscribe(ChudleyElliot)
from __future__ import (absolute_import, division, print_function)
import unittest
import numpy as np
from MsdTestHelper import (is_registered, check_output, do_a_fit)
class ChudleyElliotTest(unittest.TestCase):
def test_function_has_been_registered(self):
status, msg = is_registered("ChudleyElliot")
if not status:
self.fail(msg)
def test_function_output(self):
input = [0.01, 0.1, 1.0, 10.0]
expected = [4.52422472e-05, 4.51112743e-03,
3.37001059e-01, 4.78915177e-01]
tolerance = 1.0e-04
status, output = check_output("ChudleyElliot", input, expected,
tolerance, Tau=1.42, L=2.42)
if not status:
msg = 'Computed output {} from input {} unequal to expected: {}'
self.fail(msg.format(*[str(a) for a in (output, input, expected)]))
@staticmethod
def test_do_fit():
do_a_fit(np.asarray([0.01, 0.1, 1.0, 10.0]), 'ChudleyElliot',
guess=dict(Tau=1.0, L=1.0),
target=dict(Tau=1.42, L=2.42), atol=0.01)
if __name__ == '__main__':
unittest.main()
......@@ -369,7 +369,7 @@ class JumpCETest(JumpFitFunctionTestBase):
def __init__(self):
JumpFitFunctionTestBase.__init__(self)
self._function = 'name=ChudleyElliot,Tau=3.31,L=1.42'
self._function = 'name=ChudleyElliot,Tau=1.42,L=2.42'
self.tolerance = 5e-3
def get_reference_files(self):
......
98fbf74ea7914ee4bce2a6e032d823f5
\ No newline at end of file
150dd41d09950d0fd0073cae136ce6cf
......@@ -15,7 +15,13 @@ associated long range diffusive motions of molecules.
The Chudley-Elliot Jump diffusion model [1]_ has the form:
.. math:: Gamma(Q) = (1 - sin(Ql)/Ql)/tau
.. math:: HWHM(Q) = \frac{\hbar}{\tau} \cdot \frac{1 - sin(Ql)}{Ql}
Units of :math:`l` are inverse units of :math:`Q`.
Units of :math:`HWHM` are :math:`meV` if units of :math:`\tau` are *ps*.
Alternatively, units of :math:`HWHM` are :math:`\mu eV` if units of
:math:`\tau` are *ns*.
.. attributes::
......
......@@ -36,7 +36,7 @@ Algorithms
New Algorithms
**************
##############
......@@ -59,10 +59,12 @@ New
Improvements
############
- :ref:`ChudleyElliot <func-ChudleyElliot>` includes hbar in the definition
Bugfixes
########
:ref:`Release 3.14.0 <v3.14.0>`
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment