Skip to content

Commit

Permalink
Refs #8347 Refactor functions to use Numpy functions where possible.
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Jackson committed Dec 10, 2013
1 parent fcafaac commit fca13a6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
Expand Up @@ -3,7 +3,7 @@
ChudleyElliot jump fit
Models the Q dependence of the QENS line width (Gamma (hwhm)), diffusion coefficients (D),
residence times (tau) and jump lengths (l) to extract the associated long range diffusive
residence times (tau) and jump lengths (length) to extract the associated long range diffusive
motions of molecules.
The Chudley-Elliot Jump diffusion model (1961) has the form
Gamma(Q) = (1 - sin(Ql)/Ql)/tau
Expand Down Expand Up @@ -50,23 +50,22 @@ def init(self):

def function1D(self, xvals):
tau = self.getParameterValue("Tau")
l = self.getParameterValue("L")
length = self.getParameterValue("L")

hwhm = []
for x in xvals:
h = (1.0-math.sin(x*l)/(x*l))/tau
hwhm.append(h)
return np.array(hwhm)
xvals = np.array(xvals)
hwhm = (1.0 - np.sin(xvals * length) / (xvals * length)) / tau

return hwhm

def functionDeriv1D(self, xvals, jacobian):
tau = self.getParameterValue("Tau")
l = self.getParameterValue("L")
length = self.getParameterValue("L")
i = 0
for x in xvals:
s = math.sin(x*l)/(x*l)
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*l)-s)/(l*tau));
jacobian.set(i,1,(math.cos(x*length)-s)/(length*tau));
i += 1

# Required to have Mantid recognise the new function
Expand Down
Expand Up @@ -51,15 +51,16 @@ def init(self):
def function1D(self, xvals):
tau = self.getParameterValue("Tau")
l = self.getParameterValue("L")
hwhm = []
for x in xvals:
h = (1.0-math.exp(-l*x*x))/tau
hwhm.append(h)
return np.array(hwhm)

xvals = np.array(xvals)
hwhm = (1.0 - np.exp( -l * xvals * xvals )) / tau

return hwhm

def functionDeriv1D(self, xvals, jacobian):
tau = self.getParameterValue("Tau")
l = self.getParameterValue("L")

i = 0
for x in xvals:
ex = math.exp(-l*x*x)
Expand Down
Expand Up @@ -3,7 +3,7 @@
Teixeira's model for water
Models the Q dependence of the QENS line width (Gamma (hwhm)), diffusion coefficients (D),
residence times (tau) and jump lengths (l) to extract the associated long range diffusive
residence times (tau) and jump lengths (length) to extract the associated long range diffusive
motions of molecules.
The this model (1961) has the form
Gamma(Q) = D*Q^2/(1 + D*Q^2*tau)
Expand Down Expand Up @@ -50,21 +50,22 @@ def init(self):

def function1D(self, xvals):
tau = self.getParameterValue("Tau")
l = self.getParameterValue("L")
hwhm = []
for x in xvals:
h = x*x*l/(tau*(1+x*x*l))
hwhm.append(h)
return np.array(hwhm)
length = self.getParameterValue("L")

xvals = np.array(xvals)
hwhm = xvals * xvals * length / (tau * (1 + xvals * xvals * length))

return hwhm

def functionDeriv1D(self, xvals, jacobian):
tau = self.getParameterValue("Tau")
l = self.getParameterValue("L")
length = self.getParameterValue("L")

i = 0
for x in xvals:
h = x*x*l/(tau*(1+x*x*l))
h = x*x*length/(tau*(1+x*x*length))
jacobian.set(i,0,-h/tau);
jacobian.set(i,1,h*(1.0-h*tau)/l);
jacobian.set(i,1,h*(1.0-h*tau)/length);
i += 1

# Required to have Mantid recognise the new function
Expand Down

0 comments on commit fca13a6

Please sign in to comment.