diff --git a/Framework/PythonInterface/plugins/functions/Bessel.py b/Framework/PythonInterface/plugins/functions/Bessel.py new file mode 100644 index 0000000000000000000000000000000000000000..e76526636643c6503f1ffedcad357e7d47e1f492 --- /dev/null +++ b/Framework/PythonInterface/plugins/functions/Bessel.py @@ -0,0 +1,30 @@ +# Mantid Repository : https://github.com/mantidproject/mantid +# +# Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI, +# NScD Oak Ridge National Laboratory, European Spallation Source +# & Institut Laue - Langevin +# SPDX - License - Identifier: GPL - 3.0 + +# pylint: disable=invalid-name, anomalous-backslash-in-string, attribute-defined-outside-init + +from mantid.api import IFunction1D, FunctionFactory +import numpy as np +from scipy import special as sp + + +class Bessel(IFunction1D): + + def category(self): + return "Muon" + + def init(self): + self.declareParameter("A0", 1, 'Amplitude') + self.declareParameter("Phi", 0.1, 'Phase(rad)') + self.declareParameter("Nu", 0.1, 'Frequency(MHz)') + + def function1D(self, x): + A0 = self.getParameterValue("A0") + Phi = self.getParameterValue("Phi") + Nu = self.getParameterValue("Nu") + return A0 * sp.j0(2 * np.pi * Nu * x + Phi) + +FunctionFactory.subscribe(Bessel) diff --git a/Framework/PythonInterface/test/python/plugins/functions/BesselTest.py b/Framework/PythonInterface/test/python/plugins/functions/BesselTest.py new file mode 100755 index 0000000000000000000000000000000000000000..33fca8e5f0d71f5e25e4b841128176115fe259c7 --- /dev/null +++ b/Framework/PythonInterface/test/python/plugins/functions/BesselTest.py @@ -0,0 +1,35 @@ +# Mantid Repository : https://github.com/mantidproject/mantid +# +# Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI, +# NScD Oak Ridge National Laboratory, European Spallation Source +# & Institut Laue - Langevin +# SPDX - License - Identifier: GPL - 3.0 + +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 BesselTest(unittest.TestCase): + + def test_function_has_been_registered(self): + status, msg = is_registered("Bessel") + if not status: + self.fail(msg) + + def test_function_output(self): + input = [0.0, 4.0, 8.0, 12.0] + expected = [0.09900249722395764, -0.010116392139648565, -0.024891569859118595, -0.006976567202361606] + tolerance = 1.0e-05 + status, output = check_output("Bessel", input, expected, tolerance, A0=0.1, Phi=0.2, Nu=0.2) + if not status: + msg = 'Computed output {} from input {} unequal to expected: {}' + self.fail(msg.format(*[str(i) for i in (output, input, expected)])) + + def test_do_fit(self): + do_a_fit(np.arange(0.1, 16, 0.2), 'Bessel', guess=dict(A0=0.15, Phi=0.25, Nu=0.25), target=dict(A0=0.1, Phi=0.2, Nu=0.2), atol=0.01) + +if __name__ == '__main__': + unittest.main() diff --git a/Framework/PythonInterface/test/python/plugins/functions/CMakeLists.txt b/Framework/PythonInterface/test/python/plugins/functions/CMakeLists.txt old mode 100644 new mode 100755 index 08fae10eb0191d2003e73b179cf06c0964205258..7522cb376c4f4a3e19391f8f6f9794ecf95fe900 --- a/Framework/PythonInterface/test/python/plugins/functions/CMakeLists.txt +++ b/Framework/PythonInterface/test/python/plugins/functions/CMakeLists.txt @@ -1,6 +1,7 @@ # Tests for Fit functions set(TEST_PY_FILES + BesselTest.py DSFinterp1DFitTest.py EISFDiffSphereTest.py EISFDiffCylinderTest.py diff --git a/docs/source/fitting/fitfunctions/Bessel.rst b/docs/source/fitting/fitfunctions/Bessel.rst new file mode 100644 index 0000000000000000000000000000000000000000..e104415e41e90f6d35078de51e5a3f64e2239b96 --- /dev/null +++ b/docs/source/fitting/fitfunctions/Bessel.rst @@ -0,0 +1,40 @@ +.. _func-Bessel: + +====== +Bessel +====== + +.. index:: Bessel + +Description +----------- + +.. math:: A(t)=A_0J_0(2\pi\nu t+\phi) + +where, + +:math:`A_0` is the amplitude, + +:math:`\nu` is the frequency of oscillation (MHz), + +:math:`\phi` is the phase at :math:`t=0`, + +and :math:`J_0(x)` is the Bessel Function of the first kind, its expression is given by: + +.. math:: J_0(x)=\sum_{l=0}^{\infty}\frac{(-1)^l}{2^{2l}(l!)^2}x^{2l}. + +.. figure:: /images/Bessel.png + :alt: A plot of Bessel function. + +.. attributes:: + +.. properties:: + +References +---------- + +[1] `Savici et al., PRB 66 (2002) <https://journals.aps.org/prb/pdf/10.1103/PhysRevB.66.014524>`_. + +.. categories:: + +.. sourcelink:: diff --git a/docs/source/images/Bessel.png b/docs/source/images/Bessel.png new file mode 100644 index 0000000000000000000000000000000000000000..4220b53b94d02c1b0ad269eba79a0a2fac3e35ee Binary files /dev/null and b/docs/source/images/Bessel.png differ