Changeset 2de9a5e in sasmodels
- Timestamp:
- Jul 11, 2014 2:47:47 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:
- be5d7df
- Parents:
- 8faffcd
- Files:
-
- 3 added
- 5 edited
- 5 moved
Legend:
- Unmodified
- Added
- Removed
-
Capcyl_Kfun.cpp
r8faffcd r2de9a5e 14 14 return(val); 15 15 } 16 const real Gauss76Z[76]={ 16 /* 17 real Gauss76Z[76]={ 17 18 .999505948362153*(-1.0), //0 18 19 .997397786355355*(-1.0), … … 92 93 -.999505948362153*(-1.0) //75 93 94 }; 94 constreal Gauss76Wt[76]={95 real Gauss76Wt[76]={ 95 96 .00126779163408536, //0 96 97 .00294910295364247, … … 170 171 .00126779163408536 //75 (indexed from 0) 171 172 }; 173 */ -
Kernel-CapCyl.cpp
r8faffcd r2de9a5e 1 __kernel void CapCylinderKernel(__global const float *qx, __global const float *qy, __global float *_ _ptvalue, __global float *vol_i1 __kernel void CapCylinderKernel(__global const float *qx, __global const float *qy, __global float *_ptvalue, __global float *vol_i, 2 2 const float rad_cyl, const float rad_cap, const float length, const float thet, const float ph, const float sub, 3 3 const float scale, const float phi_weight, const float theta_float, const float rad_cap_weight, const float rad_cyl_weight, 4 const float length_weight, const int total, const int size )4 const float length_weight, const int total, const int size, __const float Gauss76Wt, __const float Gauss76Z) 5 5 //ph is phi, sub is sldc-slds, thet is theta 6 6 { … … 8 8 if(i < total) 9 9 { 10 float q = sqrt(qx[i]*qx[i] + qy[i]*qy[i]) 10 float q = sqrt(qx[i]*qx[i] + qy[i]*qy[i]); 11 11 float pi = 4.0*atan(1.0); 12 12 float theta = thet*pi/180.0; … … 16 16 float cos_val = cyl_x*qx[i]/q + cyl_y*qy[i]/q; 17 17 float alpha = acos(cos_val); 18 float yyy=0; float ans1=0; float ans2=0; float y=0; float xx=0; float ans=0; float zij=0; float be=0 18 float yyy=0; float ans1=0; float ans2=0; float y=0; float xx=0; float ans=0; float zij=0; float be=0; float summj=0; 19 19 20 20 float hDist = -1.0*sqrt(fabs(rad_cap*rad_cap-rad_cyl*rad_cyl)); 21 vol_i[i] = pi*rad_cyl*rad_cyl*len _cyl+2.0*pi/3.0*((rad_cap-hDist)*(rad_cap-hDist)*(2*rad_cap+hDist));21 vol_i[i] = pi*rad_cyl*rad_cyl*length+2.0*pi/3.0*((rad_cap-hDist)*(rad_cap-hDist)*(2*rad_cap+hDist)); 22 22 float vaj = -1.0*hDist/rad_cap; 23 23 24 for( j=0;j<76;j++) //the 76 corresponds to the Gauss constants24 for(int j=0;j<76;j++) //the 76 corresponds to the Gauss constants 25 25 { 26 26 zij = (Gauss76Z[j]*(1.0-vaj)+vaj+1.0)/2.0; … … 45 45 } 46 46 float answer=yyy*yyy*1.0e8*sub*sub*scale/pi*rad_cyl*rad_cyl*length+2.0*pi*(2.0*rad_cap*rad_cap*rad_cap/3.0+rad_cap*rad_cap*hDist-hDist*hDist*hDist/3.0); 47 answer/=sin(alpha) 47 answer/=sin(alpha); 48 48 49 49 _ptvalue[i] = rad_cyl_weight*length_weight*rad_cap_weight*theta_weight*phi_weight*vol_i[i]*answer -
Kernel-CoreShellCylinder.cpp
r8faffcd r2de9a5e 11 11 float pi = 4.0*atan(1.0); 12 12 float theta = axis_theta*pi/180.0; 13 float phi = axis_phi*pi/180.0; 14 float cyl_x = cos(theta)*cos(phi); 13 float cyl_x = cos(theta)*cos(axis_phi*pi/180.0); 15 14 float cyl_y = sin(theta); 16 float cos_val = cyl_x*qx[i]/q + cyl_y*qx[i]/q; 17 float alpha = acos(cos_val); 15 float alpha = acos(cyl_x*qx[i]/q + cyl_y*qx[i]/q); 18 16 19 17 if (alpha == 0.0){ … … 23 21 float si1=0; float si2=0; float be1=0; float be2=0; 24 22 25 float dr1 = core_sld-shell_sld;26 float dr2 = shell_sld-solvent_sld;27 float vol1 = pi*radius*radius*(length);28 23 float vol2 = pi*(radius+thickness)*(radius+thickness)*(length+2.0*thickness); 29 24 … … 54 49 si2 = sin(sinarg2)/sinarg2; 55 50 } 51 float tt = 2.0*vol2*(shell_sld-solvent_sld)*si2*be2 + 2.0*(pi*radius*radius*(length))*(core_sld-shell_sld)*si1*be1; 56 52 57 float t1 = 2.0*vol1*dr1*si1*be1; 58 float t2 = 2.0*vol2*dr2*si2*be2; 59 60 float answer = ((t1+t2)*(t1+t2))*sin(alpha)/fabs(sin(alpha)); 53 float answer = (tt*tt)*sin(alpha)/fabs(sin(alpha)); 61 54 float vol=pi*(radius+thickness)*(radius+thickness)*(length+2.0*thickness); 62 55 answer = answer/vol*1.0e8*scale; -
Kernel-Lamellar.cpp
r8a20be5 r2de9a5e 1 #ifndef real2 # define real float3 #endif4 1 5 2 __kernel void LamellarKernel(__global const real *qx, global const real *qy, __global real *ret, const real bi_thick, 6 const real scale, const real sub, const real background, constint length)3 const real scale, const real sub, const int length) 7 4 { 8 5 int i = get_global_id(0); … … 12 9 real pi = 4.0*atan(1.0); 13 10 real Pq = 2.0*sub*(sub/q)/q*(1.0-cos(q*bi_thick)); 14 ret[i] = 2.0*pi*scale*Pq/(q*q)/bi_thick*1.0e8; 15 ret[i] += background; 11 ret[i] = 2.0*pi*scale*Pq/(q*q)/bi_thick*1.0e8 ; 16 12 } 17 13 } -
code_capcyl.py
r8faffcd r2de9a5e 7 7 from weights import GaussianDispersion 8 8 from sasmodel import card 9 from Capcyl_Gauss import Gauss76Wt, Gauss76Z 9 10 10 11 def set_precision(src, qx, qy, dtype): … … 34 35 trala = open('NR_BessJ1.cpp').read()+"\n"+open('Capcyl_Kfun.cpp').read()+"\n"+open('Kernel-Cylinder.cpp').read() 35 36 src, qx, qy = set_precision(trala, qx, qy, dtype=dtype) 37 self.prg = cl.Program(ctx, src).build() 38 self.qx, self.qy = qx, qy 36 39 37 self.prg = cl.Program(ctx, open('Kernel-CapCyl.cpp').read()).build()38 40 39 41 #buffers … … 41 43 self.qx_b = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=self.qx) 42 44 self.qy_b = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=self.qy) 45 G, Z = Gauss76Wt, Gauss76Z 46 self.Gauss76W_b = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=G) 47 self.Gauss76Z_b = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=Z) 43 48 self.res_b = cl.Buffer(ctx, mf.WRITE_ONLY, qx.nbytes) 44 49 self.res = np.empty_like(self.qx) … … 73 78 np.float32(theta.value[k]), np.float32(phi.value[l]), np.float32(sub), np.float32(pars['scale']), 74 79 np.float32(phi.weight[l]), np.float32(theta.weight[k]), np.float32(rad_cap.weight[m]), 75 np.float32(rad_cyl.weight[i]), np.float32(length.weight[j]), np.uint32(self.qx.size), np.uint32(size)) 80 np.float32(rad_cyl.weight[i]), np.float32(length.weight[j]), np.uint32(self.qx.size), np.uint32(size), 81 self.Gauss76W_b, self.Gauss76Z_b) 76 82 77 83 cl.enqueue_copy(queue, self.res, self.res_b) -
code_lamellar.py
r8a20be5 r2de9a5e 11 11 if dtype == 'double': 12 12 header = """\ 13 #define real float 14 """ 15 else: 16 header = """\ 13 17 #pragma OPENCL EXTENSION cl_khr_fp64: enable 14 18 #define real double 15 19 """ 16 return header+src,qx,qy 17 else: 18 return src,qx,qy 20 return header+src, qx, qy 19 21 20 22 … … 23 25 'scale':1, 'bi_thick':1, 'sld_bi':1e-6, 'sld_sol':0, 'background':0, 24 26 } 25 26 def __init__(self, qx, qy, dtype='float '):27 PD_PARS = {'bi_thick'} 28 def __init__(self, qx, qy, dtype='float32'): 27 29 28 30 #create context, queue, and build program … … 51 53 for i in xrange(len(bi_thick.weight)): 52 54 self.prg.LamellarKernel(self.queue, self.qx.shape, None, self.qx_b, self.qy_b, self.res_b, real(bi_thick.value[i]), 53 real(pars['scale']), real(sub), real(pars['background']),np.uint32(self.qx.size))55 real(pars['scale']), real(sub), np.uint32(self.qx.size)) 54 56 cl.enqueue_copy(self.queue, self.res, self.res_b) 55 57 -
fit.py
r8faffcd r2de9a5e 3 3 4 4 from bumps.names import * 5 from cylcode import GpuCylinder 6 from lamellarcode import GpuLamellar 7 from ellipsecode import GpuEllipse 8 from coreshellcylcode import GpuCoreShellCylinder 5 from code_cylinder import GpuCylinder 6 from code_lamellar import GpuLamellar 7 from code_ellipse import GpuEllipse 8 from code_coreshellcyl import GpuCoreShellCylinder 9 from code_capcyl import GpuCapCylinder 10 from code_triaxialellipse import GpuTriEllipse 9 11 from sasmodel import SasModel, load_data, set_beam_stop 10 12 … … 25 27 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, 26 28 radius_b_pd_nsigma=3, axis_theta_pd=0.1, axis_theta_pd_n=6, axis_theta_pd_nsigma=3, axis_phi_pd=0.1, 27 axis_phi_pd_n=6, axis_phi_pd_nsigma=3, dtype='float ')29 axis_phi_pd_n=6, axis_phi_pd_nsigma=3, dtype='float32') 28 30 29 31 model = SasModel(data, GpuLamellar, scale=1, bi_thick=100, sld_bi=.291e-6, sld_sol=5.77e-6, background=0, 30 bi_thick_pd=0.1, bi_thick_pd_n=35, bi_thick_pd_nsigma=3, dtype='float ')32 bi_thick_pd=0.1, bi_thick_pd_n=35, bi_thick_pd_nsigma=3, dtype='float32') 31 33 32 """ 34 33 35 model = SasModel(data, GpuCoreShellCylinder, scale=1, radius=64.1, thickness=1, length=266.96, core_sld=1e-6, shell_sld=4e-6, 34 36 solvent_sld=1e-6, background=0, axis_theta=0, axis_phi=0, radius_pd=0.1, radius_pd_n=10, radius_pd_nsigma=3, 35 37 length_pd=0.1, length_pd_n=10, length_pd_nsigma=3, thickness_pd=0.1, thickness_pd_n=2, thickness_pd_nsigma=3, 36 38 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, 37 axis_phi_pd_nsigma=3, dtype='float ')39 axis_phi_pd_nsigma=3, dtype='float32') 38 40 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_) 41 model = SasModel(data, GpuCapCylinder, scale=1, rad_cyl=20, rad_cap=40, length=400, sld_capcyl=1e-6, sld_solv=6.3e-6, 42 background=0, theta=0, phi=0, rad_cyl_pd=.1, rad_cyl_pd_n=10, rad_cyl_nsigma=3, rad_cap_pd=.1, rad_cap_pd_n=1, 43 rad_cap_pd_nsigma=3, length_pd=.1, length_pd_n=10, length_pd_nsigma=3, theta_pd=.1, theta_pd_n=4, 44 theta_pd_nsigma=3, phi_pd=.1, phi_pd_n=4, phi_pd_nsigma=3, dtype='float32') 45 """ 46 model = SasModel(data, GpuTriEllipse, scale=1, axisA=35, axisB=100, axisC=400, sldEll=1e-6, sldSolv=6.3e-6, 47 background=0, theta=57, phi=57, psi=0, theta_pd=.1, theta_pd_n=4, 48 theta_pd_nsigma=3, phi_pd=.1, phi_pd_n=4, phi_pd_nsigma=3, psi_pd=.1, psi_pd_n=4, psi_pd_nsigma=3, 49 axisA_pd=.1, axisA_pd_n=4, axisA_pd_nsigma=3, axisB_pd=.1, axisB_pd_n=4, axisB_pd_nsigma=3, 50 axisC_pd=.1, axisC_pd_n=4, axisC_pd_nsigma=3, dtype='float') 41 51 42 model.scale.range(0,1 0)52 model.scale.range(0,1) 43 53 44 54 problem = FitProblem(model)
Note: See TracChangeset
for help on using the changeset viewer.