Changeset 60eab2a in sasmodels


Ignore:
Timestamp:
Mar 24, 2016 8:12:07 AM (9 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:
380e8c9
Parents:
e69b36f
Message:

support autogenerated Iqxy in C models

Location:
sasmodels
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/core.py

    r69aa451 r60eab2a  
    222222    elif kernel.dim == '2d': 
    223223        pars_2d = set(p.name for p in kernel.info['parameters'].type['2d']) 
    224         active = lambda name: name in pars_1d 
     224        active = lambda name: name in pars_2d 
    225225    else: 
    226226        active = lambda name: True 
  • sasmodels/direct_model.py

    r48fbd50 r60eab2a  
    7878            q_mono = sesans.make_all_q(data) 
    7979        elif self.data_type == 'Iqxy': 
    80             partype = model.info['par_type'] 
    81             if not partype['orientation'] and not partype['magnetic']: 
    82                 raise ValueError("not 2D without orientation or magnetic parameters") 
     80            #if not model.info['parameters'].has_2d: 
     81            #    raise ValueError("not 2D without orientation or magnetic parameters") 
    8382            q = np.sqrt(data.qx_data**2 + data.qy_data**2) 
    8483            qmin = getattr(data, 'qmin', 1e-16) 
  • sasmodels/generate.py

    r76a9ffe r60eab2a  
    415415         } 
    416416    """ 
    417     par_decl = ', '.join(p.as_argument() for p in pars) if pars else 'void' 
     417    par_decl = ', '.join(p.as_function_argument() for p in pars) if pars else 'void' 
    418418    return _FN_TEMPLATE % {'name': name, 'body': body, 'pars': par_decl} 
    419419 
     
    661661    performs a similar role for Iq written in C. 
    662662    """ 
    663     if model_info['Iq'] is not None and model_info['Iqxy'] is None: 
     663    if callable(model_info['Iq']) and model_info['Iqxy'] is None: 
    664664        partable = model_info['parameters'] 
    665665        if partable.type['1d'] != partable.type['2d']: 
     
    730730        filename=abspath(kernel_module.__file__), 
    731731        name=name, 
    732         title=kernel_module.title, 
    733         description=kernel_module.description, 
     732        title=getattr(kernel_module, 'title', name+" model"), 
     733        description=getattr(kernel_module, 'description', 'no description'), 
    734734        parameters=parameters, 
    735735        composition=None, 
  • sasmodels/kernel_iq.c

    r69aa451 r60eab2a  
    1616 
    1717typedef struct { 
     18#if MAX_PD > 0 
    1819    int32_t pd_par[MAX_PD];     // id of the nth polydispersity variable 
    1920    int32_t pd_length[MAX_PD];  // length of the nth polydispersity weight vector 
     
    2122    int32_t pd_stride[MAX_PD];  // stride to move to the next index at this level 
    2223    int32_t pd_isvol[MAX_PD];   // True if parameter is a volume weighting parameter 
     24#endif // MAX_PD > 0 
    2325    int32_t par_offset[NPARS];  // offset of par values in the value & weight vector 
    2426    int32_t par_coord[NPARS];   // polydispersity coordination bitvector 
     
    5254  double *pvec = (double *)(&local_values);  // Alias named parameters with a vector 
    5355 
    54   local int offset[NPARS];  // NPARS excludes scale/background 
    55  
    56 #if 0 // defined(USE_SHORTCUT_OPTIMIZATION) 
     56#if MAX_PD > 0 
    5757  if (problem->pd_length[0] == 1) { 
     58#endif // MAX_PD > 0 
    5859    // Shouldn't need to copy!! 
    59  
    6060    for (int k=0; k < NPARS; k++) { 
    6161      pvec[k] = values[k+2];  // skip scale and background 
     
    6767    #endif 
    6868    for (int i=0; i < nq; i++) { 
    69       const double scattering = CALL_IQ(q, i, local_values); 
    70       result[i] = values[0]*scattering/volume + values[1]; 
     69      double scattering = CALL_IQ(q, i, local_values); 
     70      if (volume != 0.0) scattering /= volume; 
     71      result[i] = values[0]*scattering + values[1]; 
    7172    } 
    7273    return; 
    73   } 
    74   printf("falling through\n"); 
    75 #endif 
     74#if MAX_PD > 0 
     75  } 
     76 
     77  // polydispersity loop index positions 
     78  local int offset[NPARS];  // NPARS excludes scale/background 
    7679 
    7780  printf("Entering polydispersity\n"); 
     
    177180      } 
    178181    } 
    179     printf("rad len %f %f\n",local_values.radius, local_values.length); 
    180182    #ifdef INVALID 
    181183    if (INVALID(local_values)) continue; 
     
    199201  } 
    200202 
    201   //Makes a normalization avialable for the next round 
     203  //Makes a normalization available for the next round 
    202204  result[nq] = norm; 
    203205  result[nq+1] = vol; 
     
    216218    } 
    217219  } 
     220#endif // MAX_PD > 0 
    218221} 
  • sasmodels/modelinfo.py

    r69aa451 r60eab2a  
    3030        processed.append(parse_parameter(*p)) 
    3131    partable = ParameterTable(processed) 
    32     set_vector_length_from_reference(partable) 
    3332    return partable 
    34  
    35 def set_vector_length_from_reference(partable): 
    36     # Sort out the length of the vector parameters such as thickness[n] 
    37     for p in partable: 
    38         if p.length_control: 
    39            ref = partable[p.length_control] 
    40            low, high = ref.limits 
    41            if int(low) != low or int(high) != high or low<0 or high>20: 
    42                raise ValueError("expected limits on %s to be within [0, 20]"%ref.name) 
    43            p.length = low 
    4433 
    4534def parse_parameter(name, units='', default=None, 
     
    172161    def __init__(self, name, units='', default=None, limits=(-np.inf, np.inf), 
    173162                 type='', description=''): 
    174         self.id = name 
     163        self.id = name.split('[')[0].strip() 
    175164        self.name = name 
    176165        self.default = default 
     
    235224        self._name_table= dict((p.name, p) for p in parameters) 
    236225        self._categorize_parameters() 
     226 
     227        self._set_vector_lengths() 
     228        self._set_defaults() 
     229 
     230    def _set_vector_lengths(self): 
     231        # Sort out the length of the vector parameters such as thickness[n] 
     232        for p in self.parameters: 
     233            if p.length_control: 
     234                ref = self._name_table[p.length_control] 
     235                low, high = ref.limits 
     236                if int(low) != low or int(high) != high or low<0 or high>20: 
     237                    raise ValueError("expected limits on %s to be within [0, 20]"%ref.name) 
     238                p.length = low 
     239 
     240    def _set_defaults(self): 
     241        # Construct default values, including vector defaults 
     242        defaults = {} 
     243        for p in self.parameters: 
     244            if p.length == 1: 
     245                defaults[p.id] = p.default 
     246            else: 
     247                for k in range(p.length): 
     248                    defaults["%s[%d]"%(p.id, k)] = p.default 
     249        self.defaults = defaults 
    237250 
    238251    def __getitem__(self, k): 
     
    289302        par_type['1d'] = [p for p in pars if p.type not in ('orientation', 'magnetic')] 
    290303        par_type['2d'] = [p for p in pars if p.type != 'magnetic'] 
    291         par_type['magnetic'] = [p for p in pars] 
    292304        par_type['pd'] = [p for p in pars if p.polydisperse] 
    293305        par_type['pd_relative'] = [p for p in pars if p.relative_pd] 
     
    304316 
    305317    @property 
    306     def defaults(self): 
    307         return dict((p.name, p.default) for p in self.parameters) 
    308  
    309     @property 
    310318    def num_pd(self): 
    311319        """ 
     
    313321        shape dimensions and orientational distributions). 
    314322        """ 
    315         return len(self.type['pd']) 
     323        return sum(p.length for p in self.type['pd']) 
    316324 
    317325    @property 
Note: See TracChangeset for help on using the changeset viewer.