source: sasview/sansmodels/src/c_models/coreshellsphere.cpp @ 65261207

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 65261207 was e08bd5b, checked in by Jae Cho <jhjcho@…>, 13 years ago

c models fix: scale fix for P*S

  • Property mode set to 100644
File size: 4.8 KB
RevLine 
[0f5bc9f]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;
[011e0e4]26#include "core_shell.h"
[0f5bc9f]27
28extern "C" {
[011e0e4]29#include "libSphere.h"
[0f5bc9f]30}
31
[011e0e4]32typedef struct {
33  double scale;
34  double radius;
35  double thickness;
36  double core_sld;
37  double shell_sld;
38  double solvent_sld;
39  double background;
40} CoreShellParameters;
41
[0f5bc9f]42CoreShellModel :: CoreShellModel() {
[011e0e4]43  scale      = Parameter(1.0);
44  radius     = Parameter(60.0, true);
45  radius.set_min(0.0);
46  thickness  = Parameter(10.0, true);
47  thickness.set_min(0.0);
48  core_sld   = Parameter(1.e-6);
49  shell_sld  = Parameter(2.e-6);
50  solvent_sld = Parameter(3.e-6);
51  background = Parameter(0.0);
[0f5bc9f]52}
53
54/**
55 * Function to evaluate 1D scattering function
56 * The NIST IGOR library is used for the actual calculation.
57 * @param q: q-value
58 * @return: function value
59 */
60double CoreShellModel :: operator()(double q) {
[011e0e4]61  double dp[7];
62
63  // Fill parameter array for IGOR library
64  // Add the background after averaging
65
66  dp[0] = scale();
67  dp[1] = radius();
68  dp[2] = thickness();
69  dp[3] = core_sld();
70  dp[4] = shell_sld();
71  dp[5] = solvent_sld();
72  dp[6] = 0.0;
73
74
75  // Get the dispersion points for the radius
76  vector<WeightPoint> weights_rad;
77  radius.get_weights(weights_rad);
78
79  // Get the dispersion points for the thickness
80  vector<WeightPoint> weights_thick;
81  thickness.get_weights(weights_thick);
82
83  // Perform the computation, with all weight points
84  double sum = 0.0;
85  double norm = 0.0;
86  double vol = 0.0;
87
88  // Loop over radius weight points
89  for(size_t i=0; i<weights_rad.size(); i++) {
90    dp[1] = weights_rad[i].value;
91
92    // Loop over thickness weight points
93    for(size_t j=0; j<weights_thick.size(); j++) {
94      dp[2] = weights_thick[j].value;
95      //Un-normalize SphereForm by volume
96      sum += weights_rad[i].weight
97          * weights_thick[j].weight * CoreShellForm(dp, q)* pow(weights_rad[i].value+weights_thick[j].value,3);
98
99      //Find average volume
100      vol += weights_rad[i].weight * weights_thick[j].weight
101          * pow(weights_rad[i].value+weights_thick[j].value,3);
102      norm += weights_rad[i].weight
103          * weights_thick[j].weight;
104    }
105  }
106
107  if (vol != 0.0 && norm != 0.0) {
108    //Re-normalize by avg volume
109    sum = sum/(vol/norm);}
110
111  return sum/norm + background();
[0f5bc9f]112}
113
114/**
115 * Function to evaluate 2D scattering function
116 * @param q_x: value of Q along x
117 * @param q_y: value of Q along y
118 * @return: function value
119 */
120double CoreShellModel :: operator()(double qx, double qy) {
[011e0e4]121  double q = sqrt(qx*qx + qy*qy);
122  return (*this).operator()(q);
[0f5bc9f]123}
124
125/**
126 * Function to evaluate 2D scattering function
127 * @param pars: parameters of the sphere
128 * @param q: q-value
129 * @param phi: angle phi
130 * @return: function value
131 */
132double CoreShellModel :: evaluate_rphi(double q, double phi) {
[011e0e4]133  return (*this).operator()(q);
[0f5bc9f]134}
[5eb9154]135/**
136 * Function to calculate effective radius
137 * @return: effective radius value
138 */
139double CoreShellModel :: calculate_ER() {
[011e0e4]140  CoreShellParameters dp;
141
142  dp.radius     = radius();
143  dp.thickness  = thickness();
144
145  double rad_out = 0.0;
146
147  // Perform the computation, with all weight points
148  double sum = 0.0;
149  double norm = 0.0;
150
151
152  // Get the dispersion points for the major shell
153  vector<WeightPoint> weights_thickness;
154  thickness.get_weights(weights_thickness);
155
156  // Get the dispersion points for the minor shell
157  vector<WeightPoint> weights_radius ;
158  radius.get_weights(weights_radius);
159
160  // Loop over major shell weight points
161  for(int j=0; j< (int)weights_thickness.size(); j++) {
162    dp.thickness = weights_thickness[j].value;
163    for(int k=0; k< (int)weights_radius.size(); k++) {
164      dp.radius = weights_radius[k].value;
165      sum += weights_thickness[j].weight
166          * weights_radius[k].weight*(dp.radius+dp.thickness);
167      norm += weights_thickness[j].weight* weights_radius[k].weight;
168    }
169  }
170  if (norm != 0){
171    //return the averaged value
172    rad_out =  sum/norm;}
173  else{
174    //return normal value
175    rad_out = (dp.radius+dp.thickness);}
176
177  return rad_out;
[5eb9154]178}
[e08bd5b]179double CoreShellModel :: calculate_VR() {
180  return 1.0;
181}
Note: See TracBrowser for help on using the repository browser.