Changeset 318b5bbb in sasview for sansmodels/src/c_models


Ignore:
Timestamp:
Dec 18, 2012 10:55:24 AM (12 years ago)
Author:
Jae Cho <jhjcho@…>
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
6550b64
Parents:
0203ade
Message:

Added polarization and magnetic stuffs

Location:
sansmodels/src/c_models
Files:
1 added
20 edited

Legend:

Unmodified
Added
Removed
  • sansmodels/src/c_models/barbell.cpp

    re08bd5b r318b5bbb  
    258258 
    259259                                          // Cylinder orientation 
    260                                     const double cyl_x = sin(_theta * pi/180.0) * cos(_phi * pi/180.0); 
    261                                     const double cyl_y = sin(_theta * pi/180.0) * sin(_phi * pi/180.0); 
     260                                    const double cyl_x = cos(_theta * pi/180.0) * cos(_phi * pi/180.0); 
     261                                    const double cyl_y = sin(_theta * pi/180.0); 
    262262 
    263263                                    // Compute the angle btw vector q and the 
     
    291291                                                } 
    292292                                                if (weights_theta.size()>1) { 
    293                                                         _ptvalue *= fabs(sin(weights_theta[l].value*pi/180.0)); 
     293                                                        _ptvalue *= fabs(cos(weights_theta[l].value*pi/180.0)); 
    294294                                                } 
    295295                                                sum += _ptvalue; 
  • sansmodels/src/c_models/bcc.cpp

    re08bd5b r318b5bbb  
    5454 */ 
    5555static double bc_analytical_2D_scaled(BCParameters *pars, double q, double q_x, double q_y) { 
    56   double b3_x, b3_y, b3_z, b1_x, b1_y; 
     56  double b3_x, b3_y, b3_z, b1_x, b1_y, b2_x, b2_y; 
    5757  double q_z; 
    58   double alpha, cos_val_b3, cos_val_b2, cos_val_b1; 
     58  double cos_val_b3, cos_val_b2, cos_val_b1; 
    5959  double a1_dot_q, a2_dot_q,a3_dot_q; 
    6060  double answer; 
     
    8686  ///  instead of against q coordinate(PRB 36(46), 3(6), 1754(3854)) 
    8787    // b3 axis orientation 
    88     b3_x = sin(theta) * cos(phi);//negative sign here??? 
    89     b3_y = sin(theta) * sin(phi); 
    90     b3_z = cos(theta); 
    91     cos_val_b3 =  b3_x*q_x + b3_y*q_y + b3_z*q_z; 
    92  
    93     alpha = acos(cos_val_b3); 
     88    b3_x = cos(theta) * cos(phi); 
     89    b3_y = sin(theta); 
     90    //b3_z = -cos(theta) * sin(phi); 
     91    cos_val_b3 =  b3_x*q_x + b3_y*q_y;// + b3_z*q_z; 
     92 
     93    //alpha = acos(cos_val_b3); 
    9494    // b1 axis orientation 
    95     b1_x = sin(psi); 
    96     b1_y = cos(psi); 
    97   cos_val_b1 = (b1_x*q_x + b1_y*q_y); 
     95    b1_x = -cos(phi)*sin(psi) * sin(theta)+sin(phi)*cos(psi); 
     96    b1_y = sin(psi)*cos(theta); 
     97    cos_val_b1 = b1_x*q_x + b1_y*q_y; 
    9898    // b2 axis orientation 
    99   cos_val_b2 = sin(acos(cos_val_b1)); 
    100   // alpha corrections 
    101   cos_val_b2 *= sin(alpha); 
    102   cos_val_b1 *= sin(alpha); 
    103  
     99    b2_x = -sin(theta)*cos(psi)*cos(phi)-sin(psi)*sin(phi); 
     100        b2_y = cos(theta)*cos(psi); 
     101    cos_val_b2 = b2_x*q_x + b2_y*q_y; 
     102     
     103    // The following test should always pass 
     104    if (fabs(cos_val_b3)>1.0) { 
     105      //printf("bcc_ana_2D: Unexpected error: cos()>1\n"); 
     106      cos_val_b3 = 1.0; 
     107    } 
     108    if (fabs(cos_val_b2)>1.0) { 
     109      //printf("bcc_ana_2D: Unexpected error: cos()>1\n"); 
     110      cos_val_b2 = 1.0; 
     111    } 
     112    if (fabs(cos_val_b1)>1.0) { 
     113      //printf("bcc_ana_2D: Unexpected error: cos()>1\n"); 
     114      cos_val_b1 = 1.0; 
     115    } 
    104116    // Compute the angle btw vector q and the a3 axis 
    105117    a3_dot_q = 0.5*aa*q*(cos_val_b2+cos_val_b1-cos_val_b3); 
     
    111123    a2_dot_q = 0.5*aa*q*(cos_val_b3+cos_val_b1-cos_val_b2); 
    112124 
    113     // The following test should always pass 
    114     if (fabs(cos_val_b3)>1.0) { 
    115       printf("bcc_ana_2D: Unexpected error: cos(alpha)>1\n"); 
    116       return 0; 
    117     } 
     125 
    118126    // Get Fkq and Fkq_2 
    119127    Fkq = exp(-0.5*pow(Da/aa,2.0)*(a1_dot_q*a1_dot_q+a2_dot_q*a2_dot_q+a3_dot_q*a3_dot_q)); 
     
    287295                                        } 
    288296                                        if (weights_theta.size()>1) { 
    289                                                 _ptvalue *= fabs(sin(weights_theta[j].value*pi/180.0)); 
     297                                                _ptvalue *= fabs(cos(weights_theta[j].value*pi/180.0)); 
    290298                                        } 
    291299                                        sum += _ptvalue; 
  • sansmodels/src/c_models/capcyl.cpp

    re08bd5b r318b5bbb  
    136136 */ 
    137137static double capcyl_analytical_2D_scaled(CapCylParameters *pars, double q, double q_x, double q_y) { 
    138   double cyl_x, cyl_y, cyl_z; 
    139   double q_z; 
     138  double cyl_x, cyl_y;//, cyl_z; 
     139  //double q_z; 
    140140  double alpha, cos_val; 
    141141  double answer; 
     
    157157  //double Pi = 4.0*atan(1.0); 
    158158    // Cylinder orientation 
    159     cyl_x = sin(theta) * cos(phi); 
    160     cyl_y = sin(theta) * sin(phi); 
    161     cyl_z = cos(theta); 
     159    cyl_x = cos(theta) * cos(phi); 
     160    cyl_y = sin(theta); 
     161    //cyl_z = -cos(theta) * sin(phi); 
    162162 
    163163    // q vector 
    164     q_z = 0; 
     164    //q_z = 0; 
    165165 
    166166    // Compute the angle btw vector q and the 
    167167    // axis of the cylinder 
    168     cos_val = cyl_x*q_x + cyl_y*q_y + cyl_z*q_z; 
     168    cos_val = cyl_x*q_x + cyl_y*q_y;// + cyl_z*q_z; 
    169169 
    170170    // The following test should always pass 
     
    348348                                                } 
    349349                                                if (weights_theta.size()>1) { 
    350                                                         _ptvalue *= fabs(sin(weights_theta[l].value*pi/180.0)); 
     350                                                        _ptvalue *= fabs(cos(weights_theta[l].value*pi/180.0)); 
    351351                                                } 
    352352                                                sum += _ptvalue; 
  • sansmodels/src/c_models/corefourshell.cpp

    re08bd5b r318b5bbb  
    2828extern "C" { 
    2929        #include "libSphere.h" 
     30        #include "libmultifunc/libfunc.h" 
    3031} 
    3132 
     
    4445  double sld_solv; 
    4546  double background; 
     47  double M0_sld_shell1; 
     48  double M_theta_shell1; 
     49  double M_phi_shell1; 
     50  double M0_sld_shell2; 
     51  double M_theta_shell2; 
     52  double M_phi_shell2; 
     53  double M0_sld_shell3; 
     54  double M_theta_shell3; 
     55  double M_phi_shell3; 
     56  double M0_sld_shell4; 
     57  double M_theta_shell4; 
     58  double M_phi_shell4; 
     59  double M0_sld_core0; 
     60  double M_theta_core0; 
     61  double M_phi_core0; 
     62  double M0_sld_solv; 
     63  double M_theta_solv; 
     64  double M_phi_solv; 
     65  double Up_frac_i; 
     66  double Up_frac_f; 
     67  double Up_theta; 
    4668} CoreFourShellParameters; 
    4769 
     
    6587        sld_solv   = Parameter(6.4e-6); 
    6688        background = Parameter(0.001); 
     89        M0_sld_shell1 = Parameter(0.0e-6); 
     90        M_theta_shell1 = Parameter(0.0); 
     91        M_phi_shell1 = Parameter(0.0); 
     92        M0_sld_shell2 = Parameter(0.0e-6); 
     93        M_theta_shell2 = Parameter(0.0); 
     94        M_phi_shell2 = Parameter(0.0); 
     95        M0_sld_shell3 = Parameter(0.0e-6); 
     96        M_theta_shell3 = Parameter(0.0); 
     97        M_phi_shell3 = Parameter(0.0); 
     98        M0_sld_shell4 = Parameter(0.0e-6); 
     99        M_theta_shell4 = Parameter(0.0); 
     100        M_phi_shell4 = Parameter(0.0); 
     101        M0_sld_core0 = Parameter(0.0e-6); 
     102        M_theta_core0 = Parameter(0.0); 
     103        M_phi_core0 = Parameter(0.0); 
     104        M0_sld_solv = Parameter(0.0e-6); 
     105        M_theta_solv = Parameter(0.0); 
     106        M_phi_solv = Parameter(0.0); 
     107        Up_frac_i = Parameter(0.5); 
     108        Up_frac_f = Parameter(0.5); 
     109        Up_theta = Parameter(0.0); 
     110 
    67111} 
    68112 
     
    78122        // Fill parameter array for IGOR library 
    79123        // Add the background after averaging 
     124 
    80125        dp[0] = scale(); 
    81126        dp[1] = rad_core0(); 
     
    158203 * @return: function value 
    159204 */ 
     205 
     206static double corefourshell_analytical_2D_scaled(CoreFourShellParameters *pars, double q, double q_x, double q_y) { 
     207        double dp[13]; 
     208 
     209        // Fill parameter array for IGOR library 
     210        // Add the background after averaging 
     211 
     212        dp[0] = pars->scale; 
     213        dp[1] = pars->rad_core0; 
     214        dp[2] = 0.0; //sld_core0; 
     215        dp[3] = pars->thick_shell1; 
     216        dp[4] = 0.0; //sld_shell1; 
     217        dp[5] = pars->thick_shell2; 
     218        dp[6] = 0.0; //sld_shell2; 
     219        dp[7] = pars->thick_shell3; 
     220        dp[8] = 0.0; //sld_shell3; 
     221        dp[9] = pars->thick_shell4; 
     222        dp[10] = 0.0; //sld_shell4; 
     223        dp[11] = 0.0; //sld_solv; 
     224        dp[12] = 0.0; 
     225 
     226    double sld_core0 = pars->sld_core0; 
     227    double sld_shell1 = pars->sld_shell1; 
     228        double sld_shell2 = pars->sld_shell2; 
     229        double sld_shell3 = pars->sld_shell3; 
     230        double sld_shell4 = pars->sld_shell4; 
     231        double sld_solv = pars->sld_solv; 
     232        double answer = 0.0; 
     233        double m_max0 = pars->M0_sld_core0; 
     234        double m_max_shell1 = pars->M0_sld_shell1; 
     235        double m_max_shell2 = pars->M0_sld_shell2; 
     236        double m_max_shell3 = pars->M0_sld_shell3; 
     237        double m_max_shell4 = pars->M0_sld_shell4; 
     238        double m_max_solv = pars->M0_sld_solv; 
     239 
     240        if (m_max0 < 1.0e-32 && m_max_solv < 1.0e-32 && m_max_shell1 < 1.0e-32 && m_max_shell2 < 
     241                                                1.0e-32 && m_max_shell3 < 1.0e-32 && m_max_shell4 < 1.0e-32){ 
     242                dp[2] = sld_core0; 
     243                dp[4] = sld_shell1; 
     244                dp[6] = sld_shell2; 
     245                dp[8] = sld_shell3; 
     246                dp[10] = sld_shell4; 
     247                dp[11] = sld_solv; 
     248                answer = FourShell(dp, q); 
     249        } 
     250        else{ 
     251                double qx = q_x; 
     252                double qy = q_y; 
     253                double s_theta = pars->Up_theta; 
     254                double m_phi0 = pars->M_phi_core0; 
     255                double m_theta0 = pars->M_theta_core0; 
     256                double m_phi_shell1 = pars->M_phi_shell1; 
     257                double m_theta_shell1 = pars->M_theta_shell1; 
     258                double m_phi_shell2 = pars->M_phi_shell2; 
     259                double m_theta_shell2 = pars->M_theta_shell2; 
     260                double m_phi_shell3 = pars->M_phi_shell3; 
     261                double m_theta_shell3 = pars->M_theta_shell3; 
     262                double m_phi_shell4 = pars->M_phi_shell4; 
     263                double m_theta_shell4 = pars->M_theta_shell4; 
     264                double m_phi_solv = pars->M_phi_solv; 
     265                double m_theta_solv = pars->M_theta_solv; 
     266                double in_spin = pars->Up_frac_i; 
     267                double out_spin = pars->Up_frac_f; 
     268                polar_sld p_sld_core0; 
     269                polar_sld p_sld_shell1; 
     270                polar_sld p_sld_shell2; 
     271                polar_sld p_sld_shell3; 
     272                polar_sld p_sld_shell4; 
     273                polar_sld p_sld_solv; 
     274                //Find (b+m) slds 
     275                p_sld_core0 = cal_msld(1, qx, qy, sld_core0, m_max0, m_theta0, m_phi0, 
     276                                                                in_spin, out_spin, s_theta); 
     277                p_sld_shell1 = cal_msld(1, qx, qy, sld_shell1, m_max_shell1, m_theta_shell1, m_phi_shell1, 
     278                                                                in_spin, out_spin, s_theta); 
     279                p_sld_shell2 = cal_msld(1, qx, qy, sld_shell2, m_max_shell2, m_theta_shell2, m_phi_shell2, 
     280                                                                in_spin, out_spin, s_theta); 
     281                p_sld_shell3 = cal_msld(1, qx, qy, sld_shell3, m_max_shell3, m_theta_shell3, m_phi_shell3, 
     282                                                                in_spin, out_spin, s_theta); 
     283                p_sld_shell4 = cal_msld(1, qx, qy, sld_shell4, m_max_shell4, m_theta_shell4, m_phi_shell4, 
     284                                                                in_spin, out_spin, s_theta); 
     285                p_sld_solv = cal_msld(1, qx, qy, sld_solv, m_max_solv, m_theta_solv, m_phi_solv, 
     286                                                                in_spin, out_spin, s_theta); 
     287                //up_up 
     288                if (in_spin > 0.0 && out_spin > 0.0){ 
     289                        dp[2] = p_sld_core0.uu; 
     290                        dp[4] = p_sld_shell1.uu; 
     291                        dp[6] = p_sld_shell2.uu; 
     292                        dp[8] = p_sld_shell3.uu; 
     293                        dp[10] = p_sld_shell4.uu; 
     294                        dp[11] = p_sld_solv.uu; 
     295                        answer += FourShell(dp, q); 
     296                        } 
     297                //down_down 
     298                if (in_spin < 1.0 && out_spin < 1.0){ 
     299                        dp[2] = p_sld_core0.dd; 
     300                        dp[4] = p_sld_shell1.dd; 
     301                        dp[6] = p_sld_shell2.dd; 
     302                        dp[8] = p_sld_shell3.dd; 
     303                        dp[10] = p_sld_shell4.dd; 
     304                        dp[11] = p_sld_solv.dd; 
     305                        answer += FourShell(dp, q); 
     306                        } 
     307                //up_down 
     308                if (in_spin > 0.0 && out_spin < 1.0){ 
     309                        dp[2] = p_sld_core0.re_ud; 
     310                        dp[4] = p_sld_shell1.re_ud; 
     311                        dp[6] = p_sld_shell2.re_ud; 
     312                        dp[8] = p_sld_shell3.re_ud; 
     313                        dp[10] = p_sld_shell4.re_ud; 
     314                        dp[11] = p_sld_solv.re_ud; 
     315                        answer += FourShell(dp, q); 
     316                        dp[2] = p_sld_core0.im_ud; 
     317                        dp[4] = p_sld_shell1.im_ud; 
     318                        dp[6] = p_sld_shell2.im_ud; 
     319                        dp[8] = p_sld_shell3.im_ud; 
     320                        dp[10] = p_sld_shell4.im_ud; 
     321                        dp[11] = p_sld_solv.im_ud; 
     322                        answer += FourShell(dp, q); 
     323                        } 
     324                //down_up 
     325                if (in_spin < 1.0 && out_spin > 0.0){ 
     326                        dp[2] = p_sld_core0.re_du; 
     327                        dp[4] = p_sld_shell1.re_du; 
     328                        dp[6] = p_sld_shell2.re_du; 
     329                        dp[8] = p_sld_shell3.re_du; 
     330                        dp[10] = p_sld_shell4.re_du; 
     331                        dp[11] = p_sld_solv.re_du; 
     332                        answer += FourShell(dp, q); 
     333                        dp[2] = p_sld_core0.im_du; 
     334                        dp[4] = p_sld_shell1.im_du; 
     335                        dp[6] = p_sld_shell2.im_du; 
     336                        dp[8] = p_sld_shell3.im_du; 
     337                        dp[10] = p_sld_shell4.im_du; 
     338                        dp[11] = p_sld_solv.im_du; 
     339                        answer += FourShell(dp, q); 
     340                        } 
     341        } 
     342        // Already normalized 
     343        // add in the background 
     344        answer += pars->background; 
     345        return answer; 
     346} 
     347 
     348/** 
     349 * Function to evaluate 2D scattering function 
     350 * @param pars: parameters 
     351 * @param q: q-value 
     352 * @return: function value 
     353 */ 
     354static double corefourshell_analytical_2DXY(CoreFourShellParameters *pars, double qx, double qy) { 
     355  double q; 
     356  q = sqrt(qx*qx+qy*qy); 
     357  return corefourshell_analytical_2D_scaled(pars, q, qx/q, qy/q); 
     358} 
     359 
     360 
    160361double CoreFourShellModel :: operator()(double qx, double qy) { 
    161         double q = sqrt(qx*qx + qy*qy); 
    162         return (*this).operator()(q); 
     362        CoreFourShellParameters dp; 
     363        dp.scale = scale(); 
     364        dp.rad_core0 = rad_core0(); 
     365        dp.sld_core0 = sld_core0(); 
     366        dp.thick_shell1 = thick_shell1(); 
     367        dp.sld_shell1 = sld_shell1(); 
     368        dp.thick_shell2 = thick_shell2(); 
     369        dp.sld_shell2 = sld_shell2(); 
     370        dp.thick_shell3 = thick_shell3(); 
     371        dp.sld_shell3 = sld_shell3(); 
     372        dp.thick_shell4 = thick_shell4(); 
     373        dp.sld_shell4 = sld_shell4(); 
     374        dp.sld_solv = sld_solv(); 
     375        dp.background = 0.0; 
     376        dp.M0_sld_shell1 = M0_sld_shell1(); 
     377        dp.M_theta_shell1 = M_theta_shell1(); 
     378        dp.M_phi_shell1 = M_phi_shell1(); 
     379        dp.M0_sld_shell2 = M0_sld_shell2(); 
     380        dp.M_theta_shell2 = M_theta_shell2(); 
     381        dp.M_phi_shell2 = M_phi_shell2(); 
     382        dp.M0_sld_shell3 = M0_sld_shell3(); 
     383        dp.M_theta_shell3 = M_theta_shell3(); 
     384        dp.M_phi_shell3 = M_phi_shell3(); 
     385        dp.M0_sld_shell4 = M0_sld_shell4(); 
     386        dp.M_theta_shell4 = M_theta_shell4(); 
     387        dp.M_phi_shell4 = M_phi_shell4(); 
     388        dp.M0_sld_core0 = M0_sld_core0(); 
     389        dp.M_theta_core0 = M_theta_core0(); 
     390        dp.M_phi_core0 = M_phi_core0(); 
     391        dp.M0_sld_solv = M0_sld_solv(); 
     392        dp.M_theta_solv = M_theta_solv(); 
     393        dp.M_phi_solv = M_phi_solv(); 
     394        dp.Up_frac_i = Up_frac_i(); 
     395        dp.Up_frac_f = Up_frac_f(); 
     396        dp.Up_theta = Up_theta(); 
     397     
     398        // Get the dispersion points for the radius 
     399        vector<WeightPoint> weights_rad; 
     400        rad_core0.get_weights(weights_rad); 
     401 
     402        // Get the dispersion points for the thick 1 
     403        vector<WeightPoint> weights_s1; 
     404        thick_shell1.get_weights(weights_s1); 
     405 
     406        // Get the dispersion points for the thick 2 
     407        vector<WeightPoint> weights_s2; 
     408        thick_shell2.get_weights(weights_s2); 
     409 
     410        // Get the dispersion points for the thick 3 
     411        vector<WeightPoint> weights_s3; 
     412        thick_shell3.get_weights(weights_s3); 
     413 
     414        // Get the dispersion points for the thick 4 
     415        vector<WeightPoint> weights_s4; 
     416        thick_shell4.get_weights(weights_s4); 
     417 
     418        // Perform the computation, with all weight points 
     419        double sum = 0.0; 
     420        double norm = 0.0; 
     421        double vol = 0.0; 
     422 
     423        // Loop over radius weight points 
     424        for(size_t i=0; i<weights_rad.size(); i++) { 
     425                dp.rad_core0 = weights_rad[i].value; 
     426                // Loop over radius weight points 
     427                for(size_t j=0; j<weights_s1.size(); j++) { 
     428                        dp.thick_shell1 = weights_s1[j].value; 
     429                        // Loop over radius weight points 
     430                        for(size_t k=0; k<weights_s2.size(); k++) { 
     431                                dp.thick_shell2 = weights_s2[k].value; 
     432                                // Loop over radius weight points 
     433                                for(size_t l=0; l<weights_s3.size(); l++) { 
     434                                        dp.thick_shell3 = weights_s3[l].value; 
     435                                        // Loop over radius weight points 
     436                                        for(size_t m=0; m<weights_s4.size(); m++) { 
     437                                                dp.thick_shell4 = weights_s4[m].value; 
     438                                                //Un-normalize FourShell by volume 
     439                                                sum += weights_rad[i].weight*weights_s1[j].weight*weights_s2[k].weight*weights_s3[l].weight*weights_s4[m].weight 
     440                                                        * corefourshell_analytical_2DXY(&dp, qx, qy) * pow((weights_rad[i].value+weights_s1[j].value+weights_s2[k].value+weights_s3[l].value+weights_s4[m].value),3); 
     441                                                //Find average volume 
     442                                                vol += weights_rad[i].weight*weights_s1[j].weight*weights_s2[k].weight*weights_s3[l].weight*weights_s4[m].weight 
     443                                                        * pow((weights_rad[i].value+weights_s1[j].value+weights_s2[k].value+weights_s3[l].value+weights_s4[m].value),3); 
     444 
     445                                                norm += weights_rad[i].weight*weights_s1[j].weight*weights_s2[k].weight*weights_s3[l].weight*weights_s4[m].weight; 
     446                                        } 
     447                                } 
     448                        } 
     449                } 
     450        } 
     451 
     452        if (vol != 0.0 && norm != 0.0) { 
     453                //Re-normalize by avg volume 
     454                sum = sum/(vol/norm);} 
     455        return sum/norm + background(); 
    163456} 
    164457 
     
    171464 */ 
    172465double CoreFourShellModel :: evaluate_rphi(double q, double phi) { 
    173         return (*this).operator()(q); 
     466        double qx = q*cos(phi); 
     467        double qy = q*sin(phi); 
     468        return (*this).operator()(qx, qy); 
    174469} 
    175470 
  • sansmodels/src/c_models/coreshellbicelle.cpp

    r02bdfc5 r318b5bbb  
    5656 */ 
    5757static double core_shell_bicelle_analytical_2D_scaled(CoreShellBicelleParameters *pars, double q, double q_x, double q_y) { 
    58   double cyl_x, cyl_y, cyl_z; 
    59   double q_z; 
     58  double cyl_x, cyl_y;//, cyl_z; 
     59  //double q_z; 
    6060  double alpha, vol, cos_val; 
    6161  double answer; 
     
    6666 
    6767  // Cylinder orientation 
    68   cyl_x = sin(theta) * cos(phi); 
    69   cyl_y = sin(theta) * sin(phi); 
    70   cyl_z = cos(theta); 
     68  cyl_x = cos(theta) * cos(phi); 
     69  cyl_y = sin(theta); 
     70  //cyl_z = -cos(theta) * sin(phi); 
    7171 
    7272  // q vector 
    73   q_z = 0; 
     73  //q_z = 0; 
    7474 
    7575  // Compute the angle btw vector q and the 
    7676  // axis of the cylinder 
    77   cos_val = cyl_x*q_x + cyl_y*q_y + cyl_z*q_z; 
     77  cos_val = cyl_x*q_x + cyl_y*q_y;// + cyl_z*q_z; 
    7878 
    7979  // The following test should always pass 
     
    315315 
    316316                                if (weights_theta.size()>1) { 
    317                                   _ptvalue *= fabs(sin(weights_theta[k].value*pi/180.0)); 
     317                                  _ptvalue *= fabs(cos(weights_theta[k].value*pi/180.0)); 
    318318                                } 
    319319                                sum += _ptvalue; 
  • sansmodels/src/c_models/coreshellcylinder.cpp

    re08bd5b r318b5bbb  
    5454 */ 
    5555static double core_shell_cylinder_analytical_2D_scaled(CoreShellCylinderParameters *pars, double q, double q_x, double q_y) { 
    56   double cyl_x, cyl_y, cyl_z; 
    57   double q_z; 
     56  double cyl_x, cyl_y;//, cyl_z; 
     57  //double q_z; 
    5858  double alpha, vol, cos_val; 
    5959  double answer; 
     
    6464 
    6565  // Cylinder orientation 
    66   cyl_x = sin(theta) * cos(phi); 
    67   cyl_y = sin(theta) * sin(phi); 
    68   cyl_z = cos(theta); 
     66  cyl_x = cos(theta) * cos(phi); 
     67  cyl_y = sin(theta); 
     68  //cyl_z = -cos(theta) * sin(phi); 
    6969 
    7070  // q vector 
    71   q_z = 0; 
     71  //q_z = 0; 
    7272 
    7373  // Compute the angle btw vector q and the 
    7474  // axis of the cylinder 
    75   cos_val = cyl_x*q_x + cyl_y*q_y + cyl_z*q_z; 
     75  cos_val = cyl_x*q_x + cyl_y*q_y;// + cyl_z*q_z; 
    7676 
    7777  // The following test should always pass 
    7878  if (fabs(cos_val)>1.0) { 
    7979    printf("core_shell_cylinder_analytical_2D: Unexpected error: cos(alpha)=%g\n", cos_val); 
    80     return 0; 
     80    cos_val = 1.0; 
    8181  } 
    8282 
    8383  alpha = acos( cos_val ); 
    84  
     84  if (alpha == 0.0){ 
     85        alpha = 1.0e-26; 
     86  } 
    8587  // Call the IGOR library function to get the kernel 
    8688  answer = CoreShellCylKernel(q, pars->radius, pars->thickness, 
     
    285287 
    286288            if (weights_theta.size()>1) { 
    287               _ptvalue *= fabs(sin(weights_theta[k].value*pi/180.0)); 
     289              _ptvalue *= fabs(cos(weights_theta[k].value*pi/180.0)); 
    288290            } 
    289291            sum += _ptvalue; 
  • sansmodels/src/c_models/coreshellsphere.cpp

    re08bd5b r318b5bbb  
    2828extern "C" { 
    2929#include "libSphere.h" 
     30#include "libmultifunc/libfunc.h" 
    3031} 
    3132 
     
    3839  double solvent_sld; 
    3940  double background; 
     41  double M0_sld_shell; 
     42  double M_theta_shell; 
     43  double M_phi_shell; 
     44  double M0_sld_core; 
     45  double M_theta_core; 
     46  double M_phi_core; 
     47  double M0_sld_solv; 
     48  double M_theta_solv; 
     49  double M_phi_solv; 
     50  double Up_frac_i; 
     51  double Up_frac_f; 
     52  double Up_theta; 
    4053} CoreShellParameters; 
    4154 
     
    5063  solvent_sld = Parameter(3.e-6); 
    5164  background = Parameter(0.0); 
     65  M0_sld_shell = Parameter(0.0e-6); 
     66  M_theta_shell = Parameter(0.0); 
     67  M_phi_shell = Parameter(0.0); 
     68  M0_sld_core = Parameter(0.0e-6); 
     69  M_theta_core = Parameter(0.0); 
     70  M_phi_core = Parameter(0.0); 
     71  M0_sld_solv = Parameter(0.0e-6); 
     72  M_theta_solv = Parameter(0.0); 
     73  M_phi_solv = Parameter(0.0); 
     74  Up_frac_i = Parameter(0.5); 
     75  Up_frac_f = Parameter(0.5); 
     76  Up_theta = Parameter(0.0); 
    5277} 
    5378 
     
    7297  dp[6] = 0.0; 
    7398 
     99  //im 
     100  ///dp[7] = 0.0; 
     101  ///dp[8] = 0.0; 
     102  ///dp[9] = 0.0; 
    74103 
    75104  // Get the dispersion points for the radius 
     
    112141} 
    113142 
     143 
     144 
     145/** 
     146 * Function to evaluate 2D scattering function 
     147 * @param pars: parameters 
     148 * @param q: q-value 
     149 * @param q_x: q_x / q 
     150 * @param q_y: q_y / q 
     151 * @return: function value 
     152 */ 
     153 
     154static double coreshell_analytical_2D_scaled(CoreShellParameters *pars, double q, double q_x, double q_y) { 
     155        double dp[7]; 
     156        //convert angle degree to radian 
     157        dp[0] = pars->scale; 
     158        dp[1] = pars->radius; 
     159        dp[2] = pars->thickness; 
     160        dp[3] = 0.0; 
     161        dp[4] = 0.0; 
     162        dp[5] = 0.0; 
     163        dp[6] = 0.0; 
     164        //im 
     165        ///dp[7] = 0.0; 
     166        ///dp[8] = 0.0; 
     167        ///dp[9] = 0.0; 
     168 
     169    double sld_core = pars->core_sld; 
     170    double sld_shell = pars->shell_sld; 
     171        double sld_solv = pars->solvent_sld; 
     172        double answer = 0.0; 
     173        double m_max = pars->M0_sld_core; 
     174        double m_max_shell = pars->M0_sld_shell; 
     175        double m_max_solv = pars->M0_sld_solv; 
     176 
     177        if (m_max < 1.0e-32 && m_max_solv < 1.0e-32 && m_max_shell < 1.0e-32){ 
     178                dp[3] = sld_core; 
     179                dp[4] = sld_shell; 
     180                dp[5] = sld_solv; 
     181                answer = CoreShellForm(dp, q); 
     182        } 
     183        else{ 
     184                double qx = q_x; 
     185                double qy = q_y; 
     186                double s_theta = pars->Up_theta; 
     187                double m_phi = pars->M_phi_core; 
     188                double m_theta = pars->M_theta_core; 
     189                double m_phi_shell = pars->M_phi_shell; 
     190                double m_theta_shell = pars->M_theta_shell; 
     191                double m_phi_solv = pars->M_phi_solv; 
     192                double m_theta_solv = pars->M_theta_solv; 
     193                double in_spin = pars->Up_frac_i; 
     194                double out_spin = pars->Up_frac_f; 
     195                polar_sld p_sld_core; 
     196                polar_sld p_sld_shell; 
     197                polar_sld p_sld_solv; 
     198                //Find (b+m) slds 
     199                p_sld_core = cal_msld(1, qx, qy, sld_core, m_max, m_theta, m_phi, 
     200                                                                in_spin, out_spin, s_theta); 
     201                p_sld_shell = cal_msld(1, qx, qy, sld_shell, m_max_shell, m_theta_shell, m_phi_shell, 
     202                                                                in_spin, out_spin, s_theta); 
     203                p_sld_solv = cal_msld(1, qx, qy, sld_solv, m_max_solv, m_theta_solv, m_phi_solv, 
     204                                                                in_spin, out_spin, s_theta); 
     205                //up_up 
     206                if (in_spin > 0.0 && out_spin > 0.0){ 
     207                        dp[3] = p_sld_core.uu; 
     208                        dp[4] = p_sld_shell.uu; 
     209                        dp[5] = p_sld_solv.uu; 
     210                        answer += CoreShellForm(dp, q); 
     211                        } 
     212                //down_down 
     213                if (in_spin < 1.0 && out_spin < 1.0){ 
     214                        dp[3] = p_sld_core.dd; 
     215                        dp[4] = p_sld_shell.dd; 
     216                        dp[5] = p_sld_solv.dd; 
     217                        answer += CoreShellForm(dp, q); 
     218                        } 
     219                //up_down 
     220                if (in_spin > 0.0 && out_spin < 1.0){ 
     221                        dp[3] = p_sld_core.re_ud; 
     222                        dp[4] = p_sld_shell.re_ud; 
     223                        dp[5] = p_sld_solv.re_ud; 
     224                        answer += CoreShellForm(dp, q); 
     225                        dp[3] = p_sld_core.im_ud; 
     226                        dp[4] = p_sld_shell.im_ud; 
     227                        dp[5] = p_sld_solv.im_ud; 
     228                        answer += CoreShellForm(dp, q); 
     229                        } 
     230                //down_up 
     231                if (in_spin < 1.0 && out_spin > 0.0){ 
     232                        dp[3] = p_sld_core.re_du; 
     233                        dp[4] = p_sld_shell.re_du; 
     234                        dp[5] = p_sld_solv.re_du; 
     235                        answer += CoreShellForm(dp, q); 
     236                        dp[3] = p_sld_core.im_du; 
     237                        dp[4] = p_sld_shell.im_du; 
     238                        dp[5] = p_sld_solv.im_du; 
     239                        answer += CoreShellForm(dp, q); 
     240                        } 
     241        } 
     242        // Already normalized 
     243        // add in the background 
     244        answer += pars->background; 
     245        return answer; 
     246} 
     247 
     248/** 
     249 * Function to evaluate 2D scattering function 
     250 * @param pars: parameters 
     251 * @param q: q-value 
     252 * @return: function value 
     253 */ 
     254static double coreshell_analytical_2DXY(CoreShellParameters *pars, double qx, double qy) { 
     255  double q; 
     256  q = sqrt(qx*qx+qy*qy); 
     257  return coreshell_analytical_2D_scaled(pars, q, qx/q, qy/q); 
     258} 
     259 
     260 
    114261/** 
    115262 * Function to evaluate 2D scattering function 
     
    119266 */ 
    120267double CoreShellModel :: operator()(double qx, double qy) { 
    121   double q = sqrt(qx*qx + qy*qy); 
    122   return (*this).operator()(q); 
     268        CoreShellParameters dp; 
     269    dp.scale = scale(); 
     270    dp.radius = radius(); 
     271    dp.thickness = thickness(); 
     272    dp.core_sld = core_sld(); 
     273    dp.shell_sld = shell_sld(); 
     274    dp.solvent_sld = solvent_sld(); 
     275    dp.background = 0.0; 
     276    dp.M0_sld_shell = M0_sld_shell(); 
     277    dp.M_theta_shell = M_theta_shell(); 
     278    dp.M_phi_shell = M_phi_shell(); 
     279    dp.M0_sld_core = M0_sld_core(); 
     280    dp.M_theta_core = M_theta_core(); 
     281    dp.M_phi_core = M_phi_core(); 
     282    dp.M0_sld_solv = M0_sld_solv(); 
     283    dp.M_theta_solv = M_theta_solv(); 
     284    dp.M_phi_solv = M_phi_solv(); 
     285    dp.Up_frac_i = Up_frac_i(); 
     286    dp.Up_frac_f = Up_frac_f(); 
     287    dp.Up_theta = Up_theta(); 
     288 
     289        // Get the dispersion points for the radius 
     290        vector<WeightPoint> weights_rad; 
     291        radius.get_weights(weights_rad); 
     292 
     293        // Get the dispersion points for the thickness 
     294        vector<WeightPoint> weights_thick; 
     295        thickness.get_weights(weights_thick); 
     296 
     297        // Perform the computation, with all weight points 
     298        double sum = 0.0; 
     299        double norm = 0.0; 
     300        double vol = 0.0; 
     301 
     302        // Loop over radius weight points 
     303        for(size_t i=0; i<weights_rad.size(); i++) { 
     304        dp.radius = weights_rad[i].value; 
     305 
     306        // Loop over thickness weight points 
     307        for(size_t j=0; j<weights_thick.size(); j++) { 
     308          dp.thickness = weights_thick[j].value; 
     309          //Un-normalize SphereForm by volume 
     310          sum += weights_rad[i].weight 
     311                  * weights_thick[j].weight * coreshell_analytical_2DXY(&dp, qx, qy) * 
     312                        pow(weights_rad[i].value+weights_thick[j].value,3); 
     313 
     314          //Find average volume 
     315          vol += weights_rad[i].weight * weights_thick[j].weight 
     316                  * pow(weights_rad[i].value+weights_thick[j].value,3); 
     317          norm += weights_rad[i].weight 
     318                  * weights_thick[j].weight; 
     319        } 
     320        } 
     321 
     322        if (vol != 0.0 && norm != 0.0) { 
     323                //Re-normalize by avg volume 
     324                sum = sum/(vol/norm);} 
     325        return sum/norm + background(); 
    123326} 
    124327 
     
    131334 */ 
    132335double CoreShellModel :: evaluate_rphi(double q, double phi) { 
    133   return (*this).operator()(q); 
     336        double qx = q*cos(phi); 
     337        double qy = q*sin(phi); 
     338        return (*this).operator()(qx, qy); 
    134339} 
    135340/** 
  • sansmodels/src/c_models/csparallelepiped.cpp

    re08bd5b r318b5bbb  
    143143static double csparallelepiped_analytical_2D_scaled(CSParallelepipedParameters *pars, double q, double q_x, double q_y) { 
    144144  double dp[13]; 
    145   double cparallel_x, cparallel_y, cparallel_z, bparallel_x, bparallel_y, parallel_x, parallel_y; 
    146   double q_z; 
    147   double alpha, cos_val_c, cos_val_b, cos_val_a, edgeA, edgeB, edgeC; 
     145  double cparallel_x, cparallel_y, bparallel_x, bparallel_y, parallel_x, parallel_y; 
     146  //double q_z; 
     147  double cos_val_c, cos_val_b, cos_val_a, edgeA, edgeB, edgeC; 
    148148 
    149149  double answer; 
     
    176176 
    177177  // parallelepiped c axis orientation 
    178   cparallel_x = sin(theta) * cos(phi); 
    179   cparallel_y = sin(theta) * sin(phi); 
    180   cparallel_z = cos(theta); 
     178  cparallel_x = cos(theta) * cos(phi); 
     179  cparallel_y = sin(theta); 
     180  //cparallel_z = -cos(theta) * sin(phi); 
    181181 
    182182  // q vector 
    183   q_z = 0.0; 
     183  //q_z = 0.0; 
    184184 
    185185  // Compute the angle btw vector q and the 
    186186  // axis of the parallelepiped 
    187   cos_val_c = cparallel_x*q_x + cparallel_y*q_y + cparallel_z*q_z; 
    188   alpha = acos(cos_val_c); 
     187  cos_val_c = cparallel_x*q_x + cparallel_y*q_y;// + cparallel_z*q_z; 
     188  //alpha = acos(cos_val_c); 
    189189 
    190190  // parallelepiped a axis orientation 
    191   parallel_x = sin(psi);//cos(pars->parallel_theta) * sin(pars->parallel_phi)*sin(pars->parallel_psi); 
    192   parallel_y = cos(psi);//cos(pars->parallel_theta) * cos(pars->parallel_phi)*cos(pars->parallel_psi); 
     191  parallel_x = -cos(phi)*sin(psi) * sin(theta)+sin(phi)*cos(psi); 
     192  parallel_y = sin(psi)*cos(theta); 
    193193 
    194194  cos_val_a = parallel_x*q_x + parallel_y*q_y; 
     
    197197 
    198198  // parallelepiped b axis orientation 
    199   bparallel_x = sqrt(1.0-sin(theta)*cos(phi))*cos(psi);//cos(pars->parallel_theta) * cos(pars->parallel_phi)* cos(pars->parallel_psi); 
    200   bparallel_y = sqrt(1.0-sin(theta)*cos(phi))*sin(psi);//cos(pars->parallel_theta) * sin(pars->parallel_phi)* sin(pars->parallel_psi); 
     199  bparallel_x = -sin(theta)*cos(psi)*cos(phi)-sin(psi)*sin(phi); 
     200  bparallel_y = cos(theta)*cos(psi); 
    201201  // axis of the parallelepiped 
    202   cos_val_b = sin(acos(cos_val_a)) ; 
    203  
    204  
     202  cos_val_b = bparallel_x*q_x + bparallel_y*q_y; 
    205203 
    206204  // The following test should always pass 
    207205  if (fabs(cos_val_c)>1.0) { 
    208     printf("parallel_ana_2D: Unexpected error: cos(alpha)>1\n"); 
    209     return 0; 
    210   } 
    211  
     206    //printf("parallel_ana_2D: Unexpected error: cos(alpha)>1\n"); 
     207    cos_val_c = 1.0; 
     208  } 
     209  if (fabs(cos_val_a)>1.0) { 
     210    //printf("parallel_ana_2D: Unexpected error: cos(alpha)>1\n"); 
     211    cos_val_a = 1.0; 
     212  } 
     213  if (fabs(cos_val_b)>1.0) { 
     214    //printf("parallel_ana_2D: Unexpected error: cos(alpha)>1\n"); 
     215    cos_val_b = 1.0; 
     216  } 
    212217  // Call the IGOR library function to get the kernel 
    213   answer = cspkernel( dp,q, sin(alpha)*cos_val_a,sin(alpha)*cos_val_b,cos_val_c); 
     218  answer = cspkernel( dp, q, cos_val_a, cos_val_b, cos_val_c); 
    214219 
    215220  //convert to [cm-1] 
     
    434439 
    435440              if (weights_parallel_theta.size()>1) { 
    436                 _ptvalue *= fabs(sin(weights_parallel_theta[l].value*pi/180.0)); 
     441                _ptvalue *= fabs(cos(weights_parallel_theta[l].value*pi/180.0)); 
    437442              } 
    438443              sum += _ptvalue; 
  • sansmodels/src/c_models/cylinder.cpp

    r20efe7b r318b5bbb  
    2828        #include "libCylinder.h" 
    2929        #include "libStructureFactor.h" 
     30        #include "libmultifunc/libfunc.h" 
    3031} 
    3132#include "cylinder.h" 
     
    4142    double cyl_theta; 
    4243    double cyl_phi; 
     44    double M0_sld_cyl; 
     45    double M_theta_cyl; 
     46    double M_phi_cyl; 
     47    double M0_sld_solv; 
     48    double M_theta_solv; 
     49    double M_phi_solv; 
     50    double Up_frac_i; 
     51        double Up_frac_f; 
     52        double Up_theta; 
    4353} CylinderParameters; 
    4454 
     
    5464        cyl_theta  = Parameter(0.0, true); 
    5565        cyl_phi    = Parameter(0.0, true); 
     66        M0_sld_cyl = Parameter(0.0e-6); 
     67        M_theta_cyl = Parameter(0.0); 
     68        M_phi_cyl = Parameter(0.0);  
     69        M0_sld_solv = Parameter(0.0e-6); 
     70        M_theta_solv = Parameter(0.0); 
     71        M_phi_solv = Parameter(0.0);  
     72        Up_frac_i = Parameter(0.5);  
     73        Up_frac_f = Parameter(0.5); 
     74        Up_theta = Parameter(0.0); 
    5675} 
    5776 
     
    122141 */ 
    123142static double cylinder_analytical_2D_scaled(CylinderParameters *pars, double q, double q_x, double q_y) { 
    124   double cyl_x, cyl_y, cyl_z; 
    125   double q_z; 
    126   double alpha, vol, cos_val; 
    127   double answer; 
    128   //convert angle degree to radian 
    129   double pi = 4.0*atan(1.0); 
    130   double theta = pars->cyl_theta * pi/180.0; 
    131   double phi = pars->cyl_phi * pi/180.0; 
     143    double cyl_x, cyl_y;//, cyl_z; 
     144    //double q_z; 
     145    double alpha, vol, cos_val; 
     146    double answer = 0.0; 
     147    double form = 0.0; 
     148    //convert angle degree to radian 
     149    double pi = 4.0*atan(1.0); 
     150    double theta = pars->cyl_theta * pi/180.0; 
     151    double phi = pars->cyl_phi * pi/180.0; 
     152    double sld_solv = pars->sldSolv; 
     153    double sld_cyl = pars->sldCyl; 
     154    double m_max = pars->M0_sld_cyl; 
     155    double m_max_solv = pars->M0_sld_solv; 
     156    double contrast = 0.0; 
    132157 
    133158    // Cylinder orientation 
    134     cyl_x = sin(theta) * cos(phi); 
    135     cyl_y = sin(theta) * sin(phi); 
    136     cyl_z = cos(theta); 
    137  
     159        cyl_x = cos(theta) * cos(phi); 
     160    cyl_y = sin(theta); 
     161    //cyl_z = -cos(theta) * sin(phi); 
    138162    // q vector 
    139     q_z = 0.0; 
     163    //q_z = 0.0; 
    140164 
    141165    // Compute the angle btw vector q and the 
    142166    // axis of the cylinder 
    143     cos_val = cyl_x*q_x + cyl_y*q_y + cyl_z*q_z; 
     167    cos_val = cyl_x*q_x + cyl_y*q_y;// + cyl_z*q_z; 
    144168 
    145169    // The following test should always pass 
     
    157181        } 
    158182  // Call the IGOR library function to get the kernel 
    159   answer = CylKernel(q, pars->radius, pars->length/2.0, alpha) / sin(alpha); 
    160  
    161   // Multiply by contrast^2 
    162   answer *= (pars->sldCyl - pars->sldSolv)*(pars->sldCyl - pars->sldSolv); 
    163  
    164   //normalize by cylinder volume 
    165   //NOTE that for this (Fournet) definition of the integral, one must MULTIPLY by Vcyl 
     183  //answer = CylKernel(q, pars->radius, pars->length/2.0, alpha) / sin(alpha); 
     184 
     185    // Call the IGOR library function to get the kernel 
     186    form = CylKernel(q, pars->radius, pars->length/2.0, alpha) / sin(alpha); 
     187 
     188        if (m_max < 1.0e-32 && m_max_solv < 1.0e-32){ 
     189                // Multiply by contrast^2 
     190                contrast = (pars->sldCyl - pars->sldSolv); 
     191                answer = contrast * contrast * form; 
     192        } 
     193        else{ 
     194                double qx = q_x; 
     195                double qy = q_y; 
     196                double s_theta = pars->Up_theta; 
     197                double m_phi = pars->M_phi_cyl; 
     198                double m_theta = pars->M_theta_cyl; 
     199                double m_phi_solv = pars->M_phi_solv; 
     200                double m_theta_solv = pars->M_theta_solv; 
     201                double in_spin = pars->Up_frac_i; 
     202                double out_spin = pars->Up_frac_f; 
     203                polar_sld p_sld; 
     204                polar_sld p_sld_solv; 
     205                p_sld = cal_msld(1, qx, qy, sld_cyl, m_max, m_theta, m_phi,  
     206                                                in_spin, out_spin, s_theta); 
     207                p_sld_solv = cal_msld(1, qx, qy, sld_solv, m_max_solv, m_theta_solv, m_phi_solv,  
     208                                                in_spin, out_spin, s_theta); 
     209                //up_up  
     210                if (in_spin > 0.0 && out_spin > 0.0){                     
     211                        answer += ((p_sld.uu- p_sld_solv.uu) * (p_sld.uu- p_sld_solv.uu) * form); 
     212                        } 
     213                //down_down 
     214                if (in_spin < 1.0 && out_spin < 1.0){ 
     215                        answer += ((p_sld.dd - p_sld_solv.dd) * (p_sld.dd - p_sld_solv.dd) * form); 
     216                        } 
     217                //up_down 
     218                if (in_spin > 0.0 && out_spin < 1.0){ 
     219                        answer += ((p_sld.re_ud - p_sld_solv.re_ud) * (p_sld.re_ud - p_sld_solv.re_ud) * form); 
     220                        answer += ((p_sld.im_ud - p_sld_solv.im_ud) * (p_sld.im_ud - p_sld_solv.im_ud) * form); 
     221                        } 
     222                //down_up        
     223                if (in_spin < 1.0 && out_spin > 0.0){ 
     224                        answer += ((p_sld.re_du - p_sld_solv.re_du) * (p_sld.re_du - p_sld_solv.re_du) * form); 
     225                        answer += ((p_sld.im_du - p_sld_solv.im_du) * (p_sld.im_du - p_sld_solv.im_du) * form); 
     226                        } 
     227        } 
     228 
     229    //normalize by cylinder volume 
     230    //NOTE that for this (Fournet) definition of the integral, one must MULTIPLY by Vcyl 
    166231    vol = acos(-1.0) * pars->radius * pars->radius * pars->length; 
    167   answer *= vol; 
    168  
    169   //convert to [cm-1] 
    170   answer *= 1.0e8; 
    171  
    172   //Scale 
    173   answer *= pars->scale; 
    174  
    175   // add in the background 
    176   answer += pars->background; 
    177  
    178   return answer; 
     232    answer *= vol; 
     233 
     234    //convert to [cm-1] 
     235    answer *= 1.0e8; 
     236 
     237    //Scale 
     238    answer *= pars->scale; 
     239 
     240    // add in the background 
     241    answer += pars->background; 
     242 
     243    return answer; 
    179244} 
    180245 
     
    208273        dp.cyl_theta  = cyl_theta(); 
    209274        dp.cyl_phi    = cyl_phi(); 
    210  
     275        dp.Up_theta =  Up_theta(); 
     276        dp.M_phi_cyl =  M_phi_cyl(); 
     277        dp.M_theta_cyl =  M_theta_cyl(); 
     278        dp.M0_sld_cyl =  M0_sld_cyl(); 
     279        dp.M_phi_solv =  M_phi_solv(); 
     280        dp.M_theta_solv =  M_theta_solv(); 
     281        dp.M0_sld_solv =  M0_sld_solv(); 
     282        dp.Up_frac_i =  Up_frac_i(); 
     283        dp.Up_frac_f =  Up_frac_f(); 
     284         
    211285        // Get the dispersion points for the radius 
    212286        vector<WeightPoint> weights_rad; 
     
    255329                                                *pow(weights_rad[i].value,2)*weights_len[j].value; 
    256330                                        if (weights_theta.size()>1) { 
    257                                                 _ptvalue *= fabs(sin(weights_theta[k].value*pi/180.0)); 
     331                                                _ptvalue *= fabs(cos(weights_theta[k].value*pi/180.0)); 
    258332                                        } 
    259333                                        sum += _ptvalue; 
  • sansmodels/src/c_models/ellipsoid.cpp

    re08bd5b r318b5bbb  
    5151 */ 
    5252static double ellipsoid_analytical_2D_scaled(EllipsoidParameters *pars, double q, double q_x, double q_y) { 
    53   double cyl_x, cyl_y, cyl_z; 
    54   double q_z; 
     53  double cyl_x, cyl_y;//, cyl_z; 
     54  //double q_z; 
    5555  double alpha, vol, cos_val; 
    5656  double answer; 
     
    6161 
    6262  // Ellipsoid orientation 
    63   cyl_x = sin(theta) * cos(phi); 
    64   cyl_y = sin(theta) * sin(phi); 
    65   cyl_z = cos(theta); 
     63  cyl_x = cos(theta) * cos(phi); 
     64  cyl_y = sin(theta); 
     65  //cyl_z = -cos(theta) * sin(phi); 
    6666 
    6767  // q vector 
    68   q_z = 0.0; 
     68  //q_z = 0.0; 
    6969 
    7070  // Compute the angle btw vector q and the 
    7171  // axis of the cylinder 
    72   cos_val = cyl_x*q_x + cyl_y*q_y + cyl_z*q_z; 
     72  cos_val = cyl_x*q_x + cyl_y*q_y;// + cyl_z*q_z; 
    7373 
    7474  // The following test should always pass 
     
    252252          * pow(weights_rad_b[j].value,2) * weights_rad_a[i].value; 
    253253          if (weights_theta.size()>1) { 
    254             _ptvalue *= fabs(sin(weights_theta[k].value*pi/180.0)); 
     254            _ptvalue *= fabs(cos(weights_theta[k].value*pi/180.0)); 
    255255          } 
    256256          sum += _ptvalue; 
  • sansmodels/src/c_models/ellipticalcylinder.cpp

    re08bd5b r318b5bbb  
    4646 
    4747 
    48 static double elliptical_cylinder_kernel(EllipticalCylinderParameters *pars, double q, double alpha, double nu) { 
     48static double elliptical_cylinder_kernel(EllipticalCylinderParameters *pars, double q, double cos_val, double cos_nu, double cos_mu) { 
    4949  double qr; 
    5050  double qL; 
     
    5555  r_major = pars->r_ratio * pars->r_minor; 
    5656 
    57   qr = q*sin(alpha)*sqrt( r_major*r_major*sin(nu)*sin(nu) + pars->r_minor*pars->r_minor*cos(nu)*cos(nu) ); 
    58   qL = q*pars->length*cos(alpha)/2.0; 
     57  qr = q*sqrt( r_major*r_major*cos_nu*cos_nu + pars->r_minor*pars->r_minor*cos_mu*cos_mu ); 
     58  qL = q*pars->length*cos_val/2.0; 
    5959 
    6060  if (qr==0){ 
     
    8383 */ 
    8484static double elliptical_cylinder_analytical_2D_scaled(EllipticalCylinderParameters *pars, double q, double q_x, double q_y) { 
    85   double cyl_x, cyl_y, cyl_z; 
    86   double ell_x, ell_y; 
    87   double q_z; 
    88   double alpha, vol, cos_val; 
    89   double nu, cos_nu; 
     85  double cyl_x, cyl_y;//, cyl_z; 
     86  double ella_x, ella_y, ellb_x, ellb_y; 
     87  //double q_z; 
     88  double vol, cos_val; 
     89  double cos_mu, cos_nu; 
    9090  double answer; 
    9191  //convert angle degree to radian 
     
    9696 
    9797  //Cylinder orientation 
    98   cyl_x = sin(theta) * cos(phi); 
    99   cyl_y = sin(theta) * sin(phi); 
    100   cyl_z = cos(theta); 
     98  cyl_x = cos(theta) * cos(phi); 
     99  cyl_y = sin(theta); 
     100  //cyl_z = -cos(theta) * sin(phi); 
    101101 
    102102  // q vector 
    103   q_z = 0; 
    104  
    105   // Compute the angle btw vector q and the 
    106   // axis of the cylinder 
    107   cos_val = cyl_x*q_x + cyl_y*q_y + cyl_z*q_z; 
    108  
    109   // The following test should always pass 
    110   if (fabs(cos_val)>1.0) { 
    111     printf("cyl_ana_2D: Unexpected error: cos(alpha)>1\n"); 
    112     return 0; 
    113   } 
     103  //q_z = 0; 
    114104 
    115105  // Note: cos(alpha) = 0 and 1 will get an 
    116106  // undefined value from CylKernel 
    117   alpha = acos( cos_val ); 
     107  //alpha = acos( cos_val ); 
    118108 
    119109  //ellipse orientation: 
     
    125115 
    126116  //x- y- component on the detector plane. 
    127   ell_x =  cos(psi); 
    128   ell_y =  sin(psi); 
     117  ella_x =  -cos(phi)*sin(psi) * sin(theta)+sin(phi)*cos(psi); 
     118  ella_y =  sin(psi)*cos(theta); 
     119  ellb_x =  -sin(theta)*cos(psi)*cos(phi)-sin(psi)*sin(phi); 
     120  ellb_y =  cos(theta)*cos(psi); 
     121   
     122  // Compute the angle btw vector q and the 
     123  // axis of the cylinder 
     124  cos_val = cyl_x*q_x + cyl_y*q_y;// + cyl_z*q_z; 
    129125 
    130126  // calculate the axis of the ellipse wrt q-coord. 
    131   cos_nu = ell_x*q_x + ell_y*q_y; 
    132   nu = acos(cos_nu); 
    133  
     127  cos_nu = ella_x*q_x + ella_y*q_y; 
     128  cos_mu = ellb_x*q_x + ellb_y*q_y; 
     129   
    134130  // The following test should always pass 
     131  if (fabs(cos_val)>1.0) { 
     132    //printf("cyl_ana_2D: Unexpected error: cos(alpha)>1\n"); 
     133    cos_val = 1.0; 
     134  } 
    135135  if (fabs(cos_nu)>1.0) { 
    136     printf("cyl_ana_2D: Unexpected error: cos(nu)>1\n"); 
    137     return 0; 
    138   } 
    139  
    140   answer = elliptical_cylinder_kernel(pars, q, alpha,nu); 
     136    //printf("cyl_ana_2D: Unexpected error: cos(nu)>1\n"); 
     137    cos_nu = 1.0; 
     138  } 
     139  if (fabs(cos_mu)>1.0) { 
     140    //printf("cyl_ana_2D: Unexpected error: cos(nu)>1\n"); 
     141    cos_mu = 1.0; 
     142  } 
     143  answer = elliptical_cylinder_kernel(pars, q, cos_val, cos_nu, cos_mu); 
    141144 
    142145  // Multiply by contrast^2 
     
    347350              * weights_rat[m].value; 
    348351              if (weights_theta.size()>1) { 
    349                 _ptvalue *= fabs(sin(weights_theta[k].value*pi/180.0)); 
     352                _ptvalue *= fabs(cos(weights_theta[k].value*pi/180.0)); 
    350353              } 
    351354              sum += _ptvalue; 
  • sansmodels/src/c_models/fcc.cpp

    re08bd5b r318b5bbb  
    5353 */ 
    5454static double fc_analytical_2D_scaled(FCParameters *pars, double q, double q_x, double q_y) { 
    55   double b3_x, b3_y, b3_z, b1_x, b1_y; 
     55  double b3_x, b3_y, b3_z, b1_x, b1_y, b2_x, b2_y; 
    5656  double q_z; 
    57   double alpha, cos_val_b3, cos_val_b2, cos_val_b1; 
     57  double cos_val_b3, cos_val_b2, cos_val_b1; 
    5858  double a1_dot_q, a2_dot_q,a3_dot_q; 
    5959  double answer; 
     
    8383  ///  instead of against q coordinate in PRB 36(46), 3(6), 1754(3854) 
    8484  // b3 axis orientation 
    85   b3_x = sin(theta) * cos(phi);//negative sign here??? 
    86   b3_y = sin(theta) * sin(phi); 
    87   b3_z = cos(theta); 
    88   cos_val_b3 =  b3_x*q_x + b3_y*q_y + b3_z*q_z; 
    89   alpha = acos(cos_val_b3); 
     85  b3_x = cos(theta) * cos(phi); 
     86  b3_y = sin(theta); 
     87  //b3_z = -cos(theta) * sin(phi); 
     88  cos_val_b3 =  b3_x*q_x + b3_y*q_y;// + b3_z*q_z; 
     89   
    9090  // b1 axis orientation 
    91   b1_x = sin(psi); 
    92   b1_y = cos(psi); 
    93   cos_val_b1 = (b1_x*q_x + b1_y*q_y); 
     91  b1_x = -cos(phi)*sin(psi) * sin(theta)+sin(phi)*cos(psi); 
     92  b1_y = sin(psi)*cos(theta); 
     93  cos_val_b1 = b1_x*q_x + b1_y*q_y; 
     94   
    9495  // b2 axis orientation 
    95   cos_val_b2 = sin(acos(cos_val_b1)); 
    96   // alpha correction 
    97   cos_val_b2 *= sin(alpha); 
    98   cos_val_b1 *= sin(alpha); 
    99  
     96  b2_x = -sin(theta)*cos(psi)*cos(phi)-sin(psi)*sin(phi); 
     97  b2_y = cos(theta)*cos(psi); 
     98  cos_val_b2 =  b2_x*q_x + b2_y*q_y; 
     99   
     100  // The following test should always pass 
     101  if (fabs(cos_val_b3)>1.0) { 
     102    //printf("bcc_ana_2D: Unexpected error: cos()>1\n"); 
     103    cos_val_b3 = 1.0; 
     104  } 
     105  if (fabs(cos_val_b2)>1.0) { 
     106    //printf("bcc_ana_2D: Unexpected error: cos()>1\n"); 
     107    cos_val_b2 = 1.0; 
     108  } 
     109  if (fabs(cos_val_b1)>1.0) { 
     110    //printf("bcc_ana_2D: Unexpected error: cos()>1\n"); 
     111    cos_val_b1 = 1.0; 
     112  } 
    100113  // Compute the angle btw vector q and the a3 axis 
    101114  a3_dot_q = 0.5*aa*q*(cos_val_b2+cos_val_b1); 
     
    107120  a2_dot_q = 0.5*aa*q*(cos_val_b3+cos_val_b1); 
    108121 
    109   // The following test should always pass 
    110   if (fabs(cos_val_b3)>1.0) { 
    111     printf("fcc_ana_2D: Unexpected error: cos(alpha)>1\n"); 
    112     return 0; 
    113   } 
     122 
    114123  // Get Fkq and Fkq_2 
    115124  Fkq = exp(-0.5*pow(Da/aa,2.0)*(a1_dot_q*a1_dot_q+a2_dot_q*a2_dot_q+a3_dot_q*a3_dot_q)); 
     
    282291          } 
    283292          if (weights_theta.size()>1) { 
    284             _ptvalue *= fabs(sin(weights_theta[j].value*pi/180.0)); 
     293            _ptvalue *= fabs(cos(weights_theta[j].value*pi/180.0)); 
    285294          } 
    286295          sum += _ptvalue; 
  • sansmodels/src/c_models/hollowcylinder.cpp

    re08bd5b r318b5bbb  
    5353static double hollow_cylinder_analytical_2D_scaled(HollowCylinderParameters *pars, double q, double q_x, double q_y) { 
    5454  double cyl_x, cyl_y, cyl_z; 
    55   double q_z; 
     55  //double q_z; 
    5656  double  alpha,vol, cos_val; 
    5757  double answer; 
     
    6262 
    6363  // Cylinder orientation 
    64   cyl_x = sin(theta) * cos(phi); 
    65   cyl_y = sin(theta) * sin(phi); 
    66   cyl_z = cos(theta); 
     64  cyl_x = cos(theta) * cos(phi); 
     65  cyl_y = sin(theta); 
     66  //cyl_z = -cos(theta) * sin(phi); 
    6767 
    6868  // q vector 
    69   q_z = 0; 
     69  //q_z = 0; 
    7070 
    7171  // Compute the angle btw vector q and the 
    7272  // axis of the cylinder 
    73   cos_val = cyl_x*q_x + cyl_y*q_y + cyl_z*q_z; 
     73  cos_val = cyl_x*q_x + cyl_y*q_y;// + cyl_z*q_z; 
    7474 
    7575  // The following test should always pass 
     
    280280                * weights_length[j].value); 
    281281            if (weights_theta.size()>1) { 
    282               _ptvalue *= fabs(sin(weights_theta[k].value * pi/180.0)); 
     282              _ptvalue *= fabs(cos(weights_theta[k].value * pi/180.0)); 
    283283            } 
    284284            sum += _ptvalue; 
  • sansmodels/src/c_models/libfunc.c

    r5da3cc5 r318b5bbb  
    103103    return -tmp+log(2.5066282746310005*ser/x); 
    104104} 
     105 
     106// calculate magnetic sld and return total sld 
     107// bn : contrast (not just sld of the layer) 
     108// m0: max mag of M; mtheta: angle from x-z plane; 
     109// mphi: angle (anti-clock-wise)of x-z projection(M) from x axis 
     110// spinfraci: the fraction of UP among UP+Down (before sample) 
     111// spinfracf: the fraction of UP among UP+Down (after sample and before detector) 
     112// spintheta: angle (anti-clock-wise) between neutron spin(up) and x axis 
     113// Note: all angles are in degrees. 
     114polar_sld cal_msld(int isangle, double qx, double qy, double bn, 
     115                                double m01, double mtheta1, double mphi1, 
     116                                double spinfraci, double spinfracf, double spintheta) 
     117{ 
     118        //locals 
     119        double q_x = qx; 
     120        double q_y = qy; 
     121        double sld = bn; 
     122        int is_angle = isangle; 
     123        double pi = 4.0*atan(1.0); 
     124        double s_theta = spintheta * pi/180.0; 
     125        double m_max = m01; 
     126        double m_phi = mphi1; 
     127        double m_theta = mtheta1; 
     128        double in_spin = spinfraci; 
     129        double out_spin = spinfracf; 
     130 
     131        double m_perp = 0.0; 
     132        double m_perp_z = 0.0; 
     133        double m_perp_y = 0.0; 
     134        double m_perp_x = 0.0; 
     135        double m_sigma_x = 0.0; 
     136        double m_sigma_z = 0.0; 
     137        double m_sigma_y = 0.0; 
     138        double b_m = 0.0; 
     139        double q_angle = 0.0; 
     140        double mx = 0.0; 
     141        double my = 0.0; 
     142        double mz = 0.0; 
     143        polar_sld p_sld; 
     144        p_sld.uu = sld; 
     145        p_sld.dd = sld; 
     146        p_sld.re_ud = 0.0; 
     147        p_sld.im_ud = 0.0; 
     148        p_sld.re_du = 0.0; 
     149        p_sld.im_du = 0.0; 
     150 
     151        //No mag means no further calculation 
     152        if (isangle>0){ 
     153                if (m_max < 1.0e-32){ 
     154                        p_sld.uu = sqrt(sqrt(in_spin * out_spin)) * p_sld.uu; 
     155                        p_sld.dd = sqrt(sqrt((1.0 - in_spin) * (1.0 - out_spin))) * p_sld.dd; 
     156                        return p_sld; 
     157                } 
     158        } 
     159        else{ 
     160                if (fabs(m_max)< 1.0e-32 && fabs(m_phi)< 1.0e-32 && fabs(m_theta)< 1.0e-32){ 
     161                        p_sld.uu = sqrt(sqrt(in_spin * out_spin)) * p_sld.uu; 
     162                        p_sld.dd = sqrt(sqrt((1.0 - in_spin) * (1.0 - out_spin))) * p_sld.dd; 
     163                        return p_sld; 
     164                } 
     165        } 
     166 
     167        //These are needed because of the precision of inputs 
     168        if (in_spin < 0.0) in_spin = 0.0; 
     169        if (in_spin > 1.0) in_spin = 1.0; 
     170        if (out_spin < 0.0) out_spin = 0.0; 
     171        if (out_spin > 1.0) out_spin = 1.0; 
     172 
     173        if (q_x == 0.0) q_angle = pi / 2.0; 
     174        else q_angle = atan(q_y/q_x); 
     175        if (q_y < 0.0 && q_x < 0.0) q_angle -= pi; 
     176        else if (q_y > 0.0 && q_x < 0.0) q_angle += pi; 
     177 
     178        q_angle = pi/2.0 - q_angle; 
     179        if (q_angle > pi) q_angle -= 2.0 * pi; 
     180        else if (q_angle < -pi) q_angle += 2.0 * pi; 
     181 
     182        if (fabs(q_x) < 1.0e-16 && fabs(q_y) < 1.0e-16){ 
     183                m_perp = 0.0; 
     184                } 
     185        else { 
     186                m_perp = m_max; 
     187                } 
     188        if (is_angle > 0){ 
     189                m_phi *= pi/180.0; 
     190                m_theta *= pi/180.0; 
     191                mx = m_perp * cos(m_theta) * cos(m_phi); 
     192                my = m_perp * sin(m_theta); 
     193                mz = -(m_perp * cos(m_theta) * sin(m_phi)); 
     194        } 
     195        else{ 
     196                mx = m_perp; 
     197                my = m_phi; 
     198                mz = m_theta; 
     199        } 
     200        //ToDo: simplify these steps 
     201        // m_perp1 -m_perp2 
     202        m_perp_x = (mx) *  cos(q_angle); 
     203        m_perp_x -= (my) * sin(q_angle); 
     204        m_perp_y = m_perp_x; 
     205        m_perp_x *= cos(-q_angle); 
     206        m_perp_y *= sin(-q_angle); 
     207        m_perp_z = mz; 
     208 
     209        m_sigma_x = (m_perp_x * cos(-s_theta) - m_perp_y * sin(-s_theta)); 
     210        m_sigma_y = (m_perp_x * sin(-s_theta) + m_perp_y * cos(-s_theta)); 
     211        m_sigma_z = (m_perp_z); 
     212 
     213        //Find b 
     214        p_sld.uu -= m_sigma_x; 
     215        p_sld.dd += m_sigma_x; 
     216        p_sld.re_ud = m_sigma_y; 
     217        p_sld.re_du = m_sigma_y; 
     218        p_sld.im_ud = m_sigma_z; 
     219        p_sld.im_du = -m_sigma_z; 
     220 
     221        p_sld.uu = sqrt(sqrt(in_spin * out_spin)) * p_sld.uu; 
     222        p_sld.dd = sqrt(sqrt((1.0 - in_spin) * (1.0 - out_spin))) * p_sld.dd; 
     223 
     224        p_sld.re_ud = sqrt(sqrt(in_spin * (1.0 - out_spin))) * p_sld.re_ud; 
     225        p_sld.im_ud = sqrt(sqrt(in_spin * (1.0 - out_spin))) * p_sld.im_ud; 
     226        p_sld.re_du = sqrt(sqrt((1.0 - in_spin) * out_spin)) * p_sld.re_du; 
     227        p_sld.im_du = sqrt(sqrt((1.0 - in_spin) * out_spin)) * p_sld.im_du; 
     228 
     229        return p_sld; 
     230} 
     231 
    105232 
    106233/** Modifications below by kieranrcampbell@gmail.com 
     
    131258    ap = a; 
    132259    del = sum = 1.0/a; 
    133      
     260 
    134261    for(n=1;n<=ITMAX;n++) { 
    135262      ++ap; 
     
    150277 
    151278/** 
    152    Implements the incomplete gamma function Q(a,x) evaluated by its continued fraction  
    153    representation  
     279   Implements the incomplete gamma function Q(a,x) evaluated by its continued fraction 
     280   representation 
    154281**/ 
    155282 
     
    196323} 
    197324 
    198 /**  
     325/** 
    199326    Implementation of the error function, erf(x) 
    200327**/ 
  • sansmodels/src/c_models/parallelepiped.cpp

    re08bd5b r318b5bbb  
    2929        #include "libCylinder.h" 
    3030        #include "libStructureFactor.h" 
     31        #include "libmultifunc/libfunc.h" 
    3132} 
    3233#include "parallelepiped.h" 
     
    4445    double parallel_phi; 
    4546    double parallel_psi; 
     47    double M0_sld_pipe; 
     48    double M_theta_pipe; 
     49    double M_phi_pipe; 
     50    double M0_sld_solv; 
     51    double M_theta_solv; 
     52    double M_phi_solv; 
     53    double Up_frac_i; 
     54        double Up_frac_f; 
     55        double Up_theta; 
    4656} ParallelepipedParameters; 
    4757 
     
    8595 */ 
    8696static double parallelepiped_analytical_2D_scaled(ParallelepipedParameters *pars, double q, double q_x, double q_y) { 
    87   double cparallel_x, cparallel_y, cparallel_z, bparallel_x, bparallel_y, parallel_x, parallel_y; 
    88   double q_z; 
    89   double alpha, vol, cos_val_c, cos_val_b, cos_val_a, edgeA, edgeB, edgeC; 
    90  
    91   double answer; 
     97  double cparallel_x, cparallel_y, bparallel_x, bparallel_y, parallel_x, parallel_y; 
     98  //double q_z; 
     99  double vol, cos_val_c, cos_val_b, cos_val_a, edgeA, edgeB, edgeC; 
     100 
     101  double answer = 0.0; 
     102  double form = 0.0; 
    92103  double pi = 4.0*atan(1.0); 
    93  
     104   
    94105  //convert angle degree to radian 
    95106  double theta = pars->parallel_theta * pi/180.0; 
    96107  double phi = pars->parallel_phi * pi/180.0; 
    97108  double psi = pars->parallel_psi * pi/180.0; 
    98  
     109  double sld_solv = pars->sldSolv; 
     110  double sld_pipe = pars->sldPipe; 
     111  double m_max = pars->M0_sld_pipe; 
     112  double m_max_solv = pars->M0_sld_solv; 
     113  double contrast = 0.0; 
     114     
    99115  edgeA = pars->short_a; 
    100116  edgeB = pars->short_b; 
     
    103119 
    104120    // parallelepiped c axis orientation 
    105     cparallel_x = sin(theta) * cos(phi); 
    106     cparallel_y = sin(theta) * sin(phi); 
    107     cparallel_z = cos(theta); 
     121    cparallel_x = cos(theta) * cos(phi); 
     122    cparallel_y = sin(theta); 
     123    //cparallel_z = -cos(theta) * sin(phi); 
    108124 
    109125    // q vector 
    110     q_z = 0.0; 
     126    //q_z = 0.0; 
    111127 
    112128    // Compute the angle btw vector q and the 
    113129    // axis of the parallelepiped 
    114     cos_val_c = cparallel_x*q_x + cparallel_y*q_y + cparallel_z*q_z; 
    115     alpha = acos(cos_val_c); 
     130    cos_val_c = cparallel_x*q_x + cparallel_y*q_y;// + cparallel_z*q_z; 
     131    //alpha = acos(cos_val_c); 
    116132 
    117133    // parallelepiped a axis orientation 
    118     parallel_x = sin(psi);//cos(pars->parallel_theta) * sin(pars->parallel_phi)*sin(pars->parallel_psi); 
    119     parallel_y = cos(psi);//cos(pars->parallel_theta) * cos(pars->parallel_phi)*cos(pars->parallel_psi); 
    120  
     134    parallel_x = -cos(phi)*sin(psi) * sin(theta)+sin(phi)*cos(psi); 
     135    parallel_y = sin(psi)*cos(theta); 
     136        //parallel_z = sin(theta)*sin(phi)*sin(psi)+cos(phi)*cos(psi); 
     137         
    121138    cos_val_a = parallel_x*q_x + parallel_y*q_y; 
    122139 
    123  
    124  
    125140    // parallelepiped b axis orientation 
    126     bparallel_x = sqrt(1.0-sin(theta)*cos(phi))*cos(psi);//cos(pars->parallel_theta) * cos(pars->parallel_phi)* cos(pars->parallel_psi); 
    127     bparallel_y = sqrt(1.0-sin(theta)*cos(phi))*sin(psi);//cos(pars->parallel_theta) * sin(pars->parallel_phi)* sin(pars->parallel_psi); 
     141    bparallel_x = -sin(theta)*cos(psi)*cos(phi)-sin(psi)*sin(phi); 
     142    bparallel_y = cos(theta)*cos(psi); 
     143    //bparallel_z = sin(theta)*sin(phi)*cos(psi)-sin(psi)*cos(phi); 
     144     
    128145    // axis of the parallelepiped 
    129     cos_val_b = sin(acos(cos_val_a)) ; 
    130  
    131  
     146    cos_val_b = bparallel_x*q_x + bparallel_y*q_y; 
    132147 
    133148    // The following test should always pass 
    134149    if (fabs(cos_val_c)>1.0) { 
    135       printf("parallel_ana_2D: Unexpected error: cos(alpha)>1\n"); 
    136       return 0; 
     150      //printf("parallel_ana_2D: Unexpected error: cos(alpha)>1\n"); 
     151      cos_val_c = 1.0; 
    137152    } 
    138  
     153    if (fabs(cos_val_a)>1.0) { 
     154      //printf("parallel_ana_2D: Unexpected error: cos(alpha)>1\n"); 
     155      cos_val_a = 1.0; 
     156    } 
     157    if (fabs(cos_val_b)>1.0) { 
     158      //printf("parallel_ana_2D: Unexpected error: cos(alpha)>1\n"); 
     159      cos_val_b = 1.0; 
     160    } 
    139161  // Call the IGOR library function to get the kernel 
    140   answer = pkernel( q*edgeA, q*edgeB, q*edgeC, sin(alpha)*cos_val_a,sin(alpha)*cos_val_b,cos_val_c); 
    141  
    142   // Multiply by contrast^2 
    143   answer *= (pars->sldPipe - pars->sldSolv) * (pars->sldPipe - pars->sldSolv); 
     162  form = pkernel( q*edgeA, q*edgeB, q*edgeC, cos_val_a, cos_val_b, cos_val_c); 
     163   
     164  if (m_max < 1.0e-32 && m_max_solv < 1.0e-32){ 
     165      // Multiply by contrast^2 
     166      contrast = (pars->sldPipe - pars->sldSolv); 
     167          answer = contrast * contrast * form; 
     168  } 
     169  else{ 
     170          double qx = q_x; 
     171          double qy = q_y; 
     172          double s_theta = pars->Up_theta; 
     173          double m_phi = pars->M_phi_pipe; 
     174          double m_theta = pars->M_theta_pipe; 
     175          double m_phi_solv = pars->M_phi_solv; 
     176          double m_theta_solv = pars->M_theta_solv; 
     177          double in_spin = pars->Up_frac_i; 
     178          double out_spin = pars->Up_frac_f; 
     179          polar_sld p_sld; 
     180          polar_sld p_sld_solv; 
     181          p_sld = cal_msld(1, qx, qy, sld_pipe, m_max, m_theta, m_phi,  
     182                                        in_spin, out_spin, s_theta); 
     183          p_sld_solv = cal_msld(1, qx, qy, sld_solv, m_max_solv, m_theta_solv, m_phi_solv,  
     184                                                in_spin, out_spin, s_theta); 
     185          //up_up        
     186          if (in_spin > 0.0 && out_spin > 0.0){                   
     187                  answer += ((p_sld.uu- p_sld_solv.uu) * (p_sld.uu- p_sld_solv.uu) * form); 
     188                  } 
     189          //down_down 
     190          if (in_spin < 1.0 && out_spin < 1.0){ 
     191                  answer += ((p_sld.dd - p_sld_solv.dd) * (p_sld.dd - p_sld_solv.dd) * form); 
     192                  } 
     193          //up_down 
     194          if (in_spin > 0.0 && out_spin < 1.0){ 
     195                  answer += ((p_sld.re_ud - p_sld_solv.re_ud) * (p_sld.re_ud - p_sld_solv.re_ud) * form); 
     196                  answer += ((p_sld.im_ud - p_sld_solv.im_ud) * (p_sld.im_ud - p_sld_solv.im_ud) * form); 
     197                  } 
     198          //down_up      
     199          if (in_spin < 1.0 && out_spin > 0.0){ 
     200                  answer += ((p_sld.re_du - p_sld_solv.re_du) * (p_sld.re_du - p_sld_solv.re_du) * form); 
     201                  answer += ((p_sld.im_du - p_sld_solv.im_du) * (p_sld.im_du - p_sld_solv.im_du) * form); 
     202                  } 
     203  } 
     204   
    144205 
    145206  //normalize by cylinder volume 
    146207  //NOTE that for this (Fournet) definition of the integral, one must MULTIPLY by Vparallel 
    147     vol = edgeA* edgeB * edgeC; 
     208  vol = edgeA* edgeB * edgeC; 
    148209  answer *= vol; 
    149210 
     
    186247        parallel_phi    = Parameter(0.0, true); 
    187248        parallel_psi    = Parameter(0.0, true); 
     249        M0_sld_pipe = Parameter(0.0e-6); 
     250        M_theta_pipe = Parameter(0.0); 
     251        M_phi_pipe = Parameter(0.0);  
     252        M0_sld_solv = Parameter(0.0e-6); 
     253        M_theta_solv = Parameter(0.0); 
     254        M_phi_solv = Parameter(0.0);  
     255        Up_frac_i = Parameter(0.5);  
     256        Up_frac_f = Parameter(0.5); 
     257        Up_theta = Parameter(0.0); 
    188258} 
    189259 
     
    279349        dp.parallel_phi    = parallel_phi(); 
    280350        dp.parallel_psi    = parallel_psi(); 
     351        dp.Up_theta =  Up_theta(); 
     352        dp.M_phi_pipe =  M_phi_pipe(); 
     353        dp.M_theta_pipe =  M_theta_pipe(); 
     354        dp.M0_sld_pipe =  M0_sld_pipe(); 
     355        dp.M_phi_solv =  M_phi_solv(); 
     356        dp.M_theta_solv =  M_theta_solv(); 
     357        dp.M0_sld_solv =  M0_sld_solv(); 
     358        dp.Up_frac_i =  Up_frac_i(); 
     359        dp.Up_frac_f =  Up_frac_f(); 
    281360 
    282361 
     
    346425 
    347426                                                        if (weights_parallel_theta.size()>1) { 
    348                                                                 _ptvalue *= fabs(sin(weights_parallel_theta[l].value*pi/180.0)); 
     427                                                                _ptvalue *= fabs(cos(weights_parallel_theta[l].value*pi/180.0)); 
    349428                                                        } 
    350429                                                        sum += _ptvalue; 
  • sansmodels/src/c_models/sc.cpp

    re08bd5b r318b5bbb  
    5555  double a3_x, a3_y, a3_z, a2_x, a2_y, a1_x, a1_y; 
    5656  double q_z; 
    57   double alpha, cos_val_a3, cos_val_a2, cos_val_a1; 
     57  double cos_val_a3, cos_val_a2, cos_val_a1; 
    5858  double a1_dot_q, a2_dot_q,a3_dot_q; 
    5959  double answer; 
     
    8080  /// Angles here are respect to detector coordinate instead of against q coordinate(PRB 36, 3, 1754) 
    8181  // a3 axis orientation 
    82   a3_x = sin(theta) * cos(phi);//negative sign here??? 
    83   a3_y = sin(theta) * sin(phi); 
    84   a3_z = cos(theta); 
    85  
     82  a3_x = cos(theta) * cos(phi); 
     83  a3_y = sin(theta); 
     84  //a3_z = -cos(theta) * sin(phi); 
    8685  // q vector 
    8786  q_z = 0.0; 
    8887 
    8988  // Compute the angle btw vector q and the a3 axis 
    90   cos_val_a3 = a3_x*q_x + a3_y*q_y + a3_z*q_z; 
    91   alpha = acos(cos_val_a3); 
    92   //alpha = acos(cos_val_a3); 
    93   a3_dot_q = aa*q*cos_val_a3; 
     89  cos_val_a3 = a3_x*q_x + a3_y*q_y;// + a3_z*q_z; 
     90 
    9491  // a1 axis orientation 
    95   a1_x = sin(psi); 
    96   a1_y = cos(psi); 
     92  a1_x = -cos(phi)*sin(psi) * sin(theta)+sin(phi)*cos(psi); 
     93  a1_y = sin(psi)*cos(theta); 
    9794 
    9895  cos_val_a1 = a1_x*q_x + a1_y*q_y; 
    99   a1_dot_q = aa*q*cos_val_a1*sin(alpha); 
    10096 
    10197  // a2 axis orientation 
    102   a2_x = sqrt(1.0-sin(theta)*cos(phi))*cos(psi); 
    103   a2_y = sqrt(1.0-sin(theta)*cos(phi))*sin(psi); 
     98  a2_x = -sin(theta)*cos(psi)*cos(phi)-sin(psi)*sin(phi); 
     99  a2_y = cos(theta)*cos(psi); 
    104100  // a2 axis 
    105   cos_val_a2 =  sin(acos(cos_val_a1));//a2_x*q_x + a2_y*q_y; 
    106   a2_dot_q = aa*q*cos_val_a2*sin(alpha); 
     101  cos_val_a2 =  a2_x*q_x + a2_y*q_y; 
    107102 
    108103  // The following test should always pass 
    109104  if (fabs(cos_val_a3)>1.0) { 
    110     printf("parallel_ana_2D: Unexpected error: cos(alpha)>1\n"); 
    111     return 0; 
    112   } 
     105    //printf("parallel_ana_2D: Unexpected error: cos(alpha)>1\n"); 
     106    cos_val_a3 = 1.0; 
     107  } 
     108   if (fabs(cos_val_a1)>1.0) { 
     109    //printf("parallel_ana_2D: Unexpected error: cos(alpha)>1\n"); 
     110    cos_val_a1 = 1.0; 
     111  } 
     112   if (fabs(cos_val_a2)>1.0) { 
     113    //printf("parallel_ana_2D: Unexpected error: cos(alpha)>1\n"); 
     114    cos_val_a3 = 1.0; 
     115  } 
     116  a3_dot_q = aa*q*cos_val_a3; 
     117  a1_dot_q = aa*q*cos_val_a1;//*sin(alpha); 
     118  a2_dot_q = aa*q*cos_val_a2; 
     119   
    113120  // Call Zq=Z1*Z2*Z3 
    114121  Zq = (1.0-exp(-qDa_2))/(1.0-2.0*exp(-0.5*qDa_2)*cos(a1_dot_q)+exp(-qDa_2)); 
    115   Zq = Zq * (1.0-exp(-qDa_2))/(1.0-2.0*exp(-0.5*qDa_2)*cos(a2_dot_q)+exp(-qDa_2)); 
    116   Zq = Zq * (1.0-exp(-qDa_2))/(1.0-2.0*exp(-0.5*qDa_2)*cos(a3_dot_q)+exp(-qDa_2)); 
     122  Zq *= (1.0-exp(-qDa_2))/(1.0-2.0*exp(-0.5*qDa_2)*cos(a2_dot_q)+exp(-qDa_2)); 
     123  Zq *= (1.0-exp(-qDa_2))/(1.0-2.0*exp(-0.5*qDa_2)*cos(a3_dot_q)+exp(-qDa_2)); 
    117124 
    118125  // Use SphereForm directly from libigor 
     
    278285          } 
    279286          if (weights_theta.size()>1) { 
    280             _ptvalue *= fabs(sin(weights_theta[j].value*pi/180.0)); 
     287            _ptvalue *= fabs(cos(weights_theta[j].value*pi/180.0)); 
    281288          } 
    282289          sum += _ptvalue; 
  • sansmodels/src/c_models/sphere.cpp

    re08bd5b r318b5bbb  
    2828extern "C" { 
    2929        #include "libSphere.h" 
    30 } 
     30        #include "libmultifunc/libfunc.h" 
     31} 
     32// Convenience parameter structure 
     33typedef struct { 
     34    double scale; 
     35    double radius; 
     36    double sldSph; 
     37    double sldSolv; 
     38    double background; 
     39    double M0_sld_sph; 
     40    double M_theta_sph; 
     41    double M_phi_sph; 
     42    double M0_sld_solv; 
     43    double M_theta_solv; 
     44    double M_phi_solv; 
     45    double Up_frac_i; 
     46        double Up_frac_f; 
     47        double Up_theta; 
     48} SphereParameters; 
    3149 
    3250SphereModel :: SphereModel() { 
     
    3755        sldSolv   = Parameter(1.0e-6); 
    3856        background = Parameter(0.0); 
     57        M0_sld_sph = Parameter(0.0e-6); 
     58        M_theta_sph = Parameter(0.0); 
     59        M_phi_sph = Parameter(0.0);  
     60        M0_sld_solv = Parameter(0.0e-6); 
     61        M_theta_solv = Parameter(0.0); 
     62        M_phi_solv = Parameter(0.0);  
     63        Up_frac_i = Parameter(0.5);  
     64        Up_frac_f = Parameter(0.5); 
     65        Up_theta = Parameter(0.0); 
    3966} 
    4067 
     
    87114/** 
    88115 * Function to evaluate 2D scattering function 
     116 * @param pars: parameters 
     117 * @param q: q-value 
     118 * @param q_x: q_x / q 
     119 * @param q_y: q_y / q 
     120 * @return: function value 
     121 */ 
     122 
     123static double sphere_analytical_2D_scaled(SphereParameters *pars, double q, double q_x, double q_y) { 
     124        double dp[5]; 
     125        //convert angle degree to radian 
     126        dp[0] = 1.0; 
     127        dp[1] = pars->radius; 
     128        dp[2] = 0.0; 
     129        dp[3] = 0.0; 
     130        dp[4] = 0.0; 
     131 
     132    double sldSph = pars->sldSph; 
     133    double sldSolv = pars->sldSolv; 
     134        double answer = 0.0; 
     135        double m_max = pars->M0_sld_sph; 
     136        double m_max_solv = pars->M0_sld_solv; 
     137 
     138        if (m_max < 1.0e-32 && m_max_solv < 1.0e-32){ 
     139                dp[2] = sldSph; 
     140                dp[3] = sldSolv; 
     141                answer = SphereForm(dp, q); 
     142        } 
     143        else{ 
     144                double contrast = sldSph - sldSolv; 
     145                double qx = q_x; 
     146                double qy = q_y; 
     147                double s_theta = pars->Up_theta; 
     148                double m_phi = pars->M_phi_sph; 
     149                double m_theta = pars->M_theta_sph; 
     150                double m_phi_solv = pars->M_phi_solv; 
     151                double m_theta_solv = pars->M_theta_solv; 
     152                double in_spin = pars->Up_frac_i; 
     153                double out_spin = pars->Up_frac_f; 
     154                polar_sld p_sld; 
     155                polar_sld p_sld_solv; 
     156                p_sld = cal_msld(1, qx, qy, sldSph, m_max, m_theta, m_phi,  
     157                                                        in_spin, out_spin, s_theta); 
     158                p_sld_solv = cal_msld(1, qx, qy, sldSolv, m_max_solv, m_theta_solv, m_phi_solv,  
     159                                                                in_spin, out_spin, s_theta); 
     160                //up_up  
     161                if (in_spin > 0.0 && out_spin > 0.0){                     
     162                        dp[2] = p_sld.uu; 
     163                        dp[3] = p_sld_solv.uu; 
     164                        answer += SphereForm(dp, q); 
     165                        } 
     166                //down_down 
     167                if (in_spin < 1.0 && out_spin < 1.0){ 
     168                        dp[2] = p_sld.dd; 
     169                        dp[3] = p_sld_solv.dd; 
     170                        answer += SphereForm(dp, q); 
     171                        } 
     172                //up_down 
     173                if (in_spin > 0.0 && out_spin < 1.0){ 
     174                        dp[2] = p_sld.re_ud; 
     175                        dp[3] = p_sld_solv.re_ud; 
     176                        answer += SphereForm(dp, q);     
     177                        dp[2] = p_sld.im_ud; 
     178                        dp[3] = p_sld_solv.im_ud; 
     179                        answer += SphereForm(dp, q); 
     180                        } 
     181                //down_up        
     182                if (in_spin < 1.0 && out_spin > 0.0){ 
     183                        dp[2] = p_sld.re_du; 
     184                        dp[3] = p_sld_solv.re_du; 
     185                        answer += SphereForm(dp, q);     
     186                        dp[2] = p_sld.im_du; 
     187                        dp[3] = p_sld_solv.im_du; 
     188                        answer += SphereForm(dp, q); 
     189                        } 
     190        } 
     191         
     192        // add in the background 
     193        answer *= pars->scale; 
     194        answer += pars->background; 
     195        return answer; 
     196} 
     197 
     198 
     199/** 
     200 * Function to evaluate 2D scattering function 
     201 * @param pars: parameters 
     202 * @param q: q-value 
     203 * @return: function value 
     204 */ 
     205static double sphere_analytical_2DXY(SphereParameters *pars, double qx, double qy) { 
     206  double q; 
     207  q = sqrt(qx*qx+qy*qy); 
     208  return sphere_analytical_2D_scaled(pars, q, qx/q, qy/q); 
     209} 
     210 
     211 
     212/** 
     213 * Function to evaluate 2D scattering function 
    89214 * @param q_x: value of Q along x 
    90215 * @param q_y: value of Q along y 
     
    92217 */ 
    93218double SphereModel :: operator()(double qx, double qy) { 
    94         double q = sqrt(qx*qx + qy*qy); 
    95         return (*this).operator()(q); 
     219        SphereParameters dp; 
     220        dp.scale = scale(); 
     221        dp.radius = radius(); 
     222        dp.sldSph = sldSph(); 
     223        dp.sldSolv = sldSolv(); 
     224        dp.background = 0.0; 
     225        dp.Up_theta =  Up_theta(); 
     226        dp.M_phi_sph =  M_phi_sph(); 
     227        dp.M_theta_sph =  M_theta_sph(); 
     228        dp.M0_sld_sph =  M0_sld_sph(); 
     229        dp.M_phi_solv =  M_phi_solv(); 
     230        dp.M_theta_solv =  M_theta_solv(); 
     231        dp.M0_sld_solv =  M0_sld_solv(); 
     232        dp.Up_frac_i =  Up_frac_i(); 
     233        dp.Up_frac_f =  Up_frac_f(); 
     234 
     235        // Get the dispersion points for the radius 
     236        vector<WeightPoint> weights_rad; 
     237        radius.get_weights(weights_rad); 
     238 
     239        // Perform the computation, with all weight points 
     240        double sum = 0.0; 
     241        double norm = 0.0; 
     242        double vol = 0.0; 
     243 
     244        // Loop over radius weight points 
     245        for(size_t i=0; i<weights_rad.size(); i++) { 
     246                dp.radius = weights_rad[i].value; 
     247 
     248                //Un-normalize SphereForm by volume 
     249                sum += weights_rad[i].weight 
     250                        * sphere_analytical_2DXY(&dp, qx, qy) * pow(weights_rad[i].value,3); 
     251                //Find average volume 
     252                vol += weights_rad[i].weight 
     253                        * pow(weights_rad[i].value,3); 
     254 
     255                norm += weights_rad[i].weight; 
     256        } 
     257 
     258        if (vol != 0.0 && norm != 0.0) { 
     259                //Re-normalize by avg volume 
     260                sum = sum/(vol/norm);} 
     261        return sum/norm + background(); 
    96262} 
    97263 
     
    104270 */ 
    105271double SphereModel :: evaluate_rphi(double q, double phi) { 
    106         return (*this).operator()(q); 
     272        double qx = q*cos(phi); 
     273        double qy = q*sin(phi); 
     274        return (*this).operator()(qx, qy); 
    107275} 
    108276 
  • sansmodels/src/c_models/spheroid.cpp

    re08bd5b r318b5bbb  
    5757static double spheroid_analytical_2D_scaled(SpheroidParameters *pars, double q, double q_x, double q_y) { 
    5858 
    59   double cyl_x, cyl_y, cyl_z; 
    60   double q_z; 
     59  double cyl_x, cyl_y;//, cyl_z; 
     60  //double q_z; 
    6161  double alpha, vol, cos_val; 
    6262  double answer; 
     
    7070 
    7171  // ellipsoid orientation, the axis of the rotation is consistent with the ploar axis. 
    72   cyl_x = sin(theta) * cos(phi); 
    73   cyl_y = sin(theta) * sin(phi); 
    74   cyl_z = cos(theta); 
     72  cyl_x = cos(theta) * cos(phi); 
     73  cyl_y = sin(theta); 
     74  //cyl_z = -cos(theta) * sin(phi); 
    7575  //del sld 
    7676  sldcs = pars->sld_core - pars->sld_shell; 
     
    7878 
    7979  // q vector 
    80   q_z = 0; 
     80  //q_z = 0; 
    8181 
    8282  // Compute the angle btw vector q and the 
    8383  // axis of the cylinder 
    84   cos_val = cyl_x*q_x + cyl_y*q_y + cyl_z*q_z; 
     84  cos_val = cyl_x*q_x + cyl_y*q_y;// + cyl_z*q_z; 
    8585 
    8686  // The following test should always pass 
     
    336336              * pow(weights_equat_shell[k].value,2)*weights_polar_shell[l].value; 
    337337              if (weights_theta.size()>1) { 
    338                 _ptvalue *= fabs(sin(weights_theta[m].value*pi/180.0)); 
     338                _ptvalue *= fabs(cos(weights_theta[m].value*pi/180.0)); 
    339339              } 
    340340              sum += _ptvalue; 
  • sansmodels/src/c_models/stackeddisks.cpp

    rcf7653d3 r318b5bbb  
    5858 */ 
    5959static double stacked_disks_analytical_2D_scaled(StackedDisksParameters *pars, double q, double q_x, double q_y) { 
    60   double cyl_x, cyl_y, cyl_z; 
    61   double q_z; 
     60  double cyl_x, cyl_y;//, cyl_z; 
     61  //double q_z; 
    6262  double alpha, vol, cos_val; 
    6363  double d, dum, halfheight; 
     
    6868 
    6969 
    70  
    7170  // parallelepiped orientation 
    72   cyl_x = sin(theta) * cos(phi); 
    73   cyl_y = sin(theta) * sin(phi); 
    74   cyl_z = cos(theta); 
     71  cyl_x = cos(theta) * cos(phi); 
     72  cyl_y = sin(theta); 
    7573 
    7674  // q vector 
    77   q_z = 0; 
     75  //q_z = 0; 
    7876 
    7977  // Compute the angle btw vector q and the 
    8078  // axis of the parallelepiped 
    81   cos_val = cyl_x*q_x + cyl_y*q_y + cyl_z*q_z; 
     79  cos_val = cyl_x*q_x + cyl_y*q_y;// + cyl_z*q_z; 
    8280 
    8381  // The following test should always pass 
     
    265263  double vol = 0.0; 
    266264  double pi = 4.0*atan(1.0); 
    267  
     265   
    268266  // Loop over length weight points 
    269267  for(int i=0; i< (int)weights_core_thick.size(); i++) { 
     
    294292            *pow(weights_radius[j].value,2)*(weights_core_thick[i].value+2*weights_layer_thick[k].value); 
    295293            if (weights_theta.size()>1) { 
    296               _ptvalue *= fabs(sin(weights_theta[l].value*pi/180.0)); 
     294              _ptvalue *= fabs(cos(weights_theta[l].value*pi/180.0)); 
    297295            } 
    298296            sum += _ptvalue; 
  • sansmodels/src/c_models/triaxialellipsoid.cpp

    re08bd5b r318b5bbb  
    4646} TriaxialEllipsoidParameters; 
    4747 
    48 static double triaxial_ellipsoid_kernel(TriaxialEllipsoidParameters *pars, double q, double alpha, double nu) { 
     48static double triaxial_ellipsoid_kernel(TriaxialEllipsoidParameters *pars, double q, double cos_val, double cos_nu, double cos_mu) { 
    4949  double t,a,b,c; 
    5050  double kernel; 
     
    5454  c = pars->semi_axisC ; 
    5555 
    56   t = q * sqrt(a*a*cos(nu)*cos(nu)+b*b*sin(nu)*sin(nu)*sin(alpha)*sin(alpha)+c*c*cos(alpha)*cos(alpha)); 
     56  t = q * sqrt(a*a*cos_nu*cos_nu+b*b*cos_mu*cos_mu+c*c*cos_val*cos_val); 
    5757  if (t==0.0){ 
    5858    kernel  = 1.0; 
     
    7373 */ 
    7474static double triaxial_ellipsoid_analytical_2D_scaled(TriaxialEllipsoidParameters *pars, double q, double q_x, double q_y) { 
    75   double cyl_x, cyl_y, cyl_z, ell_x, ell_y; 
    76   double q_z; 
    77   double cos_nu,nu; 
    78   double alpha, vol, cos_val; 
     75  double cyl_x, cyl_y, ella_x, ella_y, ellb_x, ellb_y; 
     76  //double q_z; 
     77  double cos_nu, cos_mu; 
     78  double vol, cos_val; 
    7979  double answer; 
    8080  double pi = 4.0*atan(1.0); 
     
    8686 
    8787  // Cylinder orientation 
    88   cyl_x = sin(theta) * cos(phi); 
    89   cyl_y = sin(theta) * sin(phi); 
    90   cyl_z = cos(theta); 
     88  cyl_x = cos(theta) * cos(phi); 
     89  cyl_y = sin(theta); 
     90  //cyl_z = -cos(theta) * sin(phi); 
    9191 
    9292  // q vector 
    93   q_z = 0.0; 
     93  //q_z = 0.0; 
    9494 
    9595  //dx = 1.0; 
     
    9797  // Compute the angle btw vector q and the 
    9898  // axis of the cylinder 
    99   cos_val = cyl_x*q_x + cyl_y*q_y + cyl_z*q_z; 
     99  cos_val = cyl_x*q_x + cyl_y*q_y;// + cyl_z*q_z; 
    100100 
    101101  // The following test should always pass 
     
    107107  // Note: cos(alpha) = 0 and 1 will get an 
    108108  // undefined value from CylKernel 
    109   alpha = acos( cos_val ); 
     109  //alpha = acos( cos_val ); 
    110110 
    111111  //ellipse orientation: 
     
    116116  // the wave vector q. 
    117117 
    118   //x- y- component on the detector plane. 
    119   ell_x =  cos(psi); 
    120   ell_y =  sin(psi); 
    121  
     118  //x- y- component of a-axis on the detector plane. 
     119  ella_x =  -cos(phi)*sin(psi) * sin(theta)+sin(phi)*cos(psi); 
     120  ella_y =  sin(psi)*cos(theta); 
     121   
     122  //x- y- component of b-axis on the detector plane. 
     123  ellb_x =  -sin(theta)*cos(psi)*cos(phi)-sin(psi)*sin(phi); 
     124  ellb_y =  cos(theta)*cos(psi); 
     125   
    122126  // calculate the axis of the ellipse wrt q-coord. 
    123   cos_nu = ell_x*q_x + ell_y*q_y; 
    124   nu = acos(cos_nu); 
    125  
     127  cos_nu = ella_x*q_x + ella_y*q_y; 
     128  cos_mu = ellb_x*q_x + ellb_y*q_y; 
     129   
     130  // The following test should always pass 
     131  if (fabs(cos_val)>1.0) { 
     132    //printf("parallel_ana_2D: Unexpected error: cos(alpha)>1\n"); 
     133    cos_val = 1.0; 
     134  } 
     135   if (fabs(cos_nu)>1.0) { 
     136    //printf("parallel_ana_2D: Unexpected error: cos(alpha)>1\n"); 
     137    cos_nu = 1.0; 
     138  } 
     139   if (fabs(cos_mu)>1.0) { 
     140    //printf("parallel_ana_2D: Unexpected error: cos(alpha)>1\n"); 
     141    cos_mu = 1.0; 
     142  }  
    126143  // Call the IGOR library function to get the kernel 
    127   answer = triaxial_ellipsoid_kernel(pars, q, alpha, nu); 
     144  answer = triaxial_ellipsoid_kernel(pars, q, cos_val, cos_nu, cos_mu); 
    128145 
    129146  // Multiply by contrast^2 
     
    325342              * weights_semi_axisA[i].value*weights_semi_axisB[j].value*weights_semi_axisC[k].value; 
    326343              if (weights_theta.size()>1) { 
    327                 _ptvalue *= fabs(sin(weights_theta[k].value*pi/180.0)); 
     344                _ptvalue *= fabs(cos(weights_theta[k].value*pi/180.0)); 
    328345              } 
    329346              sum += _ptvalue; 
Note: See TracChangeset for help on using the changeset viewer.