source: sasview/sansmodels/src/c_models/vesicle.cpp @ 046af80

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 046af80 was 82c11d3, checked in by Mathieu Doucet <doucetm@…>, 13 years ago

refactored bunch of models

  • Property mode set to 100644
File size: 4.6 KB
Line 
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;
26#include "vesicle.h"
27
28extern "C" {
29#include "libSphere.h"
30}
31
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
41VesicleModel :: VesicleModel() {
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);
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) {
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();
66  dp[3] = core_sld();
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();
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) {
111  double q = sqrt(qx*qx + qy*qy);
112  return (*this).operator()(q);
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) {
123  return (*this).operator()(q);
124}
125/**
126 * Function to calculate effective radius
127 * @return: effective radius value
128 */
129double VesicleModel :: calculate_ER() {
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;
168}
Note: See TracBrowser for help on using the repository browser.