Changes in / [502c7b8:cdd676e] in sasmodels
- Files:
-
- 1 deleted
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
explore/beta/sasfit_compare.py
r01c8d9e rcdd676e 3 3 import sys, os 4 4 BETA_DIR = os.path.dirname(os.path.realpath(__file__)) 5 #SASMODELS_DIR = os.path.dirname(os.path.dirname(BETA_DIR)) 6 SASMODELS_DIR = r"C:\Source\sasmodels" 5 SASMODELS_DIR = os.path.dirname(os.path.dirname(BETA_DIR)) 7 6 sys.path.insert(0, SASMODELS_DIR) 8 7 … … 62 61 calculator = DirectModel(data, model,cutoff=0) 63 62 calculator.pars = pars.copy() 64 calculator.pars.setdefault('background', 0)63 calculator.pars.setdefault('background', 1e-3) 65 64 return calculator 66 65 … … 232 231 # = F2/total_volume 233 232 IQD = F2/average_volume*1e-4*volfraction 234 F1 *= 1e-2 # Yun is using sld in 1/A^2, not 1e-6/A^2235 F2 *= 1e-4236 233 elif norm == 'yun': 237 234 F1 *= 1e-6 # Yun is using sld in 1/A^2, not 1e-6/A^2 … … 339 336 I = build_model(Pname+"@hardsphere", q) 340 337 Pq = P(**Ppars)*pars.get('volfraction', 1) 341 Sq = S(**Spars)338 #Sq = S(**Spars) 342 339 Iq = I(**Ipars) 343 340 #Iq = Pq*Sq*pars.get('volfraction', 1) 344 #Sq = Iq/Pq 345 #Iq = None#= Sq = None 346 r=I._kernel.results 347 return Theory(Q=q, F1=None, F2=None, P=Pq, S=None, I=None, Seff=r[1], Ibeta=Iq) 341 Sq = Iq/Pq 342 return Theory(Q=q, F1=None, F2=None, P=Pq, S=Sq, I=Iq, Seff=None, Ibeta=None) 348 343 349 344 def compare(title, target, actual, fields='F1 F2 P S I Seff Ibeta'): … … 405 400 radius_equatorial_pd=.1, radius_equatorial_pd_type=pd_type, 406 401 volfraction=0.15, 407 radius_effective=270.7543927018,408 402 #radius_effective=12.59921049894873, 409 403 ) 410 target = sasmodels_theory(q, model, beta_mode=1,**pars)404 target = sasmodels_theory(q, model, **pars) 411 405 actual = ellipsoid_pe(q, norm='sasview', **pars) 412 406 title = " ".join(("sasmodels", model, pd_type)) … … 456 450 S = data[5] 457 451 Seff = data[6] 458 target = Theory(Q=Q, F1=F1, P=P, S=S, Seff=Seff)452 target = Theory(Q=Q, F1=F1, F2=F2, P=P, S=S, Seff=Seff) 459 453 actual = sphere_r(Q, norm='yun', **pars) 460 454 title = " ".join(("yun", "sphere", "10% dispersion 10% Vf")) … … 468 462 S = data[5] 469 463 Seff = data[6] 470 target = Theory(Q=Q, F1=F1, P=P, S=S, Seff=Seff)464 target = Theory(Q=Q, F1=F1, F2=F2, P=P, S=S, Seff=Seff) 471 465 actual = sphere_r(Q, norm='yun', **pars) 472 466 title = " ".join(("yun", "sphere", "15% dispersion 10% Vf")) -
sasmodels/core.py
r01c8d9e r3221de0 140 140 used with functions in generate to build the docs or extract model info. 141 141 """ 142 143 142 if "+" in model_string: 144 143 parts = [load_model_info(part) … … 206 205 207 206 numpy_dtype, fast, platform = parse_dtype(model_info, dtype, platform) 207 208 208 source = generate.make_source(model_info) 209 209 if platform == "dll": … … 265 265 # Assign default platform, overriding ocl with dll if OpenCL is unavailable 266 266 # If opencl=False OpenCL is switched off 267 267 268 if platform is None: 268 269 platform = "ocl" … … 290 291 else: 291 292 numpy_dtype = np.dtype(dtype) 293 292 294 # Make sure that the type is supported by opencl, otherwise use dll 293 295 if platform == "ocl": -
sasmodels/data.py
r01c8d9e r65fbf7c 329 329 else: 330 330 dq = resolution * q 331 331 332 data = Data1D(q, Iq, dx=dq, dy=dIq) 332 333 data.filename = "fake data" … … 522 523 else 'log') 523 524 plt.xscale(xscale) 524 525 525 plt.xlabel("$q$/A$^{-1}$") 526 526 plt.yscale(yscale) -
sasmodels/generate.py
r01c8d9e rd86f0fc 672 672 673 673 # type in IQXY pattern could be single, float, double, long double, ... 674 _IQXY_PATTERN = re.compile(r"(^|\s)double\s+I(?P<mode>q(a c|abc|xy))\s*[(]",674 _IQXY_PATTERN = re.compile(r"(^|\s)double\s+I(?P<mode>q(ab?c|xy))\s*[(]", 675 675 flags=re.MULTILINE) 676 676 def find_xy_mode(source): … … 701 701 return 'qa' 702 702 703 # type in IQXY pattern could be single, float, double, long double, ...704 _FQ_PATTERN = re.compile(r"(^|\s)void\s+Fq[(]", flags=re.MULTILINE)705 def has_Fq(source):706 for code in source:707 m = _FQ_PATTERN.search(code)708 if m is not None:709 return True710 return False711 703 712 704 def _add_source(source, code, path, lineno=1): … … 738 730 # dispersion. Need to be careful that necessary parameters are available 739 731 # for computing volume even if we allow non-disperse volume parameters. 732 740 733 partable = model_info.parameters 734 741 735 # Load templates and user code 742 736 kernel_header = load_template('kernel_header.c') 743 737 kernel_code = load_template('kernel_iq.c') 744 738 user_code = [(f, open(f).read()) for f in model_sources(model_info)] 739 745 740 # Build initial sources 746 741 source = [] … … 748 743 for path, code in user_code: 749 744 _add_source(source, code, path) 745 750 746 if model_info.c_code: 751 747 _add_source(source, model_info.c_code, model_info.filename, … … 793 789 source.append("\\\n".join(p.as_definition() 794 790 for p in partable.kernel_parameters)) 791 795 792 # Define the function calls 796 793 if partable.form_volume_parameters: … … 803 800 call_volume = "#define CALL_VOLUME(v) 1.0" 804 801 source.append(call_volume) 802 805 803 model_refs = _call_pars("_v.", partable.iq_parameters) 806 #create varaible BETA to turn on and off beta approximation 807 BETA = has_Fq(source) 808 if not BETA: 809 pars = ",".join(["_q"] + model_refs) 810 call_iq = "#define CALL_IQ(_q, _v) Iq(%s)" % pars 811 else: 812 pars = ",".join(["_q", "&_F1", "&_F2",] + model_refs) 813 call_iq = "#define CALL_IQ(_q, _F1, _F2, _v) Fq(%s)" % pars 804 pars = ",".join(["_q"] + model_refs) 805 call_iq = "#define CALL_IQ(_q, _v) Iq(%s)" % pars 814 806 if xy_mode == 'qabc': 815 807 pars = ",".join(["_qa", "_qb", "_qc"] + model_refs) … … 839 831 magpars = [k-2 for k, p in enumerate(partable.call_parameters) 840 832 if p.type == 'sld'] 833 841 834 # Fill in definitions for numbers of parameters 842 source.append("#define BETA %d" %(1 if BETA else 0))843 835 source.append("#define MAX_PD %s"%partable.max_pd) 844 836 source.append("#define NUM_PARS %d"%partable.npars) … … 847 839 source.append("#define MAGNETIC_PARS %s"%",".join(str(k) for k in magpars)) 848 840 source.append("#define PROJECTION %d"%PROJECTION) 841 849 842 # TODO: allow mixed python/opencl kernels? 843 850 844 ocl = _kernels(kernel_code, call_iq, call_iqxy, clear_iqxy, model_info.name) 851 845 dll = _kernels(kernel_code, call_iq, call_iqxy, clear_iqxy, model_info.name) 852 853 846 result = { 854 847 'dll': '\n'.join(source+dll[0]+dll[1]+dll[2]), 855 848 'opencl': '\n'.join(source+ocl[0]+ocl[1]+ocl[2]), 856 849 } 857 #print(result['dll']) 850 858 851 return result 859 852 … … 1075 1068 model_info = make_model_info(kernel_module) 1076 1069 source = make_source(model_info) 1077 #print(source['dll'])1070 print(source['dll']) 1078 1071 1079 1072 -
sasmodels/kernel_iq.c
r01c8d9e r7c35fda 36 36 // PROJECTION : equirectangular=1, sinusoidal=2 37 37 // see explore/jitter.py for definitions. 38 39 38 40 39 #ifndef _PAR_BLOCK_ // protected block so we can include this code twice. … … 271 270 #endif // _QABC_SECTION 272 271 272 273 273 // ==================== KERNEL CODE ======================== 274 274 275 kernel 275 276 void KERNEL_NAME( … … 338 339 // The code differs slightly between opencl and dll since opencl is only 339 340 // seeing one q value (stored in the variable "this_result") while the dll 340 // version must loop over all q 341 #if BETA 342 double *beta_result = &(result[nq+1]); // = result + nq + 1 343 double weight_norm = (pd_start == 0 ? 0.0 : result[2*nq+1]); 344 #endif 341 // version must loop over all q. 345 342 #ifdef USE_OPENCL 346 343 double pd_norm = (pd_start == 0 ? 0.0 : result[nq]); 347 344 double this_result = (pd_start == 0 ? 0.0 : result[q_index]); 348 #if BETA349 double this_beta_result = (pd_start == 0 ? 0.0 : result[nq + q_index];350 345 #else // !USE_OPENCL 351 double pd_norm = (pd_start == 0 ? 0.0 : result[nq]); 346 double pd_norm = (pd_start == 0 ? 0.0 : result[nq]); 352 347 if (pd_start == 0) { 353 348 #ifdef USE_OPENMP … … 355 350 #endif 356 351 for (int q_index=0; q_index < nq; q_index++) result[q_index] = 0.0; 357 #if BETA358 for (int q_index=0; q_index < nq; q_index++) beta_result[q_index] = 0.0;359 #endif360 352 } 361 353 //if (q_index==0) printf("start %d %g %g\n", pd_start, pd_norm, result[0]); 362 354 #endif // !USE_OPENCL 363 364 365 366 355 367 356 … … 453 442 // inner loop and defines the macros that use them. 454 443 455 456 444 #if defined(CALL_IQ) 457 445 // unoriented 1D 458 446 double qk; 459 #if BETA == 0 460 #define FETCH_Q() do { qk = q[q_index]; } while (0) 461 #define BUILD_ROTATION() do {} while(0) 462 #define APPLY_ROTATION() do {} while(0) 463 #define CALL_KERNEL() CALL_IQ(qk,local_values.table) 464 465 // unoriented 1D Beta 466 #elif BETA == 1 467 double F1, F2; 468 #define FETCH_Q() do { qk = q[q_index]; } while (0) 469 #define BUILD_ROTATION() do {} while(0) 470 #define APPLY_ROTATION() do {} while(0) 471 #define CALL_KERNEL() CALL_IQ(qk,F1,F2,local_values.table) 472 #endif 447 #define FETCH_Q() do { qk = q[q_index]; } while (0) 448 #define BUILD_ROTATION() do {} while(0) 449 #define APPLY_ROTATION() do {} while(0) 450 #define CALL_KERNEL() CALL_IQ(qk, local_values.table) 473 451 474 452 #elif defined(CALL_IQ_A) … … 669 647 pd_norm += weight * CALL_VOLUME(local_values.table); 670 648 BUILD_ROTATION(); 671 #if BETA 672 if (weight > cutoff) { 673 weight_norm += weight;} 674 #endif 649 675 650 #ifndef USE_OPENCL 676 651 // DLL needs to explicitly loop over the q values. … … 718 693 } 719 694 #else // !MAGNETIC 720 #if defined(CALL_IQ) && BETA == 1 721 CALL_KERNEL(); 722 const double scatteringF1 = F1; 723 const double scatteringF2 = F2; 724 #else 725 const double scattering = CALL_KERNEL(); 726 #endif 695 const double scattering = CALL_KERNEL(); 727 696 #endif // !MAGNETIC 728 697 //printf("q_index:%d %g %g %g %g\n", q_index, scattering, weight0); 729 698 730 699 #ifdef USE_OPENCL 731 #if defined(CALL_IQ)&& BETA == 1 732 this_result += weight * scatteringF2; 733 this_beta_result += weight * scatteringF1; 734 #else 735 this_result += weight * scattering; 736 #endif 700 this_result += weight * scattering; 737 701 #else // !USE_OPENCL 738 #if defined(CALL_IQ)&& BETA == 1 739 result[q_index] += weight * scatteringF2; 740 beta_result[q_index] += weight * scatteringF1; 741 #endif 742 #else 743 result[q_index] += weight * scattering; 744 #endif 702 result[q_index] += weight * scattering; 745 703 #endif // !USE_OPENCL 746 704 } 747 705 } 748 706 } 707 749 708 // close nested loops 750 709 ++step; … … 769 728 result[q_index] = this_result; 770 729 if (q_index == 0) result[nq] = pd_norm; 771 #if BETA772 beta_result[q_index] = this_beta_result;773 #endif774 if (q_index == 0) result[nq] = pd_norm;775 776 730 //if (q_index == 0) printf("res: %g/%g\n", result[0], pd_norm); 777 731 #else // !USE_OPENCL 778 732 result[nq] = pd_norm; 779 #if BETA780 result[2*nq+1] = weight_norm;781 #endif782 733 //printf("res: %g/%g\n", result[0], pd_norm); 783 734 #endif // !USE_OPENCL -
sasmodels/kernelcl.py
r01c8d9e rd86f0fc 420 420 if self.program is None: 421 421 compile_program = environment().compile_program 422 with open('model.c','w') as fid:423 print(self.source['opencl'], file=fid)424 422 timestamp = generate.ocl_timestamp(self.info) 425 423 self.program = compile_program( … … 541 539 self.dim = '2d' if q_input.is_2d else '1d' 542 540 # plus three for the normalization values 543 self.result = np.empty( 2*q_input.nq+2,dtype)541 self.result = np.empty(q_input.nq+1, dtype) 544 542 545 543 # Inputs and outputs for each kernel call … … 557 555 else np.float16 if dtype == generate.F16 558 556 else np.float32) # will never get here, so use np.float32 559 __call__= Iq 560 561 def Iq(self, call_details, values, cutoff, magnetic): 557 558 def __call__(self, call_details, values, cutoff, magnetic): 562 559 # type: (CallDetails, np.ndarray, np.ndarray, float, bool) -> np.ndarray 563 560 context = self.queue.context … … 575 572 ] 576 573 #print("Calling OpenCL") 577 call_details.show(values)578 # Call kernel and retrieve results574 #call_details.show(values) 575 # Call kernel and retrieve results 579 576 wait_for = None 580 577 last_nap = time.clock() … … 607 604 return scale*self.result[:self.q_input.nq] + background 608 605 # return self.result[:self.q_input.nq] 609 #NEEDS TO BE FINISHED FOR OPENCL610 def beta():611 return 0612 606 613 607 def release(self): -
sasmodels/kerneldll.py
r01c8d9e r33969b6 258 258 # Note: if there is a syntax error then compile raises an error 259 259 # and the source file will not be deleted. 260 #os.unlink(filename)261 print("saving compiled file in %r"%filename)260 os.unlink(filename) 261 #print("saving compiled file in %r"%filename) 262 262 return dll 263 263 … … 371 371 def __init__(self, kernel, model_info, q_input): 372 372 # type: (Callable[[], np.ndarray], ModelInfo, PyInput) -> None 373 #,model_info,q_input)374 373 self.kernel = kernel 375 374 self.info = model_info … … 377 376 self.dtype = q_input.dtype 378 377 self.dim = '2d' if q_input.is_2d else '1d' 379 self.result = np.empty( 2*q_input.nq+2, q_input.dtype)378 self.result = np.empty(q_input.nq+1, q_input.dtype) 380 379 self.real = (np.float32 if self.q_input.dtype == generate.F32 381 380 else np.float64 if self.q_input.dtype == generate.F64 382 381 else np.float128) 383 382 384 def Iq(self, call_details, values, cutoff, magnetic):383 def __call__(self, call_details, values, cutoff, magnetic): 385 384 # type: (CallDetails, np.ndarray, np.ndarray, float, bool) -> np.ndarray 386 self._call_kernel(call_details, values, cutoff, magnetic) 385 386 kernel = self.kernel[1 if magnetic else 0] 387 args = [ 388 self.q_input.nq, # nq 389 None, # pd_start 390 None, # pd_stop pd_stride[MAX_PD] 391 call_details.buffer.ctypes.data, # problem 392 values.ctypes.data, #pars 393 self.q_input.q.ctypes.data, #q 394 self.result.ctypes.data, # results 395 self.real(cutoff), # cutoff 396 ] 397 #print("Calling DLL") 398 #call_details.show(values) 399 step = 100 400 for start in range(0, call_details.num_eval, step): 401 stop = min(start + step, call_details.num_eval) 402 args[1:3] = [start, stop] 403 kernel(*args) # type: ignore 404 387 405 #print("returned",self.q_input.q, self.result) 388 406 pd_norm = self.result[self.q_input.nq] … … 391 409 #print("scale",scale,background) 392 410 return scale*self.result[:self.q_input.nq] + background 393 __call__ = Iq394 395 def beta(self, call_details, values, cutoff, magnetic):396 # type: (CallDetails, np.ndarray, np.ndarray, float, bool) -> np.ndarray397 self._call_kernel(call_details, values, cutoff, magnetic)398 w_norm = self.result[2*self.q_input.nq + 1]399 pd_norm = self.result[self.q_input.nq]400 if w_norm == 0.:401 w_norm = 1.402 F2 = self.result[:self.q_input.nq]/w_norm403 F1 = self.result[self.q_input.nq+1:2*self.q_input.nq+1]/w_norm404 volume_avg = pd_norm/w_norm405 return F1, F2, volume_avg406 407 def _call_kernel(self, call_details, values, cutoff, magnetic):408 kernel = self.kernel[1 if magnetic else 0]409 args = [410 self.q_input.nq, # nq411 None, # pd_start412 None, # pd_stop pd_stride[MAX_PD]413 call_details.buffer.ctypes.data, # problem414 values.ctypes.data, # pars415 self.q_input.q.ctypes.data, # q416 self.result.ctypes.data, # results417 self.real(cutoff), # cutoff418 ]419 #print(self.beta_result.ctypes.data)420 # print("Calling DLL line 397")421 # print("values", values)422 #call_details.show(values)423 step = 100424 for start in range(0, call_details.num_eval, step):425 stop = min(start + step, call_details.num_eval)426 args[1:3] = [start, stop]427 kernel(*args) # type: ignore428 411 429 412 def release(self): -
sasmodels/modelinfo.py
r01c8d9e r95498a3 163 163 parameter.length = length 164 164 parameter.length_control = control 165 165 166 return parameter 166 167 … … 417 418 # scale and background are implicit parameters 418 419 COMMON = [Parameter(*p) for p in COMMON_PARAMETERS] 420 419 421 def __init__(self, parameters): 420 422 # type: (List[Parameter]) -> None 421 423 self.kernel_parameters = parameters 422 424 self._set_vector_lengths() 425 423 426 self.npars = sum(p.length for p in self.kernel_parameters) 424 427 self.nmagnetic = sum(p.length for p in self.kernel_parameters … … 427 430 if self.nmagnetic: 428 431 self.nvalues += 3 + 3*self.nmagnetic 432 429 433 self.call_parameters = self._get_call_parameters() 430 434 self.defaults = self._get_defaults() … … 440 444 self.form_volume_parameters = [p for p in self.kernel_parameters 441 445 if p.type == 'volume'] 446 442 447 # Theta offset 443 448 offset = 0 … … 461 466 self.magnetism_index = [k for k, p in enumerate(self.call_parameters) 462 467 if p.id.startswith('M0:')] 468 463 469 self.pd_1d = set(p.name for p in self.call_parameters 464 470 if p.polydisperse and p.type not in ('orientation', 'magnetic')) … … 764 770 # Custom sum/multi models 765 771 return kernel_module.model_info 766 767 772 info = ModelInfo() 768 773 #print("make parameter table", kernel_module.parameters) … … 817 822 info.lineno = {} 818 823 _find_source_lines(info, kernel_module) 824 819 825 return info 820 826 -
sasmodels/models/ellipsoid.c
r01c8d9e r108e70e 20 20 // i(h) = int_0^1 Phi^2(h a sqrt(1 + u^2(v^2-1)) du 21 21 const double v_square_minus_one = square(radius_polar/radius_equatorial) - 1.0; 22 22 23 23 // translate a point in [-1,1] to a point in [0, 1] 24 24 // const double u = GAUSS_Z[i]*(upper-lower)/2 + (upper+lower)/2; … … 36 36 const double s = (sld - sld_solvent) * form_volume(radius_polar, radius_equatorial); 37 37 return 1.0e-4 * s * s * form; 38 }39 40 static void41 Fq(double q,42 double *F1,43 double *F2,44 double sld,45 double sld_solvent,46 double radius_polar,47 double radius_equatorial)48 {49 // Using ratio v = Rp/Re, we can implement the form given in Guinier (1955)50 // i(h) = int_0^pi/2 Phi^2(h a sqrt(cos^2 + v^2 sin^2) cos dT51 // = int_0^pi/2 Phi^2(h a sqrt((1-sin^2) + v^2 sin^2) cos dT52 // = int_0^pi/2 Phi^2(h a sqrt(1 + sin^2(v^2-1)) cos dT53 // u-substitution of54 // u = sin, du = cos dT55 // i(h) = int_0^1 Phi^2(h a sqrt(1 + u^2(v^2-1)) du56 const double v_square_minus_one = square(radius_polar/radius_equatorial) - 1.0;57 // translate a point in [-1,1] to a point in [0, 1]58 // const double u = GAUSS_Z[i]*(upper-lower)/2 + (upper+lower)/2;59 const double zm = 0.5;60 const double zb = 0.5;61 double total_F2 = 0.0;62 double total_F1 = 0.0;63 for (int i=0;i<GAUSS_N;i++) {64 const double u = GAUSS_Z[i]*zm + zb;65 const double r = radius_equatorial*sqrt(1.0 + u*u*v_square_minus_one);66 const double f = sas_3j1x_x(q*r);67 total_F2 += GAUSS_W[i] * f * f;68 total_F1 += GAUSS_W[i] * f;69 }70 // translate dx in [-1,1] to dx in [lower,upper]71 const double form_squared_avg = total_F2*zm;72 const double form_avg = total_F1*zm;73 const double s = (sld - sld_solvent) * form_volume(radius_polar, radius_equatorial);74 *F2 = 1e-4 * s * s * form_squared_avg;75 *F1 = 1e-2 * s * form_avg;76 38 } 77 78 79 80 81 82 39 83 40 static double -
sasmodels/models/lib/sphere_form.c
r01c8d9e r925ad6e 13 13 return 1.0e-4*square(contrast * fq); 14 14 } 15 -
sasmodels/models/sphere.py
r01c8d9e ref07e95 67 67 ] 68 68 69 source = ["lib/sas_3j1x_x.c", "lib/sphere_form.c" , "sphere.c"]69 source = ["lib/sas_3j1x_x.c", "lib/sphere_form.c"] 70 70 71 # No volume normalization despite having a volume parameter 72 # This should perhaps be volume normalized? 73 form_volume = """ 74 return sphere_volume(radius); 75 """ 76 77 Iq = """ 78 return sphere_form(q, radius, sld, sld_solvent); 79 """ 71 80 72 81 def ER(radius): -
sasmodels/product.py
r01c8d9e r2d81cfe 16 16 import numpy as np # type: ignore 17 17 18 from .modelinfo import ParameterTable, ModelInfo , Parameter18 from .modelinfo import ParameterTable, ModelInfo 19 19 from .kernel import KernelModel, Kernel 20 20 from .details import make_details, dispersion_mesh … … 74 74 translate_name = dict((old.id, new.id) for old, new 75 75 in zip(s_pars.kernel_parameters[1:], s_list)) 76 beta_parameter = Parameter("beta_mode", "", 0, [["P*S"],["P*(1+beta*(S-1))"], "", "Structure factor dispersion calculation mode"]) 77 combined_pars = p_pars.kernel_parameters + s_list + [beta_parameter] 76 combined_pars = p_pars.kernel_parameters + s_list 78 77 parameters = ParameterTable(combined_pars) 79 78 parameters.max_pd = p_pars.max_pd + s_pars.max_pd … … 152 151 #: Structure factor modelling interaction between particles. 153 152 self.S = S 154 155 153 #: Model precision. This is not really relevant, since it is the 156 154 #: individual P and S models that control the effective dtype, … … 170 168 # in opencl; or both in opencl, but one in single precision and the 171 169 # other in double precision). 172 173 170 p_kernel = self.P.make_kernel(q_vectors) 174 171 s_kernel = self.S.make_kernel(q_vectors) … … 196 193 # type: (CallDetails, np.ndarray, float, bool) -> np.ndarray 197 194 p_info, s_info = self.info.composition[1] 195 198 196 # if there are magnetic parameters, they will only be on the 199 197 # form factor P, not the structure factor S. … … 207 205 nweights = call_details.num_weights 208 206 weights = values[nvalues:nvalues + 2*nweights] 207 209 208 # Construct the calling parameters for P. 210 209 p_npars = p_info.parameters.npars … … 219 218 p_values.append([0.]*spacer) 220 219 p_values = np.hstack(p_values).astype(self.p_kernel.dtype) 220 221 221 # Call ER and VR for P since these are needed for S. 222 222 p_er, p_vr = calc_er_vr(p_info, p_details, p_values) 223 223 s_vr = (volfrac/p_vr if p_vr != 0. else volfrac) 224 224 #print("volfrac:%g p_er:%g p_vr:%g s_vr:%g"%(volfrac,p_er,p_vr,s_vr)) 225 225 226 # Construct the calling parameters for S. 226 227 # The effective radius is not in the combined parameter list, so … … 252 253 s_values.append([0.]*spacer) 253 254 s_values = np.hstack(s_values).astype(self.s_kernel.dtype) 254 # beta mode is the first parameter after the structure factor pars 255 beta_index = 2+p_npars+s_npars 256 beta_mode = values[beta_index] 255 257 256 # Call the kernels 258 if beta_mode: # beta: 259 F1, F2, volume_avg = self.p_kernel.beta(p_details, p_values, cutoff, magnetic) 260 else: 261 p_result = self.p_kernel.Iq(p_details, p_values, cutoff, magnetic) 262 s_result = self.s_kernel.Iq(s_details, s_values, cutoff, False) 257 p_result = self.p_kernel(p_details, p_values, cutoff, magnetic) 258 s_result = self.s_kernel(s_details, s_values, cutoff, False) 259 263 260 #print("p_npars",p_npars,s_npars,p_er,s_vr,values[2+p_npars+1:2+p_npars+s_npars]) 264 261 #call_details.show(values) … … 268 265 #s_details.show(s_values) 269 266 #print("=>", s_result) 267 268 # remember the parts for plotting later 269 self.results = [p_result, s_result] 270 270 271 #import pylab as plt 271 272 #plt.subplot(211); plt.loglog(self.p_kernel.q_input.q, p_result, '-') 272 273 #plt.subplot(212); plt.loglog(self.s_kernel.q_input.q, s_result, '-') 273 274 #plt.figure() 274 if beta_mode:#beta 275 beta_factor = F1**2/F2 276 Sq_eff = 1+beta_factor*(s_result - 1) 277 self.results = [F2, Sq_eff,F1,s_result] 278 final_result = volfrac*values[0]*(F2 + (F1**2)*(s_result - 1))/volume_avg+values[1] 279 #final_result = volfrac * values[0] * F2 * Sq_eff / volume_avg + values[1] 280 else: 281 # remember the parts for plotting later 282 self.results = [p_result, s_result] 283 final_result = values[0]*(p_result*s_result) + values[1] 284 return final_result 275 276 return values[0]*(p_result*s_result) + values[1] 285 277 286 278 def release(self):
Note: See TracChangeset
for help on using the changeset viewer.