Changeset ea07075 in sasview


Ignore:
Timestamp:
Aug 3, 2009 5:41:22 PM (15 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:
e6fa43e
Parents:
2a1be2d9
Message:

done corrections and 2d extension on this model function

Location:
sansmodels/src/sans/models
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • sansmodels/src/sans/models/c_extensions/flexible_cylinder.c

    r5068697 rea07075  
    1919double flexible_cylinder_analytical_1D(FlexibleCylinderParameters *pars, double q) { 
    2020        double dp[6]; 
    21          
     21 
    2222        // Fill paramater array 
    2323        dp[0] = pars->scale; 
     
    2929 
    3030        // Call library function to evaluate model 
    31         return FlexExclVolCyl(dp, q);    
     31        return FlexExclVolCyl(dp, q); 
    3232} 
    3333/** 
     
    4040        double q; 
    4141        q = sqrt(qx*qx+qy*qy); 
    42     return flexible_cylinder_analytical_2D_scaled(pars, q, qx/q, qy/q); 
    43 }  
     42    return flexible_cylinder_analytical_1D(pars, q); 
     43} 
    4444 
    4545 
     
    5252 */ 
    5353double flexible_cylinder_analytical_2D(FlexibleCylinderParameters *pars, double q, double phi) { 
    54     return flexible_cylinder_analytical_2D_scaled(pars, q, cos(phi), sin(phi)); 
    55 }  
    56          
    57 /** 
    58  * Function to evaluate 2D scattering function 
    59  * @param pars: parameters of the flexible cylinder 
    60  * @param q: q-value 
    61  * @param q_x: q_x / q 
    62  * @param q_y: q_y / q 
    63  * @return: function value 
    64  */ 
    65 double flexible_cylinder_analytical_2D_scaled(FlexibleCylinderParameters *pars, double q, double q_x, double q_y) { 
    66         double cyl_x, cyl_y, cyl_z; 
    67         double q_z; 
    68         double alpha, vol, cos_val; 
    69         double answer; 
    70          
    71          
     54    return flexible_cylinder_analytical_1D(pars, q); 
     55} 
    7256 
    73     // parallelepiped orientation 
    74     cyl_x = sin(pars->axis_theta) * cos(pars->axis_phi); 
    75     cyl_y = sin(pars->axis_theta) * sin(pars->axis_phi); 
    76     cyl_z = cos(pars->axis_theta); 
    77       
    78     // q vector 
    79     q_z = 0; 
    80          
    81     // Compute the angle btw vector q and the 
    82     // axis of the parallelepiped 
    83     cos_val = cyl_x*q_x + cyl_y*q_y + cyl_z*q_z; 
    84      
    85     // The following test should always pass 
    86     if (fabs(cos_val)>1.0) { 
    87         printf("parallel_ana_2D: Unexpected error: cos(alpha)>1\n"); 
    88         return 0; 
    89     } 
    90      
    91     // Note: cos(alpha) = 0 and 1 will get an 
    92     // undefined value from PPKernel 
    93         alpha = acos( cos_val ); 
    9457 
    95         // Call the IGOR library function to get the kernel 
    96         answer = CylKernel(q, pars->radius, pars->length/2.0, alpha) / sin(alpha); 
    97          
    98         // Multiply by contrast^2 
    99         answer *= pars->contrast*pars->contrast; 
    100          
    101         //normalize by cylinder volume 
    102         //NOTE that for this (Fournet) definition of the integral, one must MULTIPLY by Vparallel 
    103     vol = acos(-1.0) * pars->radius * pars->radius * pars->length; 
    104         answer *= vol; 
    105          
    106         //convert to [cm-1] 
    107         answer *= 1.0e8; 
    108          
    109         //Scale 
    110         answer *= pars->scale; 
    111          
    112         // add in the background 
    113         answer += pars->background; 
    114          
    115         return answer; 
    116 } 
    117      
    118  
  • sansmodels/src/sans/models/c_extensions/flexible_cylinder.h

    r5068697 rea07075  
    77/** Structure definition for Flexible cylinder parameters 
    88 * [PYTHONCLASS] = FlexibleCylinderModel 
    9  * [DISP_PARAMS] = length, radius, axis_theta, axis_phi 
    10    [DESCRIPTION] = <text> Note : scale and contrast are both multiplicative factors in the model and are perfectly 
    11                         correlated. One or both of these parameters must be held fixed during model fitting. 
     9 * [DISP_PARAMS] = length, kuhn_length, radius 
     10   [DESCRIPTION] = <text> Note : 'scale' and 'contrast' are both multiplicative factors in the 
     11                model and are perfectly correlated. One or 
     12                both of these parameters must be held fixed 
     13                during model fitting. 
    1214                </text> 
    13         [FIXED]= <text>length.width; radius.width; axis_theta.width; axis_phi.width</text> 
    14         [ORIENTATION_PARAMS]= <text>axis_phi; axis_theta; axis_phi.width; axis_theta.width</text> 
     15        [FIXED]= <text>length.width; radius.width; , kuhn_length.width</text> 
     16        [ORIENTATION_PARAMS]= <text></text> 
    1517 
    1618 
     
    3234    //  [DEFAULT]=contrast=5.3e-6 [1/A²] 
    3335    double contrast; 
    34         /// Incoherent Background [1/cm]  
     36        /// Incoherent Background [1/cm] 
    3537        //  [DEFAULT]=background=0.0001 [1/cm] 
    3638        double background; 
    37     /// Orientation of the flexible cylinder axis w/respect incoming beam [rad] 
    38     //  [DEFAULT]=axis_theta=1.0 [rad] 
    39     double axis_theta; 
    40     /// Orientation of the flexible cylinder in the plane of the detector [rad] 
    41     //  [DEFAULT]=axis_phi=1.0 [rad] 
    42     double axis_phi; 
    4339 
    4440 
     
    5349double flexible_cylinder_analytical_2D(FlexibleCylinderParameters *pars, double q, double phi); 
    5450double flexible_cylinder_analytical_2DXY(FlexibleCylinderParameters *pars, double qx, double qy); 
    55 double flexible_cylinder_analytical_2D_scaled(FlexibleCylinderParameters *pars, double q, double q_x, double q_y); 
    5651 
    5752#endif 
  • sansmodels/src/sans/models/c_models/CFlexibleCylinderModel.cpp

    r5068697 rea07075  
    8484        // Initialize parameter dictionary 
    8585        PyDict_SetItemString(self->params,"scale",Py_BuildValue("d",1.000000)); 
    86         PyDict_SetItemString(self->params,"axis_theta",Py_BuildValue("d",1.000000)); 
    8786        PyDict_SetItemString(self->params,"length",Py_BuildValue("d",1000.000000)); 
    88         PyDict_SetItemString(self->params,"axis_phi",Py_BuildValue("d",1.000000)); 
    8987        PyDict_SetItemString(self->params,"radius",Py_BuildValue("d",20.000000)); 
    9088        PyDict_SetItemString(self->params,"background",Py_BuildValue("d",0.000100)); 
     
    9896        PyDict_SetItemString(self->dispersion, "length", disp_dict); 
    9997        disp_dict = PyDict_New(); 
     98        self->model->kuhn_length.dispersion->accept_as_source(visitor, self->model->kuhn_length.dispersion, disp_dict); 
     99        PyDict_SetItemString(self->dispersion, "kuhn_length", disp_dict); 
     100        disp_dict = PyDict_New(); 
    100101        self->model->radius.dispersion->accept_as_source(visitor, self->model->radius.dispersion, disp_dict); 
    101102        PyDict_SetItemString(self->dispersion, "radius", disp_dict); 
    102         disp_dict = PyDict_New(); 
    103         self->model->axis_theta.dispersion->accept_as_source(visitor, self->model->axis_theta.dispersion, disp_dict); 
    104         PyDict_SetItemString(self->dispersion, "axis_theta", disp_dict); 
    105         disp_dict = PyDict_New(); 
    106         self->model->axis_phi.dispersion->accept_as_source(visitor, self->model->axis_phi.dispersion, disp_dict); 
    107         PyDict_SetItemString(self->dispersion, "axis_phi", disp_dict); 
    108103 
    109104 
     
    159154            // Reader parameter dictionary 
    160155    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") ); 
    161     self->model->axis_theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "axis_theta") ); 
    162156    self->model->length = PyFloat_AsDouble( PyDict_GetItemString(self->params, "length") ); 
    163     self->model->axis_phi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "axis_phi") ); 
    164157    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") ); 
    165158    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") ); 
     
    171164    disp_dict = PyDict_GetItemString(self->dispersion, "length"); 
    172165    self->model->length.dispersion->accept_as_destination(visitor, self->model->length.dispersion, disp_dict); 
     166    disp_dict = PyDict_GetItemString(self->dispersion, "kuhn_length"); 
     167    self->model->kuhn_length.dispersion->accept_as_destination(visitor, self->model->kuhn_length.dispersion, disp_dict); 
    173168    disp_dict = PyDict_GetItemString(self->dispersion, "radius"); 
    174169    self->model->radius.dispersion->accept_as_destination(visitor, self->model->radius.dispersion, disp_dict); 
    175     disp_dict = PyDict_GetItemString(self->dispersion, "axis_theta"); 
    176     self->model->axis_theta.dispersion->accept_as_destination(visitor, self->model->axis_theta.dispersion, disp_dict); 
    177     disp_dict = PyDict_GetItemString(self->dispersion, "axis_phi"); 
    178     self->model->axis_phi.dispersion->accept_as_destination(visitor, self->model->axis_phi.dispersion, disp_dict); 
    179170 
    180171         
     
    229220            // Reader parameter dictionary 
    230221    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") ); 
    231     self->model->axis_theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "axis_theta") ); 
    232222    self->model->length = PyFloat_AsDouble( PyDict_GetItemString(self->params, "length") ); 
    233     self->model->axis_phi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "axis_phi") ); 
    234223    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") ); 
    235224    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") ); 
     
    241230    disp_dict = PyDict_GetItemString(self->dispersion, "length"); 
    242231    self->model->length.dispersion->accept_as_destination(visitor, self->model->length.dispersion, disp_dict); 
     232    disp_dict = PyDict_GetItemString(self->dispersion, "kuhn_length"); 
     233    self->model->kuhn_length.dispersion->accept_as_destination(visitor, self->model->kuhn_length.dispersion, disp_dict); 
    243234    disp_dict = PyDict_GetItemString(self->dispersion, "radius"); 
    244235    self->model->radius.dispersion->accept_as_destination(visitor, self->model->radius.dispersion, disp_dict); 
    245     disp_dict = PyDict_GetItemString(self->dispersion, "axis_theta"); 
    246     self->model->axis_theta.dispersion->accept_as_destination(visitor, self->model->axis_theta.dispersion, disp_dict); 
    247     disp_dict = PyDict_GetItemString(self->dispersion, "axis_phi"); 
    248     self->model->axis_phi.dispersion->accept_as_destination(visitor, self->model->axis_phi.dispersion, disp_dict); 
    249236 
    250237         
     
    304291    if (!strcmp(par_name, "length")) { 
    305292        self->model->length.dispersion = dispersion; 
     293    } else    if (!strcmp(par_name, "kuhn_length")) { 
     294        self->model->kuhn_length.dispersion = dispersion; 
    306295    } else    if (!strcmp(par_name, "radius")) { 
    307296        self->model->radius.dispersion = dispersion; 
    308     } else    if (!strcmp(par_name, "axis_theta")) { 
    309         self->model->axis_theta.dispersion = dispersion; 
    310     } else    if (!strcmp(par_name, "axis_phi")) { 
    311         self->model->axis_phi.dispersion = dispersion; 
    312297    } else { 
    313298            PyErr_SetString(CFlexibleCylinderModelError, 
  • sansmodels/src/sans/models/c_models/flexiblecylinder.cpp

    r5068697 rea07075  
    1919 * 
    2020 *      TODO: refactor so that we pull in the old sansmodels.c_extensions 
    21  *      TODO: add 2d  
     21 *      TODO: add 2d 
    2222 */ 
    2323 
     
    4343        contrast   = Parameter(5.3e-6); 
    4444        background = Parameter(0.0001); 
    45         axis_theta  = Parameter(0.0, true); 
    46         axis_phi    = Parameter(0.0, true); 
    4745} 
    4846 
     
    10199 */ 
    102100double FlexibleCylinderModel :: operator()(double qx, double qy) { 
    103         FlexibleCylinderParameters dp; 
    104         // Fill parameter array 
    105         dp.scale      = scale(); 
    106         dp.length     = length(); 
    107         dp.kuhn_length= kuhn_length(); 
    108         dp.radius     = radius(); 
    109         dp.contrast   = contrast(); 
    110         dp.background = background(); 
    111         dp.axis_theta  = axis_theta(); 
    112         dp.axis_phi    = axis_phi(); 
    113  
    114         // Get the dispersion points for the length 
    115         vector<WeightPoint> weights_length; 
    116         length.get_weights(weights_length); 
    117  
    118         // Get the dispersion points for the radius 
    119         vector<WeightPoint> weights_radius; 
    120         radius.get_weights(weights_radius); 
    121  
    122         // Get angular averaging for theta 
    123         vector<WeightPoint> weights_theta; 
    124         axis_theta.get_weights(weights_theta); 
    125  
    126         // Get angular averaging for phi 
    127         vector<WeightPoint> weights_phi; 
    128         axis_phi.get_weights(weights_phi); 
    129  
    130         // Perform the computation, with all weight points 
    131         double sum = 0.0; 
    132         double norm = 0.0; 
    133  
    134         // Loop over length weight points 
    135         for(int i=0; i< (int)weights_length.size(); i++) { 
    136                 dp.length = weights_length[i].value; 
    137  
    138                 // Loop over radius weight points 
    139                 for(int j=0; j< (int)weights_radius.size(); j++) { 
    140                         dp.radius = weights_radius[j].value; 
    141  
    142                                 // Average over theta distribution 
    143                                 for(int k=0; k< (int)weights_theta.size(); k++) { 
    144                                         dp.axis_theta = weights_theta[k].value; 
    145  
    146                                         // Average over phi distribution 
    147                                         for(int l=0; l <(int)weights_phi.size(); l++) { 
    148                                                 dp.axis_phi = weights_phi[l].value; 
    149  
    150                                                 double _ptvalue = weights_length[i].weight 
    151                                                         * weights_radius[j].weight 
    152                                                         * weights_theta[k].weight 
    153                                                         * weights_phi[l].weight 
    154                                                         * flexible_cylinder_analytical_2DXY(&dp, qx, qy); 
    155                                                 if (weights_theta.size()>1) { 
    156                                                         _ptvalue *= sin(weights_theta[k].value); 
    157                                                 } 
    158                                                 sum += _ptvalue; 
    159  
    160                                                 norm += weights_length[i].weight 
    161                                                         * weights_radius[j].weight 
    162                                                         * weights_theta[k].weight 
    163                                                         * weights_phi[l].weight; 
    164                                 } 
    165                         } 
    166                 } 
    167         } 
    168         // Averaging in theta needs an extra normalization 
    169         // factor to account for the sin(theta) term in the 
    170         // integration (see documentation). 
    171         if (weights_theta.size()>1) norm = norm / asin(1.0); 
    172         return sum/norm + background(); 
     101        double q = sqrt(qx*qx + qy*qy); 
     102        return (*this).operator()(q); 
    173103} 
    174104 
     
    181111 */ 
    182112double FlexibleCylinderModel :: evaluate_rphi(double q, double phi) { 
    183         double qx = q*cos(phi); 
    184         double qy = q*sin(phi); 
    185         return (*this).operator()(qx, qy); 
     113        //double qx = q*cos(phi); 
     114        //double qy = q*sin(phi); 
     115        return (*this).operator()(q); 
    186116} 
Note: See TracChangeset for help on using the changeset viewer.