- Timestamp:
- Aug 4, 2014 5:20:07 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:
- 8cdb9f1
- Parents:
- 099e053
- Location:
- Models
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
Models/code_capcyl.py
rca6c007 ra42fec0 3 3 4 4 import numpy as np 5 from math import asin,sqrt, fabs, atan5 from math import sqrt, fabs, atan 6 6 import pyopencl as cl 7 7 8 8 from weights import GaussianDispersion 9 from sasmodel import card 9 from sasmodel import card, set_precision 10 10 11 11 12 def set_precision(src, qx, qy, dtype):13 qx = np.ascontiguousarray(qx, dtype=dtype)14 qy = np.ascontiguousarray(qy, dtype=dtype)15 if np.dtype(dtype) == np.dtype('float32'):16 header = """\17 #define real float18 """19 else:20 header = """\21 #pragma OPENCL EXTENSION cl_khr_fp64: enable22 #define real double23 """24 return header+src, qx, qy25 12 26 13 class GpuCapCylinder(object): … … 50 37 51 38 _ctx,queue = card() 39 self.res[:] = 0 40 cl.enqueue_copy(queue, self.res_b, self.res) 52 41 rad_cyl,length,rad_cap,theta,phi = \ 53 42 [GaussianDispersion(int(pars[base+'_pd_n']), pars[base+'_pd'], pars[base+'_pd_nsigma']) … … 79 68 real(rad_cyl.weight[i]), real(length.weight[j]), real(theta.weight[k]), np.uint32(self.qx.size), np.uint32(size)) 80 69 81 cl.enqueue_copy(queue, self.res, self.res_b)82 83 sum += self.res84 70 vol += rad_cyl.weight[i]*length.weight[j]*rad_cap.weight[m]*vol_i 85 71 norm_vol += rad_cyl.weight[i]*length.weight[j]*rad_cap.weight[m] 86 72 norm += rad_cyl.weight[i]*length.weight[j]*rad_cap.weight[m]*theta.weight[k]*phi.weight[l] 87 73 88 if size > 1: 89 norm /= asin(1.0) 90 74 #if size > 1: 75 # norm /= asin(1.0) 76 cl.enqueue_copy(queue, self.res, self.res_b) 77 sum += self.res 91 78 if vol != 0.0 and norm_vol != 0.0: 92 79 sum *= norm_vol/vol -
Models/code_coreshellcyl.py
rca6c007 ra42fec0 6 6 7 7 from weights import GaussianDispersion 8 from sasmodel import card 9 10 11 def set_precision(src, qx, qy, dtype): 12 qx = np.ascontiguousarray(qx, dtype=dtype) 13 qy = np.ascontiguousarray(qy, dtype=dtype) 14 if np.dtype(dtype) == np.dtype('float32'): 15 header = """\ 16 #define real float 17 """ 18 else: 19 header = """\ 20 #pragma OPENCL EXTENSION cl_khr_fp64: enable 21 #define real double 22 """ 23 return header+src, qx, qy 8 from sasmodel import card, set_precision 24 9 25 10 class GpuCoreShellCylinder(object): … … 46 31 47 32 _ctx,queue = card() 33 self.res[:] = 0 34 cl.enqueue_copy(queue, self.res_b, self.res) 48 35 radius, length, thickness, axis_phi, axis_theta = [GaussianDispersion(int(pars[base+'_pd_n']), pars[base+'_pd'], pars[base+'_pd_nsigma']) 49 36 for base in GpuCoreShellCylinder.PD_PARS] … … 56 43 57 44 sum, norm, norm_vol, vol = 0.0, 0.0, 0.0, 0.0 58 59 print radius.value60 print thickness.weight61 print axis_phi.weight62 print axis_theta.weight63 print length.value64 65 45 size = len(axis_theta.weight) 66 46 … … 79 59 real(pars['shell_sld']), real(pars['solvent_sld']),np.uint32(size), 80 60 np.uint32(self.qx.size)) 81 cl.enqueue_copy(queue, self.res, self.res_b)82 83 sum += self.res84 61 vol += radius.weight[r]*length.weight[l]*thickness.weight[th]*pow(radius.value[r]+thickness.value[th],2)\ 85 62 *(length.value[l]+2.0*thickness.value[th]) … … 90 67 #if size>1: 91 68 # norm /= math.asin(1.0) 69 cl.enqueue_copy(queue, self.res, self.res_b) 70 sum = self.res 92 71 if vol != 0.0 and norm_vol != 0.0: 93 72 sum *= norm_vol/vol -
Models/code_cylinder.py
rca6c007 ra42fec0 6 6 7 7 from weights import GaussianDispersion 8 from sasmodel import card 8 from sasmodel import card, set_precision, set_precision_1d 9 9 10 11 def set_precision(src, qx, qy, dtype):12 qx = np.ascontiguousarray(qx, dtype=dtype)13 qy = np.ascontiguousarray(qy, dtype=dtype)14 if np.dtype(dtype) == np.dtype('float32'):15 header = """\16 #define real float17 """18 else:19 header = """\20 #pragma OPENCL EXTENSION cl_khr_fp64: enable21 #define real double22 """23 return header+src, qx, qy24 25 def set_precision_1d(src, q, dtype):26 q = np.ascontiguousarray(q, dtype=dtype)27 if np.dtype(dtype) == np.dtype('float32'):28 header = """\29 #define real float30 """31 else:32 header = """\33 #pragma OPENCL EXTENSION cl_khr_fp64: enable34 #define real double35 """36 return header+src, q37 10 38 11 class GpuCylinder(object): … … 55 28 self.qx_b = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=self.qx) 56 29 self.qy_b = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=self.qy) 57 self.res_b = cl.Buffer(ctx, mf.WRITE_ONLY,qx.nbytes)30 self.res_b = cl.Buffer(ctx, cl.mem_flags.READ_WRITE, self.qx.nbytes) 58 31 self.res = np.empty_like(self.qx) 59 32 … … 61 34 62 35 _ctx,queue = card() 36 self.res[:] = 0 37 cl.enqueue_copy(queue, self.res_b, self.res) 63 38 radius, length, cyl_theta, cyl_phi = \ 64 39 [GaussianDispersion(int(pars[base+'_pd_n']), pars[base+'_pd'], pars[base+'_pd_nsigma']) … … 68 43 radius.value, radius.weight = radius.get_weights(pars['radius'], 0, 10000, True) 69 44 length.value, length.weight = length.get_weights(pars['length'], 0, 10000, True) 70 cyl_theta.value, cyl_theta.weight = cyl_theta.get_weights(pars['cyl_theta'], - 90, 180, False)71 cyl_phi.value, cyl_phi.weight = cyl_phi.get_weights(pars['cyl_phi'], - 90, 180, False)45 cyl_theta.value, cyl_theta.weight = cyl_theta.get_weights(pars['cyl_theta'], -np.inf, np.inf, False) 46 cyl_phi.value, cyl_phi.weight = cyl_phi.get_weights(pars['cyl_phi'], -np.inf, np.inf, False) 72 47 73 48 #Perform the computation, with all weight points … … 87 62 real(cyl_phi.weight[l]), real(cyl_theta.value[k]), real(cyl_phi.value[l]), 88 63 np.uint32(self.qx.size), np.uint32(size)) 89 cl.enqueue_copy(queue, self.res, self.res_b) 90 sum += self.res 64 91 65 vol += radius.weight[i]*length.weight[j]*pow(radius.value[i], 2)*length.value[j] 92 66 norm_vol += radius.weight[i]*length.weight[j] … … 95 69 # if size > 1: 96 70 # norm /= math.asin(1.0) 71 cl.enqueue_copy(queue, self.res, self.res_b) 72 sum = self.res 97 73 if vol != 0.0 and norm_vol != 0.0: 98 74 sum *= norm_vol/vol -
Models/code_ellipse.py
rca6c007 ra42fec0 6 6 7 7 from weights import GaussianDispersion 8 from sasmodel import card 9 10 11 def set_precision(src, qx, qy, dtype): 12 qx = np.ascontiguousarray(qx, dtype=dtype) 13 qy = np.ascontiguousarray(qy, dtype=dtype) 14 if np.dtype(dtype) == np.dtype('float32'): 15 header = """\ 16 #define real float 17 """ 18 else: 19 header = """\ 20 #pragma OPENCL EXTENSION cl_khr_fp64: enable 21 #define real double 22 """ 23 return header+src, qx, qy 8 from sasmodel import card, set_precision 24 9 25 10 class GpuEllipse(object): … … 46 31 #b_n = radius_b # want, a_n = radius_a # want, etc 47 32 _ctx,queue = card() 33 self.res[:] = 0 34 cl.enqueue_copy(queue, self.res_b, self.res) 48 35 radius_a, radius_b, axis_theta, axis_phi = \ 49 36 [GaussianDispersion(int(pars[base+'_pd_n']), pars[base+'_pd'], pars[base+'_pd_nsigma']) … … 76 63 real(axis_phi.value[l]), self.qx_b, self.qy_b, self.res_b, 77 64 np.uint32(self.qx.size), np.uint32(len(axis_theta.weight))) 78 #copy result back from buffer 79 cl.enqueue_copy(queue, self.res, self.res_b) 80 sum += self.res 65 81 66 vol += radius_a.weight[i]*radius_b.weight[j]*pow(radius_b.value[j], 2)*radius_a.value[i] 82 67 norm_vol += radius_a.weight[i]*radius_b.weight[j] … … 88 73 # if size > 1: 89 74 # norm /= math.asin(1.0) 75 cl.enqueue_copy(queue, self.res, self.res_b) 76 sum += self.res 90 77 if vol != 0.0 and norm_vol != 0.0: 91 78 sum *= norm_vol/vol -
Models/code_lamellar.py
rca6c007 ra42fec0 5 5 import pyopencl as cl 6 6 from Models.weights import GaussianDispersion 7 8 def set_precision(src, qx, qy, dtype): 9 qx = np.ascontiguousarray(qx, dtype=dtype) 10 qy = np.ascontiguousarray(qy, dtype=dtype) 11 if dtype == 'double': 12 header = """\ 13 #define real float 14 """ 15 else: 16 header = """\ 17 #pragma OPENCL EXTENSION cl_khr_fp64: enable 18 #define real double 19 """ 20 return header+src, qx, qy 7 from sasmodel import set_precision 21 8 22 9 -
Models/code_triaxialellipse.py
rca6c007 ra42fec0 6 6 7 7 from weights import GaussianDispersion 8 from sasmodel import card 9 10 11 def set_precision(src, qx, qy, dtype): 12 qx = np.ascontiguousarray(qx, dtype=dtype) 13 qy = np.ascontiguousarray(qy, dtype=dtype) 14 if np.dtype(dtype) == np.dtype('float32'): 15 header = """\ 16 #define real float 17 """ 18 else: 19 header = """\ 20 #pragma OPENCL EXTENSION cl_khr_fp64: enable 21 #define real double 22 """ 23 return header+src, qx, qy 8 from sasmodel import card, set_precision 24 9 25 10 class GpuTriEllipse: … … 45 30 46 31 _ctx,queue = card() 32 self.res[:] = 0 33 cl.enqueue_copy(queue, self.res_b, self.res) 47 34 axisA, axisB, axisC, theta, phi, psi = \ 48 35 [GaussianDispersion(int(pars[base+'_pd_n']), pars[base+'_pd'], pars[base+'_pd_nsigma']) … … 72 59 real(axisA.weight[a]), real(axisB.weight[b]), real(axisC.weight[c]), real(psi.weight[s]), 73 60 real(phi.weight[i]), real(theta.weight[t]), np.uint32(self.qx.size), np.uint32(size)) 74 cl.enqueue_copy(queue, self.res, self.res_b)75 sum += self.res76 61 77 62 vol += axisA.weight[a]*axisB.weight[b]*axisC.weight[c]*axisA.value[a]*axisB.value[b]*axisC.value[c] … … 81 66 # if size > 1: 82 67 # norm /= asin(1.0) 83 68 cl.enqueue_copy(queue, self.res, self.res_b) 69 sum = self.res 84 70 if vol != 0.0 and norm_vol != 0.0: 85 71 sum *= norm_vol/vol -
Models/weights.py
rdbb0048 ra42fec0 19 19 sigma = width * center if relative else width 20 20 if sigma == 0: 21 return np.array([center ,1.], 'd')21 return np.array([center],'d'), np.array([1.], 'd') 22 22 x = center + np.linspace(-nsigmas * sigma, +nsigmas * sigma, npts) 23 23 x = x[(x >= min) & (x <= max)]
Note: See TracChangeset
for help on using the changeset viewer.