Changeset f4cf580 in sasmodels for sasmodels


Ignore:
Timestamp:
Sep 2, 2014 1:15:40 PM (10 years ago)
Author:
Paul Kienzle <pkienzle@…>
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:
87985ca
Parents:
5d4777d
Message:

resolve remaining differences between sasview and sasmodels

Location:
sasmodels
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/convert.py

    r5d4777d rf4cf580  
    3737        name='sphere', 
    3838        sldSph='sld', sldSolv='solvent_sld', 
    39         #radius='radius',  # DO NOT LIST IDENTICAL PARAMETERS! 
     39        radius='radius',  # listing identical parameters is optional 
    4040        ), 
    4141    } 
     
    5959    newpars = pars.copy() 
    6060    for old,new in mapping.items(): 
     61        if old == new: continue 
    6162        # Bumps style parameter names 
    6263        for variant in ("", "_pd", "_pd_n", "_pd_nsigma", "_pd_type"): 
  • sasmodels/gen.py

    r5d4777d rf4cf580  
    352352  const real I = %(fn)s(%(qcall)s, %(pcall)s); 
    353353  if (I>=REAL(0.0)) { // scattering cannot be negative 
    354     ret += weight*I; 
     354    ret += weight*I%(sasview_spherical)s; 
    355355    norm += weight; 
    356356    %(volume_norm)s 
     
    364364SPHERICAL_CORRECTION="""\ 
    365365// Correction factor for spherical integration p(theta) I(q) sin(theta) dtheta 
    366 real spherical_correction = (Ntheta>1 ? fabs(cos(M_PI_180*phi)) : REAL(1.0));\ 
     366real spherical_correction = (Ntheta>1 ? fabs(sin(M_PI_180*theta)) : REAL(1.0));\ 
     367""" 
     368# Use this to reproduce sasview behaviour 
     369SASVIEW_SPHERICAL_CORRECTION="""\ 
     370// Correction factor for spherical integration p(theta) I(q) sin(theta) dtheta 
     371real spherical_correction = (Ntheta>1 ? fabs(cos(M_PI_180*theta))*M_PI_2 : REAL(1.0));\ 
    367372""" 
    368373 
     
    472477    fq_pars = [p[0] for p in info['parameters'][len(COMMON_PARAMETERS):] 
    473478               if p[0] in set(fixed_pars+pd_pars)] 
    474     if False and "phi" in pd_pars: 
     479    if False and "theta" in pd_pars: 
    475480        spherical_correction = [indent(SPHERICAL_CORRECTION, depth)] 
    476481        weights = [p+"_w" for p in pd_pars]+['spherical_correction'] 
     482        sasview_spherical = "" 
     483    elif "theta" in pd_pars: 
     484        spherical_correction = [indent(SASVIEW_SPHERICAL_CORRECTION,depth)] 
     485        weights = [p+"_w" for p in pd_pars] 
     486        sasview_spherical = "*spherical_correction" 
    477487    else: 
    478488        spherical_correction = [] 
    479489        weights = [p+"_w" for p in pd_pars] 
     490        sasview_spherical = "" 
    480491    subst = { 
    481492        'weight_product': "*".join(weights), 
     
    484495        'qcall': q_pars['qcall'], 
    485496        'pcall': ", ".join(fq_pars), # skip scale and background 
     497        'sasview_spherical': sasview_spherical, 
    486498        } 
    487499    loop_body = [indent(LOOP_BODY%subst, depth)] 
  • sasmodels/gpu.py

    r5d4777d rf4cf580  
    2222devices, where it can be combined with other structure factors and form 
    2323factors and have instrumental resolution effects applied. 
    24  
    25  
    2624""" 
    2725import numpy as np 
     
    5957    source, info = gen.make(kernel_module) 
    6058    ## for debugging, save source to a .cl file, edit it, and reload as model 
    61     open(info['name']+'.cl','w').write(source) 
     59    #open(info['name']+'.cl','w').write(source) 
    6260    #source = open(info['name']+'.cl','r').read() 
    6361    return GpuModel(source, info, dtype) 
  • sasmodels/models/capped_cylinder.c

    r5d4777d rf4cf580  
    2222    const real upper = REAL(1.0); 
    2323    const real lower = h/cap_radius; // integral lower bound 
    24     const real m = q*cos_alpha*cap_radius; // cos argument slope 
    25     const real b = q*cos_alpha*(REAL(0.5)*length-h); // cos argument intercept 
    26     const real qrst = q*sin_alpha*cap_radius; // Q*R*sin(theta) 
     24    // cos term in integral is: 
     25    //    cos (q (R t - h + L/2) cos(alpha)) 
     26    // so turn it into: 
     27    //    cos (m t + b) 
     28    // where: 
     29    //    m = q R cos(alpha) 
     30    //    b = q(L/2-h) cos(alpha) 
     31    const real m = q*cap_radius*cos_alpha; // cos argument slope 
     32    const real b = q*(REAL(0.5)*length-h)*cos_alpha; // cos argument intercept 
     33    const real qrst = q*cap_radius*sin_alpha; // Q*R*sin(theta) 
    2734    real total = REAL(0.0); 
    2835    for (int i=0; i<76 ;i++) { 
     
    3138        const real t = REAL(0.5)*(Gauss76Z[i]*(upper-lower)+upper+lower); 
    3239        const real radical = REAL(1.0) - t*t; 
    33         const real caparg = qrst*sqrt(radical); // cap bessel function arg 
    34         const real be = (caparg == REAL(0.0) ? REAL(0.5) : J1(caparg)/caparg); 
     40        const real arg = qrst*sqrt(radical); // cap bessel function arg 
     41        const real be = (arg == REAL(0.0) ? REAL(0.5) : J1(arg)/arg); 
    3542        const real Fq = cos(m*t + b) * radical * be; 
    3643        total += Gauss76Wt[i] * Fq; 
     
    8491        // faster since we don't multiply and divide sin(alpha). 
    8592        const real besarg = q*radius*sn; 
    86         const real siarg = REAL(0.5)*q*length*cn; 
     93        const real siarg = q*REAL(0.5)*length*cn; 
    8794        // lim_{x->0} J1(x)/x = 1/2,   lim_{x->0} sin(x)/x = 1 
    8895        const real bj = (besarg == REAL(0.0) ? REAL(0.5) : J1(besarg)/besarg); 
     
    131138    const real cap_Fq = _cap_kernel(q, h, cap_radius, length, sn, cn); 
    132139 
    133     // The following is CylKernel() / sin(alpha), but we are doing it in place 
    134     // to avoid sin(alpha)/sin(alpha) for alpha = 0.  It is also a teensy bit 
    135     // faster since we don't multiply and divide sin(alpha). 
    136140    const real besarg = q*radius*sn; 
    137     const real siarg = REAL(0.5)*q*length*cn; 
     141    const real siarg = q*REAL(0.5)*length*cn; 
    138142    // lim_{x->0} J1(x)/x = 1/2,   lim_{x->0} sin(x)/x = 1 
    139143    const real bj = (besarg == REAL(0.0) ? REAL(0.5) : J1(besarg)/besarg); 
  • sasmodels/models/capped_cylinder.py

    r5d4777d rf4cf580  
    11r""" 
    22Calculates the scattering from a cylinder with spherical section end-caps. 
    3 This model simply becomes the `convex_lens`_ when the length of the cylinder 
     3This model simply becomes the a convex lens when the length of the cylinder 
    44$L=0$, that is, a sphereocylinder with end caps that have a radius larger 
    55than that of the cylinder and the center of the end cap radius lies within 
     
    128128    [ "radius", "Ang",  20, [0, inf], "volume", 
    129129      "Cylinder radius" ], 
     130    # TODO: use an expression for cap radius with fixed bounds. 
     131    # The current form requires cap radius R bigger than cylinder radius r. 
     132    # Could instead use R/r in [1,inf], r/R in [0,1], or the angle between 
     133    # cylinder and cap in [0,90].  The problem is similar for the barbell 
     134    # model.  Propose r/R in [0,1] in both cases, with the model specifying 
     135    # cylinder radius in the capped cylinder model and sphere radius in the 
     136    # barbell model.  This leads to the natural value of zero for no cap 
     137    # in the capped cylinder, and zero for no bar in the barbell model.  In 
     138    # both models, one would be a pill. 
    130139    [ "cap_radius", "Ang", 20, [0, inf], "volume", 
    131140      "Cap radius" ], 
  • sasmodels/models/sphere.py

    r5d4777d rf4cf580  
    3030 
    3131Iq = """ 
     32    const real qr = q*radius; 
    3233    real sn, cn; 
    33     const real qr = q*radius; 
    3434    SINCOS(qr, sn, cn); 
    35     const real bes = (qr==REAL(0.0) ? REAL(1.0) : (REAL(3.0)*(sn-qr*cn))/(qr*qr*qr)); 
    36     const real f = bes * (sld - solvent_sld) * form_volume(radius); 
    37     return REAL(1.0e-4)*f*f; 
     35    const real bes = qr==REAL(0.0) ? REAL(1.0) : REAL(3.0)*(sn-qr*cn)/(qr*qr*qr); 
     36    const real fq = bes * (sld - solvent_sld) * form_volume(radius); 
     37    return REAL(1.0e-4)*fq*fq; 
    3838    """ 
    3939 
Note: See TracChangeset for help on using the changeset viewer.