source: sasview/sansmodels/src/c_models/vesicle.cpp @ d555416

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since d555416 was 2d6f1f1, checked in by Jae Cho <jhjcho@…>, 13 years ago

hope it make better gui for vesicle

  • Property mode set to 100644
File size: 5.9 KB
RevLine 
[3d25331f]1/**
2        This software was developed by the University of Tennessee as part of the
3        Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
4        project funded by the US National Science Foundation.
5
6        If you use DANSE applications to do scientific research that leads to
7        publication, we ask that you acknowledge the use of the software with the
8        following sentence:
9
10        "This work benefited from DANSE software developed under NSF award DMR-0520547."
11
12        copyright 2008, University of Tennessee
13 */
14
15/**
16 * Scattering model classes
17 * The classes use the IGOR library found in
18 *   sansmodels/src/libigor
19 *
20 */
21
22#include <math.h>
23#include "parameters.hh"
24#include <stdio.h>
25using namespace std;
[82c11d3]26#include "vesicle.h"
[3d25331f]27
28extern "C" {
[82c11d3]29#include "libSphere.h"
[3d25331f]30}
31
[82c11d3]32typedef struct {
33  double scale;
34  double radius;
35  double thickness;
[2d6f1f1]36  double solv_sld;
[82c11d3]37  double shell_sld;
38  double background;
39} VesicleParameters;
40
[3d25331f]41VesicleModel :: VesicleModel() {
[82c11d3]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);
[2d6f1f1]47  solv_sld   = Parameter(6.36e-6);
[82c11d3]48  shell_sld   = Parameter(5.0e-7);
49  background = Parameter(0.0);
[3d25331f]50}
51
52/**
53 * Function to evaluate 1D scattering function
54 * The NIST IGOR library is used for the actual calculation.
55 * @param q: q-value
56 * @return: function value
57 */
58double VesicleModel :: operator()(double q) {
[82c11d3]59  double dp[6];
60
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();
[2d6f1f1]66  dp[3] = solv_sld();
[82c11d3]67  dp[4] = shell_sld();
68  dp[5] = 0.0;
69
70
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);
77
78  // Perform the computation, with all weight points
79  double sum = 0.0;
80  double norm = 0.0;
81  double vol = 0.0;
82
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);}
100
101  return sum/norm + background();
[3d25331f]102}
103
104/**
105 * Function to evaluate 2D scattering function
106 * @param q_x: value of Q along x
107 * @param q_y: value of Q along y
108 * @return: function value
109 */
110double VesicleModel :: operator()(double qx, double qy) {
[82c11d3]111  double q = sqrt(qx*qx + qy*qy);
112  return (*this).operator()(q);
[3d25331f]113}
114
115/**
116 * Function to evaluate 2D scattering function
117 * @param pars: parameters of the vesicle
118 * @param q: q-value
119 * @param phi: angle phi
120 * @return: function value
121 */
122double VesicleModel :: evaluate_rphi(double q, double phi) {
[82c11d3]123  return (*this).operator()(q);
[3d25331f]124}
[5eb9154]125/**
126 * Function to calculate effective radius
127 * @return: effective radius value
128 */
129double VesicleModel :: calculate_ER() {
[82c11d3]130  VesicleParameters dp;
131
132  dp.radius     = radius();
133  dp.thickness  = thickness();
134
135  double rad_out = 0.0;
136
137  // Perform the computation, with all weight points
138  double sum = 0.0;
139  double norm = 0.0;
140
141
142  // Get the dispersion points for the major shell
143  vector<WeightPoint> weights_thickness;
144  thickness.get_weights(weights_thickness);
145
146  // Get the dispersion points for the minor shell
147  vector<WeightPoint> weights_radius ;
148  radius.get_weights(weights_radius);
149
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);}
166
167  return rad_out;
[5eb9154]168}
[e08bd5b]169/**
170 * Function to calculate volf_ratio for shell
171 * @return: volf_ratio value
172 */
173double VesicleModel :: calculate_VR() {
174  VesicleParameters dp;
175
176  dp.radius     = radius();
177  dp.thickness  = thickness();
178
179  double rad_out = 0.0;
180
181  // Perform the computation, with all weight points
182  double sum_tot = 0.0;
183  double sum_shell = 0.0;
184
185
186  // Get the dispersion points for the major shell
187  vector<WeightPoint> weights_thickness;
188  thickness.get_weights(weights_thickness);
189
190  // Get the dispersion points for the minor shell
191  vector<WeightPoint> weights_radius ;
192  radius.get_weights(weights_radius);
193
194  // Loop over major shell weight points
195  for(int j=0; j< (int)weights_thickness.size(); j++) {
196    dp.thickness = weights_thickness[j].value;
197    for(int k=0; k< (int)weights_radius.size(); k++) {
198      dp.radius = weights_radius[k].value;
199      sum_tot += weights_thickness[j].weight
200          * weights_radius[k].weight*pow((dp.radius+dp.thickness), 3);
201      sum_shell += weights_thickness[j].weight
202                  * weights_radius[k].weight*(pow((dp.radius+dp.thickness), 3)
203                                  - pow((dp.radius), 3));
204    }
205  }
206  if (sum_tot == 0.0){
207    //return the default value
208    rad_out =  1.0;}
209  else{
210    //return ratio value
211    return sum_shell/sum_tot;
212  }
213}
Note: See TracBrowser for help on using the repository browser.