Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/models/hollow_rectangular_prism_thin_walls.c

    ra807206 rab2aea8  
    22double Iq(double q, double sld, double solvent_sld, double length_a,  
    33          double b2a_ratio, double c2a_ratio); 
    4 double Iqxy(double qx, double qy, double sld, double solvent_sld,  
    5             double length_a, double b2a_ratio, double c2a_ratio); 
    64 
    75double form_volume(double length_a, double b2a_ratio, double c2a_ratio) 
    86{ 
    9     double b_side = length_a * b2a_ratio; 
    10     double c_side = length_a * c2a_ratio; 
    11     double vol_shell = 2.0 * (length_a*b_side + length_a*c_side + b_side*c_side); 
     7    double length_b = length_a * b2a_ratio; 
     8    double length_c = length_a * c2a_ratio; 
     9    double vol_shell = 2.0 * (length_a*length_b + length_a*length_c + length_b*length_c); 
    1210    return vol_shell; 
    1311} 
     
    2018    double c2a_ratio) 
    2119{ 
    22     double b_side = length_a * b2a_ratio; 
    23     double c_side = length_a * c2a_ratio; 
    24     double a_half = 0.5 * length_a; 
    25     double b_half = 0.5 * b_side; 
    26     double c_half = 0.5 * c_side; 
     20    const double length_b = length_a * b2a_ratio; 
     21    const double length_c = length_a * c2a_ratio; 
     22    const double a_half = 0.5 * length_a; 
     23    const double b_half = 0.5 * length_b; 
     24    const double c_half = 0.5 * length_c; 
    2725 
    2826   //Integration limits to use in Gaussian quadrature 
    29     double v1a = 0.0; 
    30     double v1b = 0.5 * M_PI;  //theta integration limits 
    31     double v2a = 0.0; 
    32     double v2b = 0.5 * M_PI;  //phi integration limits 
     27    const double v1a = 0.0; 
     28    const double v1b = M_PI_2;  //theta integration limits 
     29    const double v2a = 0.0; 
     30    const double v2b = M_PI_2;  //phi integration limits 
    3331     
    34     //Order of integration 
    35     int nordi=76;                                
    36     int nordj=76; 
     32    double outer_sum = 0.0; 
     33    for(int i=0; i<76; i++) { 
     34        const double theta = 0.5 * ( Gauss76Z[i]*(v1b-v1a) + v1a + v1b ); 
    3735 
    38     double sumi = 0.0; 
    39      
    40     for(int i=0; i<nordi; i++) { 
     36        double sin_theta, cos_theta; 
     37        double sin_c, cos_c; 
     38        SINCOS(theta, sin_theta, cos_theta); 
     39        SINCOS(q*c_half*cos_theta, sin_c, cos_c); 
    4140 
    42             double theta = 0.5 * ( Gauss76Z[i]*(v1b-v1a) + v1a + v1b );  
    43          
    4441        // To check potential problems if denominator goes to zero here !!! 
    45         double termAL_theta = 8.0*cos(q*c_half*cos(theta)) / (q*q*sin(theta)*sin(theta)); 
    46         double termAT_theta = 8.0*sin(q*c_half*cos(theta)) / (q*q*sin(theta)*cos(theta)); 
     42        const double termAL_theta = 8.0 * cos_c / (q*q*sin_theta*sin_theta); 
     43        const double termAT_theta = 8.0 * sin_c / (q*q*sin_theta*cos_theta); 
    4744 
    48             double sumj = 0.0; 
    49          
    50             for(int j=0; j<nordj; j++) { 
     45        double inner_sum = 0.0; 
     46        for(int j=0; j<76; j++) { 
     47            const double phi = 0.5 * ( Gauss76Z[j]*(v2b-v2a) + v2a + v2b ); 
    5148 
    52             double phi = 0.5 * ( Gauss76Z[j]*(v2b-v2a) + v2a + v2b );  
    53              
     49            double sin_phi, cos_phi; 
     50            double sin_a, cos_a; 
     51            double sin_b, cos_b; 
     52            SINCOS(phi, sin_phi, cos_phi); 
     53            SINCOS(q*a_half*sin_theta*sin_phi, sin_a, cos_a); 
     54            SINCOS(q*b_half*sin_theta*cos_phi, sin_b, cos_b); 
     55 
    5456            // Amplitude AL from eqn. (7c) 
    55             double AL = termAL_theta * sin(q*a_half*sin(theta)*sin(phi)) *  
    56                 sin(q*b_half*sin(theta)*cos(phi)) / (sin(phi)*cos(phi)); 
     57            const double AL = termAL_theta 
     58                * sin_a*sin_b / (sin_phi*cos_phi); 
    5759 
    5860            // Amplitude AT from eqn. (9) 
    59             double AT = termAT_theta * (  (cos(q*a_half*sin(theta)*sin(phi))*sin(q*b_half*sin(theta)*cos(phi))/cos(phi))  
    60                 + (cos(q*b_half*sin(theta)*cos(phi))*sin(q*a_half*sin(theta)*sin(phi))/sin(phi)) ); 
     61            const double AT = termAT_theta 
     62                * ( cos_a*sin_b/cos_phi + cos_b*sin_a/sin_phi ); 
    6163 
    62             sumj += Gauss76Wt[j] * (AL+AT)*(AL+AT); 
     64            inner_sum += Gauss76Wt[j] * square(AL+AT); 
     65        } 
    6366 
    64             } 
    65  
    66             sumj = 0.5 * (v2b-v2a) * sumj; 
    67             sumi += Gauss76Wt[i] * sumj * sin(theta); 
    68  
     67        inner_sum *= 0.5 * (v2b-v2a); 
     68        outer_sum += Gauss76Wt[i] * inner_sum * sin_theta; 
    6969    } 
    7070 
    71     double answer = 0.5*(v1b-v1a)*sumi; 
     71    outer_sum *= 0.5*(v1b-v1a); 
    7272 
    7373    // Normalize as in Eqn. (15) without the volume factor (as cancels with (V*DelRho)^2 normalization) 
    7474    // The factor 2 is due to the different theta integration limit (pi/2 instead of pi) 
    75     answer *= (2.0/M_PI); 
     75    double answer = outer_sum/M_PI_2; 
    7676 
    7777    // Multiply by contrast^2. Factor corresponding to volume^2 cancels with previous normalization. 
    78     answer *= (sld-solvent_sld)*(sld-solvent_sld); 
     78    answer *= square(sld-solvent_sld); 
    7979 
    8080    // Convert from [1e-12 A-1] to [cm-1] 
     
    8282 
    8383    return answer; 
    84      
    8584} 
    86  
    87 double Iqxy(double qx, double qy, 
    88     double sld, 
    89     double solvent_sld, 
    90     double length_a, 
    91     double b2a_ratio, 
    92     double c2a_ratio) 
    93 { 
    94     double q = sqrt(qx*qx + qy*qy); 
    95     double intensity = Iq(q, sld, solvent_sld, length_a, b2a_ratio, c2a_ratio);  
    96     return intensity;     
    97 } 
Note: See TracChangeset for help on using the changeset viewer.