Changeset 0d6e865 in sasmodels for sasmodels/models/cylinder.c


Ignore:
Timestamp:
Oct 11, 2016 11:42:00 AM (8 years ago)
Author:
dirk
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
1fdb555
Parents:
19e7ca7
Message:

Rewriting selected models in spherical coordinates. This fixes ticket #492 for these models.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/models/cylinder.c

    re9b1663d r0d6e865  
    11double form_volume(double radius, double length); 
     2double fq(double q, double sn, double cn,double radius, double length); 
     3double orient_avg_1D(double q, double radius, double length); 
    24double Iq(double q, double sld, double solvent_sld, double radius, double length); 
    35double Iqxy(double qx, double qy, double sld, double solvent_sld, 
     
    1113} 
    1214 
     15double fq(double q, double sn, double cn, double radius, double length) 
     16{ 
     17    // precompute qr and qh to save time in the loop 
     18    const double qr = q*radius; 
     19    const double qh = q*0.5*length;  
     20    return  sas_J1c(qr*sn) * sinc(qh*cn) ; 
     21} 
     22 
     23double orient_avg_1D(double q, double radius, double length) 
     24{ 
     25    // translate a point in [-1,1] to a point in [0, pi/2] 
     26    const double zm = M_PI_4; 
     27    const double zb = M_PI_4;  
     28 
     29    double total = 0.0; 
     30    for (int i=0; i<76 ;i++) { 
     31        const double alpha = Gauss76Z[i]*zm + zb; 
     32        double sn, cn; // slots to hold sincos function output 
     33        // alpha(theta,phi) the projection of the cylinder on the detector plane 
     34        SINCOS(alpha, sn, cn); 
     35        total += Gauss76Wt[i] * fq(q, sn, cn, radius, length)* fq(q, sn, cn, radius, length) * sn; 
     36    } 
     37    // translate dx in [-1,1] to dx in [lower,upper] 
     38    return total*zm; 
     39} 
     40 
    1341double Iq(double q, 
    1442    double sld, 
     
    1745    double length) 
    1846{ 
    19     // precompute qr and qh to save time in the loop 
    20     const double qr = q*radius; 
    21     const double qh = q*0.5*length; 
    22  
    23     // translate a point in [-1,1] to a point in [0, pi/2] 
    24     const double zm = M_PI_4; 
    25     const double zb = M_PI_4; 
    26  
    27     double total = 0.0; 
    28     for (int i=0; i<76 ;i++) { 
    29         const double alpha = Gauss76Z[i]*zm + zb; 
    30         double sn, cn; 
    31         SINCOS(alpha, sn, cn); 
    32         const double fq = sinc(qh*cn) * sas_J1c(qr*sn); 
    33         total += Gauss76Wt[i] * fq*fq * sn; 
    34     } 
    35     // translate dx in [-1,1] to dx in [lower,upper] 
    36     const double form = total*zm; 
    3747    const double s = (sld - solvent_sld) * form_volume(radius, length); 
    38     return 1.0e-4 * s * s * form; 
     48    return 1.0e-4 * s * s * orient_avg_1D(q, radius, length); 
    3949} 
    4050 
     
    5161 
    5262    // Compute angle alpha between q and the cylinder axis 
    53     SINCOS(theta*M_PI_180, sn, cn); 
     63    SINCOS(phi*M_PI_180, sn, cn); 
    5464    const double q = sqrt(qx*qx + qy*qy); 
    55     const double cos_val = (q==0. ? 1.0 : (cn*cos(phi*M_PI_180)*qx + sn*qy)/q); 
     65    const double cos_val = (q==0. ? 1.0 : (cn*qx + sn*qy)*sin(theta*M_PI_180)/q); 
     66 
    5667    const double alpha = acos(cos_val); 
    5768 
    5869    SINCOS(alpha, sn, cn); 
    59     const double fq = sinc(q*0.5*length*cn) * sas_J1c(q*radius*sn); 
    6070    const double s = (sld-solvent_sld) * form_volume(radius, length); 
    61     return 1.0e-4 * square(s * fq); 
     71    return 1.0e-4 * square(s * fq(q, sn, cn, radius, length)); 
    6272} 
Note: See TracChangeset for help on using the changeset viewer.