diff --git a/Framework/PythonInterface/plugins/functions/ChudleyElliot.py b/Framework/PythonInterface/plugins/functions/ChudleyElliot.py index 792f7f4c16a979dc006fb91ff3bc08b756ddbf13..4a72abd2e7399d0c209d664b7ecdca896e288b45 100644 --- a/Framework/PythonInterface/plugins/functions/ChudleyElliot.py +++ b/Framework/PythonInterface/plugins/functions/ChudleyElliot.py @@ -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) diff --git a/Framework/PythonInterface/test/python/plugins/functions/ChudleyElliotTest.py b/Framework/PythonInterface/test/python/plugins/functions/ChudleyElliotTest.py new file mode 100644 index 0000000000000000000000000000000000000000..1e858ccf23d60acc9796254835da5c3449bd50e8 --- /dev/null +++ b/Framework/PythonInterface/test/python/plugins/functions/ChudleyElliotTest.py @@ -0,0 +1,35 @@ +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() diff --git a/Testing/SystemTests/tests/analysis/ISISIndirectBayesTest.py b/Testing/SystemTests/tests/analysis/ISISIndirectBayesTest.py index 687464ba1d4cad0a7ddeaba17d8b34e899d66ad0..4295810502f47b3a3192806be049530b3fb85afb 100644 --- a/Testing/SystemTests/tests/analysis/ISISIndirectBayesTest.py +++ b/Testing/SystemTests/tests/analysis/ISISIndirectBayesTest.py @@ -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): diff --git a/Testing/SystemTests/tests/analysis/reference/ISISIndirectBayes_JumpCETest.nxs.md5 b/Testing/SystemTests/tests/analysis/reference/ISISIndirectBayes_JumpCETest.nxs.md5 index 4b36586a486a363b41d76818d1604300fb34e648..d4c89bf40a19e1c9d961d7df1a3b11a674a3d5b9 100644 --- a/Testing/SystemTests/tests/analysis/reference/ISISIndirectBayes_JumpCETest.nxs.md5 +++ b/Testing/SystemTests/tests/analysis/reference/ISISIndirectBayes_JumpCETest.nxs.md5 @@ -1 +1 @@ -98fbf74ea7914ee4bce2a6e032d823f5 \ No newline at end of file +150dd41d09950d0fd0073cae136ce6cf diff --git a/docs/source/fitting/fitfunctions/ChudleyElliot.rst b/docs/source/fitting/fitfunctions/ChudleyElliot.rst index 228945d1e1ae2560ccc37a424a9c2617794f663d..b865f3547509169501e2716777e5b8ace3a51df8 100644 --- a/docs/source/fitting/fitfunctions/ChudleyElliot.rst +++ b/docs/source/fitting/fitfunctions/ChudleyElliot.rst @@ -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:: diff --git a/docs/source/release/v3.14.0/framework.rst b/docs/source/release/v3.14.0/framework.rst index 4c29021bfc9c8c4f50ec2810217a59275331ac2f..8c56a7797cc0f8ac5e88dc9626ba659b94269e31 100644 --- a/docs/source/release/v3.14.0/framework.rst +++ b/docs/source/release/v3.14.0/framework.rst @@ -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>` + +