Changeset 82c11d3 in sasview for sansmodels/src/c_models/vesicle.cpp


Ignore:
Timestamp:
Jan 5, 2012 6:24:51 PM (13 years ago)
Author:
Mathieu Doucet <doucetm@…>
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:
20d91bd
Parents:
98fdccd
Message:

refactored bunch of models

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sansmodels/src/c_models/vesicle.cpp

    r67424cd r82c11d3  
    2121 
    2222#include <math.h> 
    23 #include "models.hh" 
    2423#include "parameters.hh" 
    2524#include <stdio.h> 
    2625using namespace std; 
     26#include "vesicle.h" 
    2727 
    2828extern "C" { 
    29         #include "libSphere.h" 
    30         #include "vesicle.h" 
     29#include "libSphere.h" 
    3130} 
    3231 
     32typedef struct { 
     33  double scale; 
     34  double radius; 
     35  double thickness; 
     36  double core_sld; 
     37  double shell_sld; 
     38  double background; 
     39} VesicleParameters; 
     40 
    3341VesicleModel :: VesicleModel() { 
    34         scale      = Parameter(1.0); 
    35         radius     = Parameter(100.0, true); 
    36         radius.set_min(0.0); 
    37         thickness  = Parameter(30.0, true); 
    38         thickness.set_min(0.0); 
    39         core_sld   = Parameter(6.36e-6); 
    40         shell_sld   = Parameter(5.0e-7); 
    41         background = Parameter(0.0); 
     42  scale      = Parameter(1.0); 
     43  radius     = Parameter(100.0, true); 
     44  radius.set_min(0.0); 
     45  thickness  = Parameter(30.0, true); 
     46  thickness.set_min(0.0); 
     47  core_sld   = Parameter(6.36e-6); 
     48  shell_sld   = Parameter(5.0e-7); 
     49  background = Parameter(0.0); 
    4250} 
    4351 
     
    4957 */ 
    5058double VesicleModel :: operator()(double q) { 
    51         double dp[6]; 
     59  double dp[6]; 
    5260 
    53         // Fill parameter array for IGOR library 
    54         // Add the background after averaging 
    55         dp[0] = scale(); 
    56         dp[1] = radius(); 
    57         dp[2] = thickness(); 
    58         dp[3] = core_sld(); 
    59         dp[4] = shell_sld(); 
    60         dp[5] = 0.0; 
     61  // Fill parameter array for IGOR library 
     62  // Add the background after averaging 
     63  dp[0] = scale(); 
     64  dp[1] = radius(); 
     65  dp[2] = thickness(); 
     66  dp[3] = core_sld(); 
     67  dp[4] = shell_sld(); 
     68  dp[5] = 0.0; 
    6169 
    6270 
    63         // Get the dispersion points for the core radius 
    64         vector<WeightPoint> weights_radius; 
    65         radius.get_weights(weights_radius); 
    66         // Get the dispersion points for the thickness 
    67         vector<WeightPoint> weights_thickness; 
    68         thickness.get_weights(weights_thickness); 
     71  // Get the dispersion points for the core radius 
     72  vector<WeightPoint> weights_radius; 
     73  radius.get_weights(weights_radius); 
     74  // Get the dispersion points for the thickness 
     75  vector<WeightPoint> weights_thickness; 
     76  thickness.get_weights(weights_thickness); 
    6977 
    70         // Perform the computation, with all weight points 
    71         double sum = 0.0; 
    72         double norm = 0.0; 
    73         double vol = 0.0; 
     78  // Perform the computation, with all weight points 
     79  double sum = 0.0; 
     80  double norm = 0.0; 
     81  double vol = 0.0; 
    7482 
    75         // Loop over radius weight points 
    76         for(int i=0; i< (int)weights_radius.size(); i++) { 
    77                 dp[1] = weights_radius[i].value; 
    78                 for(int j=0; j< (int)weights_thickness.size(); j++) { 
    79                         dp[2] = weights_thickness[j].value; 
    80                         sum += weights_radius[i].weight 
    81                                 * weights_thickness[j].weight * VesicleForm(dp, q) 
    82                                 *(pow(weights_radius[i].value+weights_thickness[j].value,3)-pow(weights_radius[i].value,3)); 
    83                         //Find average volume 
    84                         vol += weights_radius[i].weight * weights_thickness[j].weight 
    85                                 *(pow(weights_radius[i].value+weights_thickness[j].value,3)-pow(weights_radius[i].value,3)); 
    86                         norm += weights_radius[i].weight * weights_thickness[j].weight; 
    87                 } 
    88         } 
    89         if (vol != 0.0 && norm != 0.0) { 
    90                 //Re-normalize by avg volume 
    91                 sum = sum/(vol/norm);} 
     83  // Loop over radius weight points 
     84  for(int i=0; i< (int)weights_radius.size(); i++) { 
     85    dp[1] = weights_radius[i].value; 
     86    for(int j=0; j< (int)weights_thickness.size(); j++) { 
     87      dp[2] = weights_thickness[j].value; 
     88      sum += weights_radius[i].weight 
     89          * weights_thickness[j].weight * VesicleForm(dp, q) 
     90      *(pow(weights_radius[i].value+weights_thickness[j].value,3)-pow(weights_radius[i].value,3)); 
     91      //Find average volume 
     92      vol += weights_radius[i].weight * weights_thickness[j].weight 
     93          *(pow(weights_radius[i].value+weights_thickness[j].value,3)-pow(weights_radius[i].value,3)); 
     94      norm += weights_radius[i].weight * weights_thickness[j].weight; 
     95    } 
     96  } 
     97  if (vol != 0.0 && norm != 0.0) { 
     98    //Re-normalize by avg volume 
     99    sum = sum/(vol/norm);} 
    92100 
    93         return sum/norm + background(); 
     101  return sum/norm + background(); 
    94102} 
    95103 
     
    101109 */ 
    102110double VesicleModel :: operator()(double qx, double qy) { 
    103         double q = sqrt(qx*qx + qy*qy); 
    104         return (*this).operator()(q); 
     111  double q = sqrt(qx*qx + qy*qy); 
     112  return (*this).operator()(q); 
    105113} 
    106114 
     
    113121 */ 
    114122double VesicleModel :: evaluate_rphi(double q, double phi) { 
    115         return (*this).operator()(q); 
     123  return (*this).operator()(q); 
    116124} 
    117125/** 
     
    120128 */ 
    121129double VesicleModel :: calculate_ER() { 
    122         VesicleParameters dp; 
     130  VesicleParameters dp; 
    123131 
    124         dp.radius     = radius(); 
    125         dp.thickness  = thickness(); 
     132  dp.radius     = radius(); 
     133  dp.thickness  = thickness(); 
    126134 
    127         double rad_out = 0.0; 
     135  double rad_out = 0.0; 
    128136 
    129         // Perform the computation, with all weight points 
    130         double sum = 0.0; 
    131         double norm = 0.0; 
     137  // Perform the computation, with all weight points 
     138  double sum = 0.0; 
     139  double norm = 0.0; 
    132140 
    133141 
    134         // Get the dispersion points for the major shell 
    135         vector<WeightPoint> weights_thickness; 
    136         thickness.get_weights(weights_thickness); 
     142  // Get the dispersion points for the major shell 
     143  vector<WeightPoint> weights_thickness; 
     144  thickness.get_weights(weights_thickness); 
    137145 
    138         // Get the dispersion points for the minor shell 
    139         vector<WeightPoint> weights_radius ; 
    140         radius.get_weights(weights_radius); 
     146  // Get the dispersion points for the minor shell 
     147  vector<WeightPoint> weights_radius ; 
     148  radius.get_weights(weights_radius); 
    141149 
    142         // Loop over major shell weight points 
    143         for(int j=0; j< (int)weights_thickness.size(); j++) { 
    144                 dp.thickness = weights_thickness[j].value; 
    145                 for(int k=0; k< (int)weights_radius.size(); k++) { 
    146                         dp.radius = weights_radius[k].value; 
    147                         sum += weights_thickness[j].weight 
    148                                 * weights_radius[k].weight*(dp.radius+dp.thickness); 
    149                         norm += weights_thickness[j].weight* weights_radius[k].weight; 
    150                 } 
    151         } 
    152         if (norm != 0){ 
    153                 //return the averaged value 
    154                 rad_out =  sum/norm;} 
    155         else{ 
    156                 //return normal value 
    157                 rad_out = (dp.radius+dp.thickness);} 
     150  // Loop over major shell weight points 
     151  for(int j=0; j< (int)weights_thickness.size(); j++) { 
     152    dp.thickness = weights_thickness[j].value; 
     153    for(int k=0; k< (int)weights_radius.size(); k++) { 
     154      dp.radius = weights_radius[k].value; 
     155      sum += weights_thickness[j].weight 
     156          * weights_radius[k].weight*(dp.radius+dp.thickness); 
     157      norm += weights_thickness[j].weight* weights_radius[k].weight; 
     158    } 
     159  } 
     160  if (norm != 0){ 
     161    //return the averaged value 
     162    rad_out =  sum/norm;} 
     163  else{ 
     164    //return normal value 
     165    rad_out = (dp.radius+dp.thickness);} 
    158166 
    159         return rad_out; 
     167  return rad_out; 
    160168} 
Note: See TracChangeset for help on using the changeset viewer.