Changeset 34756fd in sasmodels


Ignore:
Timestamp:
Dec 3, 2014 5:04:40 PM (10 years ago)
Author:
Paul Kienzle <pkienzle@…>
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:
3699587, 8a3e0af
Parents:
34d49af
Message:

add single to double comparison for the new models

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • compare_many.py

    r216a9e1 r34756fd  
    99                     eval_opencl, eval_ctypes, make_data) 
    1010 
    11 def get_stats(target, model_eval, name, pars, data, index, dtype, cutoff): 
    12     value, _ = model_eval(name, pars, data, dtype='single', cutoff=cutoff) 
     11def get_stats(target, value, index): 
    1312    resid = abs(value-target)[index] 
    1413    relerr = resid/target[index] 
     
    4544 
    4645        env = environment() 
    47         gpu_single = get_stats(target, eval_opencl, name, pars, data, index, 'single', cutoff) 
     46        gpu_single_value,_ = eval_opencl(name, pars, data, dtype='single', cutoff=cutoff) 
     47        gpu_single = get_stats(target, gpu_single_value, index) 
    4848        if env.has_double: 
    49             gpu_double = get_stats(target, eval_opencl, name, pars, data, index, 'double', cutoff) 
     49            gpu_double_value,_ = eval_opencl(name, pars, data, dtype='double', cutoff=cutoff) 
     50            gpu_double = get_stats(target, gpu_double_value, index) 
    5051        else: 
    5152            gpu_double = [0]*len(gpu_single) 
    52         cpu_double = get_stats(target, eval_ctypes, name, pars, data, index, 'double', cutoff) 
     53        cpu_double_value,_ =  eval_ctypes(name, pars, data, dtype='double', cutoff=cutoff) 
     54        cpu_double = get_stats(target, cpu_double_value, index) 
     55        single_double = get_stats(cpu_double_value, gpu_single_value, index) 
    5356 
    54         values = list(gpu_single) + list(gpu_double) + list(cpu_double) + [v for _,v in sorted(pars.items())] 
     57        values = (list(gpu_single) + list(gpu_double) + list(cpu_double) 
     58                  + list(single_double) + [v for _,v in sorted(pars.items())]) 
    5559        if gpu_single[0] > 5e-5: 
    5660            if first: 
    57                 print_column_headers(pars,'GPU single|GPU double|CPU double'.split('|')) 
     61                print_column_headers(pars,'GPU single|GPU double|CPU double|single/double'.split('|')) 
    5862                first = False 
    5963            print(("%d,"%seed)+','.join("%g"%v for v in values)) 
  • sasmodels/models/capped_cylinder.c

    r994d77f r34756fd  
    5252{ 
    5353    // cap radius should never be less than radius when this is called 
    54     // Note: cap volume = pi hc/6 * (3 a^2 + hc^2), where a is the cylinder 
    55     // radius and hc is the height of the cap.  Multiply by two for both ends. 
    56     // So: 
    57     //      cap V = pi hc (r^2 + hc^2/3) 
    58     //      cylinder V = pi r^2 L 
    59     //      V = cylinder V + cap V 
     54 
     55    // Note: volume V = 2*V_cap + V_cyl 
     56    // 
     57    // V_cyl = pi r_cyl^2 L 
     58    // V_cap = 1/6 pi h_c (3 r_cyl^2 + h_c^2) = 1/3 pi h_c^2 (3 r_cap - h_c) 
     59    // 
     60    // The docs for capped cylinder give the volume as: 
     61    //    V = pi r^2 L + 2/3 pi (R-h)^2 (2R + h) 
     62    // where r_cap=R and h = R - h_c. 
     63    // 
     64    // The first part is clearly V_cyl.  The second part requires some work: 
     65    //    (R-h)^2 => h_c^2 
     66    //    (2R+h) => 2R+ h_c-h_c + h => 2R + (R-h)-hc + h => 3R-h_c 
     67    // And so: 
     68    //    2/3 pi (R-h)^2 (2R + h) => 2/3 pi h_c^2 (3 r_cap - h_c) 
     69    // which is 2 V_cap, using the second form above. 
     70    // 
     71    // In this function we are going to use the first form of V_cap 
     72    // 
     73    //      V = V_cyl + 2 V_cap 
    6074    //        = pi r^2 L + pi hc (r^2 + hc^2/3) 
    61     //        = pi * (r^2 (L+hc) + hc^3/3) 
     75    //        = pi (r^2 (L+hc) + hc^3/3) 
    6276    const double hc = cap_radius - sqrt(cap_radius*cap_radius - radius*radius); 
    6377    return M_PI*(radius*radius*(length+hc) + 0.333333333333333*hc*hc*hc); 
Note: See TracChangeset for help on using the changeset viewer.