def torusGrad(x,y,z,rin,rout):
    """Return the derivatives of the Torus surface function
    with origin tangent to outer surface."""
    dfdz = 4*(rin+rout+z)*(2*rin*(rout+z)+2*rout*z+x**2+y**2+z**2)
    dfdy = 4*y*(2*rin*(rout+z)+2*rout*z+x**2+y**2+z**2)
    dfdx = 4*x*(-rin**2+(rin+rout+z)**2+rout**2+x**2+y**2)
    return dfdx,dfdy,dfdz