source: sasview/sansmodels/src/sans/models/c_models/fuzzysphere.cpp @ 7bc88bf

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

More models added and correction of Wrappergenerator on model parameter value precision

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