source: sasview/sansmodels/src/sans/models/c_models/sphere.cpp @ 0da56f5

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

Updated the definition of SLD params according to new libigor functions

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