Changeset 8faffcd in sasmodels
- Timestamp:
- Jul 10, 2014 4:06:29 PM (10 years ago)
- Branches:
- master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- 2de9a5e
- Parents:
- 8a20be5
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
Kernel-CapCyl.cpp
r8a20be5 r8faffcd 22 22 float vaj = -1.0*hDist/rad_cap; 23 23 24 for(j=0;j<76;j++) //the value 76 was pre-set in the kernel...24 for(j=0;j<76;j++) //the 76 corresponds to the Gauss constants 25 25 { 26 zij = ( Gauss76Z[j]*(1.0-vaj) + vaj + 1.0 )/2.0; //the "t" dummy27 yyy = Gauss76Wt[j]*ConvLens_kernel( dp,q,zij,alpha); //uses the same Kernel as the Dumbbell, here L>026 zij = (Gauss76Z[j]*(1.0-vaj)+vaj+1.0)/2.0; 27 yyy = Gauss76Wt[j]*ConvLens_kernel(length,rad_cyl,rad_cap,q,zij,alpha); 28 28 summj += yyy; 29 29 } … … 35 35 if(arg2 == 0) {be = 0.5;} 36 36 else { 37 float ax=fabs(arg2); 38 if ((ax < 8.0) { 39 y=arg2*arg2; 40 ans1=arg2*(72362614232.0+y*(-7895059235.0+y*(242396853.1+y*(-2972611.439+y*(15704.48260+y*(-30.16036606)))))); 41 ans2=144725228442.0+y*(2300535178.0+y*(18583304.74+y*(99447.43394+y*(376.9991397+y*1.0)))); 42 ans=ans1/ans2; 43 } 44 else { 45 y=64.0/(ax*ax); 46 xx=ax-2.356194491; 47 ans1=1.0+y*(0.183105e-2+y*(-0.3516396496e-4+y*(0.2457520174e-5+y*(-0.240337019e-6)))); 48 ans2=0.04687499995+y*(-0.2002690873e-3+y*(0.8449199096e-5+y*(-0.88228987e-6+y*0.105787412e-6))); 49 ans=sqrt(0.636619772/ax)*(cos(xx)*ans1-(8.0/ax)*sin(xx)*ans2); 50 if (arg2 < 0.0) {ans *= -1;} 51 } 52 be = ans/arg2 37 be = NR_BessJ1(arg2)/arg2; 53 38 } 54 39 55 if(arg1 == 0.0) { //limiting value of sinc(0) is 1; sinc is not defined in math.h40 if(arg1 == 0.0) { 56 41 yyy += pi*rad_cyl*rad_cyl*length*2.0*be; 57 42 } -
Kernel-CoreShellCylinder.cpp
r8a20be5 r8faffcd 22 22 23 23 float si1=0; float si2=0; float be1=0; float be2=0; 24 float ax=0; float z=0; float xx=0; float y=0; float ans=0; float ans1=0; float ans2=0;25 24 26 25 float dr1 = core_sld-shell_sld; … … 37 36 if (besarg1 == 0.0){be1 = 0.5;} 38 37 else{ 39 be l = NR_BessJ1(besarg1)/besarg138 be1 = NR_BessJ1(besarg1)/besarg1; 40 39 } 41 40 if (besarg2 == 0.0){be2 = 0.5;} 42 41 else{ 43 if((ax=fabs(besarg2)) < 8.0) 44 { 45 y=besarg2*besarg2; 46 ans1=besarg2*(72362614232.0+y*(-7895059235.0+y*(242396853.1+y*(-2972611.439+y*(15704.48260+y*(-30.16036606)))))); 47 ans2=144725228442.0+y*(2300535178.0+y*(18583304.74+y*(99447.43394+y*(376.9991397+y*1.0)))); 48 ans=ans1/ans2; 49 } 50 else 51 { 52 z=8.0/ax; 53 y=z*z; 54 xx=ax-2.356194491; 55 ans1=1.0+y*(0.183105e-2+y*(-0.3516396496e-4+y*(0.2457520174e-5+y*(-0.240337019e-6)))); 56 ans2=0.04687499995+y*(-0.2002690873e-3+y*(0.8449199096e-5+y*(-0.88228987e-6+y*0.105787412e-6))); 57 ans=sqrt(0.636619772/ax)*(cos(xx)*ans1-z*sin(xx)*ans2); 58 if (besarg2 < 0.0) {ans *= -1;} 59 } 60 be2 = ans/besarg2; 42 be2 = NR_BessJ1(besarg2)/besarg2; 61 43 } 62 44 if (sinarg1 == 0.0){ -
capcylcope.py
r8a20be5 r8faffcd 6 6 import pyopencl as cl 7 7 from weights import GaussianDispersion 8 from sasmodel import card 9 10 def set_precision(src, qx, qy, dtype): 11 qx = np.ascontiguousarray(qx, dtype=dtype) 12 qy = np.ascontiguousarray(qy, dtype=dtype) 13 if np.dtype(dtype) == np.dtype('float32'): 14 header = """\ 15 #define real float 16 """ 17 else: 18 header = """\ 19 #pragma OPENCL EXTENSION cl_khr_fp64: enable 20 #define real double 21 """ 22 return header+src, qx, qy 8 23 9 24 class GpuCapCylinder(object): … … 13 28 PD_PARS = ['rad_cyl', 'length', 'rad_cap', 'theta', 'phi'] 14 29 15 def __init__(self, qx, qy ):30 def __init__(self, qx, qy, dtype='float32'): 16 31 17 self.qx = np.asarray(qx, np.float32)18 self.qy = np.asarray(qy, np.float32)19 32 #create context, queue, and build program 20 self.ctx = cl.create_some_context() 21 self.queue = cl.CommandQueue(self.ctx) 33 ctx,_queue = card() 34 trala = open('NR_BessJ1.cpp').read()+"\n"+open('Capcyl_Kfun.cpp').read()+"\n"+open('Kernel-Cylinder.cpp').read() 35 src, qx, qy = set_precision(trala, qx, qy, dtype=dtype) 22 36 23 self.prg = cl.Program( self.ctx, open('Kernel-CapCyl.cpp').read()).build()37 self.prg = cl.Program(ctx, open('Kernel-CapCyl.cpp').read()).build() 24 38 25 39 #buffers 26 40 mf = cl.mem_flags 27 self.qx_b = cl.Buffer( self.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=self.qx)28 self.qy_b = cl.Buffer( self.ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=self.qy)29 self.res_b = cl.Buffer( self.ctx, mf.WRITE_ONLY, qx.nbytes)41 self.qx_b = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=self.qx) 42 self.qy_b = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=self.qy) 43 self.res_b = cl.Buffer(ctx, mf.WRITE_ONLY, qx.nbytes) 30 44 self.res = np.empty_like(self.qx) 31 45 self.vol_i = float(0.0) 32 self.vol_b = cl.Buffer( self.ctx, mf.WRITE_ONLY, self.vol_i.nbytes)46 self.vol_b = cl.Buffer(ctx, mf.WRITE_ONLY, self.vol_i.nbytes) 33 47 34 48 def eval(self, pars): 35 49 50 _ctx,queue = card() 36 51 rad_cyl,length,rad_cap,theta,phi = \ 37 52 [GaussianDispersion(int(pars[base+'_pd_n']), pars[base+'_pd'], pars[base+'_pd_nsigma']) … … 54 69 for l in xrange(len(phi.weight)): 55 70 56 self.prg.CapCylinderKernel( self.queue, self.qx.shape, None, self.qx_b, self.qy_b, self.res_b,71 self.prg.CapCylinderKernel(queue, self.qx.shape, None, self.qx_b, self.qy_b, self.res_b, 57 72 self.vol_b, np.float32(rad_cyl.value[i]), np.float32(rad_cap.value[m]), np.float32(length.value[j]), 58 73 np.float32(theta.value[k]), np.float32(phi.value[l]), np.float32(sub), np.float32(pars['scale']), … … 60 75 np.float32(rad_cyl.weight[i]), np.float32(length.weight[j]), np.uint32(self.qx.size), np.uint32(size)) 61 76 62 cl.enqueue_copy( self.queue, self.res, self.res_b)63 cl.enqueue_copy( self.queue, self.vol_i, self.vol_b)77 cl.enqueue_copy(queue, self.res, self.res_b) 78 cl.enqueue_copy(queue, self.vol_i, self.vol_b) 64 79 65 80 sum += self.res -
fit.py
r8a20be5 r8faffcd 12 12 data = load_data('JUN03289.DAT') 13 13 set_beam_stop(data, 0.004) 14 15 16 17 14 """ 18 15 model = SasModel(data, GpuCylinder, scale=1, radius=64.1, length=266.96, sldCyl=.291e-6, sldSolv=5.77e-6, background=0, 19 16 cyl_theta=0, cyl_phi=0, radius_pd=0.1, radius_pd_n=10, radius_pd_nsigma=3,length_pd=0.1, … … 24 21 model.cyl_theta.range(0,90) 25 22 model.cyl_phi.range(0,90) 26 """ 23 27 24 model = SasModel(data, GpuEllipse, scale=.027, radius_a=60, radius_b=180, sldEll=.297e-6, sldSolv=5.773e-6, background=4.9, 28 25 axis_theta=0, axis_phi=90, radius_a_pd=0.1, radius_a_pd_n=10, radius_a_pd_nsigma=3, radius_b_pd=0.1, radius_b_pd_n=10, … … 33 30 bi_thick_pd=0.1, bi_thick_pd_n=35, bi_thick_pd_nsigma=3, dtype='float') 34 31 35 36 model = SasModel(data, GpuCoreShellCylinder, scale=1, radius=64.1, thickness=1, length=266.96, core_sld=1e-6, shell_sld= 1e-6,37 solvent_sld= 4e-6, background=0, axis_theta=0, axis_phi=0, radius_pd=0.1, radius_pd_n=10, radius_pd_nsigma=3,32 """ 33 model = SasModel(data, GpuCoreShellCylinder, scale=1, radius=64.1, thickness=1, length=266.96, core_sld=1e-6, shell_sld=4e-6, 34 solvent_sld=1e-6, background=0, axis_theta=0, axis_phi=0, radius_pd=0.1, radius_pd_n=10, radius_pd_nsigma=3, 38 35 length_pd=0.1, length_pd_n=10, length_pd_nsigma=3, thickness_pd=0.1, thickness_pd_n=2, thickness_pd_nsigma=3, 39 36 axis_theta_pd=0.1, axis_theta_pd_n=2, axis_theta_pd_nsigma=3, axis_phi_pd=0.1, axis_phi_pd_n=2, 40 37 axis_phi_pd_nsigma=3, dtype='float') 41 """ 38 39 model = SasModel(data, GpuCapCylinder, scale, rad_cyl, rad_cap, length, sld_capcyl, sld_solv, background, theta, phi, 40 rad_cyl_pd, rad_cyl_pd_n, rad_cyl_nsigma, rad_cap_pd, rad_cap_pd_n, rad_cap_pd_nsigma, length_) 42 41 43 42 model.scale.range(0,10) -
fit2.py
r8a20be5 r8faffcd 34 34 radial.cyl_phi.range(0,90) 35 35 radial.scale.range(0,10) 36 trans.cyl_theta = radial.cyl_theta + 90. 36 37 37 38 38 fv = FreeVariables(names=['radial','trans'], 39 cyl_theta=radial.cyl_theta, 40 cyl_phi = radial.cyl_phi) 41 problem = FitProblem([radial,trans], freevars=fv) 39 problem = FitProblem([radial,trans]) 42 40 43 41 -
sasmodel.py
r8a20be5 r8faffcd 62 62 class SasModel(object): 63 63 def __init__(self, data, model, dtype='float32', **kw): 64 self.__dict__['_parameters'] = {} 64 65 self.index = data.mask==0 65 66 self.iq = data.data[self.index] … … 79 80 pars.update((base+'_pd_nsigma', 3) for base in model.PD_PARS) 80 81 pars.update(kw) 81 self._parameters = dict((k, Parameter (v, name=k)) for k, v in pars.items())82 self._parameters = dict((k, Parameter.default(v, name=k)) for k, v in pars.items()) 82 83 83 84 def numpoints(self): … … 90 91 return self._parameters[par] 91 92 93 def __setattr__(self, par, val): 94 if par in self._parameters: 95 self._parameters[par] = val 96 else: 97 self.__dict__[par] = val 98 92 99 def theory(self): 93 100 pars = dict((k,v.value) for k,v in self._parameters.items()) 94 print pars95 101 result = self.gpu.eval(pars) 96 102 return result
Note: See TracChangeset
for help on using the changeset viewer.