source: sasview/sansmodels/src/c_models/sphere.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: 3.4 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 "sphere.h"
27
28extern "C" {
29        #include "libSphere.h"
30}
31
32SphereModel :: SphereModel() {
33        scale      = Parameter(1.0);
34        radius     = Parameter(20.0, true);
35        radius.set_min(0.0);
36        sldSph   = Parameter(4.0e-6);
37        sldSolv   = Parameter(1.0e-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[5];
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] = sldSph();
55        dp[3] = sldSolv();
56        dp[4] = 0.0;
57
58        // Get the dispersion points for the radius
59        vector<WeightPoint> weights_rad;
60        radius.get_weights(weights_rad);
61
62        // Perform the computation, with all weight points
63        double sum = 0.0;
64        double norm = 0.0;
65        double vol = 0.0;
66
67        // Loop over radius weight points
68        for(size_t i=0; i<weights_rad.size(); i++) {
69                dp[1] = weights_rad[i].value;
70
71                //Un-normalize SphereForm by volume
72                sum += weights_rad[i].weight
73                        * SphereForm(dp, q) * pow(weights_rad[i].value,3);
74                //Find average volume
75                vol += weights_rad[i].weight
76                        * pow(weights_rad[i].value,3);
77
78                norm += weights_rad[i].weight;
79        }
80
81        if (vol != 0.0 && norm != 0.0) {
82                //Re-normalize by avg volume
83                sum = sum/(vol/norm);}
84        return sum/norm + background();
85}
86
87/**
88 * Function to evaluate 2D scattering function
89 * @param q_x: value of Q along x
90 * @param q_y: value of Q along y
91 * @return: function value
92 */
93double SphereModel :: operator()(double qx, double qy) {
94        double q = sqrt(qx*qx + qy*qy);
95        return (*this).operator()(q);
96}
97
98/**
99 * Function to evaluate 2D scattering function
100 * @param pars: parameters of the sphere
101 * @param q: q-value
102 * @param phi: angle phi
103 * @return: function value
104 */
105double SphereModel :: evaluate_rphi(double q, double phi) {
106        return (*this).operator()(q);
107}
108
109/**
110 * Function to calculate effective radius
111 * @return: effective radius value
112 */
113double SphereModel :: calculate_ER() {
114        double rad_out = 0.0;
115
116        // Perform the computation, with all weight points
117        double sum = 0.0;
118        double norm = 0.0;
119
120        // Get the dispersion points for the radius
121        vector<WeightPoint> weights_rad;
122        radius.get_weights(weights_rad);
123        // Loop over radius weight points to average the radius value
124        for(size_t i=0; i<weights_rad.size(); i++) {
125                sum += weights_rad[i].weight
126                        * weights_rad[i].value;
127                norm += weights_rad[i].weight;
128        }
129        if (norm != 0){
130                //return the averaged value
131                rad_out =  sum/norm;}
132        else{
133                //return normal value
134                rad_out = radius();}
135
136        return rad_out;
137}
Note: See TracBrowser for help on using the repository browser.