Changeset 4605bf10 in sasmodels


Ignore:
Timestamp:
Apr 18, 2016 9:47:14 AM (8 years ago)
Author:
wojciech
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
a7c2cfe
Parents:
eb97b11
Message:

Bug fixes in spherical sld model

Location:
sasmodels/models
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/models/spherical_sld.c

    reb97b11 r4605bf10  
    1 //Headers 
    2 static double form_volume(double thick_inter[], 
    3     double thick_flat_[], 
    4     double core_radius, 
    5     int n_shells); 
    6  
    7 static double Iq(double q, 
     1static double form_volume( 
    82    int n_shells, 
    9     double thick_inter[], 
    10     double func_inter[], 
    11     double sld_core, 
    12     double sld_solvent, 
    13     double sld_flat[], 
     3    double radius_core, 
    144    double thick_flat[], 
    15     double nu_inter[], 
    16     int npts_inter, 
    17     double core_radius); 
    18  
    19 static double Iqxy(double qx, double qy, 
    20     int n_shells, 
    21     double thick_inter[], 
    22     double func_inter[], 
    23     double sld_core, 
    24     double sld_solvent, 
    25     double sld_flat[], 
    26     double thick_flat[], 
    27     double nu_inter[], 
    28     int npts_inter, 
    29     double core_radius); 
    30  
    31 //Main code 
    32 static double form_volume(double thick_inter[], 
    33     double thick_flat_[], 
    34     double core_radius, 
    35     int n) 
     5    double thick_inter[]) 
    366{ 
    377    double radius = 0.0; 
    388    int i; 
    39     double r = core_radius; 
    40     for (i=0; i < n; i++) { 
     9    double r = radius_core; 
     10    for (i=0; i < n_shells; i++) { 
    4111        r += thick_inter[i]; 
    4212        r += thick_flat[i]; 
     
    191161    } 
    192162  } 
    193   //vol += vol_sub; 
    194163  f2 = f * f / vol; 
    195   //f2 *= scale; 
    196   //f2 += background; 
    197   //free(fun_type); 
    198   //free(sld); 
    199   //free(thick_inter); 
    200   //free(thick); 
    201   //free(fun_coef); 
    202164 
    203165  return (f2); 
     
    210172 * @return: function value 
    211173 */ 
    212 double Iq(double q, 
     174static double Iq(double q, 
    213175    int n_shells, 
    214     double thick_inter[], 
    215     double func_inter[], 
     176    int npts_inter, 
     177    double radius_core, 
    216178    double sld_core, 
    217179    double sld_solvent, 
    218180    double sld_flat[], 
    219181    double thick_flat[], 
    220     double nu_inter[], 
    221     int npts_inter, 
    222     double core_radius 
    223     ) { 
     182    double func_inter[], 
     183    double thick_inter[], 
     184    double nu_inter[] ) { 
    224185 
    225186    //printf("Number of points %d\n",npts_inter); 
    226187    double intensity; 
    227     //TODO: Remove this container at later stage. It is only kept to minimize stupid errors now 
     188    //TODO: Remove this container at later stage. 
    228189    double dp[60]; 
    229190    dp[0] = n_shells; 
    230191    //This is scale will also have to be removed at some stage 
    231192    dp[1] = 1.0; 
    232     dp[2] = thick_inter_0; 
    233     dp[3] = func_inter_0; 
     193    dp[2] = thick_inter[0]; 
     194    dp[3] = func_inter[0]; 
    234195    dp[4] = sld_core; 
    235196    dp[5] = sld_solvent; 
    236197    dp[6] = 0.0; 
    237198 
    238     for (i=0; i<n; i++){ 
     199    for (int i=1; i<n_shells; i++){ 
    239200        dp[i+7] = sld_flat[i]; 
    240201        dp[i+17] = thick_inter[i]; 
     
    245206 
    246207    dp[57] = npts_inter; 
    247     dp[58] = nu_inter_0; 
    248     dp[59] = rad_core_0; 
     208    dp[58] = nu_inter[0]; 
     209    dp[59] = radius_core; 
    249210 
    250211    intensity = 1.0e-4*sphere_sld_kernel(dp,q); 
     
    259220 * @return: function value 
    260221 */ 
    261 double Iqxy(double qx, double qy, 
     222 
     223/*static double Iqxy(double qx, double qy, 
    262224    int n_shells, 
    263     double thick_inter[], 
    264     double func_inter[], 
     225    int npts_inter, 
     226    double radius_core 
    265227    double sld_core, 
    266228    double sld_solvent, 
    267229    double sld_flat[], 
    268230    double thick_flat[], 
     231    double func_inter[], 
     232    double thick_inter[], 
    269233    double nu_inter[], 
    270     int npts_inter, 
    271     double core_radius 
    272234    ) { 
    273235 
    274236    double q = sqrt(qx*qx + qy*qy); 
    275     return Iq(q, n_shells, thick_inter[], func_inter[], sld_core, sld_solvent, 
    276     sld_flat[], thick_flat[],nu_inter[], npts_inter, core_radius) 
    277  
    278 } 
    279  
     237    return Iq(q, n_shells, npts_inter, radius_core, sld_core, sld_solvent, 
     238    sld_flat[], thick_flat[], func_inter[], thick_inter[], nu_inter[]) 
     239}*/ 
     240 
  • sasmodels/models/spherical_sld.py

    reb97b11 r4605bf10  
    171171#            ["name", "units", default, [lower, upper], "type", "description"], 
    172172parameters = [["n_shells",                "",               1,      [0, 9],         "", "number of shells"], 
     173              ["npts_inter",       "",               35,     [0, 35],        "", "number of points in each sublayer Must be odd number"], 
    173174              ["radius_core",      "Ang",            50.0,   [0, inf],       "", "intern layer thickness"], 
    174175              ["sld_core",         "1e-6/Ang^2",     2.07,   [-inf, inf],    "", "sld function flat"], 
    175176              ["sld_solvent",      "1e-6/Ang^2",     1.0,    [-inf, inf],    "", "sld function solvent"], 
    176               ["sld_flat[n]",      "1e-6/Ang^2",     4.06,   [-inf, inf],    "", "sld function flat"], 
    177               ["thick_flat[n]",    "Ang",            100.0,  [0, inf],       "", "flat layer_thickness"], 
    178               ["func_inter[n]",    "",               0,      [0, 4],         "", "Erf:0, RPower:1, LPower:2, RExp:3, LExp:4"], 
    179               ["thick_inter[n]",   "Ang",            50.0,   [0, inf],       "", "intern layer thickness"], 
    180               ["nu_inter[n]",      "",               2.5,    [-inf, inf],    "", "steepness parameter"], 
    181               ["npts_inter",       "",               35,     [0, 35],        "", "number of points in each sublayer Must be odd number"], 
     177              ["sld_flat[n_shells]",      "1e-6/Ang^2",     4.06,   [-inf, inf],    "", "sld function flat"], 
     178              ["thick_flat[n_shells]",    "Ang",            100.0,  [0, inf],       "", "flat layer_thickness"], 
     179              ["func_inter[n_shells]",    "",               0,      [0, 4],         "", "Erf:0, RPower:1, LPower:2, RExp:3, LExp:4"], 
     180              ["thick_inter[n_shells]",   "Ang",            50.0,   [0, inf],       "", "intern layer thickness"], 
     181              ["nu_inter[n_shells]",      "",               2.5,    [-inf, inf],    "", "steepness parameter"], 
    182182              ] 
    183183# pylint: enable=bad-whitespace, line-too-long 
     
    195195    Returns shape profile with x=radius, y=SLD. 
    196196    """ 
    197  
    198     #total_radius = 1.25*(sum(thickness[:n_shells]) + core_radius + 1) 
    199     #dr = total_radius/400  # 400 points for a smooth plot 
    200197 
    201198    z = [] 
     
    220217                    # shift half sub thickness for the first point 
    221218                    z0 -= dz#/2.0 
    222                         z.append(z0) 
    223                         #z0 -= dz/2.0 
    224                         z0 += thick_flat[i] 
    225                         sld_i = sld_flat[i] 
    226                         beta.append(sld_flat[i]) 
    227                         dz = 0 
     219                    z.append(z0) 
     220                    #z0 -= dz/2.0 
     221                    z0 += thick_flat[i] 
     222                    sld_i = sld_flat[i] 
     223                    beta.append(sld_flat[i]) 
     224                    dz = 0 
     225                else: 
     226                    nu = nu_inter[i-1] 
     227                    # decide which sld is which, sld_r or sld_l 
     228                    if i == 1: 
     229                        sld_l = sld_core 
    228230                    else: 
    229                         nu = nu_inter[i-1] 
    230                         # decide which sld is which, sld_r or sld_l 
    231                         if i == 1: 
    232                             sld_l = sld_core 
    233                         else: 
    234                             sld_l = sld_flat[i-1] 
    235                         if i == n_shells+1: 
    236                             sld_r = sld_solvent 
    237                         else: 
    238                             sld_r = sld_flat[i] 
    239                         # get function type 
    240                         func_idx = func_inter[i-1] 
    241                         # calculate the sld 
    242                         sld_i = intersldfunc(func_idx, npts_inter, n_s, nu, 
     231                        sld_l = sld_flat[i-1] 
     232                    if i == n_shells+1: 
     233                        sld_r = sld_solvent 
     234                    else: 
     235                        sld_r = sld_flat[i] 
     236                    # get function type 
     237                    func_idx = func_inter[i-1] 
     238                    # calculate the sld 
     239                    sld_i = intersldfunc(func_idx, npts_inter, n_s, nu, 
    243240                                            sld_l, sld_r) 
    244                     # append to the list 
    245                     z.append(z0) 
    246                     beta.append(sld_i) 
    247                     z0 += dz 
    248                     if j == 1: 
    249                         break 
    250     # put sld of solvent 
     241                # append to the list 
     242                z.append(z0) 
     243                beta.append(sld_i) 
     244                z0 += dz 
     245                if j == 1: 
     246                    break 
    251247    z.append(z0) 
    252248    beta.append(sld_solvent) 
     
    255251    beta.append(sld_solvent) 
    256252    # return sld profile (r, beta) 
    257      
    258253    return np.asarray(z), np.asarray(beta)*1e-6 
    259254 
     
    268263    n=4, 
    269264    scale=1.0, 
    270     solvent_sld=1.0, 
     265    sld_solvent=1.0, 
    271266    background=0.0, 
    272267    npts_inter=35.0, 
Note: See TracChangeset for help on using the changeset viewer.