forked from AmbaPant/mantid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
AFMLF.py
47 lines (38 loc) · 1.97 KB
/
AFMLF.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Mantid Repository : https://github.com/mantidproject/mantid
#
# Copyright © 2019 ISIS Rutherford Appleton Laboratory UKRI,
# NScD Oak Ridge National Laboratory, European Spallation Source,
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# 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
class AFMLF(IFunction1D):
def category(self):
return "Muon\\MuonSpecific"
def init(self):
self.declareParameter("A0", 0.2, 'Amplitude')
self.declareParameter("Freq", 2, 'ZF Frequency (MHz)')
self.declareParameter(
"Angle", 50, 'Angle of internal field w.r.t. to applied field (degrees)')
self.declareParameter("Field", 10, 'Applied Field (G)')
self.declareParameter("Phi", 0.0, 'Phase (rad)')
def function1D(self, x):
A0 = self.getParameterValue("A0")
Freq = self.getParameterValue("Freq")
theta = self.getParameterValue("Angle")
B = self.getParameterValue("Field")
phi = self.getParameterValue("Phi")
FreqInt = Freq
FreqExt = 0.01355 * B
theta = np.pi / 180 * theta
omega1 = 2 * np.pi * \
np.sqrt(FreqInt ** 2 + FreqExt ** 2 + 2 * FreqInt * FreqExt * np.cos(theta))
omega2 = 2 * np.pi * \
np.sqrt(FreqInt ** 2 + FreqExt ** 2 - 2 * FreqInt * FreqExt * np.cos(theta))
a1 = (FreqInt * np.sin(theta)) ** 2 / ((FreqExt + FreqInt
* np.cos(theta)) ** 2 + (FreqInt * np.sin(theta)) ** 2)
a2 = (FreqInt * np.sin(theta)) ** 2 / ((FreqExt - FreqInt
* np.cos(theta)) ** 2 + (FreqInt * np.sin(theta)) ** 2)
return A0 * ((1 - a1) + a1 * np.cos(omega1 * x + phi) + (1 - a2) + a2 * np.cos(omega2 * x + phi)) / 2
FunctionFactory.subscribe(AFMLF)