Index: Kernel/Kernel-CapCyl.cpp
===================================================================
--- Kernel/Kernel-CapCyl.cpp	(revision 099e05357033bb53919d7a0213dc1bd7a0b54ebb)
+++ Kernel/Kernel-CapCyl.cpp	(revision a42fec0a6299c921e6b9422a1e4fa8aa60d78022)
@@ -42,5 +42,5 @@
         answer/=sin(alpha);
 
-        _ptvalue[i] = rad_cyl_weight*length_weight*rad_cap_weight*theta_weight*phi_weight*vol_i*answer;
+        _ptvalue[i] += rad_cyl_weight*length_weight*rad_cap_weight*theta_weight*phi_weight*vol_i*answer;
      //   if (size>1) {
    //         _ptvalue[i] *= fabs(cos(thet*pi/180.0));
Index: Kernel/Kernel-CoreShellCylinder.cpp
===================================================================
--- Kernel/Kernel-CoreShellCylinder.cpp	(revision 099e05357033bb53919d7a0213dc1bd7a0b54ebb)
+++ Kernel/Kernel-CoreShellCylinder.cpp	(revision a42fec0a6299c921e6b9422a1e4fa8aa60d78022)
@@ -44,5 +44,5 @@
         answer *= answer/(pi*(radius+thickness)*(radius+thickness)*(length+2.0*thickness))*1.0e8*scale;
 
-        _ptvalue[i] = radius_weight*length_weight*thickness_weight*theta_weight*phi_weight*answer*pow(radius+thickness,2)*(length+2.0*thickness);
+        _ptvalue[i] += radius_weight*length_weight*thickness_weight*theta_weight*phi_weight*answer*pow(radius+thickness,2)*(length+2.0*thickness);
      //   if (size>1) {
        // _ptvalue[i] *= fabs(cos(axis_theta*pi/180.0));
Index: Kernel/Kernel-Cylinder.cpp
===================================================================
--- Kernel/Kernel-Cylinder.cpp	(revision 099e05357033bb53919d7a0213dc1bd7a0b54ebb)
+++ Kernel/Kernel-Cylinder.cpp	(revision a42fec0a6299c921e6b9422a1e4fa8aa60d78022)
@@ -42,5 +42,6 @@
         real answer = sub*sub*form*acos(-1.0)*rr*rr*h*1.0e8*scale;
 
-        _ptvalue[i] = radius_weight*length_weight*theta_weight*phi_weight*answer*pow(rr,2)*h;
+        _ptvalue[i] += radius_weight*length_weight*theta_weight*phi_weight*answer*pow(rr,2)*h;
+
        // if (size>1) {
          //   _ptvalue[i] *= fabs(cos(cyl_theta*pi/180.0));
Index: Kernel/Kernel-Ellipse.cpp
===================================================================
--- Kernel/Kernel-Ellipse.cpp	(revision 099e05357033bb53919d7a0213dc1bd7a0b54ebb)
+++ Kernel/Kernel-Ellipse.cpp	(revision a42fec0a6299c921e6b9422a1e4fa8aa60d78022)
@@ -20,5 +20,5 @@
          ret*=ret*9.0*sub*sub*4.0/3.0*acos(-1.0)*radius_b*radius_b*radius_a*scale*(1.0e8);
 
-         _ptvalue[i] = radius_a_weight*radius_b_weight*axis_theta_weight*radius_a*axis_phi_weight*ret*pow(radius_b, 2);
+         _ptvalue[i] += radius_a_weight*radius_b_weight*axis_theta_weight*radius_a*axis_phi_weight*ret*pow(radius_b, 2);
          //if(size > 1){
           //  _ptvalue[i] *= fabs(cos(axis_theta*pi/180.0));
Index: Kernel/Kernel-TriaxialEllipse.cpp
===================================================================
--- Kernel/Kernel-TriaxialEllipse.cpp	(revision 099e05357033bb53919d7a0213dc1bd7a0b54ebb)
+++ Kernel/Kernel-TriaxialEllipse.cpp	(revision a42fec0a6299c921e6b9422a1e4fa8aa60d78022)
@@ -32,5 +32,5 @@
         answer*=answer*sub*sub*4.0*pi/3.0*axisA*axisB*axisC*1.0e8*scale;
 
-        _ptvalue[i] = axisA_weight*axisB_weight*axisC_weight*theta_weight*phi_weight*psi_weight*answer*axisA*axisB*axisC;
+        _ptvalue[i] += axisA_weight*axisB_weight*axisC_weight*theta_weight*phi_weight*psi_weight*answer*axisA*axisB*axisC;
        // if (size>1)
          //   _ptvalue[i] *= fabs(cos(theta*pi/180.0));
Index: Models/code_capcyl.py
===================================================================
--- Models/code_capcyl.py	(revision ca6c007657eda53e1961f1c89b6cff0712a587bd)
+++ Models/code_capcyl.py	(revision a42fec0a6299c921e6b9422a1e4fa8aa60d78022)
@@ -3,24 +3,11 @@
 
 import numpy as np
-from math import asin, sqrt, fabs, atan
+from math import sqrt, fabs, atan
 import pyopencl as cl
 
 from weights import GaussianDispersion
-from sasmodel import card
+from sasmodel import card, set_precision
 
 
-def set_precision(src, qx, qy, dtype):
-    qx = np.ascontiguousarray(qx, dtype=dtype)
-    qy = np.ascontiguousarray(qy, dtype=dtype)
-    if np.dtype(dtype) == np.dtype('float32'):
-        header = """\
-#define real float
-"""
-    else:
-        header = """\
-#pragma OPENCL EXTENSION cl_khr_fp64: enable
-#define real double
-"""
-    return header+src, qx, qy
 
 class GpuCapCylinder(object):
@@ -50,4 +37,6 @@
 
         _ctx,queue = card()
+        self.res[:] = 0
+        cl.enqueue_copy(queue, self.res_b, self.res)
         rad_cyl,length,rad_cap,theta,phi = \
             [GaussianDispersion(int(pars[base+'_pd_n']), pars[base+'_pd'], pars[base+'_pd_nsigma'])
@@ -79,14 +68,12 @@
                                         real(rad_cyl.weight[i]), real(length.weight[j]), real(theta.weight[k]), np.uint32(self.qx.size), np.uint32(size))
 
-                            cl.enqueue_copy(queue, self.res, self.res_b)
-
-                            sum += self.res
                             vol += rad_cyl.weight[i]*length.weight[j]*rad_cap.weight[m]*vol_i
                             norm_vol += rad_cyl.weight[i]*length.weight[j]*rad_cap.weight[m]
                             norm += rad_cyl.weight[i]*length.weight[j]*rad_cap.weight[m]*theta.weight[k]*phi.weight[l]
 
-        if size > 1:
-            norm /= asin(1.0)
-
+        #if size > 1:
+         #   norm /= asin(1.0)
+        cl.enqueue_copy(queue, self.res, self.res_b)
+        sum += self.res
         if vol != 0.0 and norm_vol != 0.0:
             sum *= norm_vol/vol
Index: Models/code_coreshellcyl.py
===================================================================
--- Models/code_coreshellcyl.py	(revision ca6c007657eda53e1961f1c89b6cff0712a587bd)
+++ Models/code_coreshellcyl.py	(revision a42fec0a6299c921e6b9422a1e4fa8aa60d78022)
@@ -6,20 +6,5 @@
 
 from weights import GaussianDispersion
-from sasmodel import card
-
-
-def set_precision(src, qx, qy, dtype):
-    qx = np.ascontiguousarray(qx, dtype=dtype)
-    qy = np.ascontiguousarray(qy, dtype=dtype)
-    if np.dtype(dtype) == np.dtype('float32'):
-        header = """\
-#define real float
-"""
-    else:
-        header = """\
-#pragma OPENCL EXTENSION cl_khr_fp64: enable
-#define real double
-"""
-    return header+src, qx, qy
+from sasmodel import card, set_precision
 
 class GpuCoreShellCylinder(object):
@@ -46,4 +31,6 @@
 
         _ctx,queue = card()
+        self.res[:] = 0
+        cl.enqueue_copy(queue, self.res_b, self.res)
         radius, length, thickness, axis_phi, axis_theta = [GaussianDispersion(int(pars[base+'_pd_n']), pars[base+'_pd'], pars[base+'_pd_nsigma'])
                                      for base in GpuCoreShellCylinder.PD_PARS]
@@ -56,11 +43,4 @@
 
         sum, norm, norm_vol, vol = 0.0, 0.0, 0.0, 0.0
-
-        print radius.value
-        print thickness.weight
-        print axis_phi.weight
-        print axis_theta.weight
-        print length.value
-
         size = len(axis_theta.weight)
 
@@ -79,7 +59,4 @@
                                     real(pars['shell_sld']), real(pars['solvent_sld']),np.uint32(size),
                                     np.uint32(self.qx.size))
-                            cl.enqueue_copy(queue, self.res, self.res_b)
-
-                            sum += self.res
                             vol += radius.weight[r]*length.weight[l]*thickness.weight[th]*pow(radius.value[r]+thickness.value[th],2)\
                                    *(length.value[l]+2.0*thickness.value[th])
@@ -90,4 +67,6 @@
         #if size>1:
          #   norm /= math.asin(1.0)
+        cl.enqueue_copy(queue, self.res, self.res_b)
+        sum = self.res
         if vol != 0.0 and norm_vol != 0.0:
             sum *= norm_vol/vol
Index: Models/code_cylinder.py
===================================================================
--- Models/code_cylinder.py	(revision ca6c007657eda53e1961f1c89b6cff0712a587bd)
+++ Models/code_cylinder.py	(revision a42fec0a6299c921e6b9422a1e4fa8aa60d78022)
@@ -6,33 +6,6 @@
 
 from weights import GaussianDispersion
-from sasmodel import card
+from sasmodel import card, set_precision, set_precision_1d
 
-
-def set_precision(src, qx, qy, dtype):
-    qx = np.ascontiguousarray(qx, dtype=dtype)
-    qy = np.ascontiguousarray(qy, dtype=dtype)
-    if np.dtype(dtype) == np.dtype('float32'):
-        header = """\
-#define real float
-"""
-    else:
-        header = """\
-#pragma OPENCL EXTENSION cl_khr_fp64: enable
-#define real double
-"""
-    return header+src, qx, qy
-
-def set_precision_1d(src, q, dtype):
-    q = np.ascontiguousarray(q, dtype=dtype)
-    if np.dtype(dtype) == np.dtype('float32'):
-        header = """\
-#define real float
-"""
-    else:
-        header = """\
-#pragma OPENCL EXTENSION cl_khr_fp64: enable
-#define real double
-"""
-    return header+src, q
 
 class GpuCylinder(object):
@@ -55,5 +28,5 @@
         self.qx_b = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=self.qx)
         self.qy_b = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=self.qy)
-        self.res_b = cl.Buffer(ctx, mf.WRITE_ONLY, qx.nbytes)
+        self.res_b = cl.Buffer(ctx, cl.mem_flags.READ_WRITE, self.qx.nbytes)
         self.res = np.empty_like(self.qx)
 
@@ -61,4 +34,6 @@
 
         _ctx,queue = card()
+        self.res[:] = 0
+        cl.enqueue_copy(queue, self.res_b, self.res)
         radius, length, cyl_theta, cyl_phi = \
             [GaussianDispersion(int(pars[base+'_pd_n']), pars[base+'_pd'], pars[base+'_pd_nsigma'])
@@ -68,6 +43,6 @@
         radius.value, radius.weight = radius.get_weights(pars['radius'], 0, 10000, True)
         length.value, length.weight = length.get_weights(pars['length'], 0, 10000, True)
-        cyl_theta.value, cyl_theta.weight = cyl_theta.get_weights(pars['cyl_theta'], -90, 180, False)
-        cyl_phi.value, cyl_phi.weight = cyl_phi.get_weights(pars['cyl_phi'], -90, 180, False)
+        cyl_theta.value, cyl_theta.weight = cyl_theta.get_weights(pars['cyl_theta'], -np.inf, np.inf, False)
+        cyl_phi.value, cyl_phi.weight = cyl_phi.get_weights(pars['cyl_phi'], -np.inf, np.inf, False)
 
         #Perform the computation, with all weight points
@@ -87,6 +62,5 @@
                                            real(cyl_phi.weight[l]), real(cyl_theta.value[k]), real(cyl_phi.value[l]),
                                            np.uint32(self.qx.size), np.uint32(size))
-                        cl.enqueue_copy(queue, self.res, self.res_b)
-                        sum += self.res
+
                         vol += radius.weight[i]*length.weight[j]*pow(radius.value[i], 2)*length.value[j]
                         norm_vol += radius.weight[i]*length.weight[j]
@@ -95,4 +69,6 @@
        # if size > 1:
         #    norm /= math.asin(1.0)
+        cl.enqueue_copy(queue, self.res, self.res_b)
+        sum = self.res
         if vol != 0.0 and norm_vol != 0.0:
             sum *= norm_vol/vol
Index: Models/code_ellipse.py
===================================================================
--- Models/code_ellipse.py	(revision ca6c007657eda53e1961f1c89b6cff0712a587bd)
+++ Models/code_ellipse.py	(revision a42fec0a6299c921e6b9422a1e4fa8aa60d78022)
@@ -6,20 +6,5 @@
 
 from weights import GaussianDispersion
-from sasmodel import card
-
-
-def set_precision(src, qx, qy, dtype):
-    qx = np.ascontiguousarray(qx, dtype=dtype)
-    qy = np.ascontiguousarray(qy, dtype=dtype)
-    if np.dtype(dtype) == np.dtype('float32'):
-        header = """\
-#define real float
-"""
-    else:
-        header = """\
-#pragma OPENCL EXTENSION cl_khr_fp64: enable
-#define real double
-"""
-    return header+src, qx, qy
+from sasmodel import card, set_precision
 
 class GpuEllipse(object):
@@ -46,4 +31,6 @@
     #b_n = radius_b # want, a_n = radius_a # want, etc
         _ctx,queue = card()
+        self.res[:] = 0
+        cl.enqueue_copy(queue, self.res_b, self.res)
         radius_a, radius_b, axis_theta, axis_phi = \
             [GaussianDispersion(int(pars[base+'_pd_n']), pars[base+'_pd'], pars[base+'_pd_nsigma'])
@@ -76,7 +63,5 @@
                                         real(axis_phi.value[l]), self.qx_b, self.qy_b, self.res_b,
                                         np.uint32(self.qx.size), np.uint32(len(axis_theta.weight)))
-                        #copy result back from buffer
-                        cl.enqueue_copy(queue, self.res, self.res_b)
-                        sum += self.res
+
                         vol += radius_a.weight[i]*radius_b.weight[j]*pow(radius_b.value[j], 2)*radius_a.value[i]
                         norm_vol += radius_a.weight[i]*radius_b.weight[j]
@@ -88,4 +73,6 @@
     #    if size > 1:
      #       norm /= math.asin(1.0)
+        cl.enqueue_copy(queue, self.res, self.res_b)
+        sum += self.res
         if vol != 0.0 and norm_vol != 0.0:
             sum *= norm_vol/vol
Index: Models/code_lamellar.py
===================================================================
--- Models/code_lamellar.py	(revision ca6c007657eda53e1961f1c89b6cff0712a587bd)
+++ Models/code_lamellar.py	(revision a42fec0a6299c921e6b9422a1e4fa8aa60d78022)
@@ -5,18 +5,5 @@
 import pyopencl as cl
 from Models.weights import GaussianDispersion
-
-def set_precision(src, qx, qy, dtype):
-    qx = np.ascontiguousarray(qx, dtype=dtype)
-    qy = np.ascontiguousarray(qy, dtype=dtype)
-    if dtype == 'double':
-        header = """\
-#define real float
-"""
-    else:
-        header = """\
-#pragma OPENCL EXTENSION cl_khr_fp64: enable
-#define real double
-"""
-    return header+src, qx, qy
+from sasmodel import set_precision
 
 
Index: Models/code_triaxialellipse.py
===================================================================
--- Models/code_triaxialellipse.py	(revision ca6c007657eda53e1961f1c89b6cff0712a587bd)
+++ Models/code_triaxialellipse.py	(revision a42fec0a6299c921e6b9422a1e4fa8aa60d78022)
@@ -6,20 +6,5 @@
 
 from weights import GaussianDispersion
-from sasmodel import card
-
-
-def set_precision(src, qx, qy, dtype):
-    qx = np.ascontiguousarray(qx, dtype=dtype)
-    qy = np.ascontiguousarray(qy, dtype=dtype)
-    if np.dtype(dtype) == np.dtype('float32'):
-        header = """\
-#define real float
-"""
-    else:
-        header = """\
-#pragma OPENCL EXTENSION cl_khr_fp64: enable
-#define real double
-"""
-    return header+src, qx, qy
+from sasmodel import card, set_precision
 
 class GpuTriEllipse:
@@ -45,4 +30,6 @@
 
         _ctx,queue = card()
+        self.res[:] = 0
+        cl.enqueue_copy(queue, self.res_b, self.res)
         axisA, axisB, axisC, theta, phi, psi = \
             [GaussianDispersion(int(pars[base+'_pd_n']), pars[base+'_pd'], pars[base+'_pd_nsigma'])
@@ -72,6 +59,4 @@
                                             real(axisA.weight[a]), real(axisB.weight[b]), real(axisC.weight[c]), real(psi.weight[s]),
                                             real(phi.weight[i]), real(theta.weight[t]), np.uint32(self.qx.size), np.uint32(size))
-                                cl.enqueue_copy(queue, self.res, self.res_b)
-                                sum += self.res
 
                                 vol += axisA.weight[a]*axisB.weight[b]*axisC.weight[c]*axisA.value[a]*axisB.value[b]*axisC.value[c]
@@ -81,5 +66,6 @@
       #  if size > 1:
        #     norm /= asin(1.0)
-
+        cl.enqueue_copy(queue, self.res, self.res_b)
+        sum = self.res
         if vol != 0.0 and norm_vol != 0.0:
             sum *= norm_vol/vol
Index: Models/weights.py
===================================================================
--- Models/weights.py	(revision dbb0048466f8b528c1953a0eb5a496b6c1c25e32)
+++ Models/weights.py	(revision a42fec0a6299c921e6b9422a1e4fa8aa60d78022)
@@ -19,5 +19,5 @@
         sigma = width * center if relative else width
         if sigma == 0:
-            return np.array([center, 1.], 'd')
+            return np.array([center],'d'), np.array([1.], 'd')
         x = center + np.linspace(-nsigmas * sigma, +nsigmas * sigma, npts)
         x = x[(x >= min) & (x <= max)]
Index: Testers/test.py
===================================================================
--- Testers/test.py	(revision 099e05357033bb53919d7a0213dc1bd7a0b54ebb)
+++ Testers/test.py	(revision a42fec0a6299c921e6b9422a1e4fa8aa60d78022)
@@ -1,2 +1,7 @@
+impor
+
+
+
+
 import numpy as np
 
@@ -12,2 +17,3 @@
 
 print sum
+
Index: compare.py
===================================================================
--- compare.py	(revision 473183c753f3b44a54aab3a16e00e358edf72be6)
+++ compare.py	(revision a42fec0a6299c921e6b9422a1e4fa8aa60d78022)
@@ -4,5 +4,5 @@
 import datetime
 
-from Models.sasmodel import SasModel, load_data, set_beam_stop, plot_data
+from sasmodel import SasModel, load_data, set_beam_stop, plot_data
 
 
@@ -46,11 +46,14 @@
     if len(sys.argv) > 1:
         N = int(sys.argv[1])
-    data = load_data('JUN03289.DAT')
+    data = load_data('December/DEC07098.DAT')
     set_beam_stop(data, 0.004)
 
+    dtype = "float"
     pars = dict(
-        scale=1, radius=64.1, length=266.96, sldCyl=.291e-6, sldSolv=5.77e-6, background=0,
-        cyl_theta=0, cyl_phi=0, radius_pd=0.1, radius_pd_n=10, radius_pd_nsigma=3,length_pd=0.1,
-        length_pd_n=5, length_pd_nsigma=3, cyl_theta_pd=0.1, cyl_theta_pd_n=5, cyl_theta_pd_nsigma=3,
+        scale=.08, radius=64.1, length=266.96, sldCyl=.291e-6, sldSolv=5.77e-6, background=.1,
+        cyl_theta=0, cyl_phi=0,
+        radius_pd=0.1, radius_pd_n=10, radius_pd_nsigma=3,
+        length_pd=0.1,length_pd_n=5, length_pd_nsigma=3,
+        cyl_theta_pd=0.1, cyl_theta_pd_n=5, cyl_theta_pd_nsigma=3,
         cyl_phi_pd=0.1, cyl_phi_pd_n=10, cyl_phi_pd_nsigma=3,
         )
@@ -62,5 +65,6 @@
     cpu_time = toc()*1000./N
 
-    from code_cylinder import GpuCylinder
+
+    from Models.code_cylinder import GpuCylinder
     model = SasModel(data, GpuCylinder, dtype='f', **pars)
     tic()
@@ -69,4 +73,6 @@
     gpu_time = toc()*1000./N
 
+    print "gpu/cpu", max(gpu/cpu)
+    cpu *= max(gpu/cpu)
     relerr = (gpu - cpu)/cpu
     print "max(|(ocl-omp)/ocl|)", max(abs(relerr))
@@ -76,5 +82,5 @@
     plt.subplot(131); plot_data(data, cpu); plt.title("omp t=%.1f ms"%cpu_time)
     plt.subplot(132); plot_data(data, gpu); plt.title("ocl t=%.1f ms"%gpu_time)
-    plt.subplot(133); plot_data(data, 1e8*relerr); plt.title("relerr x 10^8"); plt.colorbar()
+    plt.subplot(133); plot_data(data, relerr); plt.title("relerr x 10^8"); plt.colorbar()
     plt.show()
 
@@ -85,5 +91,5 @@
     if len(sys.argv) > 1:
         N = int(sys.argv[1])
-    data = load_data('DEC07133.DAT')
+    data = load_data('DEC07106.DAT')
     set_beam_stop(data, 0.004)
 
@@ -99,5 +105,5 @@
     cpu_time = toc()*1000./N
 
-    from code_ellipse import GpuEllipse
+    from Models.code_ellipse import GpuEllipse
     model = SasModel(data, GpuEllipse, dtype='f', **pars)
     tic()
@@ -116,5 +122,5 @@
     plt.show()
 
-def coreshell(N=4):
+def coreshell(N=1):
     import sys
     import matplotlib.pyplot as plt
@@ -122,5 +128,5 @@
     if len(sys.argv) > 1:
         N = int(sys.argv[1])
-    data = load_data('DEC07133.DAT')
+    data = load_data('December/DEC07098.DAT')
     set_beam_stop(data, 0.004)
 
@@ -141,5 +147,5 @@
     cpu_time = toc()*1000./N
 
-    from code_coreshellcyl import GpuCoreShellCylinder
+    from Models.code_coreshellcyl import GpuCoreShellCylinder
     model = SasModel(data, GpuCoreShellCylinder, dtype='f', **pars)
     tic()
Index: fit.py
===================================================================
--- fit.py	(revision 099e05357033bb53919d7a0213dc1bd7a0b54ebb)
+++ fit.py	(revision a42fec0a6299c921e6b9422a1e4fa8aa60d78022)
@@ -3,5 +3,5 @@
 
 from bumps.names import *
-from sasmodel import SasModel, load_data, set_beam_stop
+from sasmodel import SasModel, load_data, set_beam_stop, set_half, set_top
 from Models.code_capcyl import GpuCapCylinder
 from Models.code_coreshellcyl import GpuCoreShellCylinder
@@ -13,9 +13,10 @@
 """ IMPORT THE DATA USED """
 #data = load_data('December/Tangential/Sector0/DEC07133.ABS')
-data = load_data('December/DEC07235.DAT')
+data = load_data('December/DEC07102.DAT')
 
 """ SET INNER BEAM STOP, OUTER RING, AND MASK HALF OF THE DATA """
-set_beam_stop(data, 0.0052)#, outer=0.025)
-#set_half(data, 'left')
+set_beam_stop(data, 0.00669)#, outer=0.025)
+set_top(data, -.018)
+#set_half(data, 'right')
 
 """
@@ -26,5 +27,5 @@
 length=1000,
 background=21,
-sldCyl=.291e-6,sldSolv=5.77e-6,
+sldCyl=.291e-6,sldSolv=7.105e-6,
 radius_pd=0.1,radius_pd_n=10,radius_pd_nsigma=0,
 length_pd=0.1,length_pd_n=5,length_pd_nsigma=0,
@@ -35,9 +36,9 @@
 model = SasModel(data, GpuEllipse,
 scale=0.08,
-radius_a=15, radius_b=200,
+radius_a=15, radius_b=800,
 sldEll=.291e-6, sldSolv=7.105e-6,
 background=0,
-axis_theta=0, axis_phi=0,
-axis_theta_pd=20, axis_theta_pd_n=10, axis_theta_pd_nsigma=3,
+axis_theta=90, axis_phi=0,
+axis_theta_pd=15, axis_theta_pd_n=40, axis_theta_pd_nsigma=3,
 
 radius_a_pd=0.222296, radius_a_pd_n=1, radius_a_pd_nsigma=0,
@@ -48,72 +49,92 @@
 
 # SET THE FITTING PARAMETERS
-#model.radius_a.range(15, 1000)
-#model.radius_b.range(15, 1000)
-model.axis_theta_pd.range(0, 360)
+model.radius_a.range(15, 1000)
+model.radius_b.range(15, 1000)
+#model.axis_theta_pd.range(0, 360)
 #model.background.range(0,1000)
 #model.scale.range(0, 1)
 """
+
 """
-
 model = SasModel(data, GpuLamellar,
-scale=0.70,
-bi_thick=5,
-sld_bi=.291e-6,sld_sol=5.77e-6,
-background=85.23,
-bi_thick_pd= 0.0013, bi_thick_pd_n=5, bi_thick_pd_nsigma=3,
+scale=0.08,
+bi_thick=19.2946,
+sld_bi=5.38e-6,sld_sol=7.105e-6,
+background=0.003,
+bi_thick_pd= 0.37765, bi_thick_pd_n=10, bi_thick_pd_nsigma=3,
 dtype='float')
 
 # SET THE FITTING PARAMETERS
-model.bi_thick.range(0, 1000)
-model.scale.range(0, 1)
+#model.bi_thick.range(0, 1000)
+#model.scale.range(0, 1)
 #model.bi_thick_pd.range(0, 1000)
 #model.background.range(0, 1000)
+model.sld_bi.range(0, 1)
+
 """
-
-model = SasModel(data, GpuCylinder,
-scale=0.08, radius=46, length=719,
-sldCyl=.291e-6, sldSolv=5.77e-6, background=0,
-cyl_theta=0, cyl_phi=0,
-cyl_theta_pd=23, cyl_theta_pd_n=10, cyl_theta_pd_nsigma=3,
+if 1:
+    model = SasModel(data, GpuCylinder,
+    scale=0.0104,
+    radius=92.5,
+    length=798.3,
+    sldCyl=.29e-6,
+    sldSolv=7.105e-6,
+    background=5,
+    cyl_theta=0,
+    cyl_phi=0,
+    cyl_theta_pd=22.11,
+    cyl_theta_pd_n=20,
+    cyl_theta_pd_nsigma=3,
+    radius_pd=.0084,
+    radius_pd_n=10,
+    radius_pd_nsigma=3,
+    length_pd=0.493,
+    length_pd_n=10,
+    length_pd_nsigma=3,
+    cyl_phi_pd=0,
+    cyl_phi_pd_n=1,
+    cyl_phi_pd_nsigma=3,
+    dtype='float')
 
 
-radius_pd=0.1, radius_pd_n=20, radius_pd_nsigma=0,
-length_pd=0.1, length_pd_n=20, length_pd_nsigma=0,
-cyl_phi_pd=0.1, cyl_phi_pd_n=20, cyl_phi_pd_nsigma=0,
-dtype='float')
 
-# SET THE FITTING PARAMETERS
-model.radius.range(0, 25)
-#model.length.range(0, 1000)
-#model.cyl_theta_pd.range(0,90)
-#model.scale.range(0, 1)
-#model.background.range(0, 1000)
+    # SET THE FITTING PARAMETERS
+    #model.radius.range(1, 500)
+    #model.length.range(1, 4000)
+    #model.cyl_theta.range(-90,100)
+    #model.cyl_theta_pd.range(0, 90)
+    #model.cyl_theta_pd_n = model.cyl_theta_pd + 5
+    #model.radius_pd.range(0, 90)
+    #model.length_pd.range(0, 90)
+    model.scale.range(0, 1)
+    #model.background.range(0, 100)
+    #model.sldCyl.range(0, 1)
 
 
-"""
-model = SasModel(data, GpuCoreShellCylinder,
-                 scale= 0.08, radius=200, thickness=30, length=2000,
-                 core_sld=7e-6, shell_sld=.291e-6, solvent_sld=7.105e-6,
-                 background=0, axis_theta=0, axis_phi=0,
+if 0:
+    model = SasModel(data, GpuCoreShellCylinder,
+                     scale= .00031, radius=19.5, thickness=30, length=22,
+                     core_sld=7.105e-6, shell_sld=.291e-6, solvent_sld=7.105e-6,
+                     background=0.2, axis_theta=0, axis_phi=0,
 
-                 radius_pd=0.38, radius_pd_n=10, radius_pd_nsigma=3,
-                 length_pd=.9, length_pd_n=10, length_pd_nsigma=3,
-                 thickness_pd=0.1, thickness_pd_n=1, thickness_pd_nsigma=0,
-                 axis_theta_pd=10, axis_theta_pd_n=40, axis_theta_pd_nsigma=3,
-                 axis_phi_pd=0.1, axis_phi_pd_n=1, axis_phi_pd_nsigma=0,
-                 dtype='float')
+                     radius_pd=0.26, radius_pd_n=10, radius_pd_nsigma=3,
+                     length_pd=0.26, length_pd_n=10, length_pd_nsigma=3,
+                     thickness_pd=1, thickness_pd_n=1, thickness_pd_nsigma=1,
+                     axis_theta_pd=1, axis_theta_pd_n=10, axis_theta_pd_nsigma=3,
+                     axis_phi_pd=0.1, axis_phi_pd_n=1, axis_phi_pd_nsigma=1,
+                     dtype='float')
 
-# SET THE FITTING PARAMETERS
-model.radius.range(15, 1000)
-#model.length.range(0, 1000)
-#model.thickness.range(20, 50)
-#model.axis_phi.range(0, 90)
-#model.radius_pd.range(0, 1)
-#model.radius_b_pd.range(0, 1)
-#model.axis_theta_pd.range(0, 360)
-#model.axis_phi_pd.range(0, 360)
-#model.background.range(0,1000)
-model.scale.range(0, 1)
-"""
+    # SET THE FITTING PARAMETERS
+    #model.radius.range(115, 1000)
+    #model.length.range(0, 2500)
+    #model.thickness.range(18, 38)
+    #model.thickness_pd.range(0, 1)
+    #model.axis_phi.range(0, 90)
+    #model.radius_pd.range(0, 1)
+    #model.length_pd.range(0, 1)
+    #model.axis_theta_pd.range(0, 360)
+    #model.background.range(0,5)
+    model.scale.range(0, 1)
+
 
 
@@ -135,8 +156,8 @@
 """
 model = SasModel(data, GpuTriEllipse,
-                 scale=0.0036, axisA=118, axisB=70, axisC=800,
+                 scale=0.08, axisA=15, axisB=20, axisC=500,
                  sldEll=7.105e-6, sldSolv=.291e-6,
-                 background=15, theta=90, phi=0, psi=0,
-                 theta_pd=22, theta_pd_n=40, theta_pd_nsigma=3,
+                 background=5, theta=0, phi=0, psi=0,
+                 theta_pd=20, theta_pd_n=40, theta_pd_nsigma=3,
                  phi_pd=.1, phi_pd_n=1, phi_pd_nsigma=0,
                  psi_pd=30, psi_pd_n=1, psi_pd_nsigma=0,
@@ -150,5 +171,4 @@
 #model.axisC.range(15, 1000)
 #model.background.range(0,1000)
-model.scale.range(0, 1)
 #model.theta_pd.range(0, 360)
 #model.phi_pd.range(0, 360)
Index: fit2.py
===================================================================
--- fit2.py	(revision 473183c753f3b44a54aab3a16e00e358edf72be6)
+++ fit2.py	(revision a42fec0a6299c921e6b9422a1e4fa8aa60d78022)
@@ -3,12 +3,15 @@
 
 from bumps.names import *
-from cylcode import GpuCylinder
-from Models.sasmodel import SasModel, load_data, set_beam_stop
+from Models.code_coreshellcyl import GpuCoreShellCylinder
+from sasmodel import SasModel, load_data, set_beam_stop, set_top
 
 
-radial_data = load_data('JUN03289.DAT')
-set_beam_stop(radial_data, 0.004)
-trans_data = load_data('JUN03305.DAT')
-set_beam_stop(trans_data, 0.004)
+radial_data = load_data('December/DEC07267.DAT')
+set_beam_stop(radial_data, 0.00669, outer=0.025)
+set_top(radial_data, -.0185)
+
+tan_data = load_data('December/DEC07266.DAT')
+set_beam_stop(tan_data, 0.00669, outer=0.025)
+set_top(tan_data, -.0185)
 
 
@@ -17,22 +20,33 @@
 dtype='float32'
 radial = SasModel(radial_data,
-                  GpuCylinder, dtype=dtype,
-                  scale=1, radius=64.1, length=266.96, sldCyl=.291e-6, sldSolv=5.77e-6, background=0,
-                  cyl_theta=0, cyl_phi=0, radius_pd=0.1, radius_pd_n=10, radius_pd_nsigma=3,length_pd=0.1,
-                  length_pd_n=5, length_pd_nsigma=3, cyl_theta_pd=0.1, cyl_theta_pd_n=5, cyl_theta_pd_nsigma=3,
-                  cyl_phi_pd=0.1, cyl_phi_pd_n=10, cyl_phi_pd_nsigma=3)
-trans = SasModel(trans_data,
-                  GpuCylinder, dtype=dtype,
+                 GpuCoreShellCylinder,
+                 scale= 3.75e-7, radius=378, thickness=30, length=1806,
+                 core_sld=7.105e-6, shell_sld=.291e-6, solvent_sld=7.105e-6,
+                 background=0.2, axis_theta=0, axis_phi=90,
+
+                 radius_pd=0.26, radius_pd_n=20, radius_pd_nsigma=3,
+                 length_pd=0.26, length_pd_n=20, length_pd_nsigma=3,
+                 thickness_pd=1, thickness_pd_n=1, thickness_pd_nsigma=0,
+                 axis_theta_pd=1, axis_theta_pd_n=10, axis_theta_pd_nsigma=3,
+                 axis_phi_pd=0.1, axis_phi_pd_n=1, axis_phi_pd_nsigma=0,
+                 dtype='float')
+tan = SasModel(tan_data,
+                  GpuCoreShellCylinder, dtype=dtype,
                   **radial.parameters())
 
-radial.radius.range(0,100)
-radial.length.range(0, 1000)
-radial.cyl_theta.range(0,90)
-radial.cyl_phi.range(0,90)
-radial.scale.range(0,10)
-trans.cyl_theta = radial.cyl_theta + 90.
+radial.radius.range(15, 1000)
+radial.length.range(0, 2500)
+#radial.thickness.range(18, 38)
+#radial.thickness_pd.range(0, 1)
+#radial.axis_phi.range(0, 90)
+#radial.radius_pd.range(0, 1)
+#radial.length_pd.range(0, 1)
+#radial.axis_theta_pd.range(0, 360)
+#radial.background.range(0,5)
+#radial.scale.range(0, 1)
+radial.axis_phi = tan.axis_phi + 90
 
 
-problem = FitProblem([radial,trans])
+problem = FitProblem([radial,tan])
 
 
Index: multi-fit.py
===================================================================
--- multi-fit.py	(revision d772f5d5cfc1cb59c225465b709386ac13da531b)
+++ multi-fit.py	(revision a42fec0a6299c921e6b9422a1e4fa8aa60d78022)
@@ -3,21 +3,24 @@
 
 from bumps.names import *
-from code_lamellar import GpuLamellar
-from code_ellipse import GpuEllipse
+from Models.code_lamellar import GpuLamellar
+from Models.code_ellipse import GpuEllipse
+from Models.code_cylinder import GpuCylinder
 from multisasmodels import SasModel, load_data, set_beam_stop, set_half
 import numpy as np
 
-data = load_data('DEC07282.DAT')
+data = load_data('December/DEC07238.DAT')
 set_beam_stop(data, 0.0052)#, outer=0.025)
 #set_half(data, 'left')
 
-truth = SasModel(data, GpuEllipse,
-                scale=.0011, radius_a=45.265, radius_b=600.8, sldEll=.291e-6, sldSolv=7.105e-6,
-                 background=8.30161, axis_theta=0, axis_phi=0,
-                 radius_a_pd=0.222296, radius_a_pd_n=1, radius_a_pd_nsigma=0,
-                 radius_b_pd=.000128, radius_b_pd_n=1, radius_b_pd_nsigma=0,
-                 axis_theta_pd=20, axis_theta_pd_n=40, axis_theta_pd_nsigma=3,
-                 axis_phi_pd=2.63698e-05, axis_phi_pd_n=20, axis_phi_pd_nsigma=0,
-                 dtype='float')
+truth = SasModel(data, GpuCylinder,
+scale=0.08, radius=46, length=719,
+sldCyl=.291e-6, sldSolv=5.77e-6, background=0,
+cyl_theta=90, cyl_phi=0,
+cyl_theta_pd=23, cyl_theta_pd_n=40, cyl_theta_pd_nsigma=3,
+radius_pd=0.1, radius_pd_n=10, radius_pd_nsigma=3,
+length_pd=0.1, length_pd_n=10, length_pd_nsigma=3,
+cyl_phi_pd=0.1, cyl_phi_pd_n=10, cyl_phi_pd_nsigma=3,
+dtype='float')
+
 
 #model.radius_a.range(15, 1000)
@@ -30,6 +33,14 @@
 
 
-lies = SasModel(data, GpuLamellar, scale=0, bi_thick=5, sld_bi=.291e-6, sld_sol=5.77e-6, background=85.23,
-                 bi_thick_pd= 0.0013, bi_thick_pd_n=5, bi_thick_pd_nsigma=3, dtype='float')
+lies = SasModel(data, GpuCylinder,
+scale=0.08, radius=46, length=719,
+sldCyl=.291e-6, sldSolv=5.77e-6, background=0,
+cyl_theta=90, cyl_phi=0,
+cyl_theta_pd=23, cyl_theta_pd_n=40, cyl_theta_pd_nsigma=3,
+radius_pd=0.1, radius_pd_n=10, radius_pd_nsigma=3,
+length_pd=0.1, length_pd_n=10, length_pd_nsigma=3,
+cyl_phi_pd=0.1, cyl_phi_pd_n=10, cyl_phi_pd_nsigma=3,
+dtype='float')
+
 
 
@@ -43,5 +54,5 @@
 
 
-a = np.add(np.multiply(arrayone, .5), np.multiply(arraytwo, 0))
+a = np.add(np.multiply(arrayone, .08), np.multiply(arraytwo, .08))
 truth.set_result(a)
 
Index: sasmodel.py
===================================================================
--- sasmodel.py	(revision 099e05357033bb53919d7a0213dc1bd7a0b54ebb)
+++ sasmodel.py	(revision a42fec0a6299c921e6b9422a1e4fa8aa60d78022)
@@ -16,4 +16,30 @@
     return data
 
+def set_precision(src, qx, qy, dtype):
+    qx = np.ascontiguousarray(qx, dtype=dtype)
+    qy = np.ascontiguousarray(qy, dtype=dtype)
+    if np.dtype(dtype) == np.dtype('float32'):
+        header = """\
+#define real float
+"""
+    else:
+        header = """\
+#pragma OPENCL EXTENSION cl_khr_fp64: enable
+#define real double
+"""
+    return header+src, qx, qy
+
+def set_precision_1d(src, q, dtype):
+    q = np.ascontiguousarray(q, dtype=dtype)
+    if np.dtype(dtype) == np.dtype('float32'):
+        header = """\
+#define real float
+"""
+    else:
+        header = """\
+#pragma OPENCL EXTENSION cl_khr_fp64: enable
+#define real double
+"""
+    return header+src, q
 
 def set_beam_stop(data, radius, outer=None):
@@ -28,10 +54,11 @@
 
 def set_half(data, half):
+    if half == 'right':
+        data.mask += Boxcut(x_min=-np.inf, x_max=0.0, y_min=-np.inf, y_max=np.inf)(data)
     if half == 'left':
-        data.mask += Boxcut(x_min=-np.inf, x_max=0.0, y_min=-np.inf, y_max=np.inf)(data)
-    if half == 'right':
         data.mask += Boxcut(x_min=0.0, x_max=np.inf, y_min=-np.inf, y_max=np.inf)(data)
 
-
+def set_top(data, max):
+    data.mask += Boxcut(x_min=-np.inf, x_max=np.inf, y_min=-np.inf, y_max=max)(data)
 
 def plot_data(data, iq, vmin=None, vmax=None):
@@ -69,4 +96,5 @@
     plt.colorbar()
     plt.subplot(1, 3, 3)
+    print abs(mresid).max()
     plot_data(data, mresid)
     plt.colorbar()
@@ -110,4 +138,5 @@
     def __init__(self, data, model, dtype='float32', **kw):
         self.__dict__['_parameters'] = {}
+        #self.name = data.filename
         self.is2D = hasattr(data,'qx_data')
         self.data = data
@@ -135,5 +164,11 @@
         pars.update((base+'_pd_nsigma', 3) for base in model.PD_PARS)
         pars.update(kw)
-        self._parameters = dict((k, Parameter.default(v, name=k)) for k, v in pars.items())
+        for k,v in pars.items():
+            setattr(self, k, Parameter.default(v, name=k))
+        self._parameter_names = set(pars.keys())
+        self.update()
+
+    def update(self):
+        self._cache = {}
 
     def numpoints(self):
@@ -141,19 +176,12 @@
 
     def parameters(self):
-        return self._parameters
-
-    def __getattr__(self, par):
-        return self._parameters[par]
-
-    def __setattr__(self, par, val):
-        if par in self._parameters:
-            self._parameters[par] = val
-        else:
-            self.__dict__[par] = val
+        return dict((k,getattr(self,k)) for k in self._parameter_names)
 
     def theory(self):
-        pars = dict((k,v.value) for k,v in self._parameters.items())
-        result = self.gpu.eval(pars)
-        return result
+        if 'theory' not in self._cache:
+            pars = dict((k,getattr(self,k).value) for k in self._parameter_names)
+            #print pars
+            self._cache['theory'] = self.gpu.eval(pars)
+        return self._cache['theory']
 
     def residuals(self):
@@ -178,8 +206,4 @@
         pass
 
-    def update(self):
-        pass
-
-
 def demo():
     data = load_data('DEC07086.DAT')
