Changeset 6831fa0 in sasmodels


Ignore:
Timestamp:
Oct 14, 2016 3:18:34 PM (8 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
b716cc6
Parents:
87bc707
Message:

stacked_disks: enable 2D modeling for stacked disks

Location:
sasmodels
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/compare.py

    r9068f4c r6831fa0  
    3838from . import core 
    3939from . import kerneldll 
    40 from . import weights 
     40from . import exception 
    4141from .data import plot_theory, empty_data1D, empty_data2D 
    4242from .direct_model import DirectModel 
     
    4545try: 
    4646    from typing import Optional, Dict, Any, Callable, Tuple 
    47 except: 
     47except Exception: 
    4848    pass 
    4949else: 
     
    466466            if k.endswith('.type'): 
    467467                par = k[:-5] 
     468                if v == 'gaussian': continue 
    468469                cls = dispersers[v if v != 'rectangle' else 'rectangula'] 
    469470                handle = cls() 
    470471                model[0].disperser_handles[par] = handle 
    471                 model[0].set_dispersion(par, handle) 
     472                try: 
     473                    model[0].set_dispersion(par, handle) 
     474                except Exception: 
     475                    exception.annotate_exception("while setting %s to %r" 
     476                                                 %(par, v)) 
     477                    raise 
     478 
    472479 
    473480        #print("sasview pars",oldpars) 
  • sasmodels/conversion_table.py

    r5f1acda r6831fa0  
    729729            "theta": "axis_theta", 
    730730            "sld_solvent": "solvent_sld", 
    731             "n_stacking": "n_stacking" 
     731            "n_stacking": "n_stacking", 
     732            "thick_layer": "layer_thick", 
     733            "thick_core": "core_thick", 
    732734        } 
    733735    ], 
  • sasmodels/models/stacked_disks.c

    r0d6e865 r6831fa0  
    1414          double solvent_sld); 
    1515 
     16double Iqxy(double qx, double qy, 
     17          double thick_core, 
     18          double thick_layer, 
     19          double radius, 
     20          double n_stacking, 
     21          double sigma_dnn, 
     22          double core_sld, 
     23          double layer_sld, 
     24          double solvent_sld, 
     25          double theta, 
     26          double phi); 
     27 
    1628static 
    1729double _kernel(double qq, 
     
    2234               double halfheight, 
    2335               double thick_layer, 
    24                double zi, 
     36               double sin_alpha, 
     37               double cos_alpha, 
    2538               double sigma_dnn, 
    2639               double d, 
     
    3447        // zi is the dummy variable for the integration (x in Feigin's notation) 
    3548 
    36         const double besarg1 = qq*radius*sin(zi); 
    37         const double besarg2 = qq*radius*sin(zi); 
     49        const double besarg1 = qq*radius*sin_alpha; 
     50        //const double besarg2 = qq*radius*sin_alpha; 
    3851 
    39         const double sinarg1 = qq*halfheight*cos(zi); 
    40         const double sinarg2 = qq*(halfheight+thick_layer)*cos(zi); 
     52        const double sinarg1 = qq*halfheight*cos_alpha; 
     53        const double sinarg2 = qq*(halfheight+thick_layer)*cos_alpha; 
    4154 
    4255        const double be1 = sas_J1c(besarg1); 
    43         const double be2 = sas_J1c(besarg2); 
    44         const double si1 = sin(sinarg1)/sinarg1; 
    45         const double si2 = sin(sinarg2)/sinarg2; 
     56        //const double be2 = sas_J1c(besarg2); 
     57        const double be2 = be1; 
     58        const double si1 = sinc(sinarg1); 
     59        const double si2 = sinc(sinarg2); 
    4660 
    4761        const double dr1 = (core_sld-solvent_sld); 
    4862        const double dr2 = (layer_sld-solvent_sld); 
    4963        const double area = M_PI*radius*radius; 
    50         const double totald=2.0*(thick_layer+halfheight); 
     64        const double totald = 2.0*(thick_layer+halfheight); 
    5165 
    5266        const double t1 = area*(2.0*halfheight)*dr1*(si1)*(be1); 
     
    5468 
    5569 
    56         double retval =((t1+t2)*(t1+t2))*sin(zi); 
     70        double retval =((t1+t2)*(t1+t2)); 
    5771 
    5872        // loop for the structure facture S(q) 
    5973        double sqq=0.0; 
    6074        for(int kk=1;kk<n_stacking;kk+=1) { 
    61                 double dexpt=qq*cos(zi)*qq*cos(zi)*d*d*sigma_dnn*sigma_dnn*kk/2.0; 
    62                 sqq=sqq+(n_stacking-kk)*cos(qq*cos(zi)*d*kk)*exp(-1.*dexpt); 
     75                double qd_cos_alpha = qq*d*cos_alpha; 
     76                double dexpt=square(qd_cos_alpha*sigma_dnn)*kk/2.0; 
     77                sqq += (n_stacking-kk)*cos(qd_cos_alpha*kk)*exp(-1.*dexpt); 
    6378        } 
    64  
    6579        // end of loop for S(q) 
    6680        sqq=1.0+2.0*sqq/n_stacking; 
    6781 
    68         retval *= sqq; 
    69  
    70         return(retval); 
     82        return retval * sqq; 
    7183} 
    7284 
     
    88100        double summ = 0.0;      //initialize integral 
    89101 
    90         double d=2.0*thick_layer+thick_core; 
    91         double halfheight = thick_core/2.0; 
     102        double d = 2.0*thick_layer+thick_core; 
     103        double halfheight = 0.5*thick_core; 
    92104 
    93         for(int i=0;i<N_POINTS_76;i++) { 
    94                 double zi = (Gauss76Z[i] + 1.0)*M_PI/4.0; 
    95                 double yyy = Gauss76Wt[i] * 
    96                     _kernel(q, 
     105        for(int i=0; i<N_POINTS_76; i++) { 
     106                double zi = (Gauss76Z[i] + 1.0)*M_PI_4; 
     107                double sin_alpha, cos_alpha; // slots to hold sincos function output 
     108                SINCOS(zi, sin_alpha, cos_alpha); 
     109                double yyy = _kernel(q, 
    97110                                   radius, 
    98111                                   core_sld, 
     
    101114                                   halfheight, 
    102115                                   thick_layer, 
    103                                    zi, 
     116                                   sin_alpha, 
     117                                   cos_alpha, 
    104118                                   sigma_dnn, 
    105119                                   d, 
    106120                                   n_stacking); 
    107                 summ += yyy; 
     121                summ += Gauss76Wt[i] * yyy * sin_alpha; 
    108122        } 
    109123 
    110         double answer = M_PI/4.0*summ; 
     124        double answer = M_PI_4*summ; 
    111125 
    112126        //Convert to [cm-1] 
     
    116130} 
    117131 
    118 static double stacked_disks_kernel_2d(double q, double q_x, double q_y, 
    119                             double thick_core, 
    120                             double thick_layer, 
    121                             double radius, 
    122                             double n_stacking, 
    123                             double sigma_dnn, 
    124                             double core_sld, 
    125                             double layer_sld, 
    126                             double solvent_sld, 
    127                             double theta, 
    128                             double phi) 
    129 { 
    130  
    131     double ct, st, cp, sp; 
    132  
    133     //convert angle degree to radian 
    134     theta = theta * M_PI/180.0; 
    135     phi = phi * M_PI/180.0; 
    136  
    137     SINCOS(theta, st, ct); 
    138     SINCOS(phi, sp, cp); 
    139  
    140     // silence compiler warnings about unused variable 
    141     (void) sp; 
    142  
    143     // parallelepiped orientation 
    144     const double cyl_x = st * cp; 
    145     const double cyl_y = st * sp; 
    146  
    147     // Compute the angle btw vector q and the 
    148     // axis of the parallelepiped 
    149     const double cos_val = cyl_x*q_x + cyl_y*q_y; 
    150  
    151     // Note: cos(alpha) = 0 and 1 will get an 
    152     // undefined value from Stackdisc_kern 
    153     double alpha = acos( cos_val ); 
    154  
    155     // Call the IGOR library function to get the kernel 
    156     double d = 2 * thick_layer + thick_core; 
    157     double halfheight = thick_core/2.0; 
    158     double answer = _kernel(q, 
    159                      radius, 
    160                      core_sld, 
    161                      layer_sld, 
    162                      solvent_sld, 
    163                      halfheight, 
    164                      thick_layer, 
    165                      alpha, 
    166                      sigma_dnn, 
    167                      d, 
    168                      n_stacking); 
    169  
    170     answer /= sin(alpha); 
    171     //convert to [cm-1] 
    172     answer *= 1.0e-4; 
    173  
    174     return answer; 
    175 } 
    176  
    177132double form_volume(double thick_core, 
    178133                   double thick_layer, 
    179134                   double radius, 
    180135                   double n_stacking){ 
    181     double d = 2 * thick_layer + thick_core; 
    182     return acos(-1.0) * radius * radius * d * n_stacking; 
     136    double d = 2.0 * thick_layer + thick_core; 
     137    return M_PI * radius * radius * d * n_stacking; 
    183138} 
    184139 
     
    203158                    solvent_sld); 
    204159} 
     160 
     161 
     162double 
     163Iqxy(double qx, double qy, 
     164     double thick_core, 
     165     double thick_layer, 
     166     double radius, 
     167     double n_stacking, 
     168     double sigma_dnn, 
     169     double core_sld, 
     170     double layer_sld, 
     171     double solvent_sld, 
     172     double theta, 
     173     double phi) 
     174{ 
     175    double q, sin_alpha, cos_alpha; 
     176    ORIENT_SYMMETRIC(qx, qy, theta, phi, q, sin_alpha, cos_alpha); 
     177 
     178    double d = 2.0 * thick_layer + thick_core; 
     179    double halfheight = 0.5*thick_core; 
     180    double answer = _kernel(q, 
     181                     radius, 
     182                     core_sld, 
     183                     layer_sld, 
     184                     solvent_sld, 
     185                     halfheight, 
     186                     thick_layer, 
     187                     sin_alpha, 
     188                     cos_alpha, 
     189                     sigma_dnn, 
     190                     d, 
     191                     n_stacking); 
     192 
     193    //convert to [cm-1] 
     194    answer *= 1.0e-4; 
     195 
     196    return answer; 
     197} 
     198 
Note: See TracChangeset for help on using the changeset viewer.