source: sasview/sansmodels/src/sans/models/c_models/sphere.cpp @ 885857e

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 885857e was c451be9, checked in by Jae Cho <jhjcho@…>, 15 years ago

corrections on the definition of polydispersity as suggested by steve K: should be normalized by average volume

  • Property mode set to 100644
File size: 3.5 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 "models.hh"
24#include "parameters.hh"
25#include <stdio.h>
26using namespace std;
27
28extern "C" {
29        #include "libSphere.h"
30        #include "sphere.h"
31}
32
33SphereModel :: SphereModel() {
34        scale      = Parameter(1.0);
35        radius     = Parameter(20.0, true);
36        radius.set_min(0.0);
37        contrast   = Parameter(3.e-6);
38        background = Parameter(0.0);
39}
40
41/**
42 * Function to evaluate 1D scattering function
43 * The NIST IGOR library is used for the actual calculation.
44 * @param q: q-value
45 * @return: function value
46 */
47double SphereModel :: operator()(double q) {
48        double dp[4];
49
50        // Fill parameter array for IGOR library
51        // Add the background after averaging
52        dp[0] = scale();
53        dp[1] = radius();
54        dp[2] = contrast();
55        dp[3] = 0.0;
56
57        // Get the dispersion points for the radius
58        vector<WeightPoint> weights_rad;
59        radius.get_weights(weights_rad);
60
61        // Perform the computation, with all weight points
62        double sum = 0.0;
63        double norm = 0.0;
64        double vol = 0.0;
65
66        // Loop over radius weight points
67        for(int i=0; i<weights_rad.size(); i++) {
68                dp[1] = weights_rad[i].value;
69
70                //Un-normalize SphereForm by volume
71                sum += weights_rad[i].weight
72                        * SphereForm(dp, q) * pow(weights_rad[i].value,3);
73                //Find average volume
74                vol += weights_rad[i].weight
75                        * pow(weights_rad[i].value,3);
76
77                norm += weights_rad[i].weight;
78        }
79
80        if (vol != 0.0 && norm != 0.0) {
81                //Re-normalize by avg volume
82                sum = sum/(vol/norm);}
83        return sum/norm + background();
84}
85
86/**
87 * Function to evaluate 2D scattering function
88 * @param q_x: value of Q along x
89 * @param q_y: value of Q along y
90 * @return: function value
91 */
92double SphereModel :: operator()(double qx, double qy) {
93        double q = sqrt(qx*qx + qy*qy);
94        return (*this).operator()(q);
95}
96
97/**
98 * Function to evaluate 2D scattering function
99 * @param pars: parameters of the sphere
100 * @param q: q-value
101 * @param phi: angle phi
102 * @return: function value
103 */
104double SphereModel :: evaluate_rphi(double q, double phi) {
105        return (*this).operator()(q);
106}
107
108/**
109 * Function to calculate effective radius
110 * @return: effective radius value
111 */
112double SphereModel :: calculate_ER() {
113        SphereParameters dp;
114        dp.scale = scale();
115        dp.radius = radius();
116        dp.contrast = contrast();
117        dp.background = background();
118        double rad_out = 0.0;
119
120        // Perform the computation, with all weight points
121        double sum = 0.0;
122        double norm = 0.0;
123
124        // Get the dispersion points for the radius
125        vector<WeightPoint> weights_rad;
126        radius.get_weights(weights_rad);
127        // Loop over radius weight points to average the radius value
128        for(int i=0; i<weights_rad.size(); i++) {
129                sum += weights_rad[i].weight
130                        * weights_rad[i].value;
131                norm += weights_rad[i].weight;
132        }
133        if (norm != 0){
134                //return the averaged value
135                rad_out =  sum/norm;}
136        else{
137                //return normal value
138                rad_out = radius();}
139
140        return rad_out;
141}
Note: See TracBrowser for help on using the repository browser.